3 var identityDecoder = function (src) {
7 var identityEncoder = function (src) {
11 var mapDecoder = function (src) {
13 var lines = src.split(/\n/);
15 $.each(lines, function () {
16 var m = this.match(/^(\S+)\s+(\S+)$/);
24 var mapEncoder = function (map) {
27 $.each(map, function (key) {
28 lines.push(key + " " + this);
31 return lines.join("\n");
34 var boolDecoder = function (src) {
38 var boolEncoder = function (bool) {
39 return bool ? "*" : "";
43 siteName : identityDecoder,
44 baseURI : identityDecoder,
45 defaultPage: identityDecoder,
46 styleSheet : identityDecoder,
47 languages : mapDecoder,
48 globalLock : boolDecoder
52 siteName : identityEncoder,
53 baseURI : identityEncoder,
54 defaultPage: identityEncoder,
55 styleSheet : identityEncoder,
56 languages : mapEncoder,
57 globalLock : boolEncoder
60 var cachedConf = null;
62 Rakka.getSystemConfig = function () {
63 if (cachedConf != null) {
72 url : Rakka.baseURI + "systemConfig",
74 success: function (xml) {
75 $(xml).find("value").each(function () {
76 var path = this.getAttribute("path");
77 var decoder = decoder_of[path];
79 if (decoder == null) {
80 throw new Error("unknown config path: " + path);
83 conf[path] = decoder($(this).text());
87 error : function (req) {
88 throw new Error(req.status + " " + req.statusText);
95 Rakka.showConfigPanel = function () {
96 var conf = Rakka.getSystemConfig();
97 var $area = Rakka.switchScreen();
99 $area.append($.H1({}, "Configuration"));
102 = $.INPUT({type: "text", value: conf.siteName});
105 = $.INPUT({type: "text", value: conf.baseURI});
108 = $.INPUT({type: "text", value: conf.defaultPage});
111 = $.INPUT({type: "text", value: conf.styleSheet});
114 = $.TEXTAREA({value: encoder_of.languages(conf.languages)});
117 = $.INPUT({type: "checkbox", checked: conf.globalLock});
120 = $.INPUT({type: "button", value: "Save"});
123 = $.INPUT({type: "button", value: "Cancel"});
126 = $.TABLE({className: "pageEditor"},
129 $.TH({}, "Site name"),
130 $.TD({}, fldSiteName)
133 $.TH({}, "Base URI"),
137 $.TH({}, "Default page"),
138 $.TD({}, fldDefaultPage)
141 $.TH({}, "Style sheet"),
142 $.TD({}, fldStyleSheet)
145 $.TH({}, "Languages"),
146 $.TD({}, fldLanguages)
149 $.TH({}, "Global lock"),
153 "Disallow guest users to edit pages."))
157 $.TD({}, btnSave, btnCancel)
162 $area.append(configPanel);
165 $(document).ready(function () {
166 $("input.configButton")
168 Rakka.showConfigPanel();