From 8af6f7520280dc45c0dcf8e46623c8e853057ebb Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 3 May 2016 03:36:53 +0200 Subject: [PATCH] Move unnecessary stuff from PropertyView --- src/style_manager/view/PropertyIntegerView.js | 4 ++++ src/style_manager/view/PropertyRadioView.js | 23 +++++++++++++------ src/style_manager/view/PropertySelectView.js | 5 ++++ src/style_manager/view/PropertyView.js | 16 +++---------- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/style_manager/view/PropertyIntegerView.js b/src/style_manager/view/PropertyIntegerView.js index 05dd09a3f..93dfaaed5 100644 --- a/src/style_manager/view/PropertyIntegerView.js +++ b/src/style_manager/view/PropertyIntegerView.js @@ -10,6 +10,10 @@ define(['backbone','./PropertyView', 'text!./../templates/propertyInteger.html'] initialize: function(options) { PropertyView.prototype.initialize.apply(this, arguments); _.bindAll(this, 'moveIncrement', 'upIncrement'); + this.min = this.model.get('min') || this.model.get('min')===0 ? this.model.get('min') : -5000; + this.max = this.model.get('max') || this.model.get('max')===0 ? this.model.get('max') : 5000; + this.units = this.model.get('units'); + this.unit = this.model.get('unit') ? this.model.get('unit') : (this.units.length ? this.units[0] : ''); this.events['click .'+this.pfx+'u-arrow'] = 'upArrowClick'; this.events['click .'+this.pfx+'d-arrow'] = 'downArrowClick'; this.events['mousedown .'+this.pfx+'int-arrows'] = 'downIncrement'; diff --git a/src/style_manager/view/PropertyRadioView.js b/src/style_manager/view/PropertyRadioView.js index b85e63f65..feab47ccc 100644 --- a/src/style_manager/view/PropertyRadioView.js +++ b/src/style_manager/view/PropertyRadioView.js @@ -1,17 +1,26 @@ -define(['backbone','./PropertyView', 'text!./../templates/propertyRadio.html'], +define(['backbone','./PropertyView', 'text!./../templates/propertyRadio.html'], function (Backbone, PropertyView, propertyTemplate) { - /** + /** * @class PropertyRadioView * */ return PropertyView.extend({ - + template: _.template(propertyTemplate), - + initialize: function(options) { PropertyView.prototype.initialize.apply(this, arguments); - this.className = this.className + ' '+ this.pfx +'list'; + this.list = this.model.get('list'); + this.className = this.className + ' '+ this.pfx +'list'; + }, + + /** + * Fired when the input value is updated + */ + valueUpdated: function(){ + if(this.$input) + this.model.set('value', this.$el.find('input:checked').val()); }, - + /** @inheritdoc */ renderInput: function() { var pfx = this.pfx; @@ -33,7 +42,7 @@ define(['backbone','./PropertyView', 'text!./../templates/propertyRadio.html'], } this.setValue(this.componentValue); }, - + /** @inheritdoc */ setValue: function(value){ var v = this.model.get('value') || this.defaultValue; diff --git a/src/style_manager/view/PropertySelectView.js b/src/style_manager/view/PropertySelectView.js index 1305c340c..5ecd63042 100644 --- a/src/style_manager/view/PropertySelectView.js +++ b/src/style_manager/view/PropertySelectView.js @@ -7,6 +7,11 @@ define(['backbone','./PropertyView', 'text!./../templates/propertySelect.html'], template: _.template(propertyTemplate), + initialize: function(options) { + PropertyView.prototype.initialize.apply(this, arguments); + this.list = this.model.get('list'); + }, + /** @inheritdoc */ renderInput: function() { var pfx = this.pfx; diff --git a/src/style_manager/view/PropertyView.js b/src/style_manager/view/PropertyView.js index 97f85d161..ebc289f20 100644 --- a/src/style_manager/view/PropertyView.js +++ b/src/style_manager/view/PropertyView.js @@ -8,9 +8,7 @@ define(['backbone', 'text!./../templates/propertyLabel.html', 'text!./../templat template: _.template(propertyTemplate), templateLabel: _.template(propertyLabel), - events: { - 'change': 'valueUpdated', - }, + events: {'change': 'valueUpdated'}, initialize: function(o) { this.config = o.config || {}; @@ -23,11 +21,6 @@ define(['backbone', 'text!./../templates/propertyLabel.html', 'text!./../templat this.func = this.model.get('functionName'); this.defaultValue = this.model.get('defaults'); this.property = this.model.get('property'); - this.units = this.model.get('units'); - this.min = this.model.get('min') || this.model.get('min')===0 ? this.model.get('min') : -5000; - this.max = this.model.get('max') || this.model.get('max')===0 ? this.model.get('max') : 5000; - this.unit = this.model.get('unit') ? this.model.get('unit') : (this.units.length ? this.units[0] : ''); - this.list = this.model.get('list'); this.input = this.$input = null; this.className = this.pfx + 'property'; this.inputHolderId = '#' + this.pfx + 'input-holder'; @@ -66,9 +59,6 @@ define(['backbone', 'text!./../templates/propertyLabel.html', 'text!./../templat * @return {Boolean} * */ sameValue: function(){ - if(this.property == 'test'){ - console.log('compoVal: ' + this.getComponentValue() + ' modelVal: ' + (this.model.get('value') + this.model.get('unit'))); - } return this.getComponentValue() == (this.model.get('value') + this.model.get('unit')); }, @@ -86,7 +76,7 @@ define(['backbone', 'text!./../templates/propertyLabel.html', 'text!./../templat if(targetProp) this.componentValue = targetProp; else - this.componentValue = this.defaultValue + (this.unit || ''); + this.componentValue = this.defaultValue + (this.unit || ''); // todo model // Check if wrap inside function is required if(this.func){ @@ -118,7 +108,7 @@ define(['backbone', 'text!./../templates/propertyLabel.html', 'text!./../templat }, /** - * Returns value from necessary inputs + * Returns value from inputs * @return {string} */ getValueForTarget: function(){