diff --git a/changelog.md b/changelog.md index 3503d998c..982cb4cff 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +### 0.12.1 (Minor Release) +* If an item is deleted from the edit item modal, RecordEditor.openEditItemModal will now resolve after the delete item modal is closed with 'deleted' + + ### 0.12.0 (Major Release) #### Misc Changes diff --git a/opal/static/js/opal/controllers/edit_item.js b/opal/static/js/opal/controllers/edit_item.js index 453ab2b4f..cb147b9e9 100644 --- a/opal/static/js/opal/controllers/edit_item.js +++ b/opal/static/js/opal/controllers/edit_item.js @@ -77,10 +77,11 @@ angular.module('opal.controllers').controller( }); }; - $scope.delete = function(result){ - $modalInstance.close(result); - var modal = $modal.open({ - templateUrl: '/templates/modals/delete_item_confirmation.html/', + $scope.delete = function(){ + var deferred = $q.defer(); + $modalInstance.close(deferred.promise); + var deleteModal = $modal.open({ + templateUrl: '/templates/delete_item_confirmation_modal.html', controller: 'DeleteItemConfirmationCtrl', resolve: { item: function() { @@ -88,6 +89,9 @@ angular.module('opal.controllers').controller( } } }); + deleteModal.result.then(function(result){ + deferred.resolve(result) + }); }; // @@ -122,7 +126,7 @@ angular.module('opal.controllers').controller( $scope.undischarge = function() { undischargeMoadal = $modal.open({ - templateUrl: '/templates/modals/undischarge.html/', + templateUrl: '/templates/undischarge_modal.html', controller: 'UndischargeCtrl', resolve: {episode: function(){ return episode } } } diff --git a/opal/static/js/test/edit_item.controller.test.js b/opal/static/js/test/edit_item.controller.test.js index 898279b40..f3dc472bf 100644 --- a/opal/static/js/test/edit_item.controller.test.js +++ b/opal/static/js/test/edit_item.controller.test.js @@ -159,14 +159,40 @@ describe('EditItemCtrl', function (){ it('should open the delete modal', function() { spyOn($modal, 'open'); + $modal.open.and.returnValue({ + result: { + then: function(x){ + x("cancelled"); + } + } + }); $scope.delete(); expect($modal.open).toHaveBeenCalled() var args = $modal.open.calls.mostRecent().args[0]; - expect(args.templateUrl).toEqual('/templates/modals/delete_item_confirmation.html/'); + expect(args.templateUrl).toEqual('/templates/delete_item_confirmation_modal.html'); expect(args.controller).toEqual('DeleteItemConfirmationCtrl'); expect(args.resolve.item()).toEqual(item) }); + it('should return the output of the delete modal', function(){ + spyOn($modal, 'open'); + var promiseResolved = false; + $modal.open.and.returnValue({ + result: { + then: function(x){ + x("cancelled"); + } + } + }); + spyOn($q, "defer").and.returnValue({ + resolve: function(result){ + promiseResolved = result; + } + }); + + $scope.delete("delete"); + expect(promiseResolved).toBe("cancelled"); + }); }); describe('cancel()', function(){