From: Radek Czajka <rczajka@rczajka.pl>
Date: Thu, 25 May 2023 09:36:46 +0000 (+0200)
Subject: Fixes #4405: reset metadata editor when switching views.
X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/fbedc8f26f2879a46629edc72ce20e3e85135523

Fixes #4405: reset metadata editor when switching views.
---

diff --git a/src/redakcja/static/js/wiki/base.js b/src/redakcja/static/js/wiki/base.js
index 5262ab72..b4fee85f 100644
--- a/src/redakcja/static/js/wiki/base.js
+++ b/src/redakcja/static/js/wiki/base.js
@@ -104,6 +104,15 @@
 		return this.perspectives[ $(tab).attr('id')];
 	}
 
+    $.wiki.exitTab = function(tab){
+	var self = this;
+	var $tab = $(tab);
+        if (!('.active', $tab)) return;
+	$('.active', $tab).removeClass('active');
+	self.perspectives[$tab.attr('id')].onExit();
+	$('#' + $tab.attr('data-ui-related')).hide();
+    }
+    
     $.wiki.switchToTab = function(tab){
 	var self = this;
 	var $tab = $(tab);
diff --git a/src/redakcja/static/js/wiki/view_editor_source.js b/src/redakcja/static/js/wiki/view_editor_source.js
index 988d23ca..ab8eaf08 100644
--- a/src/redakcja/static/js/wiki/view_editor_source.js
+++ b/src/redakcja/static/js/wiki/view_editor_source.js
@@ -66,9 +66,7 @@
 		$.wiki.Perspective.prototype.onExit.call(this);
 	    this.doc.setText(this.codemirror.getValue());
 
-            if ($('.vsplitbar').hasClass('active') && $('#SearchPerspective').hasClass('active')) {
-                $.wiki.switchToTab('#ScanGalleryPerspective');
-            }
+            $.wiki.exitTab('#SearchPerspective');
 
 	    if(success) success();
 	}
diff --git a/src/redakcja/static/js/wiki/view_editor_wysiwyg.js b/src/redakcja/static/js/wiki/view_editor_wysiwyg.js
index 2f510a24..5183a97e 100644
--- a/src/redakcja/static/js/wiki/view_editor_wysiwyg.js
+++ b/src/redakcja/static/js/wiki/view_editor_wysiwyg.js
@@ -743,6 +743,8 @@
         var self = this;
 
         self.caret.detach();
+
+        $.wiki.exitTab('#PropertiesPerspective');
         
         $.blockUI({
             message: 'Zapisywanie widoku...'
diff --git a/src/redakcja/static/js/wiki/view_properties.js b/src/redakcja/static/js/wiki/view_properties.js
index fd53f041..204a4dec 100644
--- a/src/redakcja/static/js/wiki/view_properties.js
+++ b/src/redakcja/static/js/wiki/view_properties.js
@@ -171,10 +171,18 @@
     PropertiesPerspective.prototype.edit = function(element) {
         let self = this;
 
-        let $node = $(element);
         $("#parents", self.$pane).empty();
         $("#bubbles").empty();
 
+        $f = $("#properties-form", self.$pane);
+        $f.empty();
+
+        if (element === null) {
+            self.$edited = null;
+            return;
+        }
+
+        let $node = $(element);
         let b = $("<div class='badge badge-primary'></div>").text($node.attr('x-node'));
         b.data('node', element);
         $("#bubbles").append(b);
@@ -193,8 +201,6 @@
         node = $(element).attr('x-node');
         $("h1", self.$pane).text(node);
 
-        $f = $("#properties-form", self.$pane);
-        $f.empty();
         self.$edited = $(element);
 
         let nodeDef = elementDefs[node];
@@ -372,6 +378,16 @@
         this.edit(p);
     }
 
+    PropertiesPerspective.prototype.onEnter = function(success, failure){
+        var self = this;
+        $.wiki.SidebarPerspective.prototype.onEnter.call(this);
+
+        if ($.wiki.activePerspective() != 'VisualPerspective')
+            $.wiki.switchToTab('#VisualPerspective');
+
+        self.edit($('[x-node="utwor"]')[0]);
+    };
+
     $.wiki.PropertiesPerspective = PropertiesPerspective;
 
 })(jQuery);