diff --git a/recruitment/templates/pipeline/components/candidate_stage_component.html b/recruitment/templates/pipeline/components/candidate_stage_component.html index 717769409..b877e70ec 100644 --- a/recruitment/templates/pipeline/components/candidate_stage_component.html +++ b/recruitment/templates/pipeline/components/candidate_stage_component.html @@ -207,24 +207,22 @@ {% endif %}
The candidate is not being moved to the next stage. Do you want to proceed?
+ + `, + icon: "warning", + showCancelButton: true, + cancelButtonColor: "#d33", + confirmButtonColor: "#008000", + confirmButtonText: "Confirm", + preConfirm: () => { + const doNotShowAgain = Swal.getPopup().querySelector('#doNotShowAgain').checked; + if (doNotShowAgain) { + sessionStorage.setItem('showRecuitmentKanbanConfirmation', 'false'); + } + } + }).then((result) => { + if (result.isConfirmed) { + handleValidDrop(targetStageId, candidateId, row, sortable); + } else { + $(sortable).sortable('cancel'); + } + }); + } else { + handleValidDrop(targetStageId, candidateId, row, sortable); + } + + } else { + handleValidDrop(targetStageId, candidateId, row, sortable); + } + } else { + handleValidDrop(targetStageId, candidateId, row, sortable); + } }, update: function (event, ui) { - array = $(this).find( - "input[type=text][name=order]:hidden" - ); - stageSelect = $(ui.item).find("[name=stage_id]"); - stageId = $(this).attr("data-stage-id"); - parent = $(this).parent(); + var array = $(this).find("input[type=text][name=order]:hidden"); + var stageSelect = $(ui.item).find("[name=stage_id]"); + var stageId = $(this).attr("data-stage-id"); + var parent = $(this).parent(); + if (stageId != stageSelect.val()) { stageSelect.val(stageId); - stageTitle = $( - `[name=stage_id] option[value=${stageId}]:first` - ).html(); - stageSelect - .next() - .find(".select2-selection__rendered") - .html(stageTitle); + var stageTitle = $(`[name=stage_id] option[value=${stageId}]:first`).html(); + stageSelect.next().find(".select2-selection__rendered").html(stageTitle); } - values = []; + + var values = []; for (let index = 0; index < array.length; index++) { values.push($(array[index]).val()); } + $.ajax({ type: "get", url: "{% url 'update-candidate-sequence' %}", @@ -523,7 +518,52 @@ }); } }); + + function handleValidDrop(stageId, candidateId, row, sortable) { + if (stageId != window.candidateCurrentStage) { + var array = $(sortable).find("input[type=text][name=order]:hidden"); + var values = []; + setTimeout(function () { + for (let index = 0; index < array.length; index++) { + values.push($(array[index]).val()); + } + $.ajax({ + type: "get", + url: "{% url 'update-candidate-stage-and-sequence' %}", + data: { + stage_id: stageId, + candidate_id: candidateId, + order: values, + }, + success: function (response) { + row.find('[name="stage_id"]').val(stageId); + Toast.fire({ + icon: "success", + title: '{% trans "Sequence updated" %}', + position: "top-end", + }); + if (response.message) { + Swal.fire({ + title: response.message, + text: `Total vacancy is ${response.vacancy}.`, + icon: "info", + confirmButtonText: "Ok", + }); + } + }, + error: function (xhr, status, error) { + Toast.fire({ + icon: "error", + title: '{% trans "Something went wrong" %}', + position: "top-end", + }); + }, + }); + }, 100); + } + } }); + $(document).on("htmx:beforeRequest", function (event) { var target = event.target; diff --git a/recruitment/templatetags/recruitmentfilters.py b/recruitment/templatetags/recruitmentfilters.py index 532e8d150..1c4016d43 100644 --- a/recruitment/templatetags/recruitmentfilters.py +++ b/recruitment/templatetags/recruitmentfilters.py @@ -5,6 +5,7 @@ This module is used to write custom template filters. """ +import json import uuid from django import template @@ -155,3 +156,11 @@ def pipeline_grouper(grouper: dict = {}): This method is used itemize the dictionary """ return grouper["title"], grouper["stages"] + + +@register.filter(name="to_json") +def to_json(value): + ordered_list = [ + {"id": val.id, "stage": val.stage, "type": val.stage_type} for val in value + ] + return json.dumps(ordered_list) diff --git a/recruitment/views/views.py b/recruitment/views/views.py index d38c4119e..b7eb2960e 100644 --- a/recruitment/views/views.py +++ b/recruitment/views/views.py @@ -825,6 +825,9 @@ def candidate_stage_update(request, cand_id): Args: id : candidate_id """ + print( + "heloooooooooooooooooooooooooooooooooooooooooooooooooo000000000000000000000000000000000000000000000000000000000000000000000000000000000" + ) stage_id = request.POST["stageId"] candidate_obj = Candidate.objects.get(id=cand_id) history_queryset = candidate_obj.history_set.all().first() diff --git a/templates/index.html b/templates/index.html index f8f708b52..59a1f0113 100755 --- a/templates/index.html +++ b/templates/index.html @@ -679,6 +679,37 @@ }, }); } + function checkSequence(element) { + var preStageId = $(element).data("stage_id") + var canIds = $(element).data("cand_id") + var stageOrderJson = $(element).attr("data-stage_order") + var stageId = $(element).val() + + var parsedStageOrder = JSON.parse(stageOrderJson); + + var stage = parsedStageOrder.find(stage => stage.id == stageId); + var preStage = parsedStageOrder.find(stage => stage.id == preStageId); + var stageOrder = parsedStageOrder.map(stage => stage.id); + + if (stageOrder.indexOf(parseInt(stageId)) != stageOrder.indexOf(parseInt(preStageId)) + 1 && stage.type != "cancelled" ) { + Swal.fire({ + title: "Confirm", + text: `Are you sure to change the candidate from ${preStage.stage} stage to ${stage.stage} stage`, + icon: 'info', + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + updateCandStage(canIds,stageId,preStageId) + } + }); + } + else { + updateCandStage(canIds,stageId,preStageId) + } + }