diff options
Diffstat (limited to 'module/web/static')
-rw-r--r-- | module/web/static/css/default/accounts.less | 6 | ||||
-rw-r--r-- | module/web/static/css/default/settings.less | 4 | ||||
-rw-r--r-- | module/web/static/css/default/style.less | 4 | ||||
-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 |
9 files changed, 201 insertions, 4 deletions
diff --git a/module/web/static/css/default/accounts.less b/module/web/static/css/default/accounts.less new file mode 100644 index 000000000..5d31df2db --- /dev/null +++ b/module/web/static/css/default/accounts.less @@ -0,0 +1,6 @@ +@import "common.less"; + +.logo-select { + width: 20px; + height: 20px; +}
\ No newline at end of file diff --git a/module/web/static/css/default/settings.less b/module/web/static/css/default/settings.less index 947cbaa22..435e1cf61 100644 --- a/module/web/static/css/default/settings.less +++ b/module/web/static/css/default/settings.less @@ -119,8 +119,4 @@ .logo-select {
width: 20px;
height: 20px;
-}
-
-.select2-container {
- min-width: 206px; // same as other input fields
}
\ No newline at end of file diff --git a/module/web/static/css/default/style.less b/module/web/static/css/default/style.less index 120864f39..4cafb1030 100644 --- a/module/web/static/css/default/style.less +++ b/module/web/static/css/default/style.less @@ -535,6 +535,10 @@ div.modal-header { }
+.select2-container {
+ min-width: 220px; // same as other input fields
+}
+
div.modal-body {
max-height: 100%;
}
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 |