From: pho Date: Sat, 19 Jan 2008 05:54:36 +0000 (+0900) Subject: implemented global lock X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=354a3b69406608a2570060bdbdbc65e83260c8ff;p=Rakka.git implemented global lock darcs-hash:20080119055436-62b54-3dcb1eaf3522793e7209bc7ec527696a0f0d55e2.gz --- diff --git a/Rakka/Resource/PageEntity.hs b/Rakka/Resource/PageEntity.hs index 8f63bba..dbef4d5 100644 --- a/Rakka/Resource/PageEntity.hs +++ b/Rakka/Resource/PageEntity.hs @@ -18,6 +18,7 @@ import Rakka.Page import Rakka.Resource import Rakka.Storage import Rakka.SystemConfig +import Rakka.Utils import Rakka.Wiki.Engine import System.FilePath import Text.XML.HXT.Arrow.Namespace @@ -116,8 +117,10 @@ entityToXHTML env -> do SiteName siteName <- getSysConfA (envSysConf env) -< () BaseURI baseURI <- getSysConfA (envSysConf env) -< () StyleSheet styleSheet <- getSysConfA (envSysConf env) -< () + GlobalLock isGLocked <- getSysConfA (envSysConf env) -< () - name <- (getXPathTreesInDoc "/page/@name/text()" >>> getText) -< page + name <- (getXPathTreesInDoc "/page/@name/text()" >>> getText) -< page + isLocked <- (getXPathTreesInDoc "/page/@isLocked/text()" >>> getText >>> parseYesOrNo) -< page let cssHref = [uriToString id (mkObjectURI baseURI styleSheet) ""] scriptSrc = [uriToString id (baseURI { uriPath = uriPath baseURI "js" }) ""] @@ -156,7 +159,9 @@ entityToXHTML env ) += ( eelem "script" += sattr "type" "text/javascript" - += txt ("Rakka.baseURI = \"" ++ uriToString id baseURI "" ++ "\";") + += txt ("Rakka.baseURI=\"" ++ uriToString id baseURI "" ++ "\";") + += txt ("Rakka.isLocked=" ++ trueOrFalse isLocked ++ ";") + += txt ("Rakka.isGlobalLocked=" ++ trueOrFalse isGLocked ++ ";") ) ) += ( eelem "body" @@ -229,6 +234,7 @@ notFoundToXHTML env -> do SiteName siteName <- getSysConfA (envSysConf env) -< () BaseURI baseURI <- getSysConfA (envSysConf env) -< () StyleSheet styleSheet <- getSysConfA (envSysConf env) -< () + GlobalLock isGLocked <- getSysConfA (envSysConf env) -< () name <- (getXPathTreesInDoc "/pageNotFound/@name/text()" >>> getText) -< pageNotFound @@ -264,6 +270,7 @@ notFoundToXHTML env += ( eelem "script" += sattr "type" "text/javascript" += txt ("Rakka.baseURI = \"" ++ uriToString id baseURI "" ++ "\";") + += txt ("Rakka.isGlobalLocked=" ++ trueOrFalse isGLocked ++ ";") ) ) += ( eelem "body" diff --git a/Rakka/SystemConfig.hs b/Rakka/SystemConfig.hs index eb526fb..11fe124 100644 --- a/Rakka/SystemConfig.hs +++ b/Rakka/SystemConfig.hs @@ -12,6 +12,7 @@ module Rakka.SystemConfig , DefaultPage(..) , StyleSheet(..) , Languages(..) + , GlobalLock(..) , serializeStringPairs , deserializeStringPairs @@ -209,3 +210,15 @@ instance SysConfValue Languages where , ("pt", "Português") , ("sv", "Svenska" ) ] + + +newtype GlobalLock = GlobalLock Bool deriving (Show, Typeable) +instance SysConfValue GlobalLock where + confPath _ = "globalLock" + serialize (GlobalLock isLocked) + | isLocked = "*" + | otherwise = "" + deserialize "*" = Just (GlobalLock True) + deserialize "" = Just (GlobalLock False) + deserialize _ = Nothing + defaultValue _ = GlobalLock False diff --git a/Rakka/Utils.hs b/Rakka/Utils.hs index 0fddc6d..693fdf2 100644 --- a/Rakka/Utils.hs +++ b/Rakka/Utils.hs @@ -1,5 +1,6 @@ module Rakka.Utils ( yesOrNo + , trueOrFalse , parseYesOrNo , maybeA , deleteIfEmpty @@ -22,6 +23,11 @@ yesOrNo True = "yes" yesOrNo False = "no" +trueOrFalse :: Bool -> String +trueOrFalse True = "true" +trueOrFalse False = "false" + + parseYesOrNo :: ArrowChoice a => a String Bool parseYesOrNo = proc str -> do case str of diff --git a/defaultPages/StyleSheet/Default.xml b/defaultPages/StyleSheet/Default.xml index 87515bd..9f4b8e7 100644 --- a/defaultPages/StyleSheet/Default.xml +++ b/defaultPages/StyleSheet/Default.xml @@ -292,6 +292,13 @@ input[type="button"] { input[type="button"]:active { background-color: #999999; } +input[type="button"][disabled] { + border-color: #e5e5e5; + color: #b5b5b5; +} +input[type="button"][disabled]:active { + background-color: #f5f5f5; +} .header, .footer, .sideBar { background-color: #eeeeee; diff --git a/js/base.js b/js/base.js index 78c08cd..f2aa402 100644 --- a/js/base.js +++ b/js/base.js @@ -1,4 +1,6 @@ /* Namespace Rakka */ var Rakka = {}; -Rakka.baseURI = null; +Rakka.baseURI = null; +Rakka.isLocked = false; +Rakka.isGlobalLocked = false; diff --git a/js/editPage.js b/js/editPage.js index f0d3d50..4e5d255 100644 --- a/js/editPage.js +++ b/js/editPage.js @@ -74,8 +74,8 @@ $(fldPageName).change(makeDirty); var chkIsLocked - = $.INPUT({type : "checkbox", - checked: (isLocked ? "checked" : "")}); + = $.INPUT({type : "checkbox", + checked : (isLocked ? "checked" : "")}); $(chkIsLocked).change(makeDirty); @@ -320,6 +320,10 @@ $area.append(pageEditor); + if (!Rakka.isLoggedIn() || Rakka.isGlobalLocked) { + $(trIsLocked).hide(); + } + isDirty = false; }; diff --git a/js/login.js b/js/login.js index 174376b..48a19b6 100644 --- a/js/login.js +++ b/js/login.js @@ -77,6 +77,7 @@ var logout = function () { document.cookie = "rakkaLoginInfo=;max-age=0"; updateLoginState(); + Rakka.restoreScreen(); }; var currentUserID; @@ -111,6 +112,10 @@ .click(function () { logout(); }); + + $("input.newButton").attr({disabled: ""}); + + $("input.editButton").attr({disabled: ""}); } else { /* ログインしてゐない */ @@ -118,17 +123,29 @@ .val("Login") .unbind("click") .click(Rakka.showLoginPanel); + + $("input.newButton").attr({ + disabled: (Rakka.isGlobalLocked ? "disabled" : "") + }); + + $("input.editButton").attr({ + disabled: (Rakka.isLocked || Rakka.isGlobalLocked ? "disabled" : "") + }); } }; Rakka.setAuthorization = function (req) { - if (currentUserID != null) { + if (Rakka.isLoggedIn()) { req.setRequestHeader( "Authorization", "Basic " + Rakka.encodeBase64(currentUserID + ":" + currentPassword)); } }; + Rakka.isLoggedIn = function () { + return currentUserID != null; + }; + $(document).ready(function () { updateLoginState(); }); diff --git a/js/screen.js b/js/screen.js index 9fc50e7..95ee043 100644 --- a/js/screen.js +++ b/js/screen.js @@ -24,18 +24,16 @@ }; Rakka.restoreScreen = function () { - if (switchedArea == null) { - throw new Error("Rakka.restoreScreen(): not switched"); - } + if (switchedArea != null) { + $("div.sideBar div.outline").show(); - $("div.sideBar div.outline").show(); + $("p.redirection").show(); - $("p.redirection").show(); + $(switchedArea).remove(); + switchedArea = null; - $(switchedArea).remove(); - switchedArea = null; - - $("div.body").children().show(); + $("div.body").children().show(); + } return null; };