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

$ajax = CRM_RPATH."_forms/orders/_ajax/ajax.states.php";

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

$LangPack = new LanguagePack($db, $aLanguage);
$windowId = "WindowChangeDate";
?>
var <?php echo $windowId;?> = new Ext.Window({
	title: '<?php echo $LangPack->GetLabel("window_change_delivery_date", "window_title","Sprememba datuma"); ?>',
    id		: '<?php echo $windowId;?>',
    width	: 450,
    height	: 200,
    plain	: true,
    layout	: 'fit',
    frame: true,
    modal: true,
    items:[new Ext.form.FormPanel({
    	bodyStyle: 'padding: 20px',
		border: false,
		id: 'addPlacForm',
		items:[{
			xtype: 'datefield',
			 format: 'd.m.Y',
        	name: 'datumDostave',
        	fieldLabel: '<?php echo $LangPack->GetLabel("window_change_delivery_date", "delivery_date","Datum dostave"); ?>',
        	allowBlank: false
		},{
			xtype: 'textarea',
        	name: 'opomba',
        	fieldLabel: '<?php echo $LangPack->GetLabel("window_change_delivery_date", "note","Opomba"); ?>',
        	anchor: '100%'
		}]
    })],
    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);
		}
	},
	buttons:[{
		text: '<?php echo $LangPack->GetLabel("CRM_all", "CRM_cancle_button","Prekliči"); ?>',
		handler: function(){
			<?php echo $windowId;?>.close();
		}
	},{
		text:'<?php echo $LangPack->GetLabel("CRM_all", "CRM_add_button","Dodaj"); ?>',
		handler: function(){
			if(Ext.getCmp('addPlacForm').getForm().isValid()){
				Ext.getCmp('addPlacForm').getForm().submit({
					url:'<?php echo $ajax;?>',
					params: {
						action: 'changeDate',
						idOrder: '<?php echo StringChecker::Check($_POST['id']); ?>',
						currentState: '<?php echo StringChecker::Check($_POST['state']); ?>',
						oldValue: '<?php echo StringChecker::Check($_POST['start_state']); ?>'
					},
					success: function(resp, opt){
						<?php echo $windowId;?>.close();			
						Ext.getCmp('<?php echo StringChecker::Check($_POST['gridName']);?>').getEl().mask('<?php echo $LangPack->GetLabel("CRM_all", "loading_mask_text","Posodabljanje...");?>');
						Ext.getCmp('<?php echo StringChecker::Check($_POST['gridName']);?>').getStore().reload({ callback: function(resp, opt, success){
							if(success){
								Ext.getCmp('<?php echo StringChecker::Check($_POST['gridName']);?>').getEl().unmask();
							}
						}});
					}
				});
			}
		}
	}]
}).show();
