| @@ -12,11 +12,12 @@ | ||
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Display data attributes. |
| 15 | 15 | * |
| 16 | - * @var array $threads | |
| 17 | - * @var array $options | |
| 18 | - * @var string $id | |
| 16 | + * @var array $threads | |
| 17 | + * @var string[] $categories | |
| 18 | + * @var array $options | |
| 19 | + * @var string $id | |
| 19 | 20 | */ |
| 20 | 21 | extract($displayData); |
| 21 | 22 | |
| 22 | 23 | $id = 'vbo-chat-interface-' . ($options['id'] ?? uniqid()); |
| @@ -109,10 +110,15 @@ | ||
| 109 | 110 | } else { |
| 110 | 111 | thread.find('.last-update-date').text(date.toLocaleDateString()); |
| 111 | 112 | } |
| 112 | 113 | |
| 114 | + // strip HTML tags from message | |
| 115 | + const tmpDiv = document.createElement("div"); | |
| 116 | + tmpDiv.innerHTML = lastMessage.message; | |
| 117 | + let plainMessageText = tmpDiv.textContent || tmpDiv.innerText || ''; | |
| 118 | + | |
| 113 | 119 | // refresh message |
| 114 | - thread.find('.chat-thread-message-body').text(shortenText(lastMessage.message, 80)).attr('data-length', lastMessage.message.length); | |
| 120 | + thread.find('.chat-thread-message-body').text(shortenText(plainMessageText, 80)).attr('data-length', plainMessageText.length); | |
| 115 | 121 | |
| 116 | 122 | // refresh attachments |
| 117 | 123 | const attachments = lastMessage.attachments.map(a => a.name).join(', '); |
| 118 | 124 | thread.find('.chat-thread-message-attachments').attr('data-length', attachments.length).find('span').text(shortenText(attachments, 80)); |
| @@ -152,8 +158,11 @@ | ||
| 152 | 158 | |
| 153 | 159 | $('#<?php echo $id; ?>').find('.chat-thread[data-context][data-id].active').removeClass('active'); |
| 154 | 160 | $(this).addClass('active'); |
| 155 | 161 | |
| 162 | + // remove any loading overlay previously appended | |
| 163 | + $('#<?php echo $id; ?>').find('.vbo-chat-target .vbo-chat-loading').remove(); | |
| 164 | + | |
| 156 | 165 | // append loading box to the chat target |
| 157 | 166 | $('#<?php echo $id; ?>').find('.vbo-chat-target').append( |
| 158 | 167 | $('<div class="vbo-chat-loading"><?php VikBookingIcons::e('circle-notch', 'fa-spin fa-3x'); ?></div>') |
| 159 | 168 | ).addClass('slide-in'); |
| @@ -167,9 +176,16 @@ | ||
| 167 | 176 | (resp) => { |
| 168 | 177 | $('#<?php echo $id; ?>').find('.vbo-chat-target').html(resp.html); |
| 169 | 178 | }, |
| 170 | 179 | (err) => { |
| 171 | - alert(err.responseText); | |
| 180 | + // update icon on loading overlay | |
| 181 | + $('#<?php echo $id; ?>').find('.vbo-chat-target .vbo-chat-loading').html( | |
| 182 | + '<?php VikBookingIcons::e('exclamation-triangle', 'fa-3x'); ?>' | |
| 183 | + ); | |
| 184 | + | |
| 185 | + setTimeout(() => { | |
| 186 | + alert(err.responseText || err.statusText || 'Connection lost!'); | |
| 187 | + }, 32); | |
| 172 | 188 | } |
| 173 | 189 | ); |
| 174 | 190 | }); |
| 175 | 191 | |
| @@ -241,8 +257,9 @@ | ||
| 241 | 257 | // POST data |
| 242 | 258 | { |
| 243 | 259 | start: totalThreads, |
| 244 | 260 | limit: threadsLimit, |
| 261 | + categories: <?php echo json_encode($categories ?? []); ?>, | |
| 245 | 262 | options: <?php echo json_encode($options ?? []); ?>, |
| 246 | 263 | }, |
| 247 | 264 | // success callback |
| 248 | 265 | (threads) => { |