* Readonly document view.
[redakcja.git] / platforma / static / js / wiki / wikiapi.js
index d0ac5dc..27ab97e 100644 (file)
        function WikiDocument(element_id) {
                var meta = $('#' + element_id);
                this.id = meta.attr('data-document-name');
+
                this.revision = $("*[data-key='revision']", meta).text();
+               this.readonly = !!$("*[data-key='readonly']", meta).text();
+
                this.galleryLink = $("*[data-key='gallery']", meta).text();
                this.galleryImages = [];
                this.text = null;
@@ -77,6 +80,7 @@
                $.ajax({
                        method: "GET",
                        url: reverse("ajax_document_text", self.id),
+                       data: {"revision": self.revision},
                        dataType: 'json',
                        success: function(data) {
                                var changed = false;
                        }
                });
        };
+
        /*
         * Fetch gallery
         */
                        }
                });
        };
+
        /*
         * Set document's text
         */
                this.text = text;
                this.has_local_changes = true;
        };
+
        /*
         * Set document's gallery link
         */
                this.galleryLink = gallery;
                this.has_local_changes = true;
        };
+
        /*
         * Save text back to the server
         */
                $.each(params['form'].serializeArray(), function() {
                        data[this.name] = this.value;
                });
-               
+
                var metaComment = '<!--';
                metaComment += '\n\tgallery:' + self.galleryLink;
                metaComment += '\n-->\n'
                        }
                });
        }; /* end of save() */
+
        WikiDocument.prototype.publish = function(params) {
                params = $.extend({}, noops, params);
                var self = this;
                var data = {
                        "addtag-id": self.id,
                };
-               
+
                /* unpack form */
                $.each(params.form.serializeArray(), function() {
                        data[this.name] = this.value;
                });
-               
+
                $.ajax({
                        url: reverse("ajax_document_addtag", self.id),
                        type: "POST",
                                                        "__all__": ["Nie udało się - błąd serwera."]
                                                });
                                        };
-
                                };
-
                        }
                });
        };
+
        $.wikiapi.WikiDocument = WikiDocument;
 })(jQuery);