
function adminRequests(selectFunction, renderTo){
	
	var queryURL = 'XmlGMServlet?action_type=shop_actions&action=request_all_not_payed_licences_requests';
	var queryField = 'licence_request';
	
	//If this store is set will be updated at every button click
	this.updateStore = null;	
	this.setUpdateStore = function(store){
		this.updateStore = store;
	}
	
	this.fileRecord = new Ext.data.Record.create([
			{name: "user", mapping: "user", type:'string'},
			{name: "product", mapping: "product", type:'string'},
			{name: "licence_type", mapping: "licence_type", type:'string'},			
			{name: "amount", mapping: "amount", type:'string'},
			{name: "price", mapping: "price", type:'string'},
			{name: "id", mapping: "id", type:'string'}
	]);
	
	this.proxy = new Ext.data.HttpProxy({url: queryURL});
    // create the Data Store
    this.store = new Ext.data.Store({
        // load using HTTP
        proxy: this.proxy,
        // the return will be XML, so lets set up a reader
        reader: new Ext.data.XmlReader({
               // records will have a "category" tag
               record: queryField
           }, this.fileRecord)
    });			

	this.store.load();	

	this.grid = new Ext.grid.GridPanel({
		store: this.store,
	    columns: [
			{header: 'user',  sortable: true},
			{header: 'product', sortable: true},
			{header: 'licence_type', sortable: true},
			{header: 'amount', width: 65, sortable: true},
			{header: 'price', sortable: true}
	    ],
	    height:180,
	    width:480,
		title: "All not payed requests"
	});		

	this.paymentOrRefuseDescription = new Ext.form.TextField({
			bodyStyle: 'text-align: left;',
	        fieldLabel: "payment of refuse description",
			width: 300
	    });
		
	//this.descriptionPanel = new 

	//this.grid.addListener('rowdblclick',selectFunction, this);
	
	this.fieldSet = null;
	
	this.fieldSet = new Ext.form.FieldSet({
		xtype: 'fieldset',
		title: "no title yet",
		collapsible: false,
		collapsed: false,
		autoHeight: true,
		bodyStyle: 'text-align:left;',
		items: [this.grid]
	});
	
	this.buttonSetPayed = new Ext.Button(
		{
			text: 'set payed',
			scope: this,
			minWidth: 100,			
			xtype: 'button',
			handler: function(This,e){
				//get the licence id				
				var selectionModel = this.grid.getSelectionModel();
				var licenceRequestId = selectionModel.getSelected().get('id');
				var description = this.paymentOrRefuseDescription.getValue();
				//send the ajax call
				ajaxSetLicenceRequestPayed(licenceRequestId, description, this);
	        }				
		}
	); 
	
	this.buttonRefuseRequest = new Ext.Button(
		{
			text: 'refuse request',
			scope: this,
			minWidth: 100,			
			xtype: 'button',
			handler: function(This,e){
				//get the licence id				
				var selectionModel = this.grid.getSelectionModel();
				var licenceRequestId = selectionModel.getSelected().get('id');
				var description = this.paymentOrRefuseDescription.getValue();
				//send the ajax call
				ajaxRefuseRequest(licenceRequestId, description, this);
	        }				
		}
	);	
	
	this.showNews = new Ext.form.FormPanel({
	        width: 505,	
			autoHeight : true,
			bodyBorder: false,
			border: false,		
			labelWidth: 200,
			items: [this.fieldSet, this.paymentOrRefuseDescription],
			buttons: [this.buttonSetPayed, this.buttonRefuseRequest]
	});
		
	this.showNews.render(renderTo);
	
}

function ajaxRefuseRequest(licenceRequestId, description, thisScope ){
	ajaxGenericCall('XmlGMServlet?action_type=shop_actions&action=refuse_licence_request',
					function(conn, response, options){
						var failure = lookForXMLFailureResponse(conn.responseXML);
						if (failure != null) { //in case there was an error show it
							showErrorDialog('ERROR!!', failure);
						}else {
							var scope = response.scope;
							scope.store.load();
							if(scope.updateStore != null) scope.updateStore.load();
							scope.paymentOrRefuseDescription.setValue("");
						}
					},
					thisScope,
					{
						licence_request_id: licenceRequestId,
						description: description
					}
	);
}

