]> gitweb @ CieloNegro.org - Rakka.git/blob - js/systemConfig.js
implemented page language select box
[Rakka.git] / js / systemConfig.js
1 (function () {
2
3     var identityDecoder = function (src) {
4         return src;
5     };
6
7     var mapDecoder = function (src) {
8         var map   = {};
9         var lines = src.split(/\n/);
10         
11         $.each(lines, function () {
12             var m = this.match(/^(\S+)\s+(\S+)$/);
13
14             map[ m[1] ] = m[2];
15         });
16
17         return map;
18     };
19
20     var boolDecoder = function (src) {
21         return src == "*";
22     };
23
24     var decoder_of = {
25         siteName   : identityDecoder,
26         baseURI    : identityDecoder,
27         defaultPage: identityDecoder,
28         styleSheet : identityDecoder,
29         languages  : mapDecoder,
30         globalLock : boolDecoder
31     };
32
33     var cachedConf = null;
34
35     Rakka.getSystemConfig = function () {
36         if (cachedConf != null) {
37             return cachedConf;
38         }
39         
40         var conf = {};
41         cachedConf = conf;
42         
43         $.ajax({
44             type   : "GET",
45             url    : Rakka.baseURI + "systemConfig",
46             async  : false,
47             success: function (xml) {
48                 $(xml).find("value").each(function () {
49                     var path    = this.getAttribute("path");
50                     var decoder = decoder_of[path];
51
52                     if (decoder == null) {
53                         throw new Error("unknown config path: " + path);
54                     }
55                     else {
56                         conf[path] = decoder($(this).text());
57                     }
58                 });
59             },
60             error  : function (req) {
61                 throw new Error(req.status + " " + req.statusText);
62             }
63         });
64
65         return conf;
66     };
67
68 })();