diff options
Diffstat (limited to 'module/web/static/js/views')
-rw-r--r-- | module/web/static/js/views/configSectionView.js | 75 | ||||
-rw-r--r-- | module/web/static/js/views/input/inputView.js | 4 | ||||
-rw-r--r-- | module/web/static/js/views/input/textInput.js | 2 | ||||
-rw-r--r-- | module/web/static/js/views/settingsView.js | 40 |
4 files changed, 99 insertions, 22 deletions
diff --git a/module/web/static/js/views/configSectionView.js b/module/web/static/js/views/configSectionView.js new file mode 100644 index 000000000..0bbe61653 --- /dev/null +++ b/module/web/static/js/views/configSectionView.js @@ -0,0 +1,75 @@ +define(['jquery', 'underscore', 'backbone', 'app', './input/inputLoader'], + function($, _, Backbone, App, load_input) { + + // Renders settings over view page + return Backbone.View.extend({ + + tagName: 'div', + + template: _.compile($("#template-config").html()), + templateItem: _.compile($("#template-config-item").html()), + + // Will only render one time with further attribute updates + rendered: false, + + events: { + 'click .btn-primary': 'submit' + // TODO cancel + }, + + initialize: function() { + }, + + // TODO: correct cleanup after building up so many views and models + render: function() { + if (!this.rendered) { + this.$el.html(this.template(this.model.toJSON())); + + // TODO: only render one time, rest of the attributes set manually + + // initialize the popover + this.$('.page-header a').popover({ + placement: 'left', + 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 input = new inputView(item.get('input'), item.get('value'), + item.get('default_value'), item.get('description')).render(); + item.set('inputView', input); + + self.listenTo(input, 'change', _.bind(self.render, self)); + el.find('.controls').append(input.el); + container.append(el); + }); + this.rendered = true; + } + // Enable button if something is changed + if (this.model.hasChanges()) + this.$('.btn-primary').removeClass('disabled'); + else + this.$('.btn-primary').addClass('disabled'); + + // Mark all inputs that are modified + _.each(this.model.get('items'), function(item) { + var input = item.get('inputView'); + var el = input.$el.parent().parent(); + if (item.isChanged()) + el.addClass('info'); + else + el.removeClass('info'); + }); + + return this; + }, + + submit: function() { + + } + + }); + });
\ No newline at end of file diff --git a/module/web/static/js/views/input/inputView.js b/module/web/static/js/views/input/inputView.js index 56087c516..ed78d2d30 100644 --- a/module/web/static/js/views/input/inputView.js +++ b/module/web/static/js/views/input/inputView.js @@ -22,15 +22,15 @@ define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) { render: function() { this.renderInput(); - // data for tooltips if (this.description && this.tooltip) { this.$el.data('content', this.description); + // TODO: render default value in popup? // this.$el.data('title', "TODO: title"); this.$el.popover({ placement: 'right', trigger: 'hover', - delay: { show: 500, hide: 100 } +// delay: { show: 500, hide: 100 } }); } diff --git a/module/web/static/js/views/input/textInput.js b/module/web/static/js/views/input/textInput.js index 36cdf9f06..3a6631a0b 100644 --- a/module/web/static/js/views/input/textInput.js +++ b/module/web/static/js/views/input/textInput.js @@ -5,7 +5,7 @@ define(['jquery', 'backbone', 'underscore', './inputView'], function($, Backbone // TODO tagName: 'input', events: { - 'keypress': 'onChange', + 'keyup': 'onChange', 'focus': 'showTooltip', 'focusout': 'hideTooltip' }, diff --git a/module/web/static/js/views/settingsView.js b/module/web/static/js/views/settingsView.js index 00c4b3739..5350f5a94 100644 --- a/module/web/static/js/views/settingsView.js +++ b/module/web/static/js/views/settingsView.js @@ -1,13 +1,11 @@ -define(['jquery', 'underscore', 'backbone', 'app', './input/inputLoader', 'models/ConfigHolder'], - function($, _, Backbone, App, load_input, ConfigHolder) { +define(['jquery', 'underscore', 'backbone', 'app', 'models/ConfigHolder', './configSectionView'], + function($, _, Backbone, App, ConfigHolder, configSectionView) { // Renders settings over view page return Backbone.View.extend({ el: "#content", templateMenu: _.compile($("#template-menu").html()), - templateConfig: _.compile($("#template-config").html()), - templateConfigItem: _.compile($("#template-config-item").html()), events: { 'click .settings-menu li > a': 'change_section' @@ -23,9 +21,12 @@ define(['jquery', 'underscore', 'backbone', 'app', './input/inputLoader', 'model config: null, isLoading: false, + initialize: function() { this.menu = this.$('.settings-menu'); - this.content = this.$('#settings-form'); + this.content = this.$('.setting-box > form'); + // set a height with css so animations will work + this.content.height(this.content.height()); this.refresh(); console.log("Settings initialized"); @@ -80,21 +81,22 @@ define(['jquery', 'underscore', 'backbone', 'app', './input/inputLoader', 'model }, show: function() { - // TODO: better refactor in separate views - this.content.html(this.templateConfig(this.config.toJSON())); - var container = this.content.find('.control-content'); - var items = this.config.get('items'); - var self = this; - _.each(items, function(item) { - var el = $('<div>').html(self.templateConfigItem(item.toJSON())); - var inputView = load_input("todo"); - el.find('.controls').append( - new inputView(item.get('input'), item.get('value'), - item.get('default_value'), item.get('description')).render().el); - container.append(el); + // TODO: better cleaning of old views + var oldHeight = this.content.height(); + this.content.empty(); + this.content.css('display', 'block'); + // reset the height + this.content.css('height', ''); + // append the new element + this.content.append(new configSectionView({model: this.config}).render().el); + // get the new height + var height = this.content.height(); + // set the old height again + this.content.height(oldHeight); + this.content.animate({ + opacity: 'show', + height: height }); - - this.content.fadeIn(); }, failure: function() { |