1// Application global variables 2let applicationsPage = 0; 3let applicationReviewResult = ''; 4let applicationReviewText = ''; 5let applicationID = ''; 6 7// Job global variables 8let jobsPage = 0; 9let currentCategories; 10let jobID; 11 12// Job Category global variables 13let categoryID = 0; 14 15 16// Doc ready 17jQuery(document).ready(function () { 18 jQuery('.modal').modal(); 19 jQuery('.tabs').tabs(); 20 jQuery('.datepicker').datepicker({container: 'body', format: 'yyyy-mm-dd'}); 21 jQuery('.fixed-action-btn').floatingActionButton(); 22 23 jQuery("#application-search-button").click(function (e) { 24 e.preventDefault(); 25 refreshApplications(); 26 }); 27 jQuery("#job-search-button").click(function (e) { 28 e.preventDefault(); 29 refreshJobs(); 30 }); 31 jQuery("#job-add-button").click(function (e) { 32 jobID = null; 33 clearTheFields(); 34 loadCategoriesToJobEditModal(); 35 }) 36 37 jQuery("#job-edit-submit-button").click(function (e) { 38 e.preventDefault(); 39 if (jobID) { 40 editJob(); 41 } else { 42 addJob(); 43 } 44 45 }); 46 jQuery("#job-delete-submit-button").click(function (e) { 47 e.preventDefault(); 48 if (jobID) { 49 deleteJob(); 50 } 51 52 }); 53 54 jQuery("#job-category-edit-submit-button").click(function (e) { 55 e.preventDefault(); 56 if (categoryID) { 57 editCategory(); 58 } else { 59 addCategory(); 60 } 61 62 }); 63 jQuery("#job-category-delete-submit-button").click(function (e) { 64 e.preventDefault(); 65 if (categoryID) { 66 deleteCategory(); 67 } 68 69 }); 70 71 handleApplicationsItemsLogic(); 72 handleJobsItemsLogic(); 73 handleJobCategoriesItemsLogic(); 74}); 75 76// Applications Tab 77 78function handleApplicationsItemsLogic() { 79 var applicationTabContent = jQuery("#applications_tab_content"); 80 applicationTabContent.on('click', '#job-details-button', function (e) { 81 var jobId = jQuery(e.target).data('job_id'); 82 83 var jobModalContent = jQuery("#job-modal-content"); 84 jobModalContent.empty(); 85 86 jobModalContent.append( 87 '<div class="loading_container" ><div class="loading"></div></div>' 88 ); 89 jQuery.ajax({ 90 type: "post", 91 dataType: "json", 92 url: myAjax.ajaxurl, 93 data: { 94 action: "get_single_job", 95 id: jobId, 96 nonce: myAjax.nonce 97 }, 98 success: function (response) { 99 jQuery(".loading_container").empty().remove(); 100 101 var isRemote = response.fields.remote && response.fields.remote[0]; 102 var remoteTag = ''; 103 if (isRemote === true) { 104 remoteTag = '<b class ="job-tag job-remote-tag"> remote </b> '; 105 } 106 var jobTypeTag = ''; 107 if(response.fields.job_type) { 108 var jobType = response.fields.job_type[0]; 109 if (jobType === 'Full Time') { 110 jobTypeTag = '<b class="job-tag job-type-full-time-tag">Full Time</b>'; 111 } else if (jobType === 'Part Time') { 112 jobTypeTag = '<b class="job-tag job-type-part-time-tag">Part Time</b>'; 113 } 114 } 115 116 jobModalContent.append(` 117 <h4>${response.job.post_title} ${response.fields.company_name ? '(' + response.fields.company_name[0] +')': ''}</h4> 118 ${remoteTag} 119 ${jobTypeTag} 120 <p class="application-location">${response.fields.location? response.fields.location[0]: ''}</p> 121 <p>${response.job.post_content}</p> 122 `); 123 }, 124 error: function (e) { 125 alert(JSON.stringify(e)); 126 } 127 }); 128 129 }); 130 applicationTabContent.on('click', '#user-details-button', function (e) { 131 var userId = jQuery(e.target).data('user_id'); 132 133 var userModalContent = jQuery("#user-modal-content"); 134 userModalContent.empty(); 135 jQuery("#linkedin-profile-button").empty().remove(); 136 jQuery("#resume-download-button").empty().remove(); 137 138 userModalContent.append( 139 '<div class="loading_container" ><div class="loading"></div></div>' 140 ); 141 142 143 jQuery.ajax({ 144 type: "post", 145 dataType: "json", 146 url: myAjax.ajaxurl, 147 data: { 148 action: "get_single_user", 149 id: userId, 150 nonce: myAjax.nonce 151 }, 152 success: function (response) { 153 jQuery(".loading_container").empty().remove(); 154 var user = response.user; 155 156 var willingToRelocateTag = ''; 157 if (user.willing_to_relocate === "Yes") { 158 willingToRelocateTag = '<b class ="job-tag job-remote-tag"> Willing To Relocate </b> '; 159 } 160 userModalContent.append(` 161 <h4>${user.user_name}</h4> 162 163 <p class="application-location">${user.city}, ${user.state} ${willingToRelocateTag}</p> 164 <p class="application-salary">phone: <b>${user.phone}</b></p> 165 <p class="application-salary">education: <b>${user.education}</b></p> 166 <p class="application-salary">major: <b>${user.major}</b></p> 167 <p class="application-salary">
167work_auth: <b>${user.work_auth}</b></p> 168 <p class="application-salary">years_of_experience: <b> ${user.years_of_experience}</b></p> 169 <p class="application-salary">preferred_position: <b> ${user.preferred_position}</b></p> 170 <p class="application-salary">availability: <b> ${user.availability}</b></p> 171 `) 172 173 174 jQuery("#user-modal-footer").append(` 175<a id="linkedin-profile-button" class="waves-effect waves-light btn-flat" target="_blank" href="${user.linkedin_profile}">Linkedin Profile</a> 176<a id="resume-download-button" class="waves-effect waves-light btn-flat" target="_blank" href="${user.resume_file_url}">Download Resume</a> 177 `) 178 179 }, 180 error: function (e) { 181 alert(JSON.stringify(e)); 182 } 183 }); 184 }); 185 186 applicationTabContent.on('click', '#reject-button', function (e) { 187 jQuery('#review-modal-textarea').val(null); 188 applicationReviewResult = 'rejected'; 189 applicationID = jQuery(e.target).data('application_id'); 190 }); 191 applicationTabContent.on('click', '#accept-button', function (e) { 192 jQuery('#review-modal-textarea').val(null); 193 applicationReviewResult = 'accepted'; 194 applicationID = jQuery(e.target).data('application_id'); 195 }); 196 197 jQuery("#review-modal-send-button").click(function (e) { 198 e.preventDefault(); 199 //Send applicationReviewResult, applicationReviewText, and applicationID to ajax backend 200 _changeApplicationStatus(); 201 202 //Change related application request status tag 203 _changeApplicationStatusTag(); 204 }) 205 206 jQuery("#load-more-button").click(function (e) { 207 e.preventDefault(); 208 applicationsPage++; 209 searchApplications(); 210 }); 211} 212 213function refreshApplications() { 214 applicationsPage = 0; 215 jQuery(".results_content").empty(); 216 searchApplications(); 217} 218 219function searchApplications() { 220 var loadMoreButton = jQuery('#load-more-button'); 221 if (loadMoreButton?.length) { 222 loadMoreButton.empty().remove(); 223 } 224 225 jQuery(".results_content").append( 226 '<div class="loading_container" ><div class="loading"></div></div>' 227 ); 228 jQuery.ajax({ 229 type: "post", 230 dataType: "json", 231 url: myAjax.ajaxurl, 232 data: { 233 action: "search_applications", 234 job: jQuery('#job-search-field').val(), 235 user: jQuery('#user-search-field').val(), 236 category: jQuery('#job-category-search-field').val(), 237 company: jQuery('#company-search-field').val(), 238 status: jQuery('#status-search-field').val(), 239 sort: jQuery('#sort-search-field').val(), 240 nonce: myAjax.nonce, 241 page: applicationsPage 242 }, 243 success: function (response) { 244 jQuery(".loading_container").empty().remove(); 245 var applicationsList = generateApplicationsList(response.applications); 246 var isLastPage = response.isLastPage; 247 var resultsContent = jQuery(".results_content"); 248 resultsContent.append(applicationsList); 249 250 if (isLastPage !== true) { 251 resultsContent.append(`<a href="#!" id="load-more-button" class="waves-effect waves-dark btn-flat">Load More</a>`); 252 } 253 }, 254 error: function (e) { 255 alert(JSON.stringify(e)); 256 } 257 }); 258} 259 260function generateApplicationsList(applications) { 261 var applicationsList = ''; 262 applications.forEach(application => { 263 applicationsList += generateApplicationsRow(application); 264 }); 265 return applicationsList; 266} 267 268function generateApplicationsRow(application) { 269 270 var status = application.meta.application_state[0]; 271 var statusText; 272 var statusClass; 273 if (status === "requested") { 274 statusText = 'Waiting For Review'; 275 statusClass = 'application-requested-tag'; 276 } else if (status === "accepted") { 277 statusText = 'Accepted'; 278 statusClass = 'application-accepted-tag'; 279 } else if (status === "rejected") { 280 statusText = 'Rejected'; 281 statusClass = 'application-rejected-tag'; 282 } 283 var applicationData = ` 284<div class="card"> 285 <div class="card-content">
286 <span class="card-title"> ${application.meta.job_title[0]} ${application.meta.company_name ? '('+ application.meta.company_name[0] +')' : ''}</span> 287 <p class="application-location">${application.meta.location ? application.meta.location[0] : ''} <b id="application-status-tag-${application.post.ID}" class="application-tag ${statusClass}"> ${statusText}</b></p> 288 <p class="application-salary">Applicant: <b>${application.meta.user_name[0]}</b></p> 289 <p class="application-salary">Preferred Salary Type: <b>${application.meta.preferred_salary_type[0]}</b></p> 290 <p class="application-salary">Preferred Salary: <b>$ ${application.meta.preferred_salary[0]}</b></p> 291 </div> 292 <div class="card-action"> 293 <a data-target="job-modal" data-job_id="${application.meta.job_id[0]}" class="waves-effect waves-dark btn-flat modal-trigger iv-outlined-button" id="job-details-button">Job Details</a> 294 <a data-target="user-modal" data-user_id="${application.meta.user_id[0]}" class="waves-effect waves-dark btn-flat modal-trigger iv-outlined-button" id="user-details-button">User Details</a> 295 <a data-target="review-modal" data-application_id="${application.post.ID}" class="waves-effect waves-light btn modal-trigger iv-button" id="accept-button">Accept</a> 296 <a data-target="review-modal" data-application_id="${application.post.ID}" class="waves-effect waves-light btn modal-trigger iv-button" id="reject-button">Reject</a> 297 </div> 298</div> 299 `; 300 return applicationData; 301} 302 303function _changeApplicationStatusTag() { 304 var applicationStatusTag = jQuery("#application-status-tag-" + applicationID); 305 applicationStatusTag.empty(); 306 if (applicationReviewResult === 'accepted') { 307 applicationStatusTag.append('Accepted') 308 applicationStatusTag.css("background-color", "green"); 309 } else { 310 applicationStatusTag.append('Rejected') 311 applicationStatusTag.css("background-color", "red"); 312 } 313 314 applicationStatusTag.css("color", "white"); 315} 316 317function _changeApplicationStatus() { 318 jQuery.ajax({ 319 type: "post", 320 dataType: "json", 321 url: myAjax.ajaxurl, 322 data: { 323 action: "review_application", 324 id: applicationID, 325 result: applicationReviewResult, 326 text: jQuery('#review-modal-textarea').val(), 327 nonce: myAjax.nonce 328 }, 329 success: function (response) { 330 M.toast({html: 'Application reviewed successfully!', classes: 'rounded success-toast'}) 331 }, 332 error: function (e) { 333 alert(JSON.stringify(e)); 334 } 335 }); 336 337} 338 339// Jobs Tab 340 341function handleJobsItemsLogic() { 342 jQuery("#load-more-jobs-button").click(function (e) { 343 e.preventDefault(); 344 jobsPage++; 345 searchJobs(); 346 }); 347 348 var applicationTabContent = jQuery("#job_tab_content"); 349 applicationTabContent.on('click', '#job-edit-button', function (e) { 350 jobID = jQuery(e.target).data('job_id'); 351 352 var jobModalContent = jQuery("#job-edit-modal-content"); 353 jobModalContent.empty(); 354 355 jobModalContent.append( 356 '<div class="loading_container" ><div class="loading"></div></div>' 357 ); 358 initEditJobModal(jobModalContent); 359 }); 360 361 applicationTabContent.on('click', '#job-delete-button', function (e) { 362 jobID = jQuery(e.target).data('job_id'); 363 }); 364 365 366} 367 368function refreshJobs() { 369 jobsPage = 0; 370 jQuery(".job_results_content").empty(); 371 searchJobs(); 372} 373 374function searchJobs() { 375 var loadMoreButton = jQuery('#load-more-jobs-button'); 376 if (loadMoreButton?.length) { 377 loadMoreButton.empty().remove(); 378 } 379 380 jQuery(".job_results_content").append( 381 '<div class="loading_container" ><div class="loading"></div></div>' 382 ); 383 var sort = jQuery('#job-sort-search-field').val(); 384 jQuery.ajax({ 385 type: "post", 386 dataType: "json", 387 url: myAjax.ajaxurl, 388 data: { 389 action: "search_jobs", 390 job: jQuery('#job-title-search-field').val(), 391 category: jQuery('#job-job-category-search-field').val(), 392 company: jQuery('#job-company-search-field').val(), 393 sort: sort ? sort : 'DESC', 394 nonce: myAjax.nonce,
395 page: jobsPage 396 }, 397 success: function (response) { 398 jQuery(".loading_container").empty().remove(); 399 var applicationsList = generateJobsList(response.jobs); 400 var isLastPage = response.isLastPage; 401 var resultsContent = jQuery(".job_results_content"); 402 resultsContent.append(applicationsList); 403 404 if (isLastPage !== true) { 405 resultsContent.append(`<a href="#!" id="load-more-jobs-button" class="waves-effect waves-dark btn-flat">Load More</a>`); 406 } 407 }, 408 error: function (e) { 409 alert(JSON.stringify(e)); 410 } 411 }); 412} 413 414function generateJobsList(job) { 415 var jobsList = ''; 416 job.forEach(job => { 417 jobsList += generateJobsRow(job); 418 }); 419 return jobsList; 420} 421 422function generateJobsRow(job) { 423 424 var jobShortDescription = ''; 425 if (job.post.post_content) { 426 let strippedContent = job.post.post_content.replace(/(<([^>]+)>)/gi, ""); 427 428 if (strippedContent.length > 300) { 429 jobShortDescription = strippedContent.slice(0, 300) + ' ...'; 430 } else { 431 jobShortDescription = strippedContent; 432 } 433 } 434 var jobTypeTag = ''; 435 var jobRemoteTag = ''; 436 437 var isRemote = job.meta.remote && job.meta.remote[0] == 'on'; 438 var remoteTag = ''; 439 if (isRemote === true) { 440 remoteTag = '<b class ="job-tag job-remote-tag"> remote </b> '; 441 } 442 443 if(job.meta.job_type) { 444 var jobType = job.meta.job_type[0]; 445 if (jobType === 'Full Time') { 446 jobTypeTag = '<b class="job-tag job-type-full-time-tag">Full Time</b>'; 447 } else if (jobType === 'Part Time') { 448 jobTypeTag = '<b class="job-tag job-type-part-time-tag">Part Time</b>'; 449 } 450 } 451 452 var jobData = ` 453<div class="card job-${job.post.ID}"> 454 <div class="card-content"> 455 <span class="card-title"> ${job.post.post_title}</span> 456 <p class="application-location">${job.meta.location ? job.meta.location[0] : ''} ${job.meta.company_name ? ', ' + job.meta.company_name[0] : ''} ${remoteTag} ${jobTypeTag}</p> 457 <p>${jobShortDescription}</p> 458 </div> 459 <div class="card-action"> 460 <a data-target="job-edit-modal" data-job_id="${job.post.ID}" class="waves-effect waves-light btn modal-trigger iv-button" id="job-edit-button">Edit</a> 461 <a data-target="job-delete-modal" data-job_id="${job.post.ID}" style="background-color: darkred; color: white" class="waves-effect waves-light btn modal-trigger iv-button" id="job-delete-button">Delete</a> 462 </div> 463</div> 464 `; 465 return jobData; 466} 467 468/// Add Job Codes 469 470function loadCategoriesToJobEditModal() { 471 let jobEditCategory = jQuery('#job-edit-category'); 472 jobEditCategory.empty(); 473 let options = ""; 474 if (currentCategories) { 475 options += `<option value="" disabled selected>Choose your option</option>`; 476 477 currentCategories.forEach(function (tax) { 478 options += `<option value="${tax.term_taxonomy_id}">${tax.name}</option>`; 479 }); 480 481 jobEditCategory.append(options); 482 jobEditCategory.formSelect(); 483 484 } 485 486} 487 488function clearTheFields() { 489 jQuery('#job-edit-title').val(null); 490 jQuery('#job-edit-descriptions').val(null); 491 jQuery('#job-edit-category').val(null); 492 jQuery('#job-edit-company').val(null); 493 jQuery('#job-edit-location').val(null); 494 jQuery('#job-edit-expiry-date').val(null); 495 jQuery('#job-edit-featured').val(null); 496 jQuery('#job-edit-remote').val(null); 497 jQuery('#job-edit-type').val(null); 498 499} 500 501function addJob() { 502 503 /// Checks required values 504 const jobTitleValue = jQuery('#job-edit-title').val(); 505 const jobDescriptionsValue = jQuery('#job-edit-descriptions').val(); 506 507 if(!jobTitleValue || !jobDescriptionsValue ) { 508 if(!jobTitleValue) { 509 M.toast({html: 'Title is required!', classes: 'rounded warning-toast'}) 510 } 511 if(!jobDescriptionsValue) { 512 M.toast({html: 'Descriptions is required!', classes: 'rounded warning-toast'}) 513 } 514 return; 515 } 516 517 /// Initiates loading 518 M.toast({html: 'Adding the new job ...', classes: 'rounded info-toast'}); 519 520 521 /// Adds the job 522 const categories = jQuery('#job-edit-category').val(); 523 524 jQuery.ajax({ 525 type: "post", 526 dataType: "json", 527 url: myAjax.ajaxurl, 528 data: { 529 action: "add_job", 530 post_title: jobTitleValue, 531 categories: categories, 532 post_content: jobDescriptionsValue, 533 company_name: jQuery('#job-edit-company').val(), 534 location: jQuery('#job-edit-location').val(), 535 expiry_date: jQuery('#job-edit-expiry-date').val(), 536 featured: jQuery('#job-edit-featured').val(), 537 remote: jQuery('#job-edit-remote').val(), 538 job_type: jQuery('#job-edit-type').val(), 539 nonce: myAjax.nonce,
540 page: jobsPage 541 }, 542 success: function (response) { 543 M.toast({html: 'Job added successfully!', classes: 'rounded success-toast'}) 544 refreshJobs(); 545 }, 546 error: function (e) { 547 M.toast({html: JSON.stringify(e), classes: 'rounded error-toast'}) 548 } 549 }); 550 551} 552 553/// Edit Job Codes 554function initEditJobModal(jobModalContent) { 555 jQuery.ajax({ 556 type: "post", 557 dataType: "json", 558 url: myAjax.ajaxurl, 559 data: { 560 action: "get_single_job", 561 id: jobID, 562 nonce: myAjax.nonce 563 }, 564 success: function (response) { 565 jQuery(".loading_container").empty().remove(); 566 567 var jobDescription = ''; 568 if (response.job.post_content) { 569 jobDescription = response.job.post_content.toString().replace(/(<([^>]+)>)/gi, ""); 570 } 571 572 jobModalContent.append(` 573 <div class="row"> 574 <!--text input start--> 575 <div class="input-field col m4 s12"> 576 <input value="${response.job.post_title}" id="job-edit-title" type="text"> 577 <label for="job-edit-title">Title</label> 578 </div> 579 <!--text input end--> 580 <!--text input start--> 581 <div class="input-field col m4 s12"> 582 <input value="${response.fields.location ? response.fields.location : ''}" id="job-edit-location" type="text"> 583 <label for="job-edit-location">Location</label> 584 </div> 585 <!--text input end--> 586 <!--text input start--> 587 <div class="input-field col m4 s12"> 588 <input value="${response.fields.company_name ? response.fields.company_name : ''}" id="job-edit-company" type="text"> 589 <label for="job-edit-company">Company</label> 590 </div> 591 <!--text input end--> 592 <!--text input start--> 593 <div class="input-field col m12 s12"> 594 <select id="job-edit-category" multiple> 595 </select> 596 <label for="job-edit-category">Category</label> 597 </div> 598 <!--text input end--> 599 <!--text input start--> 600 <div class="input-field col m4 s12"> 601 <input value="${response.fields.expiry_date ? response.fields.expiry_date : ''}" id="job-edit-expiry-date" type="text" class="datepicker"> 602 <label for="job-edit-expiry-date">Expiry Date</label> 603 </div> 604 <!--text input end--> 605 <div class="input-field col m4 s12"> 606 <select id="job-edit-type"> 607 </select> 608 <label for="job-edit-type">Job Type</label> 609 </div> 610 611 <!--text input end--> 612 <div class="input-field col m2 s12"> 613 <label> 614 <input ${response.fields.remote?.toString() === "on" ? 'checked' : ''} id="job-edit-remote" class="checkbox-custom-color" type="checkbox" /> 615 <span>Remote</span> 616 </label> 617 </div> 618 619 <!--text input end--> 620 <div class="input-field col m2 s12"> 621 <label> 622 <input ${response.fields.featured?.toString() === "on" ? 'checked' : ''} id="job-edit-featured" class="checkbox-custom-color" type="checkbox" /> 623 <span>Featured</span> 624 </label> 625 </div> 626 </div> 627 <div class="section row"> 628 <div class="input-field col s12"> 629 <textarea value="${jobDescription}" id="job-edit-descriptions" class="materialize-textarea">${jobDescription}</textarea> 630 <label for="job-edit-descriptions">Descriptions</label> 631 </div> 632 </div> 633 `); 634 635 loadSelectedCategoriesToJobEditModal(response.categories); 636 loadSelectedJobTypeToJobEditModal(response.fields.job_type); 637 638 jQuery('#job-edit-expiry-date').datepicker({container: 'body', format: 'yyyy-mm-dd'}); 639 M.updateTextFields(); 640 M.textareaAutoResize(jQuery('#job-edit-descriptions')); 641 642 }, 643 error: function (e) { 644 alert(JSON.stringify(e)); 645 } 646 }); 647 648} 649 650function loadSelectedJobTypeToJobEditModal(jobType) { 651 try { 652 let jobEditType = jQuery('#job-edit-type'); 653 654 let jobEditTypeOptions = ''; 655 656 if (jobType?.toString() === "Full Time") { 657 jobEditTypeOptions += '<option value="Full Time" selected>Full Time</option>'; 658 } else { 659 jobEditTypeOptions += '<option value="Full Time">Full Time</option>'; 660 } 661 662 if (jobType?.toString() === "Part Time") { 663 jobEditTypeOptions += '<option value="Part Time" selected>
663Part Time</option>'; 664 } else { 665 jobEditTypeOptions += '<option value="Part Time">Part Time</option>'; 666 } 667 668 jobEditType.append(jobEditTypeOptions); 669 670 jobEditType.formSelect(); 671 } catch (e) { 672 alert(e) 673 } 674} 675 676function loadSelectedCategoriesToJobEditModal(selectedTaxonomies) { 677 let jobEditCategory = jQuery('#job-edit-category'); 678 let options = ""; 679 if (currentCategories) { 680 currentCategories.forEach(function (tax) { 681 682 const isSelected = selectedTaxonomies && checkIfTaxonomySelected(selectedTaxonomies, tax); 683 if (isSelected) { 684 options += `<option value="${tax.term_taxonomy_id}" selected>${tax.name}</option>`; 685 } else { 686 options += `<option value="${tax.term_taxonomy_id}">${tax.name}</option>`; 687 } 688 }); 689 690 jobEditCategory.append(options); 691 jobEditCategory.formSelect(); 692 } 693 694} 695 696function checkIfTaxonomySelected(selectedTaxonomies, tax) { 697 let found = false; 698 for (let i = 0; i < selectedTaxonomies.length; i++) { 699 if (selectedTaxonomies[i].term_id === tax.term_id) { 700 found = true; 701 break; 702 } 703 } 704 return found; 705} 706 707function editJob() { 708 const categories = jQuery('#job-edit-category').val(); 709 const args = { 710 action: "edit_job", 711 id: jobID, 712 post_title: jQuery('#job-edit-title').val(), 713 categories: categories, 714 post_content: jQuery('#job-edit-descriptions').val(), 715 company_name: jQuery('#job-edit-company').val(), 716 location: jQuery('#job-edit-location').val(), 717 expiry_date: jQuery('#job-edit-expiry-date').val(), 718 featured: jQuery('#job-edit-featured').val(), 719 remote: jQuery('#job-edit-remote').val(), 720 job_type: jQuery('#job-edit-type').val(), 721 nonce: myAjax.nonce, 722 page: jobsPage 723 }; 724 725 //Change related job's data on the list 726 editJobClientSide(args); 727 728 jobID = null; 729 730 //Change related job's data on the server 731 editJobServerSide(args) 732} 733 734function editJobClientSide(args) { 735 let selectedJobNode = jQuery('.job-' + jobID); 736 selectedJobNode.empty(); 737 738 var jobShortDescription = ''; 739 if (args.post_content) { 740 let strippedContent = args.post_content.replace(/(<([^>]+)>)/gi, ""); 741 742 if (strippedContent.length > 300) { 743 jobShortDescription = strippedContent.slice(0, 300) + ' ...'; 744 } else { 745 jobShortDescription = strippedContent; 746 } 747 } 748 749 var isRemote = args.remote.toString() === 'on'; 750 var remoteTag = ''; 751 if (isRemote === true) { 752 remoteTag = '<b class ="job-tag job-remote-tag"> remote </b> '; 753 } 754 var jobType = args.job_type; 755 var jobTypeTag = ''; 756 if (jobType === 'Full Time') { 757 jobTypeTag = '<b class="job-tag job-type-full-time-tag">Full Time</b>'; 758 } else if (jobType === 'Part Time') { 759 jobTypeTag = '<b class="job-tag job-type-part-time-tag">Part Time</b>'; 760 } 761 762 selectedJobNode.append(` 763<!--<div class="card job-${jobID}">--> 764 765 <div class="card-content"> 766 <span class="card-title"> ${args.post_title}</span> 767 <p class="application-location">${args.location ? args.location : ''}, ${args.company_name ? ', '+args.company_name : ''} ${remoteTag} ${jobTypeTag}</p> 768 <p>${jobShortDescription}</p> 769 </div> 770 <div class="card-action"> 771 <a data-target="job-edit-modal" data-job_id="${jobID}" class="waves-effect waves-light btn modal-trigger iv-button" id="job-edit-button">Edit</a> 772 </div> 773<!-- </div>--> 774 `); 775 776} 777 778function editJobServerSide(args) { 779 780 jQuery.ajax({ 781 type: "post", 782 dataType: "json", 783 url: myAjax.ajaxurl, 784 data: args, 785 success: function (response) { 786 M.toast({html: 'Job edited successfully!', classes: 'rounded success-toast'}) 787 }, 788 error: function (e) { 789 alert(JSON.stringify(e)) 790 } 791 }); 792 793} 794 795/// Delete Job Codes 796function deleteJob() { 797 const args = { 798 action: "delete_job", 799 id: jobID, 800 nonce: myAjax.nonce,
801 page: jobsPage 802 }; 803 804 deleteJobClientSide(args); 805 806 jobID = null; 807 808 deleteJobServerSide(args); 809} 810 811function deleteJobClientSide(args) { 812 let selectedJobNode = jQuery('.job-' + jobID); 813 selectedJobNode.empty().remove(); 814 815} 816 817function deleteJobServerSide(args) { 818 819 jQuery.ajax({ 820 type: "post", 821 dataType: "json", 822 url: myAjax.ajaxurl, 823 data: args, 824 success: function (response) { 825 M.toast({html: 'Job deleted successfully!', classes: 'rounded success-toast'}) 826 }, 827 error: function (e) { 828 alert(JSON.stringify(e)) 829 } 830 }); 831 832} 833 834// Jobs Tab 835 836function handleJobCategoriesItemsLogic() { 837 838 var applicationTabContent = jQuery("#job_category_tab_content"); 839 applicationTabContent.on('click', '#job-category-edit-button', function (e) { 840 categoryID = jQuery(e.target).data('term_id'); 841 842 var jobCategoryModalContent = jQuery("#job-category-edit-modal-content"); 843 jobCategoryModalContent.empty(); 844 845 jobCategoryModalContent.append( 846 '<div class="loading_container" ><div class="loading"></div></div>' 847 ); 848 initEditJobCategoryModal(jobCategoryModalContent); 849 }); 850 851 applicationTabContent.on('click', '#job-category-delete-button', function (e) { 852 categoryID = jQuery(e.target).data('term_id'); 853 }); 854} 855 856// Add category Codes 857function addCategory() { 858 859 /// Checks required values 860 const jobCategoryTitleValue = jQuery('#job-category-edit-title').val(); 861 const jobCategorySlugValue = jQuery('#job-category-edit-slug').val(); 862 863 if(!jobCategoryTitleValue || !jobCategorySlugValue ) { 864 if(!jobCategoryTitleValue) { 865 M.toast({html: 'Title is required!', classes: 'rounded warning-toast'}) 866 } 867 if(!jobCategorySlugValue) { 868 M.toast({html: 'Slug is required!', classes: 'rounded warning-toast'}) 869 } 870 return; 871 } 872 873 /// Initiates loading 874 M.toast({html: 'Adding the new category ...', classes: 'rounded info-toast'}) 875 876 /// Adds the category 877 jQuery.ajax({ 878 type: "post", 879 dataType: "json", 880 url: myAjax.ajaxurl, 881 data: { 882 action: "add_category", 883 name: jobCategoryTitleValue, 884 slug: jobCategorySlugValue, 885 nonce: myAjax.nonce, 886 page: jobsPage 887 }, 888 success: function (response) { 889 M.toast({html: 'Job category added successfully!', classes: 'rounded success-toast'}) 890 refreshJobCategories() 891 }, 892 error: function (e) { 893 M.toast({html: JSON.stringify(e), classes: 'rounded error-toast'}) 894 } 895 }); 896 897} 898 899// Edit category Codes 900function initEditJobCategoryModal(jobCategoryModalContent) { 901 jQuery.ajax({ 902 type: "post", 903 dataType: "json", 904 url: myAjax.ajaxurl, 905 data: { 906 action: "get_single_category", 907 id: categoryID, 908 nonce: myAjax.nonce 909 }, 910 success: function (response) { 911 jQuery(".loading_container").empty().remove(); 912 913 jobCategoryModalContent.append(` 914 <div class="row"> 915 <!--text input start--> 916 <div class="input-field col m6 s12"> 917 <input value="${response.data.name?.toString()}" id="job-category-edit-title" type="text"> 918 <label for="job-category-edit-title">Title</label> 919 </div> 920 <!--text input end--> 921 <!--text input start--> 922 <div class="input-field col m6 s12"> 923 <input value="${response.data.slug?.toString()}" id="job-category-edit-slug" type="text"> 924 <label for="job-category-edit-slug">Slug</label> 925 </div> 926 <!--text input end--> 927 </div> 928 `); 929 930 M.updateTextFields(); 931 932 }, 933 error: function (e) { 934 alert(JSON.stringify(e)); 935 } 936 }); 937 938} 939 940function editCategory() { 941 const args = { 942 action: "edit_category", 943 id: categoryID, 944 name: jQuery('#job-category-edit-title').val(), 945 slug: jQuery('#job-category-edit-slug').val(), 946 nonce: myAjax.nonce,
947 page: jobsPage 948 }; 949 950 let selectedJobNode = jQuery('.category-' + categoryID); 951 952 selectedJobNode.empty(); 953 954 selectedJobNode.append(` 955<!--<div class="card category-${categoryID}">--> 956 <div class="card-content"> 957 <span class="card-title"> ${args.name}</span> 958 </div> 959 <div class="card-action"> 960 <a data-target="job-category-edit-modal" data-term_id="${categoryID}" class="waves-effect waves-light btn modal-trigger iv-button" id="job-category-edit-button">Edit</a> 961 <a data-target="job-category-delete-modal" data-term_id="${categoryID}" style="background-color: darkred; color: white" class="waves-effect waves-light btn modal-trigger iv-button" id="job-category-delete-button">Delete</a> 962 </div> 963<!--</div>--> 964 `); 965 966 jQuery.ajax({ 967 type: "post", 968 dataType: "json", 969 url: myAjax.ajaxurl, 970 data: args, 971 success: function (response) { 972 M.toast({html: 'Job category edited successfully!', classes: 'rounded success-toast'}) 973 }, 974 error: function (e) { 975 alert(JSON.stringify(e)) 976 } 977 }); 978} 979 980// Delete category Codes 981function deleteCategory() { 982 const args = { 983 action: "delete_category", 984 id: categoryID, 985 nonce: myAjax.nonce, 986 }; 987 988 let selectedJobNode = jQuery('.category-' + categoryID); 989 selectedJobNode.empty().remove(); 990 991 categoryID = null; 992 993 jQuery.ajax({ 994 type: "post", 995 dataType: "json", 996 url: myAjax.ajaxurl, 997 data: args, 998 success: function (response) { 999 M.toast({html: 'Job category deleted successfully!', classes: 'rounded success-toast'}) 1000 }, 1001 error: function (e) { 1002 alert(JSON.stringify(e)) 1003 } 1004 }); 1005} 1006 1007/// Refresh categories list 1008function refreshJobCategories() { 1009 jQuery('#job_category_tab_content').empty(); 1010 getJobCategories(); 1011} 1012 1013function getJobCategories() { 1014 jQuery.ajax({ 1015 type: "post", 1016 dataType: "json", 1017 url: myAjax.ajaxurl, 1018 data: { 1019 action: "get_job_categories", 1020 nonce: myAjax.nonce, 1021 page: jobsPage 1022 }, 1023 success: function (response) { 1024 currentCategories = response.data; 1025 jQuery('#job_category_tab_content').append(`${generateJobCategoriesList(currentCategories)}`); 1026 1027 }, 1028 error: function (e) { 1029 } 1030 }) 1031} 1032 1033function generateJobCategoriesList(childParentCategories) { 1034 var categoriesList = ''; 1035 childParentCategories.forEach(category => { 1036 categoriesList += generateJobCategoryRow(category); 1037 }); 1038 return categoriesList; 1039} 1040 1041function generateJobCategoryRow(category) { 1042 1043 var categoryData = ` 1044<div class="card category-${category.term_id}"> 1045 <div class="card-content"> 1046 <span class="card-title"> ${category.name}</span> 1047 </div> 1048 <div class="card-action"> 1049 <a data-target="job-category-edit-modal" data-term_id="${category.term_id}" class="waves-effect waves-light btn modal-trigger iv-button" id="job-category-edit-button">Edit</a> 1050 <a data-target="job-category-delete-modal" data-term_id="${category.term_id}" style="background-color: darkred; color: white" class="waves-effect waves-light btn modal-trigger iv-button" id="job-category-delete-button">Delete</a> 1051 </div> 1052</div> 1053 `; 1054 return categoryData; 1055}
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.