{% extends "layouts/base.html" %} {% block title %}Update Address{% endblock %} <!-- Specific Page CSS goes HERE --> {% block stylesheets %} <style> .main-panel > .content { padding: 0; } .container { min-width: 100%; margin: 0; padding: 0; } .row { margin: 0; } .offset-md-3 { margin-left: 0; } .card { min-height: calc(100vh - 270px); left: 300px; min-width: calc(100vw - 400px); margin-block: 0; } .card * { font-size: large; } .card .title { font-size: 2rem; } .card label { font-size: 1rem; } .form-control { height: calc(3rem + 2px); } select option { color: black; } select option:checked { color: rgb(0, 228, 0); } @media screen and (max-width: 992px) { .card { left: 200px; } } @media screen and (max-width: 768px) { .card { left: 0; } } @media screen and (max-width: 576px) { .card * { font-size: medium; } .card .title { font-size: 1.6rem; } .card label { font-size: 0.8rem; } .form-control { height: calc(2.7rem + 2px); } } </style> {% endblock %} {% block content %} <div class="content"> <div class="container"> <div class="row pt-5"> <div class="col-md-6 mt-5 offset-md-3 pt-5 mt-5"> <div class="card"> <div class="card-header text-center py-4"> <h4 class="title">Update Address</h4> </div> <form role="form" method="post" action="{% url 'update-room' %}"> {% csrf_token %} <input type="hidden" name="room_id" value="{{ room.room_id }}"> <div class="card-body px-5 py-3"> <div class="form-row"> <div class="form-group col-md-6"> <label for="id_access">Address Type</label> <select class="form-control" id="id_access" name="quarter_type"> {% for value in quarterType %} <option value="{{ value }}" {% if value|lower == room.quarter_type_id.quarter_name|lower %}selected{% endif %}>{{ value }}</option> {% endfor %} </select> <span class="text-danger"></span> </div> <div class="form-group col-md-6"> <label for="id_room_id">Address Number</label> <input type="number" class="form-control" id="id_room_id" name="room_number" value="{{ room.room_number }}" /> <span class="text-danger"></span> </div> </div> <div class="form-row"> <div class="form-group col-md-6"> <label for="id_user_type">Metering Type</label> <select class="form-control" id="id_user_type" name="room_type" onchange="toggleFields()"> <option value="metered" {% if room.is_metered %}selected{% endif %}>Metered</option> <option value="un-metered" {% if not room.is_metered %}selected{% endif %}>Un-metered</option> </select> <span class="text-danger"></span> </div> <div class="form-group col-md-6"> <label for="id_sanctioned_load">Sanctioned Load</label> <input type="text" inputmode="decimal" pattern="[0-9]*[.,]?[0-9]*" class="form-control" id="id_sanctioned_load" name="sanctioned_load" value="{{ room.sanctioned_load }}" /> <span class="text-danger"></span> </div> </div> <div class="form-row"> <div class="form-group col-md-6" id="initialReadingRow"> <label for="id_room_id">Initial Reading</label> <input type="text" inputmode="decimal" pattern="[0-9]*[.,]?[0-9]*" class="form-control" id="id_initial_reading" name="initial_reading" value="{{ room.initial_reading }}" /> <span class="text-danger"></span> </div> <div class="form-group col-md-6" id="multiplicationFactorRow"> <label for="id_mult_factor">Multiplication Factor</label> <input type="text" inputmode="decimal" pattern="[0-9]*[.,]?[0-9]*" class="form-control" id="id_mult_factor" name="mult_factor" value="{{ room.mult_factor }}" /> <span class="text-danger"></span> </div> </div> <div class="form-row" id="meterRateRow"> <div class="form-group col-md-6"> <label for="id_meter_rate">Meter Rate</label> <select class="form-control" id="id_meter_rate" name="meter_rate"> {% for value in meterRate %} <option value="{{ value }}" {% if value.name == room.meter_rate_name %}selected{% endif %}>{{ value }}</option> {% endfor %} </select> <span class="text-danger"></span> </div> </div> {% comment %} {% else %} {% endcomment %} <div class="form-row" id="flatRateRow" style="display: none"> <div class="form-group col-md-6"> <label for="id_flat_rate">Flat Rate</label> <select class="form-control" id="id_flat_rate" name="flat_rate"> {% for value in flatRate %} <option value="{{ value }}" {% if value.name == room.flat_rate_name %}selected{% endif %}>{{ value }}</option> {% endfor %} </select> <span class="text-danger"></span> </div> </div> {% comment %} {% endif %} {% endcomment %} </div> <div class="card-footer text-center"> <button type="submit" class="btn btn-fill btn-primary"> Update Address </button> </div> </form> </div> </div> </div> </div> </div> {% endblock content %} <!-- Specific Page JS goes HERE --> {% block javascripts %} <script> function toggleFields() { const userSelect = document.getElementById("id_user_type"); const multFactor = document.getElementById("multiplicationFactorRow"); const initialReadingRow = document.getElementById("initialReadingRow"); const meterRateRow = document.getElementById("meterRateRow"); const flatRateRow = document.getElementById("flatRateRow"); if (userSelect.value === "metered") { initialReadingRow.style.display = "block"; multFactor.style.display = "block"; meterRateRow.style.display = "block"; flatRateRow.style.display = "none"; } else if (userSelect.value === "un-metered") { initialReadingRow.style.display = "none"; multFactor.style.display = "none"; meterRateRow.style.display = "none"; flatRateRow.style.display = "block"; } } document.addEventListener('DOMContentLoaded', function() { toggleFields(); }); </script> {% endblock javascripts %}