From b51bb0c6d9385938eab21c70ed7ea631883260d0 Mon Sep 17 00:00:00 2001 From: pho Date: Fri, 11 Jan 2008 14:23:11 +0900 Subject: [PATCH] improved the page editor darcs-hash:20080111052311-62b54-597ae1a24d8782acd342bb720eb17907d96d0ef6.gz --- js/editPage.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- js/screen.js | 7 +++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/js/editPage.js b/js/editPage.js index 766d2e9..960ce4e 100644 --- a/js/editPage.js +++ b/js/editPage.js @@ -1,6 +1,8 @@ Rakka.$previewHeader = null; Rakka.$previewArea = null; +Rakka.isDirty = null; + Rakka.editPage = function (pageName) { var $area = Rakka.switchScreen(); @@ -59,33 +61,49 @@ Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source, Rakka.$previewArea.hide(); $area.append($.H1({}, pageName == "" ? "Create page" : "Edit page")); + + var makeDirty = function () { + Rakka.isDirty = true; + }; var fldPageName = $.INPUT({type : "text", value: pageName}); + $(fldPageName).change(makeDirty); + var btnTypeRakka = $.INPUT({type : "radio", name : "type", checked: (defaultType == "rakka" ? "checked" : "")}); + $(btnTypeRakka).change(makeDirty); + var btnTypeCSS = $.INPUT({type : "radio", name : "type", checked: (defaultType == "css" ? "checked" : "")}); + $(btnTypeCSS).change(makeDirty); + var btnTypeBinary = $.INPUT({type : "radio", name : "type", checked: (defaultType == "binary" ? "checked" : "")}); + $(btnTypeBinary).change(makeDirty); + var btnTypeRedirect = $.INPUT({type : "radio", name : "type", checked: (defaultType == "redirect" ? "checked" : "")}); + $(btnTypeRedirect).change(makeDirty); + var fldSummary = $.TEXTAREA({className: "summary"}, summary); + $(fldSummary).change(makeDirty); + var trSummary = $.TR({}, $.TH({}, "Summary"), @@ -95,16 +113,24 @@ Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source, = $.TEXTAREA({className: "source"}, (defaultType == "rakka" && source != null ? source : "")); + $(fldRakkaSource).change(makeDirty); + var fldCSSSource = $.TEXTAREA({className: "source"}, (defaultType == "css" && source != null ? source : "")); + $(fldCSSSource).change(makeDirty); + var fldUploadFile = $.INPUT({type: "file"}); + $(fldUploadFile).change(makeDirty); + var fldRedirect = $.INPUT({type: "text", value: (defaultType == "redirect" ? source : "")}); + $(fldRedirect).change(makeDirty); + var trContent = $.TR({}, $.TH({}), @@ -173,6 +199,20 @@ Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source, } }); + var btnCancel + = $.INPUT({type: "button", value: "Cancel editing"}); + + $(btnCancel).click(function () { + if (Rakka.isDirty) { + if (window.confirm("Do you really want to discard changes?")) { + Rakka.restoreScreen(); + } + } + else { + Rakka.restoreScreen(); + } + }); + var updateTRContent = function () { if (btnTypeRakka.checked) { $(trSummary).show(); @@ -247,7 +287,7 @@ Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source, trContent, $.TR({}, $.TH({}), - $.TD({}, btnPreview, btnSubmit, btnDelete) + $.TD({}, btnPreview, btnSubmit, btnDelete, btnCancel) ) ) ); @@ -258,6 +298,8 @@ Rakka.displayPageEditor = function (pageName, oldRevision, defaultType, source, } $area.append(pageEditor); + + Rakka.isDirty = false; }; Rakka.previewRakkaPage = function (pageName, source) { @@ -318,6 +360,8 @@ Rakka.showPreview = function (doc) { Rakka.$previewArea.append(child.cloneNode(true)); } } while (child = child.nextSibling); + + Rakka.scrollToTopLeft(); }; Rakka.submitTextPage = function (pageName, oldRevision, givenPageName, mimeType, summary, text) { diff --git a/js/screen.js b/js/screen.js index c30d0ab..9fc50e7 100644 --- a/js/screen.js +++ b/js/screen.js @@ -43,6 +43,13 @@ return switchedArea; }; + Rakka.scrollToTopLeft = function () { + $("div.center").each(function () { + this.scrollTop = 0; + this.scrollLeft = 0; + }); + }; + var waitingMessageBoard = null; Rakka.displayWaitingMessage = function (msg) { -- 2.40.0