+ else if (btnTypeBinary.checked) {
+ if (uploadFileBin != "") {
+ previewBinaryPage(
+ fldPageName.value, uploadFileBin);
+ }
+ }
+ });
+
+ var btnSubmit
+ = $.INPUT({type: "button", value: "Submit page"});
+
+ $(btnSubmit).click(function () {
+ if (btnTypeRakka.checked) {
+ submitTextPage(
+ pageName,
+ oldRevision,
+ fldPageName.value,
+ chkIsLocked.checked,
+ "text/x-rakka",
+ $(selPageLang).val(),
+ otherLangs,
+ fldSummary.value,
+ fldRakkaSource.value);
+ }
+ else if (btnTypeCSS.checked) {
+ submitTextPage(
+ pageName,
+ oldRevision,
+ fldPageName.value,
+ chkIsLocked.checked,
+ "text/css",
+ $(selPageLang).val(),
+ otherLangs,
+ 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(
+ pageName,
+ oldRevision,
+ fldPageName.value,
+ chkIsLocked.checked,
+ $(selPageLang).val(),
+ otherLangs,
+ fldSummary.value,
+ uploadFileBin);
+ }
+ }
+ else if (btnTypeRedirect.checked) {
+ submitRedirection(
+ pageName,
+ oldRevision,
+ fldPageName.value,
+ chkIsLocked.checked,
+ fldRedirect.value);
+ }
+ });
+
+ var btnDelete
+ = $.INPUT({type: "button", value: "Delete this page"});
+
+ $(btnDelete).click(function () {
+ if (window.confirm("Do you really want to delete this page?")) {
+ deletePage(pageName);
+ }
+ });
+
+ var updateTRContent = function () {
+ if (btnTypeRakka.checked) {
+ $(trPageLang).show();
+ $(trOtherLangs).show();
+ $(trSummary).show();
+ $(trContent).find("th").text("Wiki source");
+ $(trContent).find("td").empty().append(fldRakkaSource);
+ $(btnPreview).show();
+ }
+ else if (btnTypeCSS.checked) {
+ $(trPageLang).show();
+ $(trOtherLangs).show();
+ $(trSummary).show();
+ $(trContent).find("th").text("CSS source");
+ $(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).append(btnSelectFile);
+ $(btnPreview).show();
+ }
+ else if (btnTypeRedirect.checked) {
+ $(trPageLang).hide();
+ $(trOtherLangs).hide();
+ $(trSummary).hide();
+ $(trContent).find("th").text("Destination Page");
+ $(trContent).find("td").empty().append(fldRedirect);
+ $(btnPreview).hide();
+ }
+ };
+ $(btnTypeRakka ).change(updateTRContent);
+ $(btnTypeCSS ).change(updateTRContent);
+ $(btnTypeJS ).change(updateTRContent);
+ $(btnTypeBinary ).change(updateTRContent);
+ $(btnTypeRedirect).change(updateTRContent);
+ updateTRContent();
+
+ var pageEditor
+ = $.TABLE({className: "pageEditor"},
+ $.TBODY({},
+ $.TR({},
+ $.TH({}, "Page name"),
+ $.TD({}, fldPageName)
+ ),
+ trIsLocked,
+ $.TR({},
+ $.TH({}, "Page type"),
+ $.TD({},
+ $.UL({},
+ $.LI({},
+ $.LABEL({},
+ btnTypeRakka,
+ "Wiki page"
+ )
+ ),
+ $.LI({},
+ $.LABEL({},
+ btnTypeCSS,
+ "Style sheet"
+ )
+ ),
+ $.LI({},
+ $.LABEL({},
+ btnTypeJS,
+ "JavaScript"
+ )
+ ),
+ $.LI({},
+ $.LABEL({},
+ btnTypeBinary,
+ "Binary file"
+ )
+ ),
+ $.LI({},
+ $.LABEL({},
+ btnTypeRedirect,
+ "Redirection"
+ )
+ )
+ )
+ )
+ ),
+ trPageLang,
+ trOtherLangs,
+ trSummary,
+ trContent,
+ $.TR({},
+ $.TH({}),
+ $.TD({}, btnPreview, btnSubmit, btnDelete)
+ )
+ )
+ );
+
+ var validate = function () {
+ var isValid = (function () {
+ if (fldPageName.value.match(Rakka.rePageName) == null) {
+ return false;
+ }
+
+ if (btnTypeRedirect.checked) {
+ if (fldRedirect.value.match(Rakka.rePageName) == null) {
+ return false;
+ }
+ }
+ else {
+ for (var tag in otherLangs) {
+ if (otherLangs[tag].match(Rakka.rePageName) == null) {
+ return false;
+ }
+ }
+
+ if (btnTypeBinary.checked) {
+ if (uploadFileBin == "") {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ })();
+
+ $(btnSubmit).attr({disabled: (isValid ? "" : "disabled")});
+ };
+ $(fldPageName)
+ .add(btnTypeRakka)
+ .add(btnTypeCSS)
+ .add(btnTypeJS)
+ .add(btnTypeBinary)
+ .add(btnTypeRedirect)
+ .add($(trOtherLangs).find("input"))
+ .add(fldUploadFile)
+ .add(fldRedirect)
+ .change(validate)
+ .keyup(validate);
+ $(btnSelectFile).click(validate);
+ validate();
+
+ if (oldRevision == null || oldRevision == 0) {
+ // 削除不可
+ $(btnDelete).hide();