Some more task tweaks, now task creation works again

... my previous commit broke it (much enthusiasm checking for undefined)
This commit is contained in:
2016-10-04 15:35:42 +02:00
parent 2fd7ae7927
commit b1196e4036
2 changed files with 23 additions and 12 deletions

View File

@@ -117,35 +117,46 @@ function shot_create(project_url)
} }
/** /**
* Adds the task item to the shots/tasks list * Adds the task item to the shots/tasks list.
*
* 'shot_id' can be undefined if the task isn't attached to a shot.
*/ */
function task_add(shot_id, task_id, task_type) function task_add(shot_id, task_id, task_type)
{ {
if (shot_id === undefined || task_id === undefined || task_type === undefined) { if (task_id === undefined || task_type === undefined) {
throw new ReferenceError("task_add(" + shot_id + ", " + task_id + ", " + task_type + ") called."); throw new ReferenceError("task_add(" + shot_id + ", " + task_id + ", " + task_type + ") called.");
} }
var project_url = ProjectUtils.projectUrl(); var project_url = ProjectUtils.projectUrl();
var url = '/attract/' + project_url + '/tasks/' + task_id; var url = '/attract/' + project_url + '/tasks/' + task_id;
var context = ProjectUtils.context();
if (ProjectUtils.context() == 'task'){ if (context == 'task') {
/* WARNING: This is a copy of an element of attract/tasks/for_project #task-list.col-list
* If that changes, change this too. */
$('#task-list').append('\ $('#task-list').append('\
<a class="col-list-item task-list-item status-todo task-link"\ <a class="col-list-item task-list-item status-todo task-link active"\
href="' + url + '"\ href="' + url + '"\
data-task-id="' + task_id + '"\ data-task-id="' + task_id + '"\
id="task-' + task_id + '">\ id="task-' + task_id + '">\
<span class="status-indicator"></span>\ <span class="status-indicator"></span>\
<span class="name">New Task</span>\ <span class="name">-save your task first-</span>\
<span class="type">none</span>\ <span class="type">-</span>\
</a>\ </a>\
'); ');
} else if (ProjectUtils.context() == 'shot'){ } else if (context == 'shot') {
if (shot_id === undefined) {
throw new ReferenceError("task_add(" + shot_id + ", " + task_id + ", " + task_type + ") called in shot context.");
}
var $shot_cell = $('#shot-' + shot_id + ' .table-cell.task-type.' + task_type); var $shot_cell = $('#shot-' + shot_id + ' .table-cell.task-type.' + task_type);
var url = '/attract/' + project_url + '/shots/with-task/' + task_id; var url = '/attract/' + project_url + '/shots/with-task/' + task_id;
/* WARNING: This is a copy of an element of attract/shots/for_project #task-list.col-list
* If that changes, change this too. */
$shot_cell.append('\ $shot_cell.append('\
<a class="status-todo task-link"\ <a class="status-todo task-link active"\
title="New task"\ title="-save your task first-"\
href="' + url + '"\ href="' + url + '"\
data-task-id="' + task_id + '"\ data-task-id="' + task_id + '"\
id="task-' + task_id + '">\ id="task-' + task_id + '">\
@@ -177,10 +188,10 @@ function task_create(shot_id, task_type)
}; };
if (has_shot_id) data.parent = shot_id; if (has_shot_id) data.parent = shot_id;
$.post(url, data, function(task_data) { $.post(url, data, function(task_data) {
if (console) console.log('Task created:', task_data);
task_open(task_data.task_id); task_open(task_data.task_id);
if (has_shot_id) task_add(shot_id, task_data.task_id, task_type); task_add(shot_id, task_data.task_id, task_type);
}) })
.fail(function(xhr) { .fail(function(xhr) {
if (console) { if (console) {

View File

@@ -11,7 +11,7 @@
#task-list.col-list #task-list.col-list
| {% for task in tasks %} | {% for task in tasks %}
//- NOTE: this is tightly linked to the JS in tasks.js. //- NOTE: this is tightly linked to the JS in tasks.js, function task_add()
a.col-list-item.task-list-item( a.col-list-item.task-list-item(
id="task-{{task._id}}", id="task-{{task._id}}",
data-task-id="{{task._id}}", data-task-id="{{task._id}}",