Consolidate forms for task creation and editing

This commit is contained in:
Scot Hacker 2018-03-24 12:24:49 -07:00
parent bc8adb63f5
commit 07e02b56f7
6 changed files with 128 additions and 177 deletions

View file

@ -0,0 +1,54 @@
{# Form used by both Add Task and Edit Task views #}
<form action="" name="add_task" method="post">
{% csrf_token %}
<div id="AddEditTask" class="collapse mt-3">
<div class="form-group">
<label for="id_title" name="title">Task</label>
<input type="text" class="form-control" id="id_title" name="title" required placeholder="Task title"
value="{% if form.title.value %}{{ form.title.value }}{% endif %}">
</div>
<div class="form-group">
<label for="id_note">Description</label>
<textarea class="form-control" id="id_note" name="note" rows="5"
aria-describedby="inputNoteHelp">{% if form.note.value %}{{ form.note.value }}{% endif %}</textarea>
<small id="inputNoteHelp" class="form-text text-muted">
Describe the task or bug. Provide steps to reproduce the issue.
</small>
</div>
<div class="form-group">
<label for="id_due_date">Due Date</label>
<input type="date" class="form-control" id="id_due_date" name="due_date"
value="{% if form.due_date.value %}{{ form.due_date.value|date:"Y-m-d" }}{% endif %}">
</div>
<div class="form-group">
<label for="id_assigned_to">Assigned To</label>
{# See todo.forms.AddItemForm #}
{{form.assigned_to}}
</div>
<div class="form-group">
<label for="id_notify">Notify</label>
<input type="checkbox" checked="checked" class="form-control" id="id_notify" name="notify" aria-describedby="inputNotifyHelp"
value="{{ form.notify.text }}">
<small id="inputNotifyHelp" class="form-text text-muted">
Email notifications will only be sent if task is assigned to someone other than yourself.
</small>
</div>
<input type="hidden" name="priority"
value="{% if form.priority.value %}{{ form.priority.value }}{% else %}999{% endif %}" id="id_priority">
<input type="hidden" name="created_by" value="{{ request.user.id }}" id="id_created_by">
<input type="hidden" name="task_list" value="{{ form.task_list.value }}" id="id_task_list">
<input type="hidden" name="created_date" value="{{ created_date }}" id="id_created_date">
<p>
<input type="submit" name="add_edit_task" value="Submit" class="btn btn-primary">
</p>
</div>
</form>

View file

@ -6,49 +6,11 @@
{% block content %}
{% if list_slug != "mine" %}
<form action="" name="add_task" method="post">
{% csrf_token %}
<button class="btn btn-primary" id="AddTaskButton" type="button"
data-toggle="collapse" data-target="#AddEditTask">Add Task</button>
<button class="btn btn-primary" id="AddTaskButton" type="button"
data-toggle="collapse" data-target="#AddTask">Add Task</button>
<div id="AddTask" class="collapse mt-3">
<div class="form-group">
<label for="id_title" name="title">Task</label>
<input type="text" class="form-control" id="id_title" name="title" required placeholder="Task title" value="{{ form.title.text }}">
</div>
<div class="form-group">
<label for="id_note">Description</label>
<textarea class="form-control" id="id_note" name="note"
rows="5" aria-describedby="inputNoteHelp">{{ form.note.text }}</textarea>
<small id="inputNoteHelp" class="form-text text-muted">Describe the task or bug. Provide steps to reproduce the issue.</small>
</div>
<div class="form-group">
<label for="id_due_date">Due Date</label>
<input type="date" class="form-control" id="id_due_date" name="due_date" value="{{ form.due_date.text }}">
</div>
<div class="form-group">
<label for="id_assigned_to">Assigned To</label>
{# See todo.forms.AddItemForm #}
{{form.assigned_to}}
</div>
<div class="form-group">
<label for="id_notify">Notify</label>
<input type="checkbox" checked="checked" class="form-control" id="id_notify" name="notify" aria-describedby="inputNotifyHelp" value="{{ form.notify.text }}">
<small id="inputNotifyHelp" class="form-text text-muted">Email notifications will only be sent if task is assigned to someone other than yourself.</small>
</div>
<input type="hidden" name="priority" value="999" id="id_priority">
<input type="hidden" name="created_by" value="{{ request.user.id }}" id="id_created_by">
<input type="hidden" name="task_list" value="{{ task_list.id }}" id="id_task_list">
<input type="hidden" name="created_date" value="{{ created_date }}" id="id_created_date">
<p><input type="submit" name="add_task" value="Submit" class="btn btn-primary"></p>
</div>
</form>
{# Task edit / new task form #}
{% include 'todo/include/task_edit.html' %}
<hr />
{% endif %}
@ -74,6 +36,7 @@
<th>Comm</th>
<th>Del</th>
</tr>
{% for task in items %}
<tr id="{{ task.id }}">
<td>
@ -112,6 +75,7 @@
</table>
<input type="submit" name="process_tasks" value="Process selection" class="btn btn-sm btn-success">
{% include 'todo/include/toggle_delete.html' %}
</form>

View file

@ -1,6 +1,7 @@
{% extends "todo/base.html" %}
{% block title %}{{ list_title }} Todo Lists{% endblock %}
{% block content %}
<h1>Todo Lists</h1>

View file

@ -4,6 +4,9 @@
{% block content %}
<button class="btn btn-primary" id="EditTaskButton" type="button"
data-toggle="collapse" data-target="#AddEditTask">Edit Task</button>
<div class="card-deck">
<div class="card col-sm-8">
<div class="card-body">
@ -15,88 +18,44 @@
</div>
<div class="card col-sm-4">
<ul class="list-group list-group-flush">
<li class="list-group-item">
<strong>Assigned to:</strong>
{% if task.assigned_to %}
{{ task.assigned_to.get_full_name }}
{% else %}
Anyone
{% endif %}
</li>
<li class="list-group-item">
<strong>Reported by:</strong> {{ task.created_by.get_full_name }}
</li>
<li class="list-group-item">
<strong>Due date:</strong> {{ task.due_date }}
</li>
<li class="list-group-item">
<strong>Completed:</strong> {{ task.completed|yesno:"Yes,No" }}
</li>
<li class="list-group-item">
<strong>In list:</strong>
<a href="{% url 'todo:list_detail' task.task_list.id task.task_list.slug %}">
{{ task.task_list }}
</a>
</li>
</ul>
</div>
</div>
<button id="slideToggle" class="mt-3 btn btn-primary">Edit task</button>
{% comment %} Needs form tag {% endcomment %}
<div id="TaskEdit">
<h3>Edit Task</h3>
<table>
<tr>
<td>Title:</td>
<td>{{ form.title }}
</td>
</tr>
<tr>
<td>List:</td>
<td>{{ form.task_list }}
</td>
</tr>
<tr>
<td>Due:</td>
<td>{{ form.due_date }}
</td>
</tr>
<tr>
<td>Assigned to:</td>
<td>{{ form.assigned_to }}
</td>
</tr>
<tr>
<td valign="top">Note:</td>
<td>{{ form.note }}
</td>
</tr>
<tr>
<td>Priority:</td>
<td>{{ form.priority }}
</td>
</tr>
</table>
<p><input type="submit" class="btn btn-primary" name="edit_task" value="Edit task"></p>
<ul class="list-group list-group-flush">
<li class="list-group-item">
<strong>Assigned to:</strong>
{% if task.assigned_to %} {{ task.assigned_to.get_full_name }} {% else %} Anyone {% endif %}
</li>
<li class="list-group-item">
<strong>Reported by:</strong> {{ task.created_by.get_full_name }}
</li>
<li class="list-group-item">
<strong>Due date:</strong> {{ task.due_date }}
</li>
<li class="list-group-item">
<strong>Completed:</strong> {{ task.completed|yesno:"Yes,No" }}
</li>
<li class="list-group-item">
<strong>In list:</strong>
<a href="{% url 'todo:list_detail' task.task_list.id task.task_list.slug %}">
{{ task.task_list }}
</a>
</li>
</ul>
</div>
<hr/>
</div>
<h3>Add comment</h3>
<textarea name="comment-body"></textarea>
<p><input class="btn btn-primary" type="submit" value="Submit"></p>
<div id="TaskEdit">
{# Task edit / new task form #}
{% include 'todo/include/task_edit.html' %}
</div>
<h3>Add comment</h3>
<form action="" method="post">
{% csrf_token %}
<div class="form-group">
<textarea class="form-control" name="comment-body" rows="3"></textarea>
</div>
<input class="btn btn-primary" type="submit" name="add_comment" value="Add Comment">
</form>
<div class="task_comments">
{% if comment_list %}
@ -116,17 +75,3 @@
</div>
{% endblock %}
{% block extra_js %}
<script type="text/javascript">
$(document).ready(function () {
// Initially hide the TaskEdit form
$('#TaskEdit').hide();
// toggle slide to show the Add Task form when link clicked
$('#slideToggle').click(function () {
$(this).siblings('#TaskEdit').slideToggle();
});
});
</script>
{% endblock extra_js %}