From 5a3d3d2e9d2ab67218144f7c2e35d70f47f9ad93 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Mon, 4 Jun 2018 20:27:23 -0500 Subject: converted jrnl entry to use image for featured image --- app/utils/static/image-loader.js | 30 ++++++++++++++++++++++++++++++ app/utils/widgets.py | 8 ++++++++ 2 files changed, 38 insertions(+) (limited to 'app/utils') diff --git a/app/utils/static/image-loader.js b/app/utils/static/image-loader.js index 90054de..2b0a281 100644 --- a/app/utils/static/image-loader.js +++ b/app/utils/static/image-loader.js @@ -2,6 +2,36 @@ function add_images(){ var el = document.getElementById("id_body_markdown"); var iframe = ''; el.insertAdjacentHTML('afterend', iframe); + + var featured_image = document.getElementById("id_featured_image") + + if (featured_image) { + featured_image.querySelectorAll('li').forEach(function(element) { + var cur = element.dataset.imageid + if (cur != "") { + var request = new XMLHttpRequest(); + request.open('GET', '/photos/luximage/data/admin/tn/'+cur+'/', true); + request.onload = function() { + if (request.status >= 200 && request.status < 400) { + var data = JSON.parse(request.responseText); + var el = element.getElementsByTagName('label')[0]; + url = "url('"+data['url']+"');"; + //console.log(url); + el.style.backgroundImage = 'url('+data["url"]+')'; + + //console.log(el.style); + } else { + console.log("server error", request.statusText); + } + }; + request.onerror = function() { + console.log("error on request"); + }; + request.send(); + } + }); + } + } document.addEventListener("DOMContentLoaded", function(event) { add_images(); diff --git a/app/utils/widgets.py b/app/utils/widgets.py index eac4631..2b76f6b 100644 --- a/app/utils/widgets.py +++ b/app/utils/widgets.py @@ -99,6 +99,11 @@ def thumbnail(image_path): return '%s' % (absolute_url, image_path) +class ImageRadioSelect(forms.RadioSelect): + template_name = 'horizontal_select.html' + + + class AdminImageWidget(AdminFileWidget): """ A FileField Widget that displays an image instead of a file path @@ -124,6 +129,7 @@ class LGEntryForm(forms.ModelForm): class Meta: widgets = { 'body_markdown': forms.Textarea(attrs={'rows': 40, 'cols': 100}), + 'featured_image': ImageRadioSelect, } @@ -132,6 +138,8 @@ class LGEntryFormSmall(forms.ModelForm): widgets = { 'body_markdown': forms.Textarea(attrs={'rows': 12, 'cols': 100}), } + + class OLAdminBase(OSMGeoAdmin): default_lon = -9285175 default_lat = 4025046 -- cgit v1.2.3-70-g09d2