Reorganize depot models in preparation for more.
[redakcja.git] / src / redakcja / static / js / wiki / wikiapi.js
index 426c7f6..1bf6ebb 100644 (file)
             this.galleryStart = parseInt($("*[data-key='gallery-start']", meta).text());
             this.fullUri = $("*[data-key='full-uri']", meta).text();
 
             this.galleryStart = parseInt($("*[data-key='gallery-start']", meta).text());
             this.fullUri = $("*[data-key='full-uri']", meta).text();
 
-            var diff = $("*[data-key='diff']", meta).text();
-            if (diff) {
-                diff = diff.split(',');
-                if (diff.length == 2 && diff[0] < diff[1])
-                    this.diff = diff;
-                else if (diff.length == 1) {
-                    diff = parseInt(diff);
-                    if (diff != NaN)
-                        this.diff = [diff - 1, diff];
-                }
-            }
-
            this.galleryImages = [];
            this.text = null;
            this.has_local_changes = false;
            this.galleryImages = [];
            this.text = null;
            this.has_local_changes = false;
 
                    if (self.text === null || self.revision !== data.revision) {
                        self.text = data.text;
 
                    if (self.text === null || self.revision !== data.revision) {
                        self.text = data.text;
+                        $.wiki.undo.push(data.text);
                        self.revision = data.revision;
                        self.gallery = data.gallery;
                        changed = true;
                        self.revision = data.revision;
                        self.gallery = data.gallery;
                        changed = true;
         /*
          * Set document's text
          */
         /*
          * Set document's text
          */
-        setText(text) {
+        setText(text, silent=false) {
             if (text == this.text) return;
             if (text == this.text) return;
+            if (!silent) {
+                $.wiki.undo.push(text);
+            }
             this.text = text;
             this.has_local_changes = true;
         }
 
             this.text = text;
             this.has_local_changes = true;
         }
 
+        undo() {
+            let ctx = $.wiki.exitContext();
+            this.setText(
+                $.wiki.undo.undo(),
+                true
+            );
+            $.wiki.enterContext(ctx);
+        }
+        redo() {
+            let ctx = $.wiki.exitContext();
+            this.setText(
+                $.wiki.undo.redo(),
+                true
+            );
+            $.wiki.enterContext(ctx);
+        }
+
         /*
          * Save text back to the server
          */
         /*
          * Save text back to the server
          */