From: Radek Czajka Date: Tue, 27 Jun 2023 10:02:46 +0000 (+0200) Subject: Image chooser. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/4cab8b0725fd5a88f5a508e584b4acd346a824fc?ds=inline;hp=2de0fde86873c879961365b4b9ce3904a158e84f Image chooser. --- diff --git a/src/cover/views.py b/src/cover/views.py index e89e7962..d00123cc 100644 --- a/src/cover/views.py +++ b/src/cover/views.py @@ -22,7 +22,7 @@ from cover import forms from cover.utils import get_import_data -PREVIEW_SIZE = (216, 300) +PREVIEW_SIZE = (212, 300) def preview(request, book, chunk=None, rev=None): diff --git a/src/documents/models/book.py b/src/documents/models/book.py index 1b34fb64..f40af29b 100644 --- a/src/documents/models/book.py +++ b/src/documents/models/book.py @@ -399,7 +399,7 @@ class Book(models.Model): self.build_cover() def build_cover(self): - width, height = 216, 300 + width, height = 212, 300 try: xml = self.materialize(publishable=True).encode('utf-8') info = BookInfo.from_bytes(xml) diff --git a/src/redakcja/settings/__init__.py b/src/redakcja/settings/__init__.py index 6e705f1f..70512cb5 100644 --- a/src/redakcja/settings/__init__.py +++ b/src/redakcja/settings/__init__.py @@ -125,6 +125,8 @@ LEGIMI_BIG_WORDS = 10000 LEGIMI_SMALL_PRICE = 7 LEGIMI_BIG_PRICE = 20 +THUMBNAIL_PRESERVE_FORMAT = True + STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', diff --git a/src/redakcja/static/css/html.scss b/src/redakcja/static/css/html.scss index cfd7fc2d..881083a6 100644 --- a/src/redakcja/static/css/html.scss +++ b/src/redakcja/static/css/html.scss @@ -538,3 +538,13 @@ div[x-node] > .uwaga { border:0; color: black; } + + +#media-chooser { + img { + border: 3px solid transparent; + &.active { + border-color: green; + } + } +} diff --git a/src/redakcja/static/img/sample_cover.png b/src/redakcja/static/img/sample_cover.png index f7a678e4..355a82db 100644 Binary files a/src/redakcja/static/img/sample_cover.png and b/src/redakcja/static/img/sample_cover.png differ diff --git a/src/redakcja/static/js/wiki/view_gallery.js b/src/redakcja/static/js/wiki/view_gallery.js index e04342ff..5152f439 100644 --- a/src/redakcja/static/js/wiki/view_gallery.js +++ b/src/redakcja/static/js/wiki/view_gallery.js @@ -150,7 +150,7 @@ newPage = normalizeNumber(newPage, this.doc.galleryImages.length); this.$numberInput.val(newPage); this.config().page = newPage; - $('.gallery-image img', this.$element).attr('src', this.doc.galleryImages[newPage - 1]); + $('.gallery-image img', this.$element).attr('src', this.doc.galleryImages[newPage - 1].url); }; ScanGalleryPerspective.prototype.alterZoom = function(delta){ diff --git a/src/redakcja/static/js/wiki/view_properties.js b/src/redakcja/static/js/wiki/view_properties.js index 204a4dec..54051737 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", @@ -151,6 +152,26 @@ }); + $('#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'); + $.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')); @@ -334,22 +355,28 @@ let $fg = $("
"); $("