/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpEditListController(){	
	this._route = null;
	this._div = null;
	this._method = "get";
	this._filter = null;
	this._order = null;	
	this._pager = null;
	
	this.ID = null;
}
wlpEditListController.prototype = new wlpActionController;

wlpEditListController.prototype.routeAction = function(/*String*/ url){
	window.location = url;
}

wlpEditListController.prototype._getAditionalParams = function(){
	var strURLParam = "";
	var filterParams = null;
	var orderParams = null;
	var pagerParams = null;	
	var delimetr = "";	
	
	if (this._filter!=null) filterParams = this._filter.toString(); 
	if (this._pager!=null) pagerParams = this._pager.toString();		
	if (this._order!=null) orderParams = this._order.toString(); 		
	
	if (filterParams!=null){
		strURLParam+=delimetr+filterParams;
		delimetr = "&";
	}

	if (orderParams!=null){
		strURLParam+=delimetr+orderParams;
		delimetr = "&";
	} 
		
	if (pagerParams!=null){
		strURLParam+=delimetr+pagerParams;
	}  
	
	if (strURLParam=="") return null;
	
	return strURLParam;	
}

wlpEditListController.prototype.init = function(_id,_r,_d){
	this.ID = _id;
	this._route = _r;
	this._div = _d;
}

wlpEditListController.prototype.setDiv = function(_d){
	this._div = _d;
}

wlpEditListController.prototype.load = function(){
	
	var strURL = this._route.toString();

	var delimetr = "&";
	if (this._route.params.count==0) delimetr="?";
		
	var strURLParam = this._getAditionalParams();
		
	if (strURLParam!=null){
		strURL+=delimetr+strURLParam;
	}
//alert(strURL);
	this._load(strURL);	
}

wlpEditListController.prototype._load = function(/*String*/ _url){
	var ajaxEditItem = new Ajax.Updater(this._div, _url, {method: this._method, evalScripts: true});
}

wlpEditListController.prototype.sort = function(/*wlpProperty*/ param){
	this._order.replace(param);
	this.load();
}

wlpEditListController.prototype.page = function(/*int*/ pageNum){
		//alert(pageNum);
	this._pager.set('page',pageNum);
	this.load();
}

wlpEditListController.prototype.perPage = function(/*int*/ rpp){
	this._pager.set('page',1);
	this._pager.set('rpp',rpp);
	this.load();
}

wlpEditListController.prototype.filter = function(/*wlpURLParamSet*/filter){
	this._filter = filter;
	this.load();
}

wlpEditListController.prototype.setFilter = function(/*wlpFilter*/ filter){	
	this._filter = filter;
}

wlpEditListController.prototype.setOrder = function(/*wlpOrder*/ order){
	this._order = order;
}

wlpEditListController.prototype.setPager = function(/*wlpPager*/ pager){	
	this._pager = pager;
}