function ajaxSetLicenceRequestPayed(licenceRequestId, description, thisScope ){
	ajaxGenericCall('XmlGMServlet?action_type=shop_actions&action=set_licence_payed',
					function(conn, response, options){
						var failure = lookForXMLFailureResponse(conn.responseXML);
						if (failure != null) { //in case there was an error show it
							showErrorDialog('ERROR!!', failure);
						}else {
							var scope = response.scope;
							scope.store.load();
							if(scope.updateStore != null) scope.updateStore.load();
							scope.paymentOrRefuseDescription.setValue("");
						}
					},
					thisScope,
					{
						licence_request_id: licenceRequestId,
						description: description
					}
	);
}


function adminAllRequests(selectFunction, renderTo){
	
	//If this store is set will be updated at every button click
	this.updateStore = null;	
	this.setUpdateStore = function(store){
		this.updateStore = store;
	}	
	
	var queryURL = 'XmlGMServlet?action_type=shop_actions&action=request_all_licences_requests';
	var queryField = 'licence_request';
	
	this.fileRecord = new Ext.data.Record.create([
			{name: "user", mapping: "user", type:'string'},
			{name: "product", mapping: "product", type:'string'},
			{name: "licence_type", mapping: "licence_type", type:'string'},			
			{name: "amount", mapping: "amount", type:'string'},
			{name: "price", mapping: "price", type:'string'},
			{name: "payed", mapping: "payed", type:'string'},
			{name: "refused", mapping: "refused", type:'string'},
			{name: "payment_day", mapping: "payment_day", type:'string'},
			{name: "payment_description", mapping: "payment_description", type:'string'},
			{name: "id", mapping: "id", type:'string'}
	]);
	
	this.proxy = new Ext.data.HttpProxy({url: queryURL});
    // create the Data Store
    this.store = new Ext.data.Store({
        // load using HTTP
        proxy: this.proxy,
        // the return will be XML, so lets set up a reader
        reader: new Ext.data.XmlReader({
               // records will have a "category" tag
               record: queryField
           }, this.fileRecord)
    });			

	this.store.load();


	this.grid = new Ext.grid.GridPanel({
		store: this.store,
	    columns: [
			{header: 'user',  sortable: true},
			{header: 'product', sortable: true},
			{header: 'licence_type', sortable: true},
			{header: 'amount', width: 65, sortable: true},
			{header: 'price', sortable: true},
			{header: 'payed', width: 45, sortable: true},
			{header: 'refused', width: 60, sortable: true},
			{header: 'payment_day', width: 140, sortable: true},
			{header: 'payment_description', width: 150, sortable: true}
	    ],
	    height:250,
	    width:480,
		title: "All not payed requests"
	});		

	//this.grid.addListener('rowdblclick',selectFunction, this);
	
	this.fieldSet = null;
	
	this.fieldSet = new Ext.form.FieldSet({
		xtype: 'fieldset',
		title: "no title yet",
		collapsible: false,
		collapsed: false,
		autoHeight: true,
		bodyStyle: 'text-align:left;',
		items: [this.grid]
	});
	
	this.buttonSetNotPayed = new Ext.Button(
		{
			text: 'set not payed',
			scope: this,
			minWidth: 100,			
			xtype: 'button',
			handler: function(This,e){
				/*
				//check if required field have value
				var image = This.scope.selectMenuItemsIcon.getCombo().getValue();
				var content = getLanguageContentFromFieldSetArray(This.scope.langMenuItemFieldSets);
				var category = This.scope.edit_menu_itemsCategoryChooser.getXMLSelectedCategoriesID();
				
				this.config.itemEditor.send(image, category, content, this.config.itemEditor.specificComponents, This.scope);
				*/
	        }				
		}
	);		
	
	this.showNews = new Ext.Panel({
	        width: 505,	
			autoHeight : true,
			bodyBorder: false,
			border: false,		
			items: [this.fieldSet],
			buttons: [/*this.buttonSetNotPayed*/]
	});
		
	this.showNews.render(renderTo);
}

