]> gitweb @ CieloNegro.org - Rakka.git/commitdiff
implemented language link editor (partly)
authorpho <pho@cielonegro.org>
Sat, 16 Feb 2008 06:13:48 +0000 (15:13 +0900)
committerpho <pho@cielonegro.org>
Sat, 16 Feb 2008 06:13:48 +0000 (15:13 +0900)
darcs-hash:20080216061348-62b54-315575aae6948fbc80fea9079c16cb75eecbb17e.gz

Rakka/Resource.hs
Rakka/Storage/Repos.hs
Rakka/SystemConfig.hs
defaultPages/StyleSheet/Default.xml
js/editPage.js
schemas/rakka-page-1.0.rng

index d0d9c4866d06665732ab91344ed96dc87dc2ac2a..5cbf188e46c8a468b16b5bdbfcbd5f1722f8d7c6 100644 (file)
@@ -8,6 +8,7 @@ module Rakka.Resource
     )
     where
 
+import qualified Codec.Binary.UTF8.String as UTF8
 import           Control.Arrow
 import           Control.Arrow.ArrowList
 import           Control.Monad
@@ -113,7 +114,7 @@ getInputReader
                return $ readString [ (a_validate         , v_0)
                                    , (a_check_namespaces , v_1)
                                    , (a_remove_whitespace, v_0)
-                                   ] req
+                                   ] (UTF8.decodeString req)
       getFailingReader code headers msg
           = return $ proc _ -> abortA -< (code, (headers, msg))
 
index 76889d7e0ad5fac702041a17b4bb787fe8a491a5..b74f48cb36bb862c92399bb595fd38557996813b 100644 (file)
@@ -179,10 +179,10 @@ loadPageInRepository repos name rev
                                                      -> True
                           , entityRevision   = pageRev
                           , entityLastMod    = zonedTimeToUTC lastMod
-                          , entitySummary    = lookup "rakka:summary" props
+                          , entitySummary    = fmap decodeString (lookup "rakka:summary" props)
                           , entityOtherLang  = fromMaybe M.empty
                                              $ fmap
-                                                   (M.fromList . fromJust . deserializeStringPairs)
+                                                   (M.fromList . fromJust . deserializeStringPairs . decodeString)
                                                    (lookup "rakka:otherLang" props)
                           , entityContent    = content                                             
                           , entityUpdateInfo = undefined
@@ -315,13 +315,13 @@ putPageIntoRepository repos userID page
                setNodeProp path "rakka:isFeed"    (encodeFlag $ entityIsFeed page)
                setNodeProp path "rakka:isLocked"  (encodeFlag $ entityIsLocked page)
                setNodeProp path "rakka:isBinary"  (encodeFlag $ entityIsBinary page)
-               setNodeProp path "rakka:summary"   (entitySummary page)
+               setNodeProp path "rakka:summary"   (fmap encodeString $ entitySummary page)
                setNodeProp path "rakka:otherLang" (let otherLang = entityOtherLang page
                                                    in
                                                      if M.null otherLang then
                                                          Nothing
                                                      else
-                                                         Just (serializeStringPairs $ M.toList otherLang))
+                                                         Just (encodeString $ serializeStringPairs $ M.toList otherLang))
                applyTextLBS path Nothing (entityContent page)
 
       encodeFlag :: Bool -> Maybe String
@@ -409,7 +409,7 @@ loadAttachmentInRepository repos pName aName rev
       path = mkAttachmentPath pName aName
 
       loadAttachment' :: Rev a
-      loadAttachment' = getFileContents path >>= return . deserializeFromString
+      loadAttachment' = getFileContents path >>= return . deserializeFromString . decodeString
 
 
 putAttachmentIntoRepository :: Attachment a =>
index 11fe124a155a62c4bcb4f8b4b28601f3804aca59..ecf608df873232944880dbc0b518d6644cbebf46 100644 (file)
@@ -135,7 +135,7 @@ deserializeStringPairs :: String -> Maybe [(String, String)]
 deserializeStringPairs = sequence . map deserializePair' . lines
     where
       deserializePair' :: String -> Maybe (String, String)
-      deserializePair' s = case break (/= ' ') s of
+      deserializePair' s = case break (== ' ') s of
                              (a, ' ':b) -> Just (a, b)
                              _          -> Nothing
 
index 790b74ce88e4c28762cf5ffe1eb5ccd8df051c37..ef940d873269e476622a7b4cd0d440279b852394 100644 (file)
@@ -194,6 +194,10 @@ table.pageEditor {
     width: 97%;
     padding: 3px;
 }
+.pageEditor input.smallField {
+    width: 50%;
+    margin-left: 1em;
+}
 .pageEditor textarea.summary {
     height: 5em;
 }
index c512fcc0d78c1556310b584fb7022933232c3d26..e390a1949ec67a7cf8c7e2b8f8b698887409f82e 100644 (file)
                         ;
                     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);
     };
 
     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") );
                    $.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);
 
                     chkIsLocked.checked,
                     "text/x-rakka",
                     $(selPageLang).val(),
+                    otherLangs,
                     fldSummary.value,
                     fldRakkaSource.value);
             }
                     chkIsLocked.checked,
                     "text/css",
                     $(selPageLang).val(),
+                    otherLangs,
                     fldSummary.value,
                     fldCSSSource.value);
             }
                     fldPageName.value,
                     chkIsLocked.checked,
                     $(selPageLang).val(),
+                    otherLangs,
                     fldSummary.value,
                     fldUploadFile.value);
             }
         var updateTRContent = function () {
             if (btnTypeRakka.checked) {
                 $(trPageLang).show();
+                $(trOtherLangs).show();
                 $(trSummary).show();
                 $(trContent).find("th").text("Wiki source");
                 $(trContent).find("td").empty().append(fldRakkaSource);
             }
             else if (btnTypeCSS.checked) {
                 $(trPageLang).show();
+                $(trOtherLangs).show();
                 $(trSummary).show();
                 $(trContent).find("th").text("CSS source");
                 $(trContent).find("td").empty().append(fldCSSSource);
             }
             else if (btnTypeBinary.checked) {
                 $(trPageLang).show();
+                $(trOtherLangs).show();
                 $(trSummary).show();
                 $(trContent).find("th").text("File");
                 $(trContent).find("td").empty().append(fldUploadFile);
             }
             else if (btnTypeRedirect.checked) {
                 $(trPageLang).hide();
+                $(trOtherLangs).hide();
                 $(trSummary).hide();
                 $(trContent).find("th").text("Destination Page");
                 $(trContent).find("td").empty().append(fldRedirect);
                                        )
                                   ),
                               trPageLang,
+                              trOtherLangs,
                               trSummary,
                               trContent,
                               $.TR({},
         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);
 
             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));
         });
     };
 
-    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);
 
             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);
 
index c9dd03b280d18ed1f5ebb799e7ac46af39830d3b..15894bbe5afa5049044df6da163d50c73668dd93 100644 (file)
                 </attribute>
                 <attribute name="page">
                   <!-- ページ名 -->
-                  <data type="anyURI" />
+                  <text />
                 </attribute>
               </element>
             </zeroOrMore>