minor fix
[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             documentScheduleUrl: config.documentScheduleUrl,
17             documentForkUrl: config.documentForkUrl,
18             documentPreviewUrl: config.documentPreviewMainUrl(data.revision),
19             documentGalleryUrl: config.documentGalleryUrl,
20         }));
21
22     view.find('[data-cmd]').click(function(e) {
23         e.preventDefault();
24         var target = $(e.target);
25         if(target.hasClass('disabled')) {
26             return;
27         }
28         sandbox.publish('cmd.' + $(e.target).attr('data-cmd'));
29     });
30
31     return {
32         start: function() { sandbox.publish('ready'); },
33         getView: function() {return view;},
34         setCommandEnabled: function(cmd, enabled) {
35             var trigger = view.find('[data-cmd='+cmd+']'),
36                 disabledText = trigger.attr('data-disabled-text'),
37                 originalContent = trigger.data('originalContent');
38             trigger.toggleClass('disabled', !enabled);
39             if(enabled && originalContent) {
40                 trigger.html(originalContent);
41                 trigger.removeData('originalContent');
42             }
43             if(!enabled && disabledText) {
44                 trigger.data('originalContent', trigger.html());
45                 trigger.text(disabledText);
46             }
47         },
48         setSummaryView: function(summaryView) {
49             view.find('.bottom').prepend(summaryView);
50         }
51     };
52
53 };
54
55 });