Added refresh check for editability

This commit is contained in:
Henry 2015-11-11 11:52:30 -08:00
parent aa5734d023
commit 4c0a79116a

View File

@ -96,6 +96,7 @@ define(
toClear = [], // Properties to clear out of scope on change toClear = [], // Properties to clear out of scope on change
counter = 0, counter = 0,
couldRepresent = false, couldRepresent = false,
couldEdit = false,
lastId, lastId,
lastKey, lastKey,
changeTemplate = templateLinker.link($scope, element); changeTemplate = templateLinker.link($scope, element);
@ -143,11 +144,13 @@ define(
}); });
} }
function unchanged(canRepresent, id, key) { function unchanged(canRepresent, canEdit, id, key) {
return canRepresent && return canRepresent &&
couldRepresent && couldRepresent &&
id === lastId && id === lastId &&
key === lastKey; key === lastKey &&
canEdit &&
couldEdit;
} }
// General-purpose refresh mechanism; should set up the scope // General-purpose refresh mechanism; should set up the scope
@ -159,10 +162,11 @@ define(
path = representation && getPath(representation), path = representation && getPath(representation),
uses = ((representation || {}).uses || []), uses = ((representation || {}).uses || []),
canRepresent = !!(path && domainObject), canRepresent = !!(path && domainObject),
canEdit = !!(domainObject && domainObject.hasCapability('editor')),
id = domainObject && domainObject.getId(), id = domainObject && domainObject.getId(),
key = $scope.key; key = $scope.key;
if (unchanged(canRepresent, id, key)) { if (unchanged(canRepresent, canEdit, id, key)) {
return; return;
} }
@ -190,6 +194,7 @@ define(
// To allow simplified change detection next time around // To allow simplified change detection next time around
couldRepresent = canRepresent; couldRepresent = canRepresent;
couldEdit = canEdit;
lastId = id; lastId = id;
lastKey = key; lastKey = key;