2013-06-22 06:24:24 +00:00
|
|
|
'use strict';
|
2013-06-24 23:41:59 +00:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'app',
|
|
|
|
'marionette',
|
2013-08-31 03:08:19 +00:00
|
|
|
'Shared/Actioneer',
|
2013-06-24 23:41:59 +00:00
|
|
|
'Shared/Messenger'
|
2013-08-31 03:08:19 +00:00
|
|
|
], function (App, Marionette, Actioneer, Messenger) {
|
2013-06-24 23:41:59 +00:00
|
|
|
|
|
|
|
return Marionette.ItemView.extend({
|
|
|
|
template : 'Shared/Toolbar/ButtonTemplate',
|
|
|
|
className: 'btn',
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click': 'onClick'
|
|
|
|
},
|
|
|
|
|
|
|
|
ui: {
|
|
|
|
icon: '.x-icon'
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
this.storageKey = this.model.get('menuKey') + ':' + this.model.get('key');
|
|
|
|
this.idle = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onRender: function () {
|
|
|
|
if (this.model.get('active')) {
|
|
|
|
this.$el.addClass('active');
|
|
|
|
this.invokeCallback();
|
|
|
|
}
|
2013-06-28 23:19:00 +00:00
|
|
|
|
|
|
|
if(!this.model.get('title')){
|
|
|
|
this.$el.addClass('btn-icon-only');
|
|
|
|
}
|
2013-06-24 23:41:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function () {
|
|
|
|
if (this.idle) {
|
|
|
|
this.invokeCallback();
|
|
|
|
this.invokeRoute();
|
|
|
|
this.invokeCommand();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
invokeCommand: function () {
|
|
|
|
var command = this.model.get('command');
|
|
|
|
if (command) {
|
|
|
|
this.idle = false;
|
|
|
|
|
2013-08-31 03:08:19 +00:00
|
|
|
Actioneer.ExecuteCommand({
|
|
|
|
command : command,
|
|
|
|
button : this.$el,
|
|
|
|
element : this.ui.icon,
|
|
|
|
errorMessage : this.model.get('errorMessage'),
|
|
|
|
successMessage: this.model.get('successMessage'),
|
|
|
|
always : this._commandAlways,
|
|
|
|
context : this
|
2013-06-24 23:41:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
invokeRoute: function () {
|
|
|
|
var route = this.model.get('route');
|
|
|
|
if (route) {
|
|
|
|
|
|
|
|
require(
|
|
|
|
[
|
|
|
|
'Router'
|
|
|
|
], function () {
|
|
|
|
App.Router.navigate(route, {trigger: true});
|
2013-05-11 23:39:32 +00:00
|
|
|
});
|
2013-06-24 23:41:59 +00:00
|
|
|
}
|
|
|
|
},
|
2013-05-11 20:51:32 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
invokeCallback: function () {
|
2013-05-11 20:51:32 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
if (!this.model.ownerContext) {
|
|
|
|
throw 'ownerContext must be set.';
|
|
|
|
}
|
2013-05-11 20:51:32 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
var callback = this.model.get('callback');
|
|
|
|
if (callback) {
|
|
|
|
callback.call(this.model.ownerContext);
|
|
|
|
}
|
2013-08-31 03:08:19 +00:00
|
|
|
},
|
2013-06-24 23:41:59 +00:00
|
|
|
|
2013-08-31 03:08:19 +00:00
|
|
|
_commandAlways: function () {
|
|
|
|
if (!this.isClosed) {
|
|
|
|
this.idle = true;
|
|
|
|
}
|
|
|
|
}
|
2013-06-24 23:41:59 +00:00
|
|
|
});
|
2013-05-11 20:51:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|