Move Tasks JS to layout, since we use it everywhere

This commit is contained in:
2016-09-21 19:39:56 +02:00
parent 7d64e8bf4e
commit fb6fa299f1
7 changed files with 103 additions and 81 deletions

View File

@@ -1,4 +1,54 @@
function save_task(task_id, task_url) {
/**
* Shows a task in the #task-details div.
*/
function task_open(task_id, project_url) {
if (task_id === undefined) {
if (console) console.log("task_open(undefined) called.");
return;
}
console.log('before anything');
$('#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);
});
}
/**
* Create a task and show it in the #task-details div.
*/
function task_create(shot_id, project_url, task_type) {
var base_url = '/attract/' + project_url + '/tasks/create';
if (task_type != undefined) {
base_url += '/' + task_type;
}
$.post(base_url, function(task_data) {
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);
});
}
function task_save(task_id, task_url) {
console.log('Saving task to', task_url);
var $form = $('#task-view form');
@@ -19,10 +69,11 @@ function save_task(task_id, task_url) {
// Update the task list.
// NOTE: this is tightly linked to the HTML of the task list in for_project.jade.
$(task + ' span.name').text($form.find("input[name='name']").val());
$(task + ' span.type').text($form.find("select[name='task_type']").val());
$(task + ' span.status').text($form.find("select[name='status']").val().replace('_', ' '));
$(task + ' span.status-indicator')
.removeAttr('class')
.addClass('status-indicator ' + $form.find("select[name='status']").val());
$(task)
.removeClass('col-list-item task-list-item')
.addClass('col-list-item task-list-item status-' + $form.find("select[name='status']").val());
$('#status-bar').text('Saved task. ' + data.time);
})

View File

@@ -1,6 +1,6 @@
body
background-color: $color-background
position: fixed
position: absolute
top: 0
left: 0
right: 0

View File

@@ -22,13 +22,11 @@ html(lang="en")
nav.sidebar(role="navigation")
dl
dd
a(href="") A
a(href="{{ url_for('attract.index') }}") A
dd
a(href="") B
a(href="{% if project %}{{ url_for('attract.tasks.perproject.index', project_url=project.url) }}{% else %}{{ url_for('attract.tasks.index') }}{% endif %}") T
dd
a(href="") C
dd
a(href="") A
a(href="{% if project %}{{ url_for('attract.shots.perproject.index', project_url=project.url) }}{% else %}{{ url_for('attract.shots.index') }}{% endif %}") S
| {% block body %}
#col_left
@@ -38,5 +36,6 @@ html(lang="en")
h1 Right
| {% endblock %}
script(src="{{ url_for('static_attract', filename='js/tasks.js') }}", async=true)
| {% block footer_scripts %}{% endblock %}

View File

@@ -1,14 +1,19 @@
| {% extends 'attract/layout.html' %}
| {% block page_title %}Shots for project {{ project.name }}{% endblock %}
| {% block page_title %}Shots - {{ project.name }}{% endblock %}
| {% block body %}
#col_main
h1 Shots for <em>{{ project.name }}</em>
.col_header.task-list-header
a(href="") Shots ({{ shots | count }})
a.task-project(href="{{url_for('projects.view', project_url=project.url)}}") {{ project.name }}
a#task-add(href="javascript:task_create('{{ project.url }}');") + Create Shot
table.table
thead
tr
td Shot name
td Name
| {% for task_type in task_types %}
td {{ task_type or '- other -' }}
td.text-capitalize {{ task_type or 'other' }}
| {% endfor %}
tbody
| {% for shot in shots %}
@@ -18,16 +23,20 @@
td
| {% for task in tasks_for_shots[shot._id][task_type] %}
a(
href="javascript:task_open('{{ task._id }}');",
href="javascript:task_open('{{ task._id }}, {{ project.url }}');",
class="status-{{ task.properties.status }}") {{ task.name }}
br
| {% endfor %}
a(
href="javascript:create_task('{{ shot._id }}', '{{ task_type }}');")
| Create task
br
href="javascript:task_create('{{ shot._id }}', '{{ project.url }}', '{{ task_type }}');")
| + Task
| {% endfor %}
| {% endfor %}
#col_right
h1 Right
.col_header
| Task Details
#status-bar
#task-details
| {% endblock %}

