1import * as SslInformationModule from "domains_ssl_information"; 2 3$(() => { 4 let siteID = window.siteData.id; 5 6 // Import the SSL information button click function. 7 const sslInformation = SslInformationModule.sslInformation; 8 9 // Return primary section. 10 const primary = (domain) => { 11 if (domain.primary) { 12 return(` 13 <div class="domain-primary"> 14 <div class="icon-indicator d-flex d-lg-block align-items-center"> 15 <i aria-hidden="true" class="fas fa-star blue ms-0 ms-lg-1" aria-hidden="true"></i> 16 <span>Primary</span> 17 </div> 18 </div> 19 `); 20 } else { 21 return(` 22 <div class="domain-primary"> 23 <div class="icon-indicator d-flex d-lg-block align-items-center"> 24 <i aria-hidden="true" class="fas fa-star muted ms-0 ms-lg-1" aria-hidden="true"></i> 25 </div> 26 </div> 27 `); 28 } 29 }; 30 31 // Return primary dropdown. 32 const primary_dropdown = (domain) => { 33 if (!domain.primary) { 34 return(` 35 <li> 36 <button class="dropdown-item domain-primary" type="button"> 37 <i aria-hidden="true" class="far fa-star" aria-hidden="true"></i> 38 Set As Primary</button> 39 </li> 40 `); 41 } 42 43 return ''; 44 }; 45 46 // Return regular domain health section. 47 const regular_health = (domain) => { 48 if (domain.id !== -1 && domain.healthy) { 49 return (` 50 <span>Healthy</span> 51 <div class="icon-indicator d-flex d-md-block align-items-center"> 52 <i aria-hidden="true" class="far fa-server is-clickable green" title="" aria-hidden="true" aria-label="Healthy"></i> 53 </div> 54 `); 55 } else if (domain.id !== -1 && !domain.healthy) { 56 return (` 57 <span>Provisioning</span> 58 <div class="icon-indicator d-flex d-md-block align-items-center"> 59 <i aria-hidden="true" class="far fa-server is-clickable orange" title="" aria-hidden="true" aria-label="Provisioning"></i> 60 </div> 61 `); 62 } 63 64 return ''; 65 }; 66 67 // Return zone information section. 68 const zoneInformation = (domain) => { 69 if (domain.id !== -1) { 70 return (` 71 <a href="/zones/${domain.zoneId}?site_id=${siteID}" class="dropdown-item"> 72 <i aria-hidden="true" class="far fa-info-circle" aria-hidden="true"></i>Zone Info 73 </a> 74 `); 75 } else { 76 return(` 77 <button className="dropdown-item domain-record-information" type="button"></button> 78 `); 79 } 80 }; 81 82 const sslRetry = (domain) => { 83 if (domain.id !== -1) { 84 return (` 85 <button class="dropdown-item domain-ssl-retry" data-bs-placement="left" data-bs-toggle="tooltip" data-domain-id="${domain.id}" data-domain-label="SSL" data-domain-name="${domain.name}" data-domain-zone-id="${domain.zoneId}" title="" type="button" data-bs-original-title="Retry SSL provisioning"> 86 <i aria-hidden="true" class="far fa-sync" aria-hidden="true"></i> 87 Retry SSL 88 </button> 89 `); 90 } 91 92 return ''; 93 }; 94 95 // Append the domain data to the dom. 96 const appendNewDomainData = (data) => { 97 // Remove the current table body records. 98 $('#domain_editor .domain').remove(); 99 100 data.forEach((domain) => { 101 if (domain.id !== -1) { 102 $('#domain_editor .v3-domain-editor').append(` 103 <div class="domain" data-domain-id="${domain.id}" data-domain-name="${domain.name}" data-domain-zone-id="${domain.zoneId}"> 104 <div class="resp-table-row d-block d-lg-flex flex-wrap"> 105 ${primary(domain)} 106 <div class="domain-name mt-2 mt-lg-0" data-label="Domain Name"> 107 <h4>${domain.url}</h4> 108 <p><small>${domain.formattedDate}</small></p> 109 </div> 110 <div class="domain-actions d-flex flex-wrap align-items-center justify-content-between justify-content-lg-start ms-auto mt-2 mt-lg-0"> 111 <div class="domain-health d-flex align-items-center"> 112 ${regular_health(domain)} 113 </div> 114 <div class="domain-actions-dropdown ms-2"> 115 <div class="btn-group"> 116 <button aria-expanded="false" class="btn btn-basic reverse dropdown-toggle" data-bs-toggle="dropdown" type="button">Actions</button> 117 <ul class="dropdown-menu dropdown-menu-end"> 118 <li> 119 ${zoneInformation(domain)} 120 </li> 121 <li class=""> 122 ${sslRetry(domain)} 123 </li> 124 <li> 125 ${sslInformation(domain)} 126 </li> 127 ${primary_dropdown(domain)} 128 </ul> 129 </div> 130 </div> 131 <div aria-hidden="true" class="modal fade" id="ssl_information_${domain.id}_modal" tabindex="-1"> 132 <div class="modal-dialog"> 133 <div class="modal-content"> 134 <div class="modal-header"> 135 <h2 class="uppercase">SSL Information</h2> 136 <button aria-label="Close" class="btn-close" data-bs-dismiss="modal" type="button"></button> 137 </div> 138 <div class="modal-body"> 139 <div class="alert alert-info"> 140 <strong>${domain.url}</strong> 141 </div> 142 <div class="alert alert-dark"> 143 </div> 144 </div> 145 <div class="modal-footer"> 146 <button class="btn btn-info" data-bs-dismiss="modal" type="button"> 147 Close 148 </button> 149 </div> 150 </div> 151 </div> 152 </div> 153 </div> 154 </div> 155 </div> 156 `); 157 } else { 158 $('#domain_editor .v3-domain-editor').append(` 159 <div class="domain" data-domain-name="${domain.name}" data-domain-zone-id="${domain.zoneId}"> 160 <div class="resp-table-row d-block d-lg-flex flex-wrap"> 161 ${primary(domain)} 162 <div class="domain-name mt-2 mt-lg-0" data-label="Domain Name"> 163 <h4>${domain.url}</h4> 164 <p><small>${domain.formattedDate}</small></p> 165 </div> 166 </div> 167 </div> 168 `); 169 } 170 }); 171 }; 172 173 // Set record as the primary record. 174 $(document).on('click', '.domain-primary', (e) => { 175 e.preventDefault(); 176 177 const $clickedStar = $(e.currentTarget); 178 179 const domainTable = $clickedStar.closest('.domain'); 180 181 const zoneId = domainTable.data('domain-zone-id'); 182 183 const domainName = domainTable.data('domain-name'); 184 185 const authenticityToken = $("[name='csrf-token']").attr('content') 186 187 const domainData = { 188 zoneId: zoneId, 189 name: domainName, 190 authenticity_token: authenticityToken 191 }; 192 193 fetch(`/sites/${siteID}/domains/set_primary`, { 194 method: 'POST', 195 headers: { 196 'Content-Type': 'application/json', 197 }, 198 body: JSON.stringify(domainData), 199 }) 200 .then((response) => response.json()) 201 .then((data) => { 202 if (data) { 203 if (data.message) { 204 // Display the error. 205 toastr.error(data.message); 206 } else { 207 // Reset the editor. 208 appendNewDomainData(data); 209 210 // Display notification. 211 toastr.success('Updated primary domain'); 212 } 213 } else { 214 toastr.error('Unable to set domain as primary, please try again'); 215 } 216 }) 217 .catch((error) => { 218 console.log(error); 219 220 toastr.error('Could not set domain as primary, please try again later'); 221 }); 222 223 return false;
224 }); 225 226 // SSL Retry clicked. 227 $(document).on('click', '.domain-ssl-retry', (e) => { 228 e.preventDefault(); 229 230 const $sslButton = $(e.currentTarget); 231 232 // Get reference to the sll retry icon. 233 const $sslIcon = $sslButton.find('i'); 234 235 // Make the spinner spin. 236 $sslIcon.addClass('fa-spin'); 237 238 // Give users feedback right away that something is happening. 239 toastr.success('Retrying SSL provisioning...'); 240 241 // Get the zone and record data. 242 const zoneId = $sslButton.data('domain-zone-id'); 243 244 const id = $sslButton.data('domain-id'); 245 246 const authenticityToken = $("[name='csrf-token']").attr('content') 247 248 const putData = { 249 authenticity_token: authenticityToken 250 }; 251 252 fetch(`/zones/${zoneId}/records/${id}/ssl`, { 253 method: 'PUT', 254 headers: { 255 'Content-Type': 'application/json', 256 'Accept': 'application/json', 257 }, 258 body: JSON.stringify(putData), 259 }) 260 .then(response => { 261 // Empty response returns a 204. 262 if (response.status === 204 || response.status === 200) { 263 // Make the spinner stop spinning. 264 $sslIcon.removeClass('fa-spin'); 265 266 // Exit early, everything is going fine. 267 return false; 268 } else { 269 // Format the response to json. 270 return response.json(); 271 } 272 }) 273 .then(data => { 274 // If data is not false, or exists. 275 if (data) { 276 // Check for message. 277 if (data.message) { 278 // Display the error. 279 toastr.error(data.message); 280 } 281 } 282 283 // Make the spinner stop spinning. 284 $sslIcon.removeClass('fa-spin'); 285 }) 286 .catch((error) => { 287 // Log the actual error. 288 console.log(error); 289 290 // Toast a sensible error. 291 toastr.error('Could not process your SSL Retry at this time. Please try again later.'); 292 293 // Make the spinner stop spinning. 294 $sslIcon.removeClass('fa-spin'); 295 }); 296 }); 297})
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.