| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- /** @type Config */
- var CONFIG;
- /** @constructor */
- function Config(configData) {
- this.deviceId = null;
- /** @type {Object.<string, Object<string, string>>} serviceType => { serviceId => serviceName } */
- this.services = {};
- /** @type {string|undefined} */
- this.emojiProvider;
- /** @type{boolean|undefined} */
- this.displayAvatar;
- /** @type{boolean|undefined} */
- this.colorfulNames;
- // 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"];
- if (configData["colorfulNames"] !== undefined)
- this.colorfulNames = configData["colorfulNames"];
- };
- /** @return {string|undefined} */
- Config.prototype.getEmojiProvider = function() {
- return this.emojiProvider;
- };
- Config.prototype.isDisplayAvatars = function() {
- return this.displayAvatar !== false;
- };
- Config.prototype.isColorfulNames = function() {
- return this.colorfulNames === true;
- };
- 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"];
- }
- if (!this.isColorfulNames()) {
- rules[".chatsystem-content .chatmsg-authorGroup .chatmsg-author .chatmsg-author-name"] = ["background-color: transparent !important;"];
- }
- for (var i in rules) {
- css += i +'{';
- rules[i].forEach(function(rule) {
- css += rule +';';
- });
- css += '}';
- }
- return css;
- };
- CONFIG = new Config([]);
|