]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - js/editPage.js
implemented summary editor
[Rakka.git] / js / editPage.js
index 2dd99510f2080d3d1ec60860344b3e66deee1eb0..766d2e92383348749c008cff4c2ba4eee043c1ad 100644 (file)
@@ -25,13 +25,15 @@ Rakka.editPage = function (pageName) {
                 = $page.attr("redirect") != null ? $page.attr("redirect")
                 : $page.find("textData").text()
                 ;
-            Rakka.displayPageEditor(pageName, oldRevision, defaultType, source);
+            var summary     = $page.find("summary").text();
+                
+            Rakka.displayPageEditor(pageName, oldRevision, defaultType, source, summary);
         },
         error  : function (req) {
             Rakka.hideWaitingMessage();
             
             if (req.status == 404) {
-                Rakka.displayPageEditor(pageName, null, "rakka", null);
+                Rakka.displayPageEditor(pageName, null, "rakka", null, "");
             }
             else {
                 $area.text("Error: " + req.status + " " + req.statusText);
@@ -41,10 +43,10 @@ Rakka.editPage = function (pageName) {
 };
 
 Rakka.newPage = function () {
-    Rakka.displayPageEditor("", null, "rakka", null);
+    Rakka.displayPageEditor("", null, "rakka", null, "");
 };
 
-Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source) {
+Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source, summary) {
     var $area = Rakka.switchScreen();
     $area.empty();
 
@@ -81,11 +83,21 @@ Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source)
                    name   : "type",
                    checked: (defaultType == "redirect" ? "checked" : "")});
 
+    var fldSummary
+        = $.TEXTAREA({className: "summary"}, summary);
+
+    var trSummary
+        = $.TR({},
+               $.TH({}, "Summary"),
+               $.TD({}, fldSummary));
+
     var fldRakkaSource
-        = $.TEXTAREA({}, (defaultType == "rakka" && source != null ? source : ""));
+        = $.TEXTAREA({className: "source"},
+                     (defaultType == "rakka" && source != null ? source : ""));
 
     var fldCSSSource
-        = $.TEXTAREA({}, (defaultType == "css"   && source != null ? source : ""));
+        = $.TEXTAREA({className: "source"},
+                     (defaultType == "css"   && source != null ? source : ""));
 
     var fldUploadFile
         = $.INPUT({type: "file"});
@@ -123,6 +135,7 @@ Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source)
                 oldRevision,
                 fldPageName.value,
                 "text/x-rakka",
+                fldSummary.value,
                 fldRakkaSource.value);
         }
         else if (btnTypeCSS.checked) {
@@ -131,6 +144,7 @@ Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source)
                 oldRevision,
                 fldPageName.value,
                 "text/css",
+                fldSummary.value,
                 fldCSSSource.value);
         }
         else if (btnTypeBinary.checked) {
@@ -138,6 +152,7 @@ Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source)
                 pageName,
                 oldRevision,
                 fldPageName.value,
+                fldSummary.value,
                 fldUploadFile.value);
         }
         else if (btnTypeRedirect.checked) {
@@ -153,26 +168,32 @@ Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source)
         = $.INPUT({type: "button", value: "Delete this page"});
     
     $(btnDelete).click(function () {
-        throw new Error("FIXME: not implemented yet");
+        if (window.confirm("Do you really want to delete this page?")) {
+            Rakka.deletePage(pageName);
+        }
     });
 
     var updateTRContent = function () {
         if (btnTypeRakka.checked) {
+            $(trSummary).show();
             $(trContent).find("th").text("Wiki source");
             $(trContent).find("td").empty().append(fldRakkaSource);
             $(btnPreview).show();
         }
         else if (btnTypeCSS.checked) {
+            $(trSummary).show();
             $(trContent).find("th").text("CSS source");
             $(trContent).find("td").empty().append(fldCSSSource);
             $(btnPreview).hide();
         }
         else if (btnTypeBinary.checked) {
+            $(trSummary).show();
             $(trContent).find("th").text("File");
             $(trContent).find("td").empty().append(fldUploadFile);
             $(btnPreview).show();
         }
         else if (btnTypeRedirect.checked) {
+            $(trSummary).hide();
             $(trContent).find("th").text("Destination Page");
             $(trContent).find("td").empty().append(fldRedirect);
             $(btnPreview).hide();
@@ -222,6 +243,7 @@ Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source)
                                         )
                                    )
                               ),
+                          trSummary,
                           trContent,
                           $.TR({},
                                $.TH({}),
@@ -253,6 +275,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);
         }
     });
@@ -274,7 +320,7 @@ Rakka.showPreview = function (doc) {
     } while (child = child.nextSibling);
 };
 
-Rakka.submitTextPage = function (pageName, oldRevision, givenPageName, mimeType, text) {
+Rakka.submitTextPage = function (pageName, oldRevision, givenPageName, mimeType, summary, text) {
     var doc = document.implementation.createDocument(
         "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);
 
@@ -296,6 +342,13 @@ Rakka.submitTextPage = function (pageName, oldRevision, givenPageName, mimeType,
 
     page.setAttribute("type", mimeType);
 
+    if (summary != null) {
+        var s = doc.createElement("summary");
+        s.appendChild(
+            doc.createTextNode(summary));
+        page.appendChild(s);
+    }
+
     var textData = doc.createElement("textData");
     textData.appendChild(
         doc.createTextNode(text));
@@ -323,6 +376,65 @@ Rakka.submitTextPage = function (pageName, oldRevision, givenPageName, mimeType,
     });
 };
 
+Rakka.submitBinaryPage = function (pageName, oldRevision, givenPageName, summary, 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", "");
+
+    if (summary != null) {
+        var s = doc.createElement("summary");
+        s.appendChild(
+            doc.createTextNode(summary));
+        page.appendChild(s);
+    }
+
+    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);
@@ -364,4 +476,21 @@ Rakka.submitRedirection = function (pageName, oldRevision, givenPageName, destin
             $area.text("Error: " + req.status + " " + req.statusText);
         }
     });
-};
\ No newline at end of file
+};
+
+Rakka.deletePage = function (pageName) {
+    var url = Rakka.baseURI + encodeURI(pageName);
+    $.ajax({
+        type       : "DELETE",
+        url        : url,
+        success    : function () {
+            window.location.replace(url);
+        },
+        error      : function (req) {
+            Rakka.hideWaitingMessage();
+            
+            var $area = Rakka.switchScreen();
+            $area.text("Error: " + req.status + " " + req.statusText);
+        }
+    });
+};