00001 import java.util.Vector;
00002 import java.sql.SQLException;
00003
00004 public class ReferralEditor extends Widget
00005 {
00006 public int active;
00007 public Vector referrals;
00008 public ActionButton action;
00009
00010 public static final int SAVE = 1;
00011 public static final int SAVEADD = 2;
00012 public static final int CANCEL = 3;
00013
00014 public DoctorSelect doctor;
00015 public boolean incoming;
00016
00017 boolean done = false;
00018 boolean more = false;
00019
00020 public ReferralEditor(int active, Vector referrals, String prefix, Form form)
00021 {
00022 super(prefix, form);
00023 this.active = active;
00024 this.referrals = referrals;
00025 action = new ActionButton(n("action"), form);
00026 doctor = new DoctorSelect(0, 7, n("doctor"), form);
00027 addChild(action);
00028 addChild(doctor);
00029 }
00030
00031 public void save()
00032 {
00033 Referral r;
00034 if (active < 0)
00035 {
00036 r = new Referral();
00037 referrals.add(r);
00038 }
00039 else
00040 {
00041 r = (Referral) referrals.get(active);
00042 }
00043
00044 r.doctor_id = doctor.id.intValue();
00045 r.incoming = incoming;
00046 }
00047
00048 public void loadDefaults()
00049 {
00050 if (active < 0) return;
00051 Referral load = (Referral) referrals.get(active);
00052 doctor.id = new Integer(load.doctor_id);
00053 incoming = load.incoming;
00054 }
00055
00056 public void loadValues()
00057 {
00058 super.loadValues();
00059 incoming = toInt(loadAttribute("incoming"), 0) != 0;
00060
00061 switch(action.action)
00062 {
00063 case SAVE:
00064 done = true;
00065 save();
00066 break;
00067 case CANCEL:
00068 done = true;
00069 break;
00070 case SAVEADD:
00071 more = true;
00072 save();
00073 break;
00074 }
00075 }
00076
00077 public void display(boolean hidden)
00078 {
00079 super.display(hidden);
00080 if (hidden || modalChild != null)
00081 {
00082 printAttribute("incoming", incoming ? "1" : "0");
00083 return;
00084 }
00085 p(
00086 "\n"+
00087 "<table>\n"+
00088 "<tr>\n"+
00089 " <td>Referral</td>\n"+
00090 " <td><select name=" + n("incoming") + ">"
00091 + "<option value=1" + (incoming ? " selected" : "") + ">From"
00092 + "<option value=0" + (incoming ? "" : " selected") + ">To"
00093 + "</select></td>\n"+
00094 " <td>"); doctor.display(); p("</td>\n"+
00095 "</tr>\n"+
00096 "<tr>\n"+
00097 " <td colspan=3 align=center>\n"+
00098 "");
00099 action.display("Save", SAVE);
00100 action.display("Save and Add Another", SAVEADD);
00101 action.display("Cancel", CANCEL); p("\n"+
00102 " </td>\n"+
00103 "</tr>\n"+
00104 "</table>\n"+
00105 "");
00106 }
00107 };