fix: correctly showing current document version number after document got saved
[fnpeditor.git] / src / editor / modules / documentToolbar / documentToolbar.js
1 define(['libs/jquery', 'libs/underscore', 'utils/wlxml', 'libs/text!./template.html'], function($, _, wlxmlUtils, template) {
2
3 'use strict';
4
5 return function(sandbox) {
6     
7     var view = {
8         node: $(_.template(template)({tagNames: wlxmlUtils.wlxmlTagNames, classNames: wlxmlUtils.wlxmlClassNames})),
9         setup: function() {
10             var view = this;
11             
12             this.node.find('button').click(function(e) {
13                 e.stopPropagation();
14                 var btn = $(e.currentTarget),
15                     btnName = btn.attr('data-name'),
16                     meta = btn.attr('data-meta'),
17                     params = {},
18                     command = btnName;
19
20                 if(btn.attr('data-btn-type') === 'toggle') {
21                     command = 'toggle-' + command;
22                     btn.toggleClass('active');
23                     params.toggle = btn.hasClass('active');
24                 }
25
26                 if(btnName === 'new-node') {
27                     command = 'newNodeRequested';
28                     params.wlxmlTag = view.getOption('newTag-tag');
29                     params.wlxmlClass = view.getOption('newTag-class');
30                     if(meta) {
31                         var split = meta.split('/');
32                         params.wlxmlTag = split[0];
33                         params.wlxmlClass = split[1];
34                     }
35                 } else {
36                     params.meta = meta;
37                 }
38
39                 if(command === 'undo' || command === 'redo') {
40                     params.callback = function(disable) {
41                         btn.attr('disabled', !disable);
42                     };
43                 }
44
45                 sandbox.publish('command', command, params);
46             });
47         },
48         getOption: function(option) {
49             return this.node.find('.rng-module-documentToolbar-toolbarOption[data-option=' + option +']').val();
50         }
51     };
52     
53     view.setup();
54
55     return {
56         start: function() { sandbox.publish('ready'); },
57         getView: function() { return view.node; },
58         getOption: function(option) { return view.getOption(option); }
59     };
60 };
61
62 });