roomInfo.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. var roomInfo = (function() {
  2. var /** @const @type {Element} */
  3. dom = document.createElement("div"),
  4. /** @const @type {Element} */
  5. domHeader = document.createElement("header"), // Contain chan name + backgroundImg if any
  6. /** @const @type {Element} */
  7. headerContent = document.createElement("h3"), // Contain chan name + backgroundImg if any
  8. /** @const @type {Element} */
  9. section = document.createElement("div"),
  10. /** @const @type {Element} */
  11. topicDom = document.createElement("div"),
  12. /** @const @type {Element} */
  13. topicContent = document.createElement("span"),
  14. /** @const @type {Element} */
  15. topicDetails = document.createElement("span"),
  16. /** @const @type {Element} */
  17. phone = document.createElement("div"),
  18. /** @const @type {Element} */
  19. purposeDom = document.createElement("div"),
  20. /** @const @type {Element} */
  21. purposeContent = document.createElement("span"),
  22. /** @const @type {Element} */
  23. purposeDetails = document.createElement("span"),
  24. /** @const @type {Element} */
  25. userCount = document.createElement("div"),
  26. /** @const @type {Element} */
  27. userList = document.createElement("ul"),
  28. /** @type {ChatSystem} */
  29. currentChatCtx,
  30. /** @type {Room} */
  31. currentChan;
  32. dom.className = R.klass.chatList.roomInfo.container;
  33. domHeader.className = R.klass.chatList.roomInfo.title;
  34. topicDom.className = R.klass.chatList.roomInfo.topic;
  35. purposeDom.className = R.klass.chatList.roomInfo.purpose;
  36. phone.className = R.klass.chatList.roomInfo.phone;
  37. userCount.className = R.klass.chatList.roomInfo.userCount;
  38. userList.className = R.klass.chatList.roomInfo.userList;
  39. purposeDetails.className = topicDetails.className = R.klass.chatList.roomInfo.author;
  40. domHeader.appendChild(headerContent);
  41. dom.appendChild(domHeader);
  42. dom.appendChild(section);
  43. topicDom.appendChild(topicContent);
  44. topicDom.appendChild(topicDetails);
  45. purposeDom.appendChild(purposeContent);
  46. purposeDom.appendChild(purposeDetails);
  47. section.appendChild(topicDom);
  48. section.appendChild(phone);
  49. section.appendChild(purposeDom);
  50. section.appendChild(userCount);
  51. section.appendChild(userList);
  52. var updateCommon = function() {
  53. headerContent.textContent = currentChan.name;
  54. }, updateForChannel = function() {
  55. var ctx = currentChatCtx.getChatContext();
  56. if (ctx.capacities["topic"]) {
  57. topicDom.classList.remove(R.klass.hidden);
  58. topicContent.textContent = currentChan.topic || "";
  59. topicDetails.textContent = currentChan.topicCreator ? locale.topicDetail(currentChan.topicCreator, currentChan.topicTs) : "";
  60. } else {
  61. topicDom.classList.add(R.klass.hidden);
  62. }
  63. if (ctx.capacities["purpose"]) {
  64. purposeDom.classList.remove(R.klass.hidden);
  65. purposeContent.textContent = currentChan.purpose || "";
  66. purposeDetails.textContent = currentChan.purposeCreator ? locale.topicDetail(currentChan.purposeCreator, currentChan.purposeTs) : "";
  67. } else {
  68. purposeDom.classList.add(R.klass.hidden);
  69. }
  70. domHeader.style.backgroundImage = "";
  71. headerContent.classList.remove(R.klass.presenceIndicator);
  72. userCount.classList.remove(R.klass.hidden);
  73. userList.classList.remove(R.klass.hidden);
  74. dom.classList.add(R.klass.chatList.roomInfo.type.channel);
  75. dom.classList.remove(R.klass.chatList.roomInfo.type.user);
  76. }, updateForDm = function() {
  77. domHeader.style.backgroundImage = "url(" +currentChan.user.getLargeIcon() +")";
  78. topicContent.textContent = (currentChan.user.realName || ((currentChan.user.firstName || "") +' ' +(currentChan.user.lastName))).trim();
  79. headerContent.classList.add(R.klass.presenceIndicator);
  80. if (currentChan.user.presence)
  81. headerContent.classList.remove(R.klass.presenceAway);
  82. else
  83. headerContent.classList.add(R.klass.presenceAway);
  84. topicDom.classList.remove(R.klass.hidden);
  85. phone.classList.remove(R.klass.hidden);
  86. phone.textContent = currentChan.user.phone || "";
  87. purposeContent.textContent = currentChan.user.goal || "";
  88. purposeDom.classList.remove(R.klass.hidden);
  89. userCount.classList.add(R.klass.hidden);
  90. userList.classList.add(R.klass.hidden);
  91. dom.classList.remove(R.klass.chatList.roomInfo.type.channel);
  92. dom.classList.add(R.klass.chatList.roomInfo.type.user);
  93. }, _update = function() {
  94. updateCommon();
  95. if (currentChan instanceof PrivateMessageRoom)
  96. updateForDm();
  97. else
  98. updateForChannel();
  99. };
  100. return {
  101. /** @type {function(ChatSystem, Room)} */
  102. populate: function(channelContext, channel) {
  103. currentChatCtx = channelContext;
  104. currentChan = channel;
  105. _update();
  106. return this;
  107. },
  108. update: function() {
  109. _update();
  110. return this;
  111. },
  112. /** @type {function(Element)} */
  113. show: function(domParent) {
  114. domParent.appendChild(dom);
  115. dom.classList.remove(R.klass.hidden);
  116. return this;
  117. },
  118. hide: function() {
  119. dom.classList.add(R.klass.hidden);
  120. return this;
  121. }
  122. }
  123. })();