Made shot and task links real links with JS click handlers.

This allows "open in new window", while still using XHR for regular clicks.
This commit is contained in:
2016-09-23 10:28:47 +02:00
parent 78111968ab
commit e6e03125f7
6 changed files with 55 additions and 22 deletions

View File

@@ -33,7 +33,7 @@ def index():
@perproject_blueprint.route('/', endpoint='index')
@perproject_blueprint.route('/with-task/<task_id>', endpoint='with-task')
@perproject_blueprint.route('/with-task/<task_id>', endpoint='with_task')
@attract_project_view(extension_props=True)
def for_project(project, attract_props, task_id=None, shot_id=None):
api = pillar_api()

View File

@@ -34,11 +34,16 @@
/**
* Shows a task in the #task-details div.
*/
function task_open(task_id, project_url) {
if (task_id === undefined || project_url === undefined) {
function task_open(task_id) {
if (task_id === undefined) {
throw new ReferenceError("task_open(" + task_id + ") called.");
}
var project_url = ProjectUtils.projectUrl();
if (typeof project_url === 'undefined') {
throw "ProjectUtils.projectUrl() undefined";
}
$('#col_right .col_header span.header_text').text('Task details');
$('[id^="task-"]').removeClass('active');
@@ -60,11 +65,16 @@ function task_open(task_id, project_url) {
/**
* Shows a shot in the #task-details div.
*/
function shot_open(shot_id, project_url) {
if (shot_id === undefined || project_url === undefined) {
function shot_open(shot_id) {
if (shot_id === undefined) {
throw new ReferenceError("shot_open(" + shot_id + ") called.");
}
var project_url = ProjectUtils.projectUrl();
if (typeof project_url === 'undefined') {
throw "ProjectUtils.projectUrl() undefined";
}
$('#col_right .col_header span.header_text').text('Shot details');
$('[id^="shot-"]').removeClass('active');
@@ -209,3 +219,18 @@ function shot_save(shot_id, shot_url) {
type: 'shot'
});
}
$(function() {
$("a.shot-link[data-shot-id]").click(function(e) {
e.preventDefault();
// delegateTarget is the thing the event hander was attached to,
// rather than the thing we clicked on.
var shot_id = e.delegateTarget.dataset.shotId;
shot_open(shot_id);
});
$("a.task-link[data-task-id]").click(function(e) {
e.preventDefault();
var task_id = e.delegateTarget.dataset.taskId;
task_open(task_id);
});
});

View File

@@ -24,7 +24,7 @@ def index():
@perproject_blueprint.route('/', endpoint='index')
@attract_project_view()
def for_project(project):
def for_project(project, task_id=None):
api = pillar_api()
tasks = pillarsdk.Node.all({
@@ -35,12 +35,16 @@ def for_project(project):
return render_template('attract/tasks/for_project.html',
tasks=tasks['_items'],
open_task_id=task_id,
project=project)
@perproject_blueprint.route('/<task_id>')
@attract_project_view(extension_props=True)
def view_embed_task(project, attract_props, task_id):
def view_task(project, attract_props, task_id):
if not request.is_xhr:
return for_project(project, task_id=task_id)
api = pillar_api()
task = pillarsdk.Node.find(task_id, api=api)
node_type = project.get_node_type(node_type_task['name'])