(function () { var identityDecoder = function (src) { return src; }; var identityEncoder = 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 mapEncoder = function (map) { var lines = []; $.each(map, function (key) { lines.push(key + " " + this); }); return lines.join("\n"); }; var boolDecoder = function (src) { return src == "*"; }; var boolEncoder = function (bool) { return bool ? "*" : ""; }; var decoder_of = { siteName : identityDecoder, baseURI : identityDecoder, defaultPage: identityDecoder, styleSheet : identityDecoder, languages : mapDecoder, globalLock : boolDecoder }; var encoder_of = { siteName : identityEncoder, baseURI : identityEncoder, defaultPage: identityEncoder, styleSheet : identityEncoder, languages : mapEncoder, globalLock : boolEncoder }; var cachedConf = null; Rakka.getSystemConfig = function () { if (cachedConf != null) { return cachedConf; } var conf = {}; cachedConf = 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; }; Rakka.showConfigPanel = function () { var conf = Rakka.getSystemConfig(); var $area = Rakka.switchScreen(); $area.append($.H1({}, "Configuration")); var fldSiteName = $.INPUT({type: "text", value: conf.siteName}); var fldBaseURI = $.INPUT({type: "text", value: conf.baseURI}); var fldDefaultPage = $.INPUT({type: "text", value: conf.defaultPage}); var fldStyleSheet = $.INPUT({type: "text", value: conf.styleSheet}); var fldLanguages = $.TEXTAREA({value: encoder_of.languages(conf.languages)}); var chkGlobalLock = $.INPUT({type: "checkbox", checked: conf.globalLock}); var btnSave = $.INPUT({type: "button", value: "Save"}); var btnCancel = $.INPUT({type: "button", value: "Cancel"}); var configPanel = $.TABLE({className: "pageEditor"}, $.TBODY({}, $.TR({}, $.TH({}, "Site name"), $.TD({}, fldSiteName) ), $.TR({}, $.TH({}, "Base URI"), $.TD({}, fldBaseURI) ), $.TR({}, $.TH({}, "Default page"), $.TD({}, fldDefaultPage) ), $.TR({}, $.TH({}, "Style sheet"), $.TD({}, fldStyleSheet) ), $.TR({}, $.TH({}, "Languages"), $.TD({}, fldLanguages) ), $.TR({}, $.TH({}, "Global lock"), $.TD({}, $.LABEL({}, chkGlobalLock, "Disallow guest users to edit pages.")) ), $.TR({}, $.TH({}), $.TD({}, btnSave, btnCancel) ) ) ); $area.append(configPanel); }; $(document).ready(function () { $("input.configButton") .click(function () { Rakka.showConfigPanel(); }); }); })();