Initial work on cable template things

This commit is contained in:
2019-10-05 22:42:21 +01:00
parent 3d5272d722
commit a22956cc62
3 changed files with 169 additions and 103 deletions

View File

@@ -37,7 +37,7 @@
Asset Details Asset Details
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="form-group" <div class="form-group">
<label for="{{ form.asset_id.id_for_label }}">Asset ID</label> <label for="{{ form.asset_id.id_for_label }}">Asset ID</label>
{% render_field form.asset_id|add_class:'form-control' value=object.asset_id %} {% render_field form.asset_id|add_class:'form-control' value=object.asset_id %}
</div> </div>
@@ -47,7 +47,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="{{ form.category.id_for_label }}" >Category</label> <label for="{{ form.category.id_for_label }}" >Category</label>
<select name="{{ form.category.name }}" id="{{ form.category.id_for_label }}" required class="form-control"> <select name="{{ form.category.name }}" id="{{ form.category.id_for_label }}" required class="form-control" onchange="changeCategory()">
{% 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 %} {% if object.category.id == id %}
@@ -58,6 +58,7 @@
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
{% render_field form.is_cable|attr:'onchange=toggleBox()' value=object.is_cable %} <label for="{{ form.is_cable.id_for_label }}">Cable?</label>
<div class="form-group"> <div class="form-group">
<label for="{{ form.status.id_for_label }}" >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>
@@ -137,28 +138,92 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-6"> {#% if object.is_cable and object.category == "Power" %#}
<div class="col-md-6" hidden="true" id="cable-table">
<div class="panel panel-default">
<div class="panel-heading">
Cable Details
</div>
<div class="panel-body">
<div class="form-group">
<label for="{{ cableform.plug.id_for_label }}">Plug</label>
<select name="{{ cableform.plug.name }}" id="{{ cableform.plug.id_for_label }}" class="form-control">
<option value="None">
{% for connector in connectors %}
<option value="{{ connector.pk }}">
{{ connector.description }}
</option>
{%endfor%}
</select>
</div>
<div class="form-group">
<label for="{{ cableform.socket.id_for_label }}">Socket</label>
<select name="{{ cableform.socket.name }}" id="{{ cableform.socket.id_for_label }}" class="form-control">
<option value="None">
{% for connector in connectors %}
<option value="{{ connector.pk }}">
{{ connector.description }}
</option>
{%endfor%}
</select>
</div>
<div class="form-group">
<label for="{{ cableform.length.id_for_label }}">Length</label>
{% render_field cableform.length|add_class:'form-control' %}
<span class="input-group-addon">{{ cableform.length.help_text }}</span>
</div>
<div class="form-group">
<label for="{{ cableform.csa.id_for_label }}">Cross Sectional Area</label>
{% render_field cableform.csa|add_class:'form-control' value=object.csa %}
<span class="input-group-addon">{{ cableform.csa.help_text }}</span>
</div>
<div class="form-group">
<label for="{{ cableform.circuits.id_for_label }}">Circuits</label>
{% render_field cableform.circuits|add_class:'form-control' value=object.circuits %}
</div>
<div class="form-group">
<label for="{{ cableform.cores.id_for_label }}">Cores</label>
{% render_field cableform.cores|add_class:'form-control' value=object.cores %}
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
Collection Details Collection Details
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="form-group"> <div class="form-group">
<label for="selectpicker">Set Parent:</label> <label for="selectpicker">Set Parent</label>
{% include 'partials/asset_picker.html' %} {% include 'partials/asset_picker.html' %}
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
{% include 'partials/asset_buttons.html' %} {% include 'partials/asset_buttons.html' %}
</div> </div>
</div> </div>
</div> </form>
</div>
</form>
{% include 'partials/confirm_delete.html' with object=object %} {% include 'partials/confirm_delete.html' with object=object %}
{% endblock %} {% endblock %}
{% block js%}
<script>
function toggleBox() {
if(document.getElementById("id_category").value == "26") { //TODO: CHANGE THIS IN PRODUCTION
document.getElementById("cable-table").hidden = !document.getElementById("cable-table").hidden ;
}
}
function changeCategory() {
if(document.getElementById("id_is_cable").checked) {
this.toggleBox();
}
}
</script>
{%endblock%}

View File

@@ -192,7 +192,7 @@
<div class="panel-body"> <div class="panel-body">
{% if edit or duplicate %} {% if edit or duplicate %}
<div class="form-group"> <div class="form-group">
<label for="selectpicker">Set Parent:</label> <label for="selectpicker">Set Parent</label>
{% include 'partials/asset_picker.html' %} {% include 'partials/asset_picker.html' %}
</div> </div>
{% else%} {% else%}

View File

@@ -100,6 +100,7 @@ class AssetCreate(LoginRequiredMixin, CableFormMixin, generic.CreateView):
context = super(AssetCreate, self).get_context_data(**kwargs) context = super(AssetCreate, self).get_context_data(**kwargs)
context["create"] = True context["create"] = True
context["connectors"] = models.Connector.objects.all()
return context return context
def get_success_url(self): def get_success_url(self):