From 05a64b9314fac5f613133332d7d0b5b568ab8afc Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 29 Jan 2021 15:23:07 +0100 Subject: [PATCH] Properies pane. --- src/redakcja/settings/__init__.py | 1 + src/redakcja/static/css/gallery.css | 7 + .../static/js/wiki/view_editor_wysiwyg.js | 1 + .../static/js/wiki/view_properties.js | 152 ++++++++++++++++++ src/redakcja/static/js/wiki/wikiapi.js | 4 + src/redakcja/static/js/wiki/xslt.js | 33 ++-- src/redakcja/static/xsl/wl2html_client.xsl | 12 ++ src/wiki/templates/wiki/document_details.html | 14 +- .../templates/wiki/tabs/properties_view.html | 9 ++ .../wiki/tabs/properties_view_item.html | 4 + 10 files changed, 221 insertions(+), 16 deletions(-) create mode 100644 src/redakcja/static/js/wiki/view_properties.js create mode 100644 src/wiki/templates/wiki/tabs/properties_view.html create mode 100644 src/wiki/templates/wiki/tabs/properties_view_item.html diff --git a/src/redakcja/settings/__init__.py b/src/redakcja/settings/__init__.py index 4859abb2..c7cf3244 100644 --- a/src/redakcja/settings/__init__.py +++ b/src/redakcja/settings/__init__.py @@ -196,6 +196,7 @@ PIPELINE = { 'js/wiki/view_editor_wysiwyg.js', 'js/wiki/view_gallery.js', 'js/wiki/view_annotations.js', + 'js/wiki/view_properties.js', 'js/wiki/view_search.js', 'js/wiki/view_column_diff.js', ), diff --git a/src/redakcja/static/css/gallery.css b/src/redakcja/static/css/gallery.css index a1694a41..815229cc 100644 --- a/src/redakcja/static/css/gallery.css +++ b/src/redakcja/static/css/gallery.css @@ -8,6 +8,13 @@ background-color: #C1C1C1; } +#side-properties { + height: 100%; + overflow: auto; +} +#side-properties #parents li { + cursor: pointer; +} #side-annotations { display: flex; diff --git a/src/redakcja/static/js/wiki/view_editor_wysiwyg.js b/src/redakcja/static/js/wiki/view_editor_wysiwyg.js index 607fa3f2..517c878e 100644 --- a/src/redakcja/static/js/wiki/view_editor_wysiwyg.js +++ b/src/redakcja/static/js/wiki/view_editor_wysiwyg.js @@ -692,6 +692,7 @@ xml2html({ xml: this.doc.text, + base: this.doc.getBase(), success: function(element){ var htmlView = $('#html-view'); htmlView.html(element); diff --git a/src/redakcja/static/js/wiki/view_properties.js b/src/redakcja/static/js/wiki/view_properties.js new file mode 100644 index 00000000..571dac00 --- /dev/null +++ b/src/redakcja/static/js/wiki/view_properties.js @@ -0,0 +1,152 @@ +(function($){ + + let w = function() {}; + w = console.log; + + const elementDefs = { + "ilustr": { + "attributes": [ + { + "name": "src", + }, + { + "name": "alt", + "type": "text", + }, + ], + }, + "ref": { + "attributes": [ + { + "name": "href", + }, + ], + } + }; + + function PropertiesPerspective(options) { + let oldCallback = options.callback || function() {}; + this.vsplitbar = 'WŁAŚCIWOŚCI'; + + options.callback = function() { + let self = this; + + self.$pane = $("#side-properties"); + + $(document).on('click', '[x-node]', function(e) { + e.stopPropagation(); + self.edit(this); + }); + + self.$pane.on('click', '#parents li', function(e) { + self.edit($(this).data('node')); + }); + + self.$pane.on('change', '.form-control', function() { + let $input = $(this); + + if ($input.data("edited")) { + $input.data("edited").text($input.val()); + return; + } + + html2text({ + element: self.$edited[0], + success: function(xml) { + w(222) + let $xmlelem = $($.parseXML(xml)); + w(333, $xmlelem) + $xmlelem.contents().attr($input.data('property'), $input.val()); + w(444, $xmlelem) + let newxml = (new XMLSerializer()).serializeToString($xmlelem[0]); + w(555, newxml) + xml2html({ + xml: newxml, + base: self.doc.getBase(), + success: function(html) { + let htmlElem = $(html); + self.$edited.replaceWith(htmlElem); + self.edit(htmlElem); + } + }); + }, + error: function(e) {console.log(e);}, + }); + self.$edited; + }); + + oldCallback.call(this); + }; + + $.wiki.SidebarPerspective.call(this, options); + } + + PropertiesPerspective.prototype = new $.wiki.SidebarPerspective(); + + PropertiesPerspective.prototype.edit = function(element) { + let self = this; + + let $node = $(element); + $("#parents", self.$pane).empty(); + $node.parents('[x-node]').each(function() { + let a = $("