Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1 | frappe.ready(function () { |
| 2 | $(".task-status-switch").on("click", function () { |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 3 | var $btn = $(this); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 4 | if ($btn.attr("data-status") === "Open") { |
| 5 | reload_items("completed", "task", $btn); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 6 | } else { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 7 | reload_items("open", "task", $btn); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 8 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 9 | }); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 10 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 11 | $(".issue-status-switch").on("click", function () { |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 12 | var $btn = $(this); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 13 | if ($btn.attr("data-status") === "Open") { |
| 14 | reload_items("completed", "issue", $btn); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 15 | } else { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 16 | reload_items("open", "issue", $btn); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 17 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 18 | }); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 19 | |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 20 | var start = 10; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 21 | $(".more-tasks").click(function () { |
| 22 | more_items("task", true); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 23 | }); |
| 24 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 25 | $(".more-issues").click(function () { |
| 26 | more_items("issue", true); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 27 | }); |
| 28 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 29 | $(".more-timelogs").click(function () { |
| 30 | more_items("timelog", false); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 31 | }); |
| 32 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 33 | $(".more-timelines").click(function () { |
| 34 | more_items("timeline", false); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 35 | }); |
| 36 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 37 | $(".file-size").each(function () { |
JodeQ | 10dfd4a | 2018-09-10 13:40:43 +0200 | [diff] [blame] | 38 | $(this).text(frappe.form.formatters.FileSize($(this).text())); |
| 39 | }); |
| 40 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 41 | var reload_items = function (item_status, item, $btn) { |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 42 | $.ajax({ |
| 43 | method: "GET", |
| 44 | url: "/", |
| 45 | dataType: "json", |
| 46 | data: { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 47 | cmd: "erpnext.templates.pages.projects.get_" + item + "_html", |
| 48 | project: "{{ doc.name }}", |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 49 | item_status: item_status, |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 50 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 51 | success: function (data) { |
| 52 | if (typeof data.message == "undefined") { |
| 53 | $(".project-" + item).html("No " + item_status + " " + item); |
| 54 | $(".more-" + item).toggle(false); |
Kanchan Chauhan | 53ce94f | 2016-03-25 12:04:54 +0530 | [diff] [blame] | 55 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 56 | $(".project-" + item).html(data.message); |
| 57 | $(".more-" + item).toggle(true); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 58 | |
| 59 | // update status |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 60 | if (item_status === "open") { |
| 61 | $btn.html(__("Show Completed")).attr("data-status", "Open"); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 62 | } else { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 63 | $btn.html(__("Show Open")).attr("data-status", "Completed"); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 64 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 65 | }, |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 66 | }); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 67 | }; |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 68 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 69 | 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 Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 76 | } |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 77 | $.ajax({ |
| 78 | method: "GET", |
| 79 | url: "/", |
| 80 | dataType: "json", |
| 81 | data: { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 82 | cmd: "erpnext.templates.pages.projects.get_" + item + "_html", |
| 83 | project: "{{ doc.name }}", |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 84 | start: start, |
| 85 | item_status: item_status, |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 86 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 87 | success: function (data) { |
| 88 | $(data.message).appendTo(".project-" + item); |
| 89 | if (typeof data.message == "undefined") { |
| 90 | $(".more-" + item).toggle(false); |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 91 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 92 | start = start + 10; |
| 93 | }, |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 94 | }); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 95 | }; |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 96 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 97 | var close_item = function (item, item_name) { |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 98 | var args = { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 99 | project: "{{ doc.name }}", |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 100 | item_name: item_name, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 101 | }; |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 102 | frappe.call({ |
| 103 | btn: this, |
| 104 | type: "POST", |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 105 | method: "erpnext.templates.pages.projects.set_" + item + "_status", |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 106 | args: args, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 107 | callback: function (r) { |
| 108 | if (r.exc) { |
| 109 | if (r._server_messages) frappe.msgprint(r._server_messages); |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 110 | } else { |
| 111 | $(this).remove(); |
| 112 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 113 | }, |
| 114 | }); |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 115 | return false; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 116 | }; |
Ankush Menat | 4551d7d | 2021-08-19 13:41:10 +0530 | [diff] [blame] | 117 | }); |