Старт

This commit is contained in:
2023-11-07 19:51:49 +06:00
commit 86542a157f
5002 changed files with 199551 additions and 0 deletions

View File

@ -0,0 +1,475 @@
class TTrips
{
constructor(map){
//this.m_id=null; //id редактируемой записи
this.trips = []; //Список маршрутов
this.win=null;
this.iframe = createIFrame('trip_file_i', '/monitoring/pscripts/trips.php?fn=4', document.body, false); //Фрейм для закачки файла на сервер
}
//Открывается новое окно для создания нового рейса
// settings - объект(или строка) с настройками для создания маршрута
createTrip(settings)
{
if(this.win!=null && !this.win.closed) return; //Несколько одновременно нельзя создавать
if (typeof settings === 'string' || settings instanceof String)
{
try {
settings = JSON.parse(settings);
} catch (e) {
alert(e.message);
return;
}
}
this.win=new TWin();
this.win.pth='../metadata/dbms/form/';
this.win.BuildGUI(10,40)
this.win.getCaption().appendChild(document.createTextNode(trt("Creation_of_trip")));
//Как подгрузится содержимое выполниться данная функция для настройки по средством JS
var func=function(thiz)
{
return function()
{
setCalendar('trip_date_start','trip_date_start_s');
//кнопка выбора файла
var btn=document.getElementById('e_trip_btn_select_file');
var doc=getIframeDocument(thiz.iframe)
var inp=document.getElementById('trip_file_name');
btn.onclick=function(doc){return function(){doc.forms["form"].elements["file"].click()}}(doc);
doc.forms["form"].elements["file"].onchange = function(inp) {return function(){inp.value=this.files[0].name;/*this.value;*/};}(inp);
/*if(BeforeFirst(doc.body.innerHTML,'=')=='ok')
{
var fName=BeforeFirst(AfterFirst(doc.body.innerHTML,'='),"\n");
inp.value=BeforeLast(inp.value,'.')+'_'+fName;
if(inp.value!='')
{ thiz.sendData();
}
}*/
//Кнопка скачать файл
//Кнопка удаления файла
var btn=document.getElementById('trip_btn_delete_file');
btn.onclick=function(inp,ifr){return function(){ inp.value=''; getIframeDocument(ifr).forms["form"].reset(); }}(inp,thiz.iframe)
thiz.win.setCenter();
}
};
this.win.load("/monitoring/pscripts/trips.php?fn=2",settings,func(this));
this.win.setSize("750px","200px");
//win.setCenter();
this.win.obj=this;
//this.win.Hide(false)
this.win.setCenter();
}
editTrip(settings)
{
if(this.win!=null && !this.win.closed) //Несколько одновременно нельзя редактировать
{
alert(trt('Trip_is_already_being_edited')+'!');
return;
}
if (typeof settings === 'string' || settings instanceof String)
{
try {
settings = JSON.parse(settings);
} catch (e) {
alert(e.message);
return;
}
}
this.win=new TWin();
this.win.pth='../metadata/dbms/form/';
this.win.BuildGUI(10,40)
this.win.getCaption().appendChild(document.createTextNode(trt("Editing_of_trip")));
//Как подгрузится содержимое выполниться данная функция для настройки по средством JS
var func=function(thiz)
{
return function()
{
setCalendar('trip_date_start','trip_date_start_s');
//кнопка выбора файла
var btn=document.getElementById('e_trip_btn_select_file');
var doc=getIframeDocument(thiz.iframe)
var inp=document.getElementById('trip_file_name');
btn.onclick=function(doc){return function(){doc.forms["form"].elements["file"].click()}}(doc);
//Настраиваю форму
doc.forms["form"].elements["file"].onchange = function(inp) {return function(){inp.value=this.files[0].name;/*this.value;*/};}(inp);
thiz.iframe.onload=function(inp,obj){return function()
{ doc=getIframeDocument(this)
if(BeforeFirst(doc.body.innerHTML,'=')=='ok')
{
inp.value=BeforeFirst(AfterFirst(doc.body.innerHTML,'='),"\n")
if(inp.value!='') obj.sendData()
}
}}(inp,thiz);
//Кнопка скачать файл
var btn=document.getElementById('e_trip_btn_download_file');
btn.onclick=function(name){return function(){ window.open('/monitoring/pscripts/trips.php?fn=5&fname='+name, '_blank'); }}(document.getElementById('e_trip_file_name').value)
//Кнопка удаления файла
var btn=document.getElementById('e_trip_btn_delete_file');
btn.onclick=function(inp,ifr){return function(){ inp.value=''; getIframeDocument(ifr).forms["form"].reset(); }}(inp,thiz.iframe)
thiz.win.setCenter();
}
};
this.win.load("/monitoring/pscripts/trips.php?fn=2",settings,func(this));
this.win.setSize("750px","200px");
//win.setCenter();
this.win.obj=this;
//this.win.Hide(false)
this.win.setCenter();
}
//Удалить маршрут
deleteTrip(settings)
{
if (typeof settings === 'string' || settings instanceof String)
{
try {
settings = JSON.parse(settings);
} catch (e) {
alert(e.message);
return;
}
}
if (confirm(trt("Do_you_really_want_to_delete_the_record")+'?')) {
var req=createRequestObject();
req.onreadystatechange = function(thiz)
{
return function(){
if(req.readyState === 4){
var data=null;
try {
data = JSON.parse(req.responseText);
} catch (e) {
alert(e.message);
return;
}
if(data!=null)
{
if(data.errorMessage !== undefined && data.errorMessage!='')
{
alert(data.errorMessage);
thiz.win.hideProgressBar();
}else
{
}
}
//Фильтрую список заново
thiz.filtering();
}
};
}(this);
req.open("POST", '/monitoring/pscripts/trips.php?fn=1', true);
req.setRequestHeader("Content-type", "text/plain");
req.send(JSON.stringify(settings));
this.filtering();
}
return true;
}
saveTrip()
{
//Отправляю файлик дожидаюсь загрузки потом отправляю данные
this.win.showProgressBar();
var doc=getIframeDocument(this.iframe);
if(doc.forms["form"].elements["file"].value!='') //Отправляем файла
{
doc.forms["form"].submit();
}else //Отправляем без файла
{
this.sendData();
}
}
sendData()
{
//Считываю значения с полей и отправляю на сервер
var json='{';
if(document.getElementById('e_trip_id').value=='') json+='"id":null,';
else json+='"id":'+document.getElementById('e_trip_id').value+',';
if(document.getElementById('e_trip_type_id').value=='') json+='"trip_type_id":null,';
else json+='"trip_type_id":'+document.getElementById('e_trip_type_id').value+',';
if(document.getElementById('e_trip_route_id').value=='') json+='"route_id":null,';
else json+='"route_id":'+document.getElementById('e_trip_route_id').value+',';
if(document.getElementById('e_trip_direction').value=='') json+='"direction":null,';
else json+='"direction":'+document.getElementById('e_trip_direction').value+',';
if(document.getElementById('e_trip_carrier_id').value=='') json+='"carrier_id":null,';
else json+='"carrier_id":'+document.getElementById('e_trip_carrier_id').value+',';
if(document.getElementById('e_trip_object_id').value=='') json+='"object_id":null,';
else json+='"object_id":'+document.getElementById('e_trip_object_id').value+',';
if(document.getElementById('e_trip_date_start').value=='') json+='"date_start":null,';
else json+='"date_start":"'+document.getElementById('e_trip_date_start').value+'",';
if(document.getElementById('e_trip_passenger').value=='') json+='"passenger":null,';
else json+='"passenger":"'+document.getElementById('e_trip_passenger').value+'",';
if(document.getElementById('e_trip_file_name').value=='') json+='"file_name":null,';
else json+='"file_name":"'+document.getElementById('e_trip_file_name').value+'",';
if(document.getElementById('e_trip_description').value=='') json+='"description":null';
else json+='"description":"'+document.getElementById('e_trip_description').value+'"';
json+='}';
var req=createRequestObject();
req.onreadystatechange = function(thiz)
{
return function(){
if(req.readyState === 4){
var data=null;
try {
data = JSON.parse(req.responseText);
} catch (e) {
alert(e.message);
return;
}
if(data!=null)
{
if(data.errorMessage !== undefined && data.errorMessage!='')
{
alert(data.errorMessage);
thiz.win.hideProgressBar();
}else
{
thiz.win.Close();
}
}
//Фильтрую список заново
thiz.filtering();
}
};
}(this);
req.open("POST", '/monitoring/pscripts/trips.php?fn=3', true);
req.setRequestHeader("Content-type", "text/plain");
//alert(json);
req.send(json);
}
//Фильтруем объекты для заполнения в таблицу
filtering()
{
showProgressBar(document.getElementById('div_tbl_trips'));
//Выбираем рейсы текущей компании (если админ то все)
var data = {
company_id: document.getElementById('trip_company_id').value,
carrier_id: document.getElementById('trip_carrier_id').value,
route_id: document.getElementById('trip_route_id').value,
status: document.getElementById("trip_status").value
};
var req=createRequestObject();
req.onreadystatechange = function(thiz)
{
return function(){
if(req.readyState === 4){
var data=null;
try {
data = JSON.parse(req.responseText);
} catch (e) {
alert(e.message);
return;
}
if(data!=null)
{
thiz.trips = []; //Удаляю старые объекты
for(i=0;i<data.length;i++)
{
var obj = new TTrip();
obj.id=data[i].id;
obj.trip_type_name=data[i].trip_type_name;
obj.name=data[i].name;
obj.company_name=data[i].company_name;
obj.carrier_name=data[i].carrier_name;
obj.object_name=data[i].object_name;
obj.object_places=data[i].object_places;
obj.direction=data[i].direction;
obj.date_start=data[i].date_start;
obj.date_end=data[i].date_end;
obj.passenger=data[i].passenger;
obj.description=data[i].description;
obj.real_checkpoints=data[i].real_checkpoints;
obj.plan_checkpoints=data[i].plan_checkpoints;
thiz.trips.push(obj);
}
thiz.fillRezDiv(); //Обновляю отображение элементов
}
hideProgressBar(document.getElementById('div_tbl_trips'));
}
};
}(this);
req.open("POST", '/monitoring/pscripts/trips.php?fn=0', true);
req.setRequestHeader("Content-type", "text/plain");
req.send(JSON.stringify(data));
}
//Заполнить результатом выборки DIV в виде таблицы
fillRezDiv()
{
var div=document.getElementById("div_tbl_trips");
delChild(div);
div.innerHTML='<table id="thetable_trips" class="SShow"><thead><tr><th> </th><th title="">Дата/время отправления ('+trt('plan')+')</th><th title="">Дата/время прибытия ('+trt('plan')+')</th><th>'+trt('Route')+'</th><th title="">'+trt('Direction')+'</th><th title="">Автовокзал</th><th title="">Перевозчик</th><th title="">Автобус</th><th title=""></th></tr></thead><tbody></tbody></table>';
var theTable = document.getElementById('thetable_trips');
for(i=0;i<this.trips.length;i++)
{
let tr = document.createElement('tr');
let bgColor='';
if (i%2==0) bgColor='var(--row-color-1)'; else bgColor='var(--row-color-2)';
tr.style.backgroundColor=bgColor;
tr.onmouseover=function(){this.style.backgroundColor='var(--btn-color2)';};
tr.onmouseout=function(val1,val2){return function(){val1.style.backgroundColor=val2;}}(tr,bgColor);
var td=null;
td = document.createElement('td');
td.style.cssText="width:24px;text-align:center;vertical-align:top;";
td.innerHTML='<img id="trip_down_btn_'+this.trips[i].id+'" src="/resources/images/right.png" alt="" style="cursor: pointer;">';
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML=this.trips[i].date_start;
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML=this.trips[i].date_end;
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML=this.trips[i].name;
tr.appendChild(td);
td = document.createElement('td');
if(this.trips[i].direction) td.innerHTML=trt('Direct'); else td.innerHTML=trt('Back');
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML=this.trips[i].company_name;
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML=this.trips[i].carrier_name;
tr.appendChild(td);
td = document.createElement('td');
if(this.trips[i].object_name!=null)
td.appendChild(document.createTextNode(this.trips[i].object_name));
tr.appendChild(td);
/*td = document.createElement('td');
td.style.cssText="vertical-align:top;";
td.innerHTML='<img id="trip_edit_'+this.trips[i].id+'" src="/resources/images/edit24.png" alt="'+trt('Edit')+'" style="cursor:pointer;">';
tr.appendChild(td);*/
theTable.tBodies[0].appendChild(tr);
//Формирую раскрывающийся список
tr = document.createElement('tr');
tr.id=this.trips[i].id;
tr.style.cssText="background-color:var(--back-color-3);display:none";
td = document.createElement('td');
td.colSpan=8;
var html='<table style="width:100%;"><tr><td style="width:100%;border: 0;">';
if(this.trips[i].trip_type_name!=null)
html+='<b>'+trt('Trip_type')+'</b>: '+this.trips[i].trip_type_name+'<br>';
if(this.trips[i].passenger!=null)
{
html+='<b>'+trt('Passengers')+'</b>: '+this.trips[i].passenger;
if(this.trips[i].passenger!=null) html+=' из '+this.trips[i].object_places;
html+='<br>';
}
if(this.trips[i].description!=null)
html+='<b>'+trt('Additional_Information')+'</b>: '+this.trips[i].description+'<br>';
if(this.trips[i].real_checkpoints!=null)
html+='<b>'+'Пройдено контрольных точек'+'</b>: '+this.trips[i].real_checkpoints+' из '+this.trips[i].plan_checkpoints+'<br>';
html+='</td><td valign="top" style="border: 0;"><img id="trip_del_'+this.trips[i].id+'" src="/resources/images/del24.png" alt="'+trt('Delete')+'" title="'+trt('Delete')+'" style="cursor:pointer;"></td><td valign="top" style="border: 0;"><img id="trip_edit_'+this.trips[i].id+'" src="/resources/images/edit24.png" alt="'+trt('Edit')+'" title="'+trt('Edit')+'" style="cursor:pointer;"></td></tr></table>';
td.innerHTML=html;
tr.appendChild(td);
theTable.tBodies[0].appendChild(tr);
//Кнопка разсрыть список
var btn=document.getElementById('trip_down_btn_'+this.trips[i].id);
btn.onclick=function(tr,thiz,id){ return function(){
var btn=document.getElementById('trip_down_btn_'+id);
if(btn.src.indexOf("right.png")!=-1)
{
btn.src = '/resources/images/down.png';
//alert('Показать = '+tr+' = '+tr.style.display);
tr.style.display = 'table-row';
}else if(btn.src.indexOf("down.png")!=-1)
{
btn.src = '/resources/images/right.png';
//alert('Скрыть = '+tr+' = '+tr.style.display);
tr.style.display = 'none';
}
}; }(tr,this,this.trips[i].id);
//Кнопка редактировать
var btn=document.getElementById('trip_edit_'+this.trips[i].id)
btn.onclick=function(thiz,id){ return function(){ thiz.editTrip({id:id}); }; }(this,this.trips[i].id);
//Кнопка удалить
btn=document.getElementById('trip_del_'+this.trips[i].id)
btn.onclick=function(thiz,id){ return function(){ thiz.deleteTrip({id:id}); }; }(this,this.trips[i].id);
}
//Количество элементов в дереве
var divCnt = document.getElementById("count_trips");
delChild(divCnt);
divCnt.appendChild(document.createTextNode(this.trips.length));
}
}
class TTrip
{
constrictor(){
this.id=null;
}
}