Browse Source

Update checkbox trait

refactor-traits
Artur Arseniev 7 years ago
parent
commit
6ce017dc6f
  1. 2
      dist/css/grapes.min.css
  2. 5
      src/styles/scss/_gjs_inputs.scss
  3. 6
      src/trait_manager/view/TraitCheckboxView.js
  4. 20
      src/trait_manager/view/TraitView.js

2
dist/css/grapes.min.css

File diff suppressed because one or more lines are too long

5
src/styles/scss/_gjs_inputs.scss

@ -191,8 +191,10 @@
/* ??? */ /* ??? */
.#{$app-prefix}field-checkbox { .#{$app-prefix}field-checkbox {
padding: 0; padding: 0;
width: auto !important; width: 17px;
height: 17px; height: 17px;
display: block;
cursor: pointer;
input { input {
display: none; display: none;
@ -348,7 +350,6 @@
height: 14px; height: 14px;
margin: 0 5px; margin: 0 5px;
width: 6px; width: 6px;
cursor: pointer;
} }
.#{$app-prefix}add-trasp { .#{$app-prefix}add-trasp {

6
src/trait_manager/view/TraitCheckboxView.js

@ -5,8 +5,8 @@ export default TraitView.extend({
appendInput: 0, appendInput: 0,
templateInput() { templateInput() {
const { ppfx } = this; const { ppfx, clsField } = this;
return `<label data-input> return `<label class="${clsField}" data-input>
<i class="${ppfx}chk-icon"></i> <i class="${ppfx}chk-icon"></i>
</label>`; </label>`;
}, },
@ -16,7 +16,7 @@ export default TraitView.extend({
* @private * @private
*/ */
onChange() { onChange() {
const value = this.getInputEl().checked; const value = this.getInputElem().checked;
this.model.set('value', this.getCheckedValue(value)); this.model.set('value', this.getCheckedValue(value));
}, },

20
src/trait_manager/view/TraitView.js

@ -50,7 +50,7 @@ export default Backbone.View.extend({
* @private * @private
*/ */
onChange() { onChange() {
this.model.set('value', this.getInputEl().value); this.model.set('value', this.getInputElem().value);
}, },
getValueForTarget() { getValueForTarget() {
@ -58,7 +58,8 @@ export default Backbone.View.extend({
}, },
setInputValue(value) { setInputValue(value) {
this.getInputEl().value = value; const el = this.getInputElem();
el && (el.value = value);
}, },
/** /**
@ -66,15 +67,11 @@ export default Backbone.View.extend({
* @private * @private
*/ */
onValueChange(model, value, opts = {}) { onValueChange(model, value, opts = {}) {
const mod = this.model;
const trg = this.target;
const name = mod.get('name');
if (opts.fromTarget) { if (opts.fromTarget) {
this.setInputValue(mod.get('value')); this.setInputValue(model.get('value'));
} else { } else {
const value = this.getValueForTarget(); const val = this.getValueForTarget();
mod.setTargetValue(value, opts); model.setTargetValue(val, opts);
} }
}, },
@ -149,6 +146,11 @@ export default Backbone.View.extend({
return this.$input.get(0); return this.$input.get(0);
}, },
getInputElem() {
const { input, $input } = this;
return input || ($input && $input.get(0));
},
getModelValue() { getModelValue() {
let value; let value;
const model = this.model; const model = this.model;

Loading…
Cancel
Save