I received a question for a tighter example of this... so here it is, which is an update of the default sample.php that comes with Qcodo:
<?php
/**
* This is a standard, sample QForm which you can use as a starting
* point to build any QForm page that you wish.
*/
// Include prepend.inc to load Qcodo
require(dirname(__FILE__) . '/../includes/prepend.inc.php');
class SampleForm extends QForm {
protected $lblMessage;
protected $btnButton;
protected $pxyRefresh;
protected function Form_Create() {
$this->lblMessage = new QLabel($this);
$this->lblMessage->Text = 'Click the button to change my message.';
$this->btnButton = new QButton($this);
$this->btnButton->Text = 'Click Me';
$this->btnButton->AddAction(new QClickEvent(), new QAjaxAction('btnButton_Click'));
$this->pxyRefresh = new QControlProxy($this);
$this->pxyRefresh->AddAction(new QClickEvent(), new QAjaxAction('pxyRefresh_Click'));
// Set to "Refresh" in 1000 ms
QApplication::ExecuteJavaScript(sprintf('qcodo.setTimeout("%s", "qc.pA(\'%s\', \'%s\', \'QClickEvent\', null, null);", %s);',
$this->pxyRefresh->ControlId,
$this->pxyRefresh->Form->FormId,
$this->pxyRefresh->ControlId,
1000));
}
protected function pxyRefresh_Click($strFormId, $strControlId, $strParameter) {
$this->lblMessage->Text = QDateTime::Now()->__toString(QDateTime::FormatDisplayDateTimeFull);
// Set to "Refresh" in 1000 ms
QApplication::ExecuteJavaScript(sprintf('qcodo.setTimeout("%s", "qc.pA(\'%s\', \'%s\', \'QClickEvent\', null, null);", %s);',
$this->pxyRefresh->ControlId,
$this->pxyRefresh->Form->FormId,
$this->pxyRefresh->ControlId,
1000));
}
protected function btnButton_Click($strFormId, $strControlId, $strParameter) {
$this->lblMessage->Text = 'Hello, World!';
}
}
SampleForm::Run('SampleForm');
?>
I'm still trying to figure out the right place to hook this in -- this example is using QControlProxy, but I wonder if it makes sense to incorporate this into QForm itself.
Also, it'd be nice to get this integrated more tightly with the URL Hashing processor (which also uses timers).
Regardless, for those that can't wait, this method/example using QControlProxy will work and will work regardless of any future solution (which should hopefully come about shortly...)