
/*
 * Depends on table_data_base.js
 */

function TableDataCompanies(memberId, groupId, pNameSpace, numPages, locale, call, username, role) {
	
	this.memberId = memberId;
	this.groupId = groupId;
	this.page = 1;
	this.pNameSpace = pNameSpace;
	this.numPages = numPages;
	this.locale = locale;
	this.call = call;
	this.username = username;
	this.role = role;	
	
	this.numberOfColumns = 3;
	
	this.getRemoteListDataBean = function getRemoteListDataBean(page) {
	    
		this.addLoading(this.pNameSpace + "Trans");	    
		var parent = this;
		var callbackProxy = function(dataFromServer) {
			callbackGetRemoteListDataBean(dataFromServer, page, parent);				
		};
		var exceptionHandlerProxy = function(exceptionMessage, exception) {
			callbackExceptionGetRemoteListDataBean(exceptionMessage, exception, parent, numberOfColumns);				
		};
		
	    var callMetaData = {
	    	callback: callbackProxy,		  		  
		  	exceptionHandler: exceptionHandlerProxy
		};
	    
	    
	    switch(this.call) {
			case 0:
				CompaniesRemoteService.getRemoteCompaniesGroupListDataBean(this.groupId, page, this.locale, this.username, this.role, this.memberId, callMetaData);
				break;
			case 1: 
				CompaniesRemoteService.getRemoteCompaniesUserListDataBean(this.memberId, page, this.locale, this.username, this.role, callMetaData);
				break;
			default: break;
		}
	    
	    
	}
	
	
	function callbackExceptionGetRemoteListDataBean(exceptionMessage, exception, parent) {
		var cellFuncs = [
			function(data) {return parent.getErrorHtml(data);}
		];
		DWRUtil.removeAllRows(parent.pNameSpace + "Trans");
		DWRUtil.addRows(parent.pNameSpace + "Trans", [exceptionMessage], cellFuncs, 
			{
	      		cellCreator:function(options) {
				    var td = document.createElement("td");			    
	          		td.setAttribute('colspan', 3);          			  
				    return td;
				},escapeHtml:false
			}
		);
		
	}
	
	this.fillTable = function fillTable(resp) {
		var val;
		
		var cellFuncs = [
			function(data) {return data.name;},
		  	function(data) {return data.cipCode;},
		  	function(data) {return data.enrolmentDate;},		  	
		];	
		
		
		DWRUtil.removeAllRows(this.pNameSpace + "Trans");
		DWRUtil.addRows(this.pNameSpace + "Trans", resp.data, cellFuncs, 
		{ 
			rowCreator:function(options) {
			    var row = document.createElement("tr");			    
			    row.className = "tableListNormalTr";
			    return row;
		  	},
			cellCreator:function(options) {
			    var td = document.createElement("td");			   
			    td.className = "tableListNormal";
				
			    var index = options.cellNum;
			    
			    switch(index) {
					case 0:
						var a = document.createElement("a");
						a.className = "paginated";
						a.innerHTML = options.data;
						a.href = "javascript:gotoCompany('" + options.rowData.idEnc + "');"; 
						
						options.data = null;
						td.appendChild(a);
						break;
					
					default: break;
				}	
			    
			    return td;
			},
			escapeHtml:false 
		});		
	}
	
	this.getErrorHtml = getErrorHtml;
	this.addLoading = addLoading;
	this.backPaginatedPage = backPaginatedPage;
	this.nextPaginatedPage = nextPaginatedPage;
	this.changePaginatedPage = changePaginatedPage;
	this.updatePaginationTable = updatePaginationTable;				
}