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

120 lines
2.7 KiB
JavaScript
Raw Normal View History

frappe.ready(function() {
2016-03-22 10:30:41 +00:00
$( window ).load(function() {
$(".btn-open-tasks").click();
$(".btn-open-issues").click();
});
$('.btn-closed-tasks').click(function() {
2016-03-22 10:30:41 +00:00
reload_items('closed','tasks');
});
2016-03-22 10:30:41 +00:00
$('.btn-open-tasks').click(function() {
2016-03-22 10:30:41 +00:00
reload_items('open','tasks');
});
2016-03-22 10:30:41 +00:00
$('.btn-closed-issues').click(function() {
2016-03-22 10:30:41 +00:00
reload_items('closed','issues');
});
2016-03-22 10:30:41 +00:00
$('.btn-open-issues').click(function() {
2016-03-22 10:30:41 +00:00
reload_items('open','issues');
});
2016-03-22 10:30:41 +00:00
var start = 10;
$(".more-tasks").click(function() {
2016-03-22 10:30:41 +00:00
more_items('tasks', true);
});
$(".more-issues").click(function() {
2016-03-22 10:30:41 +00:00
more_items('issues', true);
});
$(".more-timelogs").click(function() {
2016-03-22 10:30:41 +00:00
more_items('timelogs', false);
});
$(".more-timelines").click(function() {
more_items('timelines', false);
});
$( ".project-tasks" ).on('click', '.task-x', function() {
var item_name = $(this).attr('id');
close_item('task', item_name);
});
$( ".project-issues" ).on('click', '.issue-x', function() {
var item_name = $(this).attr('id');
close_item('issue', item_name);
});
var reload_items = function(item_status, item) {
$.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) {
2016-03-22 10:30:41 +00:00
$('.project-'+ item).html(data.message);
$('.project-'+ item +'-section .btn-group .bold').removeClass('bold');
$('.btn-'+ item_status +'-'+ item).addClass( "bold" );
2016-03-22 10:30:41 +00:00
$(".more-"+ item).toggle(true);
}
});
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 .btn-primary').hasClass('btn-closed-'+ item)
? '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
});
}
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
}
});