Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #29196 from Cwiiis/bug1147786-homescreen-delete-mu…
Browse files Browse the repository at this point in the history
…ltiple-dialogs

Bug 1147786 - Fix being able to show delete-app dialog twice. r=kgrandon
  • Loading branch information
KevinGrandon committed Mar 27, 2015
2 parents 6bbcae6 + ae9472c commit 72d400b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
16 changes: 15 additions & 1 deletion apps/verticalhome/js/app_manager.js
Expand Up @@ -19,6 +19,8 @@
}

AppManager.prototype = {
dialogVisible: false,

get self() {
return this.app;
},
Expand Down Expand Up @@ -57,14 +59,21 @@

switch(e.type) {
case 'removeitem':
if (this.dialogVisible) {
return;
}

this.dialogVisible = true;
if (e.detail.detail.type == 'app') {
var request = navigator.mozApps.mgmt.uninstall(e.detail.app);
request.onsuccess = () => {
e.detail.removeFromGrid();
this.dialogVisible = false;
};
request.onerror = () => {
console.error('Error while trying to remove',
e.detail.name, request.error);
this.dialogVisible = false;
};
break;
}
Expand All @@ -73,7 +82,10 @@
title: {id: 'delete-title', args: nameObj},
body: {id: 'delete-body', args: nameObj},
cancel: {
title: 'cancel'
title: 'cancel',
cb: () => {
this.dialogVisible = false;
}
},
confirm: {
title: 'delete',
Expand All @@ -84,6 +96,8 @@

// handle the real removal asynchronously
this.handleItemRemoval(e.detail);

this.dialogVisible = false;
}
}
});
Expand Down
16 changes: 16 additions & 0 deletions apps/verticalhome/test/unit/app_manager_test.js
Expand Up @@ -35,4 +35,20 @@ suite('app_manager.js > ', function() {
assert.equal(appManager.self, app);
});

test('Can\'t show delete dialog more than once', function() {
var showDialogSpy = sinon.spy();
sinon.stub(window, 'ConfirmDialogHelper').returns({ show: showDialogSpy });

var removeItemEvent = new CustomEvent('removeitem',
{ detail:
{ detail: { type: null } }
});

appManager.handleEvent(removeItemEvent);
assert(appManager.dialogVisible);

appManager.handleEvent(removeItemEvent);
assert(showDialogSpy.calledOnce);
});

});

0 comments on commit 72d400b

Please sign in to comment.