Skip to content

Commit

Permalink
Fix for no USB devices
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxudo committed Aug 16, 2022
1 parent 88f61fb commit c56598a
Showing 1 changed file with 54 additions and 42 deletions.
96 changes: 54 additions & 42 deletions views/usb_tab.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,63 @@
<div id="usb-tab"></div>
<h2 data-i18n="usb.clienttab"></h2>
<div id="usb-msg" data-i18n="listing.loading" class="col-lg-12 text-center"></div>

<script>
$(document).on('appReady', function(){
$.getJSON(appUrl + '/module/usb/get_data/' + serialNumber, function(data){
// Set count of USB devices
$('#usb-cnt').text(data.length);
var skipThese = ['id','name','printer_id'];
$.each(data, function(i,d){
$.getJSON(appUrl + '/module/usb/get_data/' + serialNumber, function(data){
// Generate rows from data
var rows = ''
for (var prop in d){
// Skip skipThese
if(skipThese.indexOf(prop) == -1){
if(prop == 'internal' && d[prop] == 1){
rows = rows + '<tr><th>'+i18n.t('usb.'+prop)+'</th><td>'+i18n.t('yes')+'</td></tr>';
}
else if(prop == 'internal' && d[prop] == 0){
rows = rows + '<tr><th>'+i18n.t('usb.'+prop)+'</th><td>'+i18n.t('no')+'</td></tr>';
}
else if(prop == 'media' && d[prop] == 1){
rows = rows + '<tr><th>'+i18n.t('usb.'+prop)+'</th><td>'+i18n.t('yes')+'</td></tr>';
}
else if(prop == 'media' && d[prop] == 0){
rows = rows + '<tr><th>'+i18n.t('usb.'+prop)+'</th><td>'+i18n.t('no')+'</td></tr>';
// Check if we have data
if( data == "" || ! data || data.length == 0 || data.length == "0"){
$('#usb-msg').text(i18n.t('usb.nousb'));
} else {
// Hide
$('#usb-msg').text('');
$('#usb-count-view').removeClass('hide');
// Set count of USB devices
$('#usb-cnt').text(data.length);
var skipThese = ['id','name','printer_id'];
$.each(data, function(i,d){
// Generate rows from data
var rows = ''
for (var prop in d){
// Skip skipThese
if(skipThese.indexOf(prop) == -1){
if(prop == 'internal' && d[prop] == 1){
rows = rows + '<tr><th>'+i18n.t('usb.'+prop)+'</th><td>'+i18n.t('yes')+'</td></tr>';
}
else if(prop == 'internal' && d[prop] == 0){
rows = rows + '<tr><th>'+i18n.t('usb.'+prop)+'</th><td>'+i18n.t('no')+'</td></tr>';
}
else if(prop == 'media' && d[prop] == 1){
rows = rows + '<tr><th>'+i18n.t('usb.'+prop)+'</th><td>'+i18n.t('yes')+'</td></tr>';
}
else if(prop == 'media' && d[prop] == 0){
rows = rows + '<tr><th>'+i18n.t('usb.'+prop)+'</th><td>'+i18n.t('no')+'</td></tr>';
}
else if(prop == 'usb_serial_number' && d[prop] == ''){
// Do nothing for a blank device serial number
}
else {
rows = rows + '<tr><th>'+i18n.t('usb.'+prop)+'</th><td>'+d[prop]+'</td></tr>';
}
}
else if(prop == 'usb_serial_number' && d[prop] == ''){
// Do nothing for a blank device serial number
}
else {
rows = rows + '<tr><th>'+i18n.t('usb.'+prop)+'</th><td>'+d[prop]+'</td></tr>';
}
}
}
$('#usb-tab')
.append($('<h4>')
.append($('<i>')
.addClass('fa fa-usb'))
.append(' '+d.name))
.append($('<div style="max-width:370px;">')
.addClass('table-responsive')
.append($('<table>')
.addClass('table table-striped table-condensed')
.append($('<tbody>')
.append(rows))))
})
});
}
$('#usb-tab')
.append($('<h4>')
.append($('<i>')
.addClass('fa fa-usb'))
.append(' '+d.name))
.append($('<div style="max-width:370px;">')
.addClass('table-responsive')
.append($('<table>')
.addClass('table table-striped table-condensed')
.append($('<tbody>')
.append(rows))))
})
}
});
});
</script>

0 comments on commit c56598a

Please sign in to comment.