Diff -- /var/www/vhosts/webstls.com/httpdocs/assets/javascript/scripts.js
Diff
/var/www/vhosts/webstls.com/httpdocs/assets/javascript/scripts.js
added on WebSTLs (webstls.com) at 2026-07-01 22:26:28
Added
+438
lines
Removed
-0
lines
Context
0
unchanged
Blobs
from
to 3ae0924784e9
to 3ae0924784e9
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.| 1 | // ------ Make an AJAX request and get back the result using JQuery -------- // | |
| 2 | function ajax_request(url, div_id, asynchronous, get_post, form_data){ | |
| 3 | //console.log('url:'+url); | |
| 4 | var asynch_mode; | |
| 5 | if(asynchronous == 'true'){ | |
| 6 | asynch_mode = true; | |
| 7 | }else{ | |
| 8 | asynch_mode = false; | |
| 9 | } | |
| 10 | ||
| 11 | var method_type; | |
| 12 | if(get_post == 'POST'){ | |
| 13 | method_type = 'POST'; | |
| 14 | }else{ | |
| 15 | method_type = 'GET'; | |
| 16 | } | |
| 17 | ||
| 18 | // console.log('\nAJAX request url: ' + url + '\ndiv_id: ' + div_id + '\nasynchronous: ' + asynchronous + '\nmethod: ' + method_type + '\nForm data, keys and values listed below if any\n'); | |
| 19 | var form_data_string = ''; | |
| 20 | if(form_data){ | |
| 21 | //Print out just the list of keys | |
| 22 | //console.log(Object.keys(form_data)); | |
| 23 | ||
| 24 | //Loop through the keys | |
| 25 | for (let key_name of Object.keys(form_data)) { | |
| 26 | //Print out each of the keys with the values | |
| 27 | // console.log(key_name + '=' + form_data[key_name]); | |
| 28 | form_data_string += '&' + key_name + '=' + encodeURIComponent(form_data[key_name]); | |
| 29 | } | |
| 30 | console.log("Passing name value pairs as POST data" + form_data_string); | |
| 31 | } | |
| 32 | ||
| 33 | $.ajax({ | |
| 34 | url: url, | |
| 35 | async: asynch_mode, | |
| 36 | type: method_type, | |
| 37 | data: form_data_string, | |
| 38 | context: document.body, | |
| 39 | success: function(){ | |
| 40 | $(this).addClass("done") | |
| 41 | }, | |
| 42 | dataType: "html", | |
| 43 | success: function(data) { | |
| 44 | data = $.trim(data); | |
| 45 | ||
| 46 | // console.log("\nData returned: '" + data + "'"); | |
| 47 | ||
| 48 | //Callback function | |
| 49 | update_result(data, div_id); | |
| 50 | ||
| 51 | //return data; | |
| 52 | }, | |
| 53 | error: function() { | |
| 54 | // console.log('No data returned'); | |
| 55 | } | |
| 56 | }); | |
| 57 | } | |
| 58 | ||
| 59 | //Callback function to avoid the async problem | |
| 60 | function update_result(data, div_id){ | |
| 61 | // console.log('\nUpdating div_id: ' + div_id + '\nWith this data: ' + data); | |
| 62 | ||
| 63 | if(data == 'passed'){ | |
| 64 | document.getElementById(div_id).className = 'status_true'; | |
| 65 | }else if(data == 'failed'){ | |
| 66 | document.getElementById(div_id).className = 'status_false'; | |
| 67 | }else if(div_id){ | |
| 68 | //Perl piece: print "Location: $url->{page}&name=value"; | |
| 69 | //Perl piece: print "Location(parameter_to_return): $url->{page}&name=value"; | |
| 70 | var inputStr = data; | |
| 71 | ||
| 72 | //If a user is passing a parameter then pass that back to the page first | |
| 73 | var param = inputStr; | |
| 74 | var param = param.replace(/location(\(.*\)):.*/i, "$1"); | |
| 75 | param = param.replace(/\((.*)\)/i, "$1"); | |
| 76 | if(param){ | |
| 77 | //Pass back the param | |
| 78 | document.getElementById(div_id).innerHTML = param; | |
| 79 | //Remove the param from the main return string | |
| 80 | inputStr = inputStr.replace(/(location)\(.*\)(:.*)/i, "$1$2"); | |
| 81 | } | |
| 82 | ||
| 83 | //Save if it matches the location: tag or not | |
| 84 | var matches = inputStr.match(/(location:)(.*)/i); | |
| 85 | var url = inputStr.replace(/(location:)(.*)/i, "$2"); | |
| 86 | if(matches){ | |
| 87 | //Matched the URL, redirect the window | |
| 88 | window.location=url; | |
| 89 | }else{ | |
| 90 | //Match not found, update the content | |
| 91 | //console.log("Writing the data base to div: " + div_id); | |
| 92 | document.getElementById(div_id).innerHTML = data; | |
| 93 | } | |
| 94 | }else{ | |
| 95 | ||
| 96 | } | |
| 97 | } | |
| 98 | // ------------------------------------------------------------------------- // | |
| 99 | ||
| 100 | ||
| 101 | ||
| 102 | // ---------------- Toggle to hide and un-hide div areas ---------- // | |
| 103 | function toggleMessage(messageId) { | |
| 104 | var disp = document.getElementById(messageId).style.display; | |
| 105 | if ( disp == 'none' ) { | |
| 106 | this.ShowContent(messageId); | |
| 107 | } else { | |
| 108 | this.HideContent(messageId); | |
| 109 | } | |
| 110 | return false; | |
| 111 | } | |
| 112 | ||
| 113 | function HideContent(d) { | |
| 114 | if(d.length < 1) { return; } | |
| 115 | document.getElementById(d).style.display = "none"; | |
| 116 | } | |
| 117 | function ShowContent(d) { | |
| 118 | if(d.length < 1) { return; } | |
| 119 | document.getElementById(d).style.display = "block"; | |
| 120 | } | |
| 121 | // ---------------- Toggle to hide and un-hide div areas ---------- // | |
| 122 | ||
| 123 | ||
| 124 | ||
| 125 | // ---------------- Check and un-check all functions -------------- // | |
| 126 | //Set the default to not checked when a page first loads | |
| 127 | var setting_checkall = 'no'; | |
| 128 | ||
| 129 | function toggleCheckAll(field,checked){ | |
| 130 | //Verify if the checkbox was checked or not just in case the entire page wasn't reloaded after the last mass checkbox change | |
| 131 | if(checked == true){setting_checkall = 'no';} | |
| 132 | ||
| 133 | if(setting_checkall == 'no'){setting_checkall='yes';checkAll(field);} | |
| 134 | else{setting_checkall='no';uncheckAll(field);} | |
| 135 | } | |
| 136 | ||
| 137 | function checkAll(field) { | |
| 138 | if(field.length){ | |
| 139 | for (i = 0; i < field.length; i++) field[i].checked = true ; | |
| 140 | }else{ | |
| 141 | if(!field.checked) field.checked = true; | |
| 142 | } | |
| 143 | } | |
| 144 | ||
| 145 | function uncheckAll(field){ | |
| 146 | if(field.length){ | |
| 147 | for (i = 0; i < field.length; i++) field[i].checked = false ; | |
| 148 | }else{ | |
| 149 | if(field.checked) field.checked = false; | |
| 150 | } | |
| 151 | } | |
| 152 | // ---------------- Check and un-check all functions -------------- // | |
| 153 | ||
| 154 | ||
| 155 | ||
| 156 | // ---------------- Searchable drop down functions ---------------- // | |
| 157 | function dropdown_toggle(divname) { | |
| 158 | document.getElementById(divname).classList.toggle("show"); | |
| 159 | } | |
| 160 | ||
| 161 | function dropdown_search(divname,input) { | |
| 162 | var input, filter, ul, li, a, i; | |
| 163 | input = document.getElementById(input); | |
| 164 | filter = input.value.toUpperCase(); | |
| 165 | div = document.getElementById(divname); | |
| 166 | a = div.getElementsByTagName('a'); | |
| 167 | for (i = 0; i < a.length; i++) { | |
| 168 | if (a[i].innerHTML.toUpperCase().indexOf(filter) > -1) { | |
| 169 | a[i].style.display = ''; | |
| 170 | } else { | |
| 171 | a[i].style.display = 'none'; | |
| 172 | } | |
| 173 | } | |
| 174 | } | |
| 175 | // ---------------- Searchable drop down functions ---------------- // | |
| 176 | ||
| 177 | ||
| 178 | function auto_grow(element) { | |
| 179 | element.style.height = "5px"; | |
| 180 | element.style.height = (element.scrollHeight)+"px"; | |
| 181 | } | |
| 182 | ||
| 183 | ||
| 184 | ||
| 185 | //Form validation for the NBB approve & deny form ------------------------- | |
| 186 | function nbb_approve_deny_form_validation(report_id){ | |
| 187 | var verticals; | |
| 188 | ||
| 189 | //Get the list of regions that are in the multi-select dropdown | |
| 190 | var regions = Array.from(document.getElementById('user_selected_regions').selectedOptions).map(el=>el.value); | |
| 191 | ||
| 192 | // console.log("report id: " + report_id); | |
| 193 | // console.log("capacity action: " + document.getElementById('capacity_action').value); | |
| 194 | // console.log("utilization: " + document.getElementById('utilization_value').value); | |
| 195 | // console.log("current capacity: " + document.getElementById('current_capacity').value); | |
| 196 | // console.log("post capacity: " + document.getElementById('post_capacity').value); | |
| 197 | // console.log("Regions:" + regions); | |
| 198 | // console.log("note: " + document.getElementById('note').value); | |
| 199 | // console.log("custom_note: " + document.getElementById('custom_note').value); | |
| 200 | ||
| 201 | try{ | |
| 202 | // console.log("Length: " + document.approve_deny.vertical.length); | |
| 203 | if(document.approve_deny.vertical.length > 0){ | |
| 204 | for(var i=0; i<document.approve_deny.vertical.length; i++){ | |
| 205 | //Only save the values of the ones that are checked | |
| 206 | if(document.approve_deny.vertical[i].checked == true){ | |
| 207 | if(verticals){ | |
| 208 | verticals = verticals + "," + document.approve_deny.vertical[i].value; | |
| 209 | }else{ | |
| 210 | verticals = document.approve_deny.vertical[i].value; | |
| 211 | } | |
| 212 | // console.log("Checked: " + document.approve_deny.vertical[i].value); | |
| 213 | } | |
| 214 | } | |
| 215 | } | |
| 216 | } | |
| 217 | catch(err){ | |
| 218 | if (window.appToast) appToast({ message: String(err), type: 'error' }); | |
| 219 | else console.error(err); | |
| 220 | } | |
| 221 | ||
| 222 | document.getElementById('vertical').value = verticals; | |
| 223 | // console.log("Verticals: " + verticals); | |
| 224 | ||
| 225 | var note_error; | |
| 226 | if(document.getElementById('note').value == 'custom_note'){ | |
| 227 | if(document.getElementById('custom_note').value){ | |
| 228 | note_error = 'no'; | |
| 229 | }else{ | |
| 230 | note_error = 'yes'; | |
| 231 | } | |
| 232 | }else{ | |
| 233 | note_error = 'no'; | |
| 234 | } | |
| 235 | ||
| 236 | // console.log("Starting the form validation checks--------------------------------------"); | |
| 237 | if(document.getElementById('capacity_action').value == 'denied' && document.getElementById('note').value && note_error == 'no'){ | |
| 238 | //If denied they are required to put a note as to the reason why, if all is good then validation passed | |
| 239 | // console.log("Form validation section 1"); | |
| 240 | return true; | |
| 241 | }else if(document.getElementById('capacity_action').value == 'approved' && verticals && document.getElementById('post_capacity').value && regions && document.getElementById('vertical').value){ | |
| 242 | //If approved they are required to have verticals, post capacity, the notes are optional, if all is good then validation passed | |
| 243 | // console.log("Form validation section 2"); | |
| 244 | return true; | |
| 245 | }else{ | |
| 246 | //Validation failed, find out what is missing and display the error messages | |
| 247 | var form_errors = "<b>Please fix the following form errors</b><br>"; | |
| 248 | ||
| 249 | if(document.getElementById('capacity_action').value == 'denied'){ | |
| 250 | // console.log("Form validation section 3"); | |
| 251 | //If denied then we only need to display an error if they are missing the note/reason | |
| 252 | if(!document.getElementById('note').value){ | |
| 253 | form_errors += "- missing the note<br>"; | |
| 254 | } | |
| 255 | if(note_error == 'yes'){ | |
| 256 | form_errors += "- missing the custom note<br>"; | |
| 257 | } | |
| 258 | }else{ | |
| 259 | // console.log("Form validation section 4"); | |
| 260 | //If approved or not selected yet then we need to display all missing field values | |
| 261 | if(!document.getElementById('capacity_action').value){ | |
| 262 | form_errors += "- missing approve/deny status<br>"; | |
| 263 | } | |
| 264 | ||
| 265 | if(!verticals){ | |
| 266 | form_errors += "- missing the vertical(s)<br>"; | |
| 267 | } | |
| 268 | ||
| 269 | if(!document.getElementById('post_capacity').value){ | |
| 270 | form_errors += "- missing the post capacity<br>"; | |
| 271 | } | |
| 272 | ||
| 273 | if(!regions){ | |
| 274 | form_errors += "- missing the region(s)<br>"; | |
| 275 | } | |
| 276 | } | |
| 277 | ||
| 278 | error_msg(form_errors); | |
| 279 | ||
| 280 | return false; | |
| 281 | } | |
| 282 | } | |
| 283 | //------------------------------------------------------------------------- | |
| 284 | ||
| 285 | ||
| 286 | //Change all values to NBB weekly or monthly ------------------------------ | |
| 287 | function nbb_weekly_monthly_change(capacity, wc_p95, current_endstatecap, next_year_endstatecap, native_port, projected_15){ | |
| 288 | //Print all of the weekly or monthly values to the screens console that were passed in | |
| 289 | //console.log('capacity: ' + capacity); | |
| 290 | //console.log('utilization_value: ' + wc_p95); | |
| 291 | //console.log('current_endstatecap: ' + current_endstatecap); | |
| 292 | //console.log('next_year_endstatecap: ' + next_year_endstatecap); | |
| 293 | //console.log('native_port: ' + native_port); | |
| 294 | //console.log('projected_15: ' + projected_15); | |
| 295 | ||
| 296 | //Do the math to get the utilization percentage based on weekly or monthly data that was passed in | |
| 297 | var utilization_percent = Math.round((wc_p95 / capacity)*100); | |
| 298 | //console.log('utilization percentage: ' + utilization_percent ); | |
| 299 | ||
| 300 | //Update all document elements with the weekly or monthly values based on which radio button was selected | |
| 301 | document.getElementById('utilization_value').value=wc_p95; | |
| 302 | document.getElementById('utilization_percent').value=utilization_percent; | |
| 303 | document.getElementById('current_capacity').value=capacity; | |
| 304 | document.getElementById('post_capacity').value=current_endstatecap; | |
| 305 | ||
| 306 | //Update the view only data for current year, next year and projected 15 month data | |
| 307 | document.getElementById('current_year_por').innerHTML=current_endstatecap; | |
| 308 | document.getElementById('next_year_por').innerHTML=next_year_endstatecap; | |
| 309 | document.getElementById('projected_15_month').innerHTML=projected_15; | |
| 310 | } | |
| 311 | //------------------------------------------------------------------------- | |
| 312 | ||
| 313 | ||
| 314 | //Form validation for the CORE approve & deny form ------------------------ | |
| 315 | function core_approve_deny_form_validation(aggid){ | |
| 316 | var verticals; | |
| 317 | ||
| 318 | //Get the list of regions that are in the multi-select dropdown | |
| 319 | var regions = Array.from(document.getElementById('user_selected_regions').selectedOptions).map(el=>el.value); | |
| 320 | ||
| 321 | // console.log("AGG ID: " + aggid); | |
| 322 | // console.log("capacity action: " + document.getElementById('capacity_action').value); | |
| 323 | // console.log("post capacity: " + document.getElementById('post_capacity').value); | |
| 324 | // console.log("Regions:" + regions); | |
| 325 | // console.log("note: " + document.getElementById('note').value); | |
| 326 | // console.log("custom_note: " + document.getElementById('custom_note').value); | |
| 327 | ||
| 328 | try{ | |
| 329 | // console.log("Length: " + document.approve_deny.vertical.length); | |
| 330 | if(document.approve_deny.vertical.length > 0){ | |
| 331 | for(var i=0; i<document.approve_deny.vertical.length; i++){ | |
| 332 | //Only save the values of the ones that are checked | |
| 333 | if(document.approve_deny.vertical[i].checked == true){ | |
| 334 | if(verticals){ | |
| 335 | verticals = verticals + "," + document.approve_deny.vertical[i].value; | |
| 336 | }else{ | |
| 337 | verticals = document.approve_deny.vertical[i].value; | |
| 338 | } | |
| 339 | // console.log("Checked: " + document.approve_deny.vertical[i].value); | |
| 340 | } | |
| 341 | } | |
| 342 | } | |
| 343 | } | |
| 344 | catch(err){ | |
| 345 | if (window.appToast) appToast({ message: String(err), type: 'error' }); | |
| 346 | else console.error(err); | |
| 347 | } | |
| 348 | ||
| 349 | document.getElementById('vertical').value = verticals; | |
| 350 | // console.log("Verticals: " + verticals); | |
| 351 | ||
| 352 | var note_error; | |
| 353 | if(document.getElementById('note').value == 'custom_note'){ | |
| 354 | if(document.getElementById('custom_note').value){ | |
| 355 | note_error = 'no'; | |
| 356 | }else{ | |
| 357 | note_error = 'yes'; | |
| 358 | } | |
| 359 | }else{ | |
| 360 | note_error = 'no'; | |
| 361 | } | |
| 362 | ||
| 363 | // console.log("Starting the form validation checks--------------------------------------"); | |
| 364 | if(document.getElementById('capacity_action').value == 'denied' && document.getElementById('note').value && note_error == 'no'){ | |
| 365 | //If denied they are required to put a note as to the reason why, if all is good then validation passed | |
| 366 | // console.log("Form validation section 1"); | |
| 367 | return true; | |
| 368 | }else if(document.getElementById('capacity_action').value == 'approved' && verticals && document.getElementById('post_capacity').value && regions && document.getElementById('vertical').value && document.getElementById('current_build').value && document.getElementById('post_build').value && document.getElementById('state').value){ | |
| 369 | //If approved they are required to have verticals, post capacity, the notes are optional, if all is good then validation passed | |
| 370 | // console.log("Form validation section 2"); | |
| 371 | return true; | |
| 372 | }else{ | |
| 373 | //Validation failed, find out what is missing and display the error messages | |
| 374 | var form_errors = "<b>Please fix the following form errors</b><br>"; | |
| 375 | ||
| 376 | if(document.getElementById('capacity_action').value == 'denied'){ | |
| 377 | // console.log("Form validation section 3"); | |
| 378 | //If denied then we only need to display an error if they are missing the note/reason | |
| 379 | if(!document.getElementById('note').value){ | |
| 380 | form_errors += "- missing the note<br>"; | |
| 381 | } | |
| 382 | if(note_error == 'yes'){ | |
| 383 | form_errors += "- missing the custom note<br>"; | |
| 384 | } | |
| 385 | }else{ | |
| 386 | // console.log("Form validation section 4"); | |
| 387 | //If approved or not selected yet then we need to display all missing field values | |
| 388 | if(!document.getElementById('capacity_action').value){ | |
| 389 | form_errors += "- missing approve/deny status<br>"; | |
| 390 | } | |
| 391 | ||
| 392 | if(!document.getElementById('capacity_action').value){ | |
| 393 | form_errors += "- missing the state<br>"; | |
| 394 | } | |
| 395 | ||
| 396 | if(!document.getElementById('current_build').value){ | |
| 397 | form_errors += "- missing current build native 10Gbps/100Gbps selection<br>"; | |
| 398 | } | |
| 399 | ||
| 400 | if(!document.getElementById('post_build').value){ | |
| 401 | form_errors += "- missing post build native 10Gbps/100Gbps selection<br>"; | |
| 402 | } | |
| 403 | ||
| 404 | if(!verticals){ | |
| 405 | form_errors += "- missing the vertical(s)<br>"; | |
| 406 | } | |
| 407 | ||
| 408 | if(!document.getElementById('post_capacity').value){ | |
| 409 | form_errors += "- missing the post capacity<br>"; | |
| 410 | } | |
| 411 | ||
| 412 | if(!regions){ | |
| 413 | form_errors += "- missing the region(s)<br>"; | |
| 414 | } | |
| 415 | } | |
| 416 | ||
| 417 | error_msg(form_errors); | |
| 418 | ||
| 419 | return false; | |
| 420 | } | |
| 421 | } | |
| 422 | //------------------------------------------------------------------------- | |
| 423 | ||
| 424 | ||
| 425 | //Feature to hide or show parts of the form ------------------------------- | |
| 426 | function hide_divs(div){ | |
| 427 | var elms = document.getElementsByName(div); | |
| 428 | for(var i = 0; i < elms.length; i++){ | |
| 429 | elms[i].style.display='none'; | |
| 430 | } | |
| 431 | } | |
| 432 | function show_divs(div){ | |
| 433 | var elms = document.getElementsByName(div); | |
| 434 | for(var i = 0; i < elms.length; i++){ | |
| 435 | elms[i].style.display='block'; | |
| 436 | } | |
| 437 | } | |
| 438 | //------------------------------------------------------------------------- |