From 8d490fc7810e0052bad3414b445b24276bbfca63 Mon Sep 17 00:00:00 2001 From: zuber Date: Fri, 6 Nov 2009 13:41:22 +0100 Subject: [PATCH 1/1] Ustawianie galerii inline. --- apps/api/handlers/library_handlers.py | 25 ++++++++++++++++++++++-- platforma/static/js/models.js | 16 +++++++++++++++ platforma/static/js/views/gallery.js | 8 ++++++++ platforma/templates/explorer/editor.html | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/apps/api/handlers/library_handlers.py b/apps/api/handlers/library_handlers.py index 948bad4b..7e90e313 100755 --- a/apps/api/handlers/library_handlers.py +++ b/apps/api/handlers/library_handlers.py @@ -5,6 +5,7 @@ import logging log = logging.getLogger('platforma.api.library') from piston.handler import BaseHandler, AnonymousBaseHandler +from piston.utils import rc from datetime import date @@ -327,7 +328,7 @@ class DocumentHTMLHandler(BaseHandler): # class DocumentGalleryHandler(BaseHandler): - allowed_methods = ('GET') + allowed_methods = ('GET', 'POST') def read(self, request, docid): @@ -372,7 +373,27 @@ class DocumentGalleryHandler(BaseHandler): return galleries - + def create(self, request, docid): + if not request.user.is_superuser: + return rc.FORBIDDEN + + new_path = request.POST.get('path') + + if new_path: + gallery, created = GalleryForDocument.objects.get_or_create( + document = docid, + defaults = { + 'subpath': new_path, + } + ) + + if not created: + gallery.subpath = new_path + gallery.save() + + return rc.CREATED + + return rc.BAD_REQUEST # # Dublin Core handlers diff --git a/platforma/static/js/models.js b/platforma/static/js/models.js index ba2f3ce3..2c36e2bb 100755 --- a/platforma/static/js/models.js +++ b/platforma/static/js/models.js @@ -360,6 +360,22 @@ Editor.ImageGalleryModel = Editor.Model.extend({ this.pages = []; }, + setGallery: function(path) { + $.ajax({ + url: this.serverURL, + type: 'post', + data: { + path: path, + }, + success: this.settingGallerySucceeded.bind(this) + }); + }, + + settingGallerySucceeded: function(data) { + console.log('settingGallerySucceeded'); + this.load(true); + }, + load: function(force) { if (force || this.get('state') == 'empty') { console.log("setting state"); diff --git a/platforma/static/js/views/gallery.js b/platforma/static/js/views/gallery.js index d3398ce0..a403c9ef 100644 --- a/platforma/static/js/views/gallery.js +++ b/platforma/static/js/views/gallery.js @@ -220,6 +220,8 @@ var ImageGalleryView = View.extend({ { if(!this.model) return; + $('.choose-gallery-button', this.element).unbind(); + /* first unbind all */ if(this.$nextButton) this.$nextButton.unbind(); if(this.$prevButton) this.$prevButton.unbind(); @@ -261,6 +263,12 @@ var ImageGalleryView = View.extend({ this.changePageZoom(this.pageZoom); } else { this._super(template); + + var self = this; + $('.choose-gallery-button', self.element).click(function() { + console.log('CLICK CLICK') + self.model.setGallery($('#id_subpath', self.element).val()); + }); } }, diff --git a/platforma/templates/explorer/editor.html b/platforma/templates/explorer/editor.html index 0dcc06bc..8930c944 100755 --- a/platforma/templates/explorer/editor.html +++ b/platforma/templates/explorer/editor.html @@ -140,7 +140,7 @@ {% if user.is_superuser %} {% endif %} -- 2.20.1