[UPDT] PMS: Selection updation in objective list and group view

This commit is contained in:
Horilla
2023-11-17 16:47:05 +05:30
parent 890597c909
commit cd199a85c8
6 changed files with 569 additions and 119 deletions

View File

@@ -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",

View File

@@ -31,6 +31,32 @@
{% trans "On Track" %}
</span>
</div>
<!-- start of selection buttons -->
<div
class="oh-checkpoint-badge text-success mb-2"
id="selectAllObjectives"
style="cursor: pointer"
>
{% trans "Select All Objectives" %}
</div>
<div
class="oh-checkpoint-badge text-secondary mb-2"
id="unselectAllObjectives"
style="cursor: pointer"
>
{% trans "Unselect All Objectives" %}
</div>
{% comment %} <div
class="oh-checkpoint-badge text-info mb-2"
id="exportObjectives"
style="cursor: pointer; display: none"
>
{% trans "Export Objectives" %}
</div> {% endcomment %}
<div class="oh-checkpoint-badge text-danger mb-2" id="selectedShowObjectives" style="display: none"></div>
<!-- end of selection buttons -->
<div class="oh-tabs" >
<ul class="oh-tabs__tablist" >
@@ -56,12 +82,14 @@
<div class="oh-sticky-table__thead">
<div class="oh-sticky-table__tr">
<div class="oh-sticky-table__th" style="width:10px;">
<input
type="checkbox"
class="own-objects oh-input oh-input__checkbox"
id = "Ownobjectives"
title='{% trans "Select All" %}'
/>
<div class="centered-div">
<input
type="checkbox"
class="own-objects oh-input oh-input__checkbox"
id = "Ownobjectives"
title='{% trans "Select All" %}'
/>
</div>
</div>
<div class="oh-sticky-table__th">{% trans "Owner" %}</div>
<div class="oh-sticky-table__th">{% trans "Objective" %}</div>
@@ -76,16 +104,15 @@
<div class="oh-sticky-table__sd {% if own_objective.status == 'Closed' %}row-status--blue
{% elif own_objective.status == 'On Track' %}row-status--yellow {% elif own_objective.status == 'Not Started' %}row-status--gray
{% elif own_objective.status == 'Behind' %}row-status--orange {% elif own_objective.status == 'At Risk' %}row-status--red{% endif %}">
<div class="d-flex">
<div>
<input
type="checkbox"
id="{{own_objective.id}}"
value="{{own_objective.id}}"
class="oh-input objective-checkbox oh-input__checkbox own-objects-row ms-2"
/>
</div>
</div>
<div class="centered-div">
<input
type="checkbox"
id="{{own_objective.id}}"
value="{{own_objective.id}}"
onchange="highlightRow($(this))"
class="oh-input objective-checkbox oh-input__checkbox own-objects-row"
/>
</div>
</div>
<a class="oh-sticky-table__td" style="color: inherit; text-decoration: none"
href="{% url 'objective-detailed-view' emp_obj_id=own_objective.id %} ">
@@ -295,12 +322,14 @@
<div class="oh-sticky-table__thead">
<div class="oh-sticky-table__tr">
<div class="oh-sticky-table__th" style="width:10px;">
<div class="centered-div">
<input
type="checkbox"
class="all-objects oh-input oh-input__checkbox"
id = "Allobjectives"
title='{% trans "Select All" %}'
/>
</div>
</div>
<div class="oh-sticky-table__th">{% trans "Owner" %}</div>
<div class="oh-sticky-table__th">{% trans "Objective" %}</div>
@@ -315,15 +344,14 @@
<div class="oh-sticky-table__sd {% if all_objective.status == 'Closed' %}row-status--blue
{% elif all_objective.status == 'On Track' %}row-status--yellow {% elif all_objective.status == 'Not Started' %}row-status--gray
{% elif all_objective.status == 'Behind' %}row-status--orange {% elif all_objective.status == 'At Risk' %}row-status--red{% endif %}">
<div class="d-flex">
<div>
<input
type="checkbox"
id="{{all_objective.id}}"
value="{{all_objective.id}}"
class="oh-input objective-checkbox oh-input__checkbox all-objects-row ms-2"
/>
</div>
<div class="centered-div">
<input
type="checkbox"
id="{{all_objective.id}}"
value="{{all_objective.id}}"
onchange="highlightRow($(this))"
class="oh-input objective-checkbox oh-input__checkbox all-objects-row"
/>
</div>
</div>
<a class="oh-sticky-table__td" style="color: inherit; text-decoration: none"
@@ -441,6 +469,67 @@
</div>
{% endfor %}
</div>
<div class="oh-pagination">
<span
class="oh-pagination__page"
data-toggle="modal"
data-target="#addEmployeeModal"
></span>
<nav class="oh-pagination__nav">
<div class="oh-pagination__input-container me-3">
<span class="oh-pagination__label me-1">{% trans "Page" %}</span>
<input
type="number"
name="page"
class="oh-pagination__input"
value="{{all_objectives.number }}"
min="1"
hx-get="{% url 'objective-list-search' %}?{{pg}}"
hx-target="#objective_list"
/>
<span class="oh-pagination__label"
>{% trans "of" %} {{ all_objectives.paginator.num_pages }}</span
>
</div>
<ul class="oh-pagination__items">
{% if all_objectives.has_previous %}
<li class="oh-pagination__item oh-pagination__item--wide">
<a
hx-get="{% url 'objective-list-search' %}?{{pg}}&page=1"
class="oh-pagination__link"
hx-target="#objective_list"
>{% trans "First" %}</a
>
</li>
<li class="oh-pagination__item oh-pagination__item--wide">
<a
hx-get="{% url 'objective-list-search' %}?{{pg}}&page={{ all_objectives.previous_page_number }}"
class="oh-pagination__link"
hx-target="#objective_list"
>{% trans "Previous" %}</a
>
</li>
{%endif %} {% if all_objectives.has_next %}
<li class="oh-pagination__item oh-pagination__item--wide">
<a
hx-get="{% url 'objective-list-search' %}?{{pg}}&page={{ all_objectives.next_page_number }}"
class="btn btn-outline-secondary"
hx-target="#objective_list"
>{% trans "Next" %}</a
>
</li>
<li class="oh-pagination__item oh-pagination__item--wide">
<a
hx-get="{% url 'objective-list-search' %}?{{pg}}&page={{ all_objectives.paginator.num_pages }}"
hx-target="#objective_list"
class="oh-pagination__link"
>{% trans "Last" %}</a
>
</li>
{% endif %}
</ul>
</nav>
</div>
</div>
</div>
</div>
@@ -472,24 +561,43 @@
$(activeTab).toggleClass("oh-tabs__content--active");
localStorage.setItem("activeTabPms", activeTab);
});
});
$("#Allobjectives").click(function (e) {
var is_checked = $(this).is(":checked");
if (is_checked) {
$(".all-objects-row").prop("checked", true);
} else {
$(".all-objects-row").prop("checked", false);
}
tickObjectivesCheckboxes();
$(".all-objects-row").change(function () {
addingObjectivesIds();
});
$("#Ownobjectives").click(function (e) {
var is_checked = $(this).is(":checked");
if (is_checked) {
$(".own-objects-row").prop("checked", true);
} else {
$(".own-objects-row").prop("checked", false);
}
$(".all-objects").change(function () {
addingObjectivesIds();
});
$(".own-objects-row").change(function () {
addingObjectivesIds();
});
$(".own-objects").change(function () {
addingObjectivesIds();
});
$("#selectAllObjectives").click(function () {
selectAllObjectives();
});
$("#unselectAllObjectives").click(function () {
unselectAllObjectives();
});
$("#exportObjectives").click(function (e) {
exportObjectives();
});
})
$(".all-objects").change(function (e) {
var is_checked = $(this).is(":checked");
var closest = $(this)
.closest(".oh-sticky-table__thead")
.siblings(".oh-sticky-table__tbody");
if (is_checked) {
$(closest).children().find(".all-objects-row").prop("checked", true).closest(".oh-sticky-table__tr")
.addClass("highlight-selected");
} else {
$(closest).children().find(".all-objects-row").prop("checked", false).closest(".oh-sticky-table__tr")
.removeClass("highlight-selected");
}
});
</script>

View File

@@ -25,6 +25,31 @@
{% trans "On Track" %}
</span>
</div>
<!-- start of selection buttons -->
<div
class="oh-checkpoint-badge text-success mb-2"
id="selectAllObjectives"
style="cursor: pointer"
>
{% trans "Select All Objectives" %}
</div>
<div
class="oh-checkpoint-badge text-secondary mb-2"
id="unselectAllObjectives"
style="cursor: pointer"
>
{% trans "Unselect All Objectives" %}
</div>
{% comment %} <div
class="oh-checkpoint-badge text-info mb-2"
id="exportObjectives"
style="cursor: pointer; display: none"
>
{% trans "Export Objectives" %}
</div> {% endcomment %}
<div class="oh-checkpoint-badge text-danger mb-2" id="selectedShowObjectives" style="display: none"></div>
<!-- end of selection buttons -->
<div class="oh-tabs" >
<ul class="oh-tabs__tablist" >
@@ -50,12 +75,14 @@
<div class="oh-sticky-table__thead">
<div class="oh-sticky-table__tr">
<div class="oh-sticky-table__th" style="width:10px;">
<input
type="checkbox"
class="own-objects oh-input oh-input__checkbox"
id = "Ownobjectives"
title='{% trans "Select All" %}'
/>
<div class="centered-div">
<input
type="checkbox"
class="own-objects oh-input oh-input__checkbox"
id = "Ownobjectives"
title='{% trans "Select All" %}'
/>
</div>
</div>
<div class="oh-sticky-table__th">{% trans "Owner" %}</div>
<div class="oh-sticky-table__th">{% trans "Objective" %}</div>
@@ -70,16 +97,15 @@
<div class="oh-sticky-table__sd {% if own_objective.status == 'Closed' %}row-status--blue
{% elif own_objective.status == 'On Track' %}row-status--yellow {% elif own_objective.status == 'Not Started' %}row-status--gray
{% elif own_objective.status == 'Behind' %}row-status--orange {% elif own_objective.status == 'At Risk' %}row-status--red{% endif %}">
<div class="d-flex">
<div>
<input
type="checkbox"
id="{{own_objective.id}}"
value="{{own_objective.id}}"
class="oh-input objective-checkbox oh-input__checkbox own-objects-row ms-2"
/>
</div>
</div>
<div class="centered-div">
<input
type="checkbox"
id="{{own_objective.id}}"
value="{{own_objective.id}}"
onchange="highlightRow($(this))"
class="oh-input objective-checkbox oh-input__checkbox own-objects-row"
/>
</div>
</div>
<a class="oh-sticky-table__td" style="color: inherit; text-decoration: none"
href="{% url 'objective-detailed-view' emp_obj_id=own_objective.id %} ">
@@ -267,12 +293,14 @@
<div class="oh-sticky-table__thead">
<div class="oh-sticky-table__tr">
<div class="oh-sticky-table__th" style="width:10px;">
<input
type="checkbox"
class="all-objects oh-input oh-input__checkbox"
id = "Allobjectives"
title='{% trans "Select All" %}'
/>
<div class="centered-div">
<input
type="checkbox"
class="all-objects oh-input oh-input__checkbox"
id = "Allobjectives"
title='{% trans "Select All" %}'
/>
</div>
</div>
<div class="oh-sticky-table__th">{% trans "Owner" %}</div>
<div class="oh-sticky-table__th">{% trans "Objective" %}</div>
@@ -287,20 +315,18 @@
<div class="oh-sticky-table__sd {% if all_objective.status == 'Closed' %}row-status--blue
{% elif all_objective.status == 'On Track' %}row-status--yellow {% elif all_objective.status == 'Not Started' %}row-status--gray
{% elif all_objective.status == 'Behind' %}row-status--orange {% elif all_objective.status == 'At Risk' %}row-status--red{% endif %}">
<div class="d-flex">
<div>
<div class="centered-div">
<input
type="checkbox"
id="{{all_objective.id}}"
value="{{all_objective.id}}"
class="oh-input objective-checkbox oh-input__checkbox all-objects-row ms-2"
onchange="highlightRow($(this))"
class="oh-input objective-checkbox oh-input__checkbox all-objects-row"
/>
</div>
</div>
</div>
<a class="oh-sticky-table__td" style="color: inherit; text-decoration: none"
href="{% url 'objective-detailed-view' emp_obj_id=all_objective.id %} "
>
href="{% url 'objective-detailed-view' emp_obj_id=all_objective.id %} ">
<div class="oh-profile oh-profile--md">
<div class="oh-profile__avatar mr-1">
<img
@@ -506,24 +532,60 @@
$(activeTab).toggleClass("oh-tabs__content--active");
localStorage.setItem("activeTabPms", activeTab);
});
tickObjectivesCheckboxes();
});
$("#Allobjectives").click(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");
}
});
$("#Ownobjectives").click(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");
}
});
$(document).ready(function () {
tickObjectivesCheckboxes();
$(".all-objects-row").change(function () {
addingObjectivesIds();
});
$(".all-objects").change(function () {
addingObjectivesIds();
});
$(".own-objects-row").change(function () {
addingObjectivesIds();
});
$(".own-objects").change(function () {
addingObjectivesIds();
});
$("#selectAllObjectives").click(function () {
selectAllObjectives();
});
$("#unselectAllObjectives").click(function () {
unselectAllObjectives();
});
$("#exportObjectives").click(function (e) {
exportObjectives();
});
});
</script>
<script src="{% static 'src/okr/action.js' %}"></script>

View File

@@ -298,6 +298,9 @@
</div>
</div>
</section>
<div class="oh-checkpoint-badge mb-2" id="selectedObjectives" data-ids="[]" data-clicked="" style="display:none;" >
{% trans "Selected Objectives" %}
</div>
<div class="oh-wrapper" id="objective_list">
{% include 'okr/objective_list.html' %}
</div>

View File

@@ -196,4 +196,14 @@ urlpatterns = [
views.feedback_bulk_delete,
name="feedback-bulk-delete",
),
path(
"objective-select",
views.objective_select,
name="objective-select",
),
path(
"objective-select-filter",
views.objective_select_filter,
name="objective-select-filter",
),
]

View File

@@ -2057,3 +2057,54 @@ def feedback_bulk_delete(request):
except Feedback.DoesNotExist:
messages.error(request, _("Feedback not found."))
return JsonResponse({"message": "Success"})
@login_required
def objective_select(request):
"""
This method is used to return all the id of the employees to select the employee row
"""
page_number = request.GET.get("page")
table = request.GET.get("tableName")
user = request.user.employee_get
employees = EmployeeObjective.objects.all()
if page_number == "all":
if table == 'all':
employees = EmployeeObjective.objects.filter(archive=False)
else:
employees = EmployeeObjective.objects.filter(employee_id=user, archive=False)
employee_ids = [str(emp.id) for emp in employees]
total_count = employees.count()
context = {"employee_ids": employee_ids, "total_count": total_count}
return JsonResponse(context, safe=False)
@login_required
def objective_select_filter(request):
"""
This method is used to return all the ids of the filtered employees
"""
page_number = request.GET.get("page")
filtered = request.GET.get("filter")
filters = json.loads(filtered) if filtered else {}
table = request.GET.get("tableName")
user = request.user.employee_get
employee_filter = ObjectiveFilter(filters, queryset=EmployeeObjective.objects.all())
if page_number == "all":
if table == 'all':
employee_filter = ObjectiveFilter(filters, queryset=EmployeeObjective.objects.all())
else:
employee_filter = ObjectiveFilter(filters, queryset=EmployeeObjective.objects.filter(employee_id=user))
# Get the filtered queryset
filtered_employees = employee_filter.qs
employee_ids = [str(emp.id) for emp in filtered_employees]
total_count = filtered_employees.count()
context = {"employee_ids": employee_ids, "total_count": total_count}
return JsonResponse(context)