]> gitweb @ CieloNegro.org - Rakka.git/commitdiff
Global JavaScript
authorpho <pho@cielonegro.org>
Fri, 31 Oct 2008 04:44:11 +0000 (13:44 +0900)
committerpho <pho@cielonegro.org>
Fri, 31 Oct 2008 04:44:11 +0000 (13:44 +0900)
darcs-hash:20081031044411-62b54-a29a3105e5e8859766900cb019d3e5b4f40ce9f0.gz

Rakka/Resource/PageEntity.hs
js/editPage.js
js/systemConfig.js

index 670958e80c6d4b2ecf31c82f640e19f34eabc9ff..8fd0ed4d4024b39cc851a6ec88b4441225ef8c8b 100644 (file)
@@ -116,7 +116,8 @@ entityToXHTML env
           let cssHref   = [uriToString id (mkObjectURI baseURI styleSheet) ""]
               scriptSrc = [uriToString id (baseURI { uriPath = uriPath baseURI </> "js" }) ""]
 
-          feeds <- arrIO0 (findFeeds (envStorage env)) -< ()
+          feeds       <- arrIO0 (findFeeds (envStorage env)) -< ()
+          javaScripts <- arrIO0 (findJavaScripts (envStorage env)) -< ()
 
           pageTitle    <- listA (readSubPage env) -< (name, Just page, "PageTitle")
           leftSideBar  <- listA (readSubPage env) -< (name, Just page, "SideBar/Left")
@@ -164,6 +165,12 @@ entityToXHTML env
                            += txt ("Rakka.isLocked=" ++ trueOrFalse isLocked ++ ";")
                            += txt ("Rakka.isGlobalLocked=" ++ trueOrFalse isGLocked ++ ";")
                          )
