24 "options": ["lewo", "srodek", "prawo"],
41 function PropertiesPerspective(options) {
42 let oldCallback = options.callback || function() {};
43 this.vsplitbar = 'WŁAŚCIWOŚCI';
45 options.callback = function() {
48 self.$pane = $("#side-properties");
50 $("#simple-editor").on('click', '[x-node]', function(e) {
51 if (!e.redakcja_edited) {
52 e.redakcja_edited = true;
57 self.$pane.on('click', '#parents li', function(e) {
58 self.edit($(this).data('node'));
61 $(document).on('click', '#bubbles .badge', function(e) {
62 self.edit($(this).data('node'));
65 self.$pane.on('change', '.form-control', function() {
69 if ($input.attr('type') == 'checkbox') {
70 inputval = $input.is(':checked');
72 inputval = $input.val();
75 if ($input.data("edited")) {
76 if ($input.data("edited-attr")) {
77 $input.data("edited").attr($input.data("edited-attr"), inputval);
79 $input.data("edited").text(inputval);
85 element: self.$edited[0],
86 success: function(xml) {
88 let $xmlelem = $($.parseXML(xml));
90 w($input.data('property'), $input.val());
91 $xmlelem.contents().attr($input.data('property'), inputval);
93 let newxml = (new XMLSerializer()).serializeToString($xmlelem[0]);
97 base: self.doc.getBase(),
98 success: function(html) {
99 let htmlElem = $(html);
100 self.$edited.replaceWith(htmlElem);
105 error: function(e) {console.log(e);},
111 self.$pane.on('click', '.meta-add', function() {
112 // create a metadata item
113 let $fg = $(this).parent();
114 let ns = $fg.data('ns');
115 let tag = $fg.data('tag');
116 let field = $fg.data('field');
117 let span = $('<span/>');
118 span.attr('x-node', tag);
119 span.attr('x-ns', ns)
120 if (field.value_type.hasLanguage) {
121 span.attr('x-a-xml-lang', 'pl');
124 rdf = $("> [x-node='RDF']", self.$edited);
126 rdf = $("<span x-node='RDF' x-ns='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>");
127 self.$edited.prepend(rdf);
128 self.$edited.prepend('\n ');
131 rdfdesc = $("> [x-node='Description']", rdf);
132 if (!rdfdesc.length) {
133 rdfdesc = $("<span x-node='Description' x-ns='http://www.w3.org/1999/02/22-rdf-syntax-ns#' x-a-rdf-about='" + self.doc.fullUri + "'>");
134 rdf.prepend(rdfdesc);
136 rdfdesc.append('\n ');
139 span.appendTo(rdfdesc);
140 rdfdesc.append('\n ');
142 self.displayMetaProperty($fg);
147 self.$pane.on('click', '.meta-delete', function() {
148 let $fg = $(this).closest('.form-group');
149 $('input', $fg).data('edited').remove();
150 self.displayMetaProperty($fg);
155 $('#media-chooser').on('show.bs.modal', function (event) {
156 var input = $("input", $(event.relatedTarget).parent());
158 modal.data('target-input', input);
159 var imglist = modal.find('.modal-body');
161 $.each(self.doc.galleryImages, (i, imgItem) => {
162 img = $("<img>").attr("src", imgItem.thumb).attr('title', imgItem.url).data('url', imgItem.url).on('click', function() {
163 imglist.find('img').removeClass('active');
164 $(this).addClass('active');
169 $('#media-chooser .ctrl-ok').on('click', function (event) {
170 $('#media-chooser').data('target-input')
172 (new URL($('#media-chooser .active').data('url'), document.baseURI)).href
174 $('#media-chooser').modal('hide');
177 self.$pane.on('click', '.current-convert', function() {
178 self.convert($(this).attr('data-to'));
180 self.$pane.on('click', '#current-delete', function() {
185 oldCallback.call(this);
188 $.wiki.SidebarPerspective.call(this, options);
191 PropertiesPerspective.prototype = new $.wiki.SidebarPerspective();
193 PropertiesPerspective.prototype.edit = function(element) {
196 $("#parents", self.$pane).empty();
197 $("#bubbles").empty();
199 $f = $("#properties-form", self.$pane);
202 if (element === null) {
207 let $node = $(element);
208 let b = $("<div class='badge badge-primary'></div>").text($node.attr('x-node'));
209 b.data('node', element);
210 $("#bubbles").append(b);
212 $node.parents('[x-node]').each(function() {
213 let a = $("<li class='breadcrumb-item'>").text($(this).attr('x-node'));
214 a.data('node', this);
215 $("#parents", self.$pane).prepend(a)
217 let b = $("<div class='badge badge-info'></div>").text($(this).attr('x-node'));
218 b.data('node', this);
219 $("#bubbles").append(b);
223 node = $(element).attr('x-node');
224 $("h1", self.$pane).text(node);
226 self.$edited = $(element);
228 let nodeDef = elementDefs[node];
229 if (nodeDef && nodeDef.attributes) {
230 $.each(nodeDef.attributes, function(i, a) {
231 self.addEditField(a, $(element).attr('x-a-wl-' + a.name)); // ...
235 // Only utwor can has matadata now.
236 if (node == 'utwor') {
237 $('<hr>').appendTo($("#properties-form", self.$pane))
238 META_FIELDS.forEach(function(field) {
239 let $fg = $("<div class='form-group'>");
240 $("<label/>").text(field.name).appendTo($fg);
243 $("<button class='meta-add float-right btn btn-primary'>+</button>").appendTo($fg);
245 let match = field.uri.match(/({(.*)})?(.*)/);
249 let cont = $('<div class="c">');
252 $fg.data('tag', tag);
253 $fg.data('field', field);
256 self.displayMetaProperty($fg);
258 $fg.appendTo( $("#properties-form", self.$pane));
262 // check node type, find relevant tags
263 if ($node[0].nodeName == 'DIV') {
264 $("#current-convert").attr("data-current-type", "div");
265 } else if ($node[0].nodeName == 'EM') {
266 $("#current-convert").attr("data-current-type", "span");
270 PropertiesPerspective.prototype.addMetaInput = function(cont, field, element) {
273 let ig = $('<div class="input-group">');
274 //ig.data('edited', element);
277 if (field.value_type.hasLanguage) {
278 let pp = $("<div class='input-group-prepend'>");
279 let lang_input = $("<input class='form-control' size='1' class='lang'>");
280 lang_input.data('edited', $(element));
281 lang_input.data('edited-attr', 'x-a-xml-lang');
283 $(element).attr('x-a-xml-lang')
285 lang_input.appendTo(pp);
290 if (field.value_type.widget == 'select') {
291 $aninput = $("<select class='form-control'>");
292 $.each(field.value_type.options, function() {
293 $("<option>").text(this).appendTo($aninput);
296 $aninput = $("<input class='form-control'>");
297 if (field.value_type.autocomplete) {
298 let autoOptions = field.value_type.autocomplete;
299 $aninput.autocomplete(autoOptions).autocomplete('instance')._renderItem = function(ul, item) {
301 if (item.name) t += '<br><small><strong>' + item.name + '</strong></small>';
302 if (item.description) t += '<br><small><em>' + item.description + '</em></small>';
304 .append( "<div>" + t + "</div>" )
309 $aninput.data('edited', $(element))
313 $aninput.appendTo(ig);
315 let ap = $("<div class='input-group-append'>");
317 $("<button class='meta-delete btn btn-outline-secondary'>x</button>").appendTo(ap);
323 PropertiesPerspective.prototype.displayMetaProperty = function($fg) {
325 let ns = $fg.data('ns');
326 let tag = $fg.data('tag');
327 let field = $fg.data('field');
330 $('.c', $fg).empty();
332 let selector = "> [x-node='RDF'] > [x-node='Description'] > [x-node='"+tag+"']";
334 selector += "[x-ns='"+ns+"']";
336 $(selector, self.$edited).each(function() {
343 count = $('.c > .input-group', $fg).length;
344 if (field.required) {
346 $('<div class="text-warning">WYMAGANE</div>').appendTo($('.c', $fg));
353 PropertiesPerspective.prototype.addEditField = function(defn, value, elem) {
355 let $form = $("#properties-form", self.$pane);
357 let $fg = $("<div class='form-group'>");
358 $("<label/>").attr("for", "property-" + defn.name).text(defn.name).appendTo($fg);
359 let $input, $inputCnt;
362 $inputCnt =$input = $("<textarea>");
365 $inputCnt = $input = $("<select>");
366 $.each(defn.options, function(i, e) {
367 $("<option>").text(e).appendTo($input);
371 $inputCnt = $input = $("<input type='checkbox'>");
374 $inputCnt = $("<div class='media-input input-group'>");
375 $input = $("<input type='text'>");
376 $inputCnt.append($input);
377 $inputCnt.append($("<button type='button' class='ctrl-media-choose btn btn-primary' data-toggle='modal' data-target='#media-chooser'>…</button>"));
380 $inputCnt = $input = $("<input>");
383 $input.addClass("form-control").attr("id", "property-" + defn.name).data("property", defn.name);
384 if ($input.attr('type') == 'checkbox') {
385 $input.prop('checked', value == 'true');
391 $input.data("edited", elem);
393 $inputCnt.appendTo($fg);
398 PropertiesPerspective.prototype.convert = function(newtag) {
399 this.$edited.attr('x-node', newtag);
400 // TODO: take care of attributes?
403 PropertiesPerspective.prototype.delete = function(newtag) {
404 p = this.$edited.parent();
405 this.$edited.remove();
409 PropertiesPerspective.prototype.onEnter = function(success, failure){
411 $.wiki.SidebarPerspective.prototype.onEnter.call(this);
413 if ($.wiki.activePerspective() != 'VisualPerspective')
414 $.wiki.switchToTab('#VisualPerspective');
416 if (self.$edited === null) {
417 self.edit($('[x-node="utwor"]')[0]);
421 $.wiki.PropertiesPerspective = PropertiesPerspective;