View File

@@ -1,5 +1,5 @@
| {% extends 'attract/layout.html' %}
| {% block page_title %}Attract - Shots{% endblock %}
| {% block page_title %}Shots{% endblock %}
| {% block body %}
#col_main
h1 Attract projects

View File

@@ -14,72 +14,26 @@ script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery.select
a(href="") Tasks ({{ tasks | count }})
a.task-project(href="{{url_for('projects.view', project_url=project.url)}}") {{ project.name }}
a#task-add(href="javascript:task_create();") + Create Task
a#task-add(href="javascript:task_create('{{ project.url }}');") + Create Task
#task-list.col-list
| {% for task in tasks %}
//- NOTE: this is tightly linked to the JS in tasks.js.
a.col-list-item.task-list-item(
id="task-{{task._id}}",
class="status-{{ task.properties.status }}"
href="javascript:task_open('{{ task._id }}');")
span.status-indicator(class="{{ task.properties.status }}")
class="status-{{ task.properties.status }}",
href="javascript:task_open('{{ task._id }}', '{{ project.url }}');")
span.status-indicator
span.name {{ task.name }}
span.status {{ task.properties.status | undertitle }}
//- span.status {{ task.properties.status | undertitle }}
span.type {{ task.properties.task_type }}
| {% endfor %}
#col_right
.col_header
| Task Details
#status-bar
#task-details
#task-view
| {{ tasks | count }} tasks so far.
a(href="javascript:task_create();") Create a new one!
| {% endblock %}
| {% block footer_scripts %}
script.
/**
* Shows a task in the #task-details div.
*/
function task_open(task_id) {
if (task_id === undefined) {
if (console) console.log("task_open(undefined) called.");
return;
}
$('#task-list').find('a').removeClass('active');
$('#task-' + task_id).addClass('active');
var base_url = "{{ url_for('attract.tasks.perproject.view_embed_task', project_url=project.url, task_id='TASKID') }}";
var task_url = base_url.replace("TASKID", task_id);
$.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);
});
}
/**
* Create a task and show it in the #task-details div.
*/
function task_create() {
var base_url = "{{ url_for('attract.tasks.perproject.create_task', project_url=project.url) }}";
$.post(base_url, function(task_data) {
task_open(task_data.task_id);
}).fail(function(xhr) {
if (console) {
console.log('Error creating task');
console.log('XHR:', xhr);
}
$('#task-details').html(xhr.responseText);
});
}
a(href="javascript:task_create('{{ project.url }}');") Create a new one!
| {% endblock %}

View File

@@ -1,6 +1,5 @@
script(src="{{ url_for('static_attract', filename='js/tasks.js') }}",async=true)
#task-view
form(onsubmit="return save_task('{{task._id}}', '{{ url_for('attract.tasks.perproject.save', project_url=project['url'], task_id=task._id) }}')")
form(onsubmit="return task_save('{{task._id}}', '{{ url_for('attract.tasks.perproject.save', project_url=project['url'], task_id=task._id) }}')")
.input-transparent-group
input.input-transparent.task-name(
name="name",
@@ -36,9 +35,11 @@ script(src="{{ url_for('static_attract', filename='js/tasks.js') }}",async=true)
| <option value="{{ status }}" {% if status == task.properties.status %}selected{% endif %}>{{ status | undertitle }}</option>
| {% endfor %}
.input-group-separator
.input-transparent-group.select_multiple
label Assignees:
select.input-transparent(
select#assignees.input-transparent(
name="users",
multiple,
placeholder="Assigned to"
@@ -48,7 +49,15 @@ script(src="{{ url_for('static_attract', filename='js/tasks.js') }}",async=true)
| {% endfor %}
.input-transparent-group
button.btn.btn-default(type=submit) Save task
button.btn.btn-default.btn-block(type=submit) Save Changes
#task-view-feed
| Updated {{ task._updated | pretty_date }}
ul
each _, i in Array(5)
li=i
script.
$("select[name='users']").select2();
$("#assignees").select2();