brotherton-erpnext/erpnext/templates/pages/projects.js

136 lines
2.9 KiB
JavaScript
Raw Normal View History

frappe.ready(function() {
2016-03-22 10:30:41 +00:00
$('.task-status-switch').on('click', function() {
var $btn = $(this);
if($btn.attr('data-status')==='Open') {
reload_items('closed', 'task', $btn);
} else {
reload_items('open', 'task', $btn);
}
})
$('.issue-status-switch').on('click', function() {
var $btn = $(this);
if($btn.attr('data-status')==='Open') {
reload_items('closed', 'issue', $btn);
} else {
reload_items('open', 'issue', $btn);
}
})
//
// $('.btn-closed-tasks').click(function() {
// reload_items('closed','tasks');
// });
//
// $('.btn-open-tasks').click(function() {
// reload_items('open','tasks');
// });
//
// $('.btn-closed-issues').click(function() {
// reload_items('closed','issues');
// });
//
// $('.btn-open-issues').click(function() {
// reload_items('open','issues');
// });
2016-03-22 10:30:41 +00:00
var start = 10;
$(".more-tasks").click(function() {
more_items('task', true);
});
$(".more-issues").click(function() {
more_items('issue', true);
});
$(".more-timelogs").click(function() {
more_items('timelog', false);
});
2016-03-22 10:30:41 +00:00
$(".more-timelines").click(function() {
more_items('timeline', false);
});
var reload_items = function(item_status, item, $btn) {
$.ajax({
method: "GET",
url: "/",
dataType: "json",
data: {
2016-03-22 10:30:41 +00:00
cmd: "erpnext.templates.pages.projects.get_"+ item +"_html",
project: '{{ doc.name }}',
2016-03-22 10:30:41 +00:00
item_status: item_status,
},
dataType: "json",
success: function(data) {
if(typeof data.message == 'undefined') {
$('.project-'+ item).html("No "+ item_status +" "+ item);
2016-03-25 06:34:54 +00:00
$(".more-"+ item).toggle(false);
}
2016-03-22 10:30:41 +00:00
$('.project-'+ item).html(data.message);
$(".more-"+ item).toggle(true);
// update status
if(item_status==='open') {
$btn.html(__('Show closed')).attr('data-status', 'Open');
} else {
$btn.html(__('Show open')).attr('data-status', 'Closed');
}
}
});
2016-03-22 10:30:41 +00:00
}
2016-03-22 10:30:41 +00:00
var more_items = function(item, item_status){
if(item_status)
{
var item_status = $('.project-'+ item +'-section .btn-group .bold').hasClass('btn-closed-'+ item)
2016-03-22 10:30:41 +00:00
? 'closed' : 'open';
}
$.ajax({
method: "GET",
url: "/",
dataType: "json",
data: {
2016-03-22 10:30:41 +00:00
cmd: "erpnext.templates.pages.projects.get_"+ item +"_html",
project: '{{ doc.name }}',
2016-03-22 10:30:41 +00:00
start: start,
item_status: item_status,
},
dataType: "json",
success: function(data) {
2016-03-22 10:30:41 +00:00
$(data.message).appendTo('.project-'+ item);
if(typeof data.message == 'undefined') {
$(".more-"+ item).toggle(false);
}
2016-03-22 10:30:41 +00:00
start = start+10;
}
});
2016-03-22 10:30:41 +00:00
}
2016-03-22 10:30:41 +00:00
var close_item = function(item, item_name){
var args = {
project: '{{ doc.name }}',
2016-03-22 10:30:41 +00:00
item_name: item_name,
}
frappe.call({
btn: this,
type: "POST",
2016-03-22 10:30:41 +00:00
method: "erpnext.templates.pages.projects.set_"+ item +"_status",
args: args,
callback: function(r) {
if(r.exc) {
if(r._server_messages)
frappe.msgprint(r._server_messages);
} else {
$(this).remove();
}
}
})
return false;
2016-03-22 10:30:41 +00:00
}
});