From 0e6ca63a4a026d1501f6d8a7724da24976f35832 Mon Sep 17 00:00:00 2001 From: sanj Date: Fri, 14 Jan 2011 17:44:50 +0530 Subject: [PATCH] added video and audio stuff --- COPYING | 14 ++++++++ edgware/editor/models.py | 32 +++++++++++++---- edgware/editor/views.py | 21 ++++++++--- edgware/static/js/editor.js | 70 +++++++++++++++++++++---------------- 4 files changed, 95 insertions(+), 42 deletions(-) create mode 100644 COPYING diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..c97633a --- /dev/null +++ b/COPYING @@ -0,0 +1,14 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2010 Sanjay Bhangar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. + diff --git a/edgware/editor/models.py b/edgware/editor/models.py index 8dab948..07eed36 100644 --- a/edgware/editor/models.py +++ b/edgware/editor/models.py @@ -309,18 +309,34 @@ class Page(models.Model): textBoxes = [] for t in TextBox.objects.filter(page = self).exclude(is_displayed = False): textBoxes.append(t.to_dict()) - ''' + videos = [] - for v in self.videos: + for v in self.videos.all(): r = { - 'title' = v.fil.title, - 'description' = v.fil.description - 'srts' = [] - for s in v.srt: + 'id': v.id, + 'title': v.fil.title, + 'description': v.fil.description, + 'file': v.fil.file.url, + 'mime': 'video' + } + videos.append(r) + + audios = [] + for a in self.audios.all(): + r = { + 'id': a.id, + 'title': a.fil.title, + 'description': a.fil.description, + 'file': a.fil.file.url, + 'mime': 'audio' + } + audios.append(r) + + ''' #Resources: - ''' + resources = [] for res in self.resources.all(): r = {} @@ -339,6 +355,8 @@ class Page(models.Model): 'id': self.id, 'imageBoxes' : imageBoxes, 'textBoxes': textBoxes, + 'videos': videos, + 'audios': audios # 'resources' : resources } diff --git a/edgware/editor/views.py b/edgware/editor/views.py index 6c62039..579f494 100644 --- a/edgware/editor/views.py +++ b/edgware/editor/views.py @@ -39,6 +39,7 @@ def edit_page(request, id): """ send GET request to to /edit/add_media/ with page_id and resource_id . """ +@login_required def add_media(request): page_id = request.GET['page_id'] file_id = request.GET['resource_id'] @@ -49,13 +50,15 @@ def add_media(request): if typ == 'video': try: video = Video.objects.get(fil__id=file_id) - page.videos.append(video) + page.videos.add(video) + page.save() except: pass elif typ == 'audio': try: audio = Audio.objects.get(fil__id=file_id) - page.audios.append(audio) + page.audios.add(audio) + page.save() except: pass page.save() @@ -64,6 +67,7 @@ def add_media(request): } return HttpResponse(simplejson.dumps(r), mimetype="application/json") +@login_required def add_srt(request): file_id = request.POST['id'] mime = request.POST['mime'] @@ -95,7 +99,7 @@ def edit_article(request, id): } return render_to_response("editor.html", rDict) - +@login_required def image_rotate(request, id): image_id = int(id) if request.GET.has_key('degree'): @@ -121,6 +125,7 @@ def testCrop(request): } return render_to_response("testCrop.html", d) +@login_required def imagebox_crop(request): o = request.GET # project_path = "/home/sanj/soc/edgware-py/" @@ -150,6 +155,7 @@ def test_thumb(request): r = {'path': 'media/images/original/facade.jpg'} return render_to_response("thumbnailTmp.txt", r) +@login_required def textbox_new(request): if request.GET['json']: box = TextBox() @@ -181,7 +187,8 @@ def textbox_new(request): return HttpResponse(j, mimetype="application/json") else: return False - + +@login_required def textbox_update_css(request): box_id = request.GET['id'] try: @@ -215,6 +222,7 @@ def textbox_update_css(request): j = json.dumps(r) return HttpResponse(j, mimetype="application/json") +@login_required def textbox_set_html(request): id = request.GET['id'] html = request.GET['html'] @@ -238,6 +246,7 @@ def textbox_set_html(request): } return HttpResponse(json.dumps(r), mimetype="application/json") +@login_required def textbox_delete(request): id = request.GET['id'] box = TextBox.objects.get(pk=id) @@ -256,6 +265,7 @@ def textbox_delete(request): }) return HttpResponse(str(rev_id)) +@login_required def imagebox_new(request): jsonString = request.GET['json'] d = json.loads(jsonString) @@ -287,6 +297,7 @@ def imagebox_new(request): j = json.dumps(r) return HttpResponse(j, mimetype="application/json") +@login_required def imagebox_update_css(request): box_id = request.GET['id'] box = ImageBox.objects.get(pk = box_id) @@ -315,6 +326,7 @@ def imagebox_update_css(request): j = json.dumps(r) return HttpResponse(j, mimetype="application/json") +@login_required def imagebox_resize(request): box_id = request.GET['id'] width = request.GET['width'] @@ -352,6 +364,7 @@ def imagebox_resize(request): j = json.dumps(r) return HttpResponse(j, mimetype="application/json") +@login_required def imagebox_delete(request): id = request.GET['id'] box = ImageBox.objects.get(pk=id) diff --git a/edgware/static/js/editor.js b/edgware/static/js/editor.js index 9844a51..7fdca9e 100644 --- a/edgware/static/js/editor.js +++ b/edgware/static/js/editor.js @@ -272,67 +272,75 @@ Canvas.prototype.init = function() { new_index = parseInt(highest_index) + 1; // console.log('index: ' + new_index); i = new ImageBox(c, r, {css: {'z-index': "" + new_index, 'top':toPx((ev.pageY - top) - height), 'left': toPx((ev.pageX - left) - width)}}); - } - else if (r.mime == 'audio') { - media_box = $(this).children('.audio_video'); - $.getJSON('/edit/add_media/', { - resource_id: r.id, - page_id: c.id - }, function(data) { - media_box.append(""); - }); + } else if (r.mime == 'audio' || r.mime == 'video') { + that.addMedia(r); + } - } - else if (r.mime == 'video') { - - media_box = $(this).children('.audio_video'); - $.getJSON('/edit/add_media/', { - resource_id: r.id, - page_id: c.id - }, function(data) { - media_box.append(""); - }); - - } - } - else { + } else { var elem = $(ui.draggable); top = $(this).position().top; left = $(this).position().left; if (elem.hasClass('arabic')) { t = new TextBox(c, {'html': '

