1;(function (window) { 2 if (window.JCUserFilesNotifications) 3 return; 4 5 JCUserFilesNotifications = function (params) { 6 this.componentName = 'eagle:userfiles.notifications'; 7 this.blockId = params.blockId; 8 this.popupId = params.popupId; 9 this.blockObj = BX(this.blockId); 10 this.popupObj = BX(this.popupId); 11 this.counterObj = this.blockObj.querySelector('.userfiles-notifications__counter'); 12 13 this.lineTextTemplateDescription = params.lineTextTemplateDescription; 14 this.lineTextTemplateFile = params.lineTextTemplateFile; 15 this.lineTextTemplateBoth = params.lineTextTemplateBoth; 16 17 this.initPopup(); 18 19 // this.loadNotifications(); 20 this.bindGenericEvents(); 21 }; 22 23 JCUserFilesNotifications.prototype.initPopup = function () { 24 this.popupBxObj = BX.PopupWindowManager.create("UserFilesNotificationsPopup", null, { 25 autoHide: true, 26 offsetLeft: 0, 27 offsetTop: 0, 28 overlay: true, 29 closeByEsc: true, 30 titleBar: false, 31 closeIcon: {}, 32 content: '' 33 }); 34 this.popupBxObj.popupContainer.className = 'userfiles-notifications-popup-wrapper'; 35 this.popupBxObj.setContent(this.popupObj); 36 }; 37 38 JCUserFilesNotifications.prototype.openPopup = function () { 39 this.updatePopupContent(this.notifications); 40 this.popupBxObj.show(); 41 }; 42 43 JCUserFilesNotifications.prototype.setNotifications = function (notifications) { 44 if (typeof notifications === 'object') 45 notifications = Object.values(notifications); 46 47 if (!Array.isArray(notifications)) 48 notifications = []; 49 50 this.notifications = notifications; 51 52 this.updateCounter(this.notifications.length); 53 if(this.popupBxObj.isShown()) 54 this.updatePopupContent(this.notifications); 55 }; 56 57 JCUserFilesNotifications.prototype.removeNotification = function (fileId) { 58 let updatedNotificationsList = this.notifications.filter((el) => el.ID !== fileId); 59 if (updatedNotificationsList.length !== this.notifications.length) { 60 this.setNotifications(updatedNotificationsList); 61 } 62 }; 63 64 JCUserFilesNotifications.prototype.loadNotifications = function () { 65 BX.ajax.runComponentAction( 66 this.componentName, 67 'getNotifications', 68 { 69 mode: 'class', 70 data: {} 71 } 72 ).then((response) => { 73 this.setNotifications(response.data.notifications); 74 }, (response) => { 75 console.error(response); 76 this.printError(response.errors[0].message); 77 }); 78 }; 79 80 JCUserFilesNotifications.prototype.markAllAsRead = function () { 81 BX.ajax.runComponentAction( 82 this.componentName, 83 'markAllAsRead', 84 { 85 mode: 'class', 86 data: {} 87 } 88 ).then((response) => { 89 this.setNotifications([]); 90 }, (response) => { 91 console.error(response); 92 this.printError(response.errors[0].message); 93 }); 94 }; 95 96 JCUserFilesNotifications.prototype.markNotificationAsRead = function (fileId) { 97 BX.ajax.runComponentAction( 98 this.componentName, 99 'markNotificationAsRead', 100 { 101 mode: 'class', 102 data: {'fileId': fileId} 103 } 104 ).then((response) => { 105 this.removeNotification(fileId); 106 }, (response) => { 107 console.error(response); 108 this.printError(response.errors[0].message); 109 }); 110 }; 111 112 JCUserFilesNotifications.prototype.unsubscribe = function (fileId) { 113 BX.ajax.runComponentAction( 114 this.componentName, 115 'unsubscribe', 116 { 117 mode: 'class', 118 data: {'fileId': fileId} 119 } 120 ).then((response) => { 121 this.removeNotification(fileId); 122 }, (response) => { 123 console.error(response); 124 this.printError(response.errors[0].message); 125 }); 126 }; 127 128 JCUserFilesNotifications.prototype.bindGenericEvents = function () { 129 BX.bind(this.blockObj.querySelector('.userfiles-notifications__button'), 'click', BX.proxy(this.openPopup, this)); 130 BX.bind(this.popupObj.querySelector('.userfiles-notifications-popup__button-mark-all-as-read'), 'click', BX.proxy(this.markAllAsRead, this)); 131 }; 132 133 JCUserFilesNotifications.prototype.updatePopupContent = function (notifications) { 134 // опÑеделÑем конÑÐµÐ¹Ð½ÐµÑ ÑÑÑок и ÑÑÑокÑ-Ñаблон 135 let linesContainer = this.popupObj.querySelector('.userfiles-notifications-popup__lines'), 136 lineTemplate = linesContainer.querySelector('.userfiles-notifications-popup-line--template'); 137 138 // ÑдалÑем вÑе ÑÑаÑÑе ÑÑÑоки кÑоме ÑÑÑоки-Ñаблона 139 linesContainer.querySelectorAll('.userfiles-notifications-popup-line').forEach((item) => { 140 if (item !== lineTemplate) 141 item.remove(); 142 }); 143 144 if (notifications.length === 0) { 145 this.popupBxObj.close(); 146 return; 147 } 148 149 // Ð´Ð»Ñ ÑдобÑÑва блок Ñ Ð½Ð°Ð·Ð²Ð°Ð½Ð¸ÐµÐ¼ и даÑой Ð¾Ð±Ð½Ð¾Ð²Ð»ÐµÐ½Ð¸Ñ Ð² ÑÑÑоке-Ñаблоне ÑÐ¾Ñ ÑанÑем оÑделÑно 150 let lineTemplateName = lineTemplate.querySelector('.userfiles-notifications-popup-line__name'), 151 lineTemplateUpdateDate = lineTemplate.querySelector('.userfiles-notifications-popup-line__date-update'); 152 153 let _this = this; 154 notifications.forEach((notification) => { 155 // ÐÐ»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð³Ð¾ нового ÑÐ²ÐµÐ´Ð¾Ð¼Ð»ÐµÐ½Ð¸Ñ ÑоздаÑм ÑÐ²Ð¾Ñ ÑÑÑÐ¾ÐºÑ Ð¸Ð· Ñаблонной ÑÑÑоки. 156 // ÐÐ¼Ñ Ð¸ даÑÑ Ñакже дÑблиÑÑем, поÑколÑÐºÑ Ð¾Ð½Ð¸ бÑдÑÑ Ð¿Ð¾Ð´ÑÑавлÑÑÑÑÑ Ð² Ñаблон ÑÑÑоки Ñ ÑекÑÑом ÑведомлениÑ, а не напÑÑмÑÑ 157 let lineObj = lineTemplate.cloneNode(true), 158 nameObj = lineTemplateName.cloneNode(true), 159 dateObj = lineTemplateUpdateDate.cloneNode(true); 160 161 nameObj.innerText = notification.NAME; 162 dateObj.innerText = notification.CHANGE_DATE; 163 164 // в завиÑимоÑÑи Ð¾Ñ Ñипа ÑÐ²ÐµÐ´Ð¾Ð¼Ð»ÐµÐ½Ð¸Ñ (Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ñ Ð¿Ð¾Ð»Ñ Ð¾Ð¿Ð¸ÑаниÑ, Ñайл или и опиÑание, и Ñайл) беÑÑм за оÑÐ½Ð¾Ð²Ñ 165 // ÑазнÑй Ñаблон ÑÑÑоки ÑекÑÑа ÑÐ²ÐµÐ´Ð¾Ð¼Ð»ÐµÐ½Ð¸Ñ 166 let lineText; 167 if (notification.UPDATE_TYPE === 'description') 168 lineText = _this.lineTextTemplateDescription; 169 if (notification.UPDATE_TYPE === 'file') 170 lineText = _this.lineTextTemplateFile; 171 if (notification.UPDATE_TYPE === 'both') 172 lineText = _this.lineTextTemplateBoth; 173 // заÑем в Ñаблоне заменÑем наÐ
173·Ð²Ð°Ð½Ð¸Ðµ Ñайла и даÑÑ Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ Ð½Ð° ÑооÑвеÑÑÑвÑÑÑие блоки 174 lineText = lineText.replace('#FILE_NAME#', nameObj.outerHTML); 175 lineText = lineText.replace('#DATE#', dateObj.outerHTML); 176 177 // далее задаÑм ÑлеменÑам Ñоздаваемой ÑÑÑоки нÑжное ÑодеÑжимое 178 lineObj.querySelector('.userfiles-notifications-popup-line__text').innerHTML = lineText; 179 180 let titleObj = lineObj.querySelector('.userfiles-notifications-popup-line__title'); 181 titleObj.innerHTML = notification.NAME; 182 titleObj.attributes.href.value = notification.URL; 183 184 lineObj.querySelector('.userfiles-notifications-popup-line__game').innerHTML = notification.GAME; 185 lineObj.querySelector('.userfiles-notifications-popup-line__unit').innerHTML = notification.UNIT; 186 187 lineObj.querySelector('.userfiles-notifications-popup-line__type').innerHTML += notification.TYPE; 188 189 let authorObj = lineObj.querySelector('.userfiles-notifications-popup-line__author'); 190 if (notification.CREATED_USER_NAME) { 191 authorObj.innerHTML += notification.CREATED_USER_NAME; 192 this.showBlock(authorObj); 193 } else { 194 this.hideBlock(authorObj); 195 } 196 197 let labelClassName = 'userfiles-notifications-popup-line__label--' + notification.TYPE_XML_ID; 198 lineObj.querySelector('.userfiles-notifications-popup-line__label').classList.add(labelClassName); 199 200 lineObj.querySelector('.userfiles-notifications-popup-line__button--open-file').attributes.href.value = notification.URL; 201 202 // поÑле Ñого, как вÑе ÑлеменÑÑ ÑÑÑоки акÑÑализиÑованÑ, добавлÑем ÑÑÑ ÑÑÑÐ¾ÐºÑ Ð² конÑÐµÐ¹Ð½ÐµÑ ÑÑÑок и 203 // пÑивÑзÑваем ÑобÑÑÐ¸Ñ Ð½Ð° ÑлеменÑÑ ÑÑой ÑÑÑоки 204 linesContainer.appendChild(lineObj); 205 this.bindLineEvents(lineObj, notification.ID); 206 207 // поÑледний Ñаг - ÑбиÑаем Ñ Ð½Ð¾Ð²Ð¾Ð¹ ÑÑÑоки клаÑÑ ÑÑÑоки-Ñаблона, Ñем ÑамÑм Ð´ÐµÐ»Ð°Ñ ÐµÑ Ð²Ð¸Ð´Ð¸Ð¼Ð¾Ð¹ 208 lineObj.classList.remove('userfiles-notifications-popup-line--template'); 209 }); 210 }; 211 212 JCUserFilesNotifications.prototype.printError = function (errorMessage) { 213 let linesContainer = this.popupObj.querySelector('.userfiles-notifications-popup__lines'); 214 linesContainer.replaceChildren(BX.create('div', { 215 children: [ 216 BX.create('span', { 217 'text': BX.message('userfiles_notifications_error_pretext'), 218 }), 219 BX.create('span', { 220 'text': errorMessage, 221 attrs: {className: "userfiles-notifications-popup__error-message"} 222 }) 223 ] 224 })); 225 226 this.hideBlock(this.popupObj.querySelector('.userfiles-notifications-popup__footer')); 227 } 228 229 JCUserFilesNotifications.prototype.bindLineEvents = function (lineObj, fileId) { 230 BX.bind(lineObj.querySelector('.userfiles-notifications-popup__button-delete-notification'), 'click', () => this.markNotificationAsRead(fileId)); 231 BX.bind(lineObj.querySelector('.userfiles-notifications-popup__button-unsubscribe'), 'click', () => this.unsubscribe(fileId)); 232 }; 233 234 JCUserFilesNotifications.prototype.updateCounter = function (count) { 235 this.counterObj.innerText = count; 236 if (count > 0) 237 this.showBlock(this.blockObj); 238 else 239 this.hideBlock(this.blockObj); 240 }; 241 242 JCUserFilesNotifications.prototype.hideBlock = (block) => block.classList.add('userfiles-notifications__hidden'); 243 244 JCUserFilesNotifications.prototype.showBlock = (block) => block.classList.remove('userfiles-notifications__hidden'); 245})(window);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.