Browse Source

Refactor buttons and adjust run command order

drag-rules
Artur Arseniev 7 years ago
parent
commit
587590d344
  1. 2
      src/panels/index.js
  2. 15
      src/panels/model/Buttons.js
  3. 17
      src/panels/view/ButtonView.js

2
src/panels/index.js

@ -216,7 +216,7 @@ module.exports = () => {
active() {
this.getPanels().each(p => {
p.get('buttons').each(btn => {
if (btn.get('active')) btn.trigger('updateActive');
btn.get('active') && btn.trigger('updateActive');
});
});
},

15
src/panels/model/Buttons.js

@ -27,13 +27,12 @@ module.exports = Backbone.Collection.extend({
*
* @return void
* */
deactivateAll(ctx) {
var context = ctx || '';
this.forEach((model, index) => {
if (model.get('context') == context) {
model.set('active', false);
if (model.get('buttons').length)
model.get('buttons').deactivateAll(context);
deactivateAll(ctx, sender) {
const context = ctx || '';
this.forEach(model => {
if (model.get('context') == context && model !== sender) {
model.set('active', false, { silent: 1 });
model.trigger('updateActive', { fromCollection: 1 });
}
});
},
@ -49,8 +48,6 @@ module.exports = Backbone.Collection.extend({
this.forEach((model, index) => {
if (model.get('context') == context) {
model.set('disable', true);
if (model.get('buttons').length)
model.get('buttons').disableAllButtons(context);
}
});
},

17
src/panels/view/ButtonView.js

@ -75,33 +75,32 @@ module.exports = Backbone.View.extend({
*
* @return void
* */
updateActive() {
const { model, commands, em } = this;
updateActive(opts = {}) {
const { model, commands, $el, activeCls } = this;
const { fromCollection } = opts;
const context = model.get('context');
const options = model.get('options');
const commandName = model.get('command');
let command = {};
var editor = em && em.get ? em.get('Editor') : null;
var commandName = model.get('command');
var cmdIsFunc = isFunction(commandName);
if (commands && isString(commandName)) {
command = commands.get(commandName) || {};
} else if (cmdIsFunc) {
} else if (isFunction(commandName)) {
command = commands.create({ run: commandName });
} else if (commandName !== null && isObject(commandName)) {
command = commands.create(commandName);
}
if (model.get('active')) {
model.collection.deactivateAll(context);
!fromCollection && model.collection.deactivateAll(context, model);
model.set('active', true, { silent: true }).trigger('checkActive');
commands.runCommand(command, { ...options, sender: model });
// Disable button if the command has no stop method
command.noStop && model.set('active', false);
} else {
this.$el.removeClass(this.activeCls);
model.collection.deactivateAll(context);
!fromCollection && model.collection.deactivateAll(context, model);
$el.removeClass(activeCls);
commands.stopCommand(command, { ...options, sender: model, force: 1 });
}
},

Loading…
Cancel
Save