Прошу помощи .
-
Как назначить action на кнопки add doctor и add patient.
-
При выборе доктора не отображается его рабочее время . (рендер не получается)
-
Нет связи со списком в таблице.
VF:
<apex:page id=“AppointmentInfo” Controller=“AppointmentController” >
<apex:form >
<apex:pageBlock title=“Appointment Table” id=“table” ><apex:pageBlockSection >
<apex:selectList label=“Select a doctor” value="{!doctors}" size=“1” multiselect=“false” >
<apex:selectOptions value="{!selectDoctor}" />
<apex:actionSupport event=“onchange”
rendered=“true”/></apex:selectList>
</apex:pageBlockSection><apex:pageBlockSection >
<apex:commandButton action="{!save}" value=“Add New Doctor” />
</apex:pageBlockSection><apex:pageBlockSection >
<apex:outputText value="{!bDoctor.Working_Hours_Start__c}">>
</apex:outputText>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:outputText value="{!bDoctor.Working_Hours_End__c}">
</apex:outputText>
</apex:pageBlockSection><apex:pageBlockSection > <apex:selectList label="Select a patient" value="{!patiens}" size="1" multiselect="false"> <apex:selectOptions value="{!selectPatient}" rendered="true"/> </apex:selectList> </apex:pageBlockSection> <apex:pageBlockSection > <apex:commandButton value="Add New Patient" title="Add New Patient"/> </apex:pageBlockSection>
<apex:pageBlockSection > <apex:inputField label="Appointment date" value="{!appointment.Appointment_Date__c}" required="false"/> </apex:pageBlockSection>
<apex:pageBlockSection > <apex:inputField label="Duration in minutes" value="{!appointment.Duration_in_minutes__c}" required="false"/> </apex:pageBlockSection> <!-- Add new appointment button --> <apex:pageBlockSection > <apex:commandButton title="Add New Appointment" action="{!save}" value="Add New Appointment" reRender="updateAppoint"/> </apex:pageBlockSection> <apex:pageBlockTable value="{!appList}" var="doc"> <apex:column headerValue="Action"> <apex:commandLink title="View" value="{!appointment}"> <apex:param value="{!URLFOR('/'+ doc.Id)}" /> View </apex:commandLink> </apex:column> <apex:column headerValue="Doctor's Name" value="{!doc.Doctor__c}" /> <apex:column headerValue="Patient's Name" value="{!doc.Patient__c}"/> <apex:column headerValue="Date" value="{!doc.Appointment_Date__c}"/> <apex:column headerValue="Duration" value="{!doc.Duration_in_minutes__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form>
</apex:page>
КОНТРОЛЛЕР:
public with sharing class AppointmentController {
public Appointment__c appointment {get; set;}
public Doctor__c bDoctor{get;set;}
public List<Doctor__c> doctors{get;set;}
public List<Doctor__c> workHours{get;set;}
public List<Patient__c> patiens{get;set;}
public List<Appointment__c> appList {get;set;}
public String selectDoctors{get;set;}
public String selectPatients{get;set;}
Public Integer size{get;set;}
Public Integer pageSize{get; set;}
Public Integer count{get;set;}
public AppointmentController(){
appointment = new Appointment__c();
doctors = [SELECT Name,Working_Hours_End__c,Working_Hours_Start__c FROM Doctor__c ];
workHours = [SELECT Working_Hours_End__c,Working_Hours_Start__c FROM Doctor__c where Doctor__c.id =:selectDoctors];
patiens = [SELECT Id,Name FROM Patient__c];
bDoctor = doctors[0];
size = 20;
pageSize = setCon.getPageSize();
}
public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
[select id,Doctor__r.Name,Patient__r.Name,Duration_in_minutes__c,Appointment_Date__c FROM Appointment__c]));
setCon.setPageSize(size);
pageSize = setCon.getResultSize();
}
return setCon;
}
set;
}
public List<Appointment__c> getAppointmentList() {
return (List<Appointment__c>) setCon.getRecords();
}
public List getselectDoctor(){
List lOptions = new List();
for (Doctor__c doc : doctors){
lOptions.add(new SelectOption(doc.Id, doc.Name ));
workHours = [SELECT Working_Hours_End__c,Working_Hours_Start__c FROM Doctor__c where id =:selectDoctors];
if(workHours.size()>0)
// только время не совсем точное получается , ибо совсем не тот id , но с этим можно поработать
bDoctor = workHours[0];
//bDoctor = doctors[0];
}
return lOptions;
}
public List getselectPatient(){
List lOptions = new List();
for (Patient__c pat : patiens){
lOptions.add(new SelectOption(pat.Id, pat.Name));
}
return lOptions;
}
public PageReference RedirDoctors() {
PageReference newdoc = new PageReference(’/lightning/o/Doctor__c/new?count=1’);
newdoc.setRedirect(true);
return newdoc ;
}
public PageReference RedirPatients() {
PageReference newpat = new PageReference(’/lightning/o/Patient__c/new?count=1’);
newpat.setRedirect(true);
return newpat ;
}
public PageReference save() {
appointment.Doctor__c = selectDoctors;
appointment.Patient__c = selectPatients;
PageReference pageRef = Page.AppointmentInfo;
pageRef.setRedirect(true);
try {
insert appointment;
}catch (Exception e){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'This doctor already has an appointment at this time.');
ApexPages.addMessage(myMsg);
}
return pageRef;
}
public PageReference refreshPageSize() {
setCon.setPageSize(size);
return null;
}
}