X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=js%2FeditPage.js;h=c512fcc0d78c1556310b584fb7022933232c3d26;hb=fb86cb6941e466fd43ce45338024c79d0fdb33a2;hp=fb887352f85a5b80bac5092b146ea6ed68ad03bd;hpb=89c3c6ff37517012b5a799014c5a6d05d3e2e902;p=Rakka.git diff --git a/js/editPage.js b/js/editPage.js index fb88735..c512fcc 100644 --- a/js/editPage.js +++ b/js/editPage.js @@ -15,29 +15,36 @@ url : Rakka.baseURI + pageName + ".xml", success: function (pageXml) { Rakka.hideWaitingMessage(); - - 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" - ; - var source - = $page.attr("redirect") != null ? $page.attr("redirect") - : $page.find("textData").text() - ; - var summary = $page.find("summary").text(); + + if (pageXml.documentElement.tagName == "page") { + 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" + ; + var lang = $page.attr("lang"); + var isLocked = $page.attr("isLocked") == "yes"; + var source + = $page.attr("redirect") != null ? $page.attr("redirect") + : $page.find("textData").text() + ; + var summary = $page.find("summary").text(); - displayPageEditor(pageName, oldRevision, defaultType, source, summary); + displayPageEditor(pageName, oldRevision, defaultType, lang, isLocked, source, summary); + } + else { + displayPageEditor(pageName, null, "rakka", null, false, null, ""); + } }, error : function (req) { Rakka.hideWaitingMessage(); if (req.status == 404) { - displayPageEditor(pageName, null, "rakka", null, ""); + displayPageEditor(pageName, null, "rakka", null, false, null, ""); } else { $area.text("Error: " + req.status + " " + req.statusText); @@ -47,10 +54,10 @@ }; Rakka.newPage = function () { - displayPageEditor("", null, "rakka", null, ""); + displayPageEditor("", null, "rakka", null, false, null, ""); }; - var displayPageEditor = function (pageName, oldRevision, defaultType, source, summary) { + var displayPageEditor = function (pageName, oldRevision, defaultType, lang, isLocked, source, summary) { var $area = Rakka.switchScreen(); $previewHeader = $( $.H1({}, "Preview") ); @@ -72,6 +79,20 @@ $(fldPageName).change(makeDirty); + var chkIsLocked + = $.INPUT({type : "checkbox", + checked : (isLocked ? "checked" : "")}); + + $(chkIsLocked).change(makeDirty); + + var trIsLocked + = $.TR({}, + $.TH({}, "Page lock"), + $.TD({}, + $.LABEL({}, + chkIsLocked, + "Disallow anonymous users to edit or delete this page"))); + var btnTypeRakka = $.INPUT({type : "radio", name : "type", @@ -100,6 +121,34 @@ $(btnTypeRedirect).change(makeDirty); + var selPageLang + = $.SELECT({}, + $.OPTION({value: ""}, "(unspecified)"), + (function () { + var options = []; + + $.each(Rakka.getSystemConfig().languages, function (tag, name) { + options.push( + $.OPTION({value: tag}, name)); + }); + + return options; + })()); + + $(selPageLang).change(makeDirty); + + if (lang == null || lang == "") { + $(selPageLang).val($("html").attr("xml:lang")); + } + else { + $(selPageLang).val(lang); + } + + var trPageLang + = $.TR({}, + $.TH({}, "Page language"), + $.TD({}, selPageLang)); + var fldSummary = $.TEXTAREA({className: "summary"}, summary); @@ -161,7 +210,9 @@ pageName, oldRevision, fldPageName.value, + chkIsLocked.checked, "text/x-rakka", + $(selPageLang).val(), fldSummary.value, fldRakkaSource.value); } @@ -170,7 +221,9 @@ pageName, oldRevision, fldPageName.value, + chkIsLocked.checked, "text/css", + $(selPageLang).val(), fldSummary.value, fldCSSSource.value); } @@ -179,6 +232,8 @@ pageName, oldRevision, fldPageName.value, + chkIsLocked.checked, + $(selPageLang).val(), fldSummary.value, fldUploadFile.value); } @@ -187,6 +242,7 @@ pageName, oldRevision, fldPageName.value, + chkIsLocked.checked, fldRedirect.value); } }); @@ -216,24 +272,28 @@ var updateTRContent = function () { if (btnTypeRakka.checked) { + $(trPageLang).show(); $(trSummary).show(); $(trContent).find("th").text("Wiki source"); $(trContent).find("td").empty().append(fldRakkaSource); $(btnPreview).show(); } else if (btnTypeCSS.checked) { + $(trPageLang).show(); $(trSummary).show(); $(trContent).find("th").text("CSS source"); $(trContent).find("td").empty().append(fldCSSSource); $(btnPreview).hide(); } else if (btnTypeBinary.checked) { + $(trPageLang).show(); $(trSummary).show(); $(trContent).find("th").text("File"); $(trContent).find("td").empty().append(fldUploadFile); $(btnPreview).show(); } else if (btnTypeRedirect.checked) { + $(trPageLang).hide(); $(trSummary).hide(); $(trContent).find("th").text("Destination Page"); $(trContent).find("td").empty().append(fldRedirect); @@ -253,6 +313,7 @@ $.TH({}, "Page name"), $.TD({}, fldPageName) ), + trIsLocked, $.TR({}, $.TH({}, "Page type"), $.TD({}, @@ -284,6 +345,7 @@ ) ) ), + trPageLang, trSummary, trContent, $.TR({}, @@ -300,6 +362,10 @@ $area.append(pageEditor); + if (!Rakka.isLoggedIn() || Rakka.isGlobalLocked) { + $(trIsLocked).hide(); + } + isDirty = false; }; @@ -365,7 +431,7 @@ Rakka.scrollToTopLeft(); }; - var submitTextPage = function (pageName, oldRevision, givenPageName, mimeType, summary, text) { + var submitTextPage = function (pageName, oldRevision, givenPageName, isLocked, mimeType, lang, summary, text) { var doc = document.implementation.createDocument( "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null); @@ -385,9 +451,14 @@ page.appendChild(updateInfo); } + page.setAttribute("isLocked", isLocked ? "yes" : "no"); page.setAttribute("type", mimeType); - if (summary != null) { + if (lang != null && lang != "") { + page.setAttribute("lang", lang); + } + + if (summary != null && summary != "") { var s = doc.createElement("summary"); s.appendChild( doc.createTextNode(summary)); @@ -409,6 +480,9 @@ contentType: "text/xml", data : doc, processData: false, + beforeSend : function (req) { + Rakka.setAuthorization(req); + }, success : function () { window.location.replace(url); }, @@ -421,7 +495,7 @@ }); }; - var submitBinaryPage = function (pageName, oldRevision, givenPageName, summary, path) { + var submitBinaryPage = function (pageName, oldRevision, givenPageName, isLocked, lang, summary, path) { var doc = document.implementation.createDocument( "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null); @@ -441,8 +515,13 @@ page.appendChild(updateInfo); } + page.setAttribute("isLocked", isLocked ? "yes" : "no"); page.setAttribute("type", ""); + if (lang != null && lang != "") { + page.setAttribute("lang", lang); + } + if (summary != null) { var s = doc.createElement("summary"); s.appendChild( @@ -468,6 +547,9 @@ contentType: "text/xml", data : doc, processData: false, + beforeSend : function (req) { + Rakka.setAuthorization(req); + }, success : function () { window.location.replace(url); }, @@ -480,7 +562,7 @@ }); }; - var submitRedirection = function (pageName, oldRevision, givenPageName, destination) { + var submitRedirection = function (pageName, oldRevision, givenPageName, isLocked, destination) { var doc = document.implementation.createDocument( "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null); @@ -500,6 +582,7 @@ page.appendChild(updateInfo); } + page.setAttribute("isLocked", isLocked ? "yes" : "no"); page.setAttribute("redirect", destination); Rakka.displayWaitingMessage("Submitting... please wait."); @@ -511,6 +594,9 @@ contentType: "text/xml", data : doc, processData: false, + beforeSend : function (req) { + Rakka.setAuthorization(req); + }, success : function () { window.location.replace(url); }, @@ -528,6 +614,9 @@ $.ajax({ type : "DELETE", url : url, + beforeSend : function (req) { + Rakka.setAuthorization(req); + }, success : function () { window.location.replace(url); },