Files
attract/src/scripts/tutti/10_tasks.js

77 lines
2.1 KiB
JavaScript
Raw Normal View History

/**
* Create a asset and show it in the #item-details div.
*/
function thenCreateAsset(project_url)
{
if (project_url === undefined) {
throw new ReferenceError("asset_create(" + project_url+ ") called.");
}
var url = '/attract/' + project_url + '/assets/create';
data = {
project_url: project_url
};
return $.post(url, data, function(asset_data) {
pillar.events.Nodes.triggerCreated(asset_data);
return asset_data;
})
.fail(function(xhr) {
if (console) {
console.log('Error creating asset');
console.log('XHR:', xhr);
}
$('#item-details').html(xhr.responseText);
});
}
/**
* Create a task and show it in the #item-details div.
2016-10-04 15:21:59 +02:00
*
* 'shot_id' may be undefined, in which case the task will not
* be attached to a shot.
*/
function thenCreateTask(shot_id, task_type)
{
2016-10-04 15:21:59 +02:00
if (task_type === undefined) {
throw new ReferenceError("task_create(" + shot_id + ", " + task_type + ") called.");
}
var project_url = ProjectUtils.projectUrl();
var url = '/attract/' + project_url + '/tasks/create';
2016-10-04 15:21:59 +02:00
var has_shot_id = typeof shot_id !== 'undefined';
data = {
task_type: task_type,
};
2016-10-04 15:21:59 +02:00
if (has_shot_id) data.parent = shot_id;
return $.post(url, data, function(task_data) {
if (console) console.log('Task created:', task_data);
pillar.events.Nodes.triggerCreated(task_data);
return task_data;
})
.fail(function(xhr) {
if (console) {
console.log('Error creating task');
console.log('XHR:', xhr);
}
$('#item-details').html(xhr.responseText);
});
}
2016-11-09 15:26:11 +01:00
var save_on_ctrl_enter = ['shot', 'asset', 'task'];
2016-10-20 15:33:44 +02:00
$(document).on('keyup', function(e){
2017-02-14 15:57:08 +01:00
if ($.inArray(save_on_ctrl_enter, ProjectUtils.context())) {
var active = document.activeElement;
// Save on Ctrl + Enter anytime except when comment field is on focus
if (active.id != 'comment_field'){
if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey){
$("#item-save").trigger( "click" );
}
}
2016-10-20 15:33:44 +02:00
}
});