انقر على مربع التحرير

', 'css': {'direction': 'rtl'}}); - } else { + } else { t = new TextBox(c); - } + } width = parseInt(t.jq.css('width') / 2); height = parseInt(t.jq.css('height') / 2); t.setCSS({'top':toPx((ev.pageY - top) - height), 'left': toPx((ev.pageX - left) - width)}); highest_index = getHighestIndex(c.jq); new_index = parseInt(highest_index) + 1; t.setCSS({'z-index': new_index}); - } + } // console.log('dropper'); - } - }); + } + }); return this; - } +} +Canvas.prototype.addMedia = function(resource) { + var that = this; + $.getJSON("/edit/add_media/", { + resource_id: resource.id, + page_id: that.id + }, function(response) { + that.addMediaIcon(resource); + }); +} + +Canvas.prototype.addMediaIcon = function(resource) { + var typ = resource.mime; + var media_box = this.jq.find('.audio_video'); + $('').addClass('media_icon').addClass(typ + '_icon').attr("src", "/static/images/icons/" + typ + ".png").attr("title", resource.title).data("resource", resource).appendTo(media_box); +} Canvas.prototype.loadFromJSON = function(json) { +// alert(JSON.stringify(json)); // GLOBALFOO = json; var imageBoxes = json.imageBoxes; var textBoxes = json.textBoxes; + var videos = json.videos; + var audios = json.audios; +// alert(audios.length); var that = this; for (var i=0; i < imageBoxes.length; i++) { var resource = imageBoxes[i].resource; var b = new ImageBox(that, resource, imageBoxes[i]); // that.imageBoxes.append(b); - } + } for (var t=0; t < textBoxes.length; t++) { var b = new TextBox(that, textBoxes[t]); // that.textBoxes.append(b); - } } + for (var v=0; v < videos.length; v++) { + var video = videos[v]; + that.addMediaIcon(video); + } + for (var a=0; a < audios.length; a++) { + var audio = audios[a]; + that.addMediaIcon(audio); + } +} Canvas.prototype.toObj = function() { var that = this;