<?php
include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");
include_once (PATH_TO_ROOT."CRM/_CRM_config.php");
include_once (PATH_TO_ROOT."CRM/class/class.checkString.php");
	
$db->ChangeDatabase(DB_WARPIT_WEBCATI_BASE);

$ajax = CRM_RPATH."_forms/deliveryContract/_ajax/ajax.deliveryContract.php";

include_once (PATH_TO_ROOT."CRM/_CRM_config.php");
include_once(PATH_TO_ROOT."CRM/class/class.Language-Pack.php");

$LangPack = new LanguagePack($db, $aLanguage);
$windowId = "WindowChangeDate";
?>
var deliveryHistoryPageLimit = 20;
var deliveryHistoryStore = new Ext.data.Store({
	url: '<?php echo $ajax;?>',			
	baseParams:{
		action: 'getHistory',
		start: 0,
		limit: deliveryHistoryPageLimit
	},
	autoLoad: true,
	pageSize: deliveryHistoryPageLimit,
	reader: new Ext.data.JsonReader({		
		root:'rows',
		totalProperty : 'results'
	},
	new Ext.data.Record.create([
		{ name:"id_print", type: 'int' },
	 	{ name:"actionDate", type: 'string' },
	 	{ name:"count", type:'int'}
		])
	)
});
var <?php echo $windowId;?> = new Ext.Window({
	title: '<?php echo $LangPack->GetLabel("CRM_deliveryContract_history_window", "window_title","Zgodovina"); ?>',
    id		: '<?php echo $windowId;?>',
    width	: 450,
    height	: 200,
    plain	: true,
    layout	: 'fit',
    frame: true,
    modal: true,
    items:[new Ext.grid.EditorGridPanel({
    	store: deliveryHistoryStore,
	    id: '<?php echo $compName;?>',
	    border: false,
	    sm: new Ext.grid.RowSelectionModel(),
	    closable: true,
	    viewConfig:{
	    	forceFit: true,
	    },
	    region: 'center',
	    columns:[{
	    	header: '<?php echo $LangPack->GetLabel("CRM_deliveryContract_history_window", "action_date_title","Datum");?>',
	    	dataIndex: 'actionDate'
	    },{
	    	header: '<?php echo $LangPack->GetLabel("CRM_deliveryContract_history_window", "action_count_title","Seštevek");?>',
	    	width: 30,
	    	dataIndex: 'count'
	    },{
	    	header:'<?php echo $LangPack->GetLabel("CRM_deliveryContract_history_window", "print_title","Print");?>',
	    	dataIndex: 'id_print',
	    	width: 30,
	    	renderer: function(a, meta, record){
	    		return "<a href='<?php echo $ajax;?>?action=print&history=true&print_id="+a+"' target='_blank'><?php echo $LangPack->GetLabel("CRM_deliveryContract_history_window", "print_title","Print");?></a>";
	    	}
	    }],
	    bbar: [new Ext.PagingToolbar({
	        pageSize: deliveryHistoryPageLimit,
	        store: deliveryHistoryStore,
	        displayInfo: true,
	        displayMsg: '<?php echo $LangPack->GetLabel("CRM_deliveryContract_history_window", "pagger_display_msg","Printi");?> {0} - {1} of {2}',
	        emptyMsg: "<?php echo $LangPack->GetLabel("CRM_deliveryContract_history_window", "pagger_empty_msg","Ni printov");?>"
	     })]
    })],
    listeners: {
		afterRender: function(grid){
			var X = (screen.width/2) - ((Ext.getCmp('<?php echo $windowId;?>').getSize().width)/2);
			var Y = (screen.height/2) - ((Ext.getCmp('<?php echo $windowId;?>').getSize().height)/2);
			Ext.getCmp('<?php echo $windowId;?>').setPosition(X, Y);
		}
	}
}).show();
