Browse Source

Update parsing in property model

pull/312/head
Artur Arseniev 9 years ago
parent
commit
101d39c7ee
  1. 10
      src/style_manager/model/Property.js
  2. 11
      src/style_manager/view/PropertyFileView.js
  3. 21
      src/style_manager/view/PropertyStackView.js
  4. 4
      src/style_manager/view/PropertyView.js

10
src/style_manager/model/Property.js

@ -37,10 +37,18 @@ module.exports = require('backbone').Model.extend({
return value; return value;
} }
const args = [];
let valueStr = value + ''; let valueStr = value + '';
let start = valueStr.indexOf('(') + 1; let start = valueStr.indexOf('(') + 1;
let end = valueStr.lastIndexOf(')'); let end = valueStr.lastIndexOf(')');
return valueStr.substring(start, end); args.push(start);
// Will try even if the last closing parentheses is not found
if (end >= 0) {
args.push(end);
}
return String.prototype.substring.apply(valueStr, args);
}, },
/** /**

11
src/style_manager/view/PropertyFileView.js

@ -6,12 +6,13 @@ module.exports = PropertyView.extend({
templateField() { templateField() {
const pfx = this.pfx; const pfx = this.pfx;
const ppfx = this.ppfx; const ppfx = this.ppfx;
const assetsLabel = this.config.assetsLabel || 'Images';
return ` return `
<div class="${pfx}field ${pfx}file"> <div class="${pfx}field ${pfx}file">
<div id='${pfx}input-holder'> <div id='${pfx}input-holder'>
<div class="${pfx}btn-c"> <div class="${pfx}btn-c">
<button class="${pfx}btn" id="${pfx}images" type="button"> <button class="${pfx}btn" id="${pfx}images" type="button">
${this.assets} ${assetsLabel}
</button> </button>
</div> </div>
<div style="clear:both;"></div> <div style="clear:both;"></div>
@ -27,10 +28,10 @@ module.exports = PropertyView.extend({
initialize(options) { initialize(options) {
PropertyView.prototype.initialize.apply(this, arguments); PropertyView.prototype.initialize.apply(this, arguments);
this.assets = this.target.get('assets'); this.assets = this.target.get('assets');
this.modal = this.target.get('Modal'); this.modal = this.target.get('Modal');
this.am = this.target.get('AssetManager'); this.am = this.target.get('AssetManager');
this.className = this.className + ' '+ this.pfx +'file'; this.className = this.className + ' '+ this.pfx +'file';
this.events['click #'+this.pfx+'close'] = 'removeFile'; this.events['click #'+this.pfx+'close'] = 'removeFile';
this.events['click #'+this.pfx+'images'] = 'openAssetManager'; this.events['click #'+this.pfx+'images'] = 'openAssetManager';
this.delegateEvents(); this.delegateEvents();

21
src/style_manager/view/PropertyStackView.js

@ -19,11 +19,13 @@ module.exports = PropertyCompositeView.extend({
initialize(o) { initialize(o) {
PropertyCompositeView.prototype.initialize.apply(this, arguments); PropertyCompositeView.prototype.initialize.apply(this, arguments);
this.model.set('stackIndex', null); const model = this.model;
this.className = this.pfx + 'property '+ this.pfx +'stack'; const pfx = this.pfx;
this.events['click #'+this.pfx+'add'] = 'addLayer'; model.set('stackIndex', null);
this.listenTo( this.model ,'change:stackIndex', this.indexChanged); this.className = `${pfx}property ${pfx}stack`;
this.listenTo( this.model ,'updateValue', this.valueUpdated); this.events[`click #${pfx}add`] = 'addLayer';
this.listenTo(model, 'change:stackIndex', this.indexChanged);
this.listenTo(model, 'updateValue', this.valueUpdated);
this.delegateEvents(); this.delegateEvents();
}, },
@ -111,16 +113,19 @@ module.exports = PropertyCompositeView.extend({
* @private * @private
* */ * */
valueOnIndex(index, propView) { valueOnIndex(index, propView) {
var result = null; let result;
var layerIndex = this.model.get('stackIndex'); const model = this.model;
const layerIndex = model.get('stackIndex');
// If detached the value in this case is stacked, eg. substack-prop: 1px, 2px, 3px... // If detached the value in this case is stacked, eg. substack-prop: 1px, 2px, 3px...
if (this.model.get('detached')) { if (model.get('detached')) {
var targetValue = propView.getTargetValue({ignoreCustomValue: 1}); var targetValue = propView.getTargetValue({ignoreCustomValue: 1});
var valist = (targetValue + '').split(','); var valist = (targetValue + '').split(',');
result = valist[layerIndex]; result = valist[layerIndex];
result = result ? result.trim() : propView.getDefaultValue(); result = result ? result.trim() : propView.getDefaultValue();
result = propView.model.parseValue(result); result = propView.model.parseValue(result);
//console.log('Value property', propView.model.get('property'), ': ', result, 'TARGET-VALUE', targetValue, valist);
} else { } else {
var aStack = this.getStackValues(); var aStack = this.getStackValues();
var strVar = aStack[layerIndex]; var strVar = aStack[layerIndex];

4
src/style_manager/view/PropertyView.js

@ -231,6 +231,10 @@ module.exports = Backbone.View.extend({
} }
result = target.getStyle()[model.get('property')]; result = target.getStyle()[model.get('property')];
// TODO when stack type asks the sub-property (in valueOnIndex method)
// to provide its target value and its detached, I should avoid parsing
// (at least is wrong applying 'functionName' cleaning)
result = model.parseValue(result); result = model.parseValue(result);
if (!result && !opts.ignoreDefault) { if (!result && !opts.ignoreDefault) {

Loading…
Cancel
Save