diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-03-31 13:11:58 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-03-31 13:11:58 +0200 |
commit | 53bc0477f9b0217c87676103361b1633e9b12f19 (patch) | |
tree | c6461ab1c292b39e49e1a5924b75761b588b25ba /module/web/static/js | |
parent | separate addon and plugin configs (diff) | |
download | pyload-53bc0477f9b0217c87676103361b1633e9b12f19.tar.xz |
added account page
Diffstat (limited to 'module/web/static/js')
-rw-r--r-- | module/web/static/js/collections/AccountList.js | 23 | ||||
-rw-r--r-- | module/web/static/js/default.js | 7 | ||||
-rw-r--r-- | module/web/static/js/models/Account.js | 38 | ||||
-rw-r--r-- | module/web/static/js/views/accounts/accountListView.js | 44 | ||||
-rw-r--r-- | module/web/static/js/views/accounts/accountModal.js | 60 | ||||
-rw-r--r-- | module/web/static/js/views/accounts/accountView.js | 19 |
6 files changed, 191 insertions, 0 deletions
diff --git a/module/web/static/js/collections/AccountList.js b/module/web/static/js/collections/AccountList.js new file mode 100644 index 000000000..1bcf87c1e --- /dev/null +++ b/module/web/static/js/collections/AccountList.js @@ -0,0 +1,23 @@ +define(['jquery', 'backbone', 'underscore', 'app', 'models/Account'], function($, Backbone, _, App, Account) { + + return Backbone.Collection.extend({ + + model: Account, + + comparator: function(account) { + return account.get('plugin'); + }, + + initialize: function() { + + }, + + fetch: function(options) { + // TODO: refresh options? + options = App.apiRequest('getAccounts/false', null, options); + return Backbone.Collection.prototype.fetch.call(this, options); + } + + }); + +});
\ No newline at end of file diff --git a/module/web/static/js/default.js b/module/web/static/js/default.js index 62b2ef9b6..d5a0cfb3e 100644 --- a/module/web/static/js/default.js +++ b/module/web/static/js/default.js @@ -20,5 +20,12 @@ define('default', ['require', 'jquery', 'app', 'views/headerView', 'views/dashbo }); }; + App.initAccountView = function() { + require(['views/accounts/accountListView'], function(AccountListView) { + App.accountView = new AccountListView(); + App.accountView.render(); + }); + }; + return App; });
\ No newline at end of file diff --git a/module/web/static/js/models/Account.js b/module/web/static/js/models/Account.js new file mode 100644 index 000000000..55e63ac08 --- /dev/null +++ b/module/web/static/js/models/Account.js @@ -0,0 +1,38 @@ +define(['jquery', 'backbone', 'underscore', 'utils/apitypes'], function($, Backbone, _, Api) { + + return Backbone.Model.extend({ + + // TODO + // generated, not submitted + idAttribute: 'user', + + defaults: { + plugin: null, + loginname: null, + owner: -1, + valid: false, + validuntil: -1, + trafficleft: -1, + maxtraffic: -1, + premium: false, + activated: false, + shared: false, + options: null + }, + + // Model Constructor + initialize: function() { + + }, + + // Any time a model attribute is set, this method is called + validate: function(attrs) { + + }, + + save: function(options){ + // TODO + } + }); + +});
\ No newline at end of file diff --git a/module/web/static/js/views/accounts/accountListView.js b/module/web/static/js/views/accounts/accountListView.js new file mode 100644 index 000000000..ea01f679e --- /dev/null +++ b/module/web/static/js/views/accounts/accountListView.js @@ -0,0 +1,44 @@ +define(['jquery', 'underscore', 'backbone', 'app', 'collections/AccountList', './accountView'], + function($, _, Backbone, App, AccountList, accountView) { + + // Renders settings over view page + return Backbone.View.extend({ + + el: "body", + + events: { + 'click .btn-add': 'addAccount' + }, + + content: null, + accounts: null, + modal: null, + + initialize: function() { + this.content = this.$('#account-content'); + this.accounts = new AccountList(); + this.refresh(); + }, + + refresh: function() { + this.accounts.fetch({success: _.bind(this.render, this)}); + }, + + render: function() { + var self = this; + this.accounts.each(function(account) { + self.content.append(new accountView({model: account}).render().el); + }); + }, + + addAccount: function() { + var self = this; + _.requireOnce(['views/accounts/accountModal'], function(Modal) { + if (self.modal === null) + self.modal = new Modal(); + + self.modal.show(); + }); + } + }); + });
\ No newline at end of file diff --git a/module/web/static/js/views/accounts/accountModal.js b/module/web/static/js/views/accounts/accountModal.js new file mode 100644 index 000000000..898b10a89 --- /dev/null +++ b/module/web/static/js/views/accounts/accountModal.js @@ -0,0 +1,60 @@ +define(['jquery', 'underscore', 'app', 'views/abstract/modalView', 'text!tpl/default/accountDialog.html', 'select2'], + function($, _, App, modalView, template) { + return modalView.extend({ + + events: { + 'click .btn-add': 'add' + }, + template: _.compile(template), + plugins: null, + select: null, + + initialize: function() { + // Inherit parent events + this.events = _.extend({}, modalView.prototype.events, this.events); + var self = this; + $.ajax(App.apiRequest('getAccountTypes', null, {success: function(data) { + self.plugins = _.sortBy(data, function(item) { + return item; + }); + self.render(); + }})); + }, + + onRender: function() { + // TODO: could be a seperate input type if needed on multiple pages + if (this.plugins) + this.select = this.$('#pluginSelect').select2({ + escapeMarkup: function(m) { + return m; + }, + formatResult: this.format, + formatSelection: this.format, + data: {results: this.plugins, text: function(item) { + return item; + }}, + id: function(item) { + return item; + } + }); + }, + + onShow: function() { + }, + + onHide: function() { + }, + + format: function(data) { + return '<img class="logo-select" src="icons/' + data + '"> ' + data; + }, + + add: function(e) { + e.stopPropagation(); + if (this.select) { + var plugin = this.select.val(); + // TODO + } + } + }); + });
\ No newline at end of file diff --git a/module/web/static/js/views/accounts/accountView.js b/module/web/static/js/views/accounts/accountView.js new file mode 100644 index 000000000..f310e4cc2 --- /dev/null +++ b/module/web/static/js/views/accounts/accountView.js @@ -0,0 +1,19 @@ +define(['jquery', 'underscore', 'backbone', 'app'], + function($, _, Backbone, App) { + + // Renders settings over view page + return Backbone.View.extend({ + + el: "li", + + events: { + }, + + initialize: function() { + }, + + render: function() { + return this; + } + }); + });
\ No newline at end of file |