diff options
author | coderick14 | 2017-06-09 18:27:06 +0530 |
---|---|---|
committer | coderick14 | 2017-06-09 18:27:06 +0530 |
commit | e4842a334cc388043ab2ca83354170b35d114c74 (patch) | |
tree | ca18dd5d53d791c578c8458f90ebdcdcb1b25edf /templates/admin | |
parent | 864142aec4c6f91945e6d521db8a157aff426fa9 (diff) | |
download | SBHS-2018-Rpi-e4842a334cc388043ab2ca83354170b35d114c74.tar.gz SBHS-2018-Rpi-e4842a334cc388043ab2ca83354170b35d114c74.tar.bz2 SBHS-2018-Rpi-e4842a334cc388043ab2ca83354170b35d114c74.zip |
Add Ajax call to toggle board state
Diffstat (limited to 'templates/admin')
-rw-r--r-- | templates/admin/index.html | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/templates/admin/index.html b/templates/admin/index.html index 3e9ce15..3bd5e45 100644 --- a/templates/admin/index.html +++ b/templates/admin/index.html @@ -23,7 +23,7 @@ {% for b in boards %} <tr> <td>{{ b.mid }}</td> - <td><span class="label label-{% if b.online %}success{% else %}important{% endif %}">{% if b.online %}Online{% else %}Offline{% endif %}</span></td> + <td><span style="cursor: pointer;" class="label label-{% if b.temp_offline %}warning{% elif b.online %}success{% else %}important{% endif %}">{% if b.temp_offline %}Temp Offline{% elif b.online %}Online{% else %}Offline{% endif %}</span></td> <td><a href="{% url 'webcam_show_video_to_admin' b.mid %}" target="_blank">View image</a></td> <td><a href="{% url 'admin_profile' b.mid %}">View</a></td> <td><a href="{% url 'admin_logs' b.mid %}">Download</a></td> @@ -34,4 +34,43 @@ </div> </div> </div> + +<script type="text/javascript"> + $(".label-success").click(toggleState); + $(".label-warning").click(toggleState); + + function toggleState() { + var BASE_URL = window.location.origin; + if (window.confirm("Are you sure you want to toggle the state?")) { + var board_class = $(this).attr("class"); + var selected_mid = $(this).parent().prev().html(); + + var request = $.ajax({ + url : BASE_URL + '/admin/toggledevice', + method : 'POST', + data : { + 'mid' : selected_mid + } + }); + + request.done(function(data){ + if (data.status_code == 200) { + if (board_class.indexOf("label-success") > -1) { + $(this).removeClass("label-success"); + $(this).addClass("label-warning"); + $(this).html("Temp Offline"); + } + else { + $(this).removeClass("label-warning"); + $(this).addClass("label-success"); + $(this).html("Online"); + } + } + else { + alert("Sorry! The state could not be toggled."); + } + }); + } + } +</script> {% endblock %}
\ No newline at end of file |