Browse Source

Fix issues with color traits. Fixes #1104

pull/1130/head
Artur Arseniev 8 years ago
parent
commit
b02744cb8e
  1. 2
      dist/css/grapes.min.css
  2. 5
      src/domain_abstract/ui/Input.js
  3. 5
      src/domain_abstract/ui/InputColor.js
  4. 2
      src/styles/scss/_gjs_traits.scss
  5. 17
      src/trait_manager/model/Trait.js
  6. 17
      src/trait_manager/view/TraitColorView.js
  7. 27
      src/trait_manager/view/TraitView.js
  8. 2
      src/trait_manager/view/TraitsView.js

2
dist/css/grapes.min.css

File diff suppressed because one or more lines are too long

5
src/domain_abstract/ui/Input.js

@ -55,7 +55,8 @@ module.exports = Backbone.View.extend({
*/ */
handleChange(e) { handleChange(e) {
e.stopPropagation(); e.stopPropagation();
this.model.set('value', this.getInputEl().value); const value = this.getInputEl().value;
this.model.set({ value }, { fromInput: 1 });
this.elementUpdated(); this.elementUpdated();
}, },
@ -65,7 +66,7 @@ module.exports = Backbone.View.extend({
*/ */
getInputEl() { getInputEl() {
if (!this.inputEl) { if (!this.inputEl) {
const plh = this.model.get('defaults'); const plh = this.model.get('defaults') || '';
this.inputEl = $(`<input type="text" placeholder="${plh}">`); this.inputEl = $(`<input type="text" placeholder="${plh}">`);
} }

5
src/domain_abstract/ui/InputColor.js

@ -1,3 +1,5 @@
import { isUndefined } from 'underscore';
require('utils/ColorPicker'); require('utils/ColorPicker');
const Input = require('./Input'); const Input = require('./Input');
const $ = Backbone.$; const $ = Backbone.$;
@ -31,7 +33,8 @@ module.exports = Input.extend({
*/ */
setValue(val, opts = {}) { setValue(val, opts = {}) {
const model = this.model; const model = this.model;
const value = val || model.get('defaults'); const def = model.get('defaults');
const value = !isUndefined(val) ? val : !isUndefined(def) ? def : '';
const inputEl = this.getInputEl(); const inputEl = this.getInputEl();
const colorEl = this.getColorEl(); const colorEl = this.getColorEl();
const valueClr = value != 'none' ? value : ''; const valueClr = value != 'none' ? value : '';

2
src/styles/scss/_gjs_traits.scss

@ -26,6 +26,8 @@
.#{$app-prefix}label { .#{$app-prefix}label {
width: 30%; width: 30%;
text-align: left; text-align: left;
text-overflow: ellipsis;
overflow: hidden;
} }
.#{$app-prefix}field { .#{$app-prefix}field {

17
src/trait_manager/model/Trait.js

@ -40,21 +40,28 @@ module.exports = require('backbone').Model.extend({
getTargetValue() { getTargetValue() {
const name = this.get('name'); const name = this.get('name');
const target = this.target; const target = this.target;
const prop = this.get('changeProp'); let value;
if (target) return prop ? target.get(name) : target.getAttributes()[name];
if (this.get('changeProp')) {
value = target.get(name);
} else {
value = target.getAttributes()[name];
}
return !isUndefined(value) ? value : '';
}, },
setTargetValue(value) { setTargetValue(value, opts = {}) {
const target = this.target; const target = this.target;
const name = this.get('name'); const name = this.get('name');
if (isUndefined(value)) return; if (isUndefined(value)) return;
if (this.get('changeProp')) { if (this.get('changeProp')) {
target.set(name, value); target.set(name, value, opts);
} else { } else {
const attrs = { ...target.get('attributes') }; const attrs = { ...target.get('attributes') };
attrs[name] = value; attrs[name] = value;
target.set('attributes', attrs); target.set('attributes', attrs, opts);
} }
}, },

17
src/trait_manager/view/TraitColorView.js

@ -9,19 +9,20 @@ module.exports = TraitView.extend({
*/ */
getInputEl() { getInputEl() {
if (!this.$input) { if (!this.$input) {
var value = this.getModelValue(); const model = this.model;
var inputColor = new InputColor({ const value = this.getModelValue();
const inputColor = new InputColor({
model,
target: this.config.em, target: this.config.em,
contClass: this.ppfx + 'field-color', contClass: this.ppfx + 'field-color',
model: this.model,
ppfx: this.ppfx ppfx: this.ppfx
}); });
this.input = inputColor.render(); const input = inputColor.render();
this.$input = this.input.colorEl; this.$input = input.colorEl;
value = value || ''; input.setValue(value, { fromTarget: 1 });
this.model.set('value', value).trigger('change:value'); this.input = input;
this.input.setValue(value);
} }
return this.$input.get(0); return this.$input.get(0);
}, },

27
src/trait_manager/view/TraitView.js

@ -27,6 +27,7 @@ module.exports = Backbone.View.extend({
this.inputhClass = this.ppfx + 'input-holder'; this.inputhClass = this.ppfx + 'input-holder';
model.off('change:value', this.onValueChange); model.off('change:value', this.onValueChange);
this.listenTo(model, 'change:value', this.onValueChange); this.listenTo(model, 'change:value', this.onValueChange);
model.view = this;
this.tmpl = this.tmpl =
'<div class="' + '<div class="' +
this.fieldClass + this.fieldClass +
@ -64,7 +65,7 @@ module.exports = Backbone.View.extend({
this.setInputValue(mod.get('value')); this.setInputValue(mod.get('value'));
} else { } else {
const value = this.getValueForTarget(); const value = this.getValueForTarget();
mod.setTargetValue(value); mod.setTargetValue(value, opts);
} }
}, },
@ -73,8 +74,9 @@ module.exports = Backbone.View.extend({
* @private * @private
*/ */
renderLabel() { renderLabel() {
const label = this.getLabel();
this.$el.html( this.$el.html(
'<div class="' + this.labelClass + '">' + this.getLabel() + '</div>' `<div class="${this.labelClass}" title="${label}">${label}</div>`
); );
}, },
@ -96,17 +98,12 @@ module.exports = Backbone.View.extend({
*/ */
getInputEl() { getInputEl() {
if (!this.$input) { if (!this.$input) {
var md = this.model; const md = this.model;
var trg = this.target;
var name = md.get('name');
const plh = md.get('placeholder') || md.get('default') || ''; const plh = md.get('placeholder') || md.get('default') || '';
const type = md.get('type') || 'text'; const type = md.get('type') || 'text';
const attrs = trg.get('attributes');
const min = md.get('min'); const min = md.get('min');
const max = md.get('max'); const max = md.get('max');
const value = md.get('changeProp') const value = this.getModelValue();
? trg.get(name)
: md.get('value') || attrs[name];
const input = $(`<input type="${type}" placeholder="${plh}">`); const input = $(`<input type="${type}" placeholder="${plh}">`);
if (value) { if (value) {
@ -127,19 +124,19 @@ module.exports = Backbone.View.extend({
}, },
getModelValue() { getModelValue() {
var value; let value;
var model = this.model; const model = this.model;
var target = this.target; const target = this.target;
var name = model.get('name'); const name = model.get('name');
if (model.get('changeProp')) { if (model.get('changeProp')) {
value = target.get(name); value = target.get(name);
} else { } else {
var attrs = target.get('attributes'); const attrs = target.get('attributes');
value = model.get('value') || attrs[name]; value = model.get('value') || attrs[name];
} }
return value; return !isUndefined(value) ? value : '';
}, },
/** /**

2
src/trait_manager/view/TraitsView.js

@ -23,7 +23,7 @@ module.exports = DomainViews.extend({
this.pfx = config.stylePrefix || ''; this.pfx = config.stylePrefix || '';
this.ppfx = config.pStylePrefix || ''; this.ppfx = config.pStylePrefix || '';
this.className = this.pfx + 'traits'; this.className = this.pfx + 'traits';
const toListen = 'component:selected component:update:traits'; const toListen = 'component:selected';
this.listenTo(this.em, toListen, this.updatedCollection); this.listenTo(this.em, toListen, this.updatedCollection);
this.updatedCollection(); this.updatedCollection();
}, },

Loading…
Cancel
Save