Browse Source

Add inputValueChanged and modelValueChanged methods to PropertyView

pull/330/head
Artur Arseniev 9 years ago
parent
commit
8bdbb718c8
  1. 7
      src/style_manager/view/PropertyCompositeView.js
  2. 5
      src/style_manager/view/PropertyIntegerView.js
  3. 13
      src/style_manager/view/PropertyStackView.js
  4. 25
      src/style_manager/view/PropertyView.js
  5. 4
      test/specs/style_manager/view/PropertyView.js

7
src/style_manager/view/PropertyCompositeView.js

@ -20,12 +20,9 @@ module.exports = PropertyView.extend({
this.className = this.className + ' '+ this.pfx +'composite'; this.className = this.className + ' '+ this.pfx +'composite';
}, },
/** inputValueChanged(...args) {
* Fired when the input value is updated
*/
valueUpdated(...args) {
if(!this.model.get('detached')) if(!this.model.get('detached'))
PropertyView.prototype.valueUpdated.apply(this, args); PropertyView.prototype.inputValueChanged.apply(this, args);
}, },
/** /**

5
src/style_manager/view/PropertyIntegerView.js

@ -5,8 +5,9 @@ module.exports = PropertyView.extend({
initialize(options) { initialize(options) {
PropertyView.prototype.initialize.apply(this, arguments); PropertyView.prototype.initialize.apply(this, arguments);
this.listenTo(this.model, 'change:unit', this.valueChanged); const model = this.model;
this.listenTo(this.model, 'el:change', this.elementUpdated); this.listenTo(model, 'change:unit', this.modelValueChanged);
this.listenTo(model, 'el:change', this.elementUpdated);
}, },
renderInput() { renderInput() {

13
src/style_manager/view/PropertyStackView.js

@ -25,7 +25,7 @@ module.exports = PropertyCompositeView.extend({
this.className = `${pfx}property ${pfx}stack`; this.className = `${pfx}property ${pfx}stack`;
this.events[`click #${pfx}add`] = 'addLayer'; this.events[`click #${pfx}add`] = 'addLayer';
this.listenTo(model, 'change:stackIndex', this.indexChanged); this.listenTo(model, 'change:stackIndex', this.indexChanged);
this.listenTo(model, 'updateValue', this.valueUpdated); this.listenTo(model, 'updateValue', this.inputValueChanged);
this.delegateEvents(); this.delegateEvents();
}, },
@ -176,19 +176,16 @@ module.exports = PropertyCompositeView.extend({
const index = layers.indexOf(layer); const index = layers.indexOf(layer);
layer.set('value', this.model.getDefaultValue(1)); layer.set('value', this.model.getDefaultValue(1));
// In detached mode valueUpdated will add new 'layer value' // In detached mode inputValueChanged will add new 'layer value'
// to all subprops // to all subprops
this.valueUpdated(); this.inputValueChanged();
// This will set subprops with a new default values // This will set subprops with a new default values
this.model.set('stackIndex', index); this.model.set('stackIndex', index);
} }
}, },
/** inputValueChanged() {
* Fired when the input value is updated
*/
valueUpdated() {
var model = this.model; var model = this.model;
if (!model.get('detached')) { if (!model.get('detached')) {
@ -311,7 +308,7 @@ module.exports = PropertyCompositeView.extend({
// Avoid updating with detached as it will cause issues on next change // Avoid updating with detached as it will cause issues on next change
if (!detached) { if (!detached) {
this.valueUpdated(); this.inputValueChanged();
} }
this.model.set({stackIndex: null}, {silent: true}); this.model.set({stackIndex: null}, {silent: true});

25
src/style_manager/view/PropertyView.js

@ -14,7 +14,7 @@ module.exports = Backbone.View.extend({
</span> </span>
<b class="${pfx}clear">&Cross;</b> <b class="${pfx}clear">&Cross;</b>
</div> </div>
${this.templateField()} ${this.templateField(model)}
`; `;
}, },
@ -30,7 +30,7 @@ module.exports = Backbone.View.extend({
}, },
events: { events: {
'change': 'valueUpdated' 'change': 'inputValueChanged'
}, },
initialize(o) { initialize(o) {
@ -57,7 +57,7 @@ module.exports = Backbone.View.extend({
this.listenTo(this.propTarget, 'update', this.targetUpdated); this.listenTo(this.propTarget, 'update', this.targetUpdated);
this.listenTo(model, 'destroy remove', this.remove); this.listenTo(model, 'destroy remove', this.remove);
this.listenTo(model, 'change:value', this.valueChanged); this.listenTo(model, 'change:value', this.modelValueChanged);
this.listenTo(model, 'targetUpdated', this.targetUpdated); this.listenTo(model, 'targetUpdated', this.targetUpdated);
this.listenTo(model, 'change:visible', this.updateVisibility); this.listenTo(model, 'change:visible', this.updateVisibility);
this.listenTo(model, 'change:status', this.updateStatus); this.listenTo(model, 'change:status', this.updateStatus);
@ -134,9 +134,10 @@ module.exports = Backbone.View.extend({
}, },
/** /**
* Fired when the input value is updated * Triggers when the value of element input/s is changed, so have to update
* the value of the model which will propogate those changes to the target
*/ */
valueUpdated() { inputValueChanged() {
this.model.set('value', this.getInputValue()); this.model.set('value', this.getInputValue());
this.elementUpdated(); this.elementUpdated();
}, },
@ -284,13 +285,13 @@ module.exports = Backbone.View.extend({
}, },
/** /**
* Triggers when the 'value' of the model changes, so I have to update * Triggers when the `value` of the model changes, so the target and
* the target model * the input element should be updated
* @param {Object} e Events * @param {Object} e Event
* @param {Mixed} val Value * @param {Mixed} val Value
* @param {Object} opt Options * @param {Object} opt Options
* */ * */
valueChanged(e, val, opt) { modelValueChanged(e, val, opt) {
const em = this.config.em; const em = this.config.em;
const model = this.model; const model = this.model;
const value = model.getFullValue(); const value = model.getFullValue();
@ -434,8 +435,8 @@ module.exports = Backbone.View.extend({
render() { render() {
const el = this.el; const el = this.el;
el.innerHTML = this.template(this.model); el.innerHTML = this.template(this.model);
this.renderInput();
el.className = this.className; el.className = this.className;
this.renderInput();
this.updateStatus(); this.updateStatus();
return this; return this;
}, },

4
test/specs/style_manager/view/PropertyView.js

@ -69,13 +69,13 @@ module.exports = {
expect(view.model.get('value')).toNotExist(); expect(view.model.get('value')).toNotExist();
}); });
// Tests valueUpdated() // Tests inputValueChanged()
it('Update model on input change', () => { it('Update model on input change', () => {
view.$input.val(propValue).trigger('change'); view.$input.val(propValue).trigger('change');
expect(view.model.get('value')).toEqual(propValue); expect(view.model.get('value')).toEqual(propValue);
}); });
// Tests valueChanged() -> ... // Tests modelValueChanged() -> ...
it('Update input on value change', () => { it('Update input on value change', () => {
view.model.set('value', propValue); view.model.set('value', propValue);
expect(view.$input.val()).toEqual(propValue); expect(view.$input.val()).toEqual(propValue);

Loading…
Cancel
Save