1(function ($, Drupal) { 2 $(document).ready(function () { 3 if($('.portal-page').length > 0){ 4 var countdownTime = 60; 5 var countdownInterval; 6 7 // Date and time block 8 $('.hours_block .hours_block_header p').click(function(){ 9 $(this).closest('.hours_block').toggleClass('active'); 10 }) 11 12 $('.switch').click(function(){ 13 $(this).toggleClass('active'); 14 }) 15 16 // Content change, sync input and preview data 17 $('#centre_video').change(function() { 18 $('#centre_video_iframe').attr('src', $(this).val()); 19 }); 20 21 $('#centre_first_nation_name').change(function() { 22 const first_nation = $('#centre_first_nation_name').val(); 23 const last_nation = $('#centre_last_nation_name').val(); 24 const last_nation_final = (last_nation == '' ? "" : (', ' + last_nation)); 25 26 if(first_nation !== '' || last_nation !== ''){ 27 $('#nation_name_div').removeClass('force_hidden'); 28 $('#nation_name').text(first_nation + last_nation_final); 29 }else{ 30 $('#nation_name_div').addClass('force_hidden'); 31 } 32 }); 33 34 $('#centre_last_nation_name').change(function() { 35 const first_nation = $('#centre_first_nation_name').val(); 36 const last_nation = $('#centre_last_nation_name').val(); 37 const last_nation_final = (last_nation == '' ? "" : (', ' + last_nation)); 38 39 if(first_nation !== '' || last_nation !== ''){ 40 $('#nation_name_div').removeClass('force_hidden'); 41 $('#nation_name').text(first_nation + last_nation_final); 42 }else{ 43 $('#nation_name_div').addClass('force_hidden'); 44 } 45 }); 46 47 document.querySelectorAll('input[name="nqf_rating"]').forEach(radio => { 48 radio.addEventListener('change', (event) => { 49 const selectedValue = event.target.value; 50 if(selectedValue !== "0"){ 51 const dataLabel = event.target.dataset.label; 52 $('#centre_rating').removeClass('force_hidden'); 53 $('#centre_rating').text('NQF Rating: ' + dataLabel); 54 }else{ 55 $('#centre_rating').addClass('force_hidden'); 56 } 57 }); 58 }); 59 60 $('#centre_phone').change(function() { 61 $('#centre_phone_preview').text($(this).val()); 62 }); 63 64 $('#centre_email').change(function() { 65 $('#centre_email_preview').text($(this).val()); 66 }); 67 68 $('#centre_website').change(function() { 69 var website = $(this).val().replace(/^https?:\/\//, ''); 70 $('#centre_website_preview').text(website); 71 }); 72 73 $('#centre_facebook').change(function() { 74 $('#centre_facebook_preview').attr('href', $(this).val()); 75 }); 76 77 $('#centre_instagram').change(function() { 78 $('#centre_instagram_preview').attr('href', $(this).val()); 79 }); 80 81 $('#centre_linkedin').change(function() { 82 $('#centre_linkedin_preview').attr('href', $(this).val()); 83 }); 84 85 $('#centre_youtube').change(function() { 86 $('#centre_youtube_preview').attr('href', $(this).val()); 87 }); 88 89 $('#centre_tiktok').change(function() { 90 $('#centre_tiktok_preview').attr('href', $(this).val()); 91 }); 92 93 $('#fee_year_edit').change(function() { 94 $('#fee_year_preview').text($(this).val()); 95 }); 96 97 // Use token to get current/origin centre ID 98 const editing = getUrlParameter('editing'); 99 const token = getUrlParameter('token'); 100 const savedToken = localStorage.getItem('token'); 101 102 if (editing && token && savedToken && token === savedToken) { 103 $('.step-content').addClass('hidden'); 104 $('#portal-editing-target').removeClass('hidden'); 105 $('.step').removeClass('active'); 106 $('#portal-editing').addClass('active'); 107 $('.step').each(function(){ 108 if ($(this).attr('id') === 'portal-editing') { 109 return false; 110 } 111 $(this).addClass('checked'); 112 }); 113 } 114 115 // Use service approval number to get centre ID 116 $('#check_san').on('click', function (e) { 117 e.preventDefault(); 118 let serviceApprovalNumber = $('#service_approval_number').val(); 119 120 if (serviceApprovalNumber) { 121 $.ajax({ 122 url: Drupal.url('ck_form_affiliate/get-centre-id'), 123 type: 'POST', 124 data: { 125 service_approval_number: serviceApprovalNumber 126 }, 127 dataType: 'json', 128 success: function (response) { 129 if (response.success) { 130 if(response.centre_status && response.centre_status === "Branch"){ 131 $('.ck_message').text("*You don't have permission to edit this center"); 132 }else{ 133 $('.ck_message').text(''); 134 var centreId = response.node_id; 135 var centreManagerName = response.centre_manager_name; 136 var centreManagerEmail = response.centre_manager_email; 137 138 localStorage.setItem('centreId', centreId); 139 localStorage.setItem('centreManagerName', centreManagerName); 140 localStorage.setItem('centreManagerEmail', centreManagerEmail); 141 142 generateVerificationSend(centreManagerName, centreManagerEmail, centreId); 143 144 $('#check_san_next').click(); 145 } 146 } else { 147 $('.ck_message').text("*Oops! We couldn't find a center. Please double-check your Service Approval Number and try again."); 148 } 149 }, 150 error: function (jqXHR, textStatus, errorThrown) { 151 $('.ck_message').text("*Oops! Something went wrong with the request. Please reach out to the website administrator for assistance."); 152 } 153 }); 154 } else { 155 $('.ck_message').text('*Please provide the Service Approval Number.'); 156 } 157 }); 158 159 $('.resend').click(function(){ 160 // let centreId = localStorage.getItem('centreId'); 161 let centreManagerName = localStorage.getItem('centreManagerName'); 162 let centreManagerEmail = localStorage.getItem('centreManagerEmail'); 163 164 generateVerificationSend(centreManagerName, centreManagerEmail); 165 }) 166 167 function generateVerificationSend(centreManagerName, centreManagerEmail) { 168 var data = { 169 centreManagerName: centreManagerName 170 }; 171 172 // Checked 173 $.ajax({ 174 url: '/api/send-verification', 175 method: 'POST', 176 contentType: 'application/json', 177 data: JSON.stringify({ 178 phoneNumber: "", 179 emailAddress: centreManagerEmail, 180 template: "template_0", 181 data: data, 182 subject: "Verification number from C&K" 183 }), 184 success: function (response) { 185 }, 186 error: function (jqXHR, textStatus, errorThrown) { 187 } 188 }); 189 190 startCountdown(); 191 } 192 193 function startCountdown() { 194 var countdownElement = document.getElementById('count_down'); 195 var resendButton = document.querySelector('.resend'); 196 197 resendButton.style.pointerEvents = 'none'; 198 resendButton.style.opacity = '0.5'; 199 200 countdownInterval = setInterval(function() { 201 countdownTime--; 202 countdownElement.textContent = '(' + countdownTime + 's)'; 203 204 if (countdownTime <= 0) { 205 clearInterval(countdownInterval); 206 countdownElement.textContent = ''; 207 resendButton.style.pointerEvents = 'auto'; 208 resendButton.style.opacity = '1'; 209 countdownTime = 60; 210 } 211 }, 1000); 212 } 213 214 // Check verification code 215 $('#san_verify_code').on('click', function (e) { 216 e.preventDefault(); 217 218 let verificationCode = $('#sav_verification_num').val(); 219 let targetCentreId = localStorage.getItem('centreId'); 220 let centreManagerEmail = localStorage.getItem('centreManagerEmail'); 221 222 if (!verificationCode) { 223 $('.ck_message_2').text('*Please provide the Verification Code.'); 224 return; 225 } 226 227 if (!targetCentreId) { 228 $('.ck_message_2').text('*Missing target centre ID.'); 229 return; 230 } 231 232 if (!centreManagerEmail) { 233 $('.ck_message_2').text('*Missing centre manager email.'); 234 return; 235 } 236 237 $('#san_verify_code').addClass('disabled').text('Loading...'); 238 $('.ck_message_2').text(''); 239 240 let currentUrl = window.location.href; 241 let url = new URL(currentUrl); 242 let urlWithoutParams = url.origin + url.pathname; 243 244 $.ajax({ 245 url: '/api/check-verification', 246 method: 'POST', 247 contentType: 'application/json', 248 data: JSON.stringify({ 249 emailAddress: centreManagerEmail, 250 code: verificationCode 251 }), 252 success: function (response) { 253 if (response.status === true) { 254 $.ajax({ 255 url: '/duplicate-centre', 256 method: 'POST', 257 data: { 258 targetCentreId: targetCentreId 259 }, 260 success: function (response) { 261 if (response.success) { 262 var newCentreId = response.new_node_id; 263 localStorage.setItem('newCentreId', newCentreId); 264 var token = generateToken(20); 265 localStorage.setItem('token', token); 266 window.location.href = urlWithoutParams + '?editing=' + newCentreId + '&origin=' + targetCentreId + '&token='
266+ token; 267 } else { 268 $('.ck_message_2').text('Error: ' + response.message); 269 } 270 }, 271 error: function (response, jqXHR, textStatus, errorThrown) { 272 $('.ck_message_2').text('AJAX request failed: ' + textStatus); 273 }, 274 complete: function () { 275 $('#san_verify_code').removeClass('disabled'); 276 $('#san_verify_code').text('Submit'); 277 } 278 }); 279 } else { 280 $('.ck_message_2').text("*" + (response.message || "Verification failed")); 281 $('#san_verify_code').removeClass('disabled').text('Submit'); 282 } 283 }, 284 error: function (jqXHR, textStatus, errorThrown) { 285 $('.ck_message_2').text('Verification API error: ' + textStatus); 286 $('#san_verify_code').removeClass('disabled').text('Submit'); 287 } 288 }); 289 }); 290 291 // Preview content 292 const checkboxes = document.querySelectorAll('.inclusions_select_option input[type="checkbox"]'); 293 $('.lets_preview').click(function(){ 294 $('.centre_details').removeClass('edit').addClass('preview'); 295 checkboxes.forEach(function(checkbox) { 296 if (!checkbox.checked) { 297 checkbox.closest('.inclusions_select_option').classList.add('hidden'); 298 } 299 }); 300 301 const body = $('#ck_editor + .ck-editor .ck-content').text(); 302 const field_centre_video_url = $('#centre_video').val(); 303 const field_centre_phone = $('#centre_phone').val(); 304 const field_centre_email = $('#centre_email').val(); 305 const field_centre_website = $('#centre_website').val(); 306 // const field_general_information = $('#ck_editor_2 + .ck-editor .ck-content').text(); 307 const field_curriculum = $('#ck_editor_3 + .ck-editor .ck-content').text(); 308 const field_fees = $('#ck_editor_4 + .ck-editor .ck-content').text(); 309 const field_centre_inclusion_id = []; 310 const centre_inclusion_checkboxes = document.querySelectorAll('input[name="centre_inclusion[]"]:checked'); 311 centre_inclusion_checkboxes.forEach((checkbox) => { 312 field_centre_inclusion_id.push(checkbox.value.replace('centre_inclusion_', '')); 313 }); 314 315 const centre_facebook = $('#centre_facebook').val(); 316 const centre_instagram = $('#centre_instagram').val(); 317 const centre_linkedin = $('#centre_linkedin').val(); 318 const centre_youtube = $('#centre_youtube').val(); 319 const centre_tiktok = $('#centre_tiktok').val(); 320 321 !centre_facebook ? $('#centre_facebook_preview').addClass('force_hidden') : $('#centre_facebook_preview').removeClass('force_hidden'); 322 !centre_instagram ? $('#centre_instagram_preview').addClass('force_hidden') : $('#centre_instagram_preview').removeClass('force_hidden'); 323 !centre_linkedin ? $('#centre_linkedin_preview').addClass('force_hidden') : $('#centre_linkedin_preview').removeClass('force_hidden'); 324 !centre_youtube ? $('#centre_youtube_preview').addClass('force_hidden') : $('#centre_youtube_preview').removeClass('force_hidden'); 325 !centre_tiktok ? $('#centre_tiktok_preview').addClass('force_hidden') : $('#centre_tiktok_preview').removeClass('force_hidden'); 326 327 !body && $('.body_preview').addClass('hidden'); 328 !field_centre_video_url && $('.centre_video_preview').addClass('force_hidden'); 329 !field_centre_phone && $('.icon_phone').addClass('force_hidden'); 330 !field_centre_email && $('.icon_email').addClass('force_hidden'); 331 !field_centre_website && $('.icon_website').addClass('force_hidden'); 332 !field_centre_phone && !field_centre_email && !field_centre_website && $('.contact_section').addClass('force_hidden'); 333 // !field_general_information && $('#general_info').addClass('force_hidden') && $('p[data-target="general_info"]').addClass('force_hidden'); 334 !field_curriculum && $('#curriculum').addClass('force_hidden') && $('p[data-target="curriculum"]').addClass('force_hidden'); 335 336 field_centre_inclusion_id.length === 0 && $('#inclusions').addClass('force_hidden') && $('p[data-target="inclusions"]').addClass('force_hidden'); 337 338 // Fee 339 !field_fees && $('#fees').find('.ck-editor').addClass('force_hidden') 340 let fees_tabel = false; 341 $('.centre_fee_div').each(function() { 342 if ($(this).find("input").val()) { 343 $(this).removeClass('force_hidden'); 344 fees_tabel = true; 345 } else { 346 $(this).addClass('force_hidden'); 347 } 348 }); 349 !field_fees && !fees_tabel && $('#fees').addClass('force_hidden') && $('p[data-target="fees"]').addClass('force_hidden'); 350 351 352 const checkedRadio = document.querySelector('input[name="enrol_method"]:checked'); 353 const field_enrollment_mode = checkedRadio ? checkedRadio.value : null; 354 if(field_enrollment_mode == 'website'){ 355 const field_enrollment_url = $('#enrol_website_url').val(); 356 $('#temp_enrol').attr('href', field_enrollment_url); 357 } 358 359 if(field_enrollment_mode == 'email'){ 360 const field_enrollment_email = $('#enrol_email_url').val(); 361 $('#temp_enrol').attr('href', 'mailto:' + field_enrollment_email); 362 } 363 364 if(field_enrollment_mode == 'webform'){ 365 $('#temp_enrol').attr('href', '/enrol'); 366 } 367 368 const field_images_in_editor = $('#album_items').val(); 369 if(field_images_in_editor){ 370 jQuery('#centre_album_div_preview').slick('unslick'); 371 $('#centre_album_div_preview').html(field_images_in_editor); 372 initializeSlick(); 373 }else{ 374 $('#centre_gallery_div').addClass('force_hidden'); 375 } 376 377 let programs = []; 378 var days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']; 379 if($('.program_information:not(.hidden)').length > 0){ 380 $('p[data-target="programs"]').removeClass('hidden'); 381 $('.program_information:not(.hidden)').each(function(){ 382 const programId = $(this).attr('id').split('_')[1]; 383 const program = {}; 384 program.field_program_id = programId; 385 program.field_title = $('#program_name_' + programId).val(); 386 387 const programStartDate = $('#program_date_start_input_' + programId).val(); 388 const programEndDate = $('#program_date_end_input_' + programId).val(); 389 program.field_program_start_date = programStartDate ? formatDate(programStartDate) : ""; 390 program.field_program_end_date = programEndDate ? formatDate(programEndDate) : ""; 391 const program_content = $('#ck_editor_program_' + programId + ' + .ck-editor .ck-content').html();
392 const program_content_raw = $('#ck_editor_program_' + programId + ' + .ck-editor .ck-content').text(); 393 program.field_content = (program_content_raw ? program_content.replaceAll(' ', ' ') : ''); 394 program.field_weekly_time_chunk = {}; 395 396 days.forEach(day => { 397 program.field_weekly_time_chunk['field_alternate_' + day] = ($('#program_time_' + day + '_extend_switch_' + programId).hasClass('active') ? '1' : '0'); 398 399 const startDay = $('#program_time_' + day + '_start_input_' + programId).val(); 400 const endDay = $('#program_time_' + day + '_end_input_' + programId).val(); 401 if(startDay && endDay){ 402 program.field_weekly_time_chunk['field_' + day + '_opening_hours'] = formatTime2(startDay) + ' - ' + formatTime2(endDay); 403 }else{ 404 program.field_weekly_time_chunk['field_' + day + '_opening_hours'] = null; 405 } 406 407 const extendStartDay = $('#program_time_' + day + '_extend_start_input_' + programId).val(); 408 const extendEndDay = $('#program_time_' + day + '_extend_end_input_' + programId).val(); 409 if(extendStartDay && extendEndDay){ 410 program.field_weekly_time_chunk['field_' + day + '_extended_hours'] = formatTime2(extendStartDay) + ' - ' + formatTime2(extendEndDay); 411 }else{ 412 program.field_weekly_time_chunk['field_' + day + '_extended_hours'] = null; 413 } 414 415 }); 416 417 programs.push(program); 418 }) 419 }else{ 420 $('p[data-target="programs"]').addClass('hidden'); 421 } 422 423 programs.length > 0 && buildProgramsPreview(programs); 424 425 // !field_general_information && 426 !field_curriculum 427 && !field_fees 428 && field_centre_inclusion_id.length === 0 429 && programs.length === 0 430 && $('.centre_info_tabs').addClass('force_hidden'); 431 432 // $('.edit_fee_desc').each(function() { 433 // const val = $(this).val(); 434 // if (val) { 435 // $(this).siblings('.fee_desc_real').text(val); 436 // $(this).siblings('.fee_desc_real').css('margin-top', '16px'); 437 // } else { 438 // $(this).siblings('.fee_desc_real').text(""); 439 // $(this).siblings('.fee_desc_real').css('margin-top', '0px'); 440 // } 441 // }); 442 443 $('.centre_tabs_inactive_item').find('.tab_title').removeClass('active'); 444 $('.centre_tabs_inactive_item').find('.tab_title:not(.force_hidden):first').addClass('active'); 445 $('.centre_tabs_active_item').find('.tab_title').removeClass('active'); 446 $('.centre_tabs_active_item').find('.tab_title:not(.force_hidden):first').addClass('active'); 447 $('.tabs_content').find('.centre_tabs_tab').removeClass('active'); 448 $('.tabs_content').find('.centre_tabs_tab:not(.force_hidden):first').addClass('active'); 449 450 const centre_latitude = $('#centre_latitude').text(); 451 const centre_longitude = $('#centre_longitude').text(); 452 if(centre_latitude && centre_longitude){initMapCentre2(centre_latitude, centre_longitude)} 453 454 }) 455 456 // Edit content 457 $('.lets_edit').click(function(){ 458 $('.lets_submit').removeClass('disabled'); 459 460 $('.centre_details').removeClass('preview').addClass('edit'); 461 checkboxes.forEach(function(checkbox) { 462 if (!checkbox.checked) { 463 checkbox.closest('.inclusions_select_option').classList.remove('hidden'); 464 } 465 }); 466 467 $('.body_preview').removeClass('hidden'); 468 $('.centre_video_preview').removeClass('force_hidden'); 469 $('.icon_phone').removeClass('force_hidden'); 470 $('.icon_email').removeClass('force_hidden'); 471 $('.icon_website').removeClass('force_hidden'); 472 $('.contact_section').removeClass('force_hidden'); 473 $('#general_info').removeClass('force_hidden') && $('p[data-target="general_info"]').removeClass('force_hidden'); 474 $('#curriculum').removeClass('force_hidden') && $('p[data-target="curriculum"]').removeClass('force_hidden'); 475 $('#fees').removeClass('force_hidden') && $('p[data-target="fees"]').removeClass('force_hidden'); 476 $('#inclusions').removeClass('force_hidden') && $('p[data-target="inclusions"]').removeClass('force_hidden'); 477 $('.centre_info_tabs').removeClass('force_hidden'); 478 $('#centre_gallery_div').removeClass('force_hidden'); 479 $('p[data-target="programs"]').removeClass('hidden'); 480 481 $('#fees').find('.ck-editor').removeClass('force_hidden') 482 483 $('.centre_fee_div').each(function() { 484 $(this).removeClass('force_hidden'); 485 }); 486 487 }) 488 489 490 function deepSortObject(obj) { 491 if (obj === null || typeof obj !== "object") return obj; 492 if (Array.isArray(obj)) return obj.map(deepSortObject); 493 return Object.keys(obj).sort().reduce((acc, key) => { 494 acc[key] = deepSortObject(obj[key]); 495 return acc; 496 }, {}); 497 } 498 499 function normalizeField(key, value, data, newContent) { 500 switch (key) { 501 case "field_address": 502 const oldAddr = data.field_address_raw || {}; 503 const newAddr = { 504 address_line1: newContent.centre_location_address_line1 || "", 505 locality: newContent.centre_location_locality || "", 506 administrative_area: newContent.centre_location_administrative_area || "", 507 postal_code: newContent.centre_location_postal_code || "" 508 }; 509 return newAddr; 510 511 case "centre_fees": 512 if (Array.isArray(value)) { 513 return value.reduce((acc, item) => { 514 acc[item.id] = item.amount; 515 return acc; 516 }, {}); 517 } 518 return value; 519 520 case "field_affiliate_programs": 521 if (Array.isArray(value)) { 522 return value 523 .map(item => { 524 const normalized = deepSortObject(item); 525 526 normalized.field_content = normalizeEmpty( 527 normalized.field_content 528 ); 529 530 if(normalized.field_program_id){ 531 normalized.field_program_id = normalizeProgramId( 532 normalized.field_program_id 533 ); 534 } 535 536 if (normalized.field_weekly_time_chunk) { 537 Object.keys(normalized.field_weekly_time_chunk).forEac
537h(key => { 538 normalized.field_weekly_time_chunk[key] = 539 normalizeTimeRange( 540 normalized.field_weekly_time_chunk[key] 541 ); 542 }); 543 } 544 545 return normalized; 546 }) 547 .sort((a, b) => 548 a.field_program_id.localeCompare(b.field_program_id) 549 ); 550 } 551 return value; 552 553 554 case "body": 555 if (typeof value === "string") { 556 return value 557 .replace(/ /g, '') 558 .replace(/\s+/g, '') 559 .trim(); 560 } 561 return value; 562 563 default: 564 return value; 565 } 566 } 567 568 function normalizeProgramId(id) { 569 return String(id) 570 .trim() 571 .toLowerCase() 572 .replace(/[\s_-]+/g, "-"); 573 } 574 575 function normalizeEmpty(value) { 576 if (value == null) return null; 577 if (typeof value === 'string' && value.trim() === '') return null; 578 return value; 579 } 580 581 function normalizeTimeRange(value) { 582 if (typeof value !== 'string') return value; 583 584 return value 585 .trim() 586 .replace(/\s+/g, ' ') 587 .replace(/\b0(\d:\d{2})/g, '$1'); 588 } 589 590 591 function isEqual(val1, val2) { 592 if ((val1 === null && val2 === "") || (val1 === "" && val2 === null)) return true; 593 594 if (Array.isArray(val1) && Array.isArray(val2)) { 595 if (val1.length !== val2.length) return false; 596 return val1.every((item, idx) => isEqual(item, val2[idx])); 597 } 598 599 if (typeof val1 === "object" && val1 !== null && 600 typeof val2 === "object" && val2 !== null) { 601 const keys1 = Object.keys(val1); 602 const keys2 = Object.keys(val2); 603 if (keys1.length !== keys2.length) return false; 604 return keys1.every(key => isEqual(val1[key], val2[key])); 605 } 606 607 return val1 === val2; 608 } 609 610 function getChangedFields(data, newContent) { 611 const changedFields = []; 612 613 for (const key in newContent) { 614 if (!(key in data)) continue; 615 616 const oldVal = normalizeField(key, data[key], data, newContent); 617 const newVal = normalizeField(key, newContent[key], data, newContent); 618 619 if (!isEqual(oldVal, newVal)) { 620 changedFields.push(key); 621 } 622 } 623 624 return changedFields; 625 } 626 627 628
629 // Submit content 630 $('.lets_submit').click(function(){ 631 $(this).addClass('disabled'); 632 const body = $('.body_preview .ck-content').html(); 633 let body_content = (body.replaceAll(' ', ' ')); 634 if (body_content === '<p><br data-cke-filler="true"></p>') { 635 body_content = ""; 636 } 637 638 // const field_general_information_raw = $('#ck_editor_2 + .ck-editor .ck-content').text(); 639 // const field_general_information = $('#ck_editor_2 + .ck-editor .ck-content').html(); 640 // const field_general_information_content = (field_general_information_raw ? field_general_information.replaceAll(' ', ' ') : ''); 641 const field_curriculum_raw = $('#ck_editor_3 + .ck-editor .ck-content').text(); 642 const field_curriculum = $('#ck_editor_3 + .ck-editor .ck-content').html(); 643 let field_curriculum_content = (field_curriculum_raw ? field_curriculum.replaceAll(' ', ' ') : ''); 644 if (field_curriculum_content === '<p><br data-cke-filler="true"></p>') { 645 field_curriculum_content = ""; 646 } 647 648 const field_fees_raw = $('#ck_editor_4 + .ck-editor .ck-content').text(); 649 const field_fees = $('#ck_editor_4 + .ck-editor .ck-content').html(); 650 let field_fees_content = (field_fees_raw ? field_fees.replaceAll(' ', ' ') : ''); 651 if (field_fees_content === '<p><br data-cke-filler="true"></p>') { 652 field_fees_content = ""; 653 } 654 655 const field_centre_video_url = $('#centre_video').val(); 656 const field_centre_phone = $('#centre_phone').val(); 657 const field_centre_email = $('#centre_email').val(); 658 const field_centre_website = $('#centre_website').val(); 659 const checkedRadio = document.querySelector('input[name="enrol_method"]:checked'); 660 const field_enrollment_mode = checkedRadio ? checkedRadio.value : null; 661 const field_enrollment_url = $('#enrol_website_url').val(); 662 const field_enrollment_email = $('#enrol_email_url').val(); 663 const field_give_consent = document.querySelector('input[name="consent"]:checked').value; 664 const centre_facebook = $('#centre_facebook').val(); 665 const centre_instagram = $('#centre_instagram').val(); 666 const centre_linkedin = $('#centre_linkedin').val(); 667 const centre_youtube = $('#centre_youtube').val(); 668 const centre_tiktok = $('#centre_tiktok').val(); 669 const field_centre_inclusion_id = []; 670 const centre_inclusion_checkboxes = document.querySelectorAll('input[name="centre_inclusion[]"]:checked'); 671 centre_inclusion_checkboxes.forEach((checkbox) => { 672 field_centre_inclusion_id.push(checkbox.value.replace('centre_inclusion_', '')); 673 }); 674 675 const ratingRadio = document.querySelector('input[name="nqf_rating"]:checked'); 676 let centre_nqf_rating = null; 677 if (ratingRadio && ratingRadio.value !== '0') { 678 centre_nqf_rating = ratingRadio.value; 679 } 680 681 let field_image_in_editor = ""; 682 if($('#centre_featured_image_preview img').attr('src') !== ""){ 683 field_image_in_editor = $('#centre_featured_image_preview').html(); 684 } 685 const field_images_in_editor = $('#album_items').val(); 686 687 const centre_location_address_line1 = $('#centre_location_address_line1').text(); 688 const centre_location_administrative_area = $('#centre_location_administrative_area').text(); 689 const centre_location_locality = $('#centre_location_locality').text(); 690 const centre_location_postal_code = $('#centre_location_postal_code').text(); 691 const field_fee_year = $('#fee_year_preview').text(); 692 693 const field_latitude = $('#centre_latitude').text(); 694 const field_longitude = $('#centre_longitude').text(); 695 696 const field_given_name = $('#centre_first_nation_name').val(); 697 const field_family_name = $('#centre_last_nation_name').val(); 698 699 let programs = []; 700 var days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']; 701 if($('.program_information:not(.hidden)').length > 0){ 702 $('.program_information:not(.hidden)').each(function(){ 703 const programId = $(this).attr('id').split('_')[1]; 704 705 const program = {}; 706 program.field_program_id = programId; 707 program.field_title = $('#program_name_' + programId).val(); 708 program.field_program_start_date = $('#program_date_start_input_' + programId).val(); 709 program.field_program_end_date = $('#program_date_end_input_' + programId).val(); 710 const program_content = $('#ck_editor_program_' + programId + ' + .ck-editor .ck-content').html(); 711 program.field_content = program_content.replaceAll(' ', ' '); 712 program.field_content = program_content.replaceAll('<p><br data-cke-filler=\"true\"></p>', ''); 713 program.field_weekly_time_chunk = {}; 714 715 days.forEach(day => { 716 program.field_weekly_time_chunk['field_alternate_' + day] = ($('#program_time_' + day + '_extend_switch_' + programId).hasClass('active') ? '1' : '0'); 717 718 const startDay = $('#program_time_' + day + '_start_input_' + programId).val(); 719 const endDay = $('#program_time_' + day + '_end_input_' + programId).val(); 720 if(startDay && endDay){ 721 program.field_weekly_time_chunk['field_' + day + '_opening_hours'] = formatTime2(startDay) + ' - ' + formatTime2(endDay); 722 }else{ 723 program.field_weekly_time_chunk['field_' + day + '_opening_hours'] = null; 724 } 725 726 const extendStartDay = $('#program_time_' + day + '_extend_start_input_' + programId).val(); 727 const extendEndDay = $('#program_time_' + day + '_extend_end_input_' + programId).val(); 728 if(extendStartDay && extendEndDay){ 729 program.field_weekly_time_chunk['field_' + day + '_extended_hours'] = formatTime2(extendStartDay) + ' - ' + formatTime2(extendEndDay); 730 }else{ 731 program.field_weekly_time_chunk['field_' + day + '_extended_hours'] = null; 732 } 733 734 }); 735 736 programs.push(program); 737 }) 738 } 739 740 let centreFees = []; 741 if($('.centre_fee_div_toadd').length > 0){ 742 $('.centre_fee_div_toadd').each(function(){ 743 const feeId = $(this).attr('id').split('_')[1]; 744 const feeAmount = $('#fee_amount_' + feeId).val(); 745 const fee = {}; 746 fee.id = 'field_fee_' + feeId; 747 fee.amount = feeAmount; 748 feeAmount && centreFees.push(fee); 749 }); 750 } 751 752 let field_brochure_url = $('#brochure_preview a').attr('href') || ""; 753 let field_statement_of_fees_url = $('#fee_statement_preview a').attr('href') || ""; 754 755 if (field_brochure_url === '#') field_brochure_url = ''; 756 if (field_statement_of_fees_url === '#') field_statement_of_fees_url = ''; 757 758 const newContent = { 759 "body": body_content, 760 "centre_fees": centreFees, 761 "field_centre_video_url": field_centre_video_url, 762 // "field_general_information": field_general_information_content, 763 "field_curriculum": field_curriculum_content, 764 "field_fees": field_fees_content, 765 "field_centre_inclusion_id": field_centre_inclusion_id, 766 "field_centre_phone": field_centre_phone, 767 "field_centre_email": field_centre_email, 768 "field_centre_website": field_centre_website, 769 "field_enrollment_mode": field_enrollment_mode, 770 "field_enrollment_url": field_enrollment_url, 771 "field_enrollment_email": field_enrollment_email, 772 "field_give_consent": field_give_consent, 773 "field_image_in_editor": field_image_in_editor, 774 "field_images_in_editor": field_images_in_editor, 775 "field_centre_social_facebook": centre_facebook, 776 "field_centre_social_instagram": centre_instagram, 777 "field_centre_social_linkedin": centre_linkedin, 778 "field_centre_social_tiktok": centre_tiktok, 779 "field_centre_social_youtube": centre_youtube, 780 "centre_location_address_line1": centre_location_address_line1, 781 "centre_location_administrative_area": centre_location_administrative_area, 782 "centre_location_locality": centre_location_locality, 783 "centre_location_postal_code": centre_location_postal_code, 784 "field_address": "", 785 "field_latitude": field_latitude, 786 "field_longitude": field_longitude, 787 "field_affiliate_programs": programs, 788 "field_given_name": field_given_name, 789 "field_family_name": field_family_name, 790 "field_center_nqfrating_id": centre_nqf_rating, 791 "field_brochure_url": field_brochure_url, 792 "field_statement_of_fees_url": field_statement_of_fees_url, 793 "field_fee_year" : field_fee_year, 794 795 field_nation_name: (field_given_name !== "" || field_family_name !== "") 796 ? { 797 first_nation_name: field_given_name, 798 last_nation_name: field_family_name, 799 } 800 : null 801 }; 802 803 const originData = JSON.parse(localStorage.getItem('originDataSet')); 804 const changed = getChangedFields(originData, newContent); 805 806 // console.log(originData); 807 // console.log(newContent); 808 809 newContent.field_has_changed = changed; 810 811 if(editing){ 812 let centreManagerName = localStorage.getItem('centreManagerName'); 813 let centreManagerEmail = localStorage.getItem('centreManagerEmail'); 814 let newCentreId = localStorage.getItem('newCentreId'); 815 let centreId = localStorage.getItem('centreId'); 816 let centreName = $('#title').text(); 817 818 let currentUrl = window.location.href; 819 let url = new URL(currentUrl); 820 let urlWithoutParams = url.origin; 821 822 const currentHost = window.location.host; 823 const emailContent = { 824 "CentreManagerName": 'C&K manager', 825 "CentreManagerEmail": currentHost.includes('ck.localhost:8000') ? '[email protected]' : '[email protected]', 826 "CentreId": centreId, 827 "CentreName": centreName, 828 "CentreLink": urlWithoutParams + '/node/' + centreId, 829 "NewCentreLink": urlWithoutParams + '/node/' + newCentreId, 830 }; 831 832 // Checked 833 $.ajax({ 834 url: '/api/send-verification', 835 method: 'POST', 836 contentType: 'application/json', 837 data: JSON.stringify({ 838 emailAddress: emailContent.CentreManagerEmail, 839 template: "template_2", 840 data: emailContent 841 }), 842 success: function (response) { 843 }, 844 error: function (jqXHR, textStatus, errorThrown) { 845 } 846 }); 847 848 849 $.ajax({
850 url: '/update-centre/' + editing, 851 type: 'POST', 852 contentType: 'application/json', 853 data: JSON.stringify(newContent), 854 headers: { 855 'X-CSRF-Token': drupalSettings.csrf_token 856 }, 857 success: function(response) { 858 ['token', 'centreId', 'newCentreId', 'centreManagerName', 'centreManagerEmail', 'originDataSet'].forEach(function (k) { localStorage.removeItem(k); }); 859 $('.lets_submit').removeClass('disabled'); 860 $('#succeed_btn').click(); 861 }, 862 error: function(xhr, status, error) { 863 } 864 }); 865 } 866 }) 867 868 // Remove image 869 $('.centre_featured_image_temp .icon_close').click(function(){ 870 $('.centre_featured_image_temp').addClass('force_hidden'); 871 $('#centre_featured_image_preview img').attr('src', ''); 872 $('.centre_featured_image.for_preview').addClass('force_hidden'); 873 }) 874 875 // Image uploader 876 $('.image_uploader').on('click', 'img', function() { 877 var clickedImgHtml = $(this).prop('outerHTML'); 878 var currentVal = $('#album_items').val(); 879 // console.log(currentVal); 880 // console.log(clickedImgHtml); 881 var updatedVal = currentVal.replace(clickedImgHtml, ''); 882 $('#album_items').val(updatedVal); 883 $(this).remove(); 884 885 // console.log(updatedVal); 886 }); 887 888 $("#service_approval_number").on("keypress", function(event) { 889 if (event.key === "Enter") { 890 $("#check_san").click(); 891 } 892 }); 893 894 $("#sav_verification_num").on("keypress", function(event) { 895 if (event.key === "Enter") { 896 $("#san_verify_code").click(); 897 } 898 }); 899 900 function formatDate(dateString) { 901 const date = new Date(dateString); 902 const day = date.getDate();
903 const month = date.toLocaleString('default', { month: 'long' }); 904 const year = date.getFullYear(); 905 function getOrdinalSuffix(day) { 906 if (day > 3 && day < 21) return 'th'; 907 switch (day % 10) { 908 case 1: return "st"; 909 case 2: return "nd"; 910 case 3: return "rd"; 911 default: return "th"; 912 } 913 } 914 915 return `${day}${getOrdinalSuffix(day)} ${month} ${year}`; 916 } 917 918 function formatTime2(timeString) { 919 timeString = timeString.trim(); 920 const match = timeString.match(/^(\d{2}):(\d{2})$/); 921 922 if (!match) { 923 throw new Error('Invalid time format'); 924 } 925 926 let hours = parseInt(match[1], 10); 927 const minutes = match[2]; 928 let period = 'AM'; 929 930 if (hours >= 12) { 931 period = 'PM'; 932 if (hours > 12) { 933 hours -= 12; 934 } 935 } else if (hours === 0) { 936 hours = 12; 937 } 938 939 const formattedHours = hours.toString().padStart(2, '0'); 940 const formattedTime = `${formattedHours}:${minutes}${period}`; 941 942 return formattedTime; 943 } 944 945 function buildProgramsPreview(programs){ 946 var days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']; 947 let programList = ''; 948 programs.forEach(program => { 949 var times = program.field_weekly_time_chunk; 950 programList += ` 951 <div class="w-full affiliate_programs"> 952 <div class="title text-[20px] md:text-[22px] font-medium py-[21px]">${program.field_title}</div> 953 <div class="bt-divider-blue big"></div> 954 <div class="content text-sm font-[300]"> 955 <div class="flex flex-col gap-[20px]"> 956 ${program.field_program_start_date && program.field_program_end_date && `<p><span class="font-medium">Program Date:</span> ` + program.field_program_start_date + ' to ' + program.field_program_end_date + `</p>`} 957 ${program.field_content ? program.field_content : '<div class="empty_content" style="margin-top:-20px"></div>'} 958 </div> 959 <div class="weekly_time_chunk flex flex-col gap-[30px] sm:flex-row md:flex-col flex-wrap"> 960 `; 961 962 days.forEach(day => { 963 if (times['field_' + day + '_opening_hours'] !== null || times['field_' + day + '_extended_hours'] !== null) { 964 programList += ` 965 <div> 966 <div class="bt-divider-blue"></div> 967 <p class="font-medium text-white text-sm mb-4 capitalize">${day} 968 ${times['field_alternate_' + day] == '1' ? '(Alter)' : ''}</p> 969 <div class="flex flex-col gap-[10px] w-full"> 970 `; 971 972 if (times['field_' + day + '_opening_hours'] !== null) { 973 programList += ` 974 <div class="hours_blocks icon icon_clock_white flex flex-row justify-between"> 975 <p class="text-white text-xs">Operating Hours:</p> 976 <p class="text-white text-xs">${times['field_' + day + '_opening_hours']}</p> 977 </div> 978 `; 979 } 980 981 if (times['field_' + day + '_extended_hours'] !== null) { 982 programList += ` 983 <div class="hours_blocks icon icon_clock_white flex flex-row justify-between"> 984 <p class="text-white text-xs">Extended Hours:</p> 985 <p class="text-white text-xs">${times['field_' + day + '_extended_hours']}</p> 986 </div> 987 `; 988 } 989 990 programList += ` 991 </div> 992 </div> 993 `; 994 } 995 }); 996 997 programList += ` 998 </div> 999 <div class="bt-divider-blue"></div> 1000 </div> 1001 </div> 1002 `; 1003 }); 1004 1005 $('#programs_preview').html(programList); 1006 } 1007 1008 function initMapCentre2(dataLat, dataLng) { 1009 const lat = parseFloat(dataLat); 1010 const lng = parseFloat(dataLng); 1011 1012 if (isNaN(lat) || isNaN(lng)) { 1013 return; 1014 } 1015 1016 const center = { lat: lat, lng: lng }; 1017 1018 const map = new google.maps.Map(document.getElementById('centre_map'), { 1019 zoom: 15, 1020 center: center 1021 }); 1022 1023 const customPinImage = '/themes/fluffiness/images/icons/icon_yellow_map_pin.svg'; 1024 1025 new google.maps.Marker({ 1026 position: center, 1027 map: map, 1028 icon: customPinImage 1029 }); 1030 } 1031 1032 function initializeSlick() { 1033 var textarea = document.getElementById('centre_content_div'); 1034 var width = textarea.offsetWidth; 1035 document.getElementById('centre_gallery_div').style.width = width + 'px'; 1036 1037 jQuery('.centre_gallery_div').slick({ 1038 dots: false, 1039 infinite: true, 1040 fade: true, 1041 arrows: true, 1042 adaptiveHeight: true, 1043 speed: 300, 1044 slidesToShow: 1, 1045 slidesToScroll: 1, 1046 }); 1047 } 1048 } 1049 1050 if($('.view-admin-centre-with-duplications').length > 0){ 1051 // Admin approval 1052 $('.admin_approve_yes').click(function(){ 1053 $('body').addClass('overflow-hidden'); 1054 $('.admin_model').removeClass('hidden'); 1055 $('.succeed_message').addClass('hidden'); 1056 1057 var row = $(this).closest('tr'); 1058 var entryId = row.find('.views-field-nid').text().trim(); 1059 var originLink = row.find('.views-field-field-origin-centre-1 a').attr('href'); 1060 1061 var managerName = row.find('.views-field-field-centre-manager-name').text().trim(); 1062 var managerEmail = row.find('.views-field-field-centre-manager-email').text().trim(); 1063 1064 $('#new_centre_id').text(entryId); 1065 $('#centre_manager_name').text(managerName); 1066 $('#centre_manager_email').text(managerEmail); 1067 $('#view_submitted').attr('href', originLink); 1068 }) 1069 1070 $('.admin_approve_no').click(function(){ 1071 $('body').removeClass('overflow-hidden'); 1072 $('.admin_model').addClass('hidden'); 1073 }) 1074 1075 $('#submit_approval').click(function(){ 1076 const newCentreId = $('#new_centre_id').text(); 1077 const protocol = window.location.protocol; 1078 const host = window.location.hostname; 1079 const port = window.location.port; 1080 1081 const managerName = $('#centre_manager_name').text(); 1082 const managerEmail = $('#centre_manager_email').text(); 1083 const centerLink = $('#view_submitted').attr('href'); 1084 1085 const centerUrl = `${protocol}//${host}${port ? ':' + port : ''}${centerLink}`; 1086 1087 $.ajax({
1088 url: '/update-origin-centre/' + newCentreId, 1089 type: 'POST', 1090 contentType: 'application/json', 1091 headers: { 1092 'X-CSRF-Token': drupalSettings.csrf_token 1093 }, 1094 success: function(response) { 1095 sendSucceedEmail(managerName, managerEmail, centerUrl); 1096 $('body').removeClass('overflow-hidden'); 1097 $('.admin_model').addClass('hidden'); 1098 $('.succeed_message').removeClass('hidden'); 1099 }, 1100 error: function(xhr, status, error) { 1101 $('body').removeClass('overflow-hidden'); 1102 $('.admin_model').addClass('hidden'); 1103 $('.succeed_message').removeClass('hidden'); 1104 } 1105 }); 1106 }) 1107 } 1108 }) 1109 1110 function sendSucceedEmail(name, email, link) { 1111 const emailContent = { 1112 "CentreManagerName": name, 1113 "CentreManagerEmail": email, 1114 "CentreLink": link 1115 }; 1116 1117 // Checked 1118 $.ajax({ 1119 url: '/api/send-verification', 1120 method: 'POST', 1121 contentType: 'application/json', 1122 data: JSON.stringify({ 1123 emailAddress: emailContent.CentreManagerEmail, 1124 template: "template_4", 1125 data: emailContent 1126 }), 1127 success: function (response) { 1128 }, 1129 error: function (jqXHR, textStatus, errorThrown) { 1130 } 1131 }); 1132 } 1133 1134 1135 function initializeSlick() { 1136 var textarea = document.getElementById('centre_content_div'); 1137 var width = textarea.offsetWidth; 1138 document.getElementById('centre_gallery_div').style.width = width + 'px'; 1139 1140 jQuery('.centre_gallery_div').slick({ 1141 dots: false, 1142 infinite: true, 1143 fade: true, 1144 arrows: true, 1145 adaptiveHeight: true, 1146 speed: 300, 1147 slidesToShow: 1, 1148 slidesToScroll: 1, 1149 }); 1150 } 1151 1152})(jQuery, Drupal); 1153 1154function getUrlParameter(name) { 1155 name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); 1156 var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); 1157 var results = regex.exec(location.search); 1158 return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); 1159} 1160 1161function generateToken(length) { 1162 var charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; 1163 var token = ''; 1164 for (var i = 0; i < length; i++) { 1165 var randomIndex = Math.floor(Math.random() * charset.length); 1166 token += charset[randomIndex]; 1167 } 1168 return token; 1169} 1170 1171(function ($, Drupal, drupalSettings) { 1172 let bodyInstance, generalInfoInstance, curriculumInstance, feesInstance; 1173 let alreadyLogged = false; 1174 1175 Drupal.behaviors.getAffiliateContentBehavior = { 1176 attach: function (context, settings) { 1177 const checkHidden = function () { 1178 if ($('#portal-editing-target').length > 0) { 1179 if ($('#portal-editing-target').hasClass('hidden')) { 1180 setTimeout(checkHidden, 100); 1181 } else { 1182 if (!alreadyLogged) { 1183 fetchData(); 1184 alreadyLogged = true; 1185 } 1186 } 1187 } 1188 }; 1189 1190 checkHidden(); 1191 } 1192 }; 1193 1194 // Program 1195 $(document).on('click', '.fold_this_program', function() { 1196 $(this).siblings('.program_content').toggleClass('active'); 1197 $(this).toggleClass('active'); 1198 }); 1199 1200 $(document).on('click', '.fold_this_time_div', function() { 1201 $(this).find('.fold_this_time').toggleClass('active'); 1202 $(this).siblings('.program_time_content').toggleClass('active'); 1203 }); 1204 1205 $(document).on('click', '.switch_btn_primary', function() { 1206 if ($(this).find('.switch_btn').hasClass('active')) { 1207 $(this).siblings('.program_time_content').find('.yellow_switch').removeClass('active'); 1208 } 1209 $(this).find('.switch_btn').toggleClass('active'); 1210 $(this).closest('.program_time_item').toggleClass('active'); 1211 $(this).siblings('.program_time_content').addClass('active'); 1212 $(this).siblings('.program_time_content').find('.time-picker').val(''); 1213 }); 1214 1215 $(document).on('click', '.switch_btn_secondary', function() { 1216 $(this).find('.switch_btn').toggleClass('active'); 1217 }); 1218 1219 $(document).on('click', '.delete_this_program', function(){ 1220 $(this).closest('.program_information').remove(); 1221 reorderProgram(); 1222 }); 1223 1224 $(document).on('click', '.delete_fee', function(){ 1225 $(this).closest('.centre_fee_div').remove(); 1226 }); 1227 1228 $(document).on('click', '.delete_fee_real', function(){ 1229 $(this).closest('.centre_fee_div').remove(); 1230 }); 1231 1232 $(document).on('click', '#add_program', function(){ 1233 cloneProgramDiv(); 1234 }); 1235 1236 // $(document).on('click', '#add_fee', function(){ 1237 // cloneFeeDiv(); 1238 // }); 1239 1240 function fetchData() { 1241 const newCentreId = localStorage.getItem('newCentreId'); 1242 if (newCentreId && $('.centre_details').length > 0) { 1243 $.ajax({ 1244 url: '/ck-form-affiliate/content/' + newCentreId, 1245 type: 'GET', 1246 dataType: 'json', 1247 success: function (data) { 1248 if (data.error) { 1249 // console.error('Error fetching data:', data.error); 1250 } else { 1251 drupalSettings.getContentBehavior = drupalSettings.getContentBehavior || {}; 1252 drupalSettings.getContentBehavior.newCentreId = newCentreId; 1253 drupalSettings.getContentBehavior.originCentreId = data.origin_center; 1254 drupalSettings.getContentBehavior.content = data; 1255 1256 if ( 1257 !Array.isArray(data.field_affiliate_programs) || 1258 (data.field_affiliate_programs.length > 0 && 1259 data.field_affiliate_programs[0].field_title == null) 1260 ) { 1261 data.field_affiliate_programs = []; 1262 } 1263 1264 localStorage.setItem('originDataSet', JSON.stringify(data)); 1265 1266 1267 1268 createEditor(function () { 1269 passData(data); 1270 }); 1271 } 1272 }, 1273 error: function () { 1274 $('#portal-editing-target').html('<p>An error occurred while loading the content.</p>'); 1275 } 1276 }); 1277 } 1278 } 1279 1280 function makePrograms(programs){ 1281 if(programs.length > 0){ 1282 $('.program_information:not(.hidden)').remove(); 1283 var days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
1284 programs.forEach(program => { 1285 const programId = program.field_program_id.trim().replace(/[\s_-]+/g, "-"); 1286 1287 // Pass Other Data 1288 cloneProgramDiv(programId); 1289 1290 // Pass Program Data 1291 initializeCKEditor(programId, program.field_content); 1292 1293 $('#program_name_' + programId).val(program.field_title); 1294 $('#program_date_start_input_' + programId).val(program.field_program_start_date); 1295 $('#program_date_end_input_' + programId).val(program.field_program_end_date); 1296 1297 const field_weekly_time_chunk = program.field_weekly_time_chunk; 1298 1299 days.forEach(day => { 1300 // Alternate 1301 if (field_weekly_time_chunk['field_alternate_' + day] === '1') { 1302 $('#program_time_' + day + '_extend_switch_' + programId).addClass('active'); 1303 } 1304 1305 if(field_weekly_time_chunk['field_' + day + '_opening_hours'] || field_weekly_time_chunk['field_' + day + '_extended_hours']){ 1306 $('#program_time_' + day + '_switch_' + programId).addClass('active'); 1307 $('#program_time_item_' + day + '_' + programId).addClass('active'); 1308 } 1309 1310 // Opening 1311 if (field_weekly_time_chunk['field_' + day + '_opening_hours']) { 1312 const openingHours = field_weekly_time_chunk['field_' + day + '_opening_hours']; 1313 const [startTime, endTime] = openingHours.split(/\s*[–-]\s*/); 1314 const startTimeFormatted = formatTime(startTime); 1315 const endTimeFormatted = formatTime(endTime); 1316 1317 $('#program_time_' + day + '_start_input_' + programId).val(startTimeFormatted); 1318 $('#program_time_' + day + '_end_input_' + programId).val(endTimeFormatted); 1319 } 1320 1321 // Extended 1322 if (field_weekly_time_chunk['field_' + day + '_extended_hours']) { 1323 const extendedHours = field_weekly_time_chunk['field_' + day + '_extended_hours']; 1324 const [startTime, endTime] = extendedHours.split(/\s*[–-]\s*/); 1325 const startTimeFormatted = formatTime(startTime); 1326 const endTimeFormatted = formatTime(endTime); 1327 $('#program_time_' + day + '_extend_start_input_' + programId).val(startTimeFormatted); 1328 $('#program_time_' + day + '_extend_end_input_' + programId).val(endTimeFormatted); 1329 } 1330 }); 1331 }); 1332 } 1333 } 1334 1335 function initializeCKEditor(programId, initialContent) { 1336 const classicEditorConfig = { 1337 toolbar: { 1338 items: [ 1339 'bold', 1340 'italic', 1341 'heading', 1342 'numberedList', 1343 'bulletedList', 1344 'link', 1345 'insertTable' 1346 ], 1347 shouldNotGroupWhenFull: true 1348 }, 1349 alignment: { 1350 options: ['left', 'center', 'right'] 1351 }, 1352 heading: { 1353 options: [ 1354 { model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' }, 1355 { model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' }, 1356 { model: 'heading3', view: 'h3', title: 'Heading 3', class: 'ck-heading_heading3' }, 1357 { model: 'heading4', view: 'h4', title: 'Heading 4', class: 'ck-heading_heading4' } 1358 ] 1359 } 1360 }; 1361 1362 const editorElement = document.getElementById(`ck_editor_program_${programId}`); 1363 1364 ClassicEditor 1365 .create(editorElement, classicEditorConfig) 1366 .then(editor => { 1367 initialContent && editor.setData(initialContent.replace(/ /g, ' ')); 1368 }) 1369 .catch(error => { 1370 // console.error('Error initializing CKEditor:', error); 1371 }); 1372 } 1373 1374 function cloneProgramDiv(id){ 1375 var days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']; 1376 var randomString = id ?? Math.random().toString(36).substring(2, 15); 1377 var programDiv = $('#program_blank'); 1378 var clonedDiv = programDiv.clone(); 1379 1380 clonedDiv.attr('id', 'program_' + randomString); 1381 clonedDiv.find('input#program_name').attr('id', 'program_name_' + randomString); 1382 clonedDiv.find('#ck_editor_program').attr('id', 'ck_editor_program_' + randomString); 1383 clonedDiv.find('#program_date_end_input').attr('id', 'program_date_end_input_' + randomString); 1384 clonedDiv.find('#program_date_start_input').attr('id', 'program_date_start_input_' + randomString); 1385 1386 days.forEach(day => { 1387 clonedDiv.find('#program_time_item_' + day).attr('id', 'program_time_item_' + day + '_' + randomString); 1388 clonedDiv.find('#program_time_' + day + '_switch').attr('id', 'program_time_' + day + '_switch_' + randomString); 1389 clonedDiv.find('#program_time_' + day + '_start_input').attr('id', 'program_time_' + day + '_start_input_' + randomString); 1390 clonedDiv.find('#program_time_' + day + '_end_input').attr('id', 'program_time_' + day + '_end_input_' + randomString); 1391 clonedDiv.find('#program_time_' + day + '_extend_switch').attr('id', 'program_time_' + day + '_extend_switch_' + randomString); 1392 clonedDiv.find('#program_time_' + day + '_extend_start_input').attr('id', 'program_time_' + day + '_extend_start_input_' + randomString); 1393 clonedDiv.find('#program_time_' + day + '_extend_end_input').attr('id', 'program_time_' + day + '_extend_end_input_' + randomString); 1394 }); 1395 1396 clonedDiv.removeClass('hidden'); 1397 programDiv.before(clonedDiv); 1398 1399 initializeCKEditor(randomString, ""); 1400 reorderProgram(); 1401 reApplyTimePicker(); 1402 } 1403 1404 // function cloneFeeDiv(id){ 1405 // var randomString = id ?? Math.random().toString(36).substring(2, 15); 1406 // var feeDiv = $('#fee_blank'); 1407 // var clonedDiv = feeDiv.clone(); 1408 1409 // clonedDiv.attr('id', 'centre_fee_' + randomString + '_div'); 1410 // clonedDiv.find('#fee_type').attr('id', 'fee_type_' + randomString); 1411 // clonedDiv.find('#fee_desc').attr('id', 'fee_desc_' + randomString); 1412 // clonedDiv.find('#fee_amount').attr('id', 'fee_amount_' + randomString); 1413 // clonedDiv.find('#fee_desc_real').attr('id', 'fee_desc_real_' + randomString); 1414 1415 // clonedDiv.removeClass('hidden'); 1416 // feeDiv.before(clonedDiv); 1417 // } 1418 1419 function reApplyTimePicker (){ 1420 $('.time-picker').each(function(){ 1421 $(this).on('change', function() { 1422 $(this).closest('.program_time_item').addClass('active'); 1423 $(this).closest('.program_time_item').find('.switch_btn_primary .switch_btn').addClass('active'); 1424 }); 1425 }); 1426 } 1427 1428 function reorderProgram (){ 1429 var programOrders = document.querySelectorAll('span.program_order');
1430 programOrders.forEach(function(span, index) { 1431 span.textContent = index + 1; 1432 }); 1433 } 1434 1435 function createEditor(callback) { 1436 let editorsInitialized = 0; 1437 const totalEditors = 4; 1438 1439 function checkIfAllEditorsInitialized() { 1440 editorsInitialized++; 1441 if (editorsInitialized === totalEditors && typeof callback === 'function') { 1442 callback(); 1443 } 1444 } 1445 1446 const classicEditorConfig = { 1447 toolbar: { 1448 items: [ 1449 'bold', 1450 'italic', 1451 'heading', 1452 'numberedList', 1453 'bulletedList', 1454 'link', 1455 'insertTable' 1456 ], 1457 shouldNotGroupWhenFull: true 1458 }, 1459 alignment: { 1460 options: ['left', 'center', 'right'] 1461 }, 1462 heading: { 1463 options: [ 1464 { model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' }, 1465 { model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' }, 1466 { model: 'heading3', view: 'h3', title: 'Heading 3', class: 'ck-heading_heading3' }, 1467 { model: 'heading4', view: 'h4', title: 'Heading 4', class: 'ck-heading_heading4' } 1468 ] 1469 } 1470 } 1471 1472 ClassicEditor 1473 .create(document.querySelector('#ck_editor'), classicEditorConfig) 1474 .then(editor => { 1475 bodyInstance = editor; 1476 checkIfAllEditorsInitialized(); 1477 }) 1478 .catch(error => { 1479 checkIfAllEditorsInitialized(); 1480 }); 1481 1482 ClassicEditor 1483 .create(document.querySelector('#ck_editor_2'), classicEditorConfig) 1484 .then(editor => { 1485 generalInfoInstance = editor; 1486 checkIfAllEditorsInitialized(); 1487 }) 1488 .catch(error => { 1489 checkIfAllEditorsInitialized(); 1490 }); 1491 1492 ClassicEditor 1493 .create(document.querySelector('#ck_editor_3'), classicEditorConfig) 1494 .then(editor => { 1495 curriculumInstance = editor; 1496 checkIfAllEditorsInitialized(); 1497 }) 1498 .catch(error => { 1499 checkIfAllEditorsInitialized(); 1500 }); 1501 1502 ClassicEditor 1503 .create(document.querySelector('#ck_editor_4'), classicEditorConfig) 1504 .then(editor => { 1505 feesInstance = editor; 1506 checkIfAllEditorsInitialized(); 1507 }) 1508 .catch(error => { 1509 checkIfAllEditorsInitialized(); 1510 }); 1511 } 1512 1513 function passData(data) { 1514 $('#title').text(data.title.split('_')[0]); 1515 $('#centre_type').text(data.centre_type); 1516 $('#centre_type').addClass('icon_centre_type_' + data.centre_code); 1517 $('#centre_year').text(data.centre_year); 1518 1519 if(data.field_fee_year){ 1520 $('#fee_year_preview').text(data.field_fee_year); 1521 $('#fee_year_edit').val(data.field_fee_year); 1522 } 1523 1524 if(data.field_brochure_url){ 1525 $('#brochure_preview a').attr('href', data.field_brochure_url); 1526 $('#brochureFileDetails').css('display', 'flex'); 1527 $('#brochureFileInfo').text(data.field_brochure_url.length > 100 ? data.field_brochure_url.substring(0, 100) + '...' : data.field_brochure_url); 1528 $('#brochure_preview').removeClass('force_hidden'); 1529 }else{ 1530 $('#brochure_preview').addClass('force_hidden'); 1531 } 1532 1533 if(data.field_statement_of_fees_url){ 1534 $('#fee_statement_preview a').attr('href', data.field_statement_of_fees_url); 1535 $('#fee_statementFileDetails').css('display', 'flex'); 1536 $('#fee_statementFileInfo').text(data.field_statement_of_fees_url.length > 100 ? data.field_statement_of_fees_url.substring(0, 100) + '...' : data.field_statement_of_fees_url); 1537 $('#fee_statement_preview').removeClass('force_hidden'); 1538 }else{ 1539 $('#fee_statement_preview').addClass('force_hidden'); 1540 } 1541 1542 if(data.field_give_consent !== null){ 1543 const consentInput = document.querySelector(`input[name="consent"][value="${data.field_give_consent}"]`); 1544 if (consentInput) { 1545 consentInput.checked = true; 1546 } 1547 } 1548 1549 if(data.field_nation_name){ 1550 const nation_name_origin = data.field_nation_name; 1551 $('#centre_first_nation_name').val(nation_name_origin['first_nation_name']); 1552 $('#centre_last_nation_name').val(nation_name_origin['last_nation_name']); 1553 1554 if(nation_name_origin['first_nation_name'] !== ''){ 1555 $('#nation_name_div').removeClass('force_hidden'); 1556 1557 if (Array.isArray(nation_name_origin)) { 1558 const nation_name = nation_name_origin.join(','); 1559 $('#nation_name').text(nation_name); 1560 } else { 1561 const nation_name = Object.entries(nation_name_origin) 1562 .map(([key, value]) => `${value}`) 1563 .join(', '); 1564 $('#nation_name').text(nation_name); 1565 } 1566 }else{ 1567 $('#nation_name_div').addClass('force_hidden'); 1568 } 1569 } 1570 1571 if(data.centre_region){ 1572 $('#centre_region').text(data.centre_region); 1573 }else{ 1574 $('#centre_region').remove(); 1575 } 1576 1577 if(data.field_center_nqfrating_id){ 1578 $('#centre_rating').removeClass('force_hidden'); 1579 $('#nqf_' + data.field_center_nqfrating_id).prop('checked', true); 1580 const label = $('#nqf_' + data.field_center_nqfrating_id).data('label') || $('#nqf_' + data.field_center_nqfrating_id).attr('data-label'); 1581 1582 $('#centre_rating').text('NQF Rating: ' + label); 1583 }else{ 1584 $('#centre_rating').addClass('force_hidden'); 1585 $('#nqf_0').prop('checked', true); 1586 } 1587 1588 if (data.centre_fees) {
1589 Object.keys(data.centre_fees).forEach(fee_key => { 1590 const fee_value = data.centre_fees[fee_key]; 1591 $('#fee_amount_' + fee_key.replace('field_fee_', '')).val(fee_value); 1592 }); 1593 } 1594 1595 if(data.field_address) { 1596 $('#location').text(data.field_address); 1597 $('#centre_location').val(data.field_address); 1598 $('#centre_location_address_line1').text(data.field_address_raw['address_line1']); 1599 $('#centre_location_administrative_area').text(data.field_address_raw['administrative_area']); 1600 $('#centre_location_locality').text(data.field_address_raw['locality']); 1601 $('#centre_location_postal_code').text(data.field_address_raw['postal_code']); 1602 } 1603 1604 $('#enrol_website_url').val(data.field_enrollment_url); 1605 $('#enrol_email_url').val(data.field_enrollment_email); 1606 $('#enrol_' + data.field_enrollment_mode).prop('checked', true); 1607 1608 if (bodyInstance && data.body) { bodyInstance.setData(data.body); } 1609 1610 if(data.field_general_information){ 1611 $('#general_info').html(data.field_general_information); 1612 } 1613 1614 // if (generalInfoInstance && data.field_general_information) { generalInfoInstance.setData(data.field_general_information); } 1615 1616 if (curriculumInstance && data.field_curriculum) { curriculumInstance.setData(data.field_curriculum); } 1617 1618 if (feesInstance && data.field_fees) { feesInstance.setData(data.field_fees); } 1619 1620 if (data.field_centre_phone){ 1621 $('#centre_phone').val(data.field_centre_phone); 1622 $('#centre_phone_preview').text(data.field_centre_phone); 1623 } 1624 1625 if (data.field_centre_email){ 1626 $('#centre_email').val(data.field_centre_email); 1627 $('#centre_email_preview').text(data.field_centre_email); 1628 } 1629 1630 if (data.field_centre_website){ 1631 $('#centre_website').val(data.field_centre_website); 1632 var website = data.field_centre_website.replace(/^https?:\/\//, ''); 1633 $('#centre_website_preview').text(website); 1634 } 1635 1636 if (data.field_centre_social_facebook){ 1637 $('#centre_facebook').val(data.field_centre_social_facebook); 1638 $('#centre_facebook_preview').attr('href', data.field_centre_social_facebook); 1639 } 1640 1641 if (data.field_centre_social_youtube){ 1642 $('#centre_youtube').val(data.field_centre_social_youtube); 1643 $('#centre_youtube_preview').attr('href', data.field_centre_social_youtube); 1644 } 1645 1646 if (data.field_centre_social_instagram){ 1647 $('#centre_instagram').val(data.field_centre_social_instagram); 1648 $('#centre_instagram_preview').attr('href', data.field_centre_social_instagram); 1649 } 1650 1651 if (data.field_centre_social_linkedin){ 1652 $('#centre_linkedin').val(data.field_centre_social_linkedin); 1653 $('#centre_linkedin_preview').attr('href', data.field_centre_social_linkedin); 1654 } 1655 1656 if (data.field_centre_social_tiktok){ 1657 $('#centre_tiktok').val(data.field_centre_social_tiktok); 1658 $('#centre_tiktok_preview').attr('href', data.field_centre_social_tiktok); 1659 } 1660 1661 if (data.field_centre_video_url){ 1662 $('#centre_video').val(data.field_centre_video_url); 1663 $('#centre_video_iframe').attr('src', data.field_centre_video_url); 1664 } 1665 1666 if (data.field_centre_inclusion_id){ 1667 data.field_centre_inclusion_id.forEach(function(id) { 1668 $('#centre_inclusion_' + id).prop('checked', true); 1669 }); 1670 } 1671 1672 if (data.field_images_in_editor) { 1673 $('#centre_gallery_preview').html(data.field_images_in_editor); 1674 } 1675 1676 if (data.field_image_in_editor) { 1677 $('#centre_featured_image_preview').html(data.field_image_in_editor); 1678 $('#centre_featured_image_temp').html(data.field_image_in_editor); 1679 } else{ 1680 $('#centre_featured_image_temp').addClass('hidden'); 1681 $('.centre_featured_image_temp .icon_close').addClass('hidden'); 1682 } 1683 1684 if(data.field_images_in_editor){ 1685 $('#album_items').val(data.field_images_in_editor); 1686 $('#centre_album_div_preview').html(data.field_images_in_editor); 1687 $('.image_uploader').prepend(data.field_images_in_editor); 1688 makeSlick(); 1689 } 1690 1691 makePrograms(data.field_affiliate_programs); 1692 1693 if (data.field_latitude && data.field_longitude && $('#centre_location').length > 0) { 1694 $('#centre_latitude').text(data.field_latitude); 1695 $('#centre_longitude').text(data.field_longitude); 1696 1697 setTimeout(function () { 1698 initMapCentre(data.field_latitude, data.field_longitude); 1699 initAutocomplete(); 1700 }, 2000); 1701 } 1702 1703 1704 1705 function initAutocomplete() { 1706 const addressField = document.getElementById('centre_location'); 1707 if (!addressField) return; 1708 1709 const autocomplete = new google.maps.places.Autocomplete(addressField, { 1710 types: ['address'], 1711 componentRestrictions: { country: 'au' } 1712 }); 1713 1714 autocomplete.addListener('place_changed', function () { 1715 const place = autocomplete.getPlace(); 1716 if (!place.geometry) return; 1717 1718 const address = place.formatted_address; 1719 const lat = place.geometry.location.lat(); 1720 const lng = place.geometry.location.lng(); 1721 1722 $('#location').text(address); 1723 $('#centre_latitude').text(lat); 1724 $('#centre_longitude').text(lng); 1725 1726 let addressLine1 = ''; 1727 let locality = ''; 1728 let administrativeArea = ''; 1729 let postalCode = ''; 1730
1731 place.address_components.forEach(function (component) { 1732 if (component.types.includes('street_number')) { 1733 addressLine1 = component.long_name + ' ' + addressLine1; 1734 } 1735 if (component.types.includes('route')) { 1736 addressLine1 += component.long_name; 1737 } 1738 if (component.types.includes('locality')) { 1739 locality = component.long_name; 1740 } 1741 if (component.types.includes('administrative_area_level_1')) { 1742 administrativeArea = component.short_name; 1743 } 1744 if (component.types.includes('postal_code')) { 1745 postalCode = component.long_name; 1746 } 1747 }); 1748 1749 $('#centre_location_address_line1').text(addressLine1); 1750 $('#centre_location_administrative_area').text(administrativeArea); 1751 $('#centre_location_locality').text(locality); 1752 $('#centre_location_postal_code').text(postalCode); 1753 1754 initMapCentre(lat, lng); 1755 }); 1756 } 1757 } 1758 1759 function formatTime(timeString) { 1760 timeString = timeString.trim().toLowerCase(); 1761 const match = timeString.match(/^(\d{1,2}):(\d{2})\s*(am|pm)?$/i); 1762 1763 if (!match) { 1764 throw new Error('Invalid time format'); 1765 } 1766 1767 let hours = parseInt(match[1], 10); 1768 const minutes = match[2]; 1769 const period = match[3] || ''; 1770 if (period === 'pm' && hours < 12) { 1771 hours += 12; 1772 } else if (period === 'am' && hours === 12) { 1773 hours = 0; 1774 } 1775 const formattedTime = `${hours.toString().padStart(2, '0')}:${minutes}`; 1776 1777 return formattedTime; 1778 } 1779 1780 function initMapCentre(dataLat, dataLng) { 1781 const lat = parseFloat(dataLat); 1782 const lng = parseFloat(dataLng); 1783 1784 if (isNaN(lat) || isNaN(lng)) { 1785 return; 1786 } 1787 1788 const center = { lat: lat, lng: lng }; 1789 1790 const map = new google.maps.Map(document.getElementById('centre_map'), { 1791 zoom: 15, 1792 center: center 1793 }); 1794 1795 const customPinImage = '/themes/fluffiness/images/icons/icon_yellow_map_pin.svg'; 1796 1797 new google.maps.Marker({ 1798 position: center, 1799 map: map, 1800 icon: customPinImage 1801 }); 1802 1803 google.maps.event.trigger(map, "resize"); 1804 } 1805 1806 function makeSlick(){ 1807 jQuery('.centre_gallery_div').slick('unslick'); 1808 jQuery('.centre_gallery_div').removeData('slick'); 1809 initializeSlick(); 1810 } 1811 1812 function initializeSlick() { 1813 var textarea = document.getElementById('centre_content_div'); 1814 var width = textarea.offsetWidth; 1815 document.getElementById('centre_gallery_div').style.width = width + 'px'; 1816 1817 jQuery('.centre_gallery_div').slick({ 1818 dots: false, 1819 infinite: true, 1820 fade: true, 1821 arrows: true, 1822 adaptiveHeight: true, 1823 speed: 300, 1824 slidesToShow: 1, 1825 slidesToScroll: 1, 1826 }); 1827 } 1828 1829})(jQuery, Drupal, drupalSettings); 1830(function (Drupal, drupalSettings, $) { 1831 1832 Drupal.behaviors.ckFormAffiliateUpload = { 1833 attach: function (context, settings) { 1834 1835 // Only runs on the affiliate edit page (?editing=NID); silently no-op elsewhere. 1836 if (!drupalSettings.ckFormAffiliate) { 1837 return; 1838 } 1839 1840 const nodeId = drupalSettings.ckFormAffiliate.nid; 1841 1842 function uploadFile(event, type) { 1843 const file = event.target.files[0]; 1844 if (!file) return; 1845 1846 // Map type to Drupal field 1847 const fieldMap = { 1848 'brochure': 'field_brochure', 1849 'fee_statement': 'field_statement_of_fees' 1850 }; 1851 const fieldName = fieldMap[type]; 1852 if (!fieldName) return console.error('Unknown type:', type); 1853 1854 const formData = new FormData(); 1855 formData.append('file', file); 1856 formData.append('field', fieldName); 1857 formData.append('nid', nodeId); 1858 1859 fetch('/ck-form-affiliate/upload', { 1860 method: 'POST', 1861 body: formData, 1862 headers: { 1863 'X-Requested-With': 'XMLHttpRequest', 1864 'X-CSRF-Token': drupalSettings.ckFormAffiliate.csrfToken 1865 }, 1866 credentials: 'same-origin' 1867 }) 1868 .then(response => response.json()) 1869 .then(data => { 1870 if (data.success) { 1871 const fileDetailsDiv = document.getElementById(type + 'FileDetails'); 1872 fileDetailsDiv.style.display = 'flex'; 1873 document.getElementById(type + 'FileInfo').textContent = `${file.name} - ${(file.size / 1024).toFixed(2)} KB`; 1874 document.getElementById(type + '_preview').classList.remove('force_hidden'); 1875 document.getElementById(type + '_preview').querySelector('a').href = data.file_url; 1876 } else { 1877 alert('Upload failed: ' + data.message); 1878 } 1879 }) 1880 .catch(err => console.error('Upload error:', err)); 1881 1882 } 1883 1884 // Expose globally for inline onchange 1885 window.uploadFile = uploadFile; 1886 1887 } 1888 }; 1889 1890})(Drupal, drupalSettings, jQuery);
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.