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 $("> [x-node='RDF'] > [x-node='Description']", self.$edited)
126 self.displayMetaProperty($fg);
131 self.$pane.on('click', '.meta-delete', function() {
132 let $fg = $(this).closest('.form-group');
133 $('input', $fg).data('edited').remove();
134 self.displayMetaProperty($fg);
140 self.$pane.on('click', '.current-convert', function() {
141 self.convert($(this).attr('data-to'));
143 self.$pane.on('click', '#current-delete', function() {
148 oldCallback.call(this);
151 $.wiki.SidebarPerspective.call(this, options);
154 PropertiesPerspective.prototype = new $.wiki.SidebarPerspective();
156 PropertiesPerspective.prototype.edit = function(element) {
159 let $node = $(element);
160 $("#parents", self.$pane).empty();
161 $("#bubbles").empty();
163 let b = $("<div class='badge badge-primary'></div>").text($node.attr('x-node'));
164 b.data('node', element);
165 $("#bubbles").append(b);
167 $node.parents('[x-node]').each(function() {
168 let a = $("<li class='breadcrumb-item'>").text($(this).attr('x-node'));
169 a.data('node', this);
170 $("#parents", self.$pane).prepend(a)
172 let b = $("<div class='badge badge-info'></div>").text($(this).attr('x-node'));
173 b.data('node', this);
174 $("#bubbles").append(b);
178 node = $(element).attr('x-node');
179 $("h1", self.$pane).text(node);
181 $f = $("#properties-form", self.$pane);
183 self.$edited = $(element);
185 let nodeDef = elementDefs[node];
186 if (nodeDef && nodeDef.attributes) {
187 $.each(nodeDef.attributes, function(i, a) {
188 self.addEditField(a, $(element).attr('x-a-wl-' + a.name)); // ...
192 // Only utwor can has matadata now.
193 if (node == 'utwor') {
194 $('<hr>').appendTo($("#properties-form", self.$pane))
195 META_FIELDS.forEach(function(field) {
196 let $fg = $("<div class='form-group'>");
197 $("<label/>").text(field.name).appendTo($fg);
200 $("<button class='meta-add float-right btn btn-primary'>+</button>").appendTo($fg);
202 let match = field.uri.match(/({(.*)})?(.*)/);
206 let cont = $('<div class="c">');
209 $fg.data('tag', tag);
210 $fg.data('field', field);
213 self.displayMetaProperty($fg);
215 $fg.appendTo( $("#properties-form", self.$pane));
219 // check node type, find relevant tags
220 if ($node[0].nodeName == 'DIV') {
221 $("#current-convert").attr("data-current-type", "div");
222 } else if ($node[0].nodeName == 'EM') {
223 $("#current-convert").attr("data-current-type", "span");
227 PropertiesPerspective.prototype.addMetaInput = function(cont, field, element) {
230 let ig = $('<div class="input-group">');
231 //ig.data('edited', element);
234 if (field.value_type.hasLanguage) {
235 let pp = $("<div class='input-group-prepend'>");
236 let lang_input = $("<input class='form-control' size='1' class='lang'>");
237 lang_input.data('edited', $(element));
238 lang_input.data('edited-attr', 'x-a-xml-lang');
240 $(element).attr('x-a-xml-lang')
242 lang_input.appendTo(pp);
247 if (field.value_type.widget == 'select') {
248 $aninput = $("<select class='form-control'>");
249 $.each(field.value_type.options, function() {
250 $("<option>").text(this).appendTo($aninput);
253 $aninput = $("<input class='form-control'>");
254 if (field.value_type.autocomplete) {
255 $aninput.autocomplete(field.value_type.autocomplete);
258 $aninput.data('edited', $(element))
262 $aninput.appendTo(ig);
264 let ap = $("<div class='input-group-append'>");
266 $("<button class='meta-delete btn btn-outline-secondary'>x</button>").appendTo(ap);
272 PropertiesPerspective.prototype.displayMetaProperty = function($fg) {
274 let ns = $fg.data('ns');
275 let tag = $fg.data('tag');
276 let field = $fg.data('field');
279 $('.c', $fg).empty();
281 let selector = "> [x-node='RDF'] > [x-node='Description'] > [x-node='"+tag+"']";
283 selector += "[x-ns='"+ns+"']";
285 $(selector, self.$edited).each(function() {
292 count = $('.c > .input-group', $fg).length;
293 if (field.required) {
295 $('<div class="text-warning">WYMAGANE</div>').appendTo($('.c', $fg));
302 PropertiesPerspective.prototype.addEditField = function(defn, value, elem) {
304 let $form = $("#properties-form", self.$pane);
306 let $fg = $("<div class='form-group'>");
307 $("<label/>").attr("for", "property-" + defn.name).text(defn.name).appendTo($fg);
311 $input = $("<textarea>");
314 $input = $("<select>");
315 $.each(defn.options, function(i, e) {
316 $("<option>").text(e).appendTo($input);
320 $input = $("<input type='checkbox'>");
323 $input = $("<input>");
326 $input.addClass("form-control").attr("id", "property-" + defn.name).data("property", defn.name);
327 if ($input.attr('type') == 'checkbox') {
328 $input.prop('checked', value == 'true');
334 $input.data("edited", elem);
336 $input.appendTo($fg);
341 PropertiesPerspective.prototype.convert = function(newtag) {
342 this.$edited.attr('x-node', newtag);
343 // TODO: take care of attributes?
346 PropertiesPerspective.prototype.delete = function(newtag) {
347 p = this.$edited.parent();
348 this.$edited.remove();
352 $.wiki.PropertiesPerspective = PropertiesPerspective;