wireplanner/templates/model_form.html

59 lines
3.0 KiB
HTML

{{define "content"}}
<h1>{{if .IsEdit}}Edit{{else}}Create{{end}} Device Model</h1>
{{if .Error}}<div class="alert alert-error">{{.Error}}</div>{{end}}
<form method="POST" action="{{if .IsEdit}}/models/{{.Model.ID}}/update{{else}}/models/create{{end}}" enctype="multipart/form-data" id="model-form">
<fieldset>
<label>Name <input name="name" value="{{if .Model}}{{.Model.Name}}{{end}}" required></label>
<label>Manufacturer <input name="manufacturer" value="{{if .Model}}{{.Model.Manufacturer}}{{end}}"></label>
</fieldset>
<fieldset>
<label><input type="checkbox" name="is_rack_mountable" {{if not .Model}}checked{{else if .Model.IsRackMountable}}checked{{end}}> Rack-mountable</label>
<label>Height (U) <input type="number" name="height_units" value="{{if .Model}}{{if .Model.HeightUnits}}{{.Model.HeightUnits}}{{end}}{{end}}" min="1" style="width:5em"></label>
</fieldset>
<fieldset>
<label><input type="checkbox" name="is_patch_panel" {{if .Model}}{{if .Model.IsPatchPanel}}checked{{end}}{{end}}> Patch panel</label>
<label><input type="checkbox" name="is_wall_socket" {{if .Model}}{{if .Model.IsWallSocket}}checked{{end}}{{end}}> Wall socket</label>
</fieldset>
<fieldset>
<label>Front image <input type="file" name="front_image" accept="image/*">
{{if .Model}}{{if .Model.FrontImage}}<br><a href="/{{.Model.FrontImage}}" target="_blank">Current: {{.Model.FrontImage}}</a>{{end}}{{end}}
</label>
<label>Back image <input type="file" name="back_image" accept="image/*">
{{if .Model}}{{if .Model.BackImage}}<br><a href="/{{.Model.BackImage}}" target="_blank">Current: {{.Model.BackImage}}</a>{{end}}{{end}}
</label>
</fieldset>
<h3>Ports</h3>
<div id="ports-container">
{{if .Model}}
{{range $i, $p := .Model.Ports}}
<div class="port-entry">
<input name="port_name" value="{{.Name}}" placeholder="Port name (e.g. Gig1/0/1)">
<select name="port_side"><option value="front" {{if eq .Side "front"}}selected{{end}}>Front</option><option value="back" {{if eq .Side "back"}}selected{{end}}>Back</option></select>
<button type="button" onclick="this.parentElement.remove()">Remove</button>
</div>
{{end}}
{{end}}
</div>
<button type="button" onclick="addPortRow()">Add Port</button>
<div style="margin-top:1em">
<button type="submit" class="btn">{{if .IsEdit}}Update{{else}}Create{{end}} Model</button>
<a href="/models" class="btn">Cancel</a>
</div>
</form>
<script>
function addPortRow() {
var div = document.createElement('div');
div.className = 'port-entry';
div.innerHTML = '<input name="port_name" placeholder="Port name"> <select name="port_side"><option value="front">Front</option><option value="back">Back</option></select> <button type="button" onclick="this.parentElement.remove()">Remove</button>';
document.getElementById('ports-container').appendChild(div);
}
</script>
{{end}}