2016-09-21 19:39:56 +02:00
|
|
|
/**
|
|
|
|
* Shows a task in the #task-details div.
|
|
|
|
*/
|
|
|
|
function task_open(task_id, project_url) {
|
|
|
|
if (task_id === undefined) {
|
|
|
|
if (console) console.log("task_open(undefined) called.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log('before anything');
|
|
|
|
|
|
|
|
$('#task-list').find('a').removeClass('active');
|
|
|
|
$('#task-' + task_id).addClass('active');
|
|
|
|
|
|
|
|
var task_url = '/attract/' + project_url + '/tasks/' + task_id;
|
|
|
|
console.log('task_url is ' + task_url);
|
|
|
|
|
|
|
|
$.get(task_url, function(task_data) {
|
|
|
|
$('#task-details').html(task_data);
|
|
|
|
}).fail(function(xhr) {
|
|
|
|
if (console) {
|
|
|
|
console.log('Error fetching task', task_id, 'from', task_url);
|
|
|
|
console.log('XHR:', xhr);
|
|
|
|
}
|
|
|
|
$('#task-details').html(xhr.responseText);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a task and show it in the #task-details div.
|
|
|
|
*/
|
|
|
|
function task_create(shot_id, project_url, task_type) {
|
|
|
|
var base_url = '/attract/' + project_url + '/tasks/create';
|
|
|
|
|
|
|
|
if (task_type != undefined) {
|
|
|
|
base_url += '/' + task_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.post(base_url, function(task_data) {
|
|
|
|
task_open(task_data.task_id, project_url);
|
|
|
|
})
|
|
|
|
.fail(function(xhr) {
|
|
|
|
if (console) {
|
|
|
|
console.log('Error creating task');
|
|
|
|
console.log('XHR:', xhr);
|
|
|
|
}
|
|
|
|
$('#task-details').html(xhr.responseText);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function task_save(task_id, task_url) {
|
2016-09-08 11:24:58 +02:00
|
|
|
console.log('Saving task to', task_url);
|
|
|
|
|
2016-09-21 14:02:05 +02:00
|
|
|
var $form = $('#task-view form');
|
2016-09-08 11:24:58 +02:00
|
|
|
var $button = $form.find("button[type='submit']");
|
|
|
|
var payload = $form.serialize();
|
2016-09-21 14:02:05 +02:00
|
|
|
var task = '#task-' + task_id;
|
2016-09-08 11:24:58 +02:00
|
|
|
|
|
|
|
$button.attr('disabled', true);
|
2016-09-21 14:02:05 +02:00
|
|
|
$(task).addClass('processing');
|
|
|
|
$('#status-bar').text('Saving task...');
|
2016-09-08 11:24:58 +02:00
|
|
|
|
|
|
|
if (console) console.log('Sending:', payload);
|
2016-09-21 14:02:05 +02:00
|
|
|
|
2016-09-08 11:24:58 +02:00
|
|
|
$.post(task_url, payload)
|
|
|
|
.done(function(data) {
|
|
|
|
if (console) console.log('Done saving', data);
|
|
|
|
|
|
|
|
// Update the task list.
|
|
|
|
// NOTE: this is tightly linked to the HTML of the task list in for_project.jade.
|
2016-09-21 14:02:05 +02:00
|
|
|
$(task + ' span.name').text($form.find("input[name='name']").val());
|
2016-09-21 19:39:56 +02:00
|
|
|
$(task + ' span.type').text($form.find("select[name='task_type']").val());
|
2016-09-21 15:47:24 +02:00
|
|
|
$(task + ' span.status').text($form.find("select[name='status']").val().replace('_', ' '));
|
2016-09-21 19:39:56 +02:00
|
|
|
$(task)
|
|
|
|
.removeClass('col-list-item task-list-item')
|
|
|
|
.addClass('col-list-item task-list-item status-' + $form.find("select[name='status']").val());
|
2016-09-21 14:02:05 +02:00
|
|
|
|
|
|
|
$('#status-bar').text('Saved task. ' + data.time);
|
2016-09-08 11:24:58 +02:00
|
|
|
})
|
|
|
|
.fail(function(xhr_or_response_data) {
|
|
|
|
// jQuery sends the response data (if JSON), or an XHR object (if not JSON).
|
|
|
|
if (console) console.log('Failed saving', xhr_or_response_data);
|
2016-09-20 17:39:30 +02:00
|
|
|
$('#task-details').html(xhr_or_response_data.responseText);
|
2016-09-21 15:14:42 +02:00
|
|
|
$('#status-bar').text('Failed saving. ' + xhr_or_response_data.responseText);
|
2016-09-08 11:24:58 +02:00
|
|
|
})
|
|
|
|
.always(function() {
|
|
|
|
$button.attr('disabled', false);
|
2016-09-21 14:02:05 +02:00
|
|
|
$(task).removeClass('processing');
|
2016-09-08 11:24:58 +02:00
|
|
|
})
|
2016-09-21 14:02:05 +02:00
|
|
|
;
|
2016-09-08 11:24:58 +02:00
|
|
|
|
|
|
|
return false; // prevent synchronous POST to current page.
|
|
|
|
}
|