Templates & Flask end-points for managing assets.
This commit is contained in:
@@ -34,18 +34,21 @@ function item_open(item_id, item_type, pushState, project_url)
|
||||
$('[id^="' + item_type + '-"]').removeClass('active');
|
||||
$('#' + item_type + '-' + item_id).addClass('active');
|
||||
|
||||
// Special case to highlight the shot row when opening task in shot context
|
||||
if (ProjectUtils.context() == 'shot' && item_type == 'task'){
|
||||
// Special case to highlight the shot row when opening task in shot or asset context
|
||||
var pu_ctx = ProjectUtils.context();
|
||||
var pc_ctx_shot_asset = (pu_ctx == 'shot' || pu_ctx == 'asset');
|
||||
if (pc_ctx_shot_asset && item_type == 'task'){
|
||||
$('[id^="shot-"]').removeClass('active');
|
||||
$('[id^="asset-"]').removeClass('active');
|
||||
$('#task-' + item_id).closest('.table-row').addClass('active');
|
||||
}
|
||||
|
||||
var item_url = '/attract/' + project_url + '/' + item_type + 's/' + item_id;
|
||||
var push_url = item_url;
|
||||
if (ProjectUtils.context() == 'shot' && item_type == 'task'){
|
||||
push_url = '/attract/' + project_url + '/shots/with-task/' + item_id;
|
||||
if (pc_ctx_shot_asset && item_type == 'task'){
|
||||
push_url = '/attract/' + project_url + '/' + pu_ctx + 's/with-task/' + item_id;
|
||||
}
|
||||
item_url += '?context=' + ProjectUtils.context();
|
||||
item_url += '?context=' + pu_ctx;
|
||||
|
||||
statusBarSet('default', 'Loading ' + item_type + '…');
|
||||
|
||||
@@ -94,6 +97,11 @@ function shot_open(shot_id)
|
||||
item_open(shot_id, 'shot');
|
||||
}
|
||||
|
||||
function asset_open(asset_id)
|
||||
{
|
||||
item_open(asset_id, 'asset');
|
||||
}
|
||||
|
||||
window.onpopstate = function(event)
|
||||
{
|
||||
var state = event.state;
|
||||
@@ -102,26 +110,26 @@ window.onpopstate = function(event)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a task and show it in the #item-details div.
|
||||
* NOTE: Not used at the moment, we're creating shots via Blender's VSE
|
||||
* Create a asset and show it in the #item-details div.
|
||||
* NOTE: Not used at the moment, we're creating assets via Blender's VSE
|
||||
*/
|
||||
function shot_create(project_url)
|
||||
function asset_create(project_url)
|
||||
{
|
||||
if (project_url === undefined) {
|
||||
throw new ReferenceError("shot_create(" + project_url+ ") called.");
|
||||
throw new ReferenceError("asset_create(" + project_url+ ") called.");
|
||||
}
|
||||
var url = '/attract/' + project_url + '/shots/create';
|
||||
var url = '/attract/' + project_url + '/assets/create';
|
||||
|
||||
data = {
|
||||
project_url: project_url
|
||||
};
|
||||
|
||||
$.post(url, data, function(shot_data) {
|
||||
shot_open(shot_data.shot_id);
|
||||
$.post(url, data, function(asset_data) {
|
||||
asset_open(asset_data.asset_id);
|
||||
})
|
||||
.fail(function(xhr) {
|
||||
if (console) {
|
||||
console.log('Error creating task');
|
||||
console.log('Error creating asset');
|
||||
console.log('XHR:', xhr);
|
||||
}
|
||||
$('#item-details').html(xhr.responseText);
|
||||
@@ -156,17 +164,17 @@ function task_add(shot_id, task_id, task_type)
|
||||
<span class="due_date">-</span>\
|
||||
</a>\
|
||||
');
|
||||
} else if (context == 'shot') {
|
||||
} else if (context == 'shot' || context == 'asset') {
|
||||
if (shot_id === undefined) {
|
||||
throw new ReferenceError("task_add(" + shot_id + ", " + task_id + ", " + task_type + ") called in shot context.");
|
||||
throw new ReferenceError("task_add(" + shot_id + ", " + task_id + ", " + task_type + ") called in " + context + " context.");
|
||||
}
|
||||
|
||||
var $shot_cell = $('#shot-' + shot_id + ' .table-cell.task-type.' + task_type);
|
||||
var url = '/attract/' + project_url + '/shots/with-task/' + task_id;
|
||||
var $list_cell = $('#' + context + '-' + shot_id + ' .table-cell.task-type.' + task_type);
|
||||
var url = '/attract/' + project_url + '/' + context + 's/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('\
|
||||
$list_cell.append('\
|
||||
<a class="status-todo task-link active"\
|
||||
title="-save your task first-"\
|
||||
href="' + url + '"\
|
||||
@@ -175,7 +183,9 @@ function task_add(shot_id, task_id, task_type)
|
||||
</a>\
|
||||
');
|
||||
|
||||
$shot_cell.find('.task-add.task-add-link').addClass('hidden');
|
||||
$list_cell.find('.task-add.task-add-link').addClass('hidden');
|
||||
} else {
|
||||
if (console) console.log('task_add: not doing much in context', context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,6 +332,36 @@ function shot_save(shot_id, shot_url) {
|
||||
});
|
||||
}
|
||||
|
||||
function asset_save(asset_id, asset_url) {
|
||||
return attract_form_save('shot_form', 'asset-' + asset_id, asset_url, {
|
||||
done: function($asset, saved_asset) {
|
||||
// Update the asset list.
|
||||
// NOTE: this is tightly linked to the HTML of the asset list in for_project.jade.
|
||||
$('.asset-name-' + saved_asset._id).text(saved_asset.name).flashOnce();
|
||||
$asset.find('span.name').text(saved_asset.name);
|
||||
$asset.find('span.due_date').text(moment().to(saved_asset.properties.due_date));
|
||||
$asset.find('span.status').text(saved_asset.properties.status.replace('_', ' '));
|
||||
|
||||
$asset
|
||||
.removeClassPrefix('status-')
|
||||
.addClass('status-' + saved_asset.properties.status)
|
||||
.flashOnce()
|
||||
;
|
||||
|
||||
asset_open(asset_id);
|
||||
},
|
||||
fail: function($item, xhr_or_response_data) {
|
||||
if (xhr_or_response_data.status == 412) {
|
||||
// TODO: implement something nice here. Just make sure we don't throw
|
||||
// away the user's edits. It's up to the user to handle this.
|
||||
} else {
|
||||
$('#item-details').html(xhr_or_response_data.responseText);
|
||||
}
|
||||
},
|
||||
type: 'asset'
|
||||
});
|
||||
}
|
||||
|
||||
function task_delete(task_id, task_etag, task_delete_url) {
|
||||
if (task_id === undefined || task_etag === undefined || task_delete_url === undefined) {
|
||||
throw new ReferenceError("task_delete(" + task_id + ", " + task_etag + ", " + task_delete_url + ") called.");
|
||||
|
Reference in New Issue
Block a user