log = logging.getLogger('platforma.api.library')
from piston.handler import BaseHandler, AnonymousBaseHandler
+from piston.utils import rc
from datetime import date
#
class DocumentGalleryHandler(BaseHandler):
- allowed_methods = ('GET')
+ allowed_methods = ('GET', 'POST')
def read(self, request, docid):
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
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");
{
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();
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());
+ });
}
},
{% 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>