X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/008b2c8d44987a6ef6b405ffc2124f28d3c6220d..28866d0f2520b7515f3c06e9b61bcce4f44d53b1:/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 eeddf678..e38a7d07 100644 --- a/src/redakcja/static/js/wiki/view_properties.js +++ b/src/redakcja/static/js/wiki/view_properties.js @@ -8,6 +8,7 @@ "attributes": [ { "name": "src", + "type": "media", }, { "name": "alt", @@ -119,9 +120,24 @@ if (field.value_type.hasLanguage) { span.attr('x-a-xml-lang', 'pl'); } - span.appendTo( - $("> [x-node='RDF'] > [x-node='Description']", self.$edited) - ); + + rdf = $("> [x-node='RDF']", self.$edited); + if (!rdf.length) { + rdf = $(""); + self.$edited.prepend(rdf); + self.$edited.prepend('\n '); + + } + rdfdesc = $("> [x-node='Description']", rdf); + if (!rdfdesc.length) { + rdfdesc = $(""); + rdf.prepend(rdfdesc); + rdf.prepend('\n '); + rdfdesc.append('\n '); + rdf.append('\n '); + } + span.appendTo(rdfdesc); + rdfdesc.append('\n '); self.displayMetaProperty($fg); @@ -136,6 +152,27 @@ }); + $('#media-chooser').on('show.bs.modal', function (event) { + var input = $("input", $(event.relatedTarget).parent()); + var modal = $(this); + 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); + }); + }) + $('#media-chooser .ctrl-ok').on('click', function (event) { + $('#media-chooser').data('target-input') + .val( + (new URL($('#media-chooser .active').data('url'), document.baseURI)).href + ).trigger('change'); + $('#media-chooser').modal('hide'); + }); self.$pane.on('click', '.current-convert', function() { self.convert($(this).attr('data-to')); @@ -156,10 +193,18 @@ PropertiesPerspective.prototype.edit = function(element) { let self = this; - let $node = $(element); $("#parents", self.$pane).empty(); $("#bubbles").empty(); + $f = $("#properties-form", self.$pane); + $f.empty(); + + if (element === null) { + self.$edited = null; + return; + } + + let $node = $(element); let b = $("
").text($node.attr('x-node')); b.data('node', element); $("#bubbles").append(b); @@ -178,8 +223,6 @@ node = $(element).attr('x-node'); $("h1", self.$pane).text(node); - $f = $("#properties-form", self.$pane); - $f.empty(); self.$edited = $(element); let nodeDef = elementDefs[node]; @@ -243,7 +286,26 @@ pp.appendTo(ig); } - let $aninput = $(""); + let $aninput; + if (field.value_type.widget == 'select') { + $aninput = $(""); + if (field.value_type.autocomplete) { + let autoOptions = field.value_type.autocomplete; + $aninput.autocomplete(autoOptions).autocomplete('instance')._renderItem = function(ul, item) { + let t = item.label; + if (item.name) t += '
' + item.name + ''; + if (item.description) t += '
' + item.description + ''; + return $( "
  • " ) + .append( "
    " + t + "
    " ) + .appendTo( ul ); + }; + } + } $aninput.data('edited', $(element)) $aninput.val( $(element).text() @@ -266,13 +328,24 @@ // clear container $('.c', $fg).empty(); - - $("> [x-node='RDF'] > [x-node='Description'] > [x-node='"+tag+"'][x-ns='"+ns+"']", self.$edited).each(function() { + + let selector = "> [x-node='RDF'] > [x-node='Description'] > [x-node='"+tag+"']"; + if (ns) { + selector += "[x-ns='"+ns+"']"; + } + $(selector, self.$edited).each(function() { self.addMetaInput( $('.c', $fg), field, this); }); + + count = $('.c > .input-group', $fg).length; + if (field.required) { + if (!count) { + $('
    WYMAGANE
    ').appendTo($('.c', $fg)); + } + } }; @@ -283,22 +356,28 @@ let $fg = $("
    "); $("