3 var $previewHeader = null;
4 var $previewArea = null;
8 Rakka.editPage = function (pageName) {
9 var $area = Rakka.switchScreen();
11 Rakka.displayWaitingMessage("Loading... please wait.");
15 url : Rakka.baseURI + pageName + ".xml",
16 success: function (pageXml) {
17 Rakka.hideWaitingMessage();
19 if (pageXml.documentElement.tagName == "page") {
20 var $page = $(pageXml).find("page");
21 var oldRevision = $page.attr("revision");
23 = $page.attr("isBinary") == "yes" ? "binary"
24 : $page.attr("type") == "text/x-rakka" ? "rakka"
25 : $page.attr("type") == "text/css" ? "css"
26 : $page.attr("redirect") != null ? "redirect"
29 var lang = $page.attr("lang");
30 var isLocked = $page.attr("isLocked") == "yes";
31 var otherLangs = (function () {
33 $page.find("otherLang > link").each(function () {
34 obj[this.getAttribute("lang")] = this.getAttribute("page");
39 = $page.attr("redirect") != null ? $page.attr("redirect")
40 : $page.find("textData").text()
42 var summary = $page.find("summary").text();
44 displayPageEditor(pageName, oldRevision, defaultType, lang, isLocked, otherLangs, source, summary);
47 displayPageEditor(pageName, null, "rakka", null, false, {}, null, "");
50 error : function (req) {
51 Rakka.hideWaitingMessage();
53 if (req.status == 404) {
54 displayPageEditor(pageName, null, "rakka", null, false, {}, null, "");
57 $area.text("Error: " + req.status + " " + req.statusText);
63 Rakka.newPage = function () {
64 displayPageEditor("", null, "rakka", null, false, {}, null, "");
67 var displayPageEditor = function (pageName, oldRevision, defaultType, lang, isLocked, otherLangs, source, summary) {
68 var $area = Rakka.switchScreen();
70 $previewHeader = $( $.H1({}, "Preview") );
71 $area.append($previewHeader);
72 $previewHeader.hide();
74 $previewArea = $( $.DIV({className: "preview"}) );
75 $area.append($previewArea);
78 $area.append($.H1({}, pageName == "" ? "Create page" : "Edit page"));
80 var makeDirty = function () {
85 = $.INPUT({type : "text", value: pageName});
87 $(fldPageName).change(makeDirty);
90 = $.INPUT({type : "checkbox",
91 checked : (isLocked ? "checked" : "")});
93 $(chkIsLocked).change(makeDirty);
97 $.TH({}, "Page lock"),
101 "Disallow anonymous users to edit or delete this page")));
104 = $.INPUT({type : "radio",
106 checked: (defaultType == "rakka" ? "checked" : "")});
108 $(btnTypeRakka).change(makeDirty);
111 = $.INPUT({type : "radio",
113 checked: (defaultType == "css" ? "checked" : "")});
115 $(btnTypeCSS).change(makeDirty);
118 = $.INPUT({type : "radio",
120 checked: (defaultType == "binary" ? "checked" : "")});
122 $(btnTypeBinary).change(makeDirty);
125 = $.INPUT({type : "radio",
127 checked: (defaultType == "redirect" ? "checked" : "")});
129 $(btnTypeRedirect).change(makeDirty);
133 $.OPTION({value: ""}, "(unspecified)"),
137 $.each(Rakka.getSystemConfig().languages, function (tag, name) {
139 $.OPTION({value: tag}, name));
145 $(selPageLang).change(makeDirty);
147 if (lang == null || lang == "") {
148 $(selPageLang).val($("html").attr("xml:lang"));
151 $(selPageLang).val(lang);
156 $.TH({}, "Page language"),
157 $.TD({}, selPageLang));
159 var trOtherLangs = (function () {
162 $.each(Rakka.getSystemConfig().languages, function (tag, name) {
164 $.OPTION({value: tag}, name));
167 var selLang = $.SELECT({}, options);
168 var fldLink = $.INPUT({type: "text", className: "smallField"});
170 $(selLang).change(function () {
171 var pageName = otherLangs[$(selLang).val()];
173 pageName == null ? "" : pageName
175 }).trigger("change");
177 var onLinkChanged = function () {
180 var lang = $(selLang).val();
181 var pageName = $(this).val();
183 if (pageName == "") {
184 delete otherLangs[lang];
187 otherLangs[lang] = pageName;
190 $(fldLink).change(onLinkChanged).keyup(onLinkChanged);
193 $.TH({}, "Language links"),
194 $.TD({}, selLang, fldLink));
198 = $.TEXTAREA({className: "summary"}, summary);
200 $(fldSummary).change(makeDirty);
205 $.TD({}, fldSummary));
208 = $.TEXTAREA({className: "source"},
209 (defaultType == "rakka" && source != null ? source : ""));
211 $(fldRakkaSource).change(makeDirty);
214 = $.TEXTAREA({className: "source"},
215 (defaultType == "css" && source != null ? source : ""));
217 $(fldCSSSource).change(makeDirty);
220 = $.INPUT({type: "file"});
222 $(fldUploadFile).change(makeDirty);
225 = $.INPUT({type: "text", value: (defaultType == "redirect" ? source : "")});
227 $(fldRedirect).change(makeDirty);
236 = $.INPUT({type: "button", value: "Preview page"});
238 $(btnPreview).click(function () {
239 if (btnTypeRakka.checked) {
241 fldPageName.value, fldRakkaSource.value);
243 else if (btnTypeBinary.checked) {
245 fldPageName.value, fldUploadFile.value);
250 = $.INPUT({type: "button", value: "Submit page"});
252 $(btnSubmit).click(function () {
253 if (btnTypeRakka.checked) {
260 $(selPageLang).val(),
263 fldRakkaSource.value);
265 else if (btnTypeCSS.checked) {
272 $(selPageLang).val(),
277 else if (btnTypeBinary.checked) {
283 $(selPageLang).val(),
286 fldUploadFile.value);
288 else if (btnTypeRedirect.checked) {
299 = $.INPUT({type: "button", value: "Delete this page"});
301 $(btnDelete).click(function () {
302 if (window.confirm("Do you really want to delete this page?")) {
303 deletePage(pageName);
308 = $.INPUT({type: "button", value: "Cancel editing"});
310 $(btnCancel).click(function () {
312 if (window.confirm("Do you really want to discard changes?")) {
313 Rakka.restoreScreen();
317 Rakka.restoreScreen();
321 var updateTRContent = function () {
322 if (btnTypeRakka.checked) {
323 $(trPageLang).show();
324 $(trOtherLangs).show();
326 $(trContent).find("th").text("Wiki source");
327 $(trContent).find("td").empty().append(fldRakkaSource);
328 $(btnPreview).show();
330 else if (btnTypeCSS.checked) {
331 $(trPageLang).show();
332 $(trOtherLangs).show();
334 $(trContent).find("th").text("CSS source");
335 $(trContent).find("td").empty().append(fldCSSSource);
336 $(btnPreview).hide();
338 else if (btnTypeBinary.checked) {
339 $(trPageLang).show();
340 $(trOtherLangs).show();
342 $(trContent).find("th").text("File");
343 $(trContent).find("td").empty().append(fldUploadFile);
344 $(btnPreview).show();
346 else if (btnTypeRedirect.checked) {
347 $(trPageLang).hide();
348 $(trOtherLangs).hide();
350 $(trContent).find("th").text("Destination Page");
351 $(trContent).find("td").empty().append(fldRedirect);
352 $(btnPreview).hide();
355 $(btnTypeRakka ).change(updateTRContent);
356 $(btnTypeCSS ).change(updateTRContent);
357 $(btnTypeBinary ).change(updateTRContent);
358 $(btnTypeRedirect).change(updateTRContent);
362 = $.TABLE({className: "pageEditor"},
365 $.TH({}, "Page name"),
366 $.TD({}, fldPageName)
370 $.TH({}, "Page type"),
406 $.TD({}, btnPreview, btnSubmit, btnDelete, btnCancel)
411 if (oldRevision == null || oldRevision == 0) {
416 $area.append(pageEditor);
418 if (!Rakka.isLoggedIn() || Rakka.isGlobalLocked) {
419 $(trIsLocked).hide();
425 var previewRakkaPage = function (pageName, source) {
426 Rakka.displayWaitingMessage("Loading... please wait.");
428 var url = Rakka.baseURI + "render/" + encodeURI(pageName);
432 contentType: "text/x-rakka",
435 success : function (resultDoc) {
436 Rakka.hideWaitingMessage();
437 showPreview(resultDoc);
439 error : function (req) {
440 Rakka.hideWaitingMessage();
441 alert("Error: " + req.status + " " + req.statusText);
446 var previewBinaryPage = function (pageName, path) {
447 Rakka.displayWaitingMessage("Loading... please wait.");
449 /* Firefox でバイナリを送らうとすると 0x00 の位置で切れてしまふ。*/
450 var bin = Rakka.loadLocalBinaryFile(path);
451 var url = Rakka.baseURI + "render/" + encodeURI(pageName);
455 contentType: "application/x-rakka-base64-stream",
456 data : Rakka.encodeBase64(bin),
458 success : function (resultDoc) {
459 Rakka.hideWaitingMessage();
460 showPreview(resultDoc);
462 error : function (req) {
463 Rakka.hideWaitingMessage();
464 alert("Error: " + req.status + " " + req.statusText);
469 var showPreview = function (doc) {
470 $previewArea.empty();
472 $previewHeader.show();
475 var root = doc.documentElement;
476 var child = root.firstChild;
478 if (child.nodeType == 1) {
480 $previewArea.append(child.cloneNode(true));
482 } while (child = child.nextSibling);
484 Rakka.scrollToTopLeft();
487 var submitTextPage = function (pageName, oldRevision, givenPageName, isLocked, mimeType, lang, otherLangs, summary, text) {
488 var doc = document.implementation.createDocument(
489 "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);
491 var page = doc.documentElement;
493 if (oldRevision != null) {
495 var updateInfo = doc.createElement("updateInfo");
496 updateInfo.setAttribute("oldRevision", oldRevision);
498 if (pageName != givenPageName) {
499 var move = doc.createElement("move");
500 move.setAttribute("from", pageName);
501 updateInfo.appendChild(move);
504 page.appendChild(updateInfo);
507 page.setAttribute("isLocked", isLocked ? "yes" : "no");
508 page.setAttribute("type", mimeType);
510 if (lang != null && lang != "") {
511 page.setAttribute("lang", lang);
514 if (summary != null && summary != "") {
515 var s = doc.createElement("summary");
517 doc.createTextNode(summary));
521 var oLang = doc.createElement("otherLang");
522 for (var tag in otherLangs) {
523 var link = doc.createElement("link");
524 link.setAttribute("lang", tag);
525 link.setAttribute("page", otherLangs[tag]);
526 oLang.appendChild(link);
528 page.appendChild(oLang);
530 var textData = doc.createElement("textData");
531 textData.appendChild(
532 doc.createTextNode(text));
534 page.appendChild(textData);
536 Rakka.displayWaitingMessage("Submitting... please wait.");
538 var url = Rakka.baseURI + encodeURI(givenPageName);
542 contentType: "text/xml",
545 beforeSend : function (req) {
546 Rakka.setAuthorization(req);
548 success : function () {
549 window.location.replace(url);
551 error : function (req) {
552 Rakka.hideWaitingMessage();
554 var $area = Rakka.switchScreen();
555 $area.text("Error: " + req.status + " " + req.statusText);
560 var submitBinaryPage = function (pageName, oldRevision, givenPageName, isLocked, lang, otherLangs, summary, path) {
561 var doc = document.implementation.createDocument(
562 "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);
564 var page = doc.documentElement;
566 if (oldRevision != null) {
568 var updateInfo = doc.createElement("updateInfo");
569 updateInfo.setAttribute("oldRevision", oldRevision);
571 if (pageName != givenPageName) {
572 var move = doc.createElement("move");
573 move.setAttribute("from", pageName);
574 updateInfo.appendChild(move);
577 page.appendChild(updateInfo);
580 page.setAttribute("isLocked", isLocked ? "yes" : "no");
581 page.setAttribute("type", "");
583 if (lang != null && lang != "") {
584 page.setAttribute("lang", lang);
587 if (summary != null) {
588 var s = doc.createElement("summary");
590 doc.createTextNode(summary));
594 var oLang = doc.createElement("otherLang");
595 for (var tag in otherLangs) {
596 var link = doc.createElement("link");
597 link.setAttribute("lang", tag);
598 link.setAttribute("page", otherLangs[tag]);
599 oLang.appendChild(link);
601 page.appendChild(oLang);
603 var bin = Rakka.loadLocalBinaryFile(path);
604 var b64 = Rakka.encodeBase64(bin);
606 var binaryData = doc.createElement("binaryData");
607 binaryData.appendChild(
608 doc.createTextNode(b64));
610 page.appendChild(binaryData);
612 Rakka.displayWaitingMessage("Submitting... please wait.");
614 var url = Rakka.baseURI + encodeURI(givenPageName);
618 contentType: "text/xml",
621 beforeSend : function (req) {
622 Rakka.setAuthorization(req);
624 success : function () {
625 window.location.replace(url);
627 error : function (req) {
628 Rakka.hideWaitingMessage();
630 var $area = Rakka.switchScreen();
631 $area.text("Error: " + req.status + " " + req.statusText);
636 var submitRedirection = function (pageName, oldRevision, givenPageName, isLocked, destination) {
637 var doc = document.implementation.createDocument(
638 "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);
640 var page = doc.documentElement;
642 if (oldRevision != null) {
644 var updateInfo = doc.createElement("updateInfo");
645 updateInfo.setAttribute("oldRevision", oldRevision);
647 if (pageName != givenPageName) {
648 var move = doc.createElement("move");
649 move.setAttribute("from", pageName);
650 updateInfo.appendChild(move);
653 page.appendChild(updateInfo);
656 page.setAttribute("isLocked", isLocked ? "yes" : "no");
657 page.setAttribute("redirect", destination);
659 Rakka.displayWaitingMessage("Submitting... please wait.");
661 var url = Rakka.baseURI + encodeURI(givenPageName);
665 contentType: "text/xml",
668 beforeSend : function (req) {
669 Rakka.setAuthorization(req);
671 success : function () {
672 window.location.replace(url);
674 error : function (req) {
675 Rakka.hideWaitingMessage();
677 var $area = Rakka.switchScreen();
678 $area.text("Error: " + req.status + " " + req.statusText);
683 var deletePage = function (pageName) {
684 var url = Rakka.baseURI + encodeURI(pageName);
688 beforeSend : function (req) {
689 Rakka.setAuthorization(req);
691 success : function () {
692 window.location.replace(url);
694 error : function (req) {
695 Rakka.hideWaitingMessage();
697 var $area = Rakka.switchScreen();
698 $area.text("Error: " + req.status + " " + req.statusText);