diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-12-06 18:15:24 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-12-06 18:15:24 +0100 |
commit | 1f4c6cd6e4b712263b40de4ce1fcebe716019b4f (patch) | |
tree | d25db580032edff61a58b3be426b4681e23addf8 | |
parent | fixed jshint (diff) | |
download | pyload-1f4c6cd6e4b712263b40de4ce1fcebe716019b4f.tar.xz |
package edit dialog
-rw-r--r-- | pyload/api/FileApi.py | 11 | ||||
-rw-r--r-- | pyload/datatypes/PyPackage.py | 8 | ||||
-rw-r--r-- | pyload/remote/pyload.thrift | 2 | ||||
-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 | ||||
-rw-r--r-- | pyload/web/app/styles/default/dashboard.less | 2 | ||||
-rw-r--r-- | pyload/web/app/templates/default/dashboard/package.html | 4 | ||||
-rw-r--r-- | pyload/web/app/templates/default/dialogs/editPackage.html | 52 |
10 files changed, 129 insertions, 17 deletions
diff --git a/pyload/api/FileApi.py b/pyload/api/FileApi.py index d8ee26ac2..817bae348 100644 --- a/pyload/api/FileApi.py +++ b/pyload/api/FileApi.py @@ -98,18 +98,13 @@ class FileApi(ApiComponent): def updatePackage(self, pack): """Allows to modify several package attributes. - :param pid: package id - :param data: :class:`PackageInfo` + :param pack: :class:`PackageInfo` + :return updated package info """ pid = pack.pid p = self.core.files.getPackage(pid) if not p: raise PackageDoesNotExist(pid) - - #TODO: fix - for key, value in data.iteritems(): - if key == "id": continue - setattr(p, key, value) - + p.updateFromInfoData(pack) p.sync() self.core.files.save() diff --git a/pyload/datatypes/PyPackage.py b/pyload/datatypes/PyPackage.py index fa58c0fd2..955986942 100644 --- a/pyload/datatypes/PyPackage.py +++ b/pyload/datatypes/PyPackage.py @@ -66,6 +66,12 @@ class PyPackage: self.comment, self.password, self.added, self.tags, self.status, self.shared, self.packageorder ) + def updateFromInfoData(self, pack): + """ Updated allowed values from info data """ + for attr in PackageInfo.__slots__: + if attr in ("site", "comment", "password"): + setattr(self, attr, getattr(pack, attr)) + def getFiles(self): """get contaied files data""" return self.m.core.db.getAllFiles(package=self.pid) @@ -88,7 +94,7 @@ class PyPackage: def deleteIfEmpty(self): """ True if deleted """ - if not len(self.getChildren()): + if not len(self.getFiles()): self.delete() return True return False diff --git a/pyload/remote/pyload.thrift b/pyload/remote/pyload.thrift index 6773b7eac..c68bf5502 100644 --- a/pyload/remote/pyload.thrift +++ b/pyload/remote/pyload.thrift @@ -454,7 +454,7 @@ service Pyload { // Modify Files/Packages // moving package while downloading is not possible, so they will return bool to indicate success - void updatePackage(1: PackageInfo pack) throws (1: PackageDoesNotExist e), + PackageInfo updatePackage(1: PackageInfo pack) throws (1: PackageDoesNotExist e), PackageStatus setPackagePaused(1: PackageID pid, 2: bool paused) throws (1: PackageDoesNotExist e), // as above, this will move files on disk 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)); }, diff --git a/pyload/web/app/styles/default/dashboard.less b/pyload/web/app/styles/default/dashboard.less index 1e9f21fec..4978f358a 100644 --- a/pyload/web/app/styles/default/dashboard.less +++ b/pyload/web/app/styles/default/dashboard.less @@ -109,7 +109,7 @@ .package-indicator { position: absolute; top: 0; - right: 0; + right: 5px; float: right; color: @blue; text-shadow: @yellowDark 1px 1px; diff --git a/pyload/web/app/templates/default/dashboard/package.html b/pyload/web/app/templates/default/dashboard/package.html index bc8314494..751ca5b4c 100644 --- a/pyload/web/app/templates/default/dashboard/package.html +++ b/pyload/web/app/templates/default/dashboard/package.html @@ -29,8 +29,8 @@ </i> <ul class="dropdown-menu" role="menu"> <li><a href="#" class="btn-open"><i class="icon-folder-open-alt"></i> Open</a></li> - <li><a href="#"><i class="icon-plus-sign"></i> Add links</a></li> - <li><a href="#"><i class="icon-edit"></i> Details</a></li> + <li><a href="#" class="btn-add"><i class="icon-plus-sign"></i> Add links</a></li> + <li><a href="#" class="btn-edit"><i class="icon-edit"></i> Edit</a></li> <li><a href="#" class="btn-delete"><i class="icon-trash"></i> Delete</a></li> <li><a href="#" class="btn-recheck"><i class="icon-refresh"></i> Recheck</a></li> <li class="divider"></li> diff --git a/pyload/web/app/templates/default/dialogs/editPackage.html b/pyload/web/app/templates/default/dialogs/editPackage.html new file mode 100644 index 000000000..1302bdae5 --- /dev/null +++ b/pyload/web/app/templates/default/dialogs/editPackage.html @@ -0,0 +1,52 @@ +<div class="modal-header"> + <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> + <h3>{{_ "Edit Package" }}</h3> +</div> +<div class="modal-body"> + <form class="form-horizontal"> + <legend> + {{ name }} + </legend> + <div class="control-group"> + <label class="control-label" for="rename"> + {{_ "Rename" }} + </label> + + <div class="controls"> + <input type="text" id="rename" value="{{name}}" disabled> + </div> + </div> + <div class="control-group"> + <label class="control-label" for="site"> + {{_ "Site" }} + </label> + + <div class="controls"> + <input type="text" class="input" data-attr="site" id="site" value="{{site}}"> + </div> + </div> + <div class="control-group"> + <label class="control-label" for="password"> + {{_ "Password" }} + </label> + + <div class="controls"> + <input type="password" class="input" data-attr="password" id="password" value="{{password}}"> + </div> + </div> + + <div class="control-group"> + <label class="control-label" for="comment"> + {{_ "Comments" }} + </label> + + <div class="controls"> + <textarea class="input" data-attr="comment" id="comment">{{comment}}</textarea> + </div> + </div> + </form> +</div> +<div class="modal-footer"> + <a class="btn btn-close">Close</a> + <a class="btn btn-primary btn-confirm">Save</a> +</div>
\ No newline at end of file |