1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: class PersonEditPanel extends QPanel {
17:
18: protected $objPerson;
19: public $strTitleVerb;
20: protected $blnEditMode;
21:
22:
23: protected $strMethodCallBack;
24:
25:
26:
27: public $lblId;
28: public $txtFirstName;
29: public $txtLastName;
30:
31:
32: public $lstLogin;
33: public $lstProjectsAsTeamMember;
34:
35:
36: public $btnSave;
37: public $btnCancel;
38:
39:
40: protected $strTemplate = 'PersonEditPanel.tpl.php';
41:
42:
43: protected $strPadding = '10px';
44: protected $strBackColor = '#fefece';
45:
46: protected function SetupPerson($objPerson) {
47:
48:
49: if ($objPerson) {
50: $this->objPerson = $objPerson;
51: $this->strTitleVerb = QApplication::Translate('Edit');
52: $this->blnEditMode = true;
53: } else {
54: $this->objPerson = new Person();
55: $this->strTitleVerb = QApplication::Translate('Create');
56: $this->blnEditMode = false;
57: }
58: }
59:
60: public function __construct($objParentObject, $objPerson, $strMethodCallBack, $strControlId = null) {
61:
62: try {
63: parent::__construct($objParentObject, $strControlId);
64: } catch (QCallerException $objExc) {
65: $objExc->IncrementOffset();
66: throw $objExc;
67: }
68:
69:
70:
71: $this->strMethodCallBack = $strMethodCallBack;
72:
73:
74: $this->SetupPerson($objPerson);
75:
76:
77: $this->lblId_Create();
78: $this->txtFirstName_Create();
79: $this->txtLastName_Create();
80:
81:
82: $this->lstLogin_Create();
83: $this->lstProjectsAsTeamMember_Create();
84:
85:
86: $this->btnSave_Create();
87: $this->btnCancel_Create();
88: }
89:
90:
91:
92: protected function lblId_Create() {
93: $this->lblId = new QLabel($this);
94: $this->lblId->Name = QApplication::Translate('Id');
95: if ($this->blnEditMode)
96: $this->lblId->Text = $this->objPerson->Id;
97: else
98: $this->lblId->Text = 'N/A';
99: }
100:
101:
102: protected function txtFirstName_Create() {
103: $this->txtFirstName = new QTextBox($this);
104: $this->txtFirstName->Name = QApplication::Translate('First Name');
105: $this->txtFirstName->Text = $this->objPerson->FirstName;
106: $this->txtFirstName->Required = true;
107: }
108:
109:
110: protected function txtLastName_Create() {
111: $this->txtLastName = new QTextBox($this);
112: $this->txtLastName->Name = QApplication::Translate('Last Name');
113: $this->txtLastName->Text = $this->objPerson->LastName;
114: $this->txtLastName->Required = true;
115: }
116:
117:
118: protected function lstLogin_Create() {
119: $this->lstLogin = new QListBox($this);
120: $this->lstLogin->Name = QApplication::Translate('Login');
121: $this->lstLogin->AddItem(QApplication::Translate('- Select One -'), null);
122: $objLoginArray = Login::LoadAll();
123: if ($objLoginArray) foreach ($objLoginArray as $objLogin) {
124: $objListItem = new QListItem($objLogin->__toString(), $objLogin->Id);
125: if ($objLogin->PersonId == $this->objPerson->Id)
126: $objListItem->Selected = true;
127: $this->lstLogin->AddItem($objListItem);
128: }
129:
130: if ($this->lstLogin->SelectedValue)
131: $this->lstLogin->Enabled = false;
132: }
133:
134:
135: protected function lstProjectsAsTeamMember_Create() {
136: $this->lstProjectsAsTeamMember = new QListBox($this);
137: $this->lstProjectsAsTeamMember->Name = QApplication::Translate('Projects As Team Member');
138: $this->lstProjectsAsTeamMember->SelectionMode = QSelectionMode::Multiple;
139: $objAssociatedArray = $this->objPerson->GetProjectAsTeamMemberArray();
140: $objProjectArray = Project::LoadAll();
141: if ($objProjectArray) foreach ($objProjectArray as $objProject) {
142: $objListItem = new QListItem($objProject->__toString(), $objProject->Id);
143: foreach ($objAssociatedArray as $objAssociated) {
144: if ($objAssociated->Id == $objProject->Id)
145: $objListItem->Selected = true;
146: }
147: $this->lstProjectsAsTeamMember->AddItem($objListItem);
148: }
149: }
150:
151:
152:
153: protected function btnSave_Create() {
154: $this->btnSave = new QButton($this);
155: $this->btnSave->Text = QApplication::Translate('Save');
156: $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click'));
157: $this->btnSave->PrimaryButton = true;
158: $this->btnSave->CausesValidation = true;
159: }
160:
161:
162: protected function btnCancel_Create() {
163: $this->btnCancel = new QButton($this);
164: $this->btnCancel->Text = QApplication::Translate('Cancel');
165: $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click'));
166: $this->btnCancel->CausesValidation = false;
167: }
168:
169:
170: protected function UpdatePersonFields() {
171: $this->objPerson->FirstName = $this->txtFirstName->Text;
172: $this->objPerson->LastName = $this->txtLastName->Text;
173: $this->objPerson->Login = Login::Load($this->lstLogin->SelectedValue);
174: }
175:
176: protected function lstProjectsAsTeamMember_Update() {
177: $this->objPerson->UnassociateAllProjectsAsTeamMember();
178: $objSelectedListItems = $this->lstProjectsAsTeamMember->SelectedItems;
179: if ($objSelectedListItems) foreach ($objSelectedListItems as $objListItem) {
180: $this->objPerson->AssociateProjectAsTeamMember(Project::Load($objListItem->Value));
181: }
182: }
183:
184:
185:
186: public function btnSave_Click($strFormId, $strControlId, $strParameter) {
187: $this->UpdatePersonFields();
188: $this->objPerson->Save();
189:
190: $this->lstProjectsAsTeamMember_Update();
191:
192:
193: $strMethodCallBack = $this->strMethodCallBack;
194: $this->objForm->$strMethodCallBack(true);
195: }
196:
197: public function btnCancel_Click($strFormId, $strControlId, $strParameter) {
198:
199: $strMethodCallBack = $this->strMethodCallBack;
200: $this->objForm->$strMethodCallBack(false);
201: }
202: }
203: ?>