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 let $node = $(element);
175 $("#parents", self.$pane).empty();
176 $("#bubbles").empty();
178 let b = $("<div class='badge badge-primary'></div>").text($node.attr('x-node'));
179 b.data('node', element);
180 $("#bubbles").append(b);
182 $node.parents('[x-node]').each(function() {
183 let a = $("<li class='breadcrumb-item'>").text($(this).attr('x-node'));
184 a.data('node', this);
185 $("#parents", self.$pane).prepend(a)
187 let b = $("<div class='badge badge-info'></div>").text($(this).attr('x-node'));
188 b.data('node', this);
189 $("#bubbles").append(b);
193 node = $(element).attr('x-node');
194 $("h1", self.$pane).text(node);
196 $f = $("#properties-form", self.$pane);
198 self.$edited = $(element);
200 let nodeDef = elementDefs[node];
201 if (nodeDef && nodeDef.attributes) {
202 $.each(nodeDef.attributes, function(i, a) {
203 self.addEditField(a, $(element).attr('x-a-wl-' + a.name)); // ...
207 // Only utwor can has matadata now.
208 if (node == 'utwor') {
209 $('<hr>').appendTo($("#properties-form", self.$pane))
210 META_FIELDS.forEach(function(field) {
211 let $fg = $("<div class='form-group'>");
212 $("<label/>").text(field.name).appendTo($fg);
215 $("<button class='meta-add float-right btn btn-primary'>+</button>").appendTo($fg);
217 let match = field.uri.match(/({(.*)})?(.*)/);
221 let cont = $('<div class="c">');
224 $fg.data('tag', tag);
225 $fg.data('field', field);
228 self.displayMetaProperty($fg);
230 $fg.appendTo( $("#properties-form", self.$pane));
234 // check node type, find relevant tags
235 if ($node[0].nodeName == 'DIV') {
236 $("#current-convert").attr("data-current-type", "div");
237 } else if ($node[0].nodeName == 'EM') {
238 $("#current-convert").attr("data-current-type", "span");
242 PropertiesPerspective.prototype.addMetaInput = function(cont, field, element) {
245 let ig = $('<div class="input-group">');
246 //ig.data('edited', element);
249 if (field.value_type.hasLanguage) {
250 let pp = $("<div class='input-group-prepend'>");
251 let lang_input = $("<input class='form-control' size='1' class='lang'>");
252 lang_input.data('edited', $(element));
253 lang_input.data('edited-attr', 'x-a-xml-lang');
255 $(element).attr('x-a-xml-lang')
257 lang_input.appendTo(pp);
262 if (field.value_type.widget == 'select') {
263 $aninput = $("<select class='form-control'>");
264 $.each(field.value_type.options, function() {
265 $("<option>").text(this).appendTo($aninput);
268 $aninput = $("<input class='form-control'>");
269 if (field.value_type.autocomplete) {
270 $aninput.autocomplete(field.value_type.autocomplete);
273 $aninput.data('edited', $(element))
277 $aninput.appendTo(ig);
279 let ap = $("<div class='input-group-append'>");
281 $("<button class='meta-delete btn btn-outline-secondary'>x</button>").appendTo(ap);
287 PropertiesPerspective.prototype.displayMetaProperty = function($fg) {
289 let ns = $fg.data('ns');
290 let tag = $fg.data('tag');
291 let field = $fg.data('field');
294 $('.c', $fg).empty();
296 let selector = "> [x-node='RDF'] > [x-node='Description'] > [x-node='"+tag+"']";
298 selector += "[x-ns='"+ns+"']";
300 $(selector, self.$edited).each(function() {
307 count = $('.c > .input-group', $fg).length;
308 if (field.required) {
310 $('<div class="text-warning">WYMAGANE</div>').appendTo($('.c', $fg));
317 PropertiesPerspective.prototype.addEditField = function(defn, value, elem) {
319 let $form = $("#properties-form", self.$pane);
321 let $fg = $("<div class='form-group'>");
322 $("<label/>").attr("for", "property-" + defn.name).text(defn.name).appendTo($fg);
326 $input = $("<textarea>");
329 $input = $("<select>");
330 $.each(defn.options, function(i, e) {
331 $("<option>").text(e).appendTo($input);
335 $input = $("<input type='checkbox'>");
338 $input = $("<input>");
341 $input.addClass("form-control").attr("id", "property-" + defn.name).data("property", defn.name);
342 if ($input.attr('type') == 'checkbox') {
343 $input.prop('checked', value == 'true');
349 $input.data("edited", elem);
351 $input.appendTo($fg);
356 PropertiesPerspective.prototype.convert = function(newtag) {
357 this.$edited.attr('x-node', newtag);
358 // TODO: take care of attributes?
361 PropertiesPerspective.prototype.delete = function(newtag) {
362 p = this.$edited.parent();
363 this.$edited.remove();
367 $.wiki.PropertiesPerspective = PropertiesPerspective;