Browse Source

Allow to pass `el` prop to Buttons from Panels module

pull/3147/head
Artur Arseniev 6 years ago
parent
commit
f59bfa2c3e
  1. 21
      src/panels/view/ButtonView.js
  2. 11
      src/panels/view/ButtonsView.js

21
src/panels/view/ButtonView.js

@ -89,6 +89,8 @@ export default Backbone.View.extend({
const commandName = model.get('command'); const commandName = model.get('command');
let command = {}; let command = {};
if (!commandName) return;
if (commands && isString(commandName)) { if (commands && isString(commandName)) {
command = commands.get(commandName) || {}; command = commands.get(commandName) || {};
} else if (isFunction(commandName)) { } else if (isFunction(commandName)) {
@ -133,15 +135,15 @@ export default Backbone.View.extend({
* @return void * @return void
* */ * */
clicked(e) { clicked(e) {
if (this.model.get('bntsVis')) return; const { model } = this;
if (model.get('bntsVis') || model.get('disable') || !model.get('command'))
if (this.model.get('disable')) return; return;
this.toggleActive(); this.toggleActive();
}, },
toggleActive() { toggleActive() {
const { model } = this; const { model, em } = this;
const { active, togglable } = model.attributes; const { active, togglable } = model.attributes;
if (active && !togglable) return; if (active && !togglable) return;
@ -149,19 +151,18 @@ export default Backbone.View.extend({
model.set('active', !active); model.set('active', !active);
// If the stop is requested // If the stop is requested
var command = this.em.get('Commands').get('select-comp');
if (active) { if (active) {
if (model.get('runDefaultCommand')) this.em.runDefault(); if (model.get('runDefaultCommand')) em.runDefault();
} else { } else {
if (model.get('stopDefaultCommand')) this.em.stopDefault(); if (model.get('stopDefaultCommand')) em.stopDefault();
} }
}, },
render() { render() {
const label = this.model.get('label'); const { model } = this;
const label = model.get('label');
const { $el } = this; const { $el } = this;
$el.empty(); !model.get('el') && $el.empty();
this.updateAttributes(); this.updateAttributes();
label && $el.append(label); label && $el.append(label);
this.checkActive(); this.checkActive();

11
src/panels/view/ButtonsView.js

@ -31,15 +31,16 @@ export default Backbone.View.extend({
* @return Object Object created * @return Object Object created
* */ * */
addToCollection(model, fragmentEl) { addToCollection(model, fragmentEl) {
var fragment = fragmentEl || null; const fragment = fragmentEl || null;
var viewObject = ButtonView; const viewObject = ButtonView;
const el = model.get('el');
var view = new viewObject({ const view = new viewObject({
el,
model, model,
config: this.config, config: this.config,
parentM: this.parentM parentM: this.parentM
}); });
var rendered = view.render().el; const rendered = view.render().el;
if (fragment) { if (fragment) {
fragment.appendChild(rendered); fragment.appendChild(rendered);

Loading…
Cancel
Save