193 lines
5.6 KiB
JavaScript
193 lines
5.6 KiB
JavaScript
|
var protect_table = $('#protect_table');
|
|||
|
var filter_table = $('#filter_table');
|
|||
|
|
|||
|
var aply_filter = $('#aply_filter');
|
|||
|
var change_filter = $('#change_filter');
|
|||
|
|
|||
|
var data_protect = null;
|
|||
|
var data_protect_state = null;
|
|||
|
var params_state_struct = null;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//Первая загрузка страницы
|
|||
|
$(document).ready(
|
|||
|
async function () {
|
|||
|
var flag_pasport_load = await get_url_params();
|
|||
|
pasport_fill_label();
|
|||
|
pasport_show_lable();
|
|||
|
if (!flag_pasport_load)
|
|||
|
return;
|
|||
|
if (!pasport_fill_date())
|
|||
|
return;
|
|||
|
show_menu();
|
|||
|
pasport_show_date();
|
|||
|
|
|||
|
var pt = load_data_protect();
|
|||
|
var pts = load_data_protect_state();
|
|||
|
var ptss = load_params_state_struct();
|
|||
|
await Promise.all([pt, pts, ptss]);
|
|||
|
if (pts)
|
|||
|
fill_filter_protect();
|
|||
|
if (pt)
|
|||
|
fill_table_protect();
|
|||
|
}
|
|||
|
);
|
|||
|
|
|||
|
aply_filter.click(function () {
|
|||
|
read_filter();
|
|||
|
fill_table_protect();
|
|||
|
});
|
|||
|
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_protect_state.length; i++) {
|
|||
|
var check_label = filter_table.find('#protect_filter_id_' + data_protect_state[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_protect() {
|
|||
|
try {
|
|||
|
var res = await $.ajax({
|
|||
|
type: "POST",
|
|||
|
url: 'https://vsmpo.mbucb.ru/api/date/getprotect',
|
|||
|
contentType: "application/json; charset=utf-8",
|
|||
|
dataType: "json",
|
|||
|
data: JSON.stringify({
|
|||
|
"vdp": pasport_data.numVDP,
|
|||
|
"start": pasport_data.dStart,
|
|||
|
"end": pasport_data.dEnd
|
|||
|
})
|
|||
|
});
|
|||
|
data_protect = res.protect;
|
|||
|
return true;
|
|||
|
}
|
|||
|
catch (err) {
|
|||
|
data_protect = null;
|
|||
|
alert("Ошибка загрузки защит");
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
async function load_data_protect_state() {
|
|||
|
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/getprotectstate',
|
|||
|
contentType: "application/json; charset=utf-8",
|
|||
|
dataType: "json",
|
|||
|
data: JSON.stringify({"name": name_vdp})
|
|||
|
});
|
|||
|
data_protect_state = res.protectState;
|
|||
|
for (var i = 0; i < data_protect_state.length; i++)
|
|||
|
data_protect_state[i].show = true;
|
|||
|
return true;
|
|||
|
}
|
|||
|
catch (err) {
|
|||
|
data_protect = 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_protect() {
|
|||
|
try {
|
|||
|
protect_table.find('tbody').empty();
|
|||
|
if (data_protect == undefined ||
|
|||
|
data_protect == null ||
|
|||
|
data_protect_state == undefined ||
|
|||
|
data_protect_state == null)
|
|||
|
return;
|
|||
|
|
|||
|
for (var i = 0; i < data_protect.length; i++) {
|
|||
|
var state = data_protect_state.find(item => item.index == data_protect[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_protect[i].state;
|
|||
|
} else {
|
|||
|
state_idx = state_idx.states.find(item => item.index == data_protect[i].state);
|
|||
|
if (state_idx == undefined || state_idx == null) {
|
|||
|
state_idx = {};
|
|||
|
state_idx.color = "#ffffff";
|
|||
|
state_idx.name = "Операция №" + data_protect[i].state;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
protect_table.find('tbody').append(
|
|||
|
'<tr style="background-color : ' + state_idx.color + '20;">' +
|
|||
|
'<td>' + (i + 1) +
|
|||
|
'</td>' +
|
|||
|
'<td>' + data_protect[i].index +
|
|||
|
'</td>' +
|
|||
|
'<td>' + data_protect[i].start +
|
|||
|
'</td>' +
|
|||
|
'<td>' + state.name +
|
|||
|
'</td>' +
|
|||
|
'<td>' + state_idx.name +
|
|||
|
'</td>' +
|
|||
|
'</tr>');
|
|||
|
}
|
|||
|
}
|
|||
|
catch {
|
|||
|
alert("Ошибка заполнения таблицы.");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function fill_filter_protect() {
|
|||
|
filter_table.empty();
|
|||
|
if (data_protect_state == undefined ||
|
|||
|
data_protect_state == null)
|
|||
|
return;
|
|||
|
for (var i = 0; i < data_protect_state.length; i++) {
|
|||
|
filter_table.append(
|
|||
|
'<div class= "form-check">' +
|
|||
|
'<input class="form-check-input" type="checkbox" value="' + data_protect_state[i].index +
|
|||
|
'" id="protect_filter_id_' + data_protect_state[i].index + '" ' +
|
|||
|
(data_protect_state[i].show ? 'checked' : '') + '>' +
|
|||
|
'<label class="form-check-label" for="protect_filter_id_' + data_protect_state[i].index + '">' +
|
|||
|
data_protect_state[i].index + ' ' + data_protect_state[i].name +
|
|||
|
'</label></div>'
|
|||
|
);
|
|||
|
}
|
|||
|
}
|
|||
|
function read_filter() {
|
|||
|
for (var i = 0; i < data_protect_state.length; i++) {
|
|||
|
if (filter_table.find('#protect_filter_id_' + data_protect_state[i].index).is(':checked'))
|
|||
|
data_protect_state[i].show = true;
|
|||
|
else
|
|||
|
data_protect_state[i].show = false;
|
|||
|
}
|
|||
|
}
|