]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - js/editPage.js
implemented binary file preview/upload
[Rakka.git] / js / editPage.js
index 2dd99510f2080d3d1ec60860344b3e66deee1eb0..a8869fb91b6b01552be1b2341873e92475c24654 100644 (file)
@@ -253,6 +253,30 @@ Rakka.previewRakkaPage = function (pageName, source) {
             Rakka.showPreview(resultDoc);
         },
         error      : function (req) {
+            Rakka.hideWaitingMessage();
+            alert("Error: " + req.status + " " + req.statusText);
+        }
+    });
+};
+
+Rakka.previewBinaryPage = function (pageName, path) {
+    Rakka.displayWaitingMessage("Loading... please wait.");
+
+    /* Firefox でバイナリを送らうとすると 0x00 の位置で切れてしまふ。*/
+    var bin = Rakka.loadLocalBinaryFile(path);
+    var url = Rakka.baseURI + "render/" + encodeURI(pageName);
+    $.ajax({
+        type       : "POST",
+        url        : url,
+        contentType: "application/x-rakka-base64-stream",
+        data       : Rakka.encodeBase64(bin),
+        processData: false,
+        success    : function (resultDoc) {
+            Rakka.hideWaitingMessage();
+            Rakka.showPreview(resultDoc);
+        },
+        error      : function (req) {
+            Rakka.hideWaitingMessage();
             alert("Error: " + req.status + " " + req.statusText);
         }
     });
@@ -323,6 +347,58 @@ Rakka.submitTextPage = function (pageName, oldRevision, givenPageName, mimeType,
     });
 };
 
+Rakka.submitBinaryPage = function (pageName, oldRevision, givenPageName, path) {
+    var doc = document.implementation.createDocument(
+        "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);
+
+    var page = doc.documentElement;
+
+    if (oldRevision != null) {
+        // ページ書換時
+        var updateInfo = doc.createElement("updateInfo");
+        updateInfo.setAttribute("oldRevision", oldRevision);
+
+        if (pageName != givenPageName) {
+            var move = doc.createElement("move");
+            move.setAttribute("from", pageName);
+            updateInfo.appendChild(move);
+        }
+
+        page.appendChild(updateInfo);
+    }
+
+    page.setAttribute("type", "");
+
+    var bin = Rakka.loadLocalBinaryFile(path);
+    var b64 = Rakka.encodeBase64(bin);
+
+    var binaryData = doc.createElement("binaryData");
+    binaryData.appendChild(
+        doc.createTextNode(b64));
+
+    page.appendChild(binaryData);
+
+    Rakka.displayWaitingMessage("Submitting... please wait.");
+
+    var url = Rakka.baseURI + encodeURI(givenPageName);
+    $.ajax({
+        type       : "PUT",
+        url        : url,
+        contentType: "text/xml",
+        data       : doc,
+        processData: false,
+        success    : function () {
+            window.location.replace(url);
+        },
+        error      : function (req) {
+            Rakka.hideWaitingMessage();
+            
+            var $area = Rakka.switchScreen();
+            $area.text("Error: " + req.status + " " + req.statusText);
+        }
+    });
+};
+
 Rakka.submitRedirection = function (pageName, oldRevision, givenPageName, destination) {
     var doc = document.implementation.createDocument(
         "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);