package edu.duke.cabig.c3pr.web.ajax;

import java.util.List;

import org.extremecomponents.table.bean.Column;
import org.extremecomponents.table.cell.AbstractCell;
import org.extremecomponents.table.core.TableModel;

import edu.duke.cabig.c3pr.constants.ContactMechanismType;
import edu.duke.cabig.c3pr.domain.ContactMechanism;
import edu.duke.cabig.c3pr.domain.HealthcareSiteInvestigator;
import edu.duke.cabig.c3pr.domain.Investigator;

public class HealthcareSiteInvestigatorLinkDisplayCell extends AbstractCell {

	public static final String VIEW_INVESTIGATOR_URL= "editInvestigator?emailId=";
    @Override
    protected String getCellValue(final TableModel model, final Column column) {
        Investigator inv = (Investigator) model.getCurrentRowBean();
     
    	String cellValue = "";
        
    	for(HealthcareSiteInvestigator healthcareSiteInvestigator : inv.getHealthcareSiteInvestigators()){
    		cellValue += healthcareSiteInvestigator.getHealthcareSite().getName()+"<br>"  ;
    	}
    	
        setRowOnClick(model, inv);
        return cellValue;
    }

    public void setRowOnClick(TableModel tableModel, Investigator inv){    	
    	String url = "document.location='" + VIEW_INVESTIGATOR_URL + getEmailId(inv) + "'";
    	tableModel.getRowHandler().getRow().setOnclick(url);
    	tableModel.getRowHandler().getRow().setStyle("cursor:pointer");        
    }
    
    private String getEmailId(Investigator inv){
//    	List<ContactMechanism> contactMechanisms = inv.getContactMechanisms();
//    	for(ContactMechanism contactMechanism : contactMechanisms){
//    		if(contactMechanism.getType() == ContactMechanismType.EMAIL){
//    			return contactMechanism.getValue();
//    		}
//    	}
//    	return "" ;
    	return inv.getEmail();
    }

}

@@ -36,32 +36,8 @@
 x;%0A%0A
-import java.util.List;%0A%0A
 impo
@@ -80,16 +80,16 @@
 Column;%0A
+
 import o
@@ -191,119 +191,8 @@
 l;%0A%0A
-import edu.duke.cabig.c3pr.constants.ContactMechanismType;%0Aimport edu.duke.cabig.c3pr.domain.ContactMechanism;%0A
 impo
@@ -621,22 +621,16 @@
 Bean();%0A
-     %0A
     %09Str
@@ -649,25 +649,16 @@
 e = %22%22;%0A
-        %0A
     %09for
@@ -1228,24 +1228,24 @@
 %0A    %7D%0A    %0A
+
     private 
@@ -1285,306 +1285,8 @@
 v)%7B%0A
-//    %09List%3CContactMechanism%3E contactMechanisms = inv.getContactMechanisms();%0A//    %09for(ContactMechanism contactMechanism : contactMechanisms)%7B%0A//    %09%09if(contactMechanism.getType() == ContactMechanismType.EMAIL)%7B%0A//    %09%09%09return contactMechanism.getValue();%0A//    %09%09%7D%0A//    %09%7D%0A//    %09return %22%22 ;%0A
     

clean up