smartxml: minor refactoring - better naming
[fnpeditor.git] / src / editor / modules / nodePane / nodePane.js
index f3fb68a..25e5ddb 100644 (file)
@@ -10,14 +10,26 @@ define([
 
 return function(sandbox) {
     
 
 return function(sandbox) {
     
-    var view = $(_.template(templateSrc)({tagNames: wlxmlUtils.wlxmlTagNames, classNames: wlxmlUtils.wlxmlClassNames}));
+    var view = $(_.template(templateSrc)({utils: wlxmlUtils})),
+        listens = false,
+        currentNode,
+        msgs = {
+            Tag: gettext('Tag editing'),
+            Class: gettext('Class editing')
+        };
     
     view.on('change', 'select', function(e) {
         var target = $(e.target);
     
     view.on('change', 'select', function(e) {
         var target = $(e.target);
-        var attr = target.attr('class').split('-')[3] === 'tagSelect' ? 'tag' : 'class';
-        sandbox.publish('nodeElementChange', attr, target.val().replace(/-/g, '.'));
+        var attr = target.attr('class').split('-')[3] === 'tagSelect' ? 'Tag' : 'Class',
+            value = target.val().replace(/-/g, '.'),
+            oldValue = attr === 'Tag' ? currentNode.getTagName() : currentNode.getClass();
+        currentNode.document.transaction(function() {
+            currentNode['set' + attr](value);
+        }, this, msgs[attr] + ': ' + oldValue + ' -> ' + value);
     });
     });
-    
+
+
+   
     return {
         start: function() {
             sandbox.publish('ready');
     return {
         start: function() {
             sandbox.publish('ready');
@@ -25,17 +37,39 @@ return function(sandbox) {
         getView: function() {
             return view;
         },
         getView: function() {
             return view;
         },
-        setNodeElement: function(nodeElement) {
-            view.find('.rng-module-nodePane-tagSelect').val(nodeElement.getWlxmlTag());
+        setNodeElement: function(wlxmlNodeElement) {
+            if(wlxmlNodeElement) {
+                var module = this;
+                if(!listens) {
+                    wlxmlNodeElement.document.on('change', function(event) {
+                        if(currentNode && !currentNode.isInDocument()) {
+                            module.setNodeElement(null);
+                        }
+                        if(event.type === 'nodeAttrChange' && event.meta.node.sameNode(currentNode)) {
+                            module.setNodeElement(currentNode);
+                        }
+                    });
+                    listens = true;
+                }
+
+                view.find('.rng-module-nodePane-tagSelect').attr('disabled', false).val(wlxmlNodeElement.getTagName());
 
 
-            var escapedClassName = (nodeElement.getWlxmlClass() || '').replace(/\./g, '-')
-            view.find('.rng-module-nodePane-classSelect').val(escapedClassName);
+                var escapedClassName = (wlxmlNodeElement.getClass() || '').replace(/\./g, '-');
+                view.find('.rng-module-nodePane-classSelect').attr('disabled', false).val(escapedClassName);
 
 
-            var widget = metaWidget.create({attrs:nodeElement.getWlxmlMetaAttrs()});
-            widget.on('valueChanged', function(key, value) {
-                sandbox.publish('nodeElementChange', key, value);
-            });
-            view.find('.metaFields').empty().append(widget.el);
+                var attrs = _.extend(wlxmlNodeElement.getMetaAttributes(), wlxmlNodeElement.getOtherAttributes());
+                var widget = metaWidget.create({attrs:attrs});
+                widget.on('valueChanged', function(key, value) {
+                    wlxmlNodeElement.setMetaAttribute(key, value);
+                    //wlxmlNodeElement.setMetaAttribute(key, value);
+                });
+                view.find('.metaFields').empty().append(widget.el);
+            } else {
+                view.find('.rng-module-nodePane-tagSelect').attr('disabled', true).val('');
+                view.find('.rng-module-nodePane-classSelect').attr('disabled', true).val('');
+                view.find('.metaFields').empty();
+            }
+            currentNode = wlxmlNodeElement;
         }
     };
     
         }
     };