Merge branch 'assets' of https://github.com/nottinghamtec/PyRIGS into assets

This commit is contained in:
Matthew Smith
2019-10-02 21:14:03 +01:00
6 changed files with 256 additions and 249 deletions

View File

@@ -1,15 +1,26 @@
{% for item in object_list %} {% for item in object_list %}
{# <li><a href="{% url 'asset_detail' item.pk %}">{{ item.asset_id }} - {{ item.description }}</a></li>#} {# <li><a href="{% url 'asset_detail' item.pk %}">{{ item.asset_id }} - {{ item.description }}</a></li>#}
<tr> <!---TODO: When the ability to filter the list is added, remove the colours from the filter - specifically, stop greying out sold/binned stuff if it is being searched for--->
<tr class="
{% if item.status.name == 'Broken' %}
danger
{% elif item.status.name == 'Lost'%}
warning
{% elif item.status.name == 'In Service'%}
success
{% elif item.status.name in 'Sold|Binned'%}
text-muted
{% endif %}
">
<td><a href="{% url 'asset_detail' item.pk %}">{{ item.asset_id }}</a></td> <td><a href="{% url 'asset_detail' item.pk %}">{{ item.asset_id }}</a></td>
<td>{{ item.description }}</td> <td>{{ item.description }}</td>
<td>{{ item.category }}</td> <td>{{ item.category }}</td>
<td>{{ item.status }}</td> <td>{{ item.status }}</td>
<td> <td>
<div class="btn-group" role="group"> <div class="btn-group" role="group">
<button type="button" class="btn btn-default" formaction="{% url 'asset_detail' item.pk %}"><i class="glyphicon glyphicon-eye-open"></i> View</button> <a type="button" class="btn btn-default btn-sm" href="{% url 'asset_detail' item.pk %}"><i class="glyphicon glyphicon-eye-open"></i> View</a>
<button type="button" class="btn btn-default" formaction="{% url 'asset_update' item.pk %}"><i class="glyphicon glyphicon-edit"></i> Edit</button> <a type="button" class="btn btn-default btn-sm" href="{% url 'asset_update' item.pk %}"><i class="glyphicon glyphicon-edit"></i> Edit</a>
<button type="button" class="btn btn-default" formaction="{% url 'asset_update' item.pk %}?duplicate=true"><i class="glyphicon glyphicon-duplicate"></i> Duplicate</button> <a type="button" class="btn btn-default btn-sm" href="{% url 'asset_update' item.pk %}?duplicate=true"><i class="glyphicon glyphicon-duplicate"></i> Duplicate</a>
</div> </div>
</td> </td>
</tr> </tr>

View File

@@ -8,278 +8,249 @@
<div class="page-header"> <div class="page-header">
<h1> <h1>
{% if edit and object %} {% if edit and object %}
Edit Asset | {{ object.asset_id }} Edit Asset: {{ object.asset_id }} {{ object.description }}
{% elif duplicate %} {% elif duplicate %}
Duplication of Asset | {{ previous_asset_id }} Duplication of Asset: {{ previous_asset_id }}
{% elif not object %} {% elif not object %}
Create Asset Create Asset
{% else %} {% else %}
Asset | {{ object.asset_id }} Asset: {{ object.asset_id }} {{ object.description }}
{% endif %} {% endif %}
</h1>
</h1>
</div> </div>
<br> <div class="row" style="padding-bottom: 1em">
<div class="col-sm-12">
<div class="pull-right">
{% include 'partials/asset_buttons.html' %}
</div>
</div>
</div>
<form method="post" id="asset_update_form"> <form method="post" id="asset_update_form">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="id" value="{{ object.id|default:0 }}"> <input type="hidden" name="id" value="{{ object.id|default:0 }}" hidden=true>
<div class="row">
<div class="panel panel-default"> <div class="col-sm-12">
<div class="panel-heading"> <div class="panel panel-default">
Asset Details <div class="panel-heading">
</div> Asset Details
<div class="panel-body"> </div>
<div class="form-group"> <div class="panel-body">
<label for="{{ form.asset_id.id_for_label }}" class="bold-text">Asset ID</label> {% if edit or duplicate %}
{% if edit or duplicate %} <div class="form-group">
{% if duplicate %} <label for="{{ form.asset_id.id_for_label }}">Asset ID</label>
{% render_field form.asset_id|add_class:'form-control' value=object.asset_id %} {% if duplicate %}
{% elif object.asset_id %} {% render_field form.asset_id|add_class:'form-control' value=object.asset_id %}
{% render_field form.asset_id|attr:'readonly'|add_class:'disabled_input form-control' value=object.asset_id %} {% elif object.asset_id %}
{% else %} {% render_field form.asset_id|attr:'readonly disabled'|add_class:'disabled_input form-control' value=object.asset_id %}
{% render_field form.asset_id|add_class:'form-control' %} {% else %}
{% endif %} {% render_field form.asset_id|add_class:'form-control' %}
</div> {% endif %}
</div>
<div class="form-group"> <div class="form-group">
<label for="{{ form.description.id_for_label }}" <label for="{{ form.description.id_for_label }}"
class="bold-text">Description</label> >Description</label>
{% render_field form.description|add_class:'form-control' value=object.description %} {% render_field form.description|add_class:'form-control' value=object.description %}
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="{{ form.category.id_for_label }}" class="bold-text">Category</label> <label for="{{ form.category.id_for_label }}" >Category</label>
<select name="{{ form.category.name }}" id="{{ form.category.id_for_label }}" <select name="{{ form.category.name }}" id="{{ form.category.id_for_label }}"
required class="form-control"> required class="form-control">
{% for id, choice in form.category.field.choices %} {% for id, choice in form.category.field.choices %}
<option value="{{ id }}" <option value="{{ id }}"
{% if object.category.id == id %}selected{% endif %}>{{ choice }}</option> {% if object.category.id == id %}selected{% endif %}>{{ choice }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="{{ form.status.id_for_label }}" class="bold-text">Status</label> <label for="{{ form.status.id_for_label }}" >Status</label>
<select class="form-control" name="{{ form.status.name }}" id="{{ form.status.id_for_label }}" required> <select class="form-control" name="{{ form.status.name }}" id="{{ form.status.id_for_label }}" required>
{% for id, choice in form.status.field.choices %} {% for id, choice in form.status.field.choices %}
<option value="{{ id }}" <option value="{{ id }}"
{% if not object.status.id and choice == "Active" or object.status.id == id %}selected{% endif %}>{{ choice }}</option> {% if not object.status.id and choice == "Active" or object.status.id == id %}selected{% endif %}>{{ choice }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div>
<div class="form-group">
<label for="{{ form.serial_number.id_for_label }}">Serial Number</label>
{% render_field form.serial_number|add_class:'form-control' value=object.serial_number %}
</div>
<!---TODO: Lower default number of lines in comments box--->
<div class="form-group">
<label for="{{ form.comments.id_for_label }}">Comments</label>
{% render_field form.comments|add_class:'form-control' %}
</div>
{% else %}
<dt>Asset ID</dt>
<dd>{{ object.asset_id }}</dd>
<dt>Description</dt>
<dd>{{ object.description }}</dd>
<dt>Category</dt>
<dd>{{ object.category }}</dd>
<dt>Status</dt>
<dd>{{ object.status }}</dd>
<dt>Serial Number</dt>
<dd>{{ object.serial_number|default:'-' }}</dd>
<dt>Comments</dt>
<dd>{{ object.comments|default:'-'|linebreaksbr }}</dd>
{% endif %}
</div>
</div> </div>
<div class="form-group">
<label for="{{ form.serial_number.id_for_label }}">Serial Number</label>
{% render_field form.serial_number|add_class:'form-control' value=object.serial_number %}
</div>
<!---TODO: Lower default number of lines in comments box--->
<div class="form-group">
<label for="{{ form.comments.id_for_label }}">Comments</label>
{% render_field form.comments|add_class:'form-control' %}
</div>
{% else %}
<dt>Asset ID</dt>
<dd>{{ object.asset_id }}</dd>
<dt>Description</dt>
<dd>{{ object.description }}</dd>
<dt>Category</dt>
<dd>{{ object.category }}</dd>
<dt>Status</dt>
<dd>{{ object.status }}</dd>
<dt>Serial Number</dt>
<dd>{{ object.serial_number|default:'-' }}</dd>
<dt>Comments</dt>
<dd>{{ object.comments|default:'-'|linebreaksbr }}</dd>
{% endif %}
</div> </div>
</div> </div>
<div class="row">
<div class="panel panel-default"> <div class="col-md-6">
<div class="panel-heading"> <div class="panel panel-default">
Purchase Details <div class="panel-heading">
</div> Purchase Details
<div class="panel-body"> </div>
{% if edit or duplicate %} <div class="panel-body">
{% if edit or duplicate %}
<div class="form-group"> <div class="form-group">
<label for="{{ form.purchased_from.id_for_label }}">Purchased From</label> <label for="{{ form.purchased_from.id_for_label }}">Purchased From</label>
<select class="form-control" name="{{ form.purchased_from.name }}" <select class="form-control" name="{{ form.purchased_from.name }}"
id="{{ form.purchased_from.id_for_label }}"> id="{{ form.purchased_from.id_for_label }}">
{% for id, choice in form.purchased_from.field.choices %} {% for id, choice in form.purchased_from.field.choices %}
<option value="{{ id }}" <option value="{{ id }}"
{% if object.purchased_from.id == id %}selected{% endif %}>{{ choice }}</option> {% if object.purchased_from.id == id %}selected{% endif %}>{{ choice }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="{{ form.purchase_price.id_for_label }}">Purchase Price</label> <label for="{{ form.purchase_price.id_for_label }}">Purchase Price</label>
<div class="input-group"> <div class="input-group">
<span class="input-group-addon">£</span> <span class="input-group-addon">£</span>
{% render_field form.purchase_price|add_class:'form-control' value=object.purchase_price %} {% render_field form.purchase_price|add_class:'form-control' value=object.purchase_price %}
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="{{ form.salvage_value.id_for_label }}">Salvage Value</label> <label for="{{ form.salvage_value.id_for_label }}">Salvage Value</label>
<div class="input-group"> <div class="input-group">
<span class="input-group-addon">£</span> <span class="input-group-addon">£</span>
{% render_field form.salvage_value|add_class:'form-control' value=object.salvage_value %} {% render_field form.salvage_value|add_class:'form-control' value=object.salvage_value %}
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="{{ form.date_acquired.id_for_label }}" class="bold-text">Date <label for="{{ form.date_acquired.id_for_label }}" >Date
Acquired</label> Acquired</label>
{% if object.date_acquired %} {% if object.date_acquired %}
{% render_field form.date_acquired|add_class:'datepicker form-control' value=object.date_acquired|date %} {% render_field form.date_acquired|add_class:'form-control'|attr:'type="date"' value=object.date_acquired|date %}
{% else %} {% else %}
<input type="text" name="date_acquired" value="{% now "DATE_FORMAT" %}" <input type="date" name="date_acquired" value="{% now "DATE_FORMAT" %}"
class="datepicker form-control" id="id_date_acquired"> class="form-control" id="id_date_acquired">
{% endif %} {% endif %}
</div> </div>
<!---TODO: Presumably, this should only appear if the asset is in the sold category?---> <div class="form-group">
<div class="form-group"> <label for="{{ form.date_sold.id_for_label }}">Date Sold</label>
<label for="{{ form.date_sold.id_for_label }}">Date Sold</label> {% render_field form.date_sold|add_class:'form-control'|attr:'type="date"' value=object.date_sold|date %}
{% render_field form.date_sold|add_class:'datepicker form-control' value=object.date_sold|date %} </div>
</div> {% else %}
</div> <dl>
{% else %} <dt>Purchased From</dt>
<dt>Purchased From</dt> <dd>{{ object.purchased_from|default_if_none:'-' }}</dd>
<dd>{{ object.purchased_from|default_if_none:'-' }}</dd>
<dt>Purchase Price</dt> <dt>Purchase Price</dt>
<dd>£{{ object.purchase_price|default_if_none:'-' }}</dd> <dd>£{{ object.purchase_price|default_if_none:'-' }}</dd>
<dt>Salvage Value</dt> <dt>Salvage Value</dt>
<dd>£{{ object.salvage_value|default_if_none:'-' }}</dd> <dd>£{{ object.salvage_value|default_if_none:'-' }}</dd>
<dt>Date Acquired</dt> <dt>Date Acquired</dt>
<dd>{{ object.date_acquired|default_if_none:'-' }}</dd> <dd>{{ object.date_acquired|default_if_none:'-' }}</dd>
{% if object.date_sold %}
<dt>Date Sold</dt> <dt>Date Sold</dt>
<dd>{{ object.date_sold|default_if_none:'-' }}</dd> <dd>{{ object.date_sold|default_if_none:'-' }}</dd>
{% endif %} {% endif %}
</dl> </dl>
</div> {% endif %}
</div>
{% if object.is_cable %}
<div class="form-group">
<div class="panel">
<div class="panel-heading">
Cable Details
</div>
<div class="panel-body">
<dl class="dl-horizontal">
<dt>Length</dt>
<dd>{{ object.length }}m</dd>
<dt>Type</dt>
<dd>TODO</dd>
<dt>Required CSA</dt>
<dd>TODO</dd>
</dl>
</div>
</div>
</div>
{% endif %}
<div class="panel panel-default">
<div class="panel-heading">
Collection Details
</div>
<div class="panel-body">
<dl class="dl-horizontal">
{% if edit or duplicate %}
<div class="form-group">
<label for="parent_id">Parent</label>
<input type="hidden" name="{{ form.parent.html_name }}" id="hidden_parent_id"
value="{{ object.parent.id }}">
<div class="input-group">
<input type="text" id="parent_id" value="{{ object.parent|default:'' }}"
disabled="" class="form-control">
<span class="input-group-btn"><button type="button" class="btn btn-default" onclick="clearParent()">Clear
</button></span>
</div> </div>
</div> </div>
</div>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
Collection Details
</div>
<div class="panel-body">
{% if edit or duplicate %}
<div class="form-group">
<label for="parent_id">Parent</label>
<input type="hidden" name="{{ form.parent.html_name }}" id="hidden_parent_id"
value="{{ object.parent.id }}">
<div class="input-group">
<input type="text" id="parent_id" value="{{ object.parent|default:'' }}"
disabled="" class="form-control">
<span class="input-group-btn"><button type="button" class="btn btn-default" onclick="clearParent()">Clear
</button></span>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label for="parent_search">Search for asset</label> <label for="parent_search">Search for asset</label>
<div class="input-group"> <div class="input-group">
<input type="text" id="parent_search" class="form-control"> <input type="text" id="parent_search" class="form-control">
<span class="input-group-btn"><button type="button" class="btn btn-default" onclick="formAssetSearch()"> <span class="input-group-btn"><button type="button" class="btn btn-default" onclick="formAssetSearch()">
<i class="glyphicon glyphicon-search"></i> Search <i class="glyphicon glyphicon-search"></i> Search
</button></span> </button></span>
</div> </div>
</div> </div>
<div class="col s2"> <div class="col s2">
<br> <br>
</div> </div>
<div class="col s12" id="formAssetSearchResult"> <div class="col s12" id="formAssetSearchResult">
<!--Placeholder for search results--> <!--Placeholder for search results-->
</div>
{% else %}
<dl>
<dt>Parent</dt>
<dd>
{% if object.parent %}
<a href="{% url 'asset_detail' object.parent.pk %}">
{{ object.parent.asset_id }} - {{ object.parent.description }}
</a>
{% else %}
<span>-</span>
{% endif %}
</dd>
<dt>Children</dt>
{% if object.asset_parent.all %}
{% for child in object.asset_parent.all %}
<dd>
<a href="{% url 'asset_detail' child.pk %}">
{{ child.asset_id }} - {{ child.description }}
</a>
</dd>
{% endfor %}
{% else %}
<dd><span>-</span></dd>
{% endif %}
</dl>
{% endif %}
</div>
</div> </div>
</div> </div>
{% else %} </div>
<dt>Parent</dt>
<dd>
{% if object.parent %}
<a href="{% url 'asset_detail' object.parent.pk %}">
{{ object.parent.asset_id }} - {{ object.parent.description }}
</a>
{% else %}
<span>-</span>
{% endif %}
</dd>
<dt>Children</dt>
{% if object.asset_parent.all %}
{% for child in object.asset_parent.all %}
<dd>
<a href="{% url 'asset_detail' child.pk %}">
{{ child.asset_id }} - {{ child.description }}
</a>
</dd>
{% endfor %}
{% else %}
<dd><span>-</span></dd>
{% endif %}
{% endif %}
</dl>
</div>
</form> </form>
<div class="btn-group"> <div class="row">
{% if edit and object %} <div class="col-md-12">
<!--edit--> {% include 'partials/asset_buttons.html' %}
<button type="button" class="btn btn-success" onclick="updateAsset()">Save</button> </div>
<a class="btn btn-default" href="{% url 'asset_update' object.pk %}?duplicate=true">Duplicate</a>
<a class="btn btn-danger" href="#confirm_delete_modal">Delete</a>
{% elif duplicate %}
<!--duplicate-->
<button type="button" class="btn btn-default" onclick="updateAsset()">Create Duplicate</button>
<a href="{% url 'asset_detail' previous_asset_pk %}" class="btn">Cancel</a>
{% elif not object %}
<!--create-->
<button type="button" class="btn btn-success" onclick="updateAsset()">Save</button>
{% else %}
<!--detail-->
<a href="{% url 'asset_update' object.pk %}" class="btn btn-warning">Edit</a>
<a class="btn btn-default" href="{% url 'asset_update' object.pk %}?duplicate=true">Duplicate</a>
<a class="btn btn-danger" href="#confirm_delete_modal">Delete</a>
{% endif %}
</div> </div>
{% include 'confirm_delete.html' with object=object %} {% include 'partials/confirm_delete.html' with object=object %}
{% endblock %} {% endblock %}

View File

@@ -1,16 +0,0 @@
<div id="confirm_delete_modal" class="modal">
<form method="post" id="confirm_delete_form">
{% csrf_token %}
<div class="modal-content">
<h4>Confirm Delete</h4>
<p>Are you sure you want to delete asset:
<strong>{{ object }}</strong>
</p>
</div>
<div class="modal-footer">
<button type="button" class="modal-close btn-flat" onclick="deleteAsset({{ object.id }})">Delete</button>
{# <a href="#" class="modal-close btn-flat green">Close</a>#}
<a href="#" class="modal-close btn-flat red">Cancel</a>
</div>
</form>
</div>

View File

@@ -0,0 +1,20 @@
<div class="btn-group">
{% if edit and object %}
<!--edit-->
<button type="button" class="btn btn-success" onclick="updateAsset()"><i class="glyphicon glyphicon-floppy-disk"></i> Save</button>
<a class="btn btn-default" href="{% url 'asset_update' object.pk %}?duplicate=true"><i class="glyphicon glyphicon-duplicate"></i> Duplicate</a>
<a class="btn btn-danger" data-toggle="modal" data-target="#confirm_delete_modal"><i class="glyphicon glyphicon-trash"></i> Delete</a>
{% elif duplicate %}
<!--duplicate-->
<button type="button" class="btn btn-default" onclick="updateAsset()"><i class="glyphicon glyphicon-ok-sign"></i> Create Duplicate</button>
<a href="{% url 'asset_detail' previous_asset_pk %}" class="btn btn-warning"><i class="glyphicon glyphicon-remove"></i> Cancel</a>
{% elif not object %}
<!--create-->
<button type="button" class="btn btn-success" onclick="updateAsset()"><i class="glyphicon glyphicon-floppy-disk"></i> Save</button>
{% else %}
<!--detail view-->
<a href="{% url 'asset_update' object.pk %}" class="btn btn-default"><i class="glyphicon glyphicon-edit"></i> Edit</a>
<a class="btn btn-default" href="{% url 'asset_update' object.pk %}?duplicate=true"><i class="glyphicon glyphicon-duplicate"></i> Duplicate</a>
<a class="btn btn-danger" data-toggle="modal" data-target="#confirm_delete_modal"><i class="glyphicon glyphicon-trash"></i> Delete</a>
{% endif %}
</div>

View File

@@ -0,0 +1,20 @@
<div id="confirm_delete_modal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-sm" role="document">
<form method="post" id="confirm_delete_form">
{% csrf_token %}
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Confirm Delete</h4>
</div>
<div class="modal-body">
<p>Are you sure you want to delete asset:</p>
<p><strong>{{ object }}</strong></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" onclick="deleteAsset({{ object.id }})" data-dismiss="modal"><i class="glyphicon glyphicon-trash"></i> Delete</button>
<button class="btn btn-success" data-dismiss="modal">Cancel</button>
</div>
</div>
</form>
</div>
</div>

View File

@@ -1,15 +1,16 @@
{% load widget_tweaks %} {% load widget_tweaks %}
<!---TODO: Assign form-control class in here--->
<div class="form-group"> <div class="form-group">
<label for="{{ field.id_for_label }}">{{ label|default:field.label }}</label> <label for="{{ field.id_for_label }}">{{ label|default:field.label }}</label>
{% if css %} {% if css %}
{% render_field field|add_class:'form-control' %} {% render_field field|add_class:css %}
{% elif disable_if_filled and field.value %} {% elif disable_if_filled and field.value %}
{% render_field field|attr:'disabled'|add_class:'form-control' %} {% render_field field|attr:'disabled' %}
{% elif css and disable_if_filled %} {% elif css and disable_if_filled %}
{% render_field field|add_class:'form-control'|attr:'disabled' %} {% render_field field|add_class:css|attr:'disabled' %}
{% else %} {% else %}
{{ field|add_class:'form-control' }} {{ field }}
{% endif %} {% endif %}
<span class="helper-text" data-error="{{ field.errors.text }}"></span> <span class="helper-text" data-error="{{ field.errors.text }}"></span>
</div> </div>