diff options
Diffstat (limited to 'bandwagon/content/ui/settingsController.js')
-rw-r--r-- | bandwagon/content/ui/settingsController.js | 89 |
1 files changed, 88 insertions, 1 deletions
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() |