diff options
author | dave@33eels.com <dave@33eels.com@4eb1ac78-321c-0410-a911-ec516a8615a5> | 2009-03-10 20:18:37 (GMT) |
---|---|---|
committer | dave@33eels.com <dave@33eels.com@4eb1ac78-321c-0410-a911-ec516a8615a5> | 2009-03-10 20:18:37 (GMT) |
commit | 5065035ec79dd89de01b81fbecccd5bb87e7bf83 (patch) | |
tree | 22e628b53a155c79aa9fb7f26667cbdc2de167ce | |
parent | d6624618bb4c6826ec9c37bb5c3d078b24f6b149 (diff) |
Added check mark on publish menu if extension is already in collection.
Clicking the item again will remove the check mark and unpublish the item from that feed.
git-svn-id: http://svn.mozilla.org/addons/trunk@23072 4eb1ac78-321c-0410-a911-ec516a8615a5
-rw-r--r-- | bandwagon/components/bandwagon-service.js | 7 | ||||
-rw-r--r-- | bandwagon/content/scripts/rpc/constants.js | 1 | ||||
-rw-r--r-- | bandwagon/content/scripts/rpc/net.js | 8 | ||||
-rw-r--r-- | bandwagon/content/scripts/rpc/service.js | 29 | ||||
-rw-r--r-- | bandwagon/content/ui/bindings/bandwagon.xml | 22 | ||||
-rw-r--r-- | bandwagon/content/ui/overlays/extensionsOverlayController.js | 30 |
6 files changed, 91 insertions, 6 deletions
diff --git a/bandwagon/components/bandwagon-service.js b/bandwagon/components/bandwagon-service.js index c82a334..0c1201e 100644 --- a/bandwagon/components/bandwagon-service.js +++ b/bandwagon/components/bandwagon-service.js @@ -635,6 +635,13 @@ BandwagonService.prototype = { bandwagonService._collectionFactory.commitServiceDocument(bandwagonService._serviceDocument); }, + removeAddonFromCollection: function(guid, collection) + { + Bandwagon.Logger.debug("In removeAddonFromCollection()"); + + this._service.removeAddonFromCollection(guid, collection); + }, + deleteCollection: function(collection) { this._collectionFactory.deleteCollection(collection); diff --git a/bandwagon/content/scripts/rpc/constants.js b/bandwagon/content/scripts/rpc/constants.js index 6b40dc5..bf7fd8f 100644 --- a/bandwagon/content/scripts/rpc/constants.js +++ b/bandwagon/content/scripts/rpc/constants.js @@ -43,6 +43,7 @@ Bandwagon.RPC.Constants = new function() this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_GET_COLLECTION_COMPLETE = 200; this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_SHARE_TO_EMAIL_COMPLETE = 300; this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_PUBLISH_COMPLETE = 400; + this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_REMOVE_ADDON_FROM_COLLECTION_COMPLETE = 500; // xhr layer constants diff --git a/bandwagon/content/scripts/rpc/net.js b/bandwagon/content/scripts/rpc/net.js index d6ae3e9..28c3340 100644 --- a/bandwagon/content/scripts/rpc/net.js +++ b/bandwagon/content/scripts/rpc/net.js @@ -260,10 +260,16 @@ Bandwagon.RPC.Net.prototype.setMethod = function(method) { this._method = 'POST'; } - else + else if (method == 'DELETE') + { + this._method = 'DELETE'; + } + else { this._method = 'GET'; } + + this._method = method; } Bandwagon.RPC.Net.prototype.setCredentials = function(username, password) diff --git a/bandwagon/content/scripts/rpc/service.js b/bandwagon/content/scripts/rpc/service.js index 470384e..0d7e661 100644 --- a/bandwagon/content/scripts/rpc/service.js +++ b/bandwagon/content/scripts/rpc/service.js @@ -120,6 +120,10 @@ Bandwagon.RPC.Service = function() rpcnet.setMethod("POST"); rpcnet.setPostData(data); } + else if (method == "DELETE") + { + rpcnet.setMethod("DELETE"); + } else { rpcnet.setMethod("GET"); @@ -281,6 +285,31 @@ Bandwagon.RPC.Service.prototype.unsubscribeCollection = function(collection, cal } */ +Bandwagon.RPC.Service.prototype.removeAddonFromCollection = function(guid, collection, callback) +{ + var service = this; + + if (guid.substring(0,1) == "{") + { + guid = guid.substring(1, guid.length-2); + } + + Bandwagon.Logger.debug("Bandwagon.RPC.Service.removeAddonFromCollection: extension.guid = '" + guid + "', collection = '" + collection.resourceURL); + + var internalCallback = function(event) + { + // don't need to do anything here + if (callback) + callback(event); + } + + this.rpcSend(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_REMOVE_ADDON_FROM_COLLECTION_COMPLETE, + internalCallback, + collection.addonsResourceURL + guid, + "DELETE", + null); +} + Bandwagon.RPC.Service.prototype.publishToCollection = function(extension, collection, personalNote, callback) { var service = this; diff --git a/bandwagon/content/ui/bindings/bandwagon.xml b/bandwagon/content/ui/bindings/bandwagon.xml index 1c05218..e858785 100644 --- a/bandwagon/content/ui/bindings/bandwagon.xml +++ b/bandwagon/content/ui/bindings/bandwagon.xml @@ -653,11 +653,16 @@ { // populate the collections menu - function createCollectionCallbackFunction(collection) + function createAddToCollectionCallbackFunction(collection) { return function() { Bandwagon.Controller.ExtensionsOverlay.doPublishToCollection(collection); } } + function createRemoveFromCollectionCallbackFunction(collection) + { + return function() { Bandwagon.Controller.ExtensionsOverlay.doRemoveFromCollection(collection); } + } + for (var i=0; i<this.writableCollections.length; i++) { var collection = this.writableCollections[i]; @@ -665,12 +670,23 @@ if (document.getAnonymousElementByAttribute(this, "anonid", "bandwagon-collection-" + collection.resourceURL)) continue; - var callback = createCollectionCallbackFunction(collection); + var callbackAdd = createAddToCollectionCallbackFunction(collection); + var callbackRemove = createRemoveFromCollectionCallbackFunction(collection); var elemWritableCollection = document.createElementNS(XULNS, "menuitem"); elemWritableCollection.setAttribute("label", (collection.name?collection.name:collection.resourceURL)); elemWritableCollection.setAttribute("anonid", "bandwagon-collection-" + collection.resourceURL); - elemWritableCollection.addEventListener("command", callback, true); + + if (collection.__containsCurrentlySelectedExtension) + { + elemWritableCollection.setAttribute("checked", "true"); + elemWritableCollection.setAttribute("autocheck", "false"); + elemWritableCollection.addEventListener("command", callbackRemove, true); + } + else + { + elemWritableCollection.addEventListener("command", callbackAdd, true); + } elemWritableCollectionsPopup.insertBefore(elemWritableCollection, elemWritableCollectionSeparator); } diff --git a/bandwagon/content/ui/overlays/extensionsOverlayController.js b/bandwagon/content/ui/overlays/extensionsOverlayController.js index 2077dcb..103d8f9 100644 --- a/bandwagon/content/ui/overlays/extensionsOverlayController.js +++ b/bandwagon/content/ui/overlays/extensionsOverlayController.js @@ -131,6 +131,15 @@ Bandwagon.Controller.ExtensionsOverlay.doPublishToCollection = function(collecti Bandwagon.Controller.ExtensionsOverlay._openPublishDialog(params); } +Bandwagon.Controller.ExtensionsOverlay.doRemoveFromCollection = function(collection) +{ + var extension = Bandwagon.Controller.ExtensionsOverlay._getSelectedExtension(); + + Bandwagon.Logger.debug("In Bandwagon.Controller.ExtensionsOverlay.doRemoveFromCollection() with collection = '" + collection.toString() + "' and extension: name = '" + extension.name + "', guid = '" + extension.guid + "'"); + + bandwagonService.removeAddonFromCollection(extension.guid, collection); +} + Bandwagon.Controller.ExtensionsOverlay.doShareToEmail = function(emailAddress) { Bandwagon.Logger.debug("In Bandwagon.Controller.ExtensionsOverlay.doShareToEmail() with email = '" + emailAddress + "'"); @@ -257,12 +266,29 @@ Bandwagon.Controller.ExtensionsOverlay._getWritableCollections = function() { var writableCollections = []; + var extension = Bandwagon.Controller.ExtensionsOverlay._getSelectedExtension(); + for (var id in bandwagonService.collections) { + var collection = bandwagonService.collections[id]; + //if (1 || (bandwagonService.collections[id].writable && !bandwagonService.collections[id].preview)) - if (bandwagonService.collections[id].writable) + + if (collection.writable) { - writableCollections.push(bandwagonService.collections[id]); + // Check if extension is in collection + collection.__containsCurrentlySelectedExtension = false; + + for (var id in collection.addons) + { + if (extension.guid == collection.addons[id].guid) + { + collection.__containsCurrentlySelectedExtension = true; + break; + } + } + + writableCollections.push(collection); } } |