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) { initialize(o) {
this.config = o.config || {}; const config = o.config || {};
this.config = config;
this.coll = o.coll || null; this.coll = o.coll || null;
this.pfx = this.config.stylePrefix || ''; this.pfx = config.stylePrefix || '';
this.ppfx = this.config.pStylePrefix || ''; this.ppfx = config.pStylePrefix || '';
this.em = this.config.em; this.em = config.em;
this.listenTo(this.model, 'change:active', this.updateStatus); this.listenTo(this.model, 'change:active', this.updateStatus);
}, },
@ -84,7 +85,8 @@ module.exports = require('backbone').View.extend({
* @private * @private
*/ */
changeStatus() { 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 * @private
*/ */
updateStatus() { updateStatus() {
var chkOn = 'fa-check-square-o'; const { model, $el } = this;
var chkOff = 'fa-square-o'; 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 (model.get('active')) {
$chk.removeClass(chkOff).addClass(chkOn);
if (this.model.get('active')) { $el.removeClass('opac50');
this.$chk.removeClass(chkOff).addClass(chkOn);
this.$el.removeClass('opac50');
} else { } else {
this.$chk.removeClass(chkOn).addClass(chkOff); $chk.removeClass(chkOn).addClass(chkOff);
this.$el.addClass('opac50'); $el.addClass('opac50');
} }
}, },

24
src/selector_manager/view/ClassTagsView.js

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

Loading…
Cancel
Save