From 5317e8243e0c55d39241c825e0e3c27298877d00 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 3 Jan 2013 22:27:42 +0530 Subject: [PATCH] complete front-end view for media galleries --- itf/mediagallery/models.py | 5 ++ itf/mediagallery/urls.py | 1 + itf/mediagallery/views.py | 5 ++ itf/static/js/render_object.js | 28 ++++++--- itf/templates/mediagallery/view.html | 64 ++++++++++++++++++++ itf/templates/modules/scriptbank/script.html | 14 +++-- 6 files changed, 102 insertions(+), 15 deletions(-) create mode 100644 itf/templates/mediagallery/view.html diff --git a/itf/mediagallery/models.py b/itf/mediagallery/models.py index a4c9571..e96422e 100644 --- a/itf/mediagallery/models.py +++ b/itf/mediagallery/models.py @@ -22,6 +22,9 @@ class GalleryAlbum(ItfModel): def get_edit_url(self): return '/mediagallery/edit/%d' % self.id + def get_absolute_url(self): + return '/mediagallery/view/%d' % self.id + def thumbnail(self): if Photo.objects.filter(album=self).count() == 0: return None @@ -29,6 +32,8 @@ class GalleryAlbum(ItfModel): def get_dict(self): return { + 'id': self.id, + 'title': self.title, 'photos': Photo.objects.filter(album=self), 'videos': YoutubeVideo.objects.filter(album=self), 'links': GalleryLink.objects.filter(album=self) diff --git a/itf/mediagallery/urls.py b/itf/mediagallery/urls.py index a794864..fd4519f 100644 --- a/itf/mediagallery/urls.py +++ b/itf/mediagallery/urls.py @@ -1,6 +1,7 @@ from django.conf.urls.defaults import * urlpatterns = patterns('mediagallery.views', + (r'^view/(?P\d+)', 'view'), (r'^add/(?P\d+)/(?P\d+)', 'add'), (r'^edit/(?P\d+)', 'edit'), (r'^edit_title/(?P\d+)', 'edit_title'), diff --git a/itf/mediagallery/views.py b/itf/mediagallery/views.py index f563c9b..efd9f53 100644 --- a/itf/mediagallery/views.py +++ b/itf/mediagallery/views.py @@ -38,6 +38,11 @@ def edit(request, id): return render_to_response("mediagallery/upload.html", context) +def view(request, id): + gallery = get_object_or_404(GalleryAlbum, pk=id) + return render_to_response("mediagallery/view.html", gallery.get_dict()) + + def edit_title(request, id): gallery = get_object_or_404(GalleryAlbum, pk=id) title = request.GET.get("title", "") diff --git a/itf/static/js/render_object.js b/itf/static/js/render_object.js index 5b05537..0643121 100755 --- a/itf/static/js/render_object.js +++ b/itf/static/js/render_object.js @@ -92,26 +92,36 @@ $('.lightboxPrev').live("click", function(e) { $('.thumbsDetails').live("click", function(e) { // alert($(this).attr("data-bigimage")); + e.preventDefault(); var $that = $(this); - var totalImages = $(this).parent().find(".thumbsDetails").length; - var thisIndex = $(this).index(); + var totalImages = $('.thumbsDetails').length; +// var totalImages = $(this).parent().find(".thumbsDetails").length; + var thisIndex = $(this).index('.thumbsDetails'); if (thisIndex < (totalImages - 1)) { var hasNext = true; - var nextImage = $(this).parent().find(".thumbsDetails").eq(thisIndex + 1); - var preloadImage = new Image(); - preloadImage.src = nextImage.attr("data-bigimage"); + var nextImage = $(".thumbsDetails").eq(thisIndex + 1); + if (nextImage.hasAttr("data-bigimage")) { + var preloadImage = new Image(); + preloadImage.src = nextImage.attr("data-bigimage"); + } } if (thisIndex > 0 && totalImages > 1) { var hasPrev = true; - var prevImage = $(this).parent().find(".thumbsDetails").eq(thisIndex - 1); + var prevImage = $(".thumbsDetails").eq(thisIndex - 1); } var $lbox = $('#lightboxPanel'); var $cont = $('
').addClass("lightboxContainer"); - var bigImage = $(this).attr("data-bigimage"); - var $img = $('').attr("src", bigImage).addClass("lightboxImg"); - $img.appendTo($cont); + if ($(this).hasAttr("data-bigimage")) { + var bigImage = $(this).attr("data-bigimage"); + var $img = $('').attr("src", bigImage).addClass("lightboxImg"); + $img.appendTo($cont); + } + if ($(this).hasAttr("data-iframe")) { + var iframe = $(this).attr("data-iframe"); + $cont.append(iframe); + } var imgWidth = parseInt($that.attr("data-width")); var imgHeight = parseInt($that.attr("data-height")); var lightboxWidth = imgWidth + 40; diff --git a/itf/templates/mediagallery/view.html b/itf/templates/mediagallery/view.html new file mode 100644 index 0000000..23ec7f7 --- /dev/null +++ b/itf/templates/mediagallery/view.html @@ -0,0 +1,64 @@ +{% extends 'noel/staticpage.html' %} + +{% load thumbnail %} + +{% block extra_head %} + {{ block.super }} + + +{% endblock %} + +{% block main_content %} + +
+
+ +
+
+ close
+
+ + +

{{ title }}

+{% if photos %} +
+

Photos

+ {% for p in photos %} + {% thumbnail p.image "640" as bigimage %} + {% thumbnail p.image "164x114" crop="center" as thumb %} + + + {% endthumbnail %} + {% endthumbnail %} + + {% endfor %} + +
+{% endif %} + +{% if videos %} +
+

Videos

+ {% for v in videos %} + + {% endfor %} +
+{% endif %} + +{% if links %} + + +{% endif %} + +Close + +{% endblock %} diff --git a/itf/templates/modules/scriptbank/script.html b/itf/templates/modules/scriptbank/script.html index 3c8bcc5..d5fecc2 100755 --- a/itf/templates/modules/scriptbank/script.html +++ b/itf/templates/modules/scriptbank/script.html @@ -251,10 +251,12 @@ $(function() {