summaryrefslogtreecommitdiffstats
path: root/module/web/static/js/views/configSectionView.js
diff options
context:
space:
mode:
Diffstat (limited to 'module/web/static/js/views/configSectionView.js')
-rw-r--r--module/web/static/js/views/configSectionView.js75
1 files changed, 75 insertions, 0 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