4 'libs/text!./template.html'], function($, _, template) {
8 return function(sandbox) {
12 var config = sandbox.getConfig(),
13 userName = config.user && config.user.name,
14 view = $(_.template(template)({
15 userName: userName || gettext('anonymous')
18 view.find('[data-cmd]').click(function(e) {
20 var target = $(e.target);
21 if(target.hasClass('disabled')) {
24 sandbox.publish('cmd.' + $(e.target).attr('data-cmd'));
28 start: function() { sandbox.publish('ready'); },
29 getView: function() {return view;},
30 setCommandEnabled: function(cmd, enabled) {
31 var trigger = view.find('[data-cmd='+cmd+']'),
32 disabledText = trigger.attr('data-disabled-text'),
33 originalContent = trigger.data('originalContent');
34 trigger.toggleClass('disabled', !enabled);
35 if(enabled && originalContent) {
36 trigger.html(originalContent);
37 trigger.removeData('originalContent');
39 if(!enabled && disabledText) {
40 trigger.data('originalContent', trigger.html());
41 trigger.text(disabledText);