test/app/static/js/ogrModule.js

275 lines
9.0 KiB
JavaScript
Raw Permalink Blame History

function newGuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
function (c) {
var r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
}).toUpperCase();
}
function addRow(nametable, ed) {
id = 'tbody_' + nametable
sectionin = Number($('#count_' + nametable).val()) + 1
newid = newGuid()
$('#' + id).append(
$('<tr>', {
'id': 'idtre_' + id + '_' + sectionin,
}))
$('#idtre_' + id + '_' + sectionin).append(
$('<td>', {
'id': 'idtde1_' + id + '_' + sectionin,
}))
$('#idtre_' + id + '_' + sectionin).append(
$('<td>', {
'id': 'idtde2_' + id + '_' + sectionin,
'style': 'text-align: center',
}))
$('#idtre_' + id + '_' + sectionin).append(
$('<td>', {
'id': 'idtde3_' + id + '_' + sectionin,
}))
$('#idtre_' + id + '_' + sectionin).append(
$('<td>', {
'id': 'idtde4_' + id + '_' + sectionin,
}))
$('#idtre_' + id + '_' + sectionin).append(
$('<td>', {
'id': 'idtde5_' + id + '_' + sectionin,
}))
$('#idtre_' + id + '_' + sectionin).append(
$('<td>', {
'id': 'idtde6_' + id + '_' + sectionin,
}))
$('#idtre_' + id + '_' + sectionin).append(
$('<td>', {
'id': 'idtde7_' + id + '_' + sectionin,
}))
$('#idtre_' + id + '_' + sectionin).append(
$('<td>', {
'id': 'idtde8_' + id + '_' + sectionin,
}))
$('#idtde1_' + id + '_' + sectionin).append(
$('<input>', {
'id': 'tname_' + id + '_' + sectionin,
'type': 'text',
'name': 'tname_' + id + '_' + sectionin,
'class': 'form-control pull-right',
'value': '',
}))
$('#idtde2_' + id + '_' + sectionin).append(
$('<span>', {
'id': 'ed_' + id + '_' + sectionin,
}))
$('#idtde3_' + id + '_' + sectionin).append(
$('<input>', {
'id': 'tconfirmed_plan_old_' + id + '_' + sectionin,
'type': 'number',
'name': 'tconfirmed_plan_old_' + id + '_' + sectionin,
'class': 'form-control pull-right',
'style': 'text-align: right;vertical-align: middle;',
'data-id': id,
'data-name': 'confirmed_plan_old',
'data-in': sectionin,
'value': 0,
}))
$('#idtde4_' + id + '_' + sectionin).append(
$('<input>', {
'id': 'texpected_plan_old_' + id + '_' + sectionin,
'type': 'number',
'name': 'texpected_plan_old_' + id + '_' + sectionin,
'class': 'form-control pull-right',
'style': 'text-align: right;vertical-align: middle;',
'data-id': id,
'data-name': 'expected_plan_old',
'data-in': sectionin,
'value': 0,
}))
$('#idtde5_' + id + '_' + sectionin).append(
$('<input>', {
'id': 'tdiscrepancy_plan_old_' + id + '_' + sectionin,
'type': 'number',
'name': 'tdiscrepancy_plan_old_' + id + '_' + sectionin,
'class': 'form-control pull-right',
'style': 'text-align: right;vertical-align: middle;',
'readonly': 'true',
'value': 0,
}))
$('#idtde6_' + id + '_' + sectionin).append(
$('<input>', {
'id': 'tproject_plan_' + id + '_' + sectionin,
'type': 'number',
'name': 'tproject_plan_' + id + '_' + sectionin,
'class': 'form-control pull-right',
'style': 'text-align: right;vertical-align: middle;',
'data-id': id,
'data-name': 'project_plan',
'data-in': sectionin,
'value': 0,
}))
$('#idtde7_' + id + '_' + sectionin).append(
$('<input>', {
'id': 'tplan_' + id + '_' + sectionin,
'type': 'number',
'name': 'tplan_' + id + '_' + sectionin,
'class': 'form-control pull-right',
'style': 'text-align: right;vertical-align: middle;',
'data-id': id,
'data-name': 'plan',
'data-in': sectionin,
'value': 0,
}))
$('#idtde8_' + id + '_' + sectionin).append(
$('<input>', {
'id': 'tdiscrepancy_' + id + '_' + sectionin,
'type': 'number',
'name': 'tdiscrepancy_' + id + '_' + sectionin,
'class': 'form-control pull-right',
'style': 'text-align: right;vertical-align: middle;',
'readonly': 'true',
'value': 0,
}))
$('#' + 'ed_' + id + '_' + sectionin).html(ed)
$('#tname_' + sectionin).focus();
$('#count_' + nametable).val(sectionin)
suumary(nametable)
}
function suumary(name) {
count = Number($('#count_' + name).val())
project_plan_itog = 0
plan_itog = 0
discrepancy_itog = 0
for (i = 1; i <= count; i++) {
project_plan_itog = project_plan_itog + Number($('#tproject_plan_tbody_'+name+'_' + i).val())
plan_itog = plan_itog + Number($('#tplan_tbody_' + name + '_' + i).val())
discrepancy_itog = discrepancy_itog + Number($('#tdiscrepancy_tbody_' + name + '_' + i).val())
}
$('#project_plan_'+name+'_itog').html('<b>' + numberWithSpaces(project_plan_itog))
$('#plan_'+name+'_itog').html(numberWithSpaces(plan_itog))
$('#discrepancy_' + name +'_itog').html(numberWithSpaces(discrepancy_itog))
expected_plan_old_itog = 0
confirmed_plan_old_itog = 0
discrepancy_plan_old_itog = 0
for (i = 1; i <= count; i++) {
expected_plan_old_itog = expected_plan_old_itog + Number($('#texpected_plan_old_tbody_' + name + '_' + i).val())
confirmed_plan_old_itog = confirmed_plan_old_itog + Number($('#tconfirmed_plan_old_tbody_' + name + '_' + i).val())
discrepancy_plan_old_itog = discrepancy_plan_old_itog + Number($('#tdiscrepancy_plan_old_tbody_' + name + '_' + i).val())
}
$('#expected_plan_old_' + name + '_itog').html('<b>' + numberWithSpaces(expected_plan_old_itog))
$('#confirmed_plan_old_' + name + '_itog').html(numberWithSpaces(confirmed_plan_old_itog))
$('#discrepancy_plan_old_' + name + '_itog').html(numberWithSpaces(discrepancy_plan_old_itog))
}
$(document).on("input", function (ev) {
if (ev.target.getAttribute('data-id') != null) {
data_id = ev.target.getAttribute('data-id')
data_name = ev.target.getAttribute('data-name')
data_in = ev.target.getAttribute('data-in')
if (data_name == 'project_plan' || data_name == 'plan') {
discrepancy = $('#tplan_' + data_id + '_' + data_in).val() - $('#tproject_plan_' + data_id + '_' + data_in).val()
$('#tdiscrepancy_' + data_id + '_' + data_in).val(discrepancy)
}
if (data_name == 'expected_plan_old' || data_name == 'confirmed_plan_old') {
discrepancy = $('#texpected_plan_old_' + data_id + '_' + data_in).val() - $('#tconfirmed_plan_old_' + data_id + '_' + data_in).val()
$('#tdiscrepancy_plan_old_' + data_id + '_' + data_in).val(discrepancy)
}
suumary('ex')
suumary('vs')
suumary('pr')
suumary('nv')
suumary('pt')
}
});
function numberWithSpaces(x) {
var parts = x.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, " ");
return parts.join(".");
}
function save_form() {
var myRows = [];
var $headers = $("th");
var $rows = $("tbody tr").each(function (index) {
$cells = $(this).find("td");
myRows[index] = {};
$cells.each(function (cellIndex) {
myRows[index][$($headers[cellIndex]).html()] = $(this).html();
});
});
var myObj = {};
myObj.myrows = myRows;
let result = [];
let table = document.getElementById("table_row").getElementsByTagName("tbody")[0];
let trs = table.getElementsByTagName("tr");
for (let i = 2; i < trs.length; i++) {
let tds = trs[i].getElementsByTagName("td");
let obj = {};
obj.name = tds[0].innerHTML;
obj.rank = tds[1].innerHTML;
obj.phone = tds[2].innerHTML;
result.push(obj);
}
table = result
$.ajax({
type: 'POST', // <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
url: '/geoproc/monitoring/journal/save/?id={{element.id}}',
data: {
"data_table": JSON.stringify(myObj),
"element": '{{element.id}}'
},
dataType: 'json',
success: function (data) {
window.location.href = '/geoproc/monitoring/journal/';
},
error: function (dataerr) {
$("#reportPanelBody").html(dataerr); // <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> answer
},
timeout: 60000 // sets timeout to 3 seconds
});
}
$(document).ready(function () {
suumary('ex')
suumary('vs')
suumary('pr')
suumary('nv')
suumary('pt')
});