1function findQueuingInstructionsElement() { 2 return document.querySelector('.glia-instructions'); 3} 4 5function findQueueElement(queueName) { 6 return document.querySelector("div.queue[queue_name='" + queueName + "']"); 7} 8 9function findAllQueueElements() { 10 return document.querySelectorAll('div.queue'); 11} 12 13function findAllQueueMediaButtons() { 14 return document.querySelectorAll('div.queue > .card'); 15} 16 17function findMediaButtonsForQueue(queueElement) { 18 return queueElement.querySelectorAll('.card'); 19} 20 21function findCancelButton() { 22 return document.querySelector('.cancel'); 23} 24 25function getMediaButtonQueueName(button) { 26 return button.parentElement.getAttribute('queue_name'); 27} 28 29function getButtonMedium(button) { 30 return button.getAttribute('medium'); 31} 32 33function findVirtualBranchElement() { 34 return document.querySelector('.virtual-branch'); 35} 36 37//---------------------------------------------------------------------------------- 38 39function hide(element) { 40 if (element) { 41 element.style.display = 'none'; 42 } 43} 44 45function show(element) { 46 if (element) { 47 element.style.display = 'block'; 48 } 49} 50 51function showAsGrid(element) { 52 if (element) { 53 element.style.display = 'grid'; 54 } 55} 56function showAsInline(element) { 57 if (element) { 58 element.style.display = 'inline'; 59 } 60} 61 62function showCanQueue(queueElement, queueMedias) { 63 queueElement.classList.remove('disabled'); 64 updateQueueAvailableMedia(queueElement, queueMedias); 65} 66 67function showCannotQueue(queueElement) { 68 queueElement.classList.add('disabled'); 69 updateQueueAvailableMedia(queueElement, []); // Disables all media buttons 70} 71 72function showCannotQueueAnywhere() { 73 findAllQueueElements().forEach(showCannotQueue); 74} 75 76function showFailedToQueueView(error) { 77 //findQueuingInstructionsElement().innerText = 'Sorry! Currently unavailable.'; 78 //show(document.querySelector('div.instructions-container')); 79} 80 81function showCanQueueView() { 82 const element = findQueuingInstructionsElement(); 83 84 if (element) { 85 element.innerText = ''; //Please select a queue and click a media button 86 } 87 88 hide(document.querySelector('div.instructions-container')); 89 show(document.querySelector('.cms-instructions')); 90} 91 92function showAlreadyQueuedView() { 93 findQueuingInstructionsElement().innerText = 'Please wait, you will be connected shortly'; 94 show(document.querySelector('div.instructions-container')); 95 hide(document.querySelector('.cms-instructions')); 96} 97 98function showCannotQueueView() { 99 //findQueuingInstructionsElement().innerText = 'Queueing is currently disabled'; 100 //show(document.querySelector('div.instructions-container')); 101} 102 103function showVirtualBranchElement() { 104 const element = findVirtualBranchElement(); 105 106 if (element) { 107 element.classList.add('visible'); 108 } 109} 110 111function hideVirtualBranchElement() { 112 const element = findVirtualBranchElement(); 113 114 if (element) { 115 element.classList.remove('visible'); 116 } 117} 118 119function updateQueueAvailableMedia(queueElement, medias) { 120 findMediaButtonsForQueue(queueElement).forEach(function (button) { 121 var mediaUnavailable = medias.indexOf(getButtonMedium(button)) === -1; 122 //button.disabled = mediaUnavailable; 123 124 if (mediaUnavailable) { 125 button.classList.add('disabled'); 126 } 127 else { 128 button.classList.remove('disabled'); 129 } 130 }); 131} 132 133var queueTicket; 134 135function listenForQueueButtonClicks(salemove, queues) { 136 findAllQueueMediaButtons().forEach(function (mediaButton) { 137 138 var buttonQueueName = getMediaButtonQueueName(mediaButton); 139 var buttonMedium = getButtonMedium(mediaButton); 140 141 var queueId = queues 142 .filter(function (queue) { 143 return queue.name === buttonQueueName; 144 }) 145 .map(function (queue) { 146 return queue.id; 147 })[0]; 148 149 if (queueId === undefined) { 150 throw new Error('Queue button present, but queue not defined in Glia. Queue name: ' + buttonQueueName); 151 } 152 153 mediaButton.addEventListener('click', function () { 154 if (buttonMedium === 'phone') { 155 var visitorPhoneNumber = '+1'; //Put a phone number here to pass it to the queue 156 salemove 157 .queueForEngagement(buttonMedium, { 158 queueId: queueId, 159 phoneNumber: visitorPhoneNumber 160 }) 161 .catch(showFailedToQueueView); 162 } 163 else { 164 salemove 165 .queueForEngagement(buttonMedium, { queueId: queueId }) 166 .catch(showFailedToQueueView); 167 } 168 }); 169 });
170} 171 172function listenForCancel() { 173 const cancelButton = findCancelButton(); 174 if (cancelButton) { 175 cancelButton.addEventListener('click', function () { 176 if (queueTicket) { 177 queueTicket.cancel(); 178 } else { 179 throw new Error('Cannot cancel queuing while not queued'); 180 } 181 }); 182 } 183} 184 185function onQueueState(queue) { 186 if (findQueueElement(queue.name) !== null) { 187 if (queue.state.status === queue.state.STATUSES.OPEN) { 188 showCanQueue(findQueueElement(queue.name), queue.state.medias); 189 } 190 else { 191 showCannotQueue(findQueueElement(queue.name)); 192 } 193 } 194} 195 196function onVisitorQueueingState(queuingState) { 197 if (queuingState.state === queuingState.QUEUE_STATES.QUEUED) { 198 queueTicket = queuingState.ticket; 199 findAllQueueElements().forEach(hide); 200 showAsInline(findCancelButton()); 201 showAlreadyQueuedView(); 202 } 203 else if (queuingState.state === queuingState.QUEUE_STATES.CANNOT_QUEUE) { 204 queueTicket = null; 205 //findAllQueueElements().forEach(hide); 206 hide(findCancelButton()); 207 showCannotQueueView(); 208 hideVirtualBranchElement(); 209 } 210 else { 211 queueTicket = null; 212 findAllQueueElements().forEach(showAsGrid); 213 hide(findCancelButton()); 214 showCanQueueView(); 215 showVirtualBranchElement(); 216 } 217} 218 219showCannotQueueAnywhere(); 220hide(findCancelButton()); 221 222function checkGliaAvailable() { 223 gliaAttemptCount++; 224 225 if (gliaAttemptCount > 60) { 226 clearInterval(gliaInterval); 227 console.log('Timeout waiting for Glia to initialize.'); 228 } 229 230 if (typeof sm !== 'undefined') { 231 clearInterval(gliaInterval); 232 233 if (window.location.host.indexOf('gwcu.org') > -1 || window.location.host.indexOf('usucu.org') > -1 || window.location.host.indexOf('localhost') > -1) { 234 sm.getApi({ version: 'v1' }).then(function (salemove) { 235 salemove.addEventListener( 236 salemove.EVENTS.QUEUE_STATE_UPDATE, 237 onVisitorQueueingState 238 ); 239 240 listenForCancel(); 241 242 salemove.getQueues().then(function (queues) { 243 listenForQueueButtonClicks(salemove, queues); 244 245 var queueIds = queues.map(function (queue) { 246 return queue.id; 247 }); 248 249 salemove.subscribeToQueueStateUpdates(queueIds, onQueueState); 250 }); 251 }); 252 } 253 } 254} 255 256let gliaAttemptCount = 0; 257 258const gliaInterval = setInterval(checkGliaAvailable, 500);
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.