Browse Source

Update model value on target change in style manager

pull/312/head
Artur Arseniev 9 years ago
parent
commit
8326cc097e
  1. 2
      src/style_manager/view/PropertiesView.js
  2. 23
      src/style_manager/view/PropertyView.js
  3. 8
      test/specs/style_manager/model/Models.js
  4. 6
      test/specs/style_manager/view/PropertyView.js

2
src/style_manager/view/PropertiesView.js

@ -15,7 +15,7 @@ module.exports = Backbone.View.extend({
this.pfx = this.config.stylePrefix || ''; this.pfx = this.config.stylePrefix || '';
this.target = o.target || {}; this.target = o.target || {};
this.propTarget = o.propTarget || {}; this.propTarget = o.propTarget || {};
this.onChange = o.onChange || {}; this.onChange = o.onChange;
this.onInputRender = o.onInputRender || {}; this.onInputRender = o.onInputRender || {};
this.customValue = o.customValue || {}; this.customValue = o.customValue || {};
}, },

23
src/style_manager/view/PropertyView.js

@ -40,7 +40,7 @@ module.exports = Backbone.View.extend({
this.ppfx = this.config.pStylePrefix || ''; this.ppfx = this.config.pStylePrefix || '';
this.target = o.target || {}; this.target = o.target || {};
this.propTarget = o.propTarget || {}; this.propTarget = o.propTarget || {};
this.onChange = o.onChange || {}; this.onChange = o.onChange;
this.onInputRender = o.onInputRender || {}; this.onInputRender = o.onInputRender || {};
this.customValue = o.customValue || {}; this.customValue = o.customValue || {};
const model = this.model; const model = this.model;
@ -183,9 +183,9 @@ module.exports = Backbone.View.extend({
status = ''; status = '';
} }
// Maybe in some cases I should set here a value on the model (silently) model.set('value', value, {silent: 1});
this.setValue(value, 1); this.setValue(value, 1);
this.model.set('status', status); model.set('status', status);
if (em) { if (em) {
em.trigger('styleManager:change', this); em.trigger('styleManager:change', this);
@ -298,16 +298,12 @@ module.exports = Backbone.View.extend({
const onChange = this.onChange; const onChange = this.onChange;
this.setValue(value); this.setValue(value);
if (!target) {
return;
}
// Check if component is allowed to be styled // Check if component is allowed to be styled
if (!this.isTargetStylable() || !this.isComponentStylable()) { if (!target || !this.isTargetStylable() || !this.isComponentStylable()) {
return; return;
} }
if (onChange && typeof onChange === "function") { if (onChange) {
onChange(target, this, opt); onChange(target, this, opt);
} else { } else {
this.updateTargetStyle(value, null, opt); this.updateTargetStyle(value, null, opt);
@ -382,9 +378,10 @@ module.exports = Backbone.View.extend({
}, },
/** /**
* Set value to the input * Set the value to property input
* @param {String} value * @param {String} value
* @param {Boolean} force * @param {Boolean} force
* @private
* */ * */
setValue(value, force) { setValue(value, force) {
const model = this.model; const model = this.model;
@ -398,8 +395,6 @@ module.exports = Backbone.View.extend({
const input = this.$input; const input = this.$input;
input && input.val(v); input && input.val(v);
//this.model.set({value: v}, {silent: true});
}, },
updateVisibility() { updateVisibility() {

8
test/specs/style_manager/model/Models.js

@ -140,14 +140,6 @@ module.exports = {
expect(obj.has('property')).toEqual(true); expect(obj.has('property')).toEqual(true);
}); });
it('Has no properties', () => {
expect(obj.get('properties').length).toEqual(0);
});
it('Has no layers', () => {
expect(obj.get('layers').length).toEqual(0);
});
}); });
describe('Properties', () => { describe('Properties', () => {

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

@ -75,12 +75,6 @@ module.exports = {
expect(view.model.get('value')).toEqual(propValue); expect(view.model.get('value')).toEqual(propValue);
}); });
// Tests getValueForTarget()
it('Get value for target', () => {
view.model.set('value', propValue);
expect(view.getValueForTarget()).toEqual(propValue);
});
// Tests valueChanged() -> ... // Tests valueChanged() -> ...
it('Update input on value change', () => { it('Update input on value change', () => {
view.model.set('value', propValue); view.model.set('value', propValue);

Loading…
Cancel
Save