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-17 19:09:43 (GMT)
committer dave@33eels.com <dave@33eels.com@4eb1ac78-321c-0410-a911-ec516a8615a5>2009-03-17 19:09:43 (GMT)
commit4e717e4eeb3d8ab68eb1ef317ff48c4bcfb95a37 (patch)
tree181b2fdeba8327b3517112e867ab64e0f726e53c
parent2dd8d7a140e390e4e88f66e11b43053d5a58199c (diff)
Work on settings dialog (in particular auto-publish).
git-svn-id: http://svn.mozilla.org/addons/trunk@23445 4eb1ac78-321c-0410-a911-ec516a8615a5
-rw-r--r--bandwagon/components/bandwagon-service.js46
-rw-r--r--bandwagon/content/scripts/factory/collectionFactory.js4
-rw-r--r--bandwagon/content/scripts/model/collection.js5
-rw-r--r--bandwagon/content/scripts/model/serviceDocument.js2
-rw-r--r--bandwagon/content/scripts/rpc/constants.js1
-rw-r--r--bandwagon/content/scripts/rpc/service.js49
-rw-r--r--bandwagon/content/ui/settings.xul14
-rw-r--r--bandwagon/content/ui/settingsController.js89
-rw-r--r--bandwagon/locale/en-US/settings.properties4
9 files changed, 197 insertions, 17 deletions
diff --git a/bandwagon/components/bandwagon-service.js b/bandwagon/components/bandwagon-service.js
index daf9c1d..7ddb6b6 100644
--- a/bandwagon/components/bandwagon-service.js
+++ b/bandwagon/components/bandwagon-service.js
@@ -291,13 +291,13 @@ BandwagonService.prototype = {
Bandwagon.Logger.debug("Updating collections list: saw " + collections.length + " collections");
- for (var i=0; i<bandwagonService.collections.length; i++)
+ for (var id in bandwagonService.collections)
{
var isStaleCollection = true;
- for (var j=0; j<collections.length; j++)
+ for (var jd in collections)
{
- if (bandwagonService.collections[i].equals(collections[j]))
+ if (bandwagonService.collections[id].equals(collections[jd]))
{
isStaleCollection = false;
break;
@@ -306,15 +306,15 @@ BandwagonService.prototype = {
if (isStaleCollection)
{
- Bandwagon.Logger.debug("Updating collections list: removing stale collection: " + bandwagonService.collections[i].toString());
+ Bandwagon.Logger.debug("Updating collections list: removing stale collection: " + bandwagonService.collections[id].toString());
- bandwagonService.deleteCollection(bandwagonService.collections[i]);
+ bandwagonService.deleteCollection(bandwagonService.collections[id]);
}
}
- for (var i=0; i<collections.length; i++)
+ for (var id in collections)
{
- var collection = collections[i];
+ var collection = collections[id];
if (bandwagonService.collections[collection.resourceURL])
{
@@ -339,7 +339,6 @@ BandwagonService.prototype = {
}
},
-
_notifyCollectionUpdateObservers: function(collection)
{
Bandwagon.Logger.debug("Notifying collection update observers");
@@ -642,6 +641,34 @@ BandwagonService.prototype = {
this._service.removeAddonFromCollection(guid, collection);
},
+ newCollection: function(collection, callback)
+ {
+ Bandwagon.Logger.debug("In newCollection()");
+
+ /*
+ var internalCallback = function(event)
+ {
+ if (!event.isError())
+ {
+ var collection = event.collection;
+
+ bandwagonService.collections[collection.resourceURL] = collection;
+ //bandwagonService._notifyCollectionUpdateObservers(collection);
+ bandwagonService._notifyListChangeObservers();
+ }
+
+ if (callback)
+ {
+ callback(event);
+ }
+ }
+
+ this._service.newCollection(collection, internalCallback);
+ */
+
+ this._service.newCollection(collection, callback);
+ },
+
deleteCollection: function(collection)
{
this._collectionFactory.deleteCollection(collection);
@@ -817,7 +844,8 @@ BandwagonService.prototype = {
{
this._storageConnection.executeSimpleSQL(
"CREATE TABLE IF NOT EXISTS serviceDocument "
- + "(emailResourceURL TEXT NOT NULL)"
+ + "(emailResourceURL TEXT NOT NULL, "
+ + "collectionListResourceURL TEXT NOT NULL)"
);
this._storageConnection.executeSimpleSQL(
"CREATE TABLE IF NOT EXISTS collections "
diff --git a/bandwagon/content/scripts/factory/collectionFactory.js b/bandwagon/content/scripts/factory/collectionFactory.js
index 7fab344..a6b59ac 100644
--- a/bandwagon/content/scripts/factory/collectionFactory.js
+++ b/bandwagon/content/scripts/factory/collectionFactory.js
@@ -57,6 +57,7 @@ Bandwagon.Factory.CollectionFactory.prototype.openServiceDocument = function()
{
serviceDocument = new this.Bandwagon.Model.ServiceDocument();
serviceDocument.emailResourceURL = statement.getUTF8String(0);
+ serviceDocument.collectionListResourceURL = statement.getUTF8String(1);
}
}
finally
@@ -83,11 +84,12 @@ Bandwagon.Factory.CollectionFactory.prototype.commitServiceDocument = function(s
statement1.reset();
}
- var statement2 = this.connection.createStatement("INSERT INTO serviceDocument VALUES (?1)");
+ var statement2 = this.connection.createStatement("INSERT INTO serviceDocument VALUES (?1, ?2)");
try
{
statement2.bindUTF8StringParameter(0, serviceDocument.emailResourceURL);
+ statement2.bindUTF8StringParameter(1, serviceDocument.collectionListResourceURL);
statement2.execute();
}
finally
diff --git a/bandwagon/content/scripts/model/collection.js b/bandwagon/content/scripts/model/collection.js
index ea663ab..a29df57 100644
--- a/bandwagon/content/scripts/model/collection.js
+++ b/bandwagon/content/scripts/model/collection.js
@@ -152,6 +152,11 @@ Bandwagon.Model.Collection.prototype.hasAddon = function()
return false;
}
+Bandwagon.Model.Collection.prototype.getNicknameFromName = function()
+{
+ return this.name.replace(/\W/g, "_");
+}
+
Bandwagon.Model.Collection.prototype.toString = function()
{
return this.name + " (" + this.resourceURL + ")";
diff --git a/bandwagon/content/scripts/model/serviceDocument.js b/bandwagon/content/scripts/model/serviceDocument.js
index dc30c1c..70ae5b3 100644
--- a/bandwagon/content/scripts/model/serviceDocument.js
+++ b/bandwagon/content/scripts/model/serviceDocument.js
@@ -39,6 +39,7 @@ Bandwagon.Model.ServiceDocument = function()
this.Bandwagon = Bandwagon;
this.emailResourceURL = "";
+ this.collectionListResourceURL = "";
this.collections = [];
}
@@ -51,6 +52,7 @@ Bandwagon.Model.ServiceDocument.prototype.unserialize = function(xsharing)
// resource urls
this.emailResourceURL = baseURL + "/" + xsharing.email.attribute("href").toString();
+ this.collectionListResourceURL = baseURL + "/" + xsharing.collections.attribute("href").toString();
// collections
diff --git a/bandwagon/content/scripts/rpc/constants.js b/bandwagon/content/scripts/rpc/constants.js
index bf7fd8f..7ecc85e 100644
--- a/bandwagon/content/scripts/rpc/constants.js
+++ b/bandwagon/content/scripts/rpc/constants.js
@@ -44,6 +44,7 @@ Bandwagon.RPC.Constants = new function()
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;
+ this.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_NEW_COLLECTION_COMPLETE = 600;
// xhr layer constants
diff --git a/bandwagon/content/scripts/rpc/service.js b/bandwagon/content/scripts/rpc/service.js
index 0d7e661..dbf2eef 100644
--- a/bandwagon/content/scripts/rpc/service.js
+++ b/bandwagon/content/scripts/rpc/service.js
@@ -261,6 +261,55 @@ Bandwagon.RPC.Service.prototype.getCollection = function(collection, callback)
data);
}
+Bandwagon.RPC.Service.prototype.newCollection = function(collection, callback)
+{
+ var service = this;
+
+ this._logger.debug("Bandwagon.RPC.Service.newCollection: creating new collection '" + collection.toString() + "' ...");
+
+ if (collection.name == "" || service._serviceDocument == null)
+ {
+ if (callback)
+ callback(new this.Bandwagon.RPC.Event());
+
+ return;
+ }
+
+ var data = {
+ name: collection.name,
+ description: collection.description,
+ nickname: collection.getNicknameFromName(),
+ listed: (collection.listed?1:0)
+ };
+
+ var internalCallback = function(event)
+ {
+ if (event.isError())
+ {
+ collection.status = collection.STATUS_LOADERROR;
+ }
+ else
+ {
+ collection.unserialize(event.getData());
+ collection.status = collection.STATUS_LOADED;
+ }
+
+ event.collection = collection;
+
+ if (callback)
+ {
+ callback(event);
+ }
+ }
+
+ this.rpcSend(service.Bandwagon.RPC.Constants.BANDWAGON_RPC_EVENT_TYPE_BANDWAGON_RPC_NEW_COLLECTION_COMPLETE,
+ internalCallback,
+ service._serviceDocument.collectionListResourceURL,
+ "POST",
+ data);
+}
+
+
/** OBSOLETE
Bandwagon.RPC.Service.prototype.subscribeCollection = function(collection, callback)
{
diff --git a/bandwagon/content/ui/settings.xul b/bandwagon/content/ui/settings.xul
index b40dfa3..3985d6b 100644
--- a/bandwagon/content/ui/settings.xul
+++ b/bandwagon/content/ui/settings.xul
@@ -231,11 +231,11 @@
<rows>
<row align="center">
<label value="&name.label;"/>
- <textbox id=""/>
+ <textbox id="auto-name"/>
</row>
<row align="center">
<spacer/>
- <checkbox id="" label="&list.label;"/>
+ <checkbox id="auto-list" label="&list.label;"/>
</row>
</rows>
</grid>
@@ -249,13 +249,13 @@
<rows>
<row align="center">
<label value="&types.label;"/>
- <checkbox id="" label="&type.extensions.label;"/>
- <checkbox id="" label="&type.themes.label;"/>
+ <checkbox id="auto-type-extensions" label="&type.extensions.label;"/>
+ <checkbox id="auto-type-themes" label="&type.themes.label;"/>
</row>
<row align="center">
<spacer/>
- <checkbox id="" label="&type.dicts.label;"/>
- <checkbox id="" label="&type.langpacks.label;"/>
+ <checkbox id="auto-type-dicts" label="&type.dicts.label;"/>
+ <checkbox id="auto-type-langpacks" label="&type.langpacks.label;"/>
</row>
</rows>
</grid>
@@ -269,8 +269,10 @@
label="&deleteauto.label;"
oncommand="Bandwagon.Controller.Settings.doAutoDelete();"
collapsed="true"/>
+ <image id="auto-spinner" src="chrome://bandwagon/skin/images/spinner-small.gif" collapsed="true"/>
</groupbox>
</hbox>
+ <label id="auto-error" style="color: red;" value=" " collapsed="true"/>
</prefpane>
<stringbundle id="bandwagon-strings" src="chrome://bandwagon/locale/settings.properties"/>
diff --git a/bandwagon/content/ui/settingsController.js b/bandwagon/content/ui/settingsController.js
index f7f6f61..d521d15 100644
--- a/bandwagon/content/ui/settingsController.js
+++ b/bandwagon/content/ui/settingsController.js
@@ -330,7 +330,94 @@ Bandwagon.Controller.Settings.AutoCheck = function()
Bandwagon.Controller.Settings.doAutoCreate = function()
{
- // XX TODO
+ // check form
+ document.getElementById("auto-error").value = "";
+ document.getElementById("auto-error").collapsed = true;
+
+ var collectionName = document.getElementById("auto-name").value;
+
+ if (!collectionName || collectionName == "")
+ {
+ document.getElementById("auto-error").value = Bandwagon.Controller.Settings.stringBundle.getFormattedString("auto.invalid.name", [collectionName]);
+ document.getElementById("auto-error").collapsed = false;
+ return;
+ }
+
+ var autoPublishExtensions = document.getElementById("auto-type-extensions").checked;
+ var autoPublishThemes = document.getElementById("auto-type-themes").checked;
+ var autoPublishDicts = document.getElementById("auto-type-dicts").checked;
+ var autoPublishLangPacks = document.getElementById("auto-type-langpacks").checked;
+
+ if (!autoPublishExtensions && !autoPublishThemes && !autoPublishDicts && !autoPublishLangPacks)
+ {
+ document.getElementById("auto-error").value = Bandwagon.Controller.Settings.stringBundle.getString("auto.please.select.type");
+ document.getElementById("auto-error").collapsed = false;
+ return;
+ }
+
+ // disable ui settings, show throbber
+
+ var toggleUIEnabledState = function(on)
+ {
+ document.getElementById("auto-create-button").disabled = on;
+ document.getElementById("auto-name").disabled = on;
+ document.getElementById("auto-list").disabled = on;
+ document.getElementById("auto-type-extensions").disabled = on;
+ document.getElementById("auto-type-themes").disabled = on;
+ document.getElementById("auto-type-dicts").disabled = on;
+ document.getElementById("auto-type-langpacks").disabled = on;
+ document.getElementById("auto-spinner").collapsed = !on;
+ }
+
+ toggleUIEnabledState(true);
+
+ // create the collection object
+
+ var collection = new Bandwagon.Model.Collection();
+
+ collection.name = collectionName;
+ collection.description = collectionName; // nothing better to put here - api demands it
+ collection.listed = document.getElementById("auto-list").checked;
+ collection.writable = true;
+ collection.autoPublish = true;
+ collection.showNotifications = false;
+ collection.updateInterval = 60 * 60 * 24;
+ collection.addonsPerPage = Bandwagon.DEFAULT_ADDONS_PER_PAGE;
+ collection.status = collection.STATUS_NEW;
+
+ collection.autoPublishExtensions = autoPublishExtensions;
+ collection.autoPublishThemes = autoPublishThemes;
+ collection.autoPublishDicts = autoPublishDicts;
+ collection.autoPublishLangPacks = autoPublishLangPacks;
+
+ // send the api call
+
+ var newCollectionCallback = function(event)
+ {
+ if (event.isError())
+ {
+ document.getElementById("auto-error").value = Bandwagon.Controller.Settings.stringBundle.getString("auto.internal.error");
+ document.getElementById("auto-error").collapsed = false;
+ toggleUIEnabledState(false);
+ }
+ else
+ {
+ // on callback of above, refresh collection list
+ //bandwagonService.forceCheckAllForUpdatesAndUpdateCollectionsList();
+
+ // on callback of above, tell user we're done
+ document.getElementById("auto-error").style.color = 'green';
+ document.getElementById("auto-error").value = Bandwagon.Controller.Settings.stringBundle.getString("auto.done");
+ document.getElementById("auto-error").collapsed = false;
+
+ // clean-up
+ document.getElementById("auto-create-button").collapsed = true;
+ document.getElementById("auto-delete-button").collapsed = false;
+ document.getElementById("auto-spinner").collapsed = true;
+ }
+ }
+
+ bandwagonService.newCollection(collection, newCollectionCallback);
}
Bandwagon.Controller.Settings.doAutoDelete = function()
diff --git a/bandwagon/locale/en-US/settings.properties b/bandwagon/locale/en-US/settings.properties
index a9c9653..2dfccc2 100644
--- a/bandwagon/locale/en-US/settings.properties
+++ b/bandwagon/locale/en-US/settings.properties
@@ -5,3 +5,7 @@ are.you.sure.you.want.to.remove=Are you sure you want to remove '%S' from your s
saved.emails.text=You have %S saved e-mail addresses
login.status.text=You are logged in as %S
logout.status=You are not logged in
+auto.invalid.name=The collection name '%S' is not valid.
+auto.please.select.type=Please select at least one auto-publish type.
+auto.internal.error=The collection could not be created (an internal error occurred).
+auto.done=Your auto-publish collection has been created.