Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lirc plugin: improve web interface #812

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 45 additions & 16 deletions lirc/webif/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,39 @@
.shng_button_highlight{
background-color: green;
}
.checkmark {
background-color: green;
color: white;
}
.issue {
background-color: red;
color: white;
}
</style>
{% endblock pluginstyles %}
{% block pluginscripts %}
<script>
function updateButton(buttonElement, success) {
if (success == "checkmark")
buttonElement
.prop("disabled", true)
.html('<i class="fas fa-check"></i>')
.addClass(success);
else
buttonElement
.prop("disabled", true)
.html('<i class="fas fa-times"></i>')
.addClass(success);

// After 2 seconds, revert the button to its original state
setTimeout(function() {
console.log("reset button")
buttonElement
.prop("disabled", false)
.html('<i class="fas fa-play"></i>')
.removeClass(success);
}, 2000); // 2 seconds (2000 milliseconds)
}
$(document).ready( function () {
$("#button_pressed").submit(function(e) {
console.log('Sending lirc command for ' + $("#button").val());
Expand All @@ -32,23 +61,24 @@

// die Kennung des gedrückten Buttons per AJAX senden
$.post('submit', {item: $("#button").val()}, function(data) {
console.log("Return value from plugin: " + data);
const escapedVal = $.escapeSelector($("#button").val());
const buttonElement = $("#" + escapedVal + "_button");
if (data)
updateButton(buttonElement, "checkmark");
else
updateButton(buttonElement, "issue");


}).fail(function(jqXHR, textStatus, errorThrown) {
// Error callback
console.error("AJAX request failed:", textStatus, errorThrown);
const escapedVal = $.escapeSelector($("#button").val());
const buttonElement = $("#" + escapedVal + "_button");
updateButton(buttonElement, "issue");
});
return false ;
});
$(window).trigger('datatables_defaults');
/* get pagelength from http module or plugin. */
{% if webif_pagelength is defined %}webif_pagelength = {{ webif_pagelength|int }};{% endif %}
if (isNaN(parseFloat(webif_pagelength)) || webif_pagelength == 0) {
resize = true;
webif_pagelength = -1;
}
else {
resize = false;
}
console.log("Webif page length " + webif_pagelength + ", pageResize: " + resize);

try {
table = $('#maintable').DataTable( {
columnDefs: [
Expand Down Expand Up @@ -83,9 +113,8 @@
title: '{{ _('Letzte Änderung') }}',
targets: 6, "className": "last_change"
}
].concat($.fn.dataTable.defaults.columnDefs),
pageLength: webif_pagelength,
pageResize: resize});
].concat($.fn.dataTable.defaults.columnDefs)
});
}
catch (e) {
console.log("Datatable JS not loaded, showing standard table without reorder option " +e);
Expand Down Expand Up @@ -150,7 +179,7 @@
<td></td>
<td class="py-1">{{ item.property.path }}</td>
<td>
<button id="{{ item }}_button" type="button" class="btn btn-shng btn-sm" title="{{ _('Senden') }}" onclick=" $('#button').val('{{ item }}');$('#button_pressed').submit();"><i class="fas fa-play"></i></button></td>
<button id="{{ item }}_button" type="button" class="btn btn-shng btn-sm" title="{{ _('Senden') }} {{ item }}" onclick=" $('#button').val('{{ item }}');$('#button_pressed').submit();"><i class="fas fa-play"></i></button></td>
<td class="py-1">{{ p.get_iattr_value(item.conf, 'lirc_remote') }}</td>
<td class="py-1">{{ p.get_iattr_value(item.conf, 'lirc_key') }}</td>
<td class="py-1" id="{{ item._path }}_last_update" style="text-align: center">{{ item.property.last_update.strftime('%d.%m.%Y %H:%M:%S') }}</td>
Expand Down