Rakka.editPage = function (baseURI, pageName) { var $body = $("div.body"); $body.text("Loading... please wait."); // XML 版のページを取得する。 $.ajax({ url : baseURI + pageName + ".xml", success: function (pageXml) { 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("source").text(); Rakka.displayPageEditor($body, pageName, oldRevision, defaultType, source); }, error : function (req) { if (req.status == 404) { Rakka.displayPageEditor($body, pageName, null, "rakka", null); } else { $body.text("Error: " + req.status + " " + req.statusText); } } }); }; Rakka.displayPageEditor = function ($place, pageName, oldRevision, defaultType, source) { $place.empty(); $place.append($.H1({}, "Edit page")); var fldPageName = $.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 fldCSSSource = $.TEXTAREA({}, (defaultType == "css" && source != null ? source : "")); var fldUploadFile = $.INPUT({type: "file"}); var trContent = $.TR({}, $.TH({}), $.TD({}) ); var btnPreview = $.INPUT({type: "button", value: "Preview page"}); var btnSubmit = $.INPUT({type: "button", value: "Submit page"}); var btnDelete = $.INPUT({type: "button", value: "Delete this page"}); var updateTRContent = function () { if (btnTypeRakka.checked) { $(trContent).find("th").text("Wiki source"); $(trContent).find("td").empty().append(fldRakkaSource); $(trContent).show(); } else if (btnTypeCSS.checked) { $(trContent).find("th").text("CSS source"); $(trContent).find("td").empty().append(fldCSSSource); $(trContent).show(); } else if (btnTypeBinary.checked) { $(trContent).find("th").text("File"); $(trContent).find("td").empty().append(fldUploadFile); $(trContent).show(); } else { $(trContent).hide(); } }; $(btnTypeRakka ).change(updateTRContent); $(btnTypeCSS ).change(updateTRContent); $(btnTypeBinary).change(updateTRContent); updateTRContent(); var pageEditor = $.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) ) ) ); if (oldRevision == null || oldRevision == 0) { // 削除不可 $(btnDelete).hide(); } $place.append(pageEditor); };