]> gitweb @ CieloNegro.org - Rakka.git/commitdiff
Rakka.getSystemConfig()
authorpho <pho@cielonegro.org>
Mon, 11 Feb 2008 05:37:52 +0000 (14:37 +0900)
committerpho <pho@cielonegro.org>
Mon, 11 Feb 2008 05:37:52 +0000 (14:37 +0900)
darcs-hash:20080211053752-62b54-821f26c4b38fcb26572fc9a7a1fb96530281fd7f.gz

js/Makefile
js/systemConfig.js [new file with mode: 0644]

index 637f7d1c72ea45959237bbafc3d9518cd1f582ae..00a7704557b5b95fde6a66084c7e4a46f82b3306 100644 (file)
@@ -12,6 +12,7 @@ SOURCES = \
        redirection.js \
        screen.js \
        search.js \
+       systemConfig.js \
        uri.js \
        $(NULL)
 
diff --git a/js/systemConfig.js b/js/systemConfig.js
new file mode 100644 (file)
index 0000000..cb46670
--- /dev/null
@@ -0,0 +1,61 @@
+(function () {
+
+    var identityDecoder = function (src) {
+        return src;
+    };
+
+    var mapDecoder = function (src) {
+        var map   = {};
+        var lines = src.split(/\n/);
+        
+        $.each(lines, function () {
+            var m = this.match(/^(\S+)\s+(\S+)$/);
+
+            map[ m[1] ] = m[2];
+        });
+
+        return map;
+    };
+
+    var boolDecoder = function (src) {
+        return src == "*";
+    };
+
+    var decoder_of = {
+        siteName   : identityDecoder,
+        baseURI    : identityDecoder,
+        defaultPage: identityDecoder,
+        styleSheet : identityDecoder,
+        languages  : mapDecoder,
+        globalLock : boolDecoder
+    };
+
+    Rakka.getSystemConfig = function () {
+        var conf = {};
+        
+        $.ajax({
+            type   : "GET",
+            url    : Rakka.baseURI + "systemConfig",
+            async  : false,
+            success: function (xml) {
+                $(xml).find("value").each(function () {
+                    var path    = this.getAttribute("path");
+                    var decoder = decoder_of[path];
+
+                    if (decoder == null) {
+                        throw new Error("unknown config path: " + path);
+                    }
+                    else {
+                        conf[path] = decoder($(this).text());
+                    }
+                });
+            },
+            error  : function (req) {
+                throw new Error(req.status + " " + req.statusText);
+            }
+        });
+
+        return conf;
+    };
+
+})();
\ No newline at end of file