var LogistMobile_cars_Window = null;
	
/* store & model for tms_device --> */	
	Ext.define('carsLogistMobileModel', {
	    extend: 'Ext.data.Model',
		fields: ['TripId','Name','Login','Project','Login2','StartTime','EndTime', {name: 'indoor', type: 'bool'}]
	});
	var carsLogistMobileStore = new  Ext.data.Store({   
			//autoLoad: true,	
	        model: 'carsLogistMobileModel',
	        proxy: 
	        {
	          type: 'ajax',
	          url: 'app/LogistMobile_cars.php?func=show',
	          reader: 
	          {
	            type: 'json',
	            root: 'rows'
	          }
	        },listeners: {
				load: function(store, records, successful, operation, eOpts) {
					
					store.each(function(record){
						if( record.get('indoor') == true ){
							Ext.getCmp('carsLogistMobileBtnBlockAll').setText(available_cars.btnunblockcarsnapshotall);
							Ext.getCmp('carsLogistMobileBtnBlockAll').toggle(true);
						}
					});
				}
			}
	});
/* store & model for tms_device --> */


function filterReportCars(){
	
	var warehouse = Ext.getCmp('bind_warehouse_cars').getRawValue();
	var device = Ext.getCmp('filter_cars_field_cars').getValue();
	
	carsLogistMobileStore.setProxy({
	type: 'ajax',
	url: 'app/LogistMobile_cars.php?func=show&warehouse='+warehouse+'&device='+device,
	reader: {
		type: 'json',
		root: 'rows'
	}
	});
	
	carsLogistMobileStore.load();
}


