var discret_table = $('#discret_table'); var filter_table = $('#filter_table'); var aply_filter = $('#aply_filter'); var change_filter = $('#change_filter'); var data_discret = null; var data_discret_params = null; var params_state_struct = null; //Первая загрузка страницы $(document).ready( async function () { show_load(); var flag_pasport_load = await get_url_params(); pasport_fill_label(); pasport_show_lable(); if (!flag_pasport_load) { hide_load(); return; } if (!pasport_fill_date()) { hide_load(); return; } show_menu(); pasport_show_date(); var ds = load_data_discret(); var dsp = load_data_discret_params(); var dsss = load_params_state_struct(); await Promise.all([ds, dsp, dsss]); if (dsp) fill_filter_discret(); if (ds) fill_table_discret(); hide_load(); } ); aply_filter.click(function () { read_filter(); fill_table_discret(); }); var change_filter_flag = true; change_filter.click(function () { change_filter.empty(); if (change_filter_flag) change_filter.append("Установить все"); else change_filter.append("Снять все"); for (var i = 0; i < data_discret_params.length; i++) { var check_label = filter_table.find('#discret_filter_id_' + data_discret_params[i].index); if (change_filter_flag) check_label.removeAttr('checked'); else check_label.attr('checked', true); } change_filter_flag = !change_filter_flag; }); async function load_data_discret() { try { var res = await $.ajax({ type: "POST", url: 'https://vsmpo.mbucb.ru/api/date/getdiscret', contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify({ "vdp": pasport_data.numVDP, "start": pasport_data.dStart, "end": pasport_data.dEnd }) }); data_discret = res.discret; return true; } catch (err) { data_discret = null; alert("Ошибка загрузки дискретов."); return false; } } async function load_data_discret_params() { try { var name_vdp = "0" + pasport_data.numVDP; name_vdp = name_vdp.substr(name_vdp.length - 2); var res = await $.ajax({ type: "POST", url: 'https://vsmpo.mbucb.ru/api/params/getdiscret', contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify({ "name": name_vdp }) }); data_discret_params = res.discret_params; var i = 0; while (i < data_discret_params.length) { if (data_discret_params[i].skip) { data_discret_params.splice(i, 1); continue; } data_discret_params[i].show = true; i++; } return true; } catch (err) { data_discret_params = null; alert("Ошибка загрузки структуры дискретов"); return false; } } async function load_params_state_struct() { try { var res = await $.ajax({ type: "POST", url: 'https://vsmpo.mbucb.ru/api/params/getstatestruct', contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify({}) }); params_state_struct = res.stateStruct; return true; } catch (err) { params_state_struct = null; alert("Ошибка загрузки состояний"); return false; } } function fill_table_discret() { try { discret_table.find('tbody').empty(); if (data_discret == undefined || data_discret == null || data_discret_params == undefined || data_discret_params == null) return; for (var i = 0; i < data_discret.length; i++) { var state = data_discret_params.find(item => item.index == data_discret[i].index); if (state == undefined || state == null || !state.show) continue; var state_idx = params_state_struct.find(item => item.name == state.stateStruct); if (state_idx == undefined || state_idx == null) { state_idx = {}; state_idx.color = "#ffffff"; state_idx.name = "Состояние №" + data_discret[i].state; } else { state_idx = state_idx.states.find(item => item.index == data_discret[i].state); if (state_idx == undefined || state_idx == null) { state_idx = {}; state_idx.color = "#ffffff"; state_idx.name = "Состояние №" + data_discret[i].state; } } discret_table.find('tbody').append( '