editor: fix - better handle node removal in various views
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 18 Feb 2014 15:10:58 +0000 (16:10 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 23 Apr 2014 11:05:04 +0000 (13:05 +0200)
src/editor/modules/metadataEditor/metadataEditor.js
src/editor/modules/nodeBreadCrumbs/nodeBreadCrumbs.js
src/editor/modules/nodePane/nodePane.js

index 1088247..70df62e 100644 (file)
@@ -191,7 +191,7 @@ return function(sandbox) {
                 if(event.type === 'metadataRemoved' && event.meta.node.sameNode(currentNode)) {
                     view.removeMetadataRow(event.meta.row);
                 }
                 if(event.type === 'metadataRemoved' && event.meta.node.sameNode(currentNode)) {
                     view.removeMetadataRow(event.meta.row);
                 }
-                if(event.type === 'nodeDetached' && event.meta.node.sameNode(currentNode)) {
+                if(event.type === 'nodeDetached' && event.meta.node.containsNode(currentNode)) {
                     view.setMetadata(null);
                 }
             });
                     view.setMetadata(null);
                 }
             });
index 188aa6e..0540542 100644 (file)
@@ -8,7 +8,8 @@ define([
 
 return function(sandbox) {
     
 
 return function(sandbox) {
     
-    var template = _.template(templateSrc);
+    var template = _.template(templateSrc),
+        listens = false;
     
     var view = {
         dom: $('<div>' + template({node:null, parents: null}) + '</div>'),
     
     var view = {
         dom: $('<div>' + template({node:null, parents: null}) + '</div>'),
@@ -58,6 +59,14 @@ return function(sandbox) {
         start: function() { sandbox.publish('ready'); },
         getView: function() { return view.dom; },
         setNodeElement: function(nodeElement) {
         start: function() { sandbox.publish('ready'); },
         getView: function() { return view.dom; },
         setNodeElement: function(nodeElement) {
+            if(!listens && nodeElement) {
+                nodeElement.document.on('change', function() {
+                    if(view.currentNodeElement && !view.currentNodeElement.isInDocument()) {
+                        view.setNodeElement(null);
+                    }
+                });
+                listens = true;
+            }
             view.setNodeElement(nodeElement);
         },
         highlightNode: function(id) { view.highlightNode(id); },
             view.setNodeElement(nodeElement);
         },
         highlightNode: function(id) { view.highlightNode(id); },
index f7e6694..85a6fdd 100644 (file)
@@ -35,6 +35,9 @@ return function(sandbox) {
                 var module = this;
                 if(!listens) {
                     wlxmlNodeElement.document.on('change', function(event) {
                 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);
                         }
                         if(event.type === 'nodeAttrChange' && event.meta.node.sameNode(currentNode)) {
                             module.setNodeElement(currentNode);
                         }