Rakka.editPage = function (baseURI, pageName) {
- var $body = $("div.body");
-
- $body.text("Loading... please wait.");
+ var $area = Rakka.switchScreen();
+ $area.text("Loading... please wait.");
// XML 版のページを取得する。
$.ajax({
url : baseURI + pageName + ".xml",
success: function (pageXml) {
- var $page = $(pageXml).find("page");
- var oldRevision = $page.attr("revision");
- var defaultAction = $page.attr("isBinary") == "yes" ? "uploadFile"
- : $page.attr("type") == "text/x-rakka" ? "editAsWiki"
- : $page.attr("type") == "text/css" ? "editAsCSS"
- : "unknown"
- ;
- var source = $page.find("source").text();
- Rakka.displayPageEditor($body, pageName, oldRevision, defaultAction, source);
- },
+ var $page = $(pageXml).find("page");
+ var oldRevision = $page.attr("revision");
+ var defaultType
+ = $page.attr("isBinary") == "yes" ? "binary"
+ : $page.attr("type") == "text/x-rakka" ? "rakka"
+ : $page.attr("type") == "text/css" ? "css"
+ : "unknown"
+ ;
+ var source = $page.find("textData").text();
+ Rakka.displayPageEditor(baseURI, pageName, oldRevision, defaultType, source);
+ },
error : function (req) {
- if (req.status == 404) {
- Rakka.displayPageEditor($body, pageName, null, "editAsWiki");
- }
- else {
- $body.text("Error: " + req.status + " " + req.statusText);
- }
- }
- });
+ if (req.status == 404) {
+ Rakka.displayPageEditor(baseURI, pageName, null, "rakka", null);
+ }
+ else {
+ $area.text("Error: " + req.status + " " + req.statusText);
+ }
+ }
+ });
};
-Rakka.displayPageEditor = function ($place, pageName, oldRevision, defaultAction, source) {
- $place.empty();
+Rakka.displayPageEditor = function (baseURI, pageName, oldRevision, defaultType, source) {
+ var $area = Rakka.switchScreen();
+ $area.empty();
+
+ $area.append($.H1({}, "Edit page"));
var fldPageName
- = $.INPUT({type : "text", value: pageName});
+ = $.INPUT({type : "text", value: pageName});
+
+ var btnTypeRakka
+ = $.INPUT({type : "radio",
+ name : "type",
+ checked: (defaultType == "rakka" ? "checked" : "")});
+
+ var btnTypeCSS
+ = $.INPUT({type : "radio",
+ name : "type",
+ checked: (defaultType == "css" ? "checked" : "")});
+
+ var btnTypeBinary
+ = $.INPUT({type : "radio",
+ name : "type",
+ checked: (defaultType == "binary" ? "checked" : "")});
+
+
+ var fldRakkaSource
+ = $.TEXTAREA({}, (defaultType == "rakka" && source != null ? source : ""));
- var btnEditAsWiki
- = $.INPUT({type : "radio",
- name : "action",
- checked: (defaultAction == "editAsWiki" ? "checked" : "")});
+ var fldCSSSource
+ = $.TEXTAREA({}, (defaultType == "css" && source != null ? source : ""));
- var btnEditAsCSS
- = $.INPUT({type : "radio",
- name : "action",
- checked: (defaultAction == "editAsCSS" ? "checked" : "")});
+ var fldUploadFile
+ = $.INPUT({type: "file"});
- var btnUploadFile
- = $.INPUT({type : "radio",
- name : "action",
- checked: (defaultAction == "uploadFile" ? "checked" : "")});
+ var trContent
+ = $.TR({},
+ $.TH({}),
+ $.TD({})
+ );
+
+ var btnPreview
+ = $.INPUT({type: "button", value: "Preview page"});
+
+ $(btnPreview).click(function () {
+ throw new Error("FIXME: not implemented yet");
+ });
+
+ var btnSubmit
+ = $.INPUT({type: "button", value: "Submit page"});
+
+ $(btnSubmit).click(function () {
+ if (btnTypeRakka.checked) {
+ Rakka.submitTextPage(
+ baseURI,
+ pageName,
+ oldRevision,
+ fldPageName.value,
+ "text/x-rakka",
+ fldRakkaSource.value);
+ }
+ else if (btnTypeCSS.checked) {
+ Rakka.submitTextPage(
+ baseURI,
+ pageName,
+ oldRevision,
+ fldPageName.value,
+ "text/css",
+ fldCSSSource.value);
+ }
+ else if (btnTypeBinary.checked) {
+ Rakka.submitBinaryPage(
+ baseURI,
+ pageName,
+ oldRevision,
+ fldPageName.value,
+ fldUploadFile.value);
+ }
+ });
var btnDelete
- = $.INPUT({type : "radio",
- name : "action",
- checked: ""});
+ = $.INPUT({type: "button", value: "Delete this page"});
+
+ $(btnDelete).click(function () {
+ throw new Error("FIXME: not implemented yet");
+ });
+
+ var updateTRContent = function () {
+ if (btnTypeRakka.checked) {
+ $(trContent).find("th").text("Wiki source");
+ $(trContent).find("td").empty().append(fldRakkaSource);
+ }
+ else if (btnTypeCSS.checked) {
+ $(trContent).find("th").text("CSS source");
+ $(trContent).find("td").empty().append(fldCSSSource);
+ }
+ else if (btnTypeBinary.checked) {
+ $(trContent).find("th").text("File");
+ $(trContent).find("td").empty().append(fldUploadFile);
+ }
+ };
+ $(btnTypeRakka ).change(updateTRContent);
+ $(btnTypeCSS ).change(updateTRContent);
+ $(btnTypeBinary).change(updateTRContent);
+ updateTRContent();
var pageEditor
- = $.TABLE({className: "pageEditor"},
- $.TBODY({},
- $.TR({},
- $.TH({}, "Name of the page"),
- $.TD({}, fldPageName)
- ),
- $.TR({},
- $.TH({}, "Action"),
- $.TD({},
- $.UL({},
- $.LI({},
- $.LABEL({},
- btnEditAsWiki,
- "Edit as a Wiki page"
- )
- ),
- $.LI({},
- $.LABEL({},
- btnEditAsCSS,
- "Edit as a style sheet"
- )
- ),
- $.LI({},
- $.LABEL({},
- btnUploadFile,
- "Upload a file"
- )
- ),
- (oldRevision != "" && oldRevision != 0
- ? $.LI({},
- $.LABEL({},
- btnDelete,
- "Delete this page"
+ = $.TABLE({className: "pageEditor"},
+ $.TBODY({},
+ $.TR({},
+ $.TH({}, "Page name"),
+ $.TD({}, fldPageName)
+ ),
+ $.TR({},
+ $.TH({}, "Page type"),
+ $.TD({},
+ $.UL({},
+ $.LI({},
+ $.LABEL({},
+ btnTypeRakka,
+ "Wiki page"
+ )
+ ),
+ $.LI({},
+ $.LABEL({},
+ btnTypeCSS,
+ "Style sheet"
+ )
+ ),
+ $.LI({},
+ $.LABEL({},
+ btnTypeBinary,
+ "Binary file"
+ )
+ )
+ )
+ )
+ ),
+ trContent,
+ $.TR({},
+ $.TH({}),
+ $.TD({}, btnPreview, btnSubmit, btnDelete)
+ )
)
- )
- : [])
- )
- )
- )
- )
- );
-
- $place.append(pageEditor);
+ );
+
+ if (oldRevision == null || oldRevision == 0) {
+ // 削除不可
+ $(btnDelete).hide();
+ }
+
+ $area.append(pageEditor);
+};
+
+Rakka.submitTextPage = function (baseURI, pageName, oldRevision, givenPageName, mimeType, text) {
+ 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);
+ }
+
+ if (0) {
+ // redirection
+ }
+ else {
+ page.setAttribute("type", mimeType);
+
+ var textData = doc.createElement("textData");
+ textData.appendChild(
+ doc.createTextNode(text));
+
+ page.appendChild(textData);
+ }
+
+ $.ajax({
+ type : "PUT",
+ url : baseURI + encodeURI(givenPageName),
+ contentType: "text/xml",
+ data : doc,
+ processData: false
+ });
};