X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/9d566b4741eb66bf09b5c7d213aa8541886e100a..491078616e2129745f300c1f0357f5bac52e801d:/src/redakcja/static/js/wiki/view_properties.js?ds=inline diff --git a/src/redakcja/static/js/wiki/view_properties.js b/src/redakcja/static/js/wiki/view_properties.js index 35d00690..dde914fc 100644 --- a/src/redakcja/static/js/wiki/view_properties.js +++ b/src/redakcja/static/js/wiki/view_properties.js @@ -35,17 +35,20 @@ "name": "href", }, ], - } + "tab": {"attributes": [{"name": "szer"}]}, + "naglowek_parsza": {"attributes": [{"name": "nazwa"}]}, + "naglowek_czytanie": {"attributes": [{"name": "nazwa"}]} + }, }; class PropertiesPerspective extends $.wiki.SidebarPerspective { - constructor(options) { - let oldCallback = options.callback || function() {}; + vsplitbar = 'WŁAŚCIWOŚCI'; + $edited = null; - options.callback = function() { + constructor(options) { + super(options); let self = this; - self.vsplitbar = 'WŁAŚCIWOŚCI'; self.$pane = $("#side-properties"); $("#simple-editor").on('click', '[x-node]', function(e) { @@ -79,6 +82,7 @@ } else { $input.data("edited").text(inputval); } + $.wiki.perspectives.VisualPerspective.flush(); return; } @@ -100,6 +104,7 @@ let htmlElem = $(html); self.$edited.replaceWith(htmlElem); self.edit(htmlElem); + $.wiki.activePerspective().flush(); } }); }, @@ -137,6 +142,9 @@ rdfdesc.append('\n '); rdf.append('\n '); } + if (field.filter && field.filter.startswith) { + span.text(field.filter.startswith[0]); + } span.appendTo(rdfdesc); rdfdesc.append('\n '); @@ -147,8 +155,10 @@ self.$pane.on('click', '.meta-delete', function() { let $fg = $(this).closest('.form-group'); - $('input', $fg).data('edited').remove(); + let $ig = $(this).closest('.input-group'); + $('input', $ig).data('edited').remove(); self.displayMetaProperty($fg); + $.wiki.perspectives.VisualPerspective.flush(); return false; }); @@ -158,12 +168,17 @@ modal.data('target-input', input); var imglist = modal.find('.modal-body'); imglist.html(''); - $.each(self.doc.galleryImages, (i, imgItem) => { - img = $("").attr("src", imgItem.thumb).attr('title', imgItem.url).data('url', imgItem.url).on('click', function() { - imglist.find('img').removeClass('active'); - $(this).addClass('active'); - }); - imglist.append(img); + + self.doc.refreshImageGallery({ + success: function(galleryImages) { + $.each(self.doc.galleryImages, (i, imgItem) => { + let img = $("").attr("src", imgItem.thumb).attr('title', imgItem.url).data('url', imgItem.url).on('click', function() { + imglist.find('img').removeClass('active'); + $(this).addClass('active'); + }); + imglist.append(img); + }); + } }); }) $('#media-chooser .ctrl-ok').on('click', function (event) { @@ -174,17 +189,72 @@ $('#media-chooser').modal('hide'); }); + /* Meta chooser */ + $('#meta-chooser').on('show.bs.modal', function (event) { + let input = $("input", $(event.relatedTarget).closest('.input-group')); + let $fg = $(event.relatedTarget).closest('.form-group'); + let field = $fg.data('field'); + let modal = $(this); + modal.data('target-input', input); + let body = modal.find('.modal-body'); + body.html(''); + + let add_options = function(cnt, options, value) { + $.each(options, (i, item) => { + let elem = $('
'); + if (!item.usable) { + $('input', elem).remove(); + } + if (item.hidden) { + $('input', elem).prop('disabled', 'disabled'); + } + $('input', elem).val(item.value); + $('input', elem).val(item.value); + $('.value', elem).text(item.value); + $('.name', elem).append(item.name); + $('.description', elem).append(item.description); + let valueMatch = value && value.startsWith(item.value); + if (valueMatch) { + $('label', elem).addClass('text-primary') + if (value == item.value) { + $('input', elem).prop('checked', true); + } + } + if (item.sub) { + let subT = $('
+
'); + let sub = $('
'); + elem.append(subT); + elem.append(sub); + subT.on('click', () => { + sub.toggle() + }); + add_options(sub, item.sub, valueMatch ? value : null); + } + elem.appendTo(cnt); + }); + }; + + $.ajax({ + url: field.value_type.chooser.source, + data: field.filter ? {'filter': JSON.stringify(field.filter)} : '', + success: function(data) { + add_options(body, data, input.val()); + } + }); + }) + $('#meta-chooser .ctrl-ok').on('click', function (event) { + $('#meta-chooser').data('target-input').val( + $('#meta-chooser :checked').val() + ).trigger('change'); + $('#meta-chooser').modal('hide'); + }); + self.$pane.on('click', '.current-convert', function() { self.convert($(this).attr('data-to')); }); self.$pane.on('click', '#current-delete', function() { self.delete(); }); - - oldCallback.call(this); - }; - - super(options); } edit(element) { @@ -198,6 +268,7 @@ if (element === null) { self.$edited = null; + $("h1", self.$pane).text(''); return; } @@ -311,11 +382,27 @@ let ap = $("
"); ap.appendTo(ig); + + if (field.value_type.chooser) { + ap.append($("")); + } $("").appendTo(ap); // lang } + applyFilter(filter, text) { + if (filter.not) { + return !this.applyFilter(filter.not, text) + } else if (filter.startswith) { + for (prefix of filter.startswith) { + if (text.startsWith(prefix)) + return true; + } + return false; + } + } + displayMetaProperty($fg) { let self = this; let ns = $fg.data('ns'); @@ -330,6 +417,11 @@ selector += "[x-ns='"+ns+"']"; } $(selector, self.$edited).each(function() { + if (field.filter) { + let text = $(this).text(); + if (!self.applyFilter(field.filter, text)) + return; + } self.addMetaInput( $('.c', $fg), field, @@ -407,10 +499,17 @@ if ($.wiki.activePerspective() != 'VisualPerspective') $.wiki.switchToTab('#VisualPerspective'); - if (self.$edited === null) { - self.edit($('[x-node="utwor"]')[0]); + this.enable(); + } + + enable() { + if (this.$edited === null) { + this.edit($('[x-node="utwor"]')[0]); } } + disable() { + this.edit(null); + } } $.wiki.PropertiesPerspective = PropertiesPerspective;