Ustawianie galerii inline.
authorzuber <marek@stepniowski.com>
Fri, 6 Nov 2009 12:41:22 +0000 (13:41 +0100)
committerzuber <marek@stepniowski.com>
Fri, 6 Nov 2009 12:41:22 +0000 (13:41 +0100)
apps/api/handlers/library_handlers.py
platforma/static/js/models.js
platforma/static/js/views/gallery.js
platforma/templates/explorer/editor.html

index 948bad4..7e90e31 100755 (executable)
@@ -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
index ba2f3ce..2c36e2b 100755 (executable)
@@ -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");
index d3398ce..a403c9e 100644 (file)
@@ -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());
+      });
     }
   },
 
index 0dcc06b..8930c94 100755 (executable)
             {% if user.is_superuser %}
             <div class="choose-gallery">
                 <p>Dołącz galerię do dokumentu:</p>
-                <p>{{ gallery_form.subpath }} <input id="choose-gallery" type="submit" value="Dołącz"></p>
+                <p>{{ gallery_form.subpath }} <input class="choose-gallery-button" type="submit" value="Dołącz"></p>
             </div>
             {% endif %}
         </div>