metaWidget wip: reacting to class change
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 1 Jul 2013 14:12:10 +0000 (16:12 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 1 Jul 2013 14:12:10 +0000 (16:12 +0200)
modules/documentCanvas/canvasNode.js
modules/documentCanvas/documentCanvas.js
modules/documentCanvas/tests/canvasNode.test.js
modules/rng/rng.js

index a57c10a..1ef5628 100644 (file)
@@ -38,6 +38,16 @@ CanvasNode.prototype.getClass = function() {
     return this.dom.attr('wlxml-class');
 };
 
     return this.dom.attr('wlxml-class');
 };
 
+CanvasNode.prototype.setClass = function(klass) {
+    if(klass != this.getClass()) {
+        this.dom.attr('wlxml-class', klass);
+        var c = this;
+        this.getMetaAttrs().forEach(function(attr) {
+            c.dom.removeAttr('wlxml-meta-' + attr.name);
+        });
+    }
+}
+
 CanvasNode.prototype.getId = function() {
     return this.dom.attr('id');
 };
 CanvasNode.prototype.getId = function() {
     return this.dom.attr('id');
 };
index 50a3777..2fa8722 100644 (file)
@@ -29,8 +29,11 @@ return function(sandbox) {
         },
         modifyCurrentNode: function(attr, value) {
             if(manager.currentNode) {
         },
         modifyCurrentNode: function(attr, value) {
             if(manager.currentNode) {
-                if(_.contains(['tag', 'class'], attr)) {
+                if(attr === 'tag') {
                     manager.getNodeElement(manager.currentNode).attr('wlxml-'+attr, value);
                     manager.getNodeElement(manager.currentNode).attr('wlxml-'+attr, value);
+                }
+                else if(attr === 'class') {
+                    manager.currentNode.setClass(value);
                 } else {
                     // changing node meta attr
                     manager.currentNode.setMetaAttr(attr, value);
                 } else {
                     // changing node meta attr
                     manager.currentNode.setMetaAttr(attr, value);
index f944d90..0077d46 100644 (file)
@@ -81,4 +81,16 @@ suite('meta attributes', function() {
     });
 });
 
     });
 });
 
+suite('modifing node', function() {
+    test('changing class removes meta attributes', function() {
+        var node = canvasNode.create({tag: 'span', klass: 'uri', meta: {uri: 'http://some.uri.com'}});
+        
+        assert.equal(node.getMetaAttr('uri'), 'http://some.uri.com');
+
+        node.setClass('author');
+
+        assert.equal(node.getMetaAttr('uri'), undefined);
+    })
+})
+
 });
\ No newline at end of file
 });
\ No newline at end of file
index 469a6fc..2078494 100644 (file)
@@ -64,10 +64,12 @@ return function(sandbox) {
         },
         selectNode: function(canvasNode, origin) {
             sandbox.getModule('documentCanvas').selectNode(canvasNode);
         },
         selectNode: function(canvasNode, origin) {
             sandbox.getModule('documentCanvas').selectNode(canvasNode);
+            this.updateNodesModules(canvasNode);           
+        },
+        updateNodesModules: function(canvasNode) {
             sandbox.getModule('nodePane').setNode(canvasNode);
             sandbox.getModule('nodeFamilyTree').setNode(canvasNode);
             sandbox.getModule('nodeBreadCrumbs').setNode(canvasNode);
             sandbox.getModule('nodePane').setNode(canvasNode);
             sandbox.getModule('nodeFamilyTree').setNode(canvasNode);
             sandbox.getModule('nodeBreadCrumbs').setNode(canvasNode);
-            
         },
         resetDocument: function(document, reason) {
             var modules = [];
         },
         resetDocument: function(document, reason) {
             var modules = [];
@@ -199,6 +201,10 @@ return function(sandbox) {
             dirty.documentCanvas = true;
         },
         
             dirty.documentCanvas = true;
         },
         
+        currentNodeChanged: function(canvasNode) {
+            commands.updateNodesModules(canvasNode);
+        },
+
         nodeHovered: function(canvasNode) {
             commands.highlightDocumentNode(canvasNode);
         },
         nodeHovered: function(canvasNode) {
             commands.highlightDocumentNode(canvasNode);
         },