1
0

config.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /** @type Config */
  2. var CONFIG;
  3. /** @constructor */
  4. function Config(configData) {
  5. this.deviceId = null;
  6. /** @type {Object.<string, Object<string, string>>} serviceType => { serviceId => serviceName } */
  7. this.services = {};
  8. /** @type {string|undefined} */
  9. this.emojiProvider;
  10. /** @type{boolean|undefined} */
  11. this.displayAvatar;
  12. // Load global configurations
  13. for (var i =0, nbConfig = configData.length; i < nbConfig; i++)
  14. if (configData[i]["service"] === null && configData[i]["device"] === null)
  15. this.mergeConfig(JSON.parse(configData[i]["config"]));
  16. }
  17. Config.prototype.mergeConfig = function(configData) {
  18. if (configData["services"])
  19. for (var i in configData["services"]) {
  20. this.services[i] = configData["services"][i];
  21. }
  22. if (configData["emojiProvider"] !== undefined)
  23. this.emojiProvider = configData["emojiProvider"];
  24. if (configData["displayAvatar"] !== undefined)
  25. this.displayAvatar = configData["displayAvatar"];
  26. };
  27. /** @return {string|undefined} */
  28. Config.prototype.getEmojiProvider = function() {
  29. return this.emojiProvider;
  30. };
  31. Config.prototype.isDisplayAvatars = function() {
  32. return this.displayAvatar !== false;
  33. };
  34. Config.prototype.commitNewSettings = function(newSettings) {
  35. for (var i in newSettings) {
  36. // Just to check not empty object
  37. // TODO only global config atm
  38. this.mergeConfig(newSettings);
  39. onConfigUpdated();
  40. new HttpRequest(HttpRequestMethod.POST, "api/settings?service=null&device=null").send(JSON.stringify(newSettings));
  41. return;
  42. }
  43. };
  44. Config.prototype.compileCSS = function() {
  45. var rules = {},
  46. css = '';
  47. if (!this.isDisplayAvatars()) {
  48. rules[".chatsystem-content .chatmsg-authorGroup .chatmsg-author-img-wrapper"] = ["display: none"];
  49. rules[".chatsystem-content .chatmsg-authorGroup"] = ["display: flex"];
  50. rules[".chatsystem-content .chatmsg-authorGroup .chatmsg-author"] = ["position:initial", "vertical-align:top", "min-width:75px"];
  51. rules[".chatsystem-content .chatmsg-authorGroup .chatmsg-author-messages"] = ["padding-top:0", "padding-left:0", "display:inline-block", "margin-top:-4px", "flex:1"];
  52. }
  53. for (var i in rules) {
  54. css += i +'{';
  55. rules[i].forEach(function(rule) {
  56. css += rule +';';
  57. });
  58. css += '}';
  59. }
  60. return css;
  61. };
  62. CONFIG = new Config([]);