1: <?php
2: class ProjectEditPanel extends QPanel {
3: // Child Controls must be Publically Accessible so that they can be rendered in the template
4: // Typically, you would want to do this by having public __getters for each control
5: // But for simplicity of this demo, we'll simply make the child controls public, themselves.
6: public $txtName;
7: public $btnSave;
8: public $btnCancel;
9:
10: // The Local Project object which this panel represents
11: protected $objProject;
12:
13: // The Reference to the Main Form's "Method Callback" so that the form can perform additional
14: // tasks after save or cancel has been clicked
15: protected $strMethodCallBack;
16:
17: // Specify the Template File for this custom QPanel
18: protected $strTemplate = 'ProjectEditPanel.tpl.php';
19:
20: // Customize the Look/Feel
21: protected $strPadding = '10px';
22: protected $strBackColor = '#fefece';
23:
24: // We Create a new __constructor that takes in the Project we are "viewing"
25: // The functionality of __construct in a custom QPanel is similar to the QForm's Form_Create() functionality
26: public function __construct($objParentObject, $objProject, $strMethodCallBack, $strControlId = null) {
27: // First, let's call the Parent's __constructor
28: try {
29: parent::__construct($objParentObject, $strControlId);
30: } catch (QCallerException $objExc) {
31: $objExc->IncrementOffset();
32: throw $objExc;
33: }
34:
35: // Next, we set the local project object
36: $this->objProject = $objProject;
37:
38: // Let's record the reference to the form's MethodCallBack
39: // See note in ProjectViewPanel for more on this.
40: $this->strMethodCallBack = $strMethodCallBack;
41:
42: // Let's set up the other local child control
43: // Notice that we define the child controls' parents to be "this", which is this ProjectEditPanel object.
44: $this->txtName = new QTextBox($this, 'txtProjectName');
45: $this->txtName->Text = $objProject->Name;
46: $this->txtName->Name = 'Project Name';
47: $this->txtName->Required = true;
48: $this->txtName->CausesValidation = true;
49:
50: // We need to add some Enter and Esc key Events on the Textbox
51: $this->txtName->AddAction(new QEnterKeyEvent(), new QAjaxControlAction($this, 'btnSave_Click'));
52: $this->txtName->AddAction(new QEnterKeyEvent(), new QTerminateAction());
53: $this->txtName->AddAction(new QEscapeKeyEvent(), new QAjaxControlAction($this, 'btnCancel_Click'));
54: $this->txtName->AddAction(new QEscapeKeyEvent(), new QTerminateAction());
55:
56: $this->btnSave = new QButton($this);
57: $this->btnSave->Text = 'Save';
58: $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click'));
59: $this->btnSave->CausesValidation = true;
60:
61: $this->btnCancel = new QButton($this);
62: $this->btnCancel->Text = 'Cancel';
63: $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click'));
64: }
65:
66: // Because we don't need any Form_PreRender type of functionality, we do not override GetControlHtml()
67: // public function GetControlHtml() {}
68:
69: // Event Handlers Here
70: public function btnSave_Click($strFormId, $strControlId, $strParameter) {
71: // Go ahead and update the project's name
72: $this->objProject->Name = $this->txtName->Text;
73: $this->objProject->Save();
74:
75: // And call the Form's Method CallBack, passing in "true" to state that we've made an update
76: $strMethodCallBack = $this->strMethodCallBack;
77: $this->objForm->$strMethodCallBack(true);
78: }
79:
80: public function btnCancel_Click($strFormId, $strControlId, $strParameter) {
81: // Call the Form's Method CallBack, passing in "false" to state that we've made no changes
82: $strMethodCallBack = $this->strMethodCallBack;
83: $this->objForm->$strMethodCallBack(false);
84: }
85: }