Move Tasks JS to layout, since we use it everywhere

This commit is contained in:
2016-09-21 19:39:56 +02:00
parent 7d64e8bf4e
commit fb6fa299f1
7 changed files with 103 additions and 81 deletions

View File

@@ -1,4 +1,54 @@
function save_task(task_id, task_url) {
/**
* 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) {
console.log('Saving task to', task_url);
var $form = $('#task-view form');
@@ -19,10 +69,11 @@ function save_task(task_id, task_url) {
// Update the task list.
// NOTE: this is tightly linked to the HTML of the task list in for_project.jade.
$(task + ' span.name').text($form.find("input[name='name']").val());
$(task + ' span.type').text($form.find("select[name='task_type']").val());
$(task + ' span.status').text($form.find("select[name='status']").val().replace('_', ' '));
$(task + ' span.status-indicator')
.removeAttr('class')
.addClass('status-indicator ' + $form.find("select[name='status']").val());
$(task)
.removeClass('col-list-item task-list-item')
.addClass('col-list-item task-list-item status-' + $form.find("select[name='status']").val());
$('#status-bar').text('Saved task. ' + data.time);
})