better placement of the comment tutorial
[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             previewTutorial: sandbox.getTutorialItem('preview'),
21             attachmentsTutorial: sandbox.getTutorialItem('attachments'),
22             draftTutorial: sandbox.getTutorialItem('draft'),
23             saveTutorial: sandbox.getTutorialItem('save'),
24             mainPageTutorial: sandbox.getTutorialItem('mainpage'),
25             exitTutorial: sandbox.getTutorialItem('exit')
26         }));
27
28     view.find('[data-cmd]').click(function(e) {
29         e.preventDefault();
30         var target = $(e.target);
31         if(target.hasClass('disabled')) {
32             return;
33         }
34         sandbox.publish('cmd.' + $(e.target).attr('data-cmd'));
35     });
36
37     return {
38         start: function() { sandbox.publish('ready'); },
39         getView: function() {return view;},
40         setCommandEnabled: function(cmd, enabled) {
41             var trigger = view.find('[data-cmd='+cmd+']'),
42                 disabledText = trigger.attr('data-disabled-text'),
43                 originalContent = trigger.data('originalContent');
44             trigger.toggleClass('disabled', !enabled);
45             if(enabled && originalContent) {
46                 trigger.html(originalContent);
47                 trigger.removeData('originalContent');
48             }
49             if(!enabled && disabledText) {
50                 trigger.data('originalContent', trigger.html());
51                 trigger.text(disabledText);
52             }
53         },
54         setSummaryView: function(summaryView) {
55             view.find('.bottom').prepend(summaryView);
56         }
57     };
58
59 };
60
61 });