1window.addEventListener("load", () => { 2 // fetch("https://ai.mwe-srv.com/hubs/hub1_2.json") 3 const addNewTeamBtn = document.querySelector('.create-team-popup .add-new-team-btn'); 4 if(addNewTeamBtn) { 5 addNewTeamBtn.addEventListener('click', showAddNewTeam); 6 } 7 8 function showAddNewTeam() { 9 const addNewTeamCt = document.querySelector('.create-team-popup .add-new-team-ct'); 10 if(addNewTeamCt) { 11 addNewTeamCt.classList.add('show'); 12 } 13 const addNewTeamBtn = document.querySelector('.create-team-popup .add-new-team-btn'); 14 if(addNewTeamBtn) { 15 addNewTeamBtn.classList.remove('show'); 16 } 17 } 18 19 const contextSelect = document.querySelector('.create-team-popup select#context'); 20 if(contextSelect) { 21 contextSelect.addEventListener('change', handleTeamContextChange); 22 } 23 24 function handleTeamContextChange(e) { 25 const createTeamPopup = document.querySelector('.create-team-popup'); 26 if(createTeamPopup) { 27 createTeamPopup.classList.remove('initial-load'); 28 createTeamPopup.classList.remove('team-company-context'); 29 createTeamPopup.classList.remove('class-course-context'); 30 createTeamPopup.classList.remove('community-context'); 31 32 const contextEls = document.querySelectorAll('.create-team-popup .context-label-el'); 33 const organizationLabel = document.querySelector('.create-team-popup .organization-label'); 34 const purposeEls = document.querySelectorAll('.create-team-popup .purpose-el'); 35 const creatorRoleEls = document.querySelectorAll('.create-team-popup .creator-role-el'); 36 const lastProfSubject = document.querySelectorAll('.create-team-popup .hide-class'); 37 const lastProfInput = document.querySelector('.create-team-popup .hide-class input'); 38 if(e.target.value === 'team') { 39 createTeamPopup.classList.add('team-company-context'); 40 if(contextEls) { 41 contextEls.forEach(el => el.innerHTML = 'organization'); 42 } 43 44 if(purposeEls) { 45 purposeEls.forEach(el => el.classList.remove('hide')); 46 } 47 48 if(creatorRoleEls) { 49 creatorRoleEls.forEach(el => el.classList.add('hide')); 50 } 51 52 if(lastProfSubject) { 53 lastProfSubject.forEach(el => el.classList.remove('hide')); 54 } 55 } 56 else if(e.target.value === 'class') { 57 createTeamPopup.classList.add('class-course-context'); 58 if(contextEls) { 59 contextEls.forEach(el => el.innerHTML = 'class'); 60 } 61 62 if(purposeEls) { 63 purposeEls.forEach(el => el.classList.add('hide')); 64 } 65 66 if(creatorRoleEls) { 67 creatorRoleEls.forEach(el => el.classList.remove('hide')); 68 } 69 70 if(lastProfSubject) { 71 lastProfSubject.forEach(el => el.classList.add('hide')); 72 } 73 74 if(lastProfInput) { 75 lastProfInput.value = ''; 76 lastProfInput.dataset.subjectid = ''; 77 } 78 } else if(e.target.value === 'community') { 79 createTeamPopup.classList.add('community-context'); 80 if(contextEls) { 81 contextEls.forEach(el => el.innerHTML = 'community'); 82 } 83 84 if(purposeEls) { 85 purposeEls.forEach(el => el.classList.add('hide')); 86 } 87 88 if(creatorRoleEls) { 89 creatorRoleEls.forEach(el => el.classList.add('hide')); 90 } 91 92 if(lastProfSubject) { 93 lastProfSubject.forEach(el => el.classList.remove('hide')); 94 } 95 } 96 97 const hideInitiallyEls = document.querySelectorAll('.create-team-popup .hide-init'); 98 if(hideInitiallyEls) { 99 hideInitiallyEls.forEach(el => el.classList.remove('hide')); 100 } 101 102 } 103 } 104 105 const addSubjectBtn = document.querySelector('.create-team-popup .add-another-subject-btn'); 106 if(addSubjectBtn) { 107 addSubjectBtn.addEventListener('click', addSubject); 108 } 109 110 function addSubject(e) { 111 const subjects = document.querySelectorAll('.create-team-popup .subject-switch'); 112 let index = 1; 113 if(subjects) { 114 index = subjects.length + 1;
115 const subjectHTML = ` 116 <div class="search-subject-ct" data-subjectIndex="${index}"> 117 <input type="text" class="util-input-text subject-input extra-subject" placeholder="Type here and choose from options" aria-label="Type here and choose from options"> 118 <div class="search-list-wrap"></div> 119 <div class="search-list"> 120 <ul id="searchList"></ul> 121 </div> 122 </div> 123 <div class="util-toggle subject-switch" data-subjectIndex="${index}"> 124 <input type="radio" id="subject${index}Professional" name="subject${index}" value="professional" checked/> 125 <label for="subject${index}Professional"><span class="prof-label">Professional</span><span class="acad-label">Academic</span></label> 126 <input type="radio" id="subject${index}Personal" name="subject${index}" value="personal" /> 127 <label for="subject${index}Personal">Personal</label> 128 </div>`; 129 e.target.insertAdjacentHTML('beforebegin', subjectHTML); 130 const subjectInputs = document.querySelectorAll('.create-team-popup-ct .subject-input'); 131 const subjectWraps = document.querySelectorAll('.create-team-popup-ct .search-list-wrap'); 132 if(subjectInputs) { 133 subjectInputs[subjectInputs.length - 1].addEventListener('input', searchSubjectForTeams); 134 } 135 136 if(subjectWraps) { 137 subjectWraps[subjectWraps.length - 1].addEventListener('click', onSubjectSearchWrapClick); 138 } 139 140 const addBtn = document.querySelector('.create-team-popup-ct .add-another-subject-btn') 141 if(addBtn) { 142 addBtn.classList.add('hide'); 143 } 144 } 145 } 146 147 const groupingSwitchInputs = document.querySelectorAll('.create-team-popup .groupings-ct input[type="radio"]'); 148 149 if(groupingSwitchInputs) { 150 groupingSwitchInputs.forEach(input => input.addEventListener('change', onGroupingsSwitchChange)); 151 } 152 function onGroupingsSwitchChange(e) { 153 const groupingsListCt = document.querySelector('.create-team-popup .groupings-list-ct'); 154 if(groupingsListCt) { 155 if(e.target.value === 'no') { 156 groupingsListCt.classList.remove('show'); 157 } else { 158 groupingsListCt.classList.add('show'); 159 } 160 } 161 } 162 163 const addGroupingBtn = document.querySelector('.create-team-popup .add-another-grouping'); 164 if(addGroupingBtn) { 165 addGroupingBtn.addEventListener('click', addNewGrouping); 166 } 167 168 function addNewGrouping() { 169 const groupingHTML = '<input type="text" class="util-input-text" placeholder="Type here">'; 170 const groupingGrid = document.querySelector('.create-team-popup .grid-2-ct'); 171 if(groupingGrid) { 172 groupingGrid.insertAdjacentHTML('beforeend', groupingHTML); 173 } 174 } 175 176 const newTeamBtn = document.querySelector('.teams-dropdown .new-team'); 177 if(newTeamBtn) { 178 newTeamBtn.addEventListener('click', showCreateTeamPopup); 179 } 180 181 function showCreateTeamPopup() { 182 const createTeamPopupCt = document.querySelector('.create-team-popup-ct'); 183 createTeamPopupCt.style.display = 'flex'; 184 185 // stop scroll on body 186 this.bodyInitialStyle = document.body.style; 187 this.initialScroll = window.scrollY; 188 document.body.style.top = `-${window.scrollY}px`; 189 document.body.style.position = 'fixed'; 190 document.body.style.width = `100vw`; 191 document.body.style.height = '100vh'; 192 } 193 194 const cancelNewTeamBtn = document.querySelector('.create-team-popup-ct .util-cancel-btn'); 195 196 if(cancelNewTeamBtn) { 197 cancelNewTeamBtn.addEventListener('click', hideCreateTeamPopup); 198 } 199 200 function hideCreateTeamPopup() { 201 const createTeamPopupCt = document.querySelector('.create-team-popup-ct'); 202 createTeamPopupCt.style.display = 'none'; 203 204 // add back scroll on body + move to scroll position from before modal was opened 205 document.body.style = this.bodyInitialStyle; 206 } 207 208 function dataURLtoFile(dataurl, filename) { 209 var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1], 210 bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); 211 while(n--){ 212 u8arr[n] = bstr.charCodeAt(n); 213 } 214 return new File([u8arr], filename, {type:mime}); 215 } 216 217 const coverInput = document.querySelector('.create-team-popup .avatar-url'); 218 if(coverInput) { 219 coverInput.addEventListener('input', (e) => { 220 emptyAvatarFileInput(); 221 previewLogoImage(e.target.value) 222 }) 223 } 224 225 const coverFileInput = document.querySelector('.create-team-popup-ct .upload-preview-ct input[type="file"]'); 226 if(coverFileInput) { 227 coverFileInput.addEventListener("change", () => { 228 var reader = new FileReader(); 229 reader.onload = function(e){ 230 var dataURL = e.target.result; 231 var file = dataURLtoFile(dataURL, 'logo.jpg'); 232 var blob = URL.createObjectURL(file) 233 emptyAvatarURLInput() 234 previewLogoImage(blob) 235 };
236 reader.readAsDataURL(coverFileInput.files[0]); 237 }) 238 } 239 240 function emptyAvatarFileInput() { 241 if(coverFileInput) { 242 coverFileInput.value = ''; 243 } 244 } 245 246 function emptyAvatarURLInput() { 247 if(coverInput) { 248 coverInput.value = ''; 249 } 250 } 251 252 253 const coverPreview = document.querySelector('.create-team-popup-ct .preview'); 254 function previewLogoImage(imgSrc) { 255 if(coverPreview) { 256 coverPreview.style.backgroundImage = `url(${imgSrc})`; 257 coverPreview.classList.add('show'); 258 } 259 } 260 261 const subjectInputs = document.querySelectorAll('.create-team-popup-ct .subject-input'); 262 if(subjectInputs) { 263 subjectInputs.forEach(input => input.addEventListener('input', searchSubjectForTeams)); 264 } 265 266 const avatarsModal = document.querySelector('.hub-avatars-ct'); 267 268 const selectAvatarBtn = document.querySelector('.create-team-popup-ct .choose-img'); 269 if(selectAvatarBtn) { 270 selectAvatarBtn.addEventListener('click', showAvatarsModal); 271 } 272 273 let avatarsInserted = false; 274 275 function showAvatarsModal() { 276 if(!avatarsInserted) { 277 getAvatarPlaceholders(); 278 avatarsModal.classList.add('loading'); 279 } 280 if (avatarsModal) { 281 avatarsModal.classList.add('show'); 282 } 283 } 284 285 const closeAvatarBtn = document.querySelector('.hub-avatars-ct .util-close-popup'); 286 if(closeAvatarBtn) { 287 closeAvatarBtn.addEventListener('click', closeAvatarModal) 288 } 289 function closeAvatarModal() { 290 if(avatarsModal) { 291 avatarsModal.classList.remove('show'); 292 } 293 } 294 295 function getAvatarPlaceholders() { 296 util.request({ 297 url: `/hubs/getDefaultAvatars.json`, 298 success: (response) => { 299 const avatarsModalList = document.querySelector('.hub-avatars-ct .avatars-modal-list'); 300 if(avatarsModalList && response.length) { 301 response.forEach(imgURL => { 302 const img = util.makeEl({tag: 'img', src: imgURL, target: avatarsModalList}); 303 img.addEventListener('click', () => { 304 closeAvatarModal(); 305 previewLogoImage(imgURL); 306 emptyAvatarFileInput(); 307 if(coverInput) { 308 coverInput.value = imgURL; 309 } 310 }); 311 }); 312 } 313 314 avatarsModal.classList.remove('loading'); 315 avatarsInserted = true; 316 } 317 }) 318 } 319 320 function searchSubjectForTeams(e) { 321 const addBtn = document.querySelector('.create-team-popup-ct .add-another-subject-btn'); 322 if(addBtn && e.target.classList.contains('extra-subject')) { 323 addBtn.classList.add('hide'); 324 } 325 326 e.target.dataset.subjectid = ''; 327 328 const subjectInputCt = e.target.closest('.search-subject-ct'); 329 const searchList = subjectInputCt.querySelector(".create-team-popup-ct .search-list"); 330 const searchWrap = subjectInputCt.querySelector(".create-team-popup-ct .search-list-wrap"); 331 332 showLoadingSpinner(e, searchList, searchWrap); 333 util.request({ 334 url: `/subjects.json?keywords=${e.target.value}`, 335 success: (response) => { 336 showSubjectsSearchResult(response.data, searchList, searchWrap); 337 } 338 }) 339 } 340 341 function checkSubjectValues() { 342 const subjectInputs = document.querySelectorAll('.create-team-popup .grid-1-ct .subject-input'); 343 subjectInputs.forEach(subjectInput => { 344 if(!subjectInput.dataset.subjectid || subjectInput.dataset.subjectid.length == 0) { 345 subjectInput.value = ''; 346 } 347 }) 348 } 349 350 function showLoadingSpinner(e, searchList, searchWrap) { 351 searchList.style.display = "block"; 352 searchWrap.style.display = "block"; 353 searchList.querySelector("ul").innerHTML = ` 354 <li class="spinner-ct"> 355 <img src="/img/loader.gif" /> 356 </li> 357 `; 358 } 359 360 function hideSearchList(searchList, searchWrap) { 361 const spinnerCt = searchList.querySelector('.create-team-popup-ct .search-list .spinner-ct'); 362 363 searchList.style.display = "none"; 364 searchWrap.style.display = "none"; 365 if(spinnerCt) { 366 spinnerCt.remove(); 367 }; 368 } 369 370 function showSubjectsSearchResult(results, searchList, searchWrap) {
371 searchWrap.style.display = "block"; 372 searchList.style.display = "block"; 373 searchList.querySelector("ul").innerHTML = ''; 374 375 const currentSubjectInputs = document.querySelectorAll('.create-team-popup-ct .subject-input'); 376 let subjIDs = []; 377 if(currentSubjectInputs) { 378 currentSubjectInputs.forEach(subj => { 379 if(subj.dataset.subjectid) { 380 subjIDs.push(subj.dataset.subjectid); 381 } 382 }) 383 } 384 385 let filteredResults = results.filter(result => { 386 return !subjIDs.includes(result.ID); 387 }) 388 389 if(filteredResults.length > 0) { 390 filteredResults.map(obj => { 391 if(!subjIDs.includes(obj.ID)) { 392 const listItem = document.createElement("li"); 393 listItem.innerHTML = obj.label; 394 listItem.setAttribute("data-subjectName", obj.label); 395 listItem.setAttribute("data-subjectID", obj.ID); 396 searchList.querySelector("ul").innerHTML += listItem.outerHTML; 397 } 398 }); 399 const listItems = searchList.querySelectorAll("li"); 400 if(listItems && listItems[0]) { 401 listItems.forEach(li => li.addEventListener("click", (e) => selectSubject(e, searchList, searchWrap))); 402 } 403 } else { 404 const listItem = document.createElement("li"); 405 listItem.innerText = 'No results'; 406 searchList.querySelector("ul").innerHTML += listItem.outerHTML; 407 } 408 } 409 410 function selectSubject(e, searchList, searchWrap) { 411 const subjectInputCt = e.target.closest('.search-subject-ct'); 412 let subjectInput = null; 413 if(subjectInputCt) { 414 subjectInput = subjectInputCt.querySelector('.subject-input'); 415 } 416 417 if(subjectInput) { 418 subjectInput.dataset.subjectid = e.target.dataset.subjectid; 419 subjectInput.value = e.target.dataset.subjectname; 420 } 421 422 handleHiddenAddNew(subjectInputCt); 423 hideSearchList(searchList, searchWrap); 424 } 425 426 const searchSubjectWraps = document.querySelectorAll('.create-team-popup-ct .search-list-wrap'); 427 if(searchSubjectWraps) { 428 searchSubjectWraps.forEach(wrap => { 429 wrap.addEventListener('click', onSubjectSearchWrapClick); 430 }) 431 } 432 433 function onSubjectSearchWrapClick(e) { 434 const subjectInputCt = e.target.closest('.search-subject-ct'); 435 const searchList = subjectInputCt.querySelector(".create-team-popup-ct .search-list"); 436 const searchWrap = subjectInputCt.querySelector(".create-team-popup-ct .search-list-wrap"); 437 searchList.style.display = "none"; 438 searchWrap.style.display = "none"; 439 searchList.querySelector("ul").innerHTML = ''; 440 checkSubjectValues(); 441 } 442 443 const organizationName = document.querySelector('.create-team-popup-ct #organization'); 444 if(organizationName) { 445 organizationName.addEventListener('input', onOrganizationNameChange); 446 } 447 448 let organizationSearchTimeout; 449 function onOrganizationNameChange(e) { 450 clearTimeout(organizationSearchTimeout); 451 organizationSearchTimeout = setTimeout(() => { 452 if(!e.target.value) { 453 const similarCompaniesCt = document.querySelector('.create-team-popup-ct .similar-companies'); 454 if(similarCompaniesCt) { 455 similarCompaniesCt.classList.add('hide'); 456 const companiesList = similarCompaniesCt.querySelector('.companies-list-ct'); 457 if(companiesList) { 458 companiesList.innerHTML = ''; 459 } 460 } 461 } else { 462 util.request({ 463 url: `/hubs.json?keywords=${e.target.value}&names=1`, 464 success: (response) => { 465 const similarCompaniesCt = document.querySelector('.create-team-popup-ct .similar-companies'); 466 if(response.data.length > 0) { 467 if(similarCompaniesCt) { 468 similarCompaniesCt.classList.remove('hide'); 469 const companiesList = similarCompaniesCt.querySelector('.companies-list-ct'); 470 if(companiesList) { 471 companiesList.innerHTML = ''; 472 response.data.map(company => { 473 const companyEl = util.makeEl({tag: 'div', target: companiesList, cls: 'company-el'}); 474 util.makeEl({tag: 'p', html: company.name ? company.name : company.handle, target: companyEl, cls: 'name'}); 475 const contactEl = util.makeEl({tag: 'p', html: 'contact hub admin', target: companyEl, cls: 'contact'}); 476 contactEl.addEventListener("click", () => { 477 util.contactForm({ 478 url: `/hubs/${company.handle}/emailPointPerson.json`, 479 titleText: "Contact Admin", 480 nameInput: "requestName", 481 subjectInput: "requestSubject", 482 messageInput: "requestMessage", 483 emailInput: "requestEmail", 484 }); 485 }) 486 }) 487 } 488 } 489 } else { 490 if(similarCompaniesCt) { 491 similarCompaniesCt.classList.add('hide'); 492 } 493 } 494 } 495 }) 496 } 497 }, 1000); 498 } 499 500 // TODO: remove subject-id on subject input if value is emptied/edited 501 // remove img link when uploaded 502 const createTeamBtn = document.querySelector('.create-team-popup .util-save-btn'); 503 if(createTeamBtn) { 504 createTeamBtn.addEventListener('click', createTeam); 505 } 506 function createTeam() { 507 const createTeamBtn = document.querySelector('.create-team-popup .util-save-btn'); 508 if(createTeamBtn) { 509 util.buttonIsLoading(createTeamBtn, true, 'Creating...'); 510 } 511 const form = document.querySelector('.create-team-popup'); 512 util.removeErrors(form); 513 if(form) { 514 let formData = new FormData(form); 515 const newFormData = new FormData(); 516 newFormData.append('name', formData.get('name')); 517 newFormData.append('externalVisibility', formData.get('externalVisibility')); 518 newFormData.append('type', formData.get('type') != 'Choose' ? formData.get('type') : ''); 519 newFormData.append('color', formData.get('color')); 520 newFormData.append('terms', formData.get('terms')); 521 // newFormData.append('profileVisibility', formData.get('profileVisibility')); 522 523 524 if(formData.get('type') === 'team') { 525 newFormData.append('purpose', formData.get('purpose')); 526 } 527 528 if(formData.get('type') === 'class') { 529 newFormData.append('creatorRole', formData.get('creatorRole')); 530 newFormData.append('studentNumberRequired', formData.get('studentNumberRequired') === '1' ? '1' : '0'); 531 } else { 532 newFormData.append('studentNumberRequired', '0'); 533 } 534 535 if(formData.get('companyAvatar').size > 0) { 536 newFormData.append('companyAvatar', formData.get('companyAvatar')); 537 } else if(formData.get('avatar')) { 538 newFormData.append('avatar', formData.get('avatar')); 539 } 540 541 const subjectEls = document.querySelectorAll('.create-team-popup .search-subject-ct'); 542 let professionalSubjects = []; 543 let personalSubjects = []; 544 if(subjectEls) {
545 subjectEls.forEach(subjectEl => { 546 const input = subjectEl.querySelector('input'); 547 const persProfRadio = document.querySelector(`.create-team-popup .subject-switch[data-subjectindex="${subjectEl.dataset.subjectindex}"] input:checked`); 548 549 if(input && input.dataset.subjectid) { 550 if(persProfRadio.value === 'professional') { 551 professionalSubjects.push(input.dataset.subjectid) 552 } else if(persProfRadio.value === 'personal') { 553 personalSubjects.push(input.dataset.subjectid) 554 } 555 } 556 }) 557 } 558 559 let subjErrors = { 560 professional: false, 561 personal: false, 562 }; 563 564 let minProf = 4; 565 const contextSelect = document.querySelector('.create-team-popup select#context'); 566 if(contextSelect && contextSelect.value === 'class') { 567 minProf = 3; 568 } 569 570 if(professionalSubjects.length < minProf) { 571 subjErrors.professional = true; 572 } 573 574 if(personalSubjects.length < 1) { 575 subjErrors.personal = true; 576 } 577 578 if(professionalSubjects.length > 0) { 579 newFormData.append('professionalSubjects', professionalSubjects.join(',')); 580 } 581 582 if(personalSubjects.length > 0) { 583 newFormData.append('personalSubjects', personalSubjects.join(',')); 584 } 585 586 if(formData.get('groupings') === 'yes') { 587 let groupings = []; 588 const groupingInputs = document.querySelectorAll('.create-team-popup .groupings-list-ct input'); 589 if(groupingInputs) { 590 groupingInputs.forEach(grouping => { 591 if(grouping.value) { 592 groupings.push(grouping.value); 593 } 594 }) 595 } 596 597 if(groupings.length > 0) { 598 newFormData.append('hubRoles', groupings.join(',')); 599 } 600 } 601 602 fetch('/hubs/create.json', { 603 method: "POST", 604 body: newFormData, 605 credentials: "include" 606 }) 607 .then(res => res.json()) 608 .then(response => { 609 if(createTeamBtn) { 610 util.buttonIsLoading(createTeamBtn, false, 'Continue'); 611 } 612 if( 613 (response.formErrors && Object.keys(response.formErrors).length > 0) || 614 (subjErrors.professional || subjErrors.personal) 615 ) { 616 617 if((response.formErrors && Object.keys(response.formErrors).length > 0)) { 618 Object.keys(response.formErrors).forEach(field => { 619 if(field === 'terms') { 620 const termsCt = document.querySelector('.create-team-popup-ct .authority-checkbox-ct'); 621 if(termsCt) { 622 termsCt.insertAdjacentHTML('afterend', `<p class="util-form-error term-error">${response.formErrors[field]}</p>`); 623 } 624 } else { 625 const fieldEl = form.querySelector(`[name="${field}"]`); 626 if(fieldEl) { 627 fieldEl.insertAdjacentHTML('afterend', `<p class="util-form-error">${response.formErrors[field]}</p>`); 628 } 629 } 630 }) 631 } 632 633 const subjErrorsEl = document.querySelector('.create-team-popup-ct .subjects-errors'); 634 if(subjErrorsEl) { 635 if(subjErrors.personal) { 636 subjErrorsEl.insertAdjacentHTML('afterbegin', `<p class="util-form-error">You must choose at least one personal subject.</p>`); 637 } 638 639 if(subjErrors.professional) { 640 subjErrorsEl.insertAdjacentHTML('afterbegin', `<p class="util-form-error">You must choose at least ${minProf} professional subjects.</p>`); 641 } 642 } 643 } else if(formData.get('type') === 'class') { 644 window.location = `/hubs/${response.newTeam?.handle}/welcome` 645 } else { 646 window.location = `/hubs/${response.newTeam?.handle}` 647 } 648 }) 649 .catch(err => { 650 console.log(err) 651 }); 652 } 653 } 654 655 function handleHiddenAddNew(inputCt) { 656 const index = inputCt.dataset.subjectindex; 657 const initSubj = inputCt.dataset.initsubject; 658 const addBtn = document.querySelector('.create-team-popup-ct .add-another-subject-btn') 659 660 if(addBtn) { 661 if(index < 6) { 662 checkInitSubjFilled(index, initSubj, addBtn) 663 } else { 664 checkExtraSubjFilled(addBtn); 665 } 666 } 667 } 668 669 const initSubjsSelected = { 670 1: false, 671 2: false, 672 3: false, 673 4: false, 674 5: false, 675 }; 676 677 function checkInitSubjFilled(index, initSubj, addBtn) { 678 const contextSelect = document.querySelector('.create-team-popup-ct select[name="type"]'); 679 680 if(initSubj == 'true') { 681 initSubjsSelected[index] = true; 682 } 683 684 if(initSubjsSelected[1] && initSubjsSelected[2] && initSubjsSelected[3] && initSubjsSelected[5]) { 685 if(contextSelect) { 686 if(contextSelect.value === 'class' || initSubjsSelected[4]) { 687 addBtn.classList.remove('hide'); 688 } 689 } 690 } 691 } 692 693 function checkExtraSubjFilled(addBtn) { 694 const inputs = document.querySelectorAll('.create-team-popup-ct .extra-subject'); 695 if(inputs) {
696 const subjNotSelected = [...inputs].find(input => { 697 return !input.dataset.subjectid 698 }); 699 700 if(!subjNotSelected) { 701 addBtn.classList.remove('hide'); 702 } else { 703 addBtn.classList.add('hide'); 704 } 705 } 706 } 707});
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.