diff options
Diffstat (limited to 'pyload/web/app/scripts')
-rw-r--r-- | pyload/web/app/scripts/models/Package.js | 21 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/abstract/modalView.js | 15 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/dashboard/editPackageView.js | 19 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/dashboard/packageView.js | 12 |
4 files changed, 63 insertions, 4 deletions
diff --git a/pyload/web/app/scripts/models/Package.js b/pyload/web/app/scripts/models/Package.js index 555d5b7d6..a1828ed67 100644 --- a/pyload/web/app/scripts/models/Package.js +++ b/pyload/web/app/scripts/models/Package.js @@ -41,6 +41,17 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'collection return obj; }, + toServerJSON: function() { + var obj = Backbone.Model.prototype.toJSON.call(this); + return { + pid: obj.pid, + site: obj.site, + comment: obj.comment, + password: obj.password, + '@class': 'PackageInfo' + }; + }, + // Changes url + method and delegates call to super class fetch: function(options) { options = App.apiRequest( @@ -61,8 +72,14 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'collection return Backbone.Model.prototype.fetch.call(this, options); }, + // sync some attributes with the server save: function(options) { - // TODO + options = App.apiRequest( + 'updatePackage', + {pack: this.toServerJSON()}, + options); + + return Backbone.Model.prototype.fetch.call(this, options); }, togglePaused: function() { @@ -123,7 +140,7 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'collection return resp.root; } - return Backbone.model.prototype.parse.call(this, resp); + return Backbone.Model.prototype.parse.call(this, resp); }, // Any time a model attribute is set, this method is called diff --git a/pyload/web/app/scripts/views/abstract/modalView.js b/pyload/web/app/scripts/views/abstract/modalView.js index 61016a9fb..2fd84441b 100644 --- a/pyload/web/app/scripts/views/abstract/modalView.js +++ b/pyload/web/app/scripts/views/abstract/modalView.js @@ -31,6 +31,11 @@ define(['jquery', 'backbone', 'underscore', 'omniwindow'], function($, Backbone, } }, + // Class method that will show a temporary instance + display: function() { + + }, + // TODO: whole modal stuff is not very elegant render: function() { this.$el.html(this.template(this.renderContent())); @@ -110,8 +115,14 @@ define(['jquery', 'backbone', 'underscore', 'omniwindow'], function($, Backbone, }, confirm: function() { - if (this.confirmCallback) - this.confirmCallback.apply(); + // Call the confirms given or from extended class + if (this.confirmCallback) { + if (this.confirmCallback.apply() === false) + return; + } else if (_.isFunction(this.constructor.prototype.confirmCallback)) { + if (this.constructor.prototype.confirmCallback.call(this) === false) + return; + } this.hide(); }, diff --git a/pyload/web/app/scripts/views/dashboard/editPackageView.js b/pyload/web/app/scripts/views/dashboard/editPackageView.js new file mode 100644 index 000000000..45b0c6ddf --- /dev/null +++ b/pyload/web/app/scripts/views/dashboard/editPackageView.js @@ -0,0 +1,19 @@ +define(['jquery', 'underscore', 'app', 'views/abstract/modalView', 'hbs!tpl/dialogs/editPackage'], + function($, _, App, modalView, template) { + 'use strict'; + + return modalView.extend({ + template: template, + onHideDestroy: true, + + confirmCallback: function() { + var self = this; + this.$el.find('.input').each(function(i, el) { + self.model.set($(el).data('attr'), $(el).val()); + }); + this.model.save(); + } + + }); + + });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/dashboard/packageView.js b/pyload/web/app/scripts/views/dashboard/packageView.js index 382615212..89972f284 100644 --- a/pyload/web/app/scripts/views/dashboard/packageView.js +++ b/pyload/web/app/scripts/views/dashboard/packageView.js @@ -15,6 +15,8 @@ define(['jquery', 'app', 'views/abstract/itemView', 'underscore', 'hbs!tpl/dashb 'click .select': 'select', 'click .icon-chevron-down': 'loadMenu', 'click .btn-delete': 'deleteItem', + 'click .btn-edit': 'edit', + 'click .btn-add': 'add', 'click .dropdown-submenu a': 'invokeAddon' }, @@ -80,6 +82,16 @@ define(['jquery', 'app', 'views/abstract/itemView', 'underscore', 'hbs!tpl/dashb App.vent.trigger('package:selection'); }, + edit: function() { + var model = this.model; + _.requireOnce(['views/dashboard/editPackageView'], function(ModalView) { + new ModalView({model: model}).show(); + }); + }, + + add: function() { + }, + loadMenu: function() { App.addons.getForType(true, null, _.bind(this.renderSubmenu, this)); }, |