summaryrefslogtreecommitdiffstats
path: root/pyload/web/app/scripts/models
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/web/app/scripts/models')
-rw-r--r--pyload/web/app/scripts/models/Account.js21
-rw-r--r--pyload/web/app/scripts/models/ConfigItem.js13
2 files changed, 27 insertions, 7 deletions
diff --git a/pyload/web/app/scripts/models/Account.js b/pyload/web/app/scripts/models/Account.js
index d98d3374f..94893f3e2 100644
--- a/pyload/web/app/scripts/models/Account.js
+++ b/pyload/web/app/scripts/models/Account.js
@@ -1,4 +1,4 @@
-define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], function($, Backbone, _, App, Api) {
+define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', './ConfigItem'], function($, Backbone, _, App, Api, ConfigItem) {
'use strict';
return Backbone.Model.extend({
@@ -30,6 +30,15 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], function($
},
+ parse: function(resp) {
+ // Convert config to models
+ resp.config = _.map(resp.config, function(item) {
+ return new ConfigItem(item);
+ });
+
+ return resp;
+ },
+
fetch: function(options) {
var refresh = _.has(options, 'refresh') && options.refresh;
options = App.apiRequest('getAccountInfo',
@@ -47,8 +56,16 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], function($
},
save: function() {
+ // use changed config items only
+ var data = this.toJSON();
+ data.config = _.map(_.filter(data.config, function(c){
+ return c.isChanged();
+ }), function(c) {
+ return c.prepareSave();
+ });
+
// On success wait 1sec and trigger event to reload info
- var options = App.apiRequest('updateAccountInfo', {account: this.toJSON()}, {
+ var options = App.apiRequest('updateAccountInfo', {account: data}, {
success: function() {
_.delay(function() {
App.vent.trigger('account:updated');
diff --git a/pyload/web/app/scripts/models/ConfigItem.js b/pyload/web/app/scripts/models/ConfigItem.js
index ecb44cbbc..8c75f45f6 100644
--- a/pyload/web/app/scripts/models/ConfigItem.js
+++ b/pyload/web/app/scripts/models/ConfigItem.js
@@ -4,6 +4,8 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'],
return Backbone.Model.extend({
+ idAttribute: 'name',
+
defaults: {
name: '',
label: '',
@@ -29,11 +31,12 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'],
if (this.get('inputView'))
this.set('value', this.get('inputView').getVal());
- var data = this.toJSON();
- delete data.inputView;
- delete data.description;
-
- return data;
+ // These values are enough to be handled correctly
+ return {
+ name: this.get('name'),
+ value: this.get('value'),
+ '@class': this.get('@class')
+ };
}
});
}); \ No newline at end of file