Skip to content

Commit

Permalink
Update parsing in property model
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Sep 14, 2017
1 parent 3f1be03 commit 101d39c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
10 changes: 9 additions & 1 deletion src/style_manager/model/Property.js
Expand Up @@ -37,10 +37,18 @@ module.exports = require('backbone').Model.extend({
return value;
}

const args = [];
let valueStr = value + '';
let start = valueStr.indexOf('(') + 1;
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);
},

/**
Expand Down
11 changes: 6 additions & 5 deletions src/style_manager/view/PropertyFileView.js
Expand Up @@ -6,12 +6,13 @@ module.exports = PropertyView.extend({
templateField() {
const pfx = this.pfx;
const ppfx = this.ppfx;
const assetsLabel = this.config.assetsLabel || 'Images';
return `
<div class="${pfx}field ${pfx}file">
<div id='${pfx}input-holder'>
<div class="${pfx}btn-c">
<button class="${pfx}btn" id="${pfx}images" type="button">
${this.assets}
${assetsLabel}
</button>
</div>
<div style="clear:both;"></div>
Expand All @@ -27,10 +28,10 @@ module.exports = PropertyView.extend({

initialize(options) {
PropertyView.prototype.initialize.apply(this, arguments);
this.assets = this.target.get('assets');
this.modal = this.target.get('Modal');
this.am = this.target.get('AssetManager');
this.className = this.className + ' '+ this.pfx +'file';
this.assets = this.target.get('assets');
this.modal = this.target.get('Modal');
this.am = this.target.get('AssetManager');
this.className = this.className + ' '+ this.pfx +'file';
this.events['click #'+this.pfx+'close'] = 'removeFile';
this.events['click #'+this.pfx+'images'] = 'openAssetManager';
this.delegateEvents();
Expand Down
21 changes: 13 additions & 8 deletions src/style_manager/view/PropertyStackView.js
Expand Up @@ -19,11 +19,13 @@ module.exports = PropertyCompositeView.extend({

initialize(o) {
PropertyCompositeView.prototype.initialize.apply(this, arguments);
this.model.set('stackIndex', null);
this.className = this.pfx + 'property '+ this.pfx +'stack';
this.events['click #'+this.pfx+'add'] = 'addLayer';
this.listenTo( this.model ,'change:stackIndex', this.indexChanged);
this.listenTo( this.model ,'updateValue', this.valueUpdated);
const model = this.model;
const pfx = this.pfx;
model.set('stackIndex', null);
this.className = `${pfx}property ${pfx}stack`;
this.events[`click #${pfx}add`] = 'addLayer';
this.listenTo(model, 'change:stackIndex', this.indexChanged);
this.listenTo(model, 'updateValue', this.valueUpdated);
this.delegateEvents();
},

Expand Down Expand Up @@ -111,16 +113,19 @@ module.exports = PropertyCompositeView.extend({
* @private
* */
valueOnIndex(index, propView) {
var result = null;
var layerIndex = this.model.get('stackIndex');
let result;
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 (this.model.get('detached')) {
if (model.get('detached')) {
var targetValue = propView.getTargetValue({ignoreCustomValue: 1});
var valist = (targetValue + '').split(',');
result = valist[layerIndex];
result = result ? result.trim() : propView.getDefaultValue();
result = propView.model.parseValue(result);

//console.log('Value property', propView.model.get('property'), ': ', result, 'TARGET-VALUE', targetValue, valist);
} else {
var aStack = this.getStackValues();
var strVar = aStack[layerIndex];
Expand Down
4 changes: 4 additions & 0 deletions src/style_manager/view/PropertyView.js
Expand Up @@ -231,6 +231,10 @@ module.exports = Backbone.View.extend({
}

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);

if (!result && !opts.ignoreDefault) {
Expand Down

0 comments on commit 101d39c

Please sign in to comment.