23 "options": ["lewo", "srodek", "prawo"],
40 function PropertiesPerspective(options) {
41 let oldCallback = options.callback || function() {};
42 this.vsplitbar = 'WŁAŚCIWOŚCI';
44 options.callback = function() {
47 self.$pane = $("#side-properties");
49 $(document).on('click', '[x-node]', function(e) {
50 if (!e.redakcja_edited) {
51 e.redakcja_edited = true;
56 self.$pane.on('click', '#parents li', function(e) {
57 self.edit($(this).data('node'));
60 $(document).on('click', '#bubbles .badge', function(e) {
61 self.edit($(this).data('node'));
64 self.$pane.on('change', '.form-control', function() {
68 if ($input.attr('type') == 'checkbox') {
69 inputval = $input.is(':checked');
71 inputval = $input.val();
74 if ($input.data("edited")) {
75 $input.data("edited").text(inputval);
80 element: self.$edited[0],
81 success: function(xml) {
83 let $xmlelem = $($.parseXML(xml));
85 w($input.data('property'), $input.val());
86 $xmlelem.contents().attr($input.data('property'), inputval);
88 let newxml = (new XMLSerializer()).serializeToString($xmlelem[0]);
92 base: self.doc.getBase(),
93 success: function(html) {
94 let htmlElem = $(html);
95 self.$edited.replaceWith(htmlElem);
100 error: function(e) {console.log(e);},
105 self.$pane.on('click', '.current-convert', function() {
106 self.convert($(this).attr('data-to'));
108 self.$pane.on('click', '#current-delete', function() {
113 oldCallback.call(this);
116 $.wiki.SidebarPerspective.call(this, options);
119 PropertiesPerspective.prototype = new $.wiki.SidebarPerspective();
121 PropertiesPerspective.prototype.edit = function(element) {
124 let $node = $(element);
125 $("#parents", self.$pane).empty();
126 $("#bubbles").empty();
128 let b = $("<div class='badge badge-primary'></div>").text($node.attr('x-node'));
129 b.data('node', element);
130 $("#bubbles").append(b);
132 $node.parents('[x-node]').each(function() {
133 let a = $("<li class='breadcrumb-item'>").text($(this).attr('x-node'));
134 a.data('node', this);
135 $("#parents", self.$pane).prepend(a)
137 let b = $("<div class='badge badge-info'></div>").text($(this).attr('x-node'));
138 b.data('node', this);
139 $("#bubbles").append(b);
143 node = $(element).attr('x-node');
144 $("h1", self.$pane).text(node);
146 $f = $("#properties-form", self.$pane);
148 self.$edited = $(element);
150 let nodeDef = elementDefs[node];
151 if (nodeDef && nodeDef.attributes) {
152 $.each(nodeDef.attributes, function(i, a) {
153 self.addEditField(a, $(element).attr('data-wlf-' + a.name)); // ...
158 // Only utwor can has matadata now.
159 if (node == 'utwor') {
160 // Let's find all the metadata.
161 $("> [x-node='RDF'] > [x-node='Description'] > [x-node]", $node).each(function() {
164 {"name": $meta.attr('x-node'),},
173 // check node type, find relevant tags
174 if ($node[0].nodeName == 'DIV') {
175 $("#current-convert").attr("data-current-type", "div");
176 } else if ($node[0].nodeName == 'EM') {
177 $("#current-convert").attr("data-current-type", "span");
183 PropertiesPerspective.prototype.addEditField = function(defn, value, elem) {
185 let $form = $("#properties-form", self.$pane);
187 let $fg = $("<div class='form-group'>");
188 $("<label/>").attr("for", "property-" + defn.name).text(defn.name).appendTo($fg);
192 $input = $("<textarea>");
195 $input = $("<select>");
196 $.each(defn.options, function(i, e) {
197 $("<option>").text(e).appendTo($input);
201 $input = $("<input type='checkbox'>");
204 $input = $("<input>");
207 $input.addClass("form-control").attr("id", "property-" + defn.name).data("property", defn.name);
208 if ($input.attr('type') == 'checkbox') {
209 $input.prop('checked', value == 'true');
215 $input.data("edited", elem);
217 $input.appendTo($fg);
222 PropertiesPerspective.prototype.convert = function(newtag) {
223 this.$edited.attr('x-node', newtag);
224 // TODO: take care of attributes?
227 PropertiesPerspective.prototype.delete = function(newtag) {
228 p = this.$edited.parent();
229 this.$edited.remove();
233 $.wiki.PropertiesPerspective = PropertiesPerspective;