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);
246 let $aninput = $("<input class='form-control'>");
247 $aninput.data('edited', $(element))
251 $aninput.appendTo(ig);
253 let ap = $("<div class='input-group-append'>");
255 $("<button class='meta-delete btn btn-outline-secondary'>x</button>").appendTo(ap);
261 PropertiesPerspective.prototype.displayMetaProperty = function($fg) {
263 let ns = $fg.data('ns');
264 let tag = $fg.data('tag');
265 let field = $fg.data('field');
268 $('.c', $fg).empty();
270 $("> [x-node='RDF'] > [x-node='Description'] > [x-node='"+tag+"'][x-ns='"+ns+"']", self.$edited).each(function() {
277 count = $('.c > .input-group', $fg).length;
278 if (field.required) {
280 $('<div class="text-warning">WYMAGANE</div>').appendTo($('.c', $fg));
287 PropertiesPerspective.prototype.addEditField = function(defn, value, elem) {
289 let $form = $("#properties-form", self.$pane);
291 let $fg = $("<div class='form-group'>");
292 $("<label/>").attr("for", "property-" + defn.name).text(defn.name).appendTo($fg);
296 $input = $("<textarea>");
299 $input = $("<select>");
300 $.each(defn.options, function(i, e) {
301 $("<option>").text(e).appendTo($input);
305 $input = $("<input type='checkbox'>");
308 $input = $("<input>");
311 $input.addClass("form-control").attr("id", "property-" + defn.name).data("property", defn.name);
312 if ($input.attr('type') == 'checkbox') {
313 $input.prop('checked', value == 'true');
319 $input.data("edited", elem);
321 $input.appendTo($fg);
326 PropertiesPerspective.prototype.convert = function(newtag) {
327 this.$edited.attr('x-node', newtag);
328 // TODO: take care of attributes?
331 PropertiesPerspective.prototype.delete = function(newtag) {
332 p = this.$edited.parent();
333 this.$edited.remove();
337 $.wiki.PropertiesPerspective = PropertiesPerspective;