diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-03-31 18:32:13 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-03-31 18:32:13 +0200 |
commit | 9ea1ab90b4705ef4d5ce37ded36a214f276c0a18 (patch) | |
tree | 995539a44a25c54344639d5ade7aa3e48624ed97 /module/web | |
parent | added account page (diff) | |
download | pyload-9ea1ab90b4705ef4d5ce37ded36a214f276c0a18.tar.xz |
add and delete accounts, db will be resetted
Diffstat (limited to 'module/web')
-rw-r--r-- | module/web/static/js/models/Account.js | 20 | ||||
-rw-r--r-- | module/web/static/js/views/accounts/accountListView.js | 4 | ||||
-rw-r--r-- | module/web/static/js/views/accounts/accountModal.js | 13 | ||||
-rw-r--r-- | module/web/static/js/views/accounts/accountView.js | 13 | ||||
-rw-r--r-- | module/web/templates/default/accounts.html | 12 | ||||
-rwxr-xr-x | module/web/templates/default/backbone/accountDialog.html | 2 |
6 files changed, 51 insertions, 13 deletions
diff --git a/module/web/static/js/models/Account.js b/module/web/static/js/models/Account.js index 55e63ac08..c6e023578 100644 --- a/module/web/static/js/models/Account.js +++ b/module/web/static/js/models/Account.js @@ -1,4 +1,4 @@ -define(['jquery', 'backbone', 'underscore', 'utils/apitypes'], function($, Backbone, _, Api) { +define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], function($, Backbone, _, App, Api) { return Backbone.Model.extend({ @@ -22,7 +22,6 @@ define(['jquery', 'backbone', 'underscore', 'utils/apitypes'], function($, Backb // Model Constructor initialize: function() { - }, // Any time a model attribute is set, this method is called @@ -30,8 +29,21 @@ define(['jquery', 'backbone', 'underscore', 'utils/apitypes'], function($, Backb }, - save: function(options){ - // TODO + save: function(options) { + options = App.apiRequest('updateAccountInfo', {account: this.toJSON()}, options); + return $.ajax(options); + }, + + destroy: function(options) { + options = App.apiRequest('removeAccount', {account: this.toJSON()}, options); + var self = this; + options.success = function() { + self.trigger('destroy', self, self.collection, options); + }; + + // TODO request is not dispatched +// return Backbone.Model.prototype.destroy.call(this, options); + return $.ajax(options); } }); diff --git a/module/web/static/js/views/accounts/accountListView.js b/module/web/static/js/views/accounts/accountListView.js index ea01f679e..68dffaa98 100644 --- a/module/web/static/js/views/accounts/accountListView.js +++ b/module/web/static/js/views/accounts/accountListView.js @@ -26,8 +26,10 @@ define(['jquery', 'underscore', 'backbone', 'app', 'collections/AccountList', '. render: function() { var self = this; + App.vent.trigger('accounts:destroyContent'); + // TODO trs cant' be animated this.accounts.each(function(account) { - self.content.append(new accountView({model: account}).render().el); + self.content.appendWithHeight(new accountView({model: account}).render().el); }); }, diff --git a/module/web/static/js/views/accounts/accountModal.js b/module/web/static/js/views/accounts/accountModal.js index 898b10a89..755ffd510 100644 --- a/module/web/static/js/views/accounts/accountModal.js +++ b/module/web/static/js/views/accounts/accountModal.js @@ -52,8 +52,17 @@ define(['jquery', 'underscore', 'app', 'views/abstract/modalView', 'text!tpl/def add: function(e) { e.stopPropagation(); if (this.select) { - var plugin = this.select.val(); - // TODO + var plugin = this.select.val(), + login = this.$('#login').val(), + password = this.$('#password').val(), + self = this; + + $.ajax(App.apiRequest('updateAccount', { + plugin: plugin, login: login, password: password + }, { success: function() { + App.accountView.refresh(); + self.hide(); + }})); } } }); diff --git a/module/web/static/js/views/accounts/accountView.js b/module/web/static/js/views/accounts/accountView.js index f310e4cc2..7d6306523 100644 --- a/module/web/static/js/views/accounts/accountView.js +++ b/module/web/static/js/views/accounts/accountView.js @@ -1,18 +1,23 @@ -define(['jquery', 'underscore', 'backbone', 'app'], - function($, _, Backbone, App) { +define(['jquery', 'underscore', 'backbone', 'app', '../abstract/itemView'], + function($, _, Backbone, App, itemView) { // Renders settings over view page - return Backbone.View.extend({ + return itemView.extend({ - el: "li", + el: "tr", + template: _.compile($('#template-account').html()), events: { + 'click .btn-danger': 'deleteItem' }, initialize: function() { + this.listenTo(this.model, 'remove', this.unrender); + this.listenTo(App.vent, 'accounts:destroyContent', this.destroy); }, render: function() { + this.$el.html(this.template(this.model.toJSON())); return this; } }); diff --git a/module/web/templates/default/accounts.html b/module/web/templates/default/accounts.html index 06b81c330..c68f04653 100644 --- a/module/web/templates/default/accounts.html +++ b/module/web/templates/default/accounts.html @@ -14,6 +14,15 @@ {% block head %} <script type="text/template" id="template-account"> + <td><% plugin %></td> + <td><% loginname %></td> + <td><% valid %></td> + <td><% premium %></td> + <td><% trafficleft %></td> + <td><% shared %></td> + <td><% activated %></td> + <td><% shared %></td> + <td><button type="button" class="btn btn-danger">Delete</button> </td> </script> {% endblock %} @@ -29,13 +38,14 @@ <table class="table table-striped"> <thead> <tr> - <th>Name</th> <th>Plugin</th> + <th>Name</th> <th>Valid</th> <th>Premium</th> <th>Traffic</th> <th>Shared</th> <th>Activated</th> + <th>Delete</th> </tr> </thead> <tbody id="account-content"> diff --git a/module/web/templates/default/backbone/accountDialog.html b/module/web/templates/default/backbone/accountDialog.html index dbc88e66d..7961ad2ba 100755 --- a/module/web/templates/default/backbone/accountDialog.html +++ b/module/web/templates/default/backbone/accountDialog.html @@ -3,7 +3,7 @@ Add an account {% endblock %} {% block content %} - <form class="form-horizontal" action="#"> + <form class="form-horizontal" action="#" autocomplete="off"> <legend> Please enter your account data </legend> |