diff --git a/onboarding/static/onboarding_view/search.js b/onboarding/static/onboarding_view/search.js index e305851ab..836753df3 100644 --- a/onboarding/static/onboarding_view/search.js +++ b/onboarding/static/onboarding_view/search.js @@ -1,170 +1,227 @@ +function closeTag(element) { + var filterTagClass = $(element).attr("class"); + $(element).remove(); + var classArray = filterTagClass.split(" "); + var lastClass = classArray[classArray.length - 1]; + $("#" + lastClass).val(""); + if (lastClass === "job_position_id") { + $("#select2-" + lastClass + "-container").text("------------------"); + } + var button = document.querySelector( + ".oh-tabs__action-bar#filter_item button" + ); + if (button) { + button.click(); + } +} $(document).ready(function () { + function count_element() { + let stage = $(".onboarding_items"); + let count = $(".stage_count"); + let nos = []; + for (i = 0; i < stage.length; i++) { + nos.push($(stage[i]).find("[data-candidate]:visible").length); + } - function count_element () { - let stage = $(".onboarding_items") - let count = $(".stage_count") - let nos = [] - for(i=0;iSearch : ' + + search + + '' + ); + } + count_element(); + }); - $("#search").keyup(function (e) { - e.preventDefault(); - let search = $(this).val().toLowerCase(); - $(".onboarding_items").each(function () { - $(this).removeClass("d-none"); - }); - cands = $("[data-candidate]") - cands.each(function () { - var candidate = $(this).attr("data-candidate"); - if (candidate.toLowerCase().includes(search)) { - $(this).show(); - } else { - $(this).hide(); - } - }); - count_element() - }); + function job_Position() { + let search = $("#job_position_id").val().toLowerCase(); + if (search != "") { + job = $("[data-job-position]:visible"); + job.each(function () { + var candidate = $(this).attr("data-job-position"); + if (candidate.toLowerCase().includes(search)) { + $(this).show(); + } else { + $(this).hide(); + } + }); + $(".oh-filter-tag.filter-field.job_position_id").remove(); + $(".oh-filter-tag-container.filter-value").append( + 'Job position : ' + + search + + '' + ); + count_element(); + } + } + function join_date() { + let date = $("#join_date").val(); + if (date != "") { + var dateObject = new Date(date); - function job_Position (){ - let search = $("#job_position_id").val().toLowerCase() - if (search != "") { - job = $("[data-job-position]:visible") - job.each(function () { - var candidate = $(this).attr("data-job-position"); - if (candidate.toLowerCase().includes(search)) { - $(this).show(); - } else { - $(this).hide(); - } - }); - count_element() - } + var monthNames = [ + "Jan.", + "Feb.", + "March", + "April", + "May", + "June", + "July", + "Aug.", + "Sept.", + "Oct.", + "Nov.", + "Dec.", + ]; - } + var month = monthNames[dateObject.getMonth()]; + var day = dateObject.getDate(); + var year = dateObject.getFullYear(); - function join_date (){ - let date = $("#join_date").val() - if (date != "") { + var search = month + " " + day + ", " + year; + let dates = $("[data-join-date]:visible"); + dates.each(function () { + var candidate = $(this).attr("data-join-date"); - var dateObject = new Date(date); - - var monthNames = [ - "Jan.", "Feb.", "Mar.", "Apr.", "May", "June", - "July", "Aug.", "Sep.", "Oct.", "Nov.", "Dec." - ]; + if (candidate.includes(search)) { + $(this).show(); + } else { + $(this).hide(); + } + }); + $(".oh-filter-tag.filter-field.join_date").remove(); + $(".oh-filter-tag-container.filter-value").append( + 'Join date : ' + + search + + '' + ); + count_element(); + } + } - var month = monthNames[dateObject.getMonth()]; - var day = dateObject.getDate(); - var year = dateObject.getFullYear(); + function portal() { + let search = $("#portal_stage").val(); - var search = month + " " + day + ", " + year; + if (search != "") { + let portal_items = $("[data-portal-count]:visible"); + portal_items.each(function () { + var candidate = $(this).attr("data-portal-count"); + if (candidate.includes(search)) { + $(this).show(); + } else { + $(this).hide(); + } + }); + $(".oh-filter-tag.filter-field.portal_stage").remove(); + $(".oh-filter-tag-container.filter-value").append( + 'Portal stage : ' + + search + + '' + ); + count_element(); + } + } + function join_date_range() { + let start_date = $("#join_date_start").val(); + let end_date = $("#join_date_end").val(); - let dates = $("[data-join-date]:visible") - dates.each(function () { - var candidate = $(this).attr("data-join-date"); - if (candidate.includes(search)) { - $(this).show(); - } else { - $(this).hide(); - } - }); - count_element() - } - } + if (start_date || end_date) { + let visibleDates = $("[data-join-date]:visible"); - function portal(){ - let search = $("#portal_stage").val() - - if (search != "") { - let portal_items = $("[data-portal-count]:visible") - portal_items.each(function () { - var candidate = $(this).attr("data-portal-count"); - if (candidate.includes(search)) { - $(this).show(); - } else { - $(this).hide(); - } - }); - count_element() - } - } - function join_date_range() { - let start_date = $("#join_date_start").val(); - let end_date = $("#join_date_end").val(); + visibleDates.each(function () { + let candidateDateString = $(this).data("join-date"); + let candidateDate = new Date(candidateDateString); + if (!isNaN(candidateDate)) { + let showElement = true; - - - if (start_date || end_date) { - let visibleDates = $("[data-join-date]:visible"); - - visibleDates.each(function () { - let candidateDateString = $(this).data("join-date"); - let candidateDate = new Date(candidateDateString); - - if (!isNaN(candidateDate)) { - let showElement = true; + if (start_date && !end_date) { + showElement = candidateDate >= new Date(start_date); + } else if (!start_date && end_date) { + showElement = candidateDate <= new Date(end_date); + } else if (start_date && end_date) { + showElement = + candidateDate >= new Date(start_date) && + candidateDate <= new Date(end_date); + } - if (start_date && !end_date) { - showElement = candidateDate >= new Date(start_date); - } else if (!start_date && end_date) { - showElement = candidateDate <= new Date(end_date); - } else if (start_date && end_date) { - showElement = candidateDate >= new Date(start_date) && candidateDate <= new Date(end_date); - } + if (showElement) { + $(this).show(); + } else { + $(this).hide(); + } + } else { + $(this).hide(); + } + }); + count_element(); + } else { + } + $(".oh-filter-tag.filter-field.join_date_end").remove(); + $(".oh-filter-tag.filter-field.join_date_start").remove(); + if (start_date.length) { + $(".oh-filter-tag-container.filter-value").append( + 'Join date from : ' + + start_date + + '' + ); + } + if (end_date.length) { + $(".oh-filter-tag-container.filter-value").append( + 'Join date to : ' + + end_date + + '' + ); + } + } - if (showElement) { - $(this).show(); - } else { - $(this).hide(); - } - } - else { - $(this).hide(); - } - }); - - count_element(); - - } - else{ - } - } + $("#filter_item").on("click", function () { + var candidate = $("[data-job-position]"); + candidate.each(function () { + $(this).show(); + }); + $(".onboarding_items").each(function () { + $(this).removeClass("d-none"); + }); + job_Position(); + join_date(); + portal(); + join_date_range(); + }); - $("#filter_item").on("click",function(){ - var candidate = $("[data-job-position]"); - candidate.each(function () { - $(this).show(); - }) - $(".onboarding_items").each(function () { - $(this).removeClass("d-none"); - }); - job_Position(); - join_date(); - portal(); - join_date_range() + $(".oh-tabs__tab").on("click", function () { + $(".onboarding_items").each(function () { + $(this).removeClass("d-none"); + }); + job_Position(); + join_date(); + portal(); + join_date_range(); + }); - }) - - $(".oh-tabs__tab").on("click",function (){ - $(".onboarding_items").each(function () { - $(this).removeClass("d-none"); - }); - job_Position(); - join_date(); - portal(); - join_date_range() - }) - - $("#job_position_id").select2() - $("#portal_stage").select2() - -}); \ No newline at end of file + $("#job_position_id").select2(); + $("#portal_stage").select2(); +}); diff --git a/onboarding/templates/onboarding/candidate-filter.html b/onboarding/templates/onboarding/candidate-filter.html index a8585f060..6365019d1 100644 --- a/onboarding/templates/onboarding/candidate-filter.html +++ b/onboarding/templates/onboarding/candidate-filter.html @@ -41,7 +41,7 @@