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

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);

$ajax = "CRM/_forms/nastavitve/_ajax/ajax.casPrintanja.php";

$compName = str_replace(' ', '_', StringChecker::Check($_POST['tabName']));
?>

var store = new Ext.data.Store({
	url: '<?php echo $ajax;?>',			
	baseParams:{
		action: 'get'
	},
	reader: new Ext.data.JsonReader({		
			root: 'rows',
			totalProperty : 'results'
		},
		new Ext.data.Record.create([
			{name:'id', type:'id'},
			{name:'term', type:'string'},
			{name:'time', type:'string'}
		])
	)
});

var helpMenu = new Ext.menu.Menu({
	id: 'help_menu',
    items: [ 
		new Ext.form.FormPanel({
			layout: 'menu',
			padding: '5',
			align: 'left',
			frame: true,
			items: [{
				xtype: 'label',
				id: 'lab1',
		    	html: '<?php echo $LangPack->GetLabel("CRM_settings_panel", "printing_term_help_days","Atribut <b>ignore_days</b> označuje dneve,<br>ob katerih se printanje vabil ne izvede.<br>"); ?>',
		    	style: {
		    		fontSize: '13px'
		    	}
			},{
				xtype: 'label',
				id: 'lab2',
		    	html: '<br>'
			},{
				xtype: 'label',
				id: 'lab3',
				html: '<?php echo $LangPack->GetLabel("CRM_settings_panel", "printing_term_help_times","Atributi <b>time-1/2/3</b> označujejo čase,<br>ob katerih se izvede printanje vabil."); ?>',
				style: {
		    		fontSize: '13px'
		    	}
			}]
		}) 
	]
});

var sm = new Ext.grid.RowSelectionModel();

var <?php echo $compName;?> = new Ext.grid.EditorGridPanel({
		id:'<?php echo $compName;?>',
		store: store,
		sm: sm,
		title: '<?php echo str_replace('_', ' ',$compName);?>',
		closable: true,
		viewConfig:{
		    forceFit: true
		},
		columns:[{
			header: '#ID',
			dataIndex: 'id',
			hidden: true
		},{
			header: '<?php echo $LangPack->GetLabel("CRM_settings_panel", "printing_term_title","Termin"); ?>',
			dataIndex: 'term'
		},{
			header: '<?php echo $LangPack->GetLabel("CRM_settings_panel", "printing_time_title","Čas printanja"); ?>',
			dataIndex: 'time',
			editor: new Ext.form.TextField(),
			width: 500
		}],
		tbar:['->',{
			text: '<?php echo $LangPack->GetLabel("CRM_all", "CRM_help_button","Pomoč"); ?>',
			menu: helpMenu
		}],
		listeners: {
			afteredit: function(e){
				Ext.Ajax.request({
					url: '<?php echo $ajax;?>',
					params: {
						action: 'update',
						id		: e.record.data.id,
					    field	: 'cValue',
						value 	: e.value,
						oldValue: e.originalValue
					},
					success : function(resp, opt){ 
						e.record.commit();
					}
				});
			}	
		} 
	});
	<?php echo $compName;?>.getStore().reload();
	Ext.getCmp('NastavitveTabPanel').add(<?php echo $compName;?>);
	Ext.getCmp('NastavitveTabPanel').setActiveTab(<?php echo $compName;?>);