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 $("#simple-editor").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 if ($input.data("edited-attr")) {
76 $input.data("edited").attr($input.data("edited-attr"), inputval);
78 $input.data("edited").text(inputval);
84 element: self.$edited[0],
85 success: function(xml) {
87 let $xmlelem = $($.parseXML(xml));
89 w($input.data('property'), $input.val());
90 $xmlelem.contents().attr($input.data('property'), inputval);
92 let newxml = (new XMLSerializer()).serializeToString($xmlelem[0]);
96 base: self.doc.getBase(),
97 success: function(html) {
98 let htmlElem = $(html);
99 self.$edited.replaceWith(htmlElem);
104 error: function(e) {console.log(e);},
110 self.$pane.on('click', '.meta-add', function() {
111 // create a metadata item
112 let $fg = $(this).parent();
113 let ns = $fg.data('ns');
114 let tag = $fg.data('tag');
115 let field = $fg.data('field');
116 let span = $('<span/>');
117 span.attr('x-node', tag);
118 span.attr('x-ns', ns)
119 if (field.value_type.hasLanguage) {
120 span.attr('x-a-xml-lang', 'pl');
123 rdf = $("> [x-node='RDF']", self.$edited);
125 rdf = $("<span x-node='RDF' x-ns='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>");
126 self.$edited.prepend(rdf);
127 self.$edited.prepend('\n ');
130 rdfdesc = $("> [x-node='Description']", rdf);
131 if (!rdfdesc.length) {
132 rdfdesc = $("<span x-node='Description' x-ns='http://www.w3.org/1999/02/22-rdf-syntax-ns#' x-a-rdf-about='" + self.doc.fullUri + "'>");
133 rdf.prepend(rdfdesc);
135 rdfdesc.append('\n ');
138 span.appendTo(rdfdesc);
139 rdfdesc.append('\n ');
141 self.displayMetaProperty($fg);
146 self.$pane.on('click', '.meta-delete', function() {
147 let $fg = $(this).closest('.form-group');
148 $('input', $fg).data('edited').remove();
149 self.displayMetaProperty($fg);
155 self.$pane.on('click', '.current-convert', function() {
156 self.convert($(this).attr('data-to'));
158 self.$pane.on('click', '#current-delete', function() {
163 oldCallback.call(this);
166 $.wiki.SidebarPerspective.call(this, options);
169 PropertiesPerspective.prototype = new $.wiki.SidebarPerspective();
171 PropertiesPerspective.prototype.edit = function(element) {
174 $("#parents", self.$pane).empty();
175 $("#bubbles").empty();
177 $f = $("#properties-form", self.$pane);
180 if (element === null) {
185 let $node = $(element);
186 let b = $("<div class='badge badge-primary'></div>").text($node.attr('x-node'));
187 b.data('node', element);
188 $("#bubbles").append(b);
190 $node.parents('[x-node]').each(function() {
191 let a = $("<li class='breadcrumb-item'>").text($(this).attr('x-node'));
192 a.data('node', this);
193 $("#parents", self.$pane).prepend(a)
195 let b = $("<div class='badge badge-info'></div>").text($(this).attr('x-node'));
196 b.data('node', this);
197 $("#bubbles").append(b);
201 node = $(element).attr('x-node');
202 $("h1", self.$pane).text(node);
204 self.$edited = $(element);
206 let nodeDef = elementDefs[node];
207 if (nodeDef && nodeDef.attributes) {
208 $.each(nodeDef.attributes, function(i, a) {
209 self.addEditField(a, $(element).attr('x-a-wl-' + a.name)); // ...
213 // Only utwor can has matadata now.
214 if (node == 'utwor') {
215 $('<hr>').appendTo($("#properties-form", self.$pane))
216 META_FIELDS.forEach(function(field) {
217 let $fg = $("<div class='form-group'>");
218 $("<label/>").text(field.name).appendTo($fg);
221 $("<button class='meta-add float-right btn btn-primary'>+</button>").appendTo($fg);
223 let match = field.uri.match(/({(.*)})?(.*)/);
227 let cont = $('<div class="c">');
230 $fg.data('tag', tag);
231 $fg.data('field', field);
234 self.displayMetaProperty($fg);
236 $fg.appendTo( $("#properties-form", self.$pane));
240 // check node type, find relevant tags
241 if ($node[0].nodeName == 'DIV') {
242 $("#current-convert").attr("data-current-type", "div");
243 } else if ($node[0].nodeName == 'EM') {
244 $("#current-convert").attr("data-current-type", "span");
248 PropertiesPerspective.prototype.addMetaInput = function(cont, field, element) {
251 let ig = $('<div class="input-group">');
252 //ig.data('edited', element);
255 if (field.value_type.hasLanguage) {
256 let pp = $("<div class='input-group-prepend'>");
257 let lang_input = $("<input class='form-control' size='1' class='lang'>");
258 lang_input.data('edited', $(element));
259 lang_input.data('edited-attr', 'x-a-xml-lang');
261 $(element).attr('x-a-xml-lang')
263 lang_input.appendTo(pp);
268 if (field.value_type.widget == 'select') {
269 $aninput = $("<select class='form-control'>");
270 $.each(field.value_type.options, function() {
271 $("<option>").text(this).appendTo($aninput);
274 $aninput = $("<input class='form-control'>");
275 if (field.value_type.autocomplete) {
276 let autoOptions = field.value_type.autocomplete;
277 $aninput.autocomplete(autoOptions).autocomplete('instance')._renderItem = function(ul, item) {
279 if (item.name) t += '<br><small><strong>' + item.name + '</strong></small>';
280 if (item.description) t += '<br><small><em>' + item.description + '</em></small>';
282 .append( "<div>" + t + "</div>" )
287 $aninput.data('edited', $(element))
291 $aninput.appendTo(ig);
293 let ap = $("<div class='input-group-append'>");
295 $("<button class='meta-delete btn btn-outline-secondary'>x</button>").appendTo(ap);
301 PropertiesPerspective.prototype.displayMetaProperty = function($fg) {
303 let ns = $fg.data('ns');
304 let tag = $fg.data('tag');
305 let field = $fg.data('field');
308 $('.c', $fg).empty();
310 let selector = "> [x-node='RDF'] > [x-node='Description'] > [x-node='"+tag+"']";
312 selector += "[x-ns='"+ns+"']";
314 $(selector, self.$edited).each(function() {
321 count = $('.c > .input-group', $fg).length;
322 if (field.required) {
324 $('<div class="text-warning">WYMAGANE</div>').appendTo($('.c', $fg));
331 PropertiesPerspective.prototype.addEditField = function(defn, value, elem) {
333 let $form = $("#properties-form", self.$pane);
335 let $fg = $("<div class='form-group'>");
336 $("<label/>").attr("for", "property-" + defn.name).text(defn.name).appendTo($fg);
340 $input = $("<textarea>");
343 $input = $("<select>");
344 $.each(defn.options, function(i, e) {
345 $("<option>").text(e).appendTo($input);
349 $input = $("<input type='checkbox'>");
352 $input = $("<input>");
355 $input.addClass("form-control").attr("id", "property-" + defn.name).data("property", defn.name);
356 if ($input.attr('type') == 'checkbox') {
357 $input.prop('checked', value == 'true');
363 $input.data("edited", elem);
365 $input.appendTo($fg);
370 PropertiesPerspective.prototype.convert = function(newtag) {
371 this.$edited.attr('x-node', newtag);
372 // TODO: take care of attributes?
375 PropertiesPerspective.prototype.delete = function(newtag) {
376 p = this.$edited.parent();
377 this.$edited.remove();
381 PropertiesPerspective.prototype.onEnter = function(success, failure){
383 $.wiki.SidebarPerspective.prototype.onEnter.call(this);
385 if ($.wiki.activePerspective() != 'VisualPerspective')
386 $.wiki.switchToTab('#VisualPerspective');
388 self.edit($('[x-node="utwor"]')[0]);
391 $.wiki.PropertiesPerspective = PropertiesPerspective;