X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=js%2FeditPage.js;h=e390a1949ec67a7cf8c7e2b8f8b698887409f82e;hb=f1016753ef45a4c25745ccb6e81e5acbc085cc42;hp=c512fcc0d78c1556310b584fb7022933232c3d26;hpb=fb86cb6941e466fd43ce45338024c79d0fdb33a2;p=Rakka.git diff --git a/js/editPage.js b/js/editPage.js index c512fcc..e390a19 100644 --- a/js/editPage.js +++ b/js/editPage.js @@ -28,23 +28,30 @@ ; var lang = $page.attr("lang"); var isLocked = $page.attr("isLocked") == "yes"; + var otherLangs = (function () { + var obj = {}; + $page.find("otherLang > link").each(function () { + obj[this.getAttribute("lang")] = this.getAttribute("page"); + }); + return obj; + })(); var source = $page.attr("redirect") != null ? $page.attr("redirect") : $page.find("textData").text() ; var summary = $page.find("summary").text(); - displayPageEditor(pageName, oldRevision, defaultType, lang, isLocked, source, summary); + displayPageEditor(pageName, oldRevision, defaultType, lang, isLocked, otherLangs, source, summary); } else { - displayPageEditor(pageName, null, "rakka", null, false, null, ""); + displayPageEditor(pageName, null, "rakka", null, false, {}, null, ""); } }, error : function (req) { Rakka.hideWaitingMessage(); if (req.status == 404) { - displayPageEditor(pageName, null, "rakka", null, false, null, ""); + displayPageEditor(pageName, null, "rakka", null, false, {}, null, ""); } else { $area.text("Error: " + req.status + " " + req.statusText); @@ -54,10 +61,10 @@ }; Rakka.newPage = function () { - displayPageEditor("", null, "rakka", null, false, null, ""); + displayPageEditor("", null, "rakka", null, false, {}, null, ""); }; - var displayPageEditor = function (pageName, oldRevision, defaultType, lang, isLocked, source, summary) { + var displayPageEditor = function (pageName, oldRevision, defaultType, lang, isLocked, otherLangs, source, summary) { var $area = Rakka.switchScreen(); $previewHeader = $( $.H1({}, "Preview") ); @@ -149,6 +156,44 @@ $.TH({}, "Page language"), $.TD({}, selPageLang)); + var trOtherLangs = (function () { + var options = []; + + $.each(Rakka.getSystemConfig().languages, function (tag, name) { + options.push( + $.OPTION({value: tag}, name)); + }); + + var selLang = $.SELECT({}, options); + var fldLink = $.INPUT({type: "text", className: "smallField"}); + + $(selLang).change(function () { + var pageName = otherLangs[$(selLang).val()]; + $(fldLink).val( + pageName == null ? "" : pageName + ); + }).trigger("change"); + + var onLinkChanged = function () { + isDirty = true; + + var lang = $(selLang).val(); + var pageName = $(this).val(); + + if (pageName == "") { + delete otherLangs[lang]; + } + else { + otherLangs[lang] = pageName; + } + }; + $(fldLink).change(onLinkChanged).keyup(onLinkChanged); + + return $.TR({}, + $.TH({}, "Language links"), + $.TD({}, selLang, fldLink)); + })(); + var fldSummary = $.TEXTAREA({className: "summary"}, summary); @@ -213,6 +258,7 @@ chkIsLocked.checked, "text/x-rakka", $(selPageLang).val(), + otherLangs, fldSummary.value, fldRakkaSource.value); } @@ -224,6 +270,7 @@ chkIsLocked.checked, "text/css", $(selPageLang).val(), + otherLangs, fldSummary.value, fldCSSSource.value); } @@ -234,6 +281,7 @@ fldPageName.value, chkIsLocked.checked, $(selPageLang).val(), + otherLangs, fldSummary.value, fldUploadFile.value); } @@ -273,6 +321,7 @@ var updateTRContent = function () { if (btnTypeRakka.checked) { $(trPageLang).show(); + $(trOtherLangs).show(); $(trSummary).show(); $(trContent).find("th").text("Wiki source"); $(trContent).find("td").empty().append(fldRakkaSource); @@ -280,6 +329,7 @@ } else if (btnTypeCSS.checked) { $(trPageLang).show(); + $(trOtherLangs).show(); $(trSummary).show(); $(trContent).find("th").text("CSS source"); $(trContent).find("td").empty().append(fldCSSSource); @@ -287,6 +337,7 @@ } else if (btnTypeBinary.checked) { $(trPageLang).show(); + $(trOtherLangs).show(); $(trSummary).show(); $(trContent).find("th").text("File"); $(trContent).find("td").empty().append(fldUploadFile); @@ -294,6 +345,7 @@ } else if (btnTypeRedirect.checked) { $(trPageLang).hide(); + $(trOtherLangs).hide(); $(trSummary).hide(); $(trContent).find("th").text("Destination Page"); $(trContent).find("td").empty().append(fldRedirect); @@ -346,6 +398,7 @@ ) ), trPageLang, + trOtherLangs, trSummary, trContent, $.TR({}, @@ -431,7 +484,7 @@ Rakka.scrollToTopLeft(); }; - var submitTextPage = function (pageName, oldRevision, givenPageName, isLocked, mimeType, lang, summary, text) { + 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); @@ -465,6 +518,15 @@ page.appendChild(s); } + var oLang = doc.createElement("otherLang"); + for (var tag in otherLangs) { + var link = doc.createElement("link"); + link.setAttribute("lang", tag); + link.setAttribute("page", otherLangs[tag]); + oLang.appendChild(link); + } + page.appendChild(oLang); + var textData = doc.createElement("textData"); textData.appendChild( doc.createTextNode(text)); @@ -495,7 +557,7 @@ }); }; - var submitBinaryPage = function (pageName, oldRevision, givenPageName, isLocked, lang, summary, path) { + 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); @@ -529,6 +591,15 @@ page.appendChild(s); } + var oLang = doc.createElement("otherLang"); + for (var tag in otherLangs) { + var link = doc.createElement("link"); + link.setAttribute("lang", tag); + link.setAttribute("page", otherLangs[tag]); + oLang.appendChild(link); + } + page.appendChild(oLang); + var bin = Rakka.loadLocalBinaryFile(path); var b64 = Rakka.encodeBase64(bin);