Permalink
Browse files

decoupled user initiated delete from backend-driven delete

  • Loading branch information...
1 parent eadff71 commit 209bec3e1e097bd3a23125c2d3f46b859239b16f Dan Walkowski committed Sep 30, 2011
Showing with 42 additions and 4 deletions.
  1. +36 −1 apps.html
  2. +1 −1 icongrid.js
  3. +5 −2 index.html
View
@@ -88,6 +88,17 @@
$(document).ready(function() {
apps_datasource = {
+ //important callbacks for updates
+ removeItemFromGridCallback: undefined,
+ setRemovalCallback: function(callback) {
+ removeItemFromGridCallback = callback;
+ },
+
+ addItemToGridCallback: undefined,
+ setAdditionCallback: function(callback) {
+ addItemToGridCallback = callback;
+ },
+
getItemList: function(callback) {
var self = this;
navigator.mozApps.mgmt.list( function(theApps) { self.callback(theApps)});
@@ -97,10 +108,34 @@
navigator.mozApps.mgmt.launch(itemID);
},
- removeItem: function(itemID) {
+ handleWatcher: function(cmd, itemArray) {
+ var i;
+ if (cmd == "add") {
+ for (i=0, i<itemArray.length){
+ addItem(itemArray[i]);
+ }
+ } else if (cmd == "remove"){
+ for (i=0, i<itemArray.length){
+ removeItem(itemArray[i]);
+ }
+ }
+ },
+
+ userRemovedItem: function(itemID) {
+ //this better trigger a call to the update watches, so we can fix the UI
navigator.mozApps.mgmt.uninstall(itemID);
},
+ removeItem: function(itemID) {
+ if (removeItemFromGridCallback == undefined) return;
+ removeItemFromGridCallback(itemID);
+ },
+
+ addItem: function(theItem) {
+ if (addItemToGridCallback == undefined) return;
+ addItemToGridCallback(guid, theItem);
+ },
+
// if all your items have 'itemImgURL' and 'itemTitle' properties, then you don't need to implement these.
// These get called when an item doesn't have the right properties.
// Note that you can pass in data URIs for icons
View
@@ -563,7 +563,7 @@ IconGrid.prototype = {
}
if (confirm("Uninstall " + itemTitle + "?")) {
- self.datasource.removeItem(Base32.decode(guid));
+ self.datasource.userRemovedItem(Base32.decode(guid));
}
self._appRemover.removeClass("showremover");
}
View
@@ -154,11 +154,14 @@
window.open("http://www.google.com/search?q=" + itemID);
},
+ userRemovedItem: function(itemID) {
+ delete this.fruitlist[itemID];
+ this.removeItem(itemID);
+ },
+
//remove the item from the database, and then call the removeItemFromGridCallback with the guid
removeItem: function(itemID) {
if (removeItemFromGridCallback == undefined) return;
-
- delete this.fruitlist[itemID];
removeItemFromGridCallback(itemID);
},

0 comments on commit 209bec3

Please sign in to comment.