X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=js%2FeditPage.js;h=eb5097c54da1fc3bd7fa524bb8d7e7a13a36824b;hb=9c2fc861f3ed609ebb4d0f135aea38ca055bbea8;hp=5d782de880484ded293528371a31f042cb25d3a9;hpb=5ab256be8bbbb1f4a012b41ac1cc3f9b29aa7d57;p=Rakka.git diff --git a/js/editPage.js b/js/editPage.js index 5d782de..eb5097c 100644 --- a/js/editPage.js +++ b/js/editPage.js @@ -3,10 +3,6 @@ var $previewHeader = null; var $previewArea = null; - var isDirty = null; - - var rePageName = /^[^ a-z.|#\[\]][^ .|#\[\]]*$/; - Rakka.editPage = function (pageName) { var $area = Rakka.switchScreen(); @@ -22,11 +18,12 @@ 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" - : $page.attr("redirect") != null ? "redirect" - : "unknown" + = $page.attr("isBinary") == "yes" ? "binary" + : $page.attr("type") == "text/x-rakka" ? "rakka" + : $page.attr("type") == "text/css" ? "css" + : $page.attr("type") == "text/javascript" ? "js" + : $page.attr("redirect") != null ? "redirect" + : "unknown" ; var lang = $page.attr("lang"); var isLocked = $page.attr("isLocked") == "yes"; @@ -39,7 +36,8 @@ })(); var source = $page.attr("redirect") != null ? $page.attr("redirect") - : $page.find("textData").text() + : $page.attr("isBinary") != null ? Rakka.decodeBase64($page.find("binaryData").text()) + : $page.find("textData").text() ; var summary = $page.find("summary").text(); @@ -79,6 +77,7 @@ $area.append($.H1({}, pageName == "" ? "Create page" : "Edit page")); + var isDirty = null; var makeDirty = function () { isDirty = true; }; @@ -116,6 +115,12 @@ $(btnTypeCSS).change(makeDirty); + var btnTypeJS + = $.INPUT({type : "radio", + name : "type", + checked: (defaultType == "js" ? "checked" : "")}); + $(btnTypeJS).change(makeDirty); + var btnTypeBinary = $.INPUT({type : "radio", name : "type", @@ -218,10 +223,27 @@ $(fldCSSSource).change(makeDirty); - var fldUploadFile - = $.INPUT({type: "file"}); + var fldJSSource + = $.TEXTAREA({className: "source"}, + (defaultType == "js" && source != null ? source : "")); - $(fldUploadFile).change(makeDirty); + $(fldJSSource).change(makeDirty); + + var uploadFileBin + = (defaultType == "binary" && source != null ? source : ""); + var fldUploadFile + = $.TEXTAREA({className: "hexDump", disabled: true}, Rakka.hexDump(uploadFileBin, 128)); + var btnSelectFile + = $.INPUT({type: "button", value: "Select file..."}); + + $(btnSelectFile).click(function () { + var path = Rakka.selectFile("Select a binary file to upload", "open"); + if (path != null) { + uploadFileBin = Rakka.loadLocalBinaryFile(path); + fldUploadFile.value = Rakka.hexDump(uploadFileBin, 128); + makeDirty(); + } + }); var fldRedirect = $.INPUT({type: "text", value: (defaultType == "redirect" ? source : "")}); @@ -243,9 +265,9 @@ fldPageName.value, fldRakkaSource.value); } else if (btnTypeBinary.checked) { - if (fldUploadFile.value != "") { + if (uploadFileBin != "") { previewBinaryPage( - fldPageName.value, fldUploadFile.value); + fldPageName.value, uploadFileBin); } } }); @@ -278,6 +300,18 @@ fldSummary.value, fldCSSSource.value); } + else if (btnTypeJS.checked) { + submitTextPage( + pageName, + oldRevision, + fldPageName.value, + chkIsLocked.checked, + "text/javascript", + $(selPageLang).val(), + otherLangs, + fldSummary.value, + fldJSSource.value); + } else if (btnTypeBinary.checked) { if (fldUploadFile.value != "") { submitBinaryPage( @@ -288,7 +322,7 @@ $(selPageLang).val(), otherLangs, fldSummary.value, - fldUploadFile.value); + uploadFileBin); } } else if (btnTypeRedirect.checked) { @@ -341,12 +375,20 @@ $(trContent).find("td").empty().append(fldCSSSource); $(btnPreview).hide(); } + else if (btnTypeJS.checked) { + $(trPageLang).show(); + $(trOtherLangs).show(); + $(trSummary).show(); + $(trContent).find("th").text("JavaScript source"); + $(trContent).find("td").empty().append(fldJSSource); + $(btnPreview).hide(); + } else if (btnTypeBinary.checked) { $(trPageLang).show(); $(trOtherLangs).show(); $(trSummary).show(); $(trContent).find("th").text("File"); - $(trContent).find("td").empty().append(fldUploadFile); + $(trContent).find("td").empty().append(fldUploadFile).append(btnSelectFile); $(btnPreview).show(); } else if (btnTypeRedirect.checked) { @@ -360,6 +402,7 @@ }; $(btnTypeRakka ).change(updateTRContent); $(btnTypeCSS ).change(updateTRContent); + $(btnTypeJS ).change(updateTRContent); $(btnTypeBinary ).change(updateTRContent); $(btnTypeRedirect).change(updateTRContent); updateTRContent(); @@ -388,6 +431,12 @@ "Style sheet" ) ), + $.LI({}, + $.LABEL({}, + btnTypeJS, + "JavaScript" + ) + ), $.LI({}, $.LABEL({}, btnTypeBinary, @@ -416,24 +465,24 @@ var validate = function () { var isValid = (function () { - if (fldPageName.value.match(rePageName) == null) { + if (fldPageName.value.match(Rakka.rePageName) == null) { return false; } if (btnTypeRedirect.checked) { - if (fldRedirect.value.match(rePageName) == null) { + if (fldRedirect.value.match(Rakka.rePageName) == null) { return false; } } else { for (var tag in otherLangs) { - if (otherLangs[tag].match(rePageName) == null) { + if (otherLangs[tag].match(Rakka.rePageName) == null) { return false; } } if (btnTypeBinary.checked) { - if (fldUploadFile.value == "") { + if (uploadFileBin == "") { return false; } } @@ -447,6 +496,7 @@ $(fldPageName) .add(btnTypeRakka) .add(btnTypeCSS) + .add(btnTypeJS) .add(btnTypeBinary) .add(btnTypeRedirect) .add($(trOtherLangs).find("input")) @@ -454,6 +504,7 @@ .add(fldRedirect) .change(validate) .keyup(validate); + $(btnSelectFile).click(validate); validate(); if (oldRevision == null || oldRevision == 0) { @@ -466,8 +517,6 @@ if (!Rakka.isLoggedIn() || Rakka.isGlobalLocked) { $(trIsLocked).hide(); } - - isDirty = false; }; var previewRakkaPage = function (pageName, source) { @@ -491,17 +540,16 @@ }); }; - var previewBinaryPage = function (pageName, path) { + var previewBinaryPage = function (pageName, data) { 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), + data : Rakka.encodeBase64(data), processData: false, success : function (resultDoc) { Rakka.hideWaitingMessage(); @@ -605,7 +653,7 @@ }); }; - var submitBinaryPage = function (pageName, oldRevision, givenPageName, isLocked, lang, otherLangs, summary, path) { + 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; @@ -647,9 +695,7 @@ } page.appendChild(oLang); - var bin = Rakka.loadLocalBinaryFile(path); - var b64 = Rakka.encodeBase64(bin); - + var b64 = Rakka.encodeBase64(data); var binaryData = doc.createElementNS(NS, "binaryData"); binaryData.appendChild( doc.createTextNode(b64));