diff --git a/platform/commonUI/edit/bundle.js b/platform/commonUI/edit/bundle.js index fb357c0934..3d00dd80df 100644 --- a/platform/commonUI/edit/bundle.js +++ b/platform/commonUI/edit/bundle.js @@ -26,7 +26,7 @@ define([ "./src/controllers/ElementsController", "./src/controllers/EditObjectController", "./src/directives/MCTBeforeUnload", - "./src/actions/LinkAction", + "./src/actions/EditAndComposeAction", "./src/actions/EditAction", "./src/actions/PropertiesAction", "./src/actions/RemoveAction", @@ -55,7 +55,7 @@ define([ ElementsController, EditObjectController, MCTBeforeUnload, - LinkAction, + EditAndComposeAction, EditAction, PropertiesAction, RemoveAction, @@ -126,7 +126,7 @@ define([ "actions": [ { "key": "compose", - "implementation": LinkAction + "implementation": EditAndComposeAction }, { "key": "edit", diff --git a/platform/commonUI/edit/src/actions/LinkAction.js b/platform/commonUI/edit/src/actions/EditAndComposeAction.js similarity index 86% rename from platform/commonUI/edit/src/actions/LinkAction.js rename to platform/commonUI/edit/src/actions/EditAndComposeAction.js index f12539b1fe..de43ca0fdc 100644 --- a/platform/commonUI/edit/src/actions/LinkAction.js +++ b/platform/commonUI/edit/src/actions/EditAndComposeAction.js @@ -31,13 +31,14 @@ define( * @memberof platform/commonUI/edit * @implements {Action} */ - function LinkAction(context) { + function EditAndComposeAction(context) { this.domainObject = (context || {}).domainObject; this.selectedObject = (context || {}).selectedObject; } - LinkAction.prototype.perform = function () { - var self = this; + EditAndComposeAction.prototype.perform = function () { + var self = this, + editAction = this.domainObject.getCapability('action').getActions("edit")[0]; // Persist changes to the domain object function doPersist() { @@ -54,9 +55,13 @@ define( .then(doPersist); } + if (editAction) { + editAction.perform(); + } + return this.selectedObject && doLink(); }; - return LinkAction; + return EditAndComposeAction; } ); diff --git a/platform/commonUI/edit/src/policies/EditActionPolicy.js b/platform/commonUI/edit/src/policies/EditActionPolicy.js index f266d580eb..86e103b387 100644 --- a/platform/commonUI/edit/src/policies/EditActionPolicy.js +++ b/platform/commonUI/edit/src/policies/EditActionPolicy.js @@ -81,17 +81,14 @@ define( var key = action.getMetadata().key, category = (context || {}).category; - // Only worry about actions in the view-control category - if (category === 'view-control') { - // Restrict 'edit' to cases where there are editable - // views (similarly, restrict 'properties' to when - // the converse is true), and where the domain object is not - // already being edited. - if (key === 'edit') { - return this.countEditableViews(context) > 0 && !isEditing(context); - } else if (key === 'properties') { - return this.countEditableViews(context) < 1 && !isEditing(context); - } + // Restrict 'edit' to cases where there are editable + // views (similarly, restrict 'properties' to when + // the converse is true), and where the domain object is not + // already being edited. + if (key === 'edit') { + return this.countEditableViews(context) > 0 && !isEditing(context); + } else if (key === 'properties' && category === 'view-control') { + return this.countEditableViews(context) < 1 && !isEditing(context); } // Like all policies, allow by default. diff --git a/platform/commonUI/edit/test/actions/LinkActionSpec.js b/platform/commonUI/edit/test/actions/EditAndComposeActionSpec.js similarity index 75% rename from platform/commonUI/edit/test/actions/LinkActionSpec.js rename to platform/commonUI/edit/test/actions/EditAndComposeActionSpec.js index 144dd4e395..2e83b2f9c7 100644 --- a/platform/commonUI/edit/test/actions/LinkActionSpec.js +++ b/platform/commonUI/edit/test/actions/EditAndComposeActionSpec.js @@ -21,8 +21,8 @@ *****************************************************************************/ define( - ["../../src/actions/LinkAction"], - function (LinkAction) { + ["../../src/actions/EditAndComposeAction"], + function (EditAndComposeAction) { describe("The Link action", function () { var mockQ, @@ -31,6 +31,8 @@ define( mockContext, mockComposition, mockPersistence, + mockActionCapability, + mockEditAction, mockType, actionContext, model, @@ -67,18 +69,23 @@ define( mockContext = jasmine.createSpyObj("context", [ "getParent" ]); mockComposition = jasmine.createSpyObj("composition", [ "invoke", "add" ]); mockPersistence = jasmine.createSpyObj("persistence", [ "persist" ]); - mockType = jasmine.createSpyObj("type", [ "hasFeature" ]); + mockType = jasmine.createSpyObj("type", [ "hasFeature", "getKey" ]); + mockActionCapability = jasmine.createSpyObj("actionCapability", [ "getActions"]); + mockEditAction = jasmine.createSpyObj("editAction", ["perform"]); mockDomainObject.getId.andReturn("test"); mockDomainObject.getCapability.andReturn(mockContext); mockContext.getParent.andReturn(mockParent); mockType.hasFeature.andReturn(true); + mockType.getKey.andReturn("layout"); mockComposition.invoke.andReturn(mockPromise(true)); mockComposition.add.andReturn(mockPromise(true)); + mockActionCapability.getActions.andReturn([]); capabilities = { composition: mockComposition, persistence: mockPersistence, + action: mockActionCapability, type: mockType }; model = { @@ -90,7 +97,7 @@ define( selectedObject: mockDomainObject }; - action = new LinkAction(actionContext); + action = new EditAndComposeAction(actionContext); }); @@ -105,6 +112,21 @@ define( expect(mockPersistence.persist).toHaveBeenCalled(); }); + it("enables edit mode for objects that have an edit action", function () { + mockActionCapability.getActions.andReturn([mockEditAction]); + action.perform(); + expect(mockEditAction.perform).toHaveBeenCalled(); + }); + + it("Does not enable edit mode for objects that do not have an" + + " edit action", function () { + mockActionCapability.getActions.andReturn([]); + action.perform(); + expect(mockEditAction.perform).not.toHaveBeenCalled(); + expect(mockComposition.add) + .toHaveBeenCalledWith(mockDomainObject); + }); + }); } ); diff --git a/platform/representation/src/gestures/DropGesture.js b/platform/representation/src/gestures/DropGesture.js index f2d64024a3..f76d163ad4 100644 --- a/platform/representation/src/gestures/DropGesture.js +++ b/platform/representation/src/gestures/DropGesture.js @@ -54,9 +54,6 @@ define( // ...and broadcast the event. This allows specific // views to have post-drop behavior which depends on // drop position. - // Also broadcast the editableDomainObject to - // avoid race condition against non-editable - // version in EditRepresenter scope.$broadcast( GestureConstants.MCT_DROP_EVENT, id, @@ -93,21 +90,13 @@ define( function drop(e) { var event = (e || {}).originalEvent || e, - id = event.dataTransfer.getData(GestureConstants.MCT_DRAG_TYPE), - domainObjectType = domainObject.getModel().type; + id = event.dataTransfer.getData(GestureConstants.MCT_DRAG_TYPE); // Handle the drop; add the dropped identifier to the // destination domain object's composition, and persist // the change. if (id) { e.preventDefault(); - - //Use scope.apply, drop event is outside digest cycle - scope.$apply(function () { - if (domainObjectType !== 'folder') { - domainObject.getCapability('action').perform('edit'); - } - }); $q.when(action && action.perform()).then(function () { broadcastDrop(id, event); });