1: <?php
2: require_once('../qcubed.inc.php');
3:
4: class Order {
5: public $Id;
6: public $Items;
7: }
8:
9: class ExampleForm extends QForm {
10:
11: protected $dtgOrders;
12: public $objOrdersArray = array();
13:
14: protected $intOrderCnt = 0;
15:
16: protected $btnServerAction;
17: protected $btnRestartOnServerAction;
18:
19: protected $ctlTimer;
20:
21: protected $btnStart;
22: protected $btnStop;
23:
24: protected $objRandomProductsArray = array();
25:
26: protected function Form_Create() {
27:
28: $this->objRandomProductsArray[0] = '1x Sandwich, 2x Coke, 1x Big Pekahuna Burger';
29: $this->objRandomProductsArray[1] = '2x French fries, 3x Burritos, 1x Hot Dog';
30: $this->objRandomProductsArray[2] = '1x Steak - Lone Star, 5x Wiener Schnitzel';
31: $this->objRandomProductsArray[3] = '3x Socks, 3x Shorts';
32:
33:
34: $this->dtgOrders = new QDataGrid($this);
35: $this->dtgOrders->UseAjax = true;
36:
37:
38: $this->btnServerAction = new QButton($this);
39: $this->btnServerAction->SetCustomStyle('float','right');
40:
41:
42: $this->btnRestartOnServerAction = new QButton($this);
43: $this->btnStop = new QButton($this);
44: $this->btnStart = new QButton($this);
45:
46:
47: $this->ctlTimer = new QJsTimer($this,3000,true,true);
48:
49:
50: $this->dtgOrders->CreatePropertyColumn('Order-Id', 'Id');
51: $this->dtgOrders->CreatePropertyColumn('Products', 'Items');
52: $col = $this->dtgOrders->CreateCallableColumn('Remove', [$this, 'renderRemoveButton']);
53: $col->HtmlEntities = false;
54: $this->dtgOrders->SetDataBinder('dtgOrders_Bind');
55:
56: $this->btnServerAction->AddAction(new QClickEvent(),new QServerAction('OnServerAction'));
57: $this->btnServerAction->Text = "Server Action";
58:
59: $this->btnRestartOnServerAction->AddAction(new QClickEvent(),new QAjaxAction('OnToggleRestartOnServerAction'));
60: $this->btnRestartOnServerAction->Text = "Restart On Server Action [off]";
61:
62:
63: $this->ctlTimer->AddAction(new QTimerExpiredEvent(), new QAjaxAction('OnUpdateDtg'));
64:
65: $this->btnStart->AddAction(new QClickEvent(),new QAjaxControlAction($this->ctlTimer,'Start'));
66: $this->btnStop->AddAction(new QClickEvent(),new QAjaxControlAction($this->ctlTimer,'Stop'));
67: $this->btnStart->Text = 'Start';
68: $this->btnStop->Text = 'Stop';
69:
70: }
71:
72:
73: public function OnUpdateDtg() {
74:
75: $randProdNum = rand(0,3);
76: $this->intOrderCnt++;
77:
78:
79:
80: if ($this->intOrderCnt > 10) {
81: $this->intOrderCnt = 1;
82: $this->objOrdersArray = array();
83: }
84: $order = new Order();
85: $order->Id = $this->intOrderCnt;
86: $order->Items = $this->objRandomProductsArray[$randProdNum];
87: $this->objOrdersArray[$this->intOrderCnt] = $order;
88: $this->dtgOrders->MarkAsModified();
89: }
90:
91: public function OnToggleRestartOnServerAction() {
92: $blnRestart = $this->ctlTimer->RestartOnServerAction;
93: if($blnRestart)
94: $this->btnRestartOnServerAction->Text = "Restart On Server Action [off]";
95: else
96: $this->btnRestartOnServerAction->Text = "Restart On Server Action [on]";
97:
98: $this->ctlTimer->RestartOnServerAction = !$blnRestart;
99: }
100:
101: public function OnServerAction() {
102:
103: }
104:
105: public function renderRemoveButton($item) {
106: $objControlId = "removeButton" . $item->Id;
107: $objControl = $this->GetControl($objControlId);
108: if (!$objControl) {
109: $objControl = new QJqButton($this->dtgOrders, $objControlId);
110: $objControl->Text = true;
111: $objControl->ActionParameter = $item->Id;
112: $objControl->AddAction(new QClickEvent(), new QAjaxAction("removeButton_Click"));
113: }
114:
115: $objControl->Label = "Remove";
116:
117:
118:
119: return $objControl->Render(false);
120: }
121:
122:
123: public function removeButton_Click($strFormId, $strControlId, $strParameter) {
124: unset($this->objOrdersArray[$strParameter]);
125: $this->dtgOrders->MarkAsModified();
126: }
127:
128: protected function dtgOrders_Bind() {
129:
130: $this->dtgOrders->DataSource = $this->objOrdersArray;
131: }
132: }
133:
134: ExampleForm::Run('ExampleForm');
135: ?>
136: