|
|
|
@ -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 }); |
|
|
|
} |
|
|
|
}, |
|
|
|
|