diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-08-11 20:36:10 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-08-11 20:36:10 +0200 |
commit | 080643e89af62013d70bb574cd54cf4876628515 (patch) | |
tree | e79e3bebe9175da613c4a339fc4ac3fa172ecced /pyload/web/app/scripts | |
parent | another try to fix broken accounts (diff) | |
download | pyload-080643e89af62013d70bb574cd54cf4876628515.tar.xz |
improved account list
Diffstat (limited to 'pyload/web/app/scripts')
-rw-r--r-- | pyload/web/app/scripts/config.js | 1 | ||||
-rw-r--r-- | pyload/web/app/scripts/helpers/fileHelper.js | 2 | ||||
-rw-r--r-- | pyload/web/app/scripts/helpers/formatSize.js | 6 | ||||
-rw-r--r-- | pyload/web/app/scripts/helpers/formatTime.js | 21 | ||||
-rw-r--r-- | pyload/web/app/scripts/helpers/formatTimeLeft.js | 17 | ||||
-rw-r--r-- | pyload/web/app/scripts/models/Account.js | 29 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/abstract/modalView.js | 2 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/accounts/accountEdit.js | 37 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/accounts/accountView.js | 33 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/dashboard/fileView.js | 2 |
10 files changed, 131 insertions, 19 deletions
diff --git a/pyload/web/app/scripts/config.js b/pyload/web/app/scripts/config.js index 9d1d027d9..ff4082ce4 100644 --- a/pyload/web/app/scripts/config.js +++ b/pyload/web/app/scripts/config.js @@ -19,6 +19,7 @@ require.config({ marionette: '../components/backbone.marionette/lib/backbone.marionette', handlebars: '../components/handlebars.js/dist/handlebars', jed: '../components/jed/jed', + moment: '../components/momentjs/moment', // TODO: Two hbs dependencies could be replaced i18nprecompile: '../components/require-handlebars-plugin/hbs/i18nprecompile', diff --git a/pyload/web/app/scripts/helpers/fileHelper.js b/pyload/web/app/scripts/helpers/fileHelper.js index 044887eea..2e14f939f 100644 --- a/pyload/web/app/scripts/helpers/fileHelper.js +++ b/pyload/web/app/scripts/helpers/fileHelper.js @@ -1,5 +1,5 @@ // Helpers to render the file view -define('helpers/fileHelper', ['handlebars', 'utils/apitypes', 'helpers/formatTime'], +define('helpers/fileHelper', ['handlebars', 'utils/apitypes', 'helpers/formatTimeLeft'], function(Handlebars, Api, formatTime) { 'use strict'; diff --git a/pyload/web/app/scripts/helpers/formatSize.js b/pyload/web/app/scripts/helpers/formatSize.js index 926c4793d..f72d62158 100644 --- a/pyload/web/app/scripts/helpers/formatSize.js +++ b/pyload/web/app/scripts/helpers/formatSize.js @@ -1,14 +1,14 @@ // Format bytes in human readable format -define('helpers/formatSize', ['handlebars', './gettext'], function(Handlebars, gettext) { +define('helpers/formatSize', ['handlebars', 'utils/i18n'], function(Handlebars, i18n) { 'use strict'; var sizes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB']; function formatSize(bytes, options) { if (!bytes || bytes === 0) return '0 B'; if (bytes === -1) - return gettext('not available'); + return i18n.gettext('not available'); if (bytes === -2) - return gettext('unlimited'); + return i18n.gettext('unlimited'); var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10); // round to two digits diff --git a/pyload/web/app/scripts/helpers/formatTime.js b/pyload/web/app/scripts/helpers/formatTime.js index 757ff73ad..0fb0f6058 100644 --- a/pyload/web/app/scripts/helpers/formatTime.js +++ b/pyload/web/app/scripts/helpers/formatTime.js @@ -1,15 +1,18 @@ -// Format bytes in human readable format -define('helpers/formatTime', ['handlebars', 'vendor/remaining'], function(Handlebars, Remaining) { +// Formats a timestamp +define('helpers/formatTime', ['underscore','handlebars', 'moment', 'utils/i18n'], + function(_, Handlebars, moment, i18n) { 'use strict'; - function formatTime(seconds, options) { - if (seconds === Infinity) - return '∞'; - else if (!seconds || seconds <= 0) - return '-'; + function formatTime(time, format) { + if (time === -1) + return i18n.gettext('unkown'); + else if (time === -2) + return i18n.gettext('unlimited'); - // TODO: digital or written string - return Remaining.getStringDigital(seconds, window.dates); + if (!_.isString(format)) + format = 'lll'; + + return moment(time).format(format); } Handlebars.registerHelper('formatTime', formatTime); diff --git a/pyload/web/app/scripts/helpers/formatTimeLeft.js b/pyload/web/app/scripts/helpers/formatTimeLeft.js new file mode 100644 index 000000000..dafeda3e2 --- /dev/null +++ b/pyload/web/app/scripts/helpers/formatTimeLeft.js @@ -0,0 +1,17 @@ +// Format seconds in human readable format +define('helpers/formatTimeLeft', ['handlebars', 'vendor/remaining'], function(Handlebars, Remaining) { + 'use strict'; + + function formatTimeLeft(seconds, options) { + if (seconds === Infinity) + return '∞'; + else if (!seconds || seconds <= 0) + return '-'; + + // TODO: digital or written string + return Remaining.getStringDigital(seconds, window.dates); + } + + Handlebars.registerHelper('formatTimeLeft', formatTimeLeft); + return formatTimeLeft; +});
\ No newline at end of file diff --git a/pyload/web/app/scripts/models/Account.js b/pyload/web/app/scripts/models/Account.js index 9cfc1c0c1..e2cc4f9ec 100644 --- a/pyload/web/app/scripts/models/Account.js +++ b/pyload/web/app/scripts/models/Account.js @@ -5,7 +5,7 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], function($ // TODO // generated, not submitted - idAttribute: 'user', + idAttribute: 'loginname', defaults: { plugin: null, @@ -30,8 +30,31 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], function($ }, - save: function(options) { - options = App.apiRequest('updateAccountInfo', {account: this.toJSON()}, options); + fetch: function(options) { + var refresh = _.has(options, 'refresh') && options.refresh; + options = App.apiRequest('getAccountInfo', + {plugin: this.get('plugin'), + loginname: this.get('loginname'), refresh: refresh}, options); + + return Backbone.Model.prototype.fetch.call(this, options); + }, + + setPassword: function(password, options) { + options = App.apiRequest('updateAccount', + {plugin: this.get('plugin'), loginname: this.get('loginname'), password: password}, options); + + return $.ajax(options); + }, + + save: function() { + // On success wait 1sec and trigger event to reload info + var options = App.apiRequest('updateAccountInfo', {account: this.toJSON()}, { + success: function() { + _.delay(function() { + App.vent.trigger('accounts:updated'); + }, 1000); + } + }); return $.ajax(options); }, diff --git a/pyload/web/app/scripts/views/abstract/modalView.js b/pyload/web/app/scripts/views/abstract/modalView.js index 65bc0a3c8..b6d9f0eab 100644 --- a/pyload/web/app/scripts/views/abstract/modalView.js +++ b/pyload/web/app/scripts/views/abstract/modalView.js @@ -83,6 +83,8 @@ define(['jquery', 'backbone', 'underscore', 'omniwindow'], function($, Backbone, }, renderContent: function() { + if (this.model) + return this.model.toJSON(); return {}; }, diff --git a/pyload/web/app/scripts/views/accounts/accountEdit.js b/pyload/web/app/scripts/views/accounts/accountEdit.js new file mode 100644 index 000000000..b9109390b --- /dev/null +++ b/pyload/web/app/scripts/views/accounts/accountEdit.js @@ -0,0 +1,37 @@ +define(['jquery', 'underscore', 'app', 'views/abstract/modalView', 'hbs!tpl/accounts/editAccount'], + function($, _, App, modalView, template) { + 'use strict'; + return modalView.extend({ + + events: { + 'click .btn-save': 'save', + 'submit form': 'save' + }, + + template: template, + + initialize: function() { + // Inherit parent events + this.events = _.extend({}, modalView.prototype.events, this.events); + }, + + onRender: function() { + }, + + save: function() { + var password = this.$('#password').val(); + if (password !== '') { + this.model.setPassword(password); + } + + this.hide(); + return false; + }, + + onShow: function() { + }, + + onHide: function() { + } + }); + });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/accounts/accountView.js b/pyload/web/app/scripts/views/accounts/accountView.js index 7d1f04315..123327a27 100644 --- a/pyload/web/app/scripts/views/accounts/accountView.js +++ b/pyload/web/app/scripts/views/accounts/accountView.js @@ -9,10 +9,39 @@ define(['jquery', 'underscore', 'backbone', 'app', 'hbs!tpl/accounts/account'], template: template, events: { - 'click .btn-danger': 'deleteAccount' + 'click .btn-success': 'toggle', + 'click .btn-blue': 'edit', + 'click .btn-yellow': 'refresh', + 'click .btn-danger': 'remove' }, - deleteAccount: function() { + modelEvents: { + 'change': 'render' + }, + + modal: null, + + toggle: function() { + this.model.set('activated', !this.model.get('activated')); + this.model.save(); + }, + + edit: function() { + // TODO: clean the modal on view close + var self = this; + _.requireOnce(['views/accounts/accountEdit'], function(Modal) { + if (self.modal === null) + self.modal = new Modal({model: self.model}); + + self.modal.show(); + }); + }, + + refresh: function() { + this.model.fetch({refresh: true}); + }, + + remove: function() { this.model.destroy(); } }); diff --git a/pyload/web/app/scripts/views/dashboard/fileView.js b/pyload/web/app/scripts/views/dashboard/fileView.js index ce91a5f38..ed2d2ea40 100644 --- a/pyload/web/app/scripts/views/dashboard/fileView.js +++ b/pyload/web/app/scripts/views/dashboard/fileView.js @@ -1,4 +1,4 @@ -define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'views/abstract/itemView', 'helpers/formatTime', 'hbs!tpl/dashboard/file'], +define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'views/abstract/itemView', 'helpers/formatTimeLeft', 'hbs!tpl/dashboard/file'], function($, Backbone, _, App, Api, ItemView, formatTime, template) { 'use strict'; |