diff options
Diffstat (limited to 'app/utils')
-rw-r--r-- | app/utils/static/image-loader.js | 30 | ||||
-rw-r--r-- | app/utils/widgets.py | 8 |
2 files changed, 38 insertions, 0 deletions
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 = '<iframe frameborder="0" style="border: #dddddd 1px solid;margin-left: 20px;width:330px; height:720px;" src="/luximages/insert/?textarea='+el.id+'"></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 '<img style="max-width: 400px" src="%s" alt="%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 |