diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-03-28 12:37:42 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-03-28 12:37:42 +0100 |
commit | 7c1309ea483b21cb2f97a509b61cb3363de8edb8 (patch) | |
tree | 1fe9a481aa7bac344b331519f954e1c7dbe2d283 | |
parent | working reset button for config (diff) | |
download | pyload-7c1309ea483b21cb2f97a509b61cb3363de8edb8.tar.xz |
client side settings save, working dl button on dashboard
-rw-r--r-- | module/api/ConfigApi.py | 2 | ||||
-rw-r--r-- | module/api/FileApi.py | 8 | ||||
-rw-r--r-- | module/datatypes/User.py | 2 | ||||
-rw-r--r-- | module/web/pyload_app.py | 5 | ||||
-rw-r--r-- | module/web/static/js/models/ConfigHolder.js | 14 | ||||
-rw-r--r-- | module/web/static/js/models/ConfigItem.js | 15 | ||||
-rw-r--r-- | module/web/static/js/views/configSectionView.js | 22 | ||||
-rw-r--r-- | module/web/static/js/views/settingsView.js | 14 | ||||
-rw-r--r-- | module/web/templates/default/dashboard.html | 2 | ||||
-rw-r--r-- | module/web/templates/default/settings.html | 13 |
10 files changed, 78 insertions, 19 deletions
diff --git a/module/api/ConfigApi.py b/module/api/ConfigApi.py index 4fba0c34e..309400808 100644 --- a/module/api/ConfigApi.py +++ b/module/api/ConfigApi.py @@ -106,7 +106,7 @@ class ConfigApi(ApiComponent): :param config: :class:`ConfigHolder` """ - pass + #TODO @RequirePerm(Permission.Plugins) def deleteConfig(self, plugin): diff --git a/module/api/FileApi.py b/module/api/FileApi.py index a5d5a8535..8a55d9dfd 100644 --- a/module/api/FileApi.py +++ b/module/api/FileApi.py @@ -74,6 +74,14 @@ class FileApi(ApiComponent): raise FileDoesNotExists(fid) return info + @RequirePerm(Permission.Download) + def getFilePath(self, fid): + """ Internal method to get the filepath""" + info = self.getFileInfo(fid) + pack = self.core.files.getPackage(info.package) + return pack.getPath(), info.name + + @RequirePerm(Permission.All) def findFiles(self, pattern): return self.core.files.getTree(-1, True, DownloadState.All, pattern) diff --git a/module/datatypes/User.py b/module/datatypes/User.py index da7fb90bf..141191df4 100644 --- a/module/datatypes/User.py +++ b/module/datatypes/User.py @@ -41,7 +41,7 @@ class User(UserData): def hasPermission(self, perms): """ Accepts permission bit or name """ if isinstance(perms, basestring) and hasattr(Permission, perms): - perms = getattr(Role, perms) + perms = getattr(Permission, perms) return bits_set(perms, self.permission) diff --git a/module/web/pyload_app.py b/module/web/pyload_app.py index 0c3af103f..45564ed08 100644 --- a/module/web/pyload_app.py +++ b/module/web/pyload_app.py @@ -163,3 +163,8 @@ def settings(api): def admin(api): return render_to_response("admin.html", proc=[pre_processor]) +@route("/download/:fid") +@login_required('Download') +def download(fid, api): + path, name = api.getFilePath(fid) + return static_file(name, path, download=True)
\ No newline at end of file diff --git a/module/web/static/js/models/ConfigHolder.js b/module/web/static/js/models/ConfigHolder.js index abd1b9f0a..37af9d70e 100644 --- a/module/web/static/js/models/ConfigHolder.js +++ b/module/web/static/js/models/ConfigHolder.js @@ -25,7 +25,19 @@ define(['jquery', 'backbone', 'underscore', 'app', './ConfigItem'], }, save: function(options) { - // TODO + var config = this.toJSON(); + var items = []; + // Convert changed items to json + _.each(config.items, function(item) { + if (item.isChanged()) { + items.push(item.prepareSave()); + } + }); + config.items = items; + + options = App.apiRequest('saveConfig', {config: config}, options); + + return $.ajax(options); }, parse: function(resp) { diff --git a/module/web/static/js/models/ConfigItem.js b/module/web/static/js/models/ConfigItem.js index 636c28851..01a85c6cc 100644 --- a/module/web/static/js/models/ConfigItem.js +++ b/module/web/static/js/models/ConfigItem.js @@ -8,7 +8,7 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], label: "", description: "", input: null, - default_valie: null, + default_value: null, value: null, // additional attributes inputView: null @@ -21,6 +21,19 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], isChanged: function() { return this.get('inputView') && this.get('inputView').getVal() !== this.get('value'); + }, + + // set new value and return json + prepareSave: function() { + // set the new value + if (this.get('inputView')) + this.set('value', this.get('inputView').getVal()); + + var data = this.toJSON(); + delete data.inputView; + delete data.description; + + return data; } }); });
\ No newline at end of file diff --git a/module/web/static/js/views/configSectionView.js b/module/web/static/js/views/configSectionView.js index 346f7b949..949493731 100644 --- a/module/web/static/js/views/configSectionView.js +++ b/module/web/static/js/views/configSectionView.js @@ -1,8 +1,8 @@ -define(['jquery', 'underscore', 'backbone', 'app', './input/inputLoader'], - function($, _, Backbone, App, load_input) { +define(['jquery', 'underscore', 'backbone', 'app', './abstract/itemView', './input/inputLoader'], + function($, _, Backbone, App, itemView, load_input) { // Renders settings over view page - return Backbone.View.extend({ + return itemView.extend({ tagName: 'div', @@ -18,9 +18,9 @@ define(['jquery', 'underscore', 'backbone', 'app', './input/inputLoader'], }, initialize: function() { + this.listenTo(this.model, 'destroy', this.destroy); }, - // TODO: correct cleanup after building up so many views and models render: function() { if (!this.rendered) { this.$el.html(this.template(this.model.toJSON())); @@ -28,14 +28,14 @@ define(['jquery', 'underscore', 'backbone', 'app', './input/inputLoader'], // initialize the popover this.$('.page-header a').popover({ placement: 'left', - trigger: 'hover' +// trigger: 'hover' }); var container = this.$('.control-content'); var self = this; _.each(this.model.get('items'), function(item) { var el = $('<div>').html(self.templateItem(item.toJSON())); - var inputView = load_input("todo"); + var inputView = load_input(item.get('input')); var input = new inputView(item.get('input'), item.get('value'), item.get('default_value'), item.get('description')).render(); item.set('inputView', input); @@ -65,9 +65,19 @@ define(['jquery', 'underscore', 'backbone', 'app', './input/inputLoader'], return this; }, + onDestroy: function(){ + // TODO: correct cleanup after building up so many views and models + }, + submit: function(e) { e.stopPropagation(); // TODO: success / failure popups + var self = this; + this.model.save({success: function(){ + console.log("saved"); + self.render(); + }}); + }, reset: function(e) { diff --git a/module/web/static/js/views/settingsView.js b/module/web/static/js/views/settingsView.js index 5350f5a94..3b8308f19 100644 --- a/module/web/static/js/views/settingsView.js +++ b/module/web/static/js/views/settingsView.js @@ -19,6 +19,7 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ConfigHolder', './con // currently open configHolder config: null, + lastConfig: null, isLoading: false, @@ -56,6 +57,7 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ConfigHolder', './con if (this.config && this.config.get('name') === name) return; + this.lastConfig = this.config; this.config = new ConfigHolder({name: name}); this.loading(); @@ -81,10 +83,16 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ConfigHolder', './con }, show: function() { - // TODO: better cleaning of old views - var oldHeight = this.content.height(); - this.content.empty(); + // TODO animations are bit sloppy this.content.css('display', 'block'); + var oldHeight = this.content.height(); + + // this will destroy the old view + if (this.lastConfig) + this.lastConfig.trigger('destroy'); + else + this.content.empty(); + // reset the height this.content.css('height', ''); // append the new element diff --git a/module/web/templates/default/dashboard.html b/module/web/templates/default/dashboard.html index bb2a68cbf..e8041e700 100644 --- a/module/web/templates/default/dashboard.html +++ b/module/web/templates/default/dashboard.html @@ -86,7 +86,7 @@ <ul class="dropdown-menu" role="menu">
<li><a href="#" class="btn-delete"><i class="iconf-trash"></i> Delete</a></li>
<li><a href="#" class="btn-restart"><i class="iconf-refresh"></i> Restart</a></li>
- <li><a href="#" class="btn-dowload"><i class="iconf-download"></i> Download</a></li>
+ <li><a href="download/<% fid %>" target="_blank" class="btn-dowload"><i class="iconf-download"></i> Download</a></li>
<li><a href="#" class="btn-share"><i class="iconf-share"></i> Share</a></li>
<li class="divider"></li>
<li class="dropdown-submenu pull-left">
diff --git a/module/web/templates/default/settings.html b/module/web/templates/default/settings.html index 683009c37..ea570af0f 100644 --- a/module/web/templates/default/settings.html +++ b/module/web/templates/default/settings.html @@ -16,14 +16,17 @@ <script type="text/template" id="template-menu">
<%=if core%>
<li class="nav-header"><i class="icon-globe icon-white"></i> {{ _("General") }}</li>
- <%=each core%>
- <li data-name="<% this.name %>"><a href="#"><% this.label %></a></li>
+ <%= each core%>
+ <li data-name="<% name %>"><a href="#"><% label %></a></li>
<%/each%>
<%/if%>
<li class="divider"></li>
<li class="nav-header"><i class="icon-th-large icon-white"></i> {{ _("Addons") }}</li>
- <li class="divider"></li>
- <li class="nav-header"><i class="icon-th-list icon-white"></i> {{ _("Other") }}</li>
+ <%= each plugin %>
+ <li data-name="<% name %>"><a href="#"><% label %></a></li>
+ <%/each%>
+{# <li class="divider"></li>#}
+{# <li class="nav-header"><i class="icon-th-list icon-white"></i> {{ _("Other") }}</li>#}
</script>
<script type="text/template" id="template-config">
<legend>
@@ -38,7 +41,7 @@ <div class="control-content">
</div>
<div class="form-actions">
- <button type="submit" class="btn btn-primary">Save changes</button>
+ <button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-reset">Reset</button>
</div>
</script>
|