Obey length limits for wikidata import.
[redakcja.git] / src / redakcja / static / js / wiki / view_properties.js
index 56bd84d..dde914f 100644 (file)
                     "name": "href",
                 },
             ],
                     "name": "href",
                 },
             ],
-        }
+            "tab": {"attributes": [{"name": "szer"}]},
+            "naglowek_parsza": {"attributes": [{"name": "nazwa"}]},
+            "naglowek_czytanie": {"attributes": [{"name": "nazwa"}]}
+        },
     };
 
     class PropertiesPerspective extends $.wiki.SidebarPerspective {
     };
 
     class PropertiesPerspective extends $.wiki.SidebarPerspective {
                         rdfdesc.append('\n    ');
                         rdf.append('\n  ');
                     }
                         rdfdesc.append('\n    ');
                         rdf.append('\n  ');
                     }
+                    if (field.filter && field.filter.startswith) {
+                        span.text(field.filter.startswith[0]);
+                    }
                     span.appendTo(rdfdesc);
                     rdfdesc.append('\n    ');
 
                     span.appendTo(rdfdesc);
                     rdfdesc.append('\n    ');
 
                     modal.data('target-input', input);
                     var imglist = modal.find('.modal-body');
                     imglist.html('');
                     modal.data('target-input', input);
                     var imglist = modal.find('.modal-body');
                     imglist.html('');
-                    $.each(self.doc.galleryImages, (i, imgItem) => {
-                        img = $("<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 = $("<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 .ctrl-ok').on('click', function (event) {
 
                 $.ajax({
                     url: field.value_type.chooser.source,
 
                 $.ajax({
                     url: field.value_type.chooser.source,
+                    data: field.filter ? {'filter': JSON.stringify(field.filter)} : '',
                     success: function(data) {
                         add_options(body, data, input.val());
                     }
                     success: function(data) {
                         add_options(body, data, input.val());
                     }
             // lang
         }
 
             // 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');
         displayMetaProperty($fg) {
             let self = this;
             let ns = $fg.data('ns');
                 selector += "[x-ns='"+ns+"']";
             }
             $(selector, self.$edited).each(function() {
                 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,
                 self.addMetaInput(
                     $('.c', $fg),
                     field,