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Дата/время прибытия ('+trt('plan')+')'+trt('Route')+''+trt('Direction')+'АвтовокзалПеревозчикАвтобус'; var theTable = document.getElementById('thetable_trips'); for(i=0;i'; 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=''+trt('Edit')+''; 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='
'; if(this.trips[i].trip_type_name!=null) html+=''+trt('Trip_type')+': '+this.trips[i].trip_type_name+'
'; if(this.trips[i].passenger!=null) { html+=''+trt('Passengers')+': '+this.trips[i].passenger; if(this.trips[i].passenger!=null) html+=' из '+this.trips[i].object_places; html+='
'; } if(this.trips[i].description!=null) html+=''+trt('Additional_Information')+': '+this.trips[i].description+'
'; if(this.trips[i].real_checkpoints!=null) html+=''+'Пройдено контрольных точек'+': '+this.trips[i].real_checkpoints+' из '+this.trips[i].plan_checkpoints+'
'; html+='
'+trt('Delete')+''+trt('Edit')+'
'; 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; } }