diff options
Diffstat (limited to 'module/web/static')
| -rw-r--r-- | module/web/static/js/models/ConfigHolder.js | 14 | ||||
| -rw-r--r-- | module/web/static/js/models/ConfigItem.js | 15 | ||||
| -rw-r--r-- | module/web/static/js/views/configSectionView.js | 22 | ||||
| -rw-r--r-- | module/web/static/js/views/settingsView.js | 14 | 
4 files changed, 54 insertions, 11 deletions
| diff --git a/module/web/static/js/models/ConfigHolder.js b/module/web/static/js/models/ConfigHolder.js index abd1b9f0a..37af9d70e 100644 --- a/module/web/static/js/models/ConfigHolder.js +++ b/module/web/static/js/models/ConfigHolder.js @@ -25,7 +25,19 @@ define(['jquery', 'backbone', 'underscore', 'app', './ConfigItem'],              },              save: function(options) { -                // TODO +                var config = this.toJSON(); +                var items = []; +                // Convert changed items to json +                _.each(config.items, function(item) { +                    if (item.isChanged()) { +                        items.push(item.prepareSave()); +                    } +                }); +                config.items = items; + +                options = App.apiRequest('saveConfig', {config: config}, options); + +                return $.ajax(options);              },              parse: function(resp) { diff --git a/module/web/static/js/models/ConfigItem.js b/module/web/static/js/models/ConfigItem.js index 636c28851..01a85c6cc 100644 --- a/module/web/static/js/models/ConfigItem.js +++ b/module/web/static/js/models/ConfigItem.js @@ -8,7 +8,7 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'],                  label: "",                  description: "",                  input: null, -                default_valie: null, +                default_value: null,                  value: null,                  // additional attributes                  inputView: null @@ -21,6 +21,19 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'],              isChanged: function() {                  return this.get('inputView') && this.get('inputView').getVal() !== this.get('value'); +            }, + +            // set new value and return json +            prepareSave: function() { +                // set the new value +                if (this.get('inputView')) +                    this.set('value', this.get('inputView').getVal()); + +                var data = this.toJSON(); +                delete data.inputView; +                delete data.description; + +                return data;              }          });      });
\ No newline at end of file diff --git a/module/web/static/js/views/configSectionView.js b/module/web/static/js/views/configSectionView.js index 346f7b949..949493731 100644 --- a/module/web/static/js/views/configSectionView.js +++ b/module/web/static/js/views/configSectionView.js @@ -1,8 +1,8 @@ -define(['jquery', 'underscore', 'backbone', 'app', './input/inputLoader'], -    function($, _, Backbone, App, load_input) { +define(['jquery', 'underscore', 'backbone', 'app', './abstract/itemView', './input/inputLoader'], +    function($, _, Backbone, App, itemView, load_input) {          // Renders settings over view page -        return Backbone.View.extend({ +        return itemView.extend({              tagName: 'div', @@ -18,9 +18,9 @@ define(['jquery', 'underscore', 'backbone', 'app', './input/inputLoader'],              },              initialize: function() { +                this.listenTo(this.model, 'destroy', this.destroy);              }, -            // TODO: correct cleanup after building up so many views and models              render: function() {                  if (!this.rendered) {                      this.$el.html(this.template(this.model.toJSON())); @@ -28,14 +28,14 @@ define(['jquery', 'underscore', 'backbone', 'app', './input/inputLoader'],                      // initialize the popover                      this.$('.page-header a').popover({                          placement: 'left', -                        trigger: 'hover' +//                        trigger: 'hover'                      });                      var container = this.$('.control-content');                      var self = this;                      _.each(this.model.get('items'), function(item) {                          var el = $('<div>').html(self.templateItem(item.toJSON())); -                        var inputView = load_input("todo"); +                        var inputView = load_input(item.get('input'));                          var input = new inputView(item.get('input'), item.get('value'),                              item.get('default_value'), item.get('description')).render();                          item.set('inputView', input); @@ -65,9 +65,19 @@ define(['jquery', 'underscore', 'backbone', 'app', './input/inputLoader'],                  return this;              }, +            onDestroy: function(){ +                // TODO: correct cleanup after building up so many views and models +            }, +              submit: function(e) {                  e.stopPropagation();                  // TODO: success / failure popups +                var self = this; +                this.model.save({success: function(){ +                    console.log("saved"); +                    self.render(); +                }}); +              },              reset: function(e) { diff --git a/module/web/static/js/views/settingsView.js b/module/web/static/js/views/settingsView.js index 5350f5a94..3b8308f19 100644 --- a/module/web/static/js/views/settingsView.js +++ b/module/web/static/js/views/settingsView.js @@ -19,6 +19,7 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ConfigHolder', './con              // currently open configHolder              config: null, +            lastConfig: null,              isLoading: false, @@ -56,6 +57,7 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ConfigHolder', './con                  if (this.config && this.config.get('name') === name)                      return; +                this.lastConfig = this.config;                  this.config = new ConfigHolder({name: name});                  this.loading(); @@ -81,10 +83,16 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ConfigHolder', './con              },              show: function() { -                // TODO: better cleaning of old views -                var oldHeight = this.content.height(); -                this.content.empty(); +                // TODO animations are bit sloppy                  this.content.css('display', 'block'); +                var oldHeight = this.content.height(); + +                // this will destroy the old view +                if (this.lastConfig) +                    this.lastConfig.trigger('destroy'); +                else +                    this.content.empty(); +                  // reset the height                  this.content.css('height', '');                  // append the new element | 
