Skip to content

Commit

Permalink
changes record editor.editItemModal to return a promise even if its t…
Browse files Browse the repository at this point in the history
…he output of the delete item confirmation model
  • Loading branch information
fredkingham committed Dec 19, 2018
1 parent b2ba01c commit bc5ef84
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
4 changes: 4 additions & 0 deletions 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
Expand Down
14 changes: 9 additions & 5 deletions opal/static/js/opal/controllers/edit_item.js
Expand Up @@ -77,17 +77,21 @@ 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() {
return item;
}
}
});
deleteModal.result.then(function(result){
deferred.resolve(result)
});
};

//
Expand Down Expand Up @@ -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 } }
}
Expand Down
28 changes: 27 additions & 1 deletion opal/static/js/test/edit_item.controller.test.js
Expand Up @@ -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(){
Expand Down

0 comments on commit bc5ef84

Please sign in to comment.