Initial bootstrap port of asset_update

This commit is contained in:
warlordjones
2019-10-02 12:08:52 +01:00
parent 8c60f6cb1d
commit f3c7f89f31
2 changed files with 306 additions and 310 deletions

View File

@@ -4,9 +4,10 @@
{% block content %} {% block content %}
<h2 class="text-center">Asset List</h2> <div class="page-header">
<h1 class="text-center">Asset List</h1>
</div>
<div class="col-lg-6">
<form method="post" id="asset-filter-form"> <form method="post" id="asset-filter-form">
{% csrf_token %} {% csrf_token %}
<div class="input-group"> <div class="input-group">
@@ -15,7 +16,6 @@
<span class="input-group-btn"><button type="submit" class="btn">Search</button></span> <span class="input-group-btn"><button type="submit" class="btn">Search</button></span>
</div> </div>
</form> </form>
</div>
<table class="table"> <table class="table">
<thead> <thead>

View File

@@ -6,7 +6,8 @@
{% block content %} {% block content %}
<h4> <div class="page-header">
<h1>
{% if edit and object %} {% if edit and object %}
Edit Asset | {{ object.asset_id }} Edit Asset | {{ object.asset_id }}
{% elif duplicate %} {% elif duplicate %}
@@ -17,8 +18,8 @@
Asset | {{ object.asset_id }} Asset | {{ object.asset_id }}
{% endif %} {% endif %}
</h4> </h1>
<div class="divider"></div> </div>
<br> <br>
@@ -26,88 +27,56 @@
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="id" value="{{ object.id|default:0 }}"> <input type="hidden" name="id" value="{{ object.id|default:0 }}">
<div class="row"> <div class="panel panel-default">
<div class="col s12">
<div class="button-group right">
{% if edit and object %}
<!--edit-->
<button type="button" class="btn" onclick="updateAsset()">Save</button>
<a class="waves-effect waves-light btn" href="{% url 'asset_update' object.pk %}?duplicate=true">Duplicate</a>
<a class="waves-effect waves-light btn modal-trigger" href="#confirm_delete_modal">Delete</a>
{% elif duplicate %}
<!--duplicate-->
<button type="button" class="btn" 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" onclick="updateAsset()">Save</button>
{% else %}
<!--detail-->
<a href="{% url 'asset_update' object.pk %}" class="btn">Edit</a>
<a class="waves-effect waves-light btn" href="{% url 'asset_update' object.pk %}?duplicate=true">Duplicate</a>
<a class="waves-effect waves-light btn modal-trigger" href="#confirm_delete_modal">Delete</a>
{% endif %}
</div>
</div>
</div>
<div class="row">
<div class="panel">
<div class="panel-heading"> <div class="panel-heading">
Asset Details Asset Details
</div> </div>
<div class="panel-body"> <div class="panel-body">
<dl class="dl-horizontal"> <div class="form-group">
{% if edit or duplicate %}
<div class="row">
<div class="input-field col s12">
{% if duplicate %}
{% render_field form.asset_id value=object.asset_id %}
{% elif object.asset_id %}
{% render_field form.asset_id|attr:'readonly'|add_class:'disabled_input' value=object.asset_id %}
{% else %}
{% render_field form.asset_id %}
{% endif %}
<label for="{{ form.asset_id.id_for_label }}" class="bold-text">Asset ID</label> <label for="{{ form.asset_id.id_for_label }}" class="bold-text">Asset ID</label>
{% if edit or duplicate %}
{% if duplicate %}
{% render_field form.asset_id|add_class:'form-control' value=object.asset_id %}
{% elif object.asset_id %}
{% render_field form.asset_id|attr:'readonly'|add_class:'disabled_input form-control' value=object.asset_id %}
{% else %}
{% render_field form.asset_id|add_class:'form-control' %}
{% endif %}
</div> </div>
<div class="input-field col s12"> <div class="form-group">
{% render_field form.description value=object.description %}
<label for="{{ form.description.id_for_label }}" <label for="{{ form.description.id_for_label }}"
class="bold-text">Description</label> class="bold-text">Description</label>
{% render_field form.description|add_class:'form-control' value=object.description %}
</div> </div>
<div class="form-group">
<div class="input-field col s12"> <label for="{{ form.category.id_for_label }}" class="bold-text">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> 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>
<label for="{{ form.category.id_for_label }}" class="bold-text">Category</label>
</div> </div>
<div class="form-group">
<div class="input-field col s12"> <label for="{{ form.status.id_for_label }}" class="bold-text">Status</label>
<select 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>
<label for="{{ form.status.id_for_label }}" class="bold-text">Status</label>
</div> </div>
<div class="form-group">
<div class="input-field col s12">
{% render_field form.serial_number value=object.serial_number %}
<label for="{{ form.serial_number.id_for_label }}">Serial Number</label> <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> </div>
<!---TODO: Lower default number of lines in comments box--->
<div class="input-field col s12"> <div class="form-group">
{% render_field form.comments|add_class:'materialize-textarea' %}
<label for="{{ form.comments.id_for_label }}">Comments</label> <label for="{{ form.comments.id_for_label }}">Comments</label>
{% render_field form.comments|add_class:'form-control' %}
</div> </div>
{% else %} {% else %}
<dt>Asset ID</dt> <dt>Asset ID</dt>
<dd>{{ object.asset_id }}</dd> <dd>{{ object.asset_id }}</dd>
@@ -127,56 +96,58 @@
<dt>Comments</dt> <dt>Comments</dt>
<dd>{{ object.comments|default:'-'|linebreaksbr }}</dd> <dd>{{ object.comments|default:'-'|linebreaksbr }}</dd>
{% endif %} {% endif %}
</dl>
</div>
</div> </div>
</div> </div>
<div class="row"> <div class="panel panel-default">
<div class="panel">
<div class="panel-heading"> <div class="panel-heading">
Purchase Details Purchase Details
</div> </div>
<div class="panel-body"> <div class="panel-body">
<dl class="dl-horizontal">
{% if edit or duplicate %} {% if edit or duplicate %}
<div class="row">
<div class="input-field col s12"> <div class="form-group">
<select name="{{ form.purchased_from.name }}" <label for="{{ form.purchased_from.id_for_label }}">Purchased From</label>
<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>
<label for="{{ form.purchased_from.id_for_label }}">Purchased From</label>
</div> </div>
<div class="input-field col s12"> <div class="form-group">
{% render_field form.purchase_price value=object.purchase_price %}
<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">
<span class="input-group-addon">£</span>
{% render_field form.purchase_price|add_class:'form-control' value=object.purchase_price %}
</div>
</div> </div>
<div class="input-field col s12"> <div class="form-group">
{% render_field form.salvage_value value=object.salvage_value %}
<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">
<span class="input-group-addon">£</span>
{% render_field form.salvage_value|add_class:'form-control' value=object.salvage_value %}
</div>
</div> </div>
<div class="input-field col s12"> <div class="form-group">
{% if object.date_acquired %}
{% render_field form.date_acquired|add_class:'datepicker' value=object.date_acquired|date %}
{% else %}
<input type="text" name="date_acquired" value="{% now "DATE_FORMAT" %}"
class="datepicker" id="id_date_acquired">
{% endif %}
<label for="{{ form.date_acquired.id_for_label }}" class="bold-text">Date <label for="{{ form.date_acquired.id_for_label }}" class="bold-text">Date
Acquired</label> Acquired</label>
{% if object.date_acquired %}
{% render_field form.date_acquired|add_class:'datepicker form-control' value=object.date_acquired|date %}
{% else %}
<input type="text" name="date_acquired" value="{% now "DATE_FORMAT" %}"
class="datepicker form-control" id="id_date_acquired">
{% endif %}
</div> </div>
<div class="input-field col s12"> <!---TODO: Presumably, this should only appear if the asset is in the sold category?--->
{% render_field form.date_sold|add_class:'datepicker' value=object.date_sold|date %} <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:'datepicker form-control' value=object.date_sold|date %}
</div> </div>
</div> </div>
{% else %} {% else %}
@@ -198,10 +169,9 @@
</dl> </dl>
</div> </div>
</div> </div>
</div>
{% if object.is_cable %} {% if object.is_cable %}
<div class="row"> <div class="form-group">
<div class="panel"> <div class="panel">
<div class="panel-heading"> <div class="panel-heading">
Cable Details Cable Details
@@ -222,37 +192,37 @@
</div> </div>
{% endif %} {% endif %}
<div class="row"> <div class="panel panel-default">
<div class="panel">
<div class="panel-heading"> <div class="panel-heading">
Collection Details Collection Details
</div> </div>
<div class="panel-body"> <div class="panel-body">
<dl class="dl-horizontal"> <dl class="dl-horizontal">
{% if edit or duplicate %} {% if edit or duplicate %}
<div class="row">
<div class="input-field col s10"> <div class="form-group">
<label for="parent_id">Parent</label>
<input type="hidden" name="{{ form.parent.html_name }}" id="hidden_parent_id" <input type="hidden" name="{{ form.parent.html_name }}" id="hidden_parent_id"
value="{{ object.parent.id }}"> value="{{ object.parent.id }}">
<div class="input-group">
<input type="text" id="parent_id" value="{{ object.parent|default:'' }}" <input type="text" id="parent_id" value="{{ object.parent|default:'' }}"
disabled=""> disabled="" class="form-control">
<label for="parent_id">Parent</label> <span class="input-group-btn"><button type="button" class="btn btn-default" onclick="clearParent()">Clear
</button></span>
</div> </div>
<div class="col s2">
<button type="button" class="btn btn-flat" onclick="clearParent()">
<i class="material-icons">clear</i>
</button>
</div> </div>
<div class="input-field col s10">
<input type="text" id="parent_search"> <div class="form-group">
<label for="parent_search">Search for asset</label> <label for="parent_search">Search for asset</label>
{# {% render_field form.parent value=object.parent %}#} <div class="input-group">
<input type="text" id="parent_search" class="form-control">
<span class="input-group-btn"><button type="button" class="btn btn-default" onclick="formAssetSearch()">
<i class="glyphicon glyphicon-search"></i> Search
</button></span>
</div>
</div> </div>
<div class="col s2"> <div class="col s2">
<button type="button" class="btn btn-flat" onclick="formAssetSearch()">
<i class="material-icons">search</i>
</button>
<br> <br>
</div> </div>
<div class="col s12" id="formAssetSearchResult"> <div class="col s12" id="formAssetSearchResult">
@@ -286,10 +256,29 @@
{% endif %} {% endif %}
</dl> </dl>
</div> </div>
</div>
</div>
</form> </form>
<div class="btn-group">
{% if edit and object %}
<!--edit-->
<button type="button" class="btn btn-success" onclick="updateAsset()">Save</button>
<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>
{% include 'confirm_delete.html' with object=object %} {% include 'confirm_delete.html' with object=object %}
{% endblock %} {% endblock %}
@@ -313,7 +302,9 @@
window.location.href = data['url']; window.location.href = data['url'];
}, },
error: function (xhr) { console.log(xhr.status + ": " + xhr.responseText) } error: function(xhr) {
console.log(xhr.status + ": " + xhr.responseText)
}
}); });
} }
</script> </script>
@@ -336,10 +327,15 @@
<script> <script>
$(document).ready(function() { $(document).ready(function() {
{% if edit or duplicate %} {
%
if edit or duplicate %
}
var comments_id = '#{{ form.comments.id_for_label }}'; var comments_id = '#{{ form.comments.id_for_label }}';
$(comments_id).val('{{ object.comments|linebreaksn }}'); $(comments_id).val('{{ object.comments|linebreaksn }}'); {
{% endif %} %
endif %
}
}) })
</script> </script>
{% endblock %} {% endblock %}