var $previewHeader = null;
var $previewArea = null;
- var isDirty = null;
-
- var rePageName = /^[^ a-z.|#\[\]][^ .|#\[\]]*$/;
-
Rakka.editPage = function (pageName) {
var $area = Rakka.switchScreen();
Rakka.displayWaitingMessage("Loading... please wait.");
-
+
// XML 版のページを取得する。
$.ajax({
url : Rakka.baseURI + pageName + ".xml",
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";
: $page.find("textData").text()
;
var summary = $page.find("summary").text();
-
+
displayPageEditor(pageName, oldRevision, defaultType, lang, isLocked, otherLangs, source, summary);
}
else {
},
error : function (req) {
Rakka.hideWaitingMessage();
-
+
if (req.status == 404) {
displayPageEditor(pageName, null, "rakka", null, false, {}, null, "");
}
$area.append($.H1({}, pageName == "" ? "Create page" : "Edit page"));
+ var isDirty = null;
var makeDirty = function () {
isDirty = true;
};
-
+
var fldPageName
= $.INPUT({type : "text", value: pageName});
$.LABEL({},
chkIsLocked,
"Disallow anonymous users to edit or delete this page")));
-
+
var btnTypeRakka
= $.INPUT({type : "radio",
name : "type",
$(btnTypeCSS).change(makeDirty);
+ var btnTypeJS
+ = $.INPUT({type : "radio",
+ name : "type",
+ checked: (defaultType == "js" ? "checked" : "")});
+ $(btnTypeJS).change(makeDirty);
+
var btnTypeBinary
= $.INPUT({type : "radio",
name : "type",
$.OPTION({value: ""}, "(unspecified)"),
(function () {
var options = [];
-
+
$.each(Rakka.getSystemConfig().languages, function (tag, name) {
options.push(
$.OPTION({value: tag}, name));
var lang = $(selLang).val();
var pageName = $(this).val();
-
+
if (pageName == "") {
delete otherLangs[lang];
}
$(fldCSSSource).change(makeDirty);
+ var fldJSSource
+ = $.TEXTAREA({className: "source"},
+ (defaultType == "js" && source != null ? source : ""));
+
+ $(fldJSSource).change(makeDirty);
+
var fldUploadFile
= $.INPUT({type: "file"});
$(fldRedirect).change(makeDirty);
var trContent
- = $.TR({},
+ = $.TR({},
$.TH({}),
$.TD({})
);
var btnPreview
= $.INPUT({type: "button", value: "Preview page"});
-
+
$(btnPreview).click(function () {
if (btnTypeRakka.checked) {
previewRakkaPage(
var btnSubmit
= $.INPUT({type: "button", value: "Submit page"});
-
+
$(btnSubmit).click(function () {
if (btnTypeRakka.checked) {
submitTextPage(
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(
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);
$(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();
};
$(btnTypeRakka ).change(updateTRContent);
$(btnTypeCSS ).change(updateTRContent);
+ $(btnTypeJS ).change(updateTRContent);
$(btnTypeBinary ).change(updateTRContent);
$(btnTypeRedirect).change(updateTRContent);
updateTRContent();
"Style sheet"
)
),
+ $.LI({},
+ $.LABEL({},
+ btnTypeJS,
+ "JavaScript"
+ )
+ ),
$.LI({},
$.LABEL({},
btnTypeBinary,
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;
}
}
$(fldPageName)
.add(btnTypeRakka)
.add(btnTypeCSS)
+ .add(btnTypeJS)
.add(btnTypeBinary)
.add(btnTypeRedirect)
.add($(trOtherLangs).find("input"))
if (!Rakka.isLoggedIn() || Rakka.isGlobalLocked) {
$(trIsLocked).hide();
}
-
- isDirty = false;
};
var previewRakkaPage = function (pageName, source) {
Rakka.displayWaitingMessage("Loading... please wait.");
-
+
var url = Rakka.baseURI + "render/" + encodeURI(pageName);
$.ajax({
type : "POST",
var showPreview = function (doc) {
$previewArea.empty();
-
+
$previewHeader.show();
$previewArea.show();
-
+
var root = doc.documentElement;
var child = root.firstChild;
do {
Rakka.scrollToTopLeft();
};
- var submitTextPage = function (pageName, oldRevision, givenPageName, isLocked, mimeType, lang, otherLangs, summary, text) {
- var doc = document.implementation.createDocument(
- "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);
-
- var page = doc.documentElement;
+ var submitTextPage
+ = function (pageName, oldRevision, givenPageName, isLocked, mimeType, lang, otherLangs, summary, text) {
+ var NS = "http://cielonegro.org/schema/Rakka/Page/1.0";
+ var doc = document.implementation.createDocument(NS, "page", null);
+ var page = doc.documentElement;
if (oldRevision != null) {
// ページ書換時
- var updateInfo = doc.createElement("updateInfo");
+ var updateInfo = doc.createElementNS(NS, "updateInfo");
updateInfo.setAttribute("oldRevision", oldRevision);
if (pageName != givenPageName) {
- var move = doc.createElement("move");
+ var move = doc.createElementNS(NS, "move");
move.setAttribute("from", pageName);
updateInfo.appendChild(move);
}
}
if (summary != null && summary != "") {
- var s = doc.createElement("summary");
+ var s = doc.createElementNS(NS, "summary");
s.appendChild(
doc.createTextNode(summary));
page.appendChild(s);
}
- var oLang = doc.createElement("otherLang");
+ var oLang = doc.createElementNS(NS, "otherLang");
for (var tag in otherLangs) {
- var link = doc.createElement("link");
+ var link = doc.createElementNS(NS, "link");
link.setAttribute("lang", tag);
link.setAttribute("page", otherLangs[tag]);
oLang.appendChild(link);
}
page.appendChild(oLang);
- var textData = doc.createElement("textData");
+ var textData = doc.createElementNS(NS, "textData");
textData.appendChild(
doc.createTextNode(text));
},
error : function (req) {
Rakka.hideWaitingMessage();
-
+
var $area = Rakka.switchScreen();
$area.text("Error: " + req.status + " " + req.statusText);
}
};
var submitBinaryPage = function (pageName, oldRevision, givenPageName, isLocked, lang, otherLangs, summary, path) {
- var doc = document.implementation.createDocument(
- "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);
-
+ var NS = "http://cielonegro.org/schema/Rakka/Page/1.0";
+ var doc = document.implementation.createDocument(NS, "page", null);
var page = doc.documentElement;
if (oldRevision != null) {
// ページ書換時
- var updateInfo = doc.createElement("updateInfo");
+ var updateInfo = doc.createElementNS(NS, "updateInfo");
updateInfo.setAttribute("oldRevision", oldRevision);
if (pageName != givenPageName) {
- var move = doc.createElement("move");
+ var move = doc.createElementNS(NS, "move");
move.setAttribute("from", pageName);
updateInfo.appendChild(move);
}
}
if (summary != null) {
- var s = doc.createElement("summary");
+ var s = doc.createElementNS(NS, "summary");
s.appendChild(
doc.createTextNode(summary));
page.appendChild(s);
}
- var oLang = doc.createElement("otherLang");
+ var oLang = doc.createElementNS(NS, "otherLang");
for (var tag in otherLangs) {
- var link = doc.createElement("link");
+ var link = doc.createElementNS(NS, "link");
link.setAttribute("lang", tag);
link.setAttribute("page", otherLangs[tag]);
oLang.appendChild(link);
var bin = Rakka.loadLocalBinaryFile(path);
var b64 = Rakka.encodeBase64(bin);
- var binaryData = doc.createElement("binaryData");
+ var binaryData = doc.createElementNS(NS, "binaryData");
binaryData.appendChild(
doc.createTextNode(b64));
},
error : function (req) {
Rakka.hideWaitingMessage();
-
+
var $area = Rakka.switchScreen();
$area.text("Error: " + req.status + " " + req.statusText);
}
};
var submitRedirection = function (pageName, oldRevision, givenPageName, isLocked, destination) {
- var doc = document.implementation.createDocument(
- "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);
-
+ var NS = "http://cielonegro.org/schema/Rakka/Page/1.0";
+ var doc = document.implementation.createDocument(NS, "page", null);
var page = doc.documentElement;
if (oldRevision != null) {
// ページ書換時
- var updateInfo = doc.createElement("updateInfo");
+ var updateInfo = doc.createElementNS(NS, "updateInfo");
updateInfo.setAttribute("oldRevision", oldRevision);
if (pageName != givenPageName) {
- var move = doc.createElement("move");
+ var move = doc.createElementNS(NS, "move");
move.setAttribute("from", pageName);
updateInfo.appendChild(move);
}
},
error : function (req) {
Rakka.hideWaitingMessage();
-
+
var $area = Rakka.switchScreen();
$area.text("Error: " + req.status + " " + req.statusText);
}
},
error : function (req) {
Rakka.hideWaitingMessage();
-
+
var $area = Rakka.switchScreen();
$area.text("Error: " + req.status + " " + req.statusText);
}