This commit is contained in:
2021-04-13 15:57:49 +00:00
parent 4b43222be6
commit 5601f0a7a6

View File

@@ -58,8 +58,8 @@ export default {
try { try {
await initForm(vm); await initForm(vm);
//set base rights
vm.rights = window.$gz.role.getRights(window.$gz.type.WorkOrder); vm.rights = window.$gz.role.getRights(window.$gz.type.WorkOrder);
vm.formState.readOnly = !vm.rights.change;
window.$gz.eventBus.$on("menu-click", clickHandler); window.$gz.eventBus.$on("menu-click", clickHandler);
//id 0 means create a new record don't load one //id 0 means create a new record don't load one
@@ -87,10 +87,9 @@ export default {
dirty: false, dirty: false,
valid: true valid: true
}); });
//preset object so do things normally done in getdata
generateMenu(vm); //update which areas are available to user and force generate menu
//update which areas are available to user updateRights(vm, true);
setAllRights(vm);
} catch (error) { } catch (error) {
window.$gz.errorHandler.handleFormError(error, vm); window.$gz.errorHandler.handleFormError(error, vm);
} finally { } finally {
@@ -339,11 +338,7 @@ export default {
return window.$gz.form; return window.$gz.form;
}, },
fieldValueChanged(ref) { fieldValueChanged(ref) {
if ( if (this.formState.ready && !this.formState.loading) {
this.formState.ready &&
!this.formState.loading
//&& !this.formState.readOnly //commented out to not affect state setting, I think it's redundant
) {
window.$gz.form.fieldValueChanged(this, ref); window.$gz.form.fieldValueChanged(this, ref);
} }
}, },
@@ -374,7 +369,7 @@ export default {
//modify the menu as necessary //modify the menu as necessary
generateMenu(vm); generateMenu(vm);
//update which areas are available to user //update which areas are available to user
setAllRights(vm); updateRights(vm);
//Update the form status //Update the form status
window.$gz.form.setFormState({ window.$gz.form.setFormState({
@@ -436,7 +431,7 @@ export default {
stateSaved = true; stateSaved = true;
//update which areas are available to user //update which areas are available to user
//which may have changed due to state being saved (saveState sets the current islocked value) //which may have changed due to state being saved (saveState sets the current islocked value)
setAllRights(vm); updateRights(vm);
} }
//############# DELETE GRAPH ############### //############# DELETE GRAPH ###############
@@ -468,7 +463,7 @@ export default {
//in case it locks or is completed //in case it locks or is completed
if (!stateSaved && noProblem) { if (!stateSaved && noProblem) {
noProblem = await saveState(vm); noProblem = await saveState(vm);
setAllRights(vm); updateRights(vm);
} }
//## ALL PARTIAL UPDATES SUCCEEDED //## ALL PARTIAL UPDATES SUCCEEDED
@@ -828,19 +823,18 @@ function displayResError(vm, res) {
///////////////////////////// /////////////////////////////
// //
// //
function setAllRights(vm) { function updateRights(vm, forceGenerateMenu) {
//determine rights to each which sections are hidden due to form customized out or rights / roles //determine rights to each which sections are hidden due to form customized out or rights / roles
//todo: determine this and set accordingly, for now all set to available true during init
//## NOTE: these are subrights only, readOnly overrides all
const readOnlyBefore = vm.formState.readOnly; const readOnlyBefore = vm.formState.readOnly;
if (vm.obj.isLockedAtServer) { if (vm.obj.isLockedAtServer) {
//locked is always read only (with state exception for sufficient roles)
vm.formState.readOnly = true; vm.formState.readOnly = true;
} else { } else {
//state may have changed to open so set rights again if allowed here //state may have changed so update readOnly
vm.formState.readOnly = !vm.rights.change; vm.formState.readOnly = !vm.rights.change;
} }
if (readOnlyBefore != vm.formState.readOnly) { if (readOnlyBefore != vm.formState.readOnly || forceGenerateMenu === true) {
generateMenu(vm); generateMenu(vm);
} }