//var LogistMobile_test_Window = null;
function show_LogistMobile_cars_Window() {
	
	carsLogistMobileStore.load();
	Warehouse_store.load();
	
	intervalcarsLogistMobile = setInterval(function(){
        carsLogistMobileStore.load();
    }, 15000);
	
	if (!LogistMobile_cars_Window) {
		//Xcoord = Xcoord ? Xcoord :40;
	    //Ycoord = Ycoord ? Ycoord :60;  
	    //Wwidth = Wwidth ? Wwidth :1100;  
	    //Wheight = Wheight ? Wheight :600;
	    Xcoord = 40;
	    Ycoord = 60;  
	    Wwidth = 700;  
	    Wheight = 400;
			
/* grid for tms_trip --> */			
	    var carsLogistMobileGrid = new Ext.grid.Panel({
	    	//title: plan_toir.routes,
	    	selType: 'rowmodel',
	        columnLines: true,
	        layout: 'fit',
	        //id: 'TOiR_TripPlanningGridId',
	        store:  carsLogistMobileStore,
	        loadMask: true,
	        border: false,
	        autoScroll: true,
	        viewConfig: {
	        	preserveScrollOnRefresh: true,
	        },	        
	        columns:[
			{
	        	xtype: 'rownumberer',
				width: 30,	
	        },
			{
	        	//text: 'Авто',
				text: available_cars.auto,
	        	dataIndex: 'Login',
	        	//style: 'text-align:center',            
	            //align: 'center',
	        	sortable: false,
	        	width: 200,
	        },
			{
	        	//text: 'Проект',
	        	text: available_cars.project, 
	            dataIndex: 'Project',
	            //style: 'text-align:center',            
	            width: 100,
				//align: 'center',
	            sortable: true,
	        },
			{
	        	//text: 'Рейс',
	        	text: available_cars.trip, 
	            dataIndex: 'Name',
	            //style: 'text-align:center',            
	            width: 100,
				//align: 'center',
	            sortable: true,
	        },
			{        	
	        	//text: 'Начало рейса',
	        	text: available_cars.start_trip, 
	            dataIndex: 'StartTime',
	            width: 120,
				sortable: true,
	        },
			{
	        	//text: 'Конец рейса',
	        	text: available_cars.end_trip,
	            dataIndex: 'EndTime',
	            width: 120,
				sortable: true,
	        },
			{
				xtype: 'checkcolumn', 
				//text: 'Блокировать авто', 
				text: available_cars.block_cars, 
				width: 120, 
				dataIndex: 'indoor', 
				hideable: false, 
				sortable: false,
				listeners:
                {
                    checkchange:function(CheckColumn, rowIndex, checked, eOpts )
                    {
						var row = carsLogistMobileStore.getAt(rowIndex);
						
						if(checked){ text_checked = available_cars.block;}else{ text_checked = available_cars.unblock;}
						
						//Ext.MessageBox.confirm(all_toir.attention, text_checked+' '+available_cars.car_for_planning,  function(btn){
						//		if(btn=='yes'){
									
						Ext.Ajax.request({
						url: 'app/LogistMobile_cars.php',
						method: 'POST',
						params: { func:"blockCar", login:row.get('Login2'), checked:checked },
						success: function(response) {
							
						},
						failure: function(response) {
							
						}
						});
									
						//		}
						//});
						
						
					}
				}
			}
			], 
	        listeners: {
	        	itemclick: function(cmp, records) {
					
	        	}	
	        },
			tbar:[
				{
	    		xtype: 'button',
	    		//text: plan_toir.update_details,
				tooltip: plan_toir.update_details,
				iconCls: 'refresh',
	    		handler: function() {
					carsLogistMobileStore.load();
				}
				},{
					text: available_cars.btnblockcarsnapshotall,
					id: 'carsLogistMobileBtnBlockAll',
					pressed: false,
					enableToggle: true,
					handler: function(){
						if(this.pressed){
							this.setText(available_cars.btnunblockcarsnapshotall);
							carsLogistMobileStore.each(function(record){
								record.set('indoor',true);
							});
						}else{
							this.setText(available_cars.btnblockcarsnapshotall);
							carsLogistMobileStore.each(function(record){
								record.set('indoor',false);
							});
						}
								Ext.Ajax.request({
								url: 'app/LogistMobile_cars.php',
								method: 'POST',
								params: { blockcarall:true, pressed:this.pressed },
								success: function(response) {
									//console.log(response);
								},
								failure: function(response) {
									//console.log(response);
									Ext.MessageBox.alert(all_toir.error, '');
								}
								});
					}
				}
				,'-',{
			        	 xtype: 'combo',
			        	 store: Warehouse_store,
			        	 allowBlank: false,
			        	 //margin: '5 5 5 5',
			        	 width: 80,
						 editable: false,
			        	 id: 'bind_warehouse_cars',
			        	 valueField: 'ID',
			        	 displayField: 'Name',
			        	 queryMode: 'local',
						 listeners: {
							
							}
		           },
				   {
		        	   xtype: 'textfield',
		        	   id: 'filter_cars_field_cars',
					   width: 80,
		        	   enableKeyEvents: true,
		        	   listeners:  {
		        		   keypress: function(field, e, eOpts) {
		        			   if (e.getKey() == e.ENTER) {
		        				  
		        			   } 

		        		   }
		        	   }
		           }, {
		        	   xtype: 'button',
		        	   //text: 'Фильтровать',
		        	   text: all.filter,
		        	   handler: function() {            		
		        		   var filterValCar = Ext.getCmp('filter_cars_field_cars').getValue();
		        		   filterReportCars();
		        	   }
		           }, {
		        	   xtype: 'button',
		        	   //text: 'Сброс',
		        	   text: all.reset,
		        	   handler: function() {
		        		   var filterValCar = ''; 
		        		   Ext.getCmp('filter_cars_field_cars').setValue('');
						   Ext.getCmp('bind_warehouse_cars').setValue('');
						   filterReportCars();
		        	   }
		           }
			]
	    	
	    });
/* <-- grid for tms_trip */		    
	    
		
		
	        Ext.getBody().mask(all.loading);
	        LogistMobile_cars_Window = new Ext.Window({
	            layout : 'fit',
	            //title: 'Автомобили в рейсе',
	            title : available_cars.cars_in_trip,
	            closeAction : 'destroy',
	            width : parseInt(Wwidth),
	            height : parseInt(Wheight),
	            maximizable:true,
				constrain : true,
				resizable: true,
				x : 2,
	            y : 29,
	            defaults: {
	                //collapsible: true,
	                //split: true,
	            },
				listeners : {
	            	destroy : function(){
	            		LogistMobile_cars_Window = null;	
	            	}
	            },
	            items: [carsLogistMobileGrid]
			})      
		LogistMobile_cars_Window.show(); 
		Ext.getBody().unmask(all.loading);

	}



	
	
/*	
Ext.define('Person', {
    extend: 'Ext.data.Model',
    fields: ['first', 'last', 'review', {
        name: 'age',
        type: 'int'
    }]
});

	if (!LogistMobile_test_Window) {

	    Wwidth = 800;  
	    Wheight = 600; 
		
	        Ext.getBody().mask(all.loading);
	        LogistMobile_test_Window = new Ext.Window({
	            layout: 'border',
	            title: 'Test',
	            closeAction: 'destroy',
	            width: parseInt(Wwidth),
	            height: parseInt(Wheight),
	            maximizable: true,
				constrain: true,
				resizable: true,
				listeners: {
	            	destroy: function(){
	            		LogistMobile_test_Window = null;	
	            	}
	            },
				defaults: {
				collapsible: true,
				split: true,
				stateful: true
				},
				dockedItems: [
				{   
            	xtype: 'toolbar',
            	border: true,
				items: [
					{
					text: "Добавить документ",
					handler:function(){
					}
					}
				]
				},
				],
	            items: [
		{
            //title: 'Footer',
            region: 'south',
            height: 200,
            minHeight: 75,
            maxHeight: 300,
			collapsible: false,
			layout: {
			type: 'hbox',
			pack: 'start',
			align: 'stretch'
			},
			items:[
			
			{
            //bodyPadding: 5,
            //region: 'west',
            title: 'Collapse/Width Panel 1',
            flex: 1,
			//width: 240,
            //stateId: 'statePanelExample',
            stateful: true,
            split: true,
            collapsible: false,
            xtype: 'grid',
            store: Ext.create('Ext.data.Store', {
                model: 'Person',
                data: [{
                    first: 'John',
                    last: 'Smith',
                    age: 32,
                    review: 'Solid performance, needs to comment code more!'
                }, {
                    first: 'Jane',
                    last: 'Brown',
                    age: 56,
                    review: 'Excellent worker, has written over 100000 lines of code in 3 months. Deserves promotion.'
                }, {
                    first: 'Kevin',
                    last: 'Jones',
                    age: 25,
                    review: 'Insists on using one letter variable names for everything, lots of bugs introduced.'
                }, {
                    first: 'Will',
                    last: 'Zhang',
                    age: 41,
                    review: 'Average. Works at the pace of a snail but always produces reliable results.'
                }, {
                    first: 'Sarah',
                    last: 'Carter',
                    age: 23,
                    review: 'Only a junior, but showing a lot of promise. Coded a Javascript parser in Assembler, very neat.'
                }]
            }),
            columns: [{
                text: 'First Name',
                width:110,
                dataIndex: 'first'
            }, {
                text: 'Last Name',
                width:110,
                dataIndex: 'last'
            }, {
                text: 'Age',
                width:60,
                dataIndex: 'age'
            }, {
                flex: 1,
                text: 'Review',
                dataIndex: 'review'
            }]
			},
			{
            //region: 'east',
            title: 'Collapse/Width Panel 2',
			flex: 1,
			stateful: true,
            //stateId: 'stateGridExample',
            split: true,
            collapsible: false,
			xtype: 'grid',
            store: Ext.create('Ext.data.Store', {
                model: 'Person',
                data: [{
                    first: 'John',
                    last: 'Smith',
                    age: 32,
                    review: 'Solid performance, needs to comment code more!'
                }, {
                    first: 'Jane',
                    last: 'Brown',
                    age: 56,
                    review: 'Excellent worker, has written over 100000 lines of code in 3 months. Deserves promotion.'
                }, {
                    first: 'Kevin',
                    last: 'Jones',
                    age: 25,
                    review: 'Insists on using one letter variable names for everything, lots of bugs introduced.'
                }, {
                    first: 'Will',
                    last: 'Zhang',
                    age: 41,
                    review: 'Average. Works at the pace of a snail but always produces reliable results.'
                }, {
                    first: 'Sarah',
                    last: 'Carter',
                    age: 23,
                    review: 'Only a junior, but showing a lot of promise. Coded a Javascript parser in Assembler, very neat.'
                }]
            }),
            columns: [{
                text: 'First Name',
                width:110,
                dataIndex: 'first'
            }, {
                text: 'Last Name',
                width:110,
                dataIndex: 'last'
            }, {
                text: 'Age',
                width:60,
                dataIndex: 'age'
            }, {
                flex: 1,
                text: 'Review',
                dataIndex: 'review'
            }]
			}
			]
            //html: '<p>Footer content</p>'
        },
        {
            title: 'Navigation',
            region:'west',
            //floatable: false,
            //margin: '0 0 0 0',
            width: '50%',
            minWidth: 200,
            //maxWidth: 250,
            html: '<p>Secondary content like navigation links could go here</p>'
        },
        {
            //title: 'Main Content',
            collapsible: false,
            width: '50%',
			region: 'center',
			minWidth: 200,
			layout: 'fit',
            //margin: '0 0 0 0',
            items: [
				 {xtype: 'gmappanel',
                    center: {
                        geoCodeAddr: '4 Yawkey Way, Boston, MA, 02215-3409, USA',
                        marker: {title: 'Fenway Park'}
                    }
					}
			]
        }
				]
			})      
		LogistMobile_test_Window.show(); 
		Ext.getBody().unmask(all.loading);

	}
*/


}