Browse Source

Refactor class tag view

pull/2062/head
Artur Arseniev 7 years ago
parent
commit
f42ba0d9b7
  1. 30
      src/selector_manager/view/ClassTagView.js
  2. 24
      src/selector_manager/view/ClassTagsView.js

30
src/selector_manager/view/ClassTagView.js

@ -23,11 +23,12 @@ module.exports = require('backbone').View.extend({
},
initialize(o) {
this.config = o.config || {};
const config = o.config || {};
this.config = config;
this.coll = o.coll || null;
this.pfx = this.config.stylePrefix || '';
this.ppfx = this.config.pStylePrefix || '';
this.em = this.config.em;
this.pfx = config.stylePrefix || '';
this.ppfx = config.pStylePrefix || '';
this.em = config.em;
this.listenTo(this.model, 'change:active', this.updateStatus);
},
@ -84,7 +85,8 @@ module.exports = require('backbone').View.extend({
* @private
*/
changeStatus() {
this.model.set('active', !this.model.get('active'));
const { model } = this;
model.set('active', !model.get('active'));
},
/**
@ -105,17 +107,17 @@ module.exports = require('backbone').View.extend({
* @private
*/
updateStatus() {
var chkOn = 'fa-check-square-o';
var chkOff = 'fa-square-o';
const { model, $el } = this;
const chkOn = 'fa-check-square-o';
const chkOff = 'fa-square-o';
const $chk = $el.find('[data-tag-status]');
if (!this.$chk) this.$chk = this.$el.find('#' + this.pfx + 'checkbox');
if (this.model.get('active')) {
this.$chk.removeClass(chkOff).addClass(chkOn);
this.$el.removeClass('opac50');
if (model.get('active')) {
$chk.removeClass(chkOff).addClass(chkOn);
$el.removeClass('opac50');
} else {
this.$chk.removeClass(chkOn).addClass(chkOff);
this.$el.addClass('opac50');
$chk.removeClass(chkOn).addClass(chkOff);
$el.addClass('opac50');
}
},

24
src/selector_manager/view/ClassTagsView.js

@ -166,7 +166,6 @@ module.exports = Backbone.View.extend({
},
getTarget() {
const targetStyle = this.getStyleEmitter().model;
return this.target.getSelected();
},
@ -252,34 +251,30 @@ module.exports = Backbone.View.extend({
* @return {Object} Object created
* @private
* */
addToClasses(model, fragmentEl) {
var fragment = fragmentEl || null;
var view = new ClassTagView({
addToClasses(model, fragmentEl = null) {
const fragment = fragmentEl;
const classes = this.getClasses();
const rendered = new ClassTagView({
model,
config: this.config,
coll: this.collection
});
var rendered = view.render().el;
}).render().el;
if (fragment) fragment.appendChild(rendered);
else this.getClasses().append(rendered);
fragment ? fragment.appendChild(rendered) : classes.append(rendered);
return rendered;
},
/**
* Render the collection of classes
* @return {this}
* @private
*/
renderClasses() {
const frag = document.createDocumentFragment();
const classes = this.getClasses();
classes.empty();
this.collection.each(model => this.addToClasses(model, frag));
classes.get(0) && classes.empty().append(frag);
return this;
classes.append(frag);
},
/**
@ -288,8 +283,7 @@ module.exports = Backbone.View.extend({
* @private
*/
getClasses() {
if (!this.$classes) this.$classes = this.$el.find(`#${this.pfx}tags-c`);
return this.$classes;
return this.$el.find(`#${this.pfx}tags-c`);
},
/**

Loading…
Cancel
Save