wlxml: extending isInside/getParent/is to support tag name
[fnpeditor.git] / src / editor / modules / mainBar / mainBar.js
index ecf6812..0563b7c 100644 (file)
@@ -7,9 +7,20 @@ define([
 
 return function(sandbox) {
 
 
 return function(sandbox) {
 
-    var view = $(_.template(template)());
-    view.find('button').click(function(e) {
+    /* globals gettext*/
+
+    var config = sandbox.getConfig(),
+        userName = config.user && config.user.name,
+        view = $(_.template(template)({
+            userName: userName || gettext('anonymous')
+        }));
+
+    view.find('[data-cmd]').click(function(e) {
         e.preventDefault();
         e.preventDefault();
+        var target = $(e.target);
+        if(target.hasClass('disabled')) {
+            return;
+        }
         sandbox.publish('cmd.' + $(e.target).attr('data-cmd'));
     });
 
         sandbox.publish('cmd.' + $(e.target).attr('data-cmd'));
     });
 
@@ -17,7 +28,18 @@ return function(sandbox) {
         start: function() { sandbox.publish('ready'); },
         getView: function() {return view;},
         setCommandEnabled: function(cmd, enabled) {
         start: function() { sandbox.publish('ready'); },
         getView: function() {return view;},
         setCommandEnabled: function(cmd, enabled) {
-            view.find('[data-cmd='+cmd+']').toggleClass('disabled', !enabled);
+            var trigger = view.find('[data-cmd='+cmd+']'),
+                disabledText = trigger.attr('data-disabled-text'),
+                originalContent = trigger.data('originalContent');
+            trigger.toggleClass('disabled', !enabled);
+            if(enabled && originalContent) {
+                trigger.html(originalContent);
+                trigger.removeData('originalContent');
+            }
+            if(!enabled && disabledText) {
+                trigger.data('originalContent', trigger.html());
+                trigger.text(disabledText);
+            }
         },
         setVersion: function(version) {
             view.find('.version').text(version);
         },
         setVersion: function(version) {
             view.find('.version').text(version);