From 53bc0477f9b0217c87676103361b1633e9b12f19 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 31 Mar 2013 13:11:58 +0200 Subject: added account page --- module/api/AccountApi.py | 11 ++-- module/remote/apitypes.py | 2 +- module/remote/pyload.thrift | 2 +- module/web/pyload_app.py | 7 ++- module/web/static/css/default/accounts.less | 6 +++ module/web/static/css/default/settings.less | 4 -- module/web/static/css/default/style.less | 4 ++ module/web/static/js/collections/AccountList.js | 23 +++++++++ module/web/static/js/default.js | 7 +++ module/web/static/js/models/Account.js | 38 ++++++++++++++ .../static/js/views/accounts/accountListView.js | 44 ++++++++++++++++ .../web/static/js/views/accounts/accountModal.js | 60 ++++++++++++++++++++++ module/web/static/js/views/accounts/accountView.js | 19 +++++++ module/web/templates/default/accounts.html | 45 ++++++++++++++++ .../templates/default/backbone/accountDialog.html | 40 +++++++++++++++ .../default/backbone/pluginChooserDialog.html | 2 +- module/web/templates/default/base.html | 1 + module/web/templates/default/settings.html | 4 +- 18 files changed, 306 insertions(+), 13 deletions(-) create mode 100644 module/web/static/css/default/accounts.less create mode 100644 module/web/static/js/collections/AccountList.js create mode 100644 module/web/static/js/models/Account.js create mode 100644 module/web/static/js/views/accounts/accountListView.js create mode 100644 module/web/static/js/views/accounts/accountModal.js create mode 100644 module/web/static/js/views/accounts/accountView.js create mode 100644 module/web/templates/default/accounts.html create mode 100755 module/web/templates/default/backbone/accountDialog.html diff --git a/module/api/AccountApi.py b/module/api/AccountApi.py index 396824a55..d1586e7aa 100644 --- a/module/api/AccountApi.py +++ b/module/api/AccountApi.py @@ -5,6 +5,7 @@ from module.Api import Api, RequirePerm, Permission from ApiComponent import ApiComponent + class AccountApi(ApiComponent): """ All methods to control accounts """ @@ -35,13 +36,17 @@ class AccountApi(ApiComponent): """Changes pw/options for specific account.""" self.core.accountManager.updateAccount(plugin, account, password, options) + def updateAccountInfo(self, account): + """ Update account from :class:`AccountInfo` """ + #TODO + @RequirePerm(Permission.Accounts) - def removeAccount(self, plugin, account): + def removeAccount(self, account): """Remove account from pyload. - :param plugin: pluginname - :param account: accountname + :param account: :class:`ÀccountInfo` instance """ + # TODO self.core.accountManager.removeAccount(plugin, account) diff --git a/module/remote/apitypes.py b/module/remote/apitypes.py index 41f9be50e..f725aa386 100644 --- a/module/remote/apitypes.py +++ b/module/remote/apitypes.py @@ -487,7 +487,7 @@ class Iface(object): pass def recheckPackage(self, pid): pass - def removeAccount(self, plugin, account): + def removeAccount(self, account): pass def removeUser(self, uid): pass diff --git a/module/remote/pyload.thrift b/module/remote/pyload.thrift index adaede0ff..032be92fd 100644 --- a/module/remote/pyload.thrift +++ b/module/remote/pyload.thrift @@ -491,7 +491,7 @@ service Pyload { list getAccountTypes(), void updateAccount(1: PluginName plugin, 2: string account, 3: string password), void updateAccountInfo(1: AccountInfo account), - void removeAccount(1: PluginName plugin, 2: string account), + void removeAccount(1: AccountInfo account), ///////////////////////// // Auth+User Information diff --git a/module/web/pyload_app.py b/module/web/pyload_app.py index 45564ed08..483a47f07 100644 --- a/module/web/pyload_app.py +++ b/module/web/pyload_app.py @@ -154,10 +154,15 @@ def index(api): return render_to_response("dashboard.html", proc=[pre_processor]) @route("/settings") -@login_required() +@login_required('Plugins') def settings(api): return render_to_response("settings.html", proc=[pre_processor]) +@route("/accounts") +@login_required('Accounts') +def accounts(api): + return render_to_response("accounts.html", proc=[pre_processor]) + @route("/admin") @login_required() def admin(api): 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 ' ' + 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 diff --git a/module/web/templates/default/accounts.html b/module/web/templates/default/accounts.html new file mode 100644 index 000000000..06b81c330 --- /dev/null +++ b/module/web/templates/default/accounts.html @@ -0,0 +1,45 @@ +{% extends 'default/base.html' %} + +{% block title %}{{ _("Accounts") }} - {{ super() }} {% endblock %} +{% block subtitle %}{{ _("Accounts") }} +{% endblock %} + +{% block css %} + +{% endblock %} + +{% block require %} + App.initAccountView(); +{% endblock %} + +{% block head %} + +{% endblock %} + +{% block actionbar %} + + + +{% endblock %} + +{% block content %} + {# TODO: responsive layout instead of table #} +
+ + + + + + + + + + + + + + +
NamePluginValidPremiumTrafficSharedActivated
+
+{% endblock %} \ No newline at end of file diff --git a/module/web/templates/default/backbone/accountDialog.html b/module/web/templates/default/backbone/accountDialog.html new file mode 100755 index 000000000..dbc88e66d --- /dev/null +++ b/module/web/templates/default/backbone/accountDialog.html @@ -0,0 +1,40 @@ +{% extends 'default/backbone/modal.html' %} +{% block header %} + Add an account +{% endblock %} +{% block content %} +
+ + Please enter your account data + +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+{% endblock %} +{% block buttons %} + Add + Close +{% endblock %} \ No newline at end of file diff --git a/module/web/templates/default/backbone/pluginChooserDialog.html b/module/web/templates/default/backbone/pluginChooserDialog.html index 02284d0e6..a455b0cfd 100755 --- a/module/web/templates/default/backbone/pluginChooserDialog.html +++ b/module/web/templates/default/backbone/pluginChooserDialog.html @@ -3,7 +3,7 @@ Choose a plugin {% endblock %} {% block content %} -
+ Please choose a plugin, which you want to configure diff --git a/module/web/templates/default/base.html b/module/web/templates/default/base.html index 846b396a0..bf16f545a 100644 --- a/module/web/templates/default/base.html +++ b/module/web/templates/default/base.html @@ -136,6 +136,7 @@