/** @type Config */ var CONFIG; /** @constructor */ function Config(configData) { this.deviceId = null; /** @type {Object.>} serviceType => { serviceId => serviceName } */ this.services = {}; /** @type {string|undefined} */ this.emojiProvider; /** @type{boolean|undefined} */ this.displayAvatar; // Load global configurations for (var i =0, nbConfig = configData.length; i < nbConfig; i++) if (configData[i]["service"] === null && configData[i]["device"] === null) this.mergeConfig(JSON.parse(configData[i]["config"])); } Config.prototype.mergeConfig = function(configData) { if (configData["services"]) for (var i in configData["services"]) { this.services[i] = configData["services"][i]; } if (configData["emojiProvider"] !== undefined) this.emojiProvider = configData["emojiProvider"]; if (configData["displayAvatar"] !== undefined) this.displayAvatar = configData["displayAvatar"]; }; /** @return {string|undefined} */ Config.prototype.getEmojiProvider = function() { return this.emojiProvider; }; Config.prototype.isDisplayAvatars = function() { return this.displayAvatar !== false; }; Config.prototype.commitNewSettings = function(newSettings) { for (var i in newSettings) { // Just to check not empty object // TODO only global config atm this.mergeConfig(newSettings); onConfigUpdated(); new HttpRequest(HttpRequestMethod.POST, "api/settings?service=null&device=null").send(JSON.stringify(newSettings)); return; } }; Config.prototype.compileCSS = function() { var rules = {}, css = ''; if (!this.isDisplayAvatars()) { rules[".chatsystem-content .chatmsg-authorGroup .chatmsg-author-img-wrapper"] = ["display: none"]; rules[".chatsystem-content .chatmsg-authorGroup"] = ["display: flex"]; rules[".chatsystem-content .chatmsg-authorGroup .chatmsg-author"] = ["position:initial", "vertical-align:top", "min-width:75px"]; rules[".chatsystem-content .chatmsg-authorGroup .chatmsg-author-messages"] = ["padding-top:0", "padding-left:0", "display:inline-block", "margin-top:-4px", "flex:1"]; } for (var i in rules) { css += i +'{'; rules[i].forEach(function(rule) { css += rule +';'; }); css += '}'; } return css; }; CONFIG = new Config([]);