Browse Source

Update stack property in style manager

no-jquery
Artur Arseniev 9 years ago
parent
commit
146a00fd7d
  1. 10
      src/style_manager/model/Properties.js
  2. 8
      src/style_manager/model/PropertyStack.js
  3. 8
      src/style_manager/view/LayerView.js
  4. 20
      src/style_manager/view/LayersView.js
  5. 60
      src/style_manager/view/PropertyStackView.js

10
src/style_manager/model/Properties.js

@ -86,6 +86,16 @@ module.exports = require('backbone').Collection.extend(TypeableCollection).exten
} }
], ],
deepClone() {
const collection = this.clone();
collection.reset(collection.map(model => {
const cloned = model.clone();
cloned.typeView = model.typeView;
return cloned;
}));
return collection;
},
getFullValue() { getFullValue() {
let result = ''; let result = '';
this.each(model => result += `${model.getFullValue()} `); this.each(model => result += `${model.getFullValue()} `);

8
src/style_manager/model/PropertyStack.js

@ -18,13 +18,7 @@ module.exports = Property.extend({
}, },
getFullValue() { getFullValue() {
if (this.get('detached')) { return this.get('detached') ? '' : this.get('layers').getFullValue();
return '';
}
const layers = this.get('layers');
let val = layers.length ? layers.pluck('value').join(', ') : '';
return val.trim();
}, },
}); });

8
src/style_manager/view/LayerView.js

@ -32,6 +32,7 @@ module.exports = Backbone.View.extend({
this.config = o.config || {}; this.config = o.config || {};
this.pfx = this.config.stylePrefix || ''; this.pfx = this.config.stylePrefix || '';
this.sorter = o.sorter || null; this.sorter = o.sorter || null;
this.propsConfig = o.propsConfig || {};
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.valueChanged);
this.listenTo(model, 'change:active', this.updateVisibility); this.listenTo(model, 'change:active', this.updateVisibility);
@ -206,12 +207,17 @@ module.exports = Backbone.View.extend({
render() { render() {
const PropertiesView = require('./PropertiesView'); const PropertiesView = require('./PropertiesView');
const propsConfig = this.propsConfig;
const className = `${this.pfx}layer`; const className = `${this.pfx}layer`;
const model = this.model; const model = this.model;
const el = this.el; const el = this.el;
console.log(propsConfig);
const properties = new PropertiesView({ const properties = new PropertiesView({
collection: model.get('properties'), collection: model.get('properties'),
config: this.config config: this.config,
customValue: propsConfig.customValue,
propTarget: propsConfig.propTarget,
onChange: propsConfig.onChange,
}).render().el; }).render().el;
el.innerHTML = this.template(model); el.innerHTML = this.template(model);
el.className = className; el.className = className;

20
src/style_manager/view/LayersView.js

@ -9,6 +9,7 @@ module.exports = Backbone.View.extend({
this.preview = o.preview; this.preview = o.preview;
this.pfx = this.config.stylePrefix || ''; this.pfx = this.config.stylePrefix || '';
this.ppfx = this.config.pStylePrefix || ''; this.ppfx = this.config.pStylePrefix || '';
this.propsConfig = o.propsConfig;
let pfx = this.pfx; let pfx = this.pfx;
let ppfx = this.ppfx; let ppfx = this.ppfx;
let collection = this.collection; let collection = this.collection;
@ -55,6 +56,10 @@ module.exports = Backbone.View.extend({
* */ * */
addToCollection(model, fragmentEl, index) { addToCollection(model, fragmentEl, index) {
var fragment = fragmentEl || null; var fragment = fragmentEl || null;
const stackModel = this.stackModel;
const config = this.config;
const sorter = this.sorter;
const propsConfig = this.propsConfig;
if(typeof this.preview !== 'undefined'){ if(typeof this.preview !== 'undefined'){
model.set('preview', this.preview); model.set('preview', this.preview);
@ -62,15 +67,16 @@ module.exports = Backbone.View.extend({
var view = new LayerView({ var view = new LayerView({
model, model,
stackModel: this.stackModel, config,
config: this.config, sorter,
sorter: this.sorter stackModel,
propsConfig
}); });
var rendered = view.render().el; var rendered = view.render().el;
if(fragment){ if (fragment) {
fragment.appendChild( rendered ); fragment.appendChild(rendered);
}else{ } else {
if(typeof index != 'undefined'){ if(typeof index != 'undefined'){
var method = 'before'; var method = 'before';
// If the added model is the last of collection // If the added model is the last of collection

60
src/style_manager/view/PropertyStackView.js

@ -1,6 +1,5 @@
var PropertyCompositeView = require('./PropertyCompositeView'); const PropertyCompositeView = require('./PropertyCompositeView');
var Layers = require('./../model/Layers'); const LayersView = require('./LayersView');
var LayersView = require('./LayersView');
module.exports = PropertyCompositeView.extend({ module.exports = PropertyCompositeView.extend({
@ -58,14 +57,9 @@ module.exports = PropertyCompositeView.extend({
indexChanged(e) { indexChanged(e) {
const model = this.model; const model = this.model;
this.getLayers().active(model.get('stackIndex')); this.getLayers().active(model.get('stackIndex'));
/*
var layer = this.getLayers().at(model.get('stackIndex'));
layer.set('props', this.$props);
model.get('properties').each(prop => prop.trigger('targetUpdated'));
*/
}, },
/** @inheritDoc */ /** @inheritDoc *
getPropsConfig(opts) { getPropsConfig(opts) {
const model = this.model; const model = this.model;
const detached = model.get('detached'); const detached = model.get('detached');
@ -87,7 +81,7 @@ module.exports = PropertyCompositeView.extend({
propVal += (propVal ? ',' : '') + val; propVal += (propVal ? ',' : '') + val;
} }
}); });
*/ **
view.updateTargetStyle(propVal, null, opt); view.updateTargetStyle(propVal, null, opt);
} else { } else {
model.set('value', model.getFullValue(), opt); model.set('value', model.getFullValue(), opt);
@ -96,6 +90,7 @@ module.exports = PropertyCompositeView.extend({
return result; return result;
}, },
*/
/** /**
* Extract string from the composite value of the target * Extract string from the composite value of the target
@ -134,7 +129,7 @@ module.exports = PropertyCompositeView.extend({
/** /**
* Build composite value * Build composite value
* @private * @private
* */ * *
build(...args) { build(...args) {
let value = ''; let value = '';
let values = {}; let values = {};
@ -157,17 +152,15 @@ module.exports = PropertyCompositeView.extend({
const layerModel = this.getLayers().at(stackIndex); const layerModel = this.getLayers().at(stackIndex);
layerModel && layerModel.set({values, value}); layerModel && layerModel.set({values, value});
}, },
*/
addLayer() {
addLayer(e) {
const model = this.model; const model = this.model;
const layers = this.getLayers(); const layers = this.getLayers();
const layer = layers.add({ const layer = layers.add({
name: 'New', name: 'New',
properties: model.get('properties') properties: model.get('properties').deepClone(),
}); });
console.log('Props ', model.get('properties'), 'layer props', layer.get('properties'));
//layer.set('value', model.getDefaultValue(1));
// In detached mode inputValueChanged will add new 'layer value' // In detached mode inputValueChanged will add new 'layer value'
// to all subprops // to all subprops
@ -207,16 +200,38 @@ module.exports = PropertyCompositeView.extend({
* @return self * @return self
* */ * */
renderLayers() { renderLayers() {
const self = this;
const model = this.model;
const fieldEl = this.el.querySelector(`.${this.pfx}field`); const fieldEl = this.el.querySelector(`.${this.pfx}field`);
const layers = new LayersView({ const layers = new LayersView({
// TODO Here I should put the onChange method
collection: this.getLayers(), collection: this.getLayers(),
stackModel: this.model, stackModel: model,
preview: this.model.get('preview'), preview: model.get('preview'),
config: this.config config: this.config,
propsConfig: {
propTarget: this.propTarget,
// Things to do when a single sub-property is changed
onChange(el, view, opt) {
const subModel = view.model;
if (model.get('detached')) {
const subProp = subModel.get('property');
const values = self.getLayers().getPropertyValues(subProp);
view.updateTargetStyle(propVal, null, opt);
} else {
model.set('value', model.getFullValue(), opt);
}
},
// How to get a value on a single sub-property.
// eg. When the target is updated
customValue(property, mIndex) {
return self.valueOnIndex(mIndex, property);
}
}
}).render().el; }).render().el;
fieldEl.appendChild(layers); fieldEl.appendChild(layers);
this.$props.hide();
}, },
/** /**
@ -304,8 +319,7 @@ module.exports = PropertyCompositeView.extend({
}, },
onRender(...args) { onRender(...args) {
PropertyCompositeView.prototype.onRender.apply(this, args); //PropertyCompositeView.prototype.onRender.apply(this, args);
//this.refreshLayers();
this.renderLayers(); this.renderLayers();
}, },

Loading…
Cancel
Save