From cd199a85c8e891c9afe4ebfedf7bbd24e983b6ad Mon Sep 17 00:00:00 2001 From: Horilla Date: Fri, 17 Nov 2023 16:47:05 +0530 Subject: [PATCH] [UPDT] PMS: Selection updation in objective list and group view --- pms/static/src/okr/action.js | 306 ++++++++++++++++++--- pms/templates/okr/group_by.html | 190 ++++++++++--- pms/templates/okr/objective_list.html | 128 ++++++--- pms/templates/okr/objective_list_view.html | 3 + pms/urls.py | 10 + pms/views.py | 51 ++++ 6 files changed, 569 insertions(+), 119 deletions(-) diff --git a/pms/static/src/okr/action.js b/pms/static/src/okr/action.js index 51c6f0941..c14984acd 100644 --- a/pms/static/src/okr/action.js +++ b/pms/static/src/okr/action.js @@ -30,51 +30,267 @@ var norowMessages = { fr: "Aucune ligne n'a été sélectionnée.", }; +var rowMessages = { + ar: " تم الاختيار", + de: " Ausgewählt", + es: " Seleccionado", + en: " Selected", + fr: " Sélectionné", +}; + +tickObjectivesCheckboxes(); +function makeObjectivesListUnique(list) { + return Array.from(new Set(list)); +} $(".all-objects").change(function (e) { var is_checked = $(this).is(":checked"); if (is_checked) { - $(".all-objects-row").prop("checked", true); + $(".all-objects-row").prop("checked", true) + .closest(".oh-sticky-table__tr") + .addClass("highlight-selected"); } else { - $(".all-objects-row").prop("checked", false); + $(".all-objects-row").prop("checked", false) + .closest(".oh-sticky-table__tr") + .removeClass("highlight-selected"); } }); $(".own-objects").change(function (e) { var is_checked = $(this).is(":checked"); if (is_checked) { - $(".own-objects-row").prop("checked", true); + $(".own-objects-row").prop("checked", true) + .closest(".oh-sticky-table__tr") + .addClass("highlight-selected"); } else { - $(".own-objects-row").prop("checked", false); + $(".own-objects-row").prop("checked", false) + .closest(".oh-sticky-table__tr") + .removeClass("highlight-selected"); } }); function getCookie(name) { - let cookieValue = null; - if (document.cookie && document.cookie !== "") { - const cookies = document.cookie.split(";"); - for (let i = 0; i < cookies.length; i++) { - const cookie = cookies[i].trim(); - // Does this cookie string begin with the name we want? - if (cookie.substring(0, name.length + 1) === name + "=") { - cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); - break; - } + let cookieValue = null; + if (document.cookie && document.cookie !== "") { + const cookies = document.cookie.split(";"); + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i].trim(); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) === name + "=") { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; } } - return cookieValue; } - - function getCurrentLanguageCode(callback) { + return cookieValue; +} + +function getCurrentLanguageCode(callback) { + $.ajax({ + type: "GET", + url: "/employee/get-language-code/", + success: function (response) { + var languageCode = response.language_code; + callback(languageCode); // Pass the language code to the callback + }, + }); +} + + +function tickObjectivesCheckboxes() { + var ids = JSON.parse($("#selectedObjectives").attr("data-ids") || "[]"); + uniqueIds = makeObjectivesListUnique(ids); + toggleHighlight(uniqueIds); + click = $("#selectedObjectives").attr("data-clicked"); + if (click === "1") { + var tableName = localStorage.getItem('activeTabPms'); + if (tableName === '#tab_1'){ + tableName = 'self' + $('.own-objects').prop('checked',true) + } + else{ + tableName = 'all' + $('.all-objects').prop('checked',true) + $('.own-objects').prop('checked',true) + } + } + uniqueIds.forEach(function (id) { + $("#" + id).prop("checked", true).closest(".oh-sticky-table__tr") + .addClass("highlight-selected"); + }); + var selectedCount = uniqueIds.length; + getCurrentLanguageCode(function (code) { + languageCode = code; + var message = rowMessages[languageCode]; + if (selectedCount > 0) { + $("#exportObjectives").css("display", "inline-flex"); + $("#selectedShowObjectives").css("display", "inline-flex"); + $("#selectedShowObjectives").text(selectedCount + " -" + message); + } else { + $("#selectedShowObjectives").css("display", "none"); + $("#exportObjectives").css("display", "none"); + } + }); +} + +function addingObjectivesIds() { + var ids = JSON.parse($("#selectedObjectives").attr("data-ids") || "[]"); + var selectedCount = 0; + var tableName = localStorage.getItem('activeTabPms'); + if (tableName === '#tab_1'){ + tableName = 'self' + $(".own-objects-row").each(function () { + if ($(this).is(":checked")) { + ids.push(this.id); + } else { + var index = ids.indexOf(this.id); + if (index > -1) { + ids.splice(index, 1); + } + } + }); + } + else{ + tableName = 'all' + $(".all-objects-row").each(function () { + if ($(this).is(":checked")) { + ids.push(this.id); + } else { + var index = ids.indexOf(this.id); + if (index > -1) { + ids.splice(index, 1); + } + } + }); + } + + ids = makeObjectivesListUnique(ids); + selectedCount = ids.length; + + getCurrentLanguageCode(function (code) { + languageCode = code; + var message = rowMessages[languageCode]; + $("#selectedObjectives").attr("data-ids", JSON.stringify(ids)); + if (selectedCount === 0) { + $("#selectedShowObjectives").css("display", "none"); + $("#exportObjectives").css("display", "none"); + } else { + $("#exportObjectives").css("display", "inline-flex"); + $("#selectedShowObjectives").css("display", "inline-flex"); + $("#selectedShowObjectives").text(selectedCount + " - " + message); + } + }); +} + +function selectAllObjectives() { + $("#selectedObjectives").attr("data-clicked", 1); + $("#selectedShowObjectives").removeAttr("style"); + var savedFilters = JSON.parse(localStorage.getItem("savedFilters")); + var tableName = localStorage.getItem('activeTabPms'); + if (tableName === '#tab_1'){ + tableName = 'self' + $('.own-objects').prop('checked',true) + } + else{ + tableName = 'all' + $('.all-objects').prop('checked',true) + $('.own-objects').prop('checked',true) + } + if (savedFilters && savedFilters["filterData"] !== null) { + var filter = savedFilters["filterData"]; $.ajax({ + url: "/pms/objective-select-filter", + data: { page: "all", filter: JSON.stringify(filter), "tableName":tableName }, type: "GET", - url: "/employee/get-language-code/", + dataType: "json", success: function (response) { - var languageCode = response.language_code; - callback(languageCode); // Pass the language code to the callback + var employeeIds = response.employee_ids; + + for (var i = 0; i < employeeIds.length; i++) { + var empId = employeeIds[i]; + $("#" + empId).prop("checked", true); + } + $("#selectedObjectives").attr("data-ids", JSON.stringify(employeeIds)); + + count = makeObjectivesListUnique(employeeIds); + tickObjectivesCheckboxes(count); + }, + error: function (xhr, status, error) { + console.error("Error:", error); + }, + }); + } else { + $.ajax({ + url: "/pms/objective-select", + data: { page: "all", "tableName": tableName }, + type: "GET", + dataType: "json", + success: function (response) { + var employeeIds = response.employee_ids; + + for (var i = 0; i < employeeIds.length; i++) { + var empId = employeeIds[i]; + $("#" + empId).prop("checked", true).closest(".oh-sticky-table__tr") + .addClass("highlight-selected"); + } + var previousIds = $("#selectedObjectives").attr("data-ids"); + $("#selectedObjectives").attr( + "data-ids", + JSON.stringify( + Array.from(new Set([...employeeIds, ...JSON.parse(previousIds)])) + ) + ); + count = makeObjectivesListUnique(employeeIds); + tickObjectivesCheckboxes(count); + }, + error: function (xhr, status, error) { + console.error("Error:", error); }, }); } +} + +function unselectAllObjectives() { + $("#selectedObjectives").attr("data-clicked", 0); + var tableName = localStorage.getItem('activeTabPms'); + if (tableName === '#tab_1'){ + tableName = 'self' + $('.own-objects').prop('checked',false) + } + else{ + tableName = 'all' + $('.all-objects').prop('checked',false) + $('.own-objects').prop('checked',false) + } + $.ajax({ + url: "/pms/objective-select", + data: { page: "all", filter: "{}", "tableName": tableName }, + type: "GET", + dataType: "json", + success: function (response) { + var employeeIds = response.employee_ids; + + for (var i = 0; i < employeeIds.length; i++) { + var empId = employeeIds[i]; + $("#" + empId).prop("checked", false) + .closest(".oh-sticky-table__tr") + .removeClass("highlight-selected"); + } + var ids = JSON.parse($("#selectedObjectives").attr("data-ids") || "[]"); + var uniqueIds = makeObjectivesListUnique(ids); + toggleHighlight(uniqueIds); + + $("#selectedObjectives").attr("data-ids", JSON.stringify([])); + + count = []; + tickObjectivesCheckboxes(count); + }, + error: function (xhr, status, error) { + console.error("Error:", error); + }, + }); +} + $("#archiveObjectives").click(function (e) { e.preventDefault(); @@ -84,9 +300,11 @@ $("#archiveObjectives").click(function (e) { languageCode = code; var confirmMessage = archiveMessages[languageCode]; var textMessage = norowMessages[languageCode]; - var checkedRows = $(".objective-checkbox").filter(":checked"); - if (checkedRows.length === 0) { - Swal.fire({ + ids = []; + ids.push($("#selectedObjectives").attr("data-ids")); + ids = JSON.parse($("#selectedObjectives").attr("data-ids")); + if (ids.length === 0) { + Swal.fire({ text: textMessage, icon: "warning", confirmButtonText: "Close", @@ -99,14 +317,12 @@ $("#archiveObjectives").click(function (e) { confirmButtonColor: "#008000", cancelButtonColor: "#d33", confirmButtonText: "Confirm", - }).then(function (result) { - if (result.isConfirmed) { - e.preventDefault(); - ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); - }); - + }).then(function (result) { + if (result.isConfirmed) { + e.preventDefault(); + ids = []; + ids.push($("#selectedObjectives").attr("data-ids")); + ids = JSON.parse($("#selectedObjectives").attr("data-ids")); $.ajax({ type: "POST", url: "/pms/objective-bulk-archive?is_active=False", @@ -136,8 +352,10 @@ $("#unArchiveObjectives").click(function (e) { languageCode = code; var confirmMessage = unarchiveMessages[languageCode]; var textMessage = norowMessages[languageCode]; - var checkedRows = $(".objective-checkbox").filter(":checked"); - if (checkedRows.length === 0) { + ids = []; + ids.push($("#selectedObjectives").attr("data-ids")); + ids = JSON.parse($("#selectedObjectives").attr("data-ids")); + if (ids.length === 0) { Swal.fire({ text: textMessage, icon: "warning", @@ -151,14 +369,12 @@ $("#unArchiveObjectives").click(function (e) { confirmButtonColor: "#008000", cancelButtonColor: "#d33", confirmButtonText: "Confirm", - }).then(function (result) { - if (result.isConfirmed) { + }).then(function (result) { + if (result.isConfirmed) { e.preventDefault(); ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); - }); - + ids.push($("#selectedObjectives").attr("data-ids")); + ids = JSON.parse($("#selectedObjectives").attr("data-ids")); $.ajax({ type: "POST", url: "/pms/objective-bulk-archive?is_active=True", @@ -188,8 +404,10 @@ $("#deleteObjectives").click(function (e) { languageCode = code; var confirmMessage = deleteMessages[languageCode]; var textMessage = norowMessages[languageCode]; - var checkedRows = $(".objective-checkbox").filter(":checked"); - if (checkedRows.length === 0) { + ids = []; + ids.push($("#selectedObjectives").attr("data-ids")); + ids = JSON.parse($("#selectedObjectives").attr("data-ids")); + if (ids.length === 0) { Swal.fire({ text: textMessage, icon: "warning", @@ -207,10 +425,8 @@ $("#deleteObjectives").click(function (e) { if (result.isConfirmed) { e.preventDefault(); ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); - }); - + ids.push($("#selectedObjectives").attr("data-ids")); + ids = JSON.parse($("#selectedObjectives").attr("data-ids")); $.ajax({ type: "POST", url: "/pms/objective-bulk-delete", diff --git a/pms/templates/okr/group_by.html b/pms/templates/okr/group_by.html index ab5e867e3..1fc82d56c 100644 --- a/pms/templates/okr/group_by.html +++ b/pms/templates/okr/group_by.html @@ -31,6 +31,32 @@ {% trans "On Track" %} + + +
+ {% trans "Select All Objectives" %} +
+
+ {% trans "Unselect All Objectives" %} +
+ {% comment %} {% endcomment %} + + +