[New Edit Mode Prototype] Hide edit button when in edit mode #350. - Modified edit policy to hide edit button when in edit mode

This commit is contained in:
Henry
2015-11-30 17:45:46 -08:00
parent acb7d4b807
commit 4f3c9f270b
2 changed files with 21 additions and 7 deletions

View File

@@ -51,6 +51,19 @@ define(
return count;
}
/**
* Checks whether the domain object is currently being edited. If
* so, the edit action is not applicable.
* @param context
* @returns {*|boolean}
*/
function isEditing(context) {
var domainObject = (context || {}).domainObject;
return domainObject
&& domainObject.hasCapability('status')
&& domainObject.getCapability('status').get('editing');
}
EditActionPolicy.prototype.allow = function (action, context) {
var key = action.getMetadata().key,
category = (context || {}).category;
@@ -59,11 +72,12 @@ define(
if (category === 'view-control') {
// Restrict 'edit' to cases where there are editable
// views (similarly, restrict 'properties' to when
// the converse is true)
// the converse is true), and where the domain object is not
// already being edited.
if (key === 'edit') {
return countEditableViews(context) > 0;
return countEditableViews(context) > 0 && !isEditing(context);
} else if (key === 'properties') {
return countEditableViews(context) < 1;
return countEditableViews(context) < 1 && !isEditing(context);
}
}