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');
160 $.each(self.doc.galleryImages, (i, imgItem) => {
161 img = $("<img>").attr("src", imgItem.thumb).attr('title', imgItem.url).data('url', imgItem.url).on('click', function() {
162 imglist.find('img').removeClass('active');
163 $(this).addClass('active');
168 $('#media-chooser .ctrl-ok').on('click', function (event) {
169 $('#media-chooser').data('target-input')
171 (new URL($('#media-chooser .active').data('url'), document.baseURI)).href
173 $('#media-chooser').modal('hide');
176 self.$pane.on('click', '.current-convert', function() {
177 self.convert($(this).attr('data-to'));
179 self.$pane.on('click', '#current-delete', function() {
184 oldCallback.call(this);
187 $.wiki.SidebarPerspective.call(this, options);
190 PropertiesPerspective.prototype = new $.wiki.SidebarPerspective();
192 PropertiesPerspective.prototype.edit = function(element) {
195 $("#parents", self.$pane).empty();
196 $("#bubbles").empty();
198 $f = $("#properties-form", self.$pane);
201 if (element === null) {
206 let $node = $(element);
207 let b = $("<div class='badge badge-primary'></div>").text($node.attr('x-node'));
208 b.data('node', element);
209 $("#bubbles").append(b);
211 $node.parents('[x-node]').each(function() {
212 let a = $("<li class='breadcrumb-item'>").text($(this).attr('x-node'));
213 a.data('node', this);
214 $("#parents", self.$pane).prepend(a)
216 let b = $("<div class='badge badge-info'></div>").text($(this).attr('x-node'));
217 b.data('node', this);
218 $("#bubbles").append(b);
222 node = $(element).attr('x-node');
223 $("h1", self.$pane).text(node);
225 self.$edited = $(element);
227 let nodeDef = elementDefs[node];
228 if (nodeDef && nodeDef.attributes) {
229 $.each(nodeDef.attributes, function(i, a) {
230 self.addEditField(a, $(element).attr('x-a-wl-' + a.name)); // ...
234 // Only utwor can has matadata now.
235 if (node == 'utwor') {
236 $('<hr>').appendTo($("#properties-form", self.$pane))
237 META_FIELDS.forEach(function(field) {
238 let $fg = $("<div class='form-group'>");
239 $("<label/>").text(field.name).appendTo($fg);
242 $("<button class='meta-add float-right btn btn-primary'>+</button>").appendTo($fg);
244 let match = field.uri.match(/({(.*)})?(.*)/);
248 let cont = $('<div class="c">');
251 $fg.data('tag', tag);
252 $fg.data('field', field);
255 self.displayMetaProperty($fg);
257 $fg.appendTo( $("#properties-form", self.$pane));
261 // check node type, find relevant tags
262 if ($node[0].nodeName == 'DIV') {
263 $("#current-convert").attr("data-current-type", "div");
264 } else if ($node[0].nodeName == 'EM') {
265 $("#current-convert").attr("data-current-type", "span");
269 PropertiesPerspective.prototype.addMetaInput = function(cont, field, element) {
272 let ig = $('<div class="input-group">');
273 //ig.data('edited', element);
276 if (field.value_type.hasLanguage) {
277 let pp = $("<div class='input-group-prepend'>");
278 let lang_input = $("<input class='form-control' size='1' class='lang'>");
279 lang_input.data('edited', $(element));
280 lang_input.data('edited-attr', 'x-a-xml-lang');
282 $(element).attr('x-a-xml-lang')
284 lang_input.appendTo(pp);
289 if (field.value_type.widget == 'select') {
290 $aninput = $("<select class='form-control'>");
291 $.each(field.value_type.options, function() {
292 $("<option>").text(this).appendTo($aninput);
295 $aninput = $("<input class='form-control'>");
296 if (field.value_type.autocomplete) {
297 let autoOptions = field.value_type.autocomplete;
298 $aninput.autocomplete(autoOptions).autocomplete('instance')._renderItem = function(ul, item) {
300 if (item.name) t += '<br><small><strong>' + item.name + '</strong></small>';
301 if (item.description) t += '<br><small><em>' + item.description + '</em></small>';
303 .append( "<div>" + t + "</div>" )
308 $aninput.data('edited', $(element))
312 $aninput.appendTo(ig);
314 let ap = $("<div class='input-group-append'>");
316 $("<button class='meta-delete btn btn-outline-secondary'>x</button>").appendTo(ap);
322 PropertiesPerspective.prototype.displayMetaProperty = function($fg) {
324 let ns = $fg.data('ns');
325 let tag = $fg.data('tag');
326 let field = $fg.data('field');
329 $('.c', $fg).empty();
331 let selector = "> [x-node='RDF'] > [x-node='Description'] > [x-node='"+tag+"']";
333 selector += "[x-ns='"+ns+"']";
335 $(selector, self.$edited).each(function() {
342 count = $('.c > .input-group', $fg).length;
343 if (field.required) {
345 $('<div class="text-warning">WYMAGANE</div>').appendTo($('.c', $fg));
352 PropertiesPerspective.prototype.addEditField = function(defn, value, elem) {
354 let $form = $("#properties-form", self.$pane);
356 let $fg = $("<div class='form-group'>");
357 $("<label/>").attr("for", "property-" + defn.name).text(defn.name).appendTo($fg);
358 let $input, $inputCnt;
361 $inputCnt =$input = $("<textarea>");
364 $inputCnt = $input = $("<select>");
365 $.each(defn.options, function(i, e) {
366 $("<option>").text(e).appendTo($input);
370 $inputCnt = $input = $("<input type='checkbox'>");
373 $inputCnt = $("<div class='media-input input-group'>");
374 $input = $("<input type='text'>");
375 $inputCnt.append($input);
376 $inputCnt.append($("<button type='button' class='ctrl-media-choose btn btn-primary' data-toggle='modal' data-target='#media-chooser'>…</button>"));
379 $inputCnt = $input = $("<input>");
382 $input.addClass("form-control").attr("id", "property-" + defn.name).data("property", defn.name);
383 if ($input.attr('type') == 'checkbox') {
384 $input.prop('checked', value == 'true');
390 $input.data("edited", elem);
392 $inputCnt.appendTo($fg);
397 PropertiesPerspective.prototype.convert = function(newtag) {
398 this.$edited.attr('x-node', newtag);
399 // TODO: take care of attributes?
402 PropertiesPerspective.prototype.delete = function(newtag) {
403 p = this.$edited.parent();
404 this.$edited.remove();
408 PropertiesPerspective.prototype.onEnter = function(success, failure){
410 $.wiki.SidebarPerspective.prototype.onEnter.call(this);
412 if ($.wiki.activePerspective() != 'VisualPerspective')
413 $.wiki.switchToTab('#VisualPerspective');
415 if (self.$edited === null) {
416 self.edit($('[x-node="utwor"]')[0]);
420 $.wiki.PropertiesPerspective = PropertiesPerspective;