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') { |
| 6 | reload_items('closed', 'task', $btn); |
| 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') { |
| 16 | reload_items('closed', 'issue', $btn); |
| 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 | |
| 39 | |
| 40 | var reload_items = function(item_status, item, $btn) { |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 41 | $.ajax({ |
| 42 | method: "GET", |
| 43 | url: "/", |
| 44 | dataType: "json", |
| 45 | data: { |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 46 | cmd: "erpnext.templates.pages.projects.get_"+ item +"_html", |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 47 | project: '{{ doc.name }}', |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 48 | item_status: item_status, |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 49 | }, |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 50 | success: function(data) { |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 51 | if(typeof data.message == 'undefined') { |
| 52 | $('.project-'+ item).html("No "+ item_status +" "+ item); |
Kanchan Chauhan | 53ce94f | 2016-03-25 12:04:54 +0530 | [diff] [blame] | 53 | $(".more-"+ item).toggle(false); |
| 54 | } |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 55 | $('.project-'+ item).html(data.message); |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 56 | $(".more-"+ item).toggle(true); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 57 | |
| 58 | // update status |
| 59 | if(item_status==='open') { |
| 60 | $btn.html(__('Show closed')).attr('data-status', 'Open'); |
| 61 | } else { |
| 62 | $btn.html(__('Show open')).attr('data-status', 'Closed'); |
| 63 | } |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 64 | } |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 65 | }); |
| 66 | |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 67 | } |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 68 | |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 69 | var more_items = function(item, item_status){ |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 70 | if(item_status) { |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 71 | var item_status = $('.project-'+ item +'-section .btn-group .bold').hasClass('btn-closed-'+ item) |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 72 | ? 'closed' : 'open'; |
| 73 | } |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 74 | $.ajax({ |
| 75 | method: "GET", |
| 76 | url: "/", |
| 77 | dataType: "json", |
| 78 | data: { |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 79 | cmd: "erpnext.templates.pages.projects.get_"+ item +"_html", |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 80 | project: '{{ doc.name }}', |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 81 | start: start, |
| 82 | item_status: item_status, |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 83 | }, |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 84 | success: function(data) { |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 85 | |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 86 | $(data.message).appendTo('.project-'+ item); |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 87 | if(typeof data.message == 'undefined') { |
| 88 | $(".more-"+ item).toggle(false); |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 89 | } |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 90 | start = start+10; |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 91 | } |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 92 | }); |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 93 | } |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 94 | |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 95 | var close_item = function(item, item_name){ |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 96 | var args = { |
| 97 | project: '{{ doc.name }}', |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 98 | item_name: item_name, |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 99 | } |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 100 | frappe.call({ |
| 101 | btn: this, |
| 102 | type: "POST", |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 103 | method: "erpnext.templates.pages.projects.set_"+ item +"_status", |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 104 | args: args, |
| 105 | callback: function(r) { |
| 106 | if(r.exc) { |
| 107 | if(r._server_messages) |
| 108 | frappe.msgprint(r._server_messages); |
| 109 | } else { |
| 110 | $(this).remove(); |
| 111 | } |
| 112 | } |
| 113 | }) |
| 114 | return false; |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 115 | } |
Kanchan Chauhan | e14389e | 2016-03-23 14:14:38 +0530 | [diff] [blame] | 116 | }); |