2013-06-22 06:24:24 +00:00
|
|
|
'use strict';
|
2013-06-24 23:41:59 +00:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'app',
|
|
|
|
'marionette',
|
2013-09-11 06:33:47 +00:00
|
|
|
'Commands/CommandController',
|
|
|
|
'Shared/Actioneer'
|
|
|
|
], function (App, Marionette, CommandController, Actioneer) {
|
2013-06-24 23:41:59 +00:00
|
|
|
|
|
|
|
return Marionette.ItemView.extend({
|
|
|
|
template : 'Shared/Toolbar/ButtonTemplate',
|
|
|
|
className: 'btn',
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click': 'onClick'
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
this.storageKey = this.model.get('menuKey') + ':' + this.model.get('key');
|
|
|
|
},
|
|
|
|
|
|
|
|
onRender: function () {
|
|
|
|
if (this.model.get('active')) {
|
|
|
|
this.$el.addClass('active');
|
|
|
|
this.invokeCallback();
|
|
|
|
}
|
2013-06-28 23:19:00 +00:00
|
|
|
|
2013-09-11 06:33:47 +00:00
|
|
|
if (!this.model.get('title')) {
|
2013-06-28 23:19:00 +00:00
|
|
|
this.$el.addClass('btn-icon-only');
|
|
|
|
}
|
2013-09-11 06:33:47 +00:00
|
|
|
|
|
|
|
var command = this.model.get('command');
|
|
|
|
if (command) {
|
|
|
|
Actioneer.bindToCommand({
|
|
|
|
command: {name: command},
|
|
|
|
element: this.$el
|
|
|
|
});
|
|
|
|
}
|
2013-06-24 23:41:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function () {
|
2013-09-11 06:33:47 +00:00
|
|
|
|
|
|
|
if (this.$el.hasClass('disabled')) {
|
|
|
|
return;
|
2013-06-24 23:41:59 +00:00
|
|
|
}
|
2013-09-11 06:33:47 +00:00
|
|
|
|
|
|
|
this.invokeCallback();
|
|
|
|
this.invokeRoute();
|
|
|
|
this.invokeCommand();
|
2013-06-24 23:41:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
invokeCommand: function () {
|
|
|
|
var command = this.model.get('command');
|
|
|
|
if (command) {
|
2013-09-11 06:33:47 +00:00
|
|
|
CommandController.Execute(command);
|
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-05-11 20:51:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|