3 var $previewHeader = null;
4 var $previewArea = null;
8 var rePageName = /^[^ a-z.|#\[\]][^ .|#\[\]]*$/;
10 Rakka.editPage = function (pageName) {
11 var $area = Rakka.switchScreen();
13 Rakka.displayWaitingMessage("Loading... please wait.");
17 url : Rakka.baseURI + pageName + ".xml",
18 success: function (pageXml) {
19 Rakka.hideWaitingMessage();
21 if (pageXml.documentElement.tagName == "page") {
22 var $page = $(pageXml).find("page");
23 var oldRevision = $page.attr("revision");
25 = $page.attr("isBinary") == "yes" ? "binary"
26 : $page.attr("type") == "text/x-rakka" ? "rakka"
27 : $page.attr("type") == "text/css" ? "css"
28 : $page.attr("redirect") != null ? "redirect"
31 var lang = $page.attr("lang");
32 var isLocked = $page.attr("isLocked") == "yes";
33 var otherLangs = (function () {
35 $page.find("otherLang > link").each(function () {
36 obj[this.getAttribute("lang")] = this.getAttribute("page");
41 = $page.attr("redirect") != null ? $page.attr("redirect")
42 : $page.find("textData").text()
44 var summary = $page.find("summary").text();
46 displayPageEditor(pageName, oldRevision, defaultType, lang, isLocked, otherLangs, source, summary);
49 displayPageEditor(pageName, null, "rakka", null, false, {}, null, "");
52 error : function (req) {
53 Rakka.hideWaitingMessage();
55 if (req.status == 404) {
56 displayPageEditor(pageName, null, "rakka", null, false, {}, null, "");
59 $area.text("Error: " + req.status + " " + req.statusText);
65 Rakka.newPage = function () {
66 displayPageEditor("", null, "rakka", null, false, {}, null, "");
69 var displayPageEditor = function (pageName, oldRevision, defaultType, lang, isLocked, otherLangs, source, summary) {
70 var $area = Rakka.switchScreen();
72 $previewHeader = $( $.H1({}, "Preview") );
73 $area.append($previewHeader);
74 $previewHeader.hide();
76 $previewArea = $( $.DIV({className: "preview"}) );
77 $area.append($previewArea);
80 $area.append($.H1({}, pageName == "" ? "Create page" : "Edit page"));
82 var makeDirty = function () {
87 = $.INPUT({type : "text", value: pageName});
89 $(fldPageName).change(makeDirty);
92 = $.INPUT({type : "checkbox",
93 checked : (isLocked ? "checked" : "")});
95 $(chkIsLocked).change(makeDirty);
99 $.TH({}, "Page lock"),
103 "Disallow anonymous users to edit or delete this page")));
106 = $.INPUT({type : "radio",
108 checked: (defaultType == "rakka" ? "checked" : "")});
110 $(btnTypeRakka).change(makeDirty);
113 = $.INPUT({type : "radio",
115 checked: (defaultType == "css" ? "checked" : "")});
117 $(btnTypeCSS).change(makeDirty);
120 = $.INPUT({type : "radio",
122 checked: (defaultType == "binary" ? "checked" : "")});
124 $(btnTypeBinary).change(makeDirty);
127 = $.INPUT({type : "radio",
129 checked: (defaultType == "redirect" ? "checked" : "")});
131 $(btnTypeRedirect).change(makeDirty);
135 $.OPTION({value: ""}, "(unspecified)"),
139 $.each(Rakka.getSystemConfig().languages, function (tag, name) {
141 $.OPTION({value: tag}, name));
147 $(selPageLang).change(makeDirty);
149 if (lang == null || lang == "") {
150 $(selPageLang).val($("html").attr("xml:lang"));
153 $(selPageLang).val(lang);
158 $.TH({}, "Page language"),
159 $.TD({}, selPageLang));
161 var trOtherLangs = (function () {
164 $.each(Rakka.getSystemConfig().languages, function (tag, name) {
166 $.OPTION({value: tag}, name));
169 var selLang = $.SELECT({}, options);
170 var fldLink = $.INPUT({type: "text", className: "smallField"});
172 $(selLang).change(function () {
173 var pageName = otherLangs[$(selLang).val()];
175 pageName == null ? "" : pageName
177 }).trigger("change");
179 var onLinkChanged = function () {
182 var lang = $(selLang).val();
183 var pageName = $(this).val();
185 if (pageName == "") {
186 delete otherLangs[lang];
189 otherLangs[lang] = pageName;
192 $(fldLink).change(onLinkChanged).keyup(onLinkChanged);
195 $.TH({}, "Language links"),
196 $.TD({}, selLang, fldLink));
200 = $.TEXTAREA({className: "summary"}, summary);
202 $(fldSummary).change(makeDirty);
207 $.TD({}, fldSummary));
210 = $.TEXTAREA({className: "source"},
211 (defaultType == "rakka" && source != null ? source : ""));
213 $(fldRakkaSource).change(makeDirty);
216 = $.TEXTAREA({className: "source"},
217 (defaultType == "css" && source != null ? source : ""));
219 $(fldCSSSource).change(makeDirty);
222 = $.INPUT({type: "file"});
224 $(fldUploadFile).change(makeDirty);
227 = $.INPUT({type: "text", value: (defaultType == "redirect" ? source : "")});
229 $(fldRedirect).change(makeDirty);
238 = $.INPUT({type: "button", value: "Preview page"});
240 $(btnPreview).click(function () {
241 if (btnTypeRakka.checked) {
243 fldPageName.value, fldRakkaSource.value);
245 else if (btnTypeBinary.checked) {
246 if (fldUploadFile.value != "") {
248 fldPageName.value, fldUploadFile.value);
254 = $.INPUT({type: "button", value: "Submit page"});
256 $(btnSubmit).click(function () {
257 if (btnTypeRakka.checked) {
264 $(selPageLang).val(),
267 fldRakkaSource.value);
269 else if (btnTypeCSS.checked) {
276 $(selPageLang).val(),
281 else if (btnTypeBinary.checked) {
282 if (fldUploadFile.value != "") {
288 $(selPageLang).val(),
291 fldUploadFile.value);
294 else if (btnTypeRedirect.checked) {
305 = $.INPUT({type: "button", value: "Delete this page"});
307 $(btnDelete).click(function () {
308 if (window.confirm("Do you really want to delete this page?")) {
309 deletePage(pageName);
314 = $.INPUT({type: "button", value: "Cancel editing"});
316 $(btnCancel).click(function () {
318 if (window.confirm("Do you really want to discard changes?")) {
319 Rakka.restoreScreen();
323 Rakka.restoreScreen();
327 var updateTRContent = function () {
328 if (btnTypeRakka.checked) {
329 $(trPageLang).show();
330 $(trOtherLangs).show();
332 $(trContent).find("th").text("Wiki source");
333 $(trContent).find("td").empty().append(fldRakkaSource);
334 $(btnPreview).show();
336 else if (btnTypeCSS.checked) {
337 $(trPageLang).show();
338 $(trOtherLangs).show();
340 $(trContent).find("th").text("CSS source");
341 $(trContent).find("td").empty().append(fldCSSSource);
342 $(btnPreview).hide();
344 else if (btnTypeBinary.checked) {
345 $(trPageLang).show();
346 $(trOtherLangs).show();
348 $(trContent).find("th").text("File");
349 $(trContent).find("td").empty().append(fldUploadFile);
350 $(btnPreview).show();
352 else if (btnTypeRedirect.checked) {
353 $(trPageLang).hide();
354 $(trOtherLangs).hide();
356 $(trContent).find("th").text("Destination Page");
357 $(trContent).find("td").empty().append(fldRedirect);
358 $(btnPreview).hide();
361 $(btnTypeRakka ).change(updateTRContent);
362 $(btnTypeCSS ).change(updateTRContent);
363 $(btnTypeBinary ).change(updateTRContent);
364 $(btnTypeRedirect).change(updateTRContent);
368 = $.TABLE({className: "pageEditor"},
371 $.TH({}, "Page name"),
372 $.TD({}, fldPageName)
376 $.TH({}, "Page type"),
412 $.TD({}, btnPreview, btnSubmit, btnDelete, btnCancel)
417 var validate = function () {
418 var isValid = (function () {
419 if (fldPageName.value.match(rePageName) == null) {
423 if (btnTypeRedirect.checked) {
424 if (fldRedirect.value.match(rePageName) == null) {
429 for (var tag in otherLangs) {
430 if (otherLangs[tag].match(rePageName) == null) {
435 if (btnTypeBinary.checked) {
436 if (fldUploadFile.value == "") {
445 $(btnSubmit).attr({disabled: (isValid ? "" : "disabled")});
451 .add(btnTypeRedirect)
452 .add($(trOtherLangs).find("input"))
459 if (oldRevision == null || oldRevision == 0) {
464 $area.append(pageEditor);
466 if (!Rakka.isLoggedIn() || Rakka.isGlobalLocked) {
467 $(trIsLocked).hide();
473 var previewRakkaPage = function (pageName, source) {
474 Rakka.displayWaitingMessage("Loading... please wait.");
476 var url = Rakka.baseURI + "render/" + encodeURI(pageName);
480 contentType: "text/x-rakka",
483 success : function (resultDoc) {
484 Rakka.hideWaitingMessage();
485 showPreview(resultDoc);
487 error : function (req) {
488 Rakka.hideWaitingMessage();
489 alert("Error: " + req.status + " " + req.statusText);
494 var previewBinaryPage = function (pageName, path) {
495 Rakka.displayWaitingMessage("Loading... please wait.");
497 /* Firefox でバイナリを送らうとすると 0x00 の位置で切れてしまふ。*/
498 var bin = Rakka.loadLocalBinaryFile(path);
499 var url = Rakka.baseURI + "render/" + encodeURI(pageName);
503 contentType: "application/x-rakka-base64-stream",
504 data : Rakka.encodeBase64(bin),
506 success : function (resultDoc) {
507 Rakka.hideWaitingMessage();
508 showPreview(resultDoc);
510 error : function (req) {
511 Rakka.hideWaitingMessage();
512 alert("Error: " + req.status + " " + req.statusText);
517 var showPreview = function (doc) {
518 $previewArea.empty();
520 $previewHeader.show();
523 var root = doc.documentElement;
524 var child = root.firstChild;
526 if (child.nodeType == 1) {
528 $previewArea.append(child.cloneNode(true));
530 } while (child = child.nextSibling);
532 Rakka.scrollToTopLeft();
535 var submitTextPage = function (pageName, oldRevision, givenPageName, isLocked, mimeType, lang, otherLangs, summary, text) {
536 var doc = document.implementation.createDocument(
537 "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);
539 var page = doc.documentElement;
541 if (oldRevision != null) {
543 var updateInfo = doc.createElement("updateInfo");
544 updateInfo.setAttribute("oldRevision", oldRevision);
546 if (pageName != givenPageName) {
547 var move = doc.createElement("move");
548 move.setAttribute("from", pageName);
549 updateInfo.appendChild(move);
552 page.appendChild(updateInfo);
555 page.setAttribute("isLocked", isLocked ? "yes" : "no");
556 page.setAttribute("type", mimeType);
558 if (lang != null && lang != "") {
559 page.setAttribute("lang", lang);
562 if (summary != null && summary != "") {
563 var s = doc.createElement("summary");
565 doc.createTextNode(summary));
569 var oLang = doc.createElement("otherLang");
570 for (var tag in otherLangs) {
571 var link = doc.createElement("link");
572 link.setAttribute("lang", tag);
573 link.setAttribute("page", otherLangs[tag]);
574 oLang.appendChild(link);
576 page.appendChild(oLang);
578 var textData = doc.createElement("textData");
579 textData.appendChild(
580 doc.createTextNode(text));
582 page.appendChild(textData);
584 Rakka.displayWaitingMessage("Submitting... please wait.");
586 var url = Rakka.baseURI + encodeURI(givenPageName);
590 contentType: "text/xml",
593 beforeSend : function (req) {
594 Rakka.setAuthorization(req);
596 success : function () {
597 window.location.replace(url);
599 error : function (req) {
600 Rakka.hideWaitingMessage();
602 var $area = Rakka.switchScreen();
603 $area.text("Error: " + req.status + " " + req.statusText);
608 var submitBinaryPage = function (pageName, oldRevision, givenPageName, isLocked, lang, otherLangs, summary, path) {
609 var doc = document.implementation.createDocument(
610 "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);
612 var page = doc.documentElement;
614 if (oldRevision != null) {
616 var updateInfo = doc.createElement("updateInfo");
617 updateInfo.setAttribute("oldRevision", oldRevision);
619 if (pageName != givenPageName) {
620 var move = doc.createElement("move");
621 move.setAttribute("from", pageName);
622 updateInfo.appendChild(move);
625 page.appendChild(updateInfo);
628 page.setAttribute("isLocked", isLocked ? "yes" : "no");
629 page.setAttribute("type", "");
631 if (lang != null && lang != "") {
632 page.setAttribute("lang", lang);
635 if (summary != null) {
636 var s = doc.createElement("summary");
638 doc.createTextNode(summary));
642 var oLang = doc.createElement("otherLang");
643 for (var tag in otherLangs) {
644 var link = doc.createElement("link");
645 link.setAttribute("lang", tag);
646 link.setAttribute("page", otherLangs[tag]);
647 oLang.appendChild(link);
649 page.appendChild(oLang);
651 var bin = Rakka.loadLocalBinaryFile(path);
652 var b64 = Rakka.encodeBase64(bin);
654 var binaryData = doc.createElement("binaryData");
655 binaryData.appendChild(
656 doc.createTextNode(b64));
658 page.appendChild(binaryData);
660 Rakka.displayWaitingMessage("Submitting... please wait.");
662 var url = Rakka.baseURI + encodeURI(givenPageName);
666 contentType: "text/xml",
669 beforeSend : function (req) {
670 Rakka.setAuthorization(req);
672 success : function () {
673 window.location.replace(url);
675 error : function (req) {
676 Rakka.hideWaitingMessage();
678 var $area = Rakka.switchScreen();
679 $area.text("Error: " + req.status + " " + req.statusText);
684 var submitRedirection = function (pageName, oldRevision, givenPageName, isLocked, destination) {
685 var doc = document.implementation.createDocument(
686 "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);
688 var page = doc.documentElement;
690 if (oldRevision != null) {
692 var updateInfo = doc.createElement("updateInfo");
693 updateInfo.setAttribute("oldRevision", oldRevision);
695 if (pageName != givenPageName) {
696 var move = doc.createElement("move");
697 move.setAttribute("from", pageName);
698 updateInfo.appendChild(move);
701 page.appendChild(updateInfo);
704 page.setAttribute("isLocked", isLocked ? "yes" : "no");
705 page.setAttribute("redirect", destination);
707 Rakka.displayWaitingMessage("Submitting... please wait.");
709 var url = Rakka.baseURI + encodeURI(givenPageName);
713 contentType: "text/xml",
716 beforeSend : function (req) {
717 Rakka.setAuthorization(req);
719 success : function () {
720 window.location.replace(url);
722 error : function (req) {
723 Rakka.hideWaitingMessage();
725 var $area = Rakka.switchScreen();
726 $area.text("Error: " + req.status + " " + req.statusText);
731 var deletePage = function (pageName) {
732 var url = Rakka.baseURI + encodeURI(pageName);
736 beforeSend : function (req) {
737 Rakka.setAuthorization(req);
739 success : function () {
740 window.location.replace(url);
742 error : function (req) {
743 Rakka.hideWaitingMessage();
745 var $area = Rakka.switchScreen();
746 $area.text("Error: " + req.status + " " + req.statusText);