
/*
 * Depends on table_data_base.js
 */

function TableDataUsers(companyId, pNameSpace, numPages, locale, username, role, removeButtonText) {
	
	this.companyId = companyId;
	this.page = 1;
	this.pNameSpace = pNameSpace;
	this.numPages = numPages;
	this.locale = locale;
	this.username = username;
	this.role = role;
	this.removeText = removeButtonText;
	
	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
		};
		CompanyUserRemoteService.getRemoteUsersListDataBean(this.companyId, page, this.locale, this.username, this.role, callMetaData);	
	}
	
	this.fillTable = function fillTable(resp) {
		var val;		
		
		var cellFuncs = [
		    function(data) {return data.accessInfo.userName;},
			function(data) {return data.userInfo.interlocutorName + ' ' + data.userInfo.interlocutorLastName;},
		  	function(data) {return data.accessInfo.accessTypePresentationText;},
			function(data) {return removeButtonText;}		  	
		];	
		
		
		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:gotoUser('" + options.rowData.idEnc + "');"; 
						
						options.data = null;
						td.appendChild(a);
						break;
						
					case 3:
						td.className = "tableListNormalRemove";
						var par = document.createElement("p");
						par.className = "supportSmallBtnRemove";
						
						var anc = document.createElement("a");
						anc.href = "javascript:deactivateUser('" + options.rowData.idEnc + "');"; 
						
						var spa = document.createElement("span");
						spa.innerHTML = removeButtonText;
						
						options.data = null;
						
						anc.appendChild(spa);
						par.appendChild(anc);
						td.appendChild(par);
						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;			
}