Browse Source

Remove _.template from SectorView

pull/3677/head
Artur Arseniev 5 years ago
parent
commit
5d22cbfe28
  1. 61
      src/style_manager/view/SectorView.js

61
src/style_manager/view/SectorView.js

@ -1,17 +1,22 @@
import Backbone from 'backbone'; import { View } from 'backbone';
import { template } from 'underscore'; import html from 'utils/html';
import PropertiesView from './PropertiesView'; import PropertiesView from './PropertiesView';
export default Backbone.View.extend({ export default class SectorView extends View {
template: template(` template({ pfx, label }) {
<div class="<%= pfx %>title" data-sector-title> return html`
<i id="<%= pfx %>caret" class="fa"></i> <div class="${pfx}title" data-sector-title>
<%= label %> <i id="${pfx}caret" class="fa"></i>
</div>`), ${label}
</div>
`;
}
events: { events() {
'click [data-sector-title]': 'toggle' return {
}, 'click [data-sector-title]': 'toggle'
};
}
initialize(o) { initialize(o) {
this.config = o.config || {}; this.config = o.config || {};
@ -25,7 +30,7 @@ export default Backbone.View.extend({
this.listenTo(model, 'change:open', this.updateOpen); this.listenTo(model, 'change:open', this.updateOpen);
this.listenTo(model, 'updateVisibility', this.updateVisibility); this.listenTo(model, 'updateVisibility', this.updateVisibility);
this.listenTo(model, 'destroy remove', this.remove); this.listenTo(model, 'destroy remove', this.remove);
}, }
/** /**
* If all properties are hidden this will hide the sector * If all properties are hidden this will hide the sector
@ -38,7 +43,7 @@ export default Backbone.View.extend({
} }
}); });
this.el.style.display = show ? '' : 'none'; this.el.style.display = show ? '' : 'none';
}, }
/** /**
* Update visibility * Update visibility
@ -46,7 +51,7 @@ export default Backbone.View.extend({
updateOpen() { updateOpen() {
if (this.model.get('open')) this.show(); if (this.model.get('open')) this.show();
else this.hide(); else this.hide();
}, }
/** /**
* Show the content of the sector * Show the content of the sector
@ -55,7 +60,7 @@ export default Backbone.View.extend({
this.$el.addClass(this.pfx + 'open'); this.$el.addClass(this.pfx + 'open');
this.getPropertiesEl().style.display = ''; this.getPropertiesEl().style.display = '';
this.$caret.removeClass(this.caretR).addClass(this.caretD); this.$caret.removeClass(this.caretR).addClass(this.caretD);
}, }
/** /**
* Hide the content of the sector * Hide the content of the sector
@ -64,19 +69,20 @@ export default Backbone.View.extend({
this.$el.removeClass(this.pfx + 'open'); this.$el.removeClass(this.pfx + 'open');
this.getPropertiesEl().style.display = 'none'; this.getPropertiesEl().style.display = 'none';
this.$caret.removeClass(this.caretD).addClass(this.caretR); this.$caret.removeClass(this.caretD).addClass(this.caretR);
}, }
getPropertiesEl() { getPropertiesEl() {
return this.$el.find(`.${this.pfx}properties`).get(0); return this.$el.find(`.${this.pfx}properties`).get(0);
}, }
/** /**
* Toggle visibility * Toggle visibility
* */ * */
toggle(e) { toggle(e) {
var v = this.model.get('open') ? 0 : 1; const { model } = this;
this.model.set('open', v); const v = model.get('open') ? 0 : 1;
}, model.set('open', v);
}
render() { render() {
const { pfx, model, em, $el } = this; const { pfx, model, em, $el } = this;
@ -88,19 +94,20 @@ export default Backbone.View.extend({
$el.attr('class', `${pfx}sector ${pfx}sector__${id} no-select`); $el.attr('class', `${pfx}sector ${pfx}sector__${id} no-select`);
this.updateOpen(); this.updateOpen();
return this; return this;
}, }
renderProperties() { renderProperties() {
var objs = this.model.get('properties'); const { model, target, propTarget, config } = this;
const objs = model.get('properties');
if (objs) { if (objs) {
var view = new PropertiesView({ const view = new PropertiesView({
collection: objs, collection: objs,
target: this.target, target,
propTarget: this.propTarget, propTarget,
config: this.config config
}); });
this.$el.append(view.render().el); this.$el.append(view.render().el);
} }
} }
}); }

Loading…
Cancel
Save