let tableDev; HTMLImports.whenReady(function () { if ( $.fn.dataTable.isDataTable( '#deviceTable' ) ) { tableDev = $('#deviceTable').DataTable(); } else { tableDev = $('#deviceTable').DataTable( { order: [[ 6, "asc" ]], paging: true, retrieve: true, searching: true, ajax: { url: '/api/devices/', dataSrc: '' }, columns: [ { data: 'deviceName'}, { data: 'deviceType' }, { data: 'deviceClass' }, { data: 'description' }, { data: 'ipAddress' }, { data: 'port' }, { data: null, render: function (data, type) { let status; if (data.status != null) { let st1 = ``; let st2 = `${data.status.statusRus}`; if (data.status.statusEng === 'ERROR' || data.status.statusEng === 'WARNING') { let st2err = `${data.status.statusRus}`; status = st1 + st2err + ``; return status; } status = st1 + st2; return status; } return "ОТКЛЮЧЕНО"; } }, { "defaultContent": " "} ], autoWidth: false, columnDefs: [ { width: '10%', targets: 0 }, { width: '15%', targets: 1 }, { width: '10%', targets: 2 }, { width: '25%', targets: 3 }, { width: '10%', targets: 4 }, { width: '5%', targets: 5 }, { width: '15%', targets: 6 }, { width: '10%', targets: 7 } ], "createdRow": createdRowTable1, "lengthMenu": [ [-1, 10, 25, 50], ["Все", 10, 25, 50] ], "language": { "search": "Поиск:", "lengthMenu": "Показывать _MENU_ строк", "info": "Строки с _START_ по _END_ из _TOTAL_", "paginate": { "next": "Следущая", "previous": "Предыдущая" } } } ); } }); function createdRowTable1( row, data, dataIndex, cells ) { if (data.enabled === false) { $('td:eq(0)', row).css('color', 'grey'); $('td:eq(1)', row).css('color', 'grey'); $('td:eq(2)', row).css('color', 'grey'); $('td:eq(3)', row).css('color', 'grey'); $('td:eq(4)', row).css('color', 'grey'); $('td:eq(5)', row).css('color', 'grey'); $('td:eq(6)', row).css('color', 'grey'); $('td:eq(7)', row).html( ` `); } else { $('td:eq(7)', row).html( ` `); } } function deleteDevice(id) { let bool = confirm("Удалить устройство?"); if (bool) { $.ajax({ type: "DELETE", url: '/api/devices/' + id + '/', contentType: "application/json; charset=utf-8", dataType: "json", success: function () { console.log("success deleteDevice"); }, error: function(errMsg) { console.log(errMsg); }, complete: function (data) { tableDev.ajax.reload(); tableHandlers.ajax.reload(); } }); } } function enableDevice(id, name) { $.ajax({ type: "PATCH", url: '/api/devices/' + id + '/', contentType: "application/json; charset=utf-8", success: function () { startSelfTestOneDevice(name); }, error: function(errMsg) { console.log(errMsg); alert("Контроллер устройства выключен. Устройство не может быть активировано.") }, complete: function (data) { tableDev.ajax.reload(); } }); } function clearDeviceListNewContainer() { $("#device-list-new-page > .cconf").empty(); } function requestDeviceListNew() { clearDeviceListNewContainer(); resetPagingPageNumber("#device-list-new-page"); nextView("#device-list-new-page"); } function showError(id) { let elem = $('#' + id + '_0'); let isHidden = elem[0].hidden; if (isHidden) { elem.show("slow"); elem[0].hidden = false; } else { elem.hide("slow"); elem[0].hidden = true; } }