2013-06-22 09:24:24 +03:00
|
|
|
'use strict';
|
2013-06-25 02:41:59 +03:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'app',
|
|
|
|
'marionette',
|
2013-09-11 09:33:47 +03:00
|
|
|
'Commands/CommandController',
|
|
|
|
'Shared/Actioneer'
|
|
|
|
], function (App, Marionette, CommandController, Actioneer) {
|
2013-06-25 02:41:59 +03: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-29 02:19:00 +03:00
|
|
|
|
2013-09-11 09:33:47 +03:00
|
|
|
if (!this.model.get('title')) {
|
2013-06-29 02:19:00 +03:00
|
|
|
this.$el.addClass('btn-icon-only');
|
|
|
|
}
|
2013-09-11 09:33:47 +03:00
|
|
|
|
|
|
|
var command = this.model.get('command');
|
|
|
|
if (command) {
|
|
|
|
Actioneer.bindToCommand({
|
|
|
|
command: {name: command},
|
|
|
|
element: this.$el
|
|
|
|
});
|
|
|
|
}
|
2013-06-25 02:41:59 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function () {
|
2013-09-11 09:33:47 +03:00
|
|
|
|
|
|
|
if (this.$el.hasClass('disabled')) {
|
|
|
|
return;
|
2013-06-25 02:41:59 +03:00
|
|
|
}
|
2013-09-11 09:33:47 +03:00
|
|
|
|
|
|
|
this.invokeCallback();
|
|
|
|
this.invokeRoute();
|
|
|
|
this.invokeCommand();
|
2013-06-25 02:41:59 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
invokeCommand: function () {
|
|
|
|
var command = this.model.get('command');
|
|
|
|
if (command) {
|
2013-09-11 09:33:47 +03:00
|
|
|
CommandController.Execute(command);
|
2013-06-25 02:41:59 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
invokeRoute: function () {
|
|
|
|
var route = this.model.get('route');
|
|
|
|
if (route) {
|
|
|
|
|
|
|
|
require(
|
|
|
|
[
|
|
|
|
'Router'
|
|
|
|
], function () {
|
|
|
|
App.Router.navigate(route, {trigger: true});
|
2013-05-12 02:39:32 +03:00
|
|
|
});
|
2013-06-25 02:41:59 +03:00
|
|
|
}
|
|
|
|
},
|
2013-05-11 23:51:32 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
invokeCallback: function () {
|
2013-05-11 23:51:32 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
if (!this.model.ownerContext) {
|
|
|
|
throw 'ownerContext must be set.';
|
|
|
|
}
|
2013-05-11 23:51:32 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
var callback = this.model.get('callback');
|
|
|
|
if (callback) {
|
|
|
|
callback.call(this.model.ownerContext);
|
|
|
|
}
|
2013-08-31 06:08:19 +03:00
|
|
|
}
|
2013-06-25 02:41:59 +03:00
|
|
|
});
|
2013-05-11 23:51:32 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|