diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js
index 54d6d422de..f09a2b567d 100644
--- a/chrome/content/zotero/overlay.js
+++ b/chrome/content/zotero/overlay.js
@@ -1466,7 +1466,111 @@ var ZoteroPane = new function()
Zotero.purgeDataObjects(true);
}
}
-
+
+ this.createCommonsBucket = function () {
+ var prompt = Components.classes["@mozilla.org/network/default-prompt;1"]
+ .createInstance(Components.interfaces.nsIPrompt);
+
+ var invalid = false;
+
+ while (true) {
+ if (invalid) {
+ // TODO: localize
+ prompt.alert("", "Invalid title. Please try again.");
+ invalid = false;
+ }
+
+ var newTitle = {};
+ var result = prompt.prompt(
+ "",
+ // TODO: localize
+ "Enter a title for this Zotero Commons collection:",
+ newTitle,
+ "", {}
+ );
+
+ if (!result) {
+ return;
+ }
+
+ var title = Zotero.Utilities.prototype.trim(newTitle.value);
+
+ if (!title) {
+ return;
+ }
+
+ if (!Zotero.Commons.isValidBucketTitle(title)) {
+ invalid = true;
+ continue;
+ }
+
+ break;
+ }
+
+ invalid = false;
+
+ var origName = title.toLowerCase();
+ origName = origName.replace(/[^a-z0-9 ._-]/g, '');
+ origName = origName.replace(/ /g, '-');
+ origName = origName.substr(0, 32);
+
+ while (true) {
+ if (invalid) {
+ // TODO: localize
+ var msg = "'" + name + "' is not a valid Zotero Commons collection identifier.\n\n"
+ + "Collection identifiers can contain basic Latin letters, numbers,"
+ + "hyphens, and underscores. Spaces and other characters are not allowed.";
+ prompt.alert("", msg);
+ invalid = false;
+ }
+
+ var newName = { value: origName };
+ var result = prompt.prompt(
+ "",
+ // TODO: localize
+ "Enter an identifier for the collection '" + title + "'.\n\n"
+ + "The identifier will form the collection's URL "
+ + "(e.g., http://www.archive.org/details/" + origName + ") "
+ + "and can contain basic Latin letters, numbers, hyphens, and underscores. "
+ + "Spaces and other characters are not allowed.",
+ newName,
+ "", {}
+ );
+
+ if (!result) {
+ return;
+ }
+
+ var name = Zotero.Utilities.prototype.trim(newName.value);
+
+ if (!name) {
+ return;
+ }
+
+ if (!Zotero.Commons.isValidBucketName(name)) {
+ invalid = true;
+ continue;
+ }
+
+ break;
+ }
+
+ // TEMP
+ var name = "zc-test-" + name;
+
+ // TODO: localize
+ var progressWin = new Zotero.ProgressWindow();
+ progressWin.changeHeadline("Creating Zotero Commons Collection");
+ var icon = this.collectionsView.getImageSrc(this.collectionsView.selection.currentIndex);
+ progressWin.addLines(title, icon)
+ progressWin.show();
+
+ Zotero.Commons.createBucket(name, title, function () {
+ progressWin.startCloseTimer();
+ });
+ }
+
+
this.refreshCommonsBucket = function() {
if (!this.collectionsView
|| !this.collectionsView.selection
@@ -1776,7 +1880,8 @@ var ZoteroPane = new function()
exportFile: 9,
loadReport: 10,
emptyTrash: 11,
- refreshCommonsBucket: 12
+ createCommonsBucket: 12,
+ refreshCommonsBucket: 13
};
var itemGroup = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex);
@@ -1845,7 +1950,9 @@ var ZoteroPane = new function()
show = [m.emptyTrash];
}
else if (itemGroup.isHeader()) {
- // Don't show menu for headers
+ if (itemGroup.ref.id == 'commons-header') {
+ show = [m.createCommonsBucket];
+ }
}
else if (itemGroup.isBucket()) {
show = [m.refreshCommonsBucket];
diff --git a/chrome/content/zotero/overlay.xul b/chrome/content/zotero/overlay.xul
index 18c4f139d4..6c894b2c4f 100644
--- a/chrome/content/zotero/overlay.xul
+++ b/chrome/content/zotero/overlay.xul
@@ -107,6 +107,7 @@
+