roomInfo.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. pinCount = document.createElement("div"),
  26. /** @const @type {Element} */
  27. pinList = document.createElement("ul"),
  28. /** @const @type {Element} */
  29. userCount = document.createElement("div"),
  30. /** @const @type {Element} */
  31. userList = document.createElement("ul"),
  32. /** @type {ChatSystem} */
  33. currentChatCtx,
  34. /** @type {Room} */
  35. currentChan;
  36. dom.className = R.klass.chatList.roomInfo.container;
  37. domHeader.className = R.klass.chatList.roomInfo.title;
  38. topicDom.className = R.klass.chatList.roomInfo.topic;
  39. purposeDom.className = R.klass.chatList.roomInfo.purpose;
  40. phone.className = R.klass.chatList.roomInfo.phone;
  41. pinCount.className = R.klass.chatList.roomInfo.pinCount;
  42. pinList.className = R.klass.chatList.roomInfo.pinList;
  43. userCount.className = R.klass.chatList.roomInfo.userCount;
  44. userList.className = R.klass.chatList.roomInfo.userList;
  45. purposeDetails.className = topicDetails.className = R.klass.chatList.roomInfo.author;
  46. domHeader.appendChild(headerContent);
  47. dom.appendChild(domHeader);
  48. dom.appendChild(section);
  49. topicDom.appendChild(topicContent);
  50. topicDom.appendChild(topicDetails);
  51. purposeDom.appendChild(purposeContent);
  52. purposeDom.appendChild(purposeDetails);
  53. section.appendChild(topicDom);
  54. section.appendChild(phone);
  55. section.appendChild(purposeDom);
  56. section.appendChild(pinCount);
  57. section.appendChild(pinList);
  58. section.appendChild(userCount);
  59. section.appendChild(userList);
  60. var updateCommon = function() {
  61. headerContent.textContent = currentChan.name;
  62. if (currentChan.pins) {
  63. pinCount.textContent = locale.pinCount(currentChan.pins.length);
  64. pinCount.classList.remove(R.klass.hidden);
  65. pinList.classList.remove(R.klass.hidden);
  66. var pinFrag = document.createDocumentFragment();
  67. currentChan.pins.forEach(function(uiMsg) {
  68. var li = document.createElement("li");
  69. li.className = R.klass.chatList.roomInfo.pinItem;
  70. li.appendChild(uiMsg.getDom());
  71. pinFrag.appendChild(li);
  72. });
  73. pinList.textContent = '';
  74. pinList.appendChild(pinFrag);
  75. } else {
  76. pinCount.classList.add(R.klass.hidden);
  77. pinList.classList.add(R.klass.hidden);
  78. }
  79. }, updateForChannel = function() {
  80. var ctx = currentChatCtx.getChatContext();
  81. if (ctx.capacities["topic"]) {
  82. topicDom.classList.remove(R.klass.hidden);
  83. topicContent.textContent = currentChan.topic || "";
  84. topicDetails.textContent = currentChan.topicCreator ? locale.topicDetail(currentChan.topicCreator, currentChan.topicTs) : "";
  85. } else {
  86. topicDom.classList.add(R.klass.hidden);
  87. }
  88. if (ctx.capacities["purpose"]) {
  89. purposeDom.classList.remove(R.klass.hidden);
  90. purposeContent.textContent = currentChan.purpose || "";
  91. purposeDetails.textContent = currentChan.purposeCreator ? locale.topicDetail(currentChan.purposeCreator, currentChan.purposeTs) : "";
  92. } else {
  93. purposeDom.classList.add(R.klass.hidden);
  94. }
  95. domHeader.style.backgroundImage = "";
  96. headerContent.classList.remove(R.klass.presenceIndicator);
  97. dom.classList.add(R.klass.chatList.roomInfo.type.channel);
  98. dom.classList.remove(R.klass.chatList.roomInfo.type.user);
  99. }, updateForDm = function() {
  100. domHeader.style.backgroundImage = "url(" +currentChan.user.getLargeIcon() +")";
  101. topicContent.textContent = (currentChan.user.realName || ((currentChan.user.firstName || "") +' ' +(currentChan.user.lastName))).trim();
  102. headerContent.classList.add(R.klass.presenceIndicator);
  103. if (currentChan.user.presence)
  104. headerContent.classList.remove(R.klass.presenceAway);
  105. else
  106. headerContent.classList.add(R.klass.presenceAway);
  107. topicDom.classList.remove(R.klass.hidden);
  108. phone.classList.remove(R.klass.hidden);
  109. phone.textContent = currentChan.user.phone || "";
  110. purposeContent.textContent = currentChan.user.goal || "";
  111. purposeDom.classList.remove(R.klass.hidden);
  112. dom.classList.remove(R.klass.chatList.roomInfo.type.channel);
  113. dom.classList.add(R.klass.chatList.roomInfo.type.user);
  114. }, _update = function() {
  115. updateCommon();
  116. if (currentChan instanceof PrivateMessageRoom)
  117. updateForDm();
  118. else
  119. updateForChannel();
  120. };
  121. return {
  122. /** @type {function(ChatSystem, Room)} */
  123. populate: function(channelContext, channel) {
  124. currentChatCtx = channelContext;
  125. currentChan = channel;
  126. _update();
  127. return this;
  128. },
  129. update: function() {
  130. _update();
  131. return this;
  132. },
  133. /** @type {function(Element)} */
  134. show: function(domParent) {
  135. domParent.appendChild(dom);
  136. dom.classList.remove(R.klass.hidden);
  137. return this;
  138. },
  139. hide: function() {
  140. dom.classList.add(R.klass.hidden);
  141. return this;
  142. },
  143. isParentOf: function(_dom) {
  144. while (_dom) {
  145. if (_dom === dom)
  146. return true;
  147. _dom = _dom.parentNode;
  148. }
  149. return false;
  150. }
  151. }
  152. })();