blob: 622ed42f85f2fc25e353281a3c16f955caef32b4 [file] [log] [blame]
Ankush Menatec74a5e2024-03-10 19:45:40 +05301frappe.ready(function () {
2 $(".task-status-switch").on("click", function () {
Rushabh Mehtac20c5362016-03-25 17:19:28 +05303 var $btn = $(this);
Ankush Menatec74a5e2024-03-10 19:45:40 +05304 if ($btn.attr("data-status") === "Open") {
5 reload_items("completed", "task", $btn);
Rushabh Mehtac20c5362016-03-25 17:19:28 +05306 } else {
Ankush Menatec74a5e2024-03-10 19:45:40 +05307 reload_items("open", "task", $btn);
Rushabh Mehtac20c5362016-03-25 17:19:28 +05308 }
Ankush Menatec74a5e2024-03-10 19:45:40 +05309 });
Rushabh Mehtac20c5362016-03-25 17:19:28 +053010
Ankush Menatec74a5e2024-03-10 19:45:40 +053011 $(".issue-status-switch").on("click", function () {
Rushabh Mehtac20c5362016-03-25 17:19:28 +053012 var $btn = $(this);
Ankush Menatec74a5e2024-03-10 19:45:40 +053013 if ($btn.attr("data-status") === "Open") {
14 reload_items("completed", "issue", $btn);
Rushabh Mehtac20c5362016-03-25 17:19:28 +053015 } else {
Ankush Menatec74a5e2024-03-10 19:45:40 +053016 reload_items("open", "issue", $btn);
Rushabh Mehtac20c5362016-03-25 17:19:28 +053017 }
Ankush Menatec74a5e2024-03-10 19:45:40 +053018 });
Rushabh Mehtac20c5362016-03-25 17:19:28 +053019
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053020 var start = 10;
Ankush Menatec74a5e2024-03-10 19:45:40 +053021 $(".more-tasks").click(function () {
22 more_items("task", true);
Rushabh Mehtac20c5362016-03-25 17:19:28 +053023 });
24
Ankush Menatec74a5e2024-03-10 19:45:40 +053025 $(".more-issues").click(function () {
26 more_items("issue", true);
Rushabh Mehtac20c5362016-03-25 17:19:28 +053027 });
28
Ankush Menatec74a5e2024-03-10 19:45:40 +053029 $(".more-timelogs").click(function () {
30 more_items("timelog", false);
Rushabh Mehtac20c5362016-03-25 17:19:28 +053031 });
32
Ankush Menatec74a5e2024-03-10 19:45:40 +053033 $(".more-timelines").click(function () {
34 more_items("timeline", false);
Rushabh Mehtac20c5362016-03-25 17:19:28 +053035 });
36
Ankush Menatec74a5e2024-03-10 19:45:40 +053037 $(".file-size").each(function () {
JodeQ10dfd4a2018-09-10 13:40:43 +020038 $(this).text(frappe.form.formatters.FileSize($(this).text()));
39 });
40
Ankush Menatec74a5e2024-03-10 19:45:40 +053041 var reload_items = function (item_status, item, $btn) {
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053042 $.ajax({
43 method: "GET",
44 url: "/",
45 dataType: "json",
46 data: {
Ankush Menatec74a5e2024-03-10 19:45:40 +053047 cmd: "erpnext.templates.pages.projects.get_" + item + "_html",
48 project: "{{ doc.name }}",
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053049 item_status: item_status,
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053050 },
Ankush Menatec74a5e2024-03-10 19:45:40 +053051 success: function (data) {
52 if (typeof data.message == "undefined") {
53 $(".project-" + item).html("No " + item_status + " " + item);
54 $(".more-" + item).toggle(false);
Kanchan Chauhan53ce94f2016-03-25 12:04:54 +053055 }
Ankush Menatec74a5e2024-03-10 19:45:40 +053056 $(".project-" + item).html(data.message);
57 $(".more-" + item).toggle(true);
Rushabh Mehtac20c5362016-03-25 17:19:28 +053058
59 // update status
Ankush Menatec74a5e2024-03-10 19:45:40 +053060 if (item_status === "open") {
61 $btn.html(__("Show Completed")).attr("data-status", "Open");
Rushabh Mehtac20c5362016-03-25 17:19:28 +053062 } else {
Ankush Menatec74a5e2024-03-10 19:45:40 +053063 $btn.html(__("Show Open")).attr("data-status", "Completed");
Rushabh Mehtac20c5362016-03-25 17:19:28 +053064 }
Ankush Menatec74a5e2024-03-10 19:45:40 +053065 },
Rushabh Mehtac20c5362016-03-25 17:19:28 +053066 });
Ankush Menatec74a5e2024-03-10 19:45:40 +053067 };
Rushabh Mehtac20c5362016-03-25 17:19:28 +053068
Ankush Menatec74a5e2024-03-10 19:45:40 +053069 var more_items = function (item, item_status) {
70 if (item_status) {
71 item_status = $(".project-" + item + "-section .btn-group .bold").hasClass(
72 "btn-completed-" + item
73 )
74 ? "completed"
75 : "open";
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053076 }
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053077 $.ajax({
78 method: "GET",
79 url: "/",
80 dataType: "json",
81 data: {
Ankush Menatec74a5e2024-03-10 19:45:40 +053082 cmd: "erpnext.templates.pages.projects.get_" + item + "_html",
83 project: "{{ doc.name }}",
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053084 start: start,
85 item_status: item_status,
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053086 },
Ankush Menatec74a5e2024-03-10 19:45:40 +053087 success: function (data) {
88 $(data.message).appendTo(".project-" + item);
89 if (typeof data.message == "undefined") {
90 $(".more-" + item).toggle(false);
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053091 }
Ankush Menatec74a5e2024-03-10 19:45:40 +053092 start = start + 10;
93 },
Rushabh Mehtac20c5362016-03-25 17:19:28 +053094 });
Ankush Menatec74a5e2024-03-10 19:45:40 +053095 };
Rushabh Mehtac20c5362016-03-25 17:19:28 +053096
Ankush Menatec74a5e2024-03-10 19:45:40 +053097 var close_item = function (item, item_name) {
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053098 var args = {
Ankush Menatec74a5e2024-03-10 19:45:40 +053099 project: "{{ doc.name }}",
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +0530100 item_name: item_name,
Ankush Menatec74a5e2024-03-10 19:45:40 +0530101 };
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +0530102 frappe.call({
103 btn: this,
104 type: "POST",
Ankush Menatec74a5e2024-03-10 19:45:40 +0530105 method: "erpnext.templates.pages.projects.set_" + item + "_status",
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +0530106 args: args,
Ankush Menatec74a5e2024-03-10 19:45:40 +0530107 callback: function (r) {
108 if (r.exc) {
109 if (r._server_messages) frappe.msgprint(r._server_messages);
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +0530110 } else {
111 $(this).remove();
112 }
Ankush Menatec74a5e2024-03-10 19:45:40 +0530113 },
114 });
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +0530115 return false;
Ankush Menatec74a5e2024-03-10 19:45:40 +0530116 };
Ankush Menat4551d7d2021-08-19 13:41:10 +0530117});