+                      += ( constL javaScripts
+                           >>>
+                           eelem "script"
+                           += sattr "type" "text/javascript"
+                           += attr "src" (arr (mkObjectURIStr baseURI) >>> mkText)
+                         )
                     )
                  += ( eelem "body"
                       += ( eelem "div"
@@ -364,6 +371,9 @@ pageListingToXHTML env
           let cssHref   = [uriToString id (mkObjectURI baseURI styleSheet) ""]
               scriptSrc = [uriToString id (baseURI { uriPath = uriPath baseURI </> "js" }) ""]
 
+          feeds       <- arrIO0 (findFeeds (envStorage env)) -< ()
+          javaScripts <- arrIO0 (findJavaScripts (envStorage env)) -< ()
+
           pageTitle    <- listA (readSubPage env) -< (name, Nothing, "PageTitle")
           leftSideBar  <- listA (readSubPage env) -< (name, Nothing, "SideBar/Left")
           rightSideBar <- listA (readSubPage env) -< (name, Nothing, "SideBar/Right")
@@ -384,6 +394,14 @@ pageListingToXHTML env
                            += sattr "type" "text/css"
                            += attr "href" (arr id >>> mkText)
                          )
+                      += ( constL feeds
+                           >>>
+                           eelem "link"
+                           += sattr "rel"   "alternate"
+                           += sattr "type"  "application/rss+xml"
+                           += attr  "title" (txt siteName <+> txt " - " <+> mkText)
+                           += attr  "href"  (arr (mkFeedURIStr baseURI) >>> mkText)
+                         )
                       += ( constL scriptSrc
                            >>>
                            eelem "script"
@@ -395,6 +413,12 @@ pageListingToXHTML env
                            += txt ("Rakka.baseURI = \"" ++ uriToString id baseURI "" ++ "\";")
                            += txt ("Rakka.isGlobalLocked=" ++ trueOrFalse isGLocked ++ ";")
                          )
+                      += ( constL javaScripts
+                           >>>
+                           eelem "script"
+                           += sattr "type" "text/javascript"
+                           += attr "src" (arr (mkObjectURIStr baseURI) >>> mkText)
+                         )
                     )
                  += ( eelem "body"
                       += ( eelem "div"
@@ -476,6 +500,9 @@ notFoundToXHTML env
           let cssHref   = [uriToString id (mkObjectURI baseURI styleSheet) ""]
               scriptSrc = [uriToString id (baseURI { uriPath = uriPath baseURI </> "js" }) ""]
 
+          feeds       <- arrIO0 (findFeeds (envStorage env)) -< ()
+          javaScripts <- arrIO0 (findJavaScripts (envStorage env)) -< ()
+
           pageTitle    <- listA (readSubPage env) -< (name, Nothing, "PageTitle")
           leftSideBar  <- listA (readSubPage env) -< (name, Nothing, "SideBar/Left")
           rightSideBar <- listA (readSubPage env) -< (name, Nothing, "SideBar/Right")
@@ -496,6 +523,14 @@ notFoundToXHTML env
                            += sattr "type" "text/css"
                            += attr "href" (arr id >>> mkText)
                          )
+                      += ( constL feeds
+                           >>>
+                           eelem "link"
+                           += sattr "rel"   "alternate"
+                           += sattr "type"  "application/rss+xml"
+                           += attr  "title" (txt siteName <+> txt " - " <+> mkText)
+                           += attr  "href"  (arr (mkFeedURIStr baseURI) >>> mkText)
+                         )
                       += ( constL scriptSrc
                            >>>
                            eelem "script"
@@ -507,6 +542,12 @@ notFoundToXHTML env
                            += txt ("Rakka.baseURI = \"" ++ uriToString id baseURI "" ++ "\";")
                            += txt ("Rakka.isGlobalLocked=" ++ trueOrFalse isGLocked ++ ";")
                          )
+                      += ( constL javaScripts
+                           >>>
+                           eelem "script"
+                           += sattr "type" "text/javascript"
+                           += attr "src" (arr (mkObjectURIStr baseURI) >>> mkText)
+                         )
                     )
                  += ( eelem "body"
                       += ( eelem "div"
@@ -572,6 +613,22 @@ findFeeds sto
          return (map hpPageName $ srPages result)
 
 
+findJavaScripts :: Storage -> IO [PageName]
+findJavaScripts sto
+    = do cond <- newCondition
+         setPhrase   cond "[UVSET]"
+         addAttrCond cond "@title STRBW Global/"
+         addAttrCond cond "@type  STRBW text/javascript"
+         setOrder    cond "@uri STRA"
+         result <- searchPages sto cond
+         return (map hpPageName $ srPages result)
+
+
 mkFeedURIStr :: URI -> PageName -> String
 mkFeedURIStr baseURI name
     = uriToString id (mkFeedURI baseURI name) ""
+
+
+mkObjectURIStr :: URI -> PageName -> String
+mkObjectURIStr baseURI name
+    = uriToString id (mkObjectURI baseURI name) ""
index 406b7e3561603a5b083cf35e6870ad8f48b7bed2..a9813d2d3fa8bdc21bfaa6359b7a634ac93a0a49 100644 (file)
                     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"
+                        = $page.attr("isBinary") == "yes"             ? "binary"
+                        : $page.attr("type")     == "text/x-rakka"    ? "rakka"
+                        : $page.attr("type")     == "text/css"        ? "css"
+                        : $page.attr("type")     == "text/javascript" ? "js"
+                        : $page.attr("redirect") != null              ? "redirect"
+                        :                                               "unknown"
                         ;
                     var lang        = $page.attr("lang");
                     var isLocked    = $page.attr("isLocked") == "yes";
 
         $(btnTypeCSS).change(makeDirty);
 
+        var btnTypeJS
+            = $.INPUT({type   : "radio",
+                       name   : "type",
+                       checked: (defaultType == "js"       ? "checked" : "")});
+        $(btnTypeJS).change(makeDirty);
+
         var btnTypeBinary
             = $.INPUT({type   : "radio",
                        name   : "type",
 
         $(fldCSSSource).change(makeDirty);
 
+        var fldJSSource
+            = $.TEXTAREA({className: "source"},
+                         (defaultType == "js"    && source != null ? source : ""));
+
+        $(fldJSSource).change(makeDirty);
+
         var fldUploadFile
             = $.INPUT({type: "file"});
 
                     fldSummary.value,
                     fldCSSSource.value);
             }
+            else if (btnTypeJS.checked) {
+                submitTextPage(
+                    pageName,
+                    oldRevision,
+                    fldPageName.value,
+                    chkIsLocked.checked,
+                    "text/javascript",
+                    $(selPageLang).val(),
+                    otherLangs,
+                    fldSummary.value,
+                    fldJSSource.value);
+            }
             else if (btnTypeBinary.checked) {
                 if (fldUploadFile.value != "") {
                     submitBinaryPage(
                 $(trContent).find("td").empty().append(fldCSSSource);
                 $(btnPreview).hide();
             }
+            else if (btnTypeJS.checked) {
+                $(trPageLang).show();
+                $(trOtherLangs).show();
+                $(trSummary).show();
+                $(trContent).find("th").text("JavaScript source");
+                $(trContent).find("td").empty().append(fldJSSource);
+                $(btnPreview).hide();
+            }
             else if (btnTypeBinary.checked) {
                 $(trPageLang).show();
                 $(trOtherLangs).show();
         };
         $(btnTypeRakka   ).change(updateTRContent);
         $(btnTypeCSS     ).change(updateTRContent);
+        $(btnTypeJS      ).change(updateTRContent);
         $(btnTypeBinary  ).change(updateTRContent);
         $(btnTypeRedirect).change(updateTRContent);
         updateTRContent();
                                                           "Style sheet"
                                                          )
                                                  ),
+                                             $.LI({},
+                                                  $.LABEL({},
+                                                          btnTypeJS,
+                                                          "JavaScript"
+                                                         )
+                                                 ),
                                              $.LI({},
                                                   $.LABEL({},
                                                           btnTypeBinary,
         $(fldPageName)
             .add(btnTypeRakka)
             .add(btnTypeCSS)
+            .add(btnTypeJS)
             .add(btnTypeBinary)
             .add(btnTypeRedirect)
             .add($(trOtherLangs).find("input"))
index 7b8192a11ed1ce876793e7d9e44c0382f396adfd..fee6d367ed094f6f079dbbaf63d6c56441eef005 100644 (file)
 
                         var delUser = $.INPUT({type: "button", value: "Delete"});
 
+                 var validatePassword = function () {
+                     var isValid = (function () {
+                                        if (pass1.value == "") {
+                                            return false;
+                                        }
+
+                                        if (pass1.value != pass2.value) {
+                                            return false;
+                                        }
+
+                                        return true;
+                                    })();
+                     $(change).attr({disabled: (isValid ? "" : "disabled")});
+                 };
+                 validatePassword();
+                 $(pass1)
+                     .add(pass2)
+                     .change(validatePassword)
+                     .keyup(validatePassword);
+
                         $.each(users, function () {
                                 var id = users[i];
                                 var tr = $.TR({},