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