1: <?php
2: require_once('../qcubed.inc.php');
3:
4: class SelectableLabel extends QLabel {
5:
6:
7: public $Selected;
8:
9: }
10:
11: class ExampleForm extends QForm {
12:
13: protected $lblArray;
14: protected $txtArray;
15:
16: protected function Form_Create() {
17: for ($intIndex = 0; $intIndex < 10; $intIndex++) {
18:
19: $this->lblArray[$intIndex] = new SelectableLabel($this);
20: $this->lblArray[$intIndex]->Text = 'This is a Test for Item #' . ($intIndex + 1);
21: $this->lblArray[$intIndex]->CssClass = 'renamer_item';
22: $this->lblArray[$intIndex]->ActionParameter = $intIndex;
23: $this->lblArray[$intIndex]->AddAction(new QClickEvent(), new QAjaxAction('lblArray_Click'));
24:
25:
26: $this->txtArray[$intIndex] = new QTextBox($this);
27: $this->txtArray[$intIndex]->Visible = false;
28: $this->txtArray[$intIndex]->ActionParameter = $intIndex;
29:
30:
31: $this->txtArray[$intIndex]->AddAction(new QBlurEvent(), new QAjaxAction('TextItem_Save'));
32: $this->txtArray[$intIndex]->AddAction(new QEnterKeyEvent(), new QAjaxAction('TextItem_Save'));
33: $this->txtArray[$intIndex]->AddAction(new QEnterKeyEvent(), new QTerminateAction());
34:
35:
36: $this->txtArray[$intIndex]->AddAction(new QEscapeKeyEvent(), new QAjaxAction('TextItem_Cancel'));
37: $this->txtArray[$intIndex]->AddAction(new QEscapeKeyEvent(), new QTerminateAction());
38: }
39: }
40:
41: protected function lblArray_Click($strFormId, $strControlId, $strParameter) {
42:
43: if ($this->lblArray[$strParameter]->Selected) {
44:
45: $this->lblArray[$strParameter]->Visible = false;
46: $this->txtArray[$strParameter]->Visible = true;
47: $this->txtArray[$strParameter]->Text = html_entity_decode($this->lblArray[$strParameter]->Text, ENT_COMPAT, QApplication::$EncodingType);
48: QApplication::ExecuteControlCommand($this->txtArray[$strParameter]->ControlId, 'select');
49: QApplication::ExecuteControlCommand($this->txtArray[$strParameter]->ControlId, 'focus');
50: } else {
51:
52:
53: for ($intIndex = 0; $intIndex < 10; $intIndex++)
54: if ($this->lblArray[$intIndex]->Selected) {
55: $this->lblArray[$intIndex]->Selected = false;
56: $this->lblArray[$intIndex]->CssClass = 'renamer_item';
57: }
58:
59:
60: $this->lblArray[$strParameter]->Selected = true;
61: $this->lblArray[$strParameter]->CssClass = 'renamer_item renamer_item_selected';
62: }
63: }
64:
65: protected function TextItem_Save($strFormId, $strControlId, $strParameter) {
66: $strValue = trim($this->txtArray[$strParameter]->Text);
67:
68: if (strlen($strValue)) {
69:
70: $this->lblArray[$strParameter]->Text = $strValue;
71: }
72:
73:
74: $this->lblArray[$strParameter]->Visible = true;
75: $this->txtArray[$strParameter]->Visible = false;
76: $this->lblArray[$strParameter]->Selected = false;
77: $this->lblArray[$strParameter]->CssClass = 'renamer_item';
78: }
79:
80: protected function TextItem_Cancel($strFormId, $strControlId, $strParameter) {
81:
82: $this->lblArray[$strParameter]->Visible = true;
83: $this->txtArray[$strParameter]->Visible = false;
84: $this->lblArray[$strParameter]->Selected = false;
85: $this->lblArray[$strParameter]->CssClass = 'renamer_item';
86: }
87:
88: }
89:
90: ExampleForm::Run('ExampleForm');
91: ?>