Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordave@33eels.com <dave@33eels.com@4eb1ac78-321c-0410-a911-ec516a8615a5>2009-03-09 14:41:54 (GMT)
committer dave@33eels.com <dave@33eels.com@4eb1ac78-321c-0410-a911-ec516a8615a5>2009-03-09 14:41:54 (GMT)
commit05f76771713b5c41c86279c047250db87d2cb75f (patch)
treea275d18ec99be00268704bb6bd4b0e1efab07dfb
parent6c4e1783070bd906c455cd69a835d917bd7438a0 (diff)
- updated for new publish to collection / publish to email API
- offline caching of api resource urls git-svn-id: http://svn.mozilla.org/addons/trunk@23015 4eb1ac78-321c-0410-a911-ec516a8615a5
-rw-r--r--bandwagon/components/bandwagon-service.js38
-rw-r--r--bandwagon/content/scripts/bandwagon.js2
-rw-r--r--bandwagon/content/scripts/factory/collectionFactory.js73
-rw-r--r--bandwagon/content/scripts/model/collection.js20
-rw-r--r--bandwagon/content/scripts/model/serviceDocument.js10
-rw-r--r--bandwagon/content/scripts/rpc/constants.js2
-rw-r--r--bandwagon/content/scripts/rpc/service.js57
-rw-r--r--bandwagon/content/ui/bindings/bandwagon.xml4
-rw-r--r--bandwagon/content/ui/overlays/extensionsOverlayController.js9
-rw-r--r--bandwagon/content/ui/publishController.js7
10 files changed, 170 insertions, 52 deletions
diff --git a/bandwagon/components/bandwagon-service.js b/bandwagon/components/bandwagon-service.js
index 3d3d288..c82a334 100644
--- a/bandwagon/components/bandwagon-service.js
+++ b/bandwagon/components/bandwagon-service.js
@@ -80,6 +80,7 @@ BandwagonService.prototype = {
_collectionFactory: null,
_collectionUpdateTimer: null,
_bwObserver: null,
+ _serviceDocument: null,
init: function()
{
@@ -133,6 +134,15 @@ BandwagonService.prototype = {
Bandwagon.Logger.debug("opened collection from storage: " + id);
}
+ this._serviceDocument = this._collectionFactory.openServiceDocument();
+ this._service._serviceDocument = this._serviceDocument;
+
+ if (!this._serviceDocument)
+ {
+ // no service document in storage, we never had it or we've lost it - go fetch it
+ this.updateCollectionsList();
+ }
+
// start the update timer
this._bwObserver =
@@ -274,7 +284,10 @@ BandwagonService.prototype = {
}
else
{
- var collections = event.serviceDocument.collections;
+ bandwagonService._serviceDocument = event.serviceDocument;
+ bandwagonService._service._serviceDocument = bandwagonService._serviceDocument;
+
+ var collections = bandwagonService._serviceDocument.collections;
Bandwagon.Logger.debug("Updating collections list: saw " + collections.length + " collections");
@@ -395,6 +408,11 @@ BandwagonService.prototype = {
{
Bandwagon.Logger.debug("Updating collections list...");
+ this.updateServiceDocument();
+ },
+
+ updateServiceDocument: function()
+ {
if (!this.isAMOAuthenticated())
{
Bandwagon.Logger.debug("Not authenticated in AMO");
@@ -528,9 +546,6 @@ BandwagonService.prototype = {
//this._addDefaultCollection(Bandwagon.DEFAULT_COLLECTION1_URL, Bandwagon.DEFAULT_COLLECTION1_NAME);
//this._addDefaultCollection("http://www.33eels.com/clients/briks/bandwagon/testcollection.xml", "test collection");
- // get the user's list of collections
- this.updateCollectionsList();
-
/** OBSOLETE
// check for cookie to see if we have to add a collection like that
var addCollectionCookieValue = Bandwagon.Util.getCookie(Bandwagon.MAGIC_ADD_COLLECTION_COOKIE_HOST, Bandwagon.MAGIC_ADD_COLLECTION_COOKIE_NAME);
@@ -615,6 +630,9 @@ BandwagonService.prototype = {
this.commit(collection);
}
+
+ if (bandwagonService._serviceDocument)
+ bandwagonService._collectionFactory.commitServiceDocument(bandwagonService._serviceDocument);
},
deleteCollection: function(collection)
@@ -778,6 +796,10 @@ BandwagonService.prototype = {
try
{
this._storageConnection.executeSimpleSQL(
+ "CREATE TABLE IF NOT EXISTS serviceDocument "
+ + "(emailResourceURL TEXT NOT NULL)"
+ );
+ this._storageConnection.executeSimpleSQL(
"CREATE TABLE IF NOT EXISTS collections "
+ "(id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "url TEXT NOT NULL UNIQUE, "
@@ -789,7 +811,13 @@ BandwagonService.prototype = {
+ "showNotifications INTEGER NOT NULL, "
+ "autoPublish INTEGER NOT NULL, "
+ "active INTEGER NOT NULL DEFAULT 1, "
- + "addonsPerPage INTEGER NOT NULL)"
+ + "addonsPerPage INTEGER NOT NULL, "
+ + "creator TEXT, "
+ + "listed INTEGER NOT NULL DEFAULT 1, "
+ + "writable INTEGER NOT NULL DEFAULT 0, "
+ + "subscribed INTEGER NOT NULL DEFAULT 1, "
+ + "lastModified INTEGER, "
+ + "addonsResourceURL TEXT)"
);
this._storageConnection.executeSimpleSQL(
"CREATE TABLE IF NOT EXISTS collectionsAddons "
diff --git a/bandwagon/content/scripts/bandwagon.js b/bandwagon/content/scripts/bandwagon.js
index eb53f6b..24ba4c5 100644
--- a/bandwagon/content/scripts/bandwagon.js
+++ b/bandwagon/content/scripts/bandwagon.js
@@ -54,5 +54,5 @@ Bandwagon.AMO_AUTH_COOKIE_NAME = "AMOv3";
//Bandwagon.MAGIC_ADD_COLLECTION_COOKIE_HOST = "www.33eels.com"; // TODO
//Bandwagon.MAGIC_ADD_COLLECTION_COOKIE_NAME = "bandwagon_addcollection";
-Bandwagon.COMMIT_NOW = 1; // 1=commit on the fly. 0=commit when browser exit.
+Bandwagon.COMMIT_NOW = 0; // 1=commit on the fly. 0=commit when browser exit.
diff --git a/bandwagon/content/scripts/factory/collectionFactory.js b/bandwagon/content/scripts/factory/collectionFactory.js
index b237d19..7fab344 100644
--- a/bandwagon/content/scripts/factory/collectionFactory.js
+++ b/bandwagon/content/scripts/factory/collectionFactory.js
@@ -40,6 +40,62 @@ Bandwagon.Factory.CollectionFactory = function(connection)
this.connection = connection;
}
+Bandwagon.Factory.CollectionFactory.prototype.openServiceDocument = function()
+{
+ if (!this.connection)
+ return null;
+
+ var statement = this.connection.createStatement("SELECT * FROM serviceDocument LIMIT 1");
+
+ var serviceDocument = null;
+
+ try
+ {
+ statement.execute();
+
+ while (statement.executeStep())
+ {
+ serviceDocument = new this.Bandwagon.Model.ServiceDocument();
+ serviceDocument.emailResourceURL = statement.getUTF8String(0);
+ }
+ }
+ finally
+ {
+ statement.reset();
+ }
+
+ return serviceDocument;
+}
+
+Bandwagon.Factory.CollectionFactory.prototype.commitServiceDocument = function(serviceDocument)
+{
+ if (!this.connection)
+ return null;
+
+ var statement1 = this.connection.createStatement("DELETE FROM serviceDocument");
+
+ try
+ {
+ statement1.execute();
+ }
+ finally
+ {
+ statement1.reset();
+ }
+
+ var statement2 = this.connection.createStatement("INSERT INTO serviceDocument VALUES (?1)");
+
+ try
+ {
+ statement2.bindUTF8StringParameter(0, serviceDocument.emailResourceURL);
+ statement2.execute();
+ }
+ finally
+ {
+ statement2.reset();
+ }
+}
+
Bandwagon.Factory.CollectionFactory.prototype.newCollection = function()
{
return new this.Bandwagon.Model.Collection();
@@ -112,7 +168,7 @@ Bandwagon.Factory.CollectionFactory.prototype.commitCollection = function(collec
if (!this.connection)
return;
- var statement = this.connection.createStatement("REPLACE INTO collections VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)");
+ var statement = this.connection.createStatement("REPLACE INTO collections VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17)");
try
{
@@ -127,6 +183,12 @@ Bandwagon.Factory.CollectionFactory.prototype.commitCollection = function(collec
statement.bindInt32Parameter(8, (collection.autoPublish?1:0));
statement.bindInt32Parameter(9, (collection.active?1:0));
statement.bindInt32Parameter(10, collection.addonsPerPage);
+ statement.bindUTF8StringParameter(11, collection.creator);
+ statement.bindInt32Parameter(12, collection.listed);
+ statement.bindInt32Parameter(13, collection.writable);
+ statement.bindInt32Parameter(14, collection.subscribed);
+ (collection.lastModified == null?statement.bindNullParameter(15):statement.bindInt32Parameter(15, collection.lastModified.getTime()/1000));
+ statement.bindUTF8StringParameter(16, collection.addonsResourceURL);
statement.execute();
}
@@ -202,6 +264,15 @@ Bandwagon.Factory.CollectionFactory.prototype._openCollectionFromRS = function(r
collection.autoPublish = (resultset.getInt32(8)==1?true:false);
collection.active = (resultset.getInt32(9)==1?true:false);
collection.addonsPerPage = resultset.getInt32(10);
+ collection.creator = resultset.getUTF8String(11);
+ collection.listed = resultset.getInt32(12);
+ collection.writable = resultset.getInt32(13);
+ collection.subscribed = resultset.getInt32(14);
+
+ if (!resultset.getIsNull(15))
+ collection.lastModified = new Date(resultset.getInt32(15)*1000);
+
+ collection.addonsResourceURL = resultset.getUTF8String(16);
return collection;
}
diff --git a/bandwagon/content/scripts/model/collection.js b/bandwagon/content/scripts/model/collection.js
index ba949bd..ea663ab 100644
--- a/bandwagon/content/scripts/model/collection.js
+++ b/bandwagon/content/scripts/model/collection.js
@@ -40,6 +40,7 @@ Bandwagon.Model.Collection = function()
this.storageID = -1;
this.resourceURL = "";
+ this.addonsResourceURL = "";
this.name = "";
this.description = "";
@@ -58,8 +59,8 @@ Bandwagon.Model.Collection = function()
this.active = true;
this.addonsPerPage = this.Bandwagon.DEFAULT_ADDONS_PER_PAGE;
- this.preview = false;
- this.editable = false;
+ //this.preview = false;
+
this.status = this.STATUS_NEW;
this.addons = {};
@@ -166,6 +167,21 @@ Bandwagon.Model.Collection.prototype.equals = function(other)
Bandwagon.Model.Collection.prototype.unserialize = function(xcollection)
{
+ var xmlns = new Namespace('http://www.w3.org/XML/1998/namespace');
+ var baseURL = xcollection.@xmlns::base.toString();
+
+ //this.resourceURL = baseURL + "/" + xcollection.attribute("href").toString();
+
+ this.name = xcollection.attribute("name").toString();
+ this.description = xcollection.attribute("description").toString();
+ this.creator = xcollection.attribute("creator").toString();
+ this.listed = (xcollection.attribute("listed").toString()=="yes"?true:false);
+ this.writable = (xcollection.attribute("writable").toString()=="yes"?true:false);
+ this.subscribed = (xcollection.attribute("subscribed").toString()=="yes"?true:false);
+ this.lastModified = this.Bandwagon.Util.ISO8601toDate(xcollection.attribute("lastmodified").toString());
+
+ //this.addonsResourceURL = baseURL + "/" + xcollection.addons.attribute("href").toString();
+
for each (var xaddon in xcollection.addons.addon)
{
var addon = new this.Bandwagon.Model.Addon();
diff --git a/bandwagon/content/scripts/model/serviceDocument.js b/bandwagon/content/scripts/model/serviceDocument.js
index 2cd8aff..dc30c1c 100644
--- a/bandwagon/content/scripts/model/serviceDocument.js
+++ b/bandwagon/content/scripts/model/serviceDocument.js
@@ -38,6 +38,8 @@ Bandwagon.Model.ServiceDocument = function()
{
this.Bandwagon = Bandwagon;
+ this.emailResourceURL = "";
+
this.collections = [];
}
@@ -46,6 +48,10 @@ Bandwagon.Model.ServiceDocument.prototype.unserialize = function(xsharing)
var xmlns = new Namespace('http://www.w3.org/XML/1998/namespace');
var baseURL = xsharing.@xmlns::base.toString();
+ // resource urls
+
+ this.emailResourceURL = baseURL + "/" + xsharing.email.attribute("href").toString();
+
// collections
for each (var xcollection in xsharing.collections.collection)
@@ -53,7 +59,7 @@ Bandwagon.Model.ServiceDocument.prototype.unserialize = function(xsharing)
var collection = new this.Bandwagon.Model.Collection();
collection.Bandwagon = this.Bandwagon;
- collection.resourceURL = baseURL + "/" + xcollection.attribute("href");
+ collection.resourceURL = baseURL + "/" + xcollection.attribute("href").toString();
collection.name = xcollection.attribute("name").toString();
collection.description = xcollection.attribute("description").toString();
@@ -63,6 +69,8 @@ Bandwagon.Model.ServiceDocument.prototype.unserialize = function(xsharing)
collection.subscribed = (xcollection.attribute("subscribed").toString()=="yes"?true:false);
collection.lastModified = this.Bandwagon.Util.ISO8601toDate(xcollection.attribute("lastmodified").toString());
+ collection.addonsResourceURL = baseURL + "/" + xcollection.addons.attribute("href").toString();
+
this.collections.push(collection);
}
}
diff --git a/bandwagon/content/scripts/rpc/constants.js b/bandwagon/content/scripts/rpc/constants.js
index d0d36f4..6b40dc5 100644
--- a/bandwagon/content/scripts/rpc/constants.js
+++ b/bandwagon/content/scripts/rpc/constants.js
@@ -38,11 +38,11 @@
Bandwagon.RPC.Constants = new function()
{
this.BANDWAGON_RPC_SERVICE_DOCUMENT = "https://bandwagon.stage.mozilla.com/en-US/firefox/api/1.3/sharing";
- this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_SHARE_TO_EMAIL_ACTION = "firefox/api/recommend_email";
this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_GET_SERVICE_DOCUMENT_COMPLETE = 100;
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;
// xhr layer constants
diff --git a/bandwagon/content/scripts/rpc/service.js b/bandwagon/content/scripts/rpc/service.js
index df105b5..470384e 100644
--- a/bandwagon/content/scripts/rpc/service.js
+++ b/bandwagon/content/scripts/rpc/service.js
@@ -46,6 +46,7 @@ Bandwagon.RPC.Service = function()
// private instance variables
this._observers = new Array();
this._logger = null;
+ this._serviceDocument = null;
this._serviceRootURL = this.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_DOCUMENT;
this.rpcComplete = function(rpcnet, result, response, type, callback)
@@ -282,15 +283,27 @@ Bandwagon.RPC.Service.prototype.unsubscribeCollection = function(collection, cal
Bandwagon.RPC.Service.prototype.publishToCollection = function(extension, collection, personalNote, callback)
{
+ var service = this;
+
Bandwagon.Logger.debug("Bandwagon.RPC.Service.publishToCollection: extension.guid = '" + extension.guid + "', extension.name = '" + extension.name + "', collection = '" + collection.resourceURL + "', personalNote = '" + personalNote + "'");
- Bandwagon.Logger.debug("Bandwagon.RPC.Service.publishToCollection: TBD");
- // TODO
+ var data = {
+ "guid": extension.guid,
+ "comments": personalNote
+ };
- if (callback)
+ var internalCallback = function(event)
{
- setTimeout(function() { callback(new this.Bandwagon.RPC.Event()) }, 2000);
+ // don't need to do anything here
+ if (callback)
+ callback(event);
}
+
+ this.rpcSend(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_PUBLISH_COMPLETE,
+ internalCallback,
+ collection.addonsResourceURL,
+ "POST",
+ data);
}
Bandwagon.RPC.Service.prototype.shareToEmail = function(extension, emailAddress, personalNote, callback)
@@ -299,7 +312,7 @@ Bandwagon.RPC.Service.prototype.shareToEmail = function(extension, emailAddress,
Bandwagon.Logger.debug("Bandwagon.RPC.Service.shareToEmail: extension.guid = '" + extension.guid + "', extension.name = '" + extension.name + "', emailAddress = '" + emailAddress + "', personalNote = '" + personalNote + "'");
- if (!extension.guid || extension.guid == "" || !emailAddress || emailAddress == "")
+ if (!extension.guid || extension.guid == "" || !emailAddress || emailAddress == "" || service._serviceDocument == null)
{
if (callback)
callback(new this.Bandwagon.RPC.Event());
@@ -307,48 +320,22 @@ Bandwagon.RPC.Service.prototype.shareToEmail = function(extension, emailAddress,
return;
}
- var data = null;
-
var data = {
"guid": extension.guid,
- "emails[0]": emailAddress,
- "message": personalNote
+ "to": emailAddress,
+ "comments": personalNote
};
var internalCallback = function(event)
{
- if (!event.isError())
- {
- // check for service level errors
-
- var response = event.getData();
-
- // success has a body of "<success/>"
- // failure has a body e.g. "<error>Add-on not found!</error>"
-
- if (response.name() == "success")
- {
- // all ok
- }
- else if (response.name() == "error")
- {
- // "expected" error -- update the event to indicate this error
- event.setError(new service.Bandwagon.RPC.Error(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR, response.text().toString()));
- }
- else
- {
- // unknown response -- update the event to indicate an error
- event.setError(new service.Bandwagon.RPC.Error(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_UNEXPECTED_XML));
- }
- }
-
+ // don't need to do anything here
if (callback)
callback(event);
}
this.rpcSend(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_SHARE_TO_EMAIL_COMPLETE,
internalCallback,
- service.Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_SHARE_TO_EMAIL_ACTION,
+ service._serviceDocument.emailResourceURL,
"POST",
data);
}
diff --git a/bandwagon/content/ui/bindings/bandwagon.xml b/bandwagon/content/ui/bindings/bandwagon.xml
index 47ef4aa..1c05218 100644
--- a/bandwagon/content/ui/bindings/bandwagon.xml
+++ b/bandwagon/content/ui/bindings/bandwagon.xml
@@ -86,7 +86,7 @@
onset="this.setAttribute('preview', val);"
/>
- <property name="editable"
+ <property name="writable"
onget="return !document.getAnonymousElementByAttribute(this, 'anonid', 'star').collapsed;"
onset="document.getAnonymousElementByAttribute(this, 'anonid', 'star').collapsed = !val;"
/>
@@ -104,7 +104,7 @@
this.name = (collection.name && collection.name !=""?collection.name:collection.resourceURL);
this.url = collection.resourceURL;
this.preview = collection.preview;
- this.editable = collection.editable;
+ this.writable = collection.writable;
this.unread = collection.getUnreadAddons().length;
]]>
</body>
diff --git a/bandwagon/content/ui/overlays/extensionsOverlayController.js b/bandwagon/content/ui/overlays/extensionsOverlayController.js
index d4c89f5..2077dcb 100644
--- a/bandwagon/content/ui/overlays/extensionsOverlayController.js
+++ b/bandwagon/content/ui/overlays/extensionsOverlayController.js
@@ -115,7 +115,7 @@ Bandwagon.Controller.ExtensionsOverlay.init = function()
}
}
-Bandwagon.Controller.ExtensionsOverlay.doPublishToCollection = function(collections)
+Bandwagon.Controller.ExtensionsOverlay.doPublishToCollection = function(collection)
{
Bandwagon.Logger.debug("In Bandwagon.Controller.ExtensionsOverlay.doPublishToCollection() with collection = '" + collection.toString() + "'");
@@ -257,11 +257,12 @@ Bandwagon.Controller.ExtensionsOverlay._getWritableCollections = function()
{
var writableCollections = [];
- for (var id in bandwagonService.Collections)
+ for (var id in bandwagonService.collections)
{
- if (1 || (bandwagonService.Collections[id].editable && !bandwagonService.Collections[id].preview))
+ //if (1 || (bandwagonService.collections[id].writable && !bandwagonService.collections[id].preview))
+ if (bandwagonService.collections[id].writable)
{
- writableCollections.push(bandwagonService.Collections[id]);
+ writableCollections.push(bandwagonService.collections[id]);
}
}
diff --git a/bandwagon/content/ui/publishController.js b/bandwagon/content/ui/publishController.js
index 05bc8e6..fe24b04 100644
--- a/bandwagon/content/ui/publishController.js
+++ b/bandwagon/content/ui/publishController.js
@@ -179,6 +179,13 @@ Bandwagon.Controller.Publish.finished = function(event)
bandwagonService.addPreviouslySharedEmailAddress(document.getElementById("email-address").value);
}
+ if (Bandwagon.Controller.Publish.publishType == Bandwagon.Controller.Publish.TYPE_COLLECTION)
+ {
+ bandwagonService.forceCheckForUpdates(Bandwagon.Controller.Publish.publishDestination);
+ }
+
+ bandwagonService
+
document.getElementById("bandwagon-publish").cancelDialog();
}