smartxml/wlxml: Merge in document node instances caching
[fnpeditor.git] / src / editor / modules / mainBar / mainBar.js
1 define([
2 'libs/jquery',
3 'libs/underscore',
4 'libs/text!./template.html'], function($, _, template) {
5
6 'use strict';
7
8 return function(sandbox) {
9
10     /* globals gettext*/
11
12     var config = sandbox.getConfig(),
13         userName = config.user && config.user.name,
14         view = $(_.template(template)({
15             userName: userName || gettext('anonymous')
16         }));
17
18     view.find('[data-cmd]').click(function(e) {
19         e.preventDefault();
20         var target = $(e.target);
21         if(target.hasClass('disabled')) {
22             return;
23         }
24         sandbox.publish('cmd.' + $(e.target).attr('data-cmd'));
25     });
26
27     return {
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');
38             }
39             if(!enabled && disabledText) {
40                 trigger.data('originalContent', trigger.html());
41                 trigger.text(disabledText);
42             }
43         },
44         setSummaryView: function(summaryView) {
45             view.find('.bottom').prepend(summaryView);
46         }
47     };
48
49 };
50
51 });