2016-09-22 11:08:20 +02:00
|
|
|
(function ( $ ) {
|
|
|
|
$.fn.flashOnce = function() {
|
|
|
|
var target = this;
|
|
|
|
this
|
|
|
|
.addClass('flash-on')
|
|
|
|
.delay(200) // this delay is linked to the transition in the flash-on CSS class.
|
|
|
|
.queue(function() {
|
|
|
|
target
|
|
|
|
.removeClass('flash-on')
|
|
|
|
.addClass('flash-off')
|
|
|
|
.dequeue()
|
|
|
|
;})
|
|
|
|
.delay(1000) // this delay is just to clean up the flash-X classes.
|
|
|
|
.queue(function() {
|
|
|
|
target
|
|
|
|
.removeClass('flash-on flash-off')
|
|
|
|
.dequeue()
|
|
|
|
;})
|
|
|
|
;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
}(jQuery));
|
|
|
|
|
2016-09-21 19:39:56 +02:00
|
|
|
/**
|
|
|
|
* Shows a task in the #task-details div.
|
|
|
|
*/
|
|
|
|
function task_open(task_id, project_url) {
|
2016-09-22 09:27:28 +02:00
|
|
|
if (task_id === undefined || project_url === undefined) {
|
|
|
|
if (console) console.log("task_open(", task_id, project_url, ") called.");
|
2016-09-21 19:39:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-22 15:29:18 +02:00
|
|
|
/**
|
|
|
|
* Shows a shot in the #task-details div.
|
|
|
|
*/
|
|
|
|
function shot_open(shot_id, project_url) {
|
|
|
|
if (shot_id === undefined || project_url === undefined) {
|
|
|
|
if (console) console.log("shot_open(", shot_id, project_url, ") called.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#shot-list').find('a').removeClass('active');
|
|
|
|
$('#shot-link' + shot_id).addClass('active');
|
|
|
|
|
|
|
|
var shot_url = '/attract/' + project_url + '/shots/' + shot_id;
|
|
|
|
console.log('shot_url is ' + shot_url);
|
|
|
|
|
|
|
|
$.get(shot_url, function(shot_data) {
|
|
|
|
$('#task-details').html(shot_data);
|
|
|
|
}).fail(function(xhr) {
|
|
|
|
if (console) {
|
|
|
|
console.log('Error fetching shot', shot_id, 'from', shot_url);
|
|
|
|
console.log('XHR:', xhr);
|
|
|
|
}
|
|
|
|
$('#task-details').html(xhr.responseText);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-21 19:39:56 +02:00
|
|
|
/**
|
|
|
|
* Create a task and show it in the #task-details div.
|
|
|
|
*/
|
|
|
|
function task_create(shot_id, project_url, task_type) {
|
2016-09-22 09:27:28 +02:00
|
|
|
if (shot_id === undefined || project_url === undefined || task_type === undefined) {
|
|
|
|
if (console) console.log("task_create(", shot_id, project_url, task_type, ") called.");
|
|
|
|
return;
|
|
|
|
}
|
2016-09-22 10:34:51 +02:00
|
|
|
var url = '/attract/' + project_url + '/tasks/create';
|
2016-09-21 19:39:56 +02:00
|
|
|
|
2016-09-22 10:34:51 +02:00
|
|
|
data = {
|
|
|
|
task_type: task_type,
|
|
|
|
parent: shot_id,
|
|
|
|
};
|
2016-09-21 19:39:56 +02:00
|
|
|
|
2016-09-22 10:34:51 +02:00
|
|
|
$.post(url, data, function(task_data) {
|
2016-09-21 19:39:56 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-22 15:29:18 +02:00
|
|
|
function attract_form_save(form_id, item_id, item_save_url, options={})
|
|
|
|
{
|
|
|
|
var $form = $('#' + form_id);
|
2016-09-08 11:24:58 +02:00
|
|
|
var $button = $form.find("button[type='submit']");
|
2016-09-22 15:29:18 +02:00
|
|
|
|
2016-09-08 11:24:58 +02:00
|
|
|
var payload = $form.serialize();
|
2016-09-22 15:29:18 +02:00
|
|
|
var $item = $('#' + item_id);
|
2016-09-08 11:24:58 +02:00
|
|
|
|
|
|
|
$button.attr('disabled', true);
|
2016-09-22 15:29:18 +02:00
|
|
|
$item.addClass('processing');
|
2016-09-21 14:02:05 +02:00
|
|
|
$('#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-22 15:29:18 +02:00
|
|
|
$.post(item_save_url, payload)
|
|
|
|
.done(function(saved_item) {
|
|
|
|
if (console) console.log('Done saving', saved_item);
|
|
|
|
$('#status-bar').text('Saved item. ' + saved_item._updated);
|
2016-09-21 14:02:05 +02:00
|
|
|
|
2016-09-22 15:29:18 +02:00
|
|
|
if (options.done) options.done($item, saved_item);
|
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-21 15:14:42 +02:00
|
|
|
$('#status-bar').text('Failed saving. ' + xhr_or_response_data.responseText);
|
2016-09-22 15:29:18 +02:00
|
|
|
|
|
|
|
if (options.fail) options.fail($item, xhr_or_response_data);
|
2016-09-08 11:24:58 +02:00
|
|
|
})
|
|
|
|
.always(function() {
|
|
|
|
$button.attr('disabled', false);
|
2016-09-22 15:29:18 +02:00
|
|
|
$item.removeClass('processing');
|
|
|
|
|
|
|
|
if (options.always) options.always($item);
|
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.
|
|
|
|
}
|
2016-09-22 15:29:18 +02:00
|
|
|
|
|
|
|
function task_save(task_id, task_url) {
|
|
|
|
return attract_form_save('task_form', 'task-' + task_id, task_url, {
|
|
|
|
done: function($task, saved_task) {
|
|
|
|
// Update the task list.
|
|
|
|
// NOTE: this is tightly linked to the HTML of the task list in for_project.jade.
|
|
|
|
$('.task-name-' + saved_task._id).text(saved_task.name).flashOnce();
|
|
|
|
$task.find('span.name').text(saved_task.name);
|
|
|
|
$task.find('span.type').text(saved_task.task_type);
|
|
|
|
$task.find('span.status').text(saved_task.properties.status.replace('_', ' '));
|
|
|
|
|
|
|
|
// FIXME: remove all existing status-XXX classes.
|
|
|
|
$task
|
|
|
|
.removeClass('col-list-item task-list-item')
|
|
|
|
.addClass('col-list-item task-list-item status-' + saved_task.properties.status);
|
|
|
|
},
|
|
|
|
fail: function($item, xhr_or_response_data) {
|
|
|
|
$('#task-details').html(xhr_or_response_data.responseText);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function shot_save(shot_id, shot_url) {
|
|
|
|
return attract_form_save('shot_form', 'shot-' + shot_id, shot_url, {
|
|
|
|
done: function($shot, saved_shot) {
|
|
|
|
// Update the shot list.
|
|
|
|
$('.shot-name-' + saved_shot._id).text(saved_shot.name).flashOnce();
|
|
|
|
|
|
|
|
// FIXME: remove all existing status-XXX classes.
|
|
|
|
$shot
|
|
|
|
.removeClass('col-list-item shot-list-item')
|
|
|
|
.addClass('col-list-item shot-list-item status-' + saved_shot.properties.status);
|
|
|
|
},
|
|
|
|
fail: function($item, xhr_or_response_data) {
|
|
|
|
$('#task-details').html(xhr_or_response_data.responseText);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|