X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=js%2FeditPage.js;h=5297e057726aee809148a390a8f6291c3f3ba286;hb=ee28059eadd401e5f9256df590bbb7491f952685;hp=7e54fbbb75381e773848783a6408e7872070354a;hpb=fa3a9d0aecede2431e669ef33885a116f7d5f0be;p=Rakka.git diff --git a/js/editPage.js b/js/editPage.js index 7e54fbb..5297e05 100644 --- a/js/editPage.js +++ b/js/editPage.js @@ -9,17 +9,17 @@ Rakka.editPage = function (baseURI, pageName) { 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" + 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, defaultAction, source); + Rakka.displayPageEditor($body, pageName, oldRevision, defaultType, source); }, error : function (req) { if (req.status == 404) { - Rakka.displayPageEditor($body, pageName, null, "editAsWiki"); + Rakka.displayPageEditor($body, pageName, null, "rakka", null); } else { $body.text("Error: " + req.status + " " + req.statusText); @@ -28,74 +28,123 @@ Rakka.editPage = function (baseURI, pageName) { }); }; -Rakka.displayPageEditor = function ($place, pageName, oldRevision, defaultAction, source) { +Rakka.displayPageEditor = function ($place, pageName, oldRevision, defaultType, source) { $place.empty(); + $place.append($.H1({}, "Edit page")); + var fldPageName = $.INPUT({type : "text", value: pageName}); - var btnEditAsWiki + var btnTypeRakka = $.INPUT({type : "radio", - name : "action", - checked: (defaultAction == "editAsWiki" ? "checked" : "")}); + name : "type", + checked: (defaultType == "rakka" ? "checked" : "")}); - var btnEditAsCSS + var btnTypeCSS = $.INPUT({type : "radio", - name : "action", - checked: (defaultAction == "editAsCSS" ? "checked" : "")}); + name : "type", + checked: (defaultType == "css" ? "checked" : "")}); - var btnUploadFile + var btnTypeBinary = $.INPUT({type : "radio", - name : "action", - checked: (defaultAction == "uploadFile" ? "checked" : "")}); + 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 : "radio", - name : "action", - checked: ""}); + = $.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({}, "Name of the page"), + $.TH({}, "Page name"), $.TD({}, fldPageName) ), $.TR({}, - $.TH({}, "Action"), + $.TH({}, "Page type"), $.TD({}, $.UL({}, $.LI({}, $.LABEL({}, - btnEditAsWiki, - "Edit as a Wiki page" + btnTypeRakka, + "Wiki page" ) ), $.LI({}, $.LABEL({}, - btnEditAsCSS, - "Edit as a style sheet" + btnTypeCSS, + "Style sheet" ) ), $.LI({}, $.LABEL({}, - btnUploadFile, - "Upload a file" + btnTypeBinary, + "Binary file" ) - ), - (oldRevision != "" && oldRevision != 0 - ? $.LI({}, - $.LABEL({}, - btnDelete, - "Delete this page" - ) - ) - : []) + ) ) ) + ), + trContent, + $.TR({}, + $.TH({}), + $.TD({}, btnPreview, btnSubmit, btnDelete) ) ) ); + if (oldRevision == null || oldRevision == 0) { + // 削除不可 + $(btnDelete).hide(); + } + $place.append(pageEditor); };