+
+ var previewRakkaPage = function (pageName, source) {
+ Rakka.displayWaitingMessage("Loading... please wait.");
+
+ var url = Rakka.baseURI + "render/" + encodeURI(pageName);
+ $.ajax({
+ type : "POST",
+ url : url,
+ contentType: "text/x-rakka",
+ data : source,
+ processData: false,
+ success : function (resultDoc) {
+ Rakka.hideWaitingMessage();
+ showPreview(resultDoc);
+ },
+ error : function (req) {
+ Rakka.hideWaitingMessage();
+ alert("Error: " + req.status + " " + req.statusText);
+ }
+ });
+ };
+
+ var previewBinaryPage = function (pageName, data) {
+ Rakka.displayWaitingMessage("Loading... please wait.");
+
+ /* Firefox でバイナリを送らうとすると 0x00 の位置で切れてしまふ。*/
+ var url = Rakka.baseURI + "render/" + encodeURI(pageName);
+ $.ajax({
+ type : "POST",
+ url : url,
+ contentType: "application/x-rakka-base64-stream",
+ data : Rakka.encodeBase64(data),
+ processData: false,
+ success : function (resultDoc) {
+ Rakka.hideWaitingMessage();
+ showPreview(resultDoc);
+ },
+ error : function (req) {
+ Rakka.hideWaitingMessage();
+ alert("Error: " + req.status + " " + req.statusText);
+ }
+ });
+ };
+
+ var showPreview = function (doc) {
+ $previewArea.empty();
+
+ $previewHeader.show();
+ $previewArea.show();
+
+ var root = doc.documentElement;
+ var child = root.firstChild;
+ do {
+ if (child.nodeType == 1) {
+ // 要素だったので複製
+ $previewArea.append(child.cloneNode(true));
+ }
+ } while (child = child.nextSibling);
+
+ Rakka.scrollToTopLeft();
+ };
+
+ var submitTextPage
+ = function (pageName, oldRevision, givenPageName, isLocked, mimeType, lang, otherLangs, summary, text) {
+ var NS = "http://cielonegro.org/schema/Rakka/Page/1.0";
+ var doc = document.implementation.createDocument(NS, "page", null);
+ var page = doc.documentElement;
+
+ if (oldRevision != null) {
+ // ページ書換時
+ var updateInfo = doc.createElementNS(NS, "updateInfo");
+ updateInfo.setAttribute("oldRevision", oldRevision);
+
+ if (pageName != givenPageName) {
+ var move = doc.createElementNS(NS, "move");
+ move.setAttribute("from", pageName);
+ updateInfo.appendChild(move);
+ }
+
+ page.appendChild(updateInfo);
+ }
+
+ page.setAttribute("isLocked", isLocked ? "yes" : "no");
+ page.setAttribute("type", mimeType);
+
+ if (lang != null && lang != "") {
+ page.setAttribute("lang", lang);
+ }
+
+ if (summary != null && summary != "") {
+ var s = doc.createElementNS(NS, "summary");
+ s.appendChild(
+ doc.createTextNode(summary));
+ page.appendChild(s);
+ }
+
+ var oLang = doc.createElementNS(NS, "otherLang");
+ for (var tag in otherLangs) {
+ var link = doc.createElementNS(NS, "link");
+ link.setAttribute("lang", tag);
+ link.setAttribute("page", otherLangs[tag]);
+ oLang.appendChild(link);
+ }
+ page.appendChild(oLang);
+
+ var textData = doc.createElementNS(NS, "textData");
+ textData.appendChild(
+ doc.createTextNode(text));
+
+ page.appendChild(textData);
+
+ Rakka.displayWaitingMessage("Submitting... please wait.");
+
+ var url = Rakka.baseURI + encodeURI(givenPageName);
+ $.ajax({
+ type : "PUT",
+ url : url,
+ contentType: "text/xml",
+ data : doc,
+ processData: false,
+ beforeSend : function (req) {
+ Rakka.setAuthorization(req);
+ },
+ success : function () {
+ window.location.replace(url);
+ },
+ error : function (req) {
+ Rakka.hideWaitingMessage();
+
+ var $area = Rakka.switchScreen();
+ $area.text("Error: " + req.status + " " + req.statusText);
+ }
+ });
+ };
+
+ var submitBinaryPage = function (pageName, oldRevision, givenPageName, isLocked, lang, otherLangs, summary, data) {
+ var NS = "http://cielonegro.org/schema/Rakka/Page/1.0";
+ var doc = document.implementation.createDocument(NS, "page", null);
+ var page = doc.documentElement;
+
+ if (oldRevision != null) {
+ // ページ書換時
+ var updateInfo = doc.createElementNS(NS, "updateInfo");
+ updateInfo.setAttribute("oldRevision", oldRevision);
+
+ if (pageName != givenPageName) {
+ var move = doc.createElementNS(NS, "move");
+ move.setAttribute("from", pageName);
+ updateInfo.appendChild(move);
+ }
+
+ page.appendChild(updateInfo);
+ }
+
+ page.setAttribute("isLocked", isLocked ? "yes" : "no");
+ page.setAttribute("type", "");
+
+ if (lang != null && lang != "") {
+ page.setAttribute("lang", lang);
+ }
+
+ if (summary != null) {
+ var s = doc.createElementNS(NS, "summary");
+ s.appendChild(
+ doc.createTextNode(summary));
+ page.appendChild(s);
+ }
+
+ var oLang = doc.createElementNS(NS, "otherLang");
+ for (var tag in otherLangs) {
+ var link = doc.createElementNS(NS, "link");
+ link.setAttribute("lang", tag);
+ link.setAttribute("page", otherLangs[tag]);
+ oLang.appendChild(link);
+ }
+ page.appendChild(oLang);
+
+ var b64 = Rakka.encodeBase64(data);
+ var binaryData = doc.createElementNS(NS, "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,
+ beforeSend : function (req) {
+ Rakka.setAuthorization(req);
+ },
+ success : function () {
+ window.location.replace(url);
+ },
+ error : function (req) {
+ Rakka.hideWaitingMessage();
+
+ var $area = Rakka.switchScreen();
+ $area.text("Error: " + req.status + " " + req.statusText);
+ }
+ });
+ };
+
+ var submitRedirection = function (pageName, oldRevision, givenPageName, isLocked, destination) {
+ var NS = "http://cielonegro.org/schema/Rakka/Page/1.0";
+ var doc = document.implementation.createDocument(NS, "page", null);
+ var page = doc.documentElement;
+
+ if (oldRevision != null) {
+ // ページ書換時
+ var updateInfo = doc.createElementNS(NS, "updateInfo");
+ updateInfo.setAttribute("oldRevision", oldRevision);
+
+ if (pageName != givenPageName) {
+ var move = doc.createElementNS(NS, "move");
+ move.setAttribute("from", pageName);
+ updateInfo.appendChild(move);
+ }
+
+ page.appendChild(updateInfo);
+ }
+
+ page.setAttribute("isLocked", isLocked ? "yes" : "no");
+ page.setAttribute("redirect", destination);
+
+ Rakka.displayWaitingMessage("Submitting... please wait.");
+
+ var url = Rakka.baseURI + encodeURI(givenPageName);
+ $.ajax({
+ type : "PUT",
+ url : url,
+ contentType: "text/xml",
+ data : doc,
+ processData: false,
+ beforeSend : function (req) {
+ Rakka.setAuthorization(req);
+ },
+ success : function () {
+ window.location.replace(url);
+ },
+ error : function (req) {
+ Rakka.hideWaitingMessage();
+
+ var $area = Rakka.switchScreen();
+ $area.text("Error: " + req.status + " " + req.statusText);
+ }
+ });
+ };
+
+ var deletePage = function (pageName) {
+ var url = Rakka.baseURI + encodeURI(pageName);
+ $.ajax({
+ type : "DELETE",
+ url : url,
+ beforeSend : function (req) {
+ Rakka.setAuthorization(req);
+ },
+ success : function () {
+ window.location.replace(url);
+ },
+ error : function (req) {
+ Rakka.hideWaitingMessage();
+
+ var $area = Rakka.switchScreen();
+ $area.text("Error: " + req.status + " " + req.statusText);
+ }
+ });
+ };
+
+})();
\ No newline at end of file