Permalink
Browse files

Merge pull request #28 from romcart/master

Feature to disable controls during AJAX actions
  • Loading branch information...
2 parents cba4958 + cc96d7a commit baed297c988d3dc0c26814100a2ae4d09bdae525 @mikeho mikeho committed Jun 25, 2013
Showing with 42 additions and 7 deletions.
  1. +20 −5 includes/qcodo/_core/qform/_actions.inc.php
  2. +22 −2 www/assets/js/_core/post.js
@@ -105,11 +105,13 @@ class QAjaxAction extends QAction {
protected $strMethodName;
protected $objWaitIconControl;
protected $mixCausesValidationOverride;
+ protected $mixToggleEnableControls;
- public function __construct($strMethodName = null, $objWaitIconControl = 'default', $mixCausesValidationOverride = null) {
+ public function __construct($strMethodName = null, $objWaitIconControl = 'default', $mixCausesValidationOverride = null, $mixToggleEnableControls = null) {
$this->strMethodName = $strMethodName;
$this->objWaitIconControl = $objWaitIconControl;
$this->mixCausesValidationOverride = $mixCausesValidationOverride;
+ $this->mixToggleEnableControls = $mixToggleEnableControls;
}
public function __get($strName) {
@@ -120,6 +122,8 @@ public function __get($strName) {
return $this->objWaitIconControl;
case 'CausesValidationOverride':
return $this->mixCausesValidationOverride;
+ case 'ToggleEnableControls':
+ return $this->mixToggleEnableControls;
default:
try {
return parent::__get($strName);
@@ -139,8 +143,19 @@ public function RenderScript(QControl $objControl) {
$strWaitIconControlId = $this->objWaitIconControl->ControlId;
}
- return sprintf("qc.pA('%s', '%s', '%s', '%s', '%s');",
- $objControl->Form->FormId, $objControl->ControlId, get_class($this->objEvent), addslashes($objControl->ActionParameter), $strWaitIconControlId);
+ $strToggleEnableControlIds = null;
+ if ($this->mixToggleEnableControls instanceof QControl) {
+ $strToggleEnableControlIds = $this->mixToggleEnableControls->ControlId;
+ } else if (is_array($this->mixToggleEnableControls)) {
+ $arrToggleEnableControlIds = array();
+ foreach ($this->mixToggleEnableControls as $objToggleEnableControl) {
+ $arrToggleEnableControlIds[] = $objToggleEnableControl->ControlId;
+ }
+ $strToggleEnableControlIds = implode(',', $arrToggleEnableControlIds);
+ }
+
+ return sprintf("qc.pA('%s', '%s', '%s', '%s', '%s', '%s');",
+ $objControl->Form->FormId, $objControl->ControlId, get_class($this->objEvent), addslashes($objControl->ActionParameter), $strWaitIconControlId, $strToggleEnableControlIds);
}
}
@@ -151,8 +166,8 @@ public function __construct(QControl $objControl, $strMethodName, $mixCausesVali
}
class QAjaxControlAction extends QAjaxAction {
- public function __construct(QControl $objControl, $strMethodName, $objWaitIconControl = 'default', $mixCausesValidationOverride = null) {
- parent::__construct($objControl->ControlId . ':' . $strMethodName, $objWaitIconControl, $mixCausesValidationOverride);
+ public function __construct(QControl $objControl, $strMethodName, $objWaitIconControl = 'default', $mixCausesValidationOverride = null, $mixToggleEnableControls = null) {
+ parent::__construct($objControl->ControlId . ':' . $strMethodName, $objWaitIconControl, $mixCausesValidationOverride, $mixToggleEnableControls);
}
}
@@ -65,7 +65,7 @@
qcodo.ajaxQueue = new Array();
- qcodo.postAjax = function(strForm, strControl, strEvent, strParameter, strWaitIconControlId) {
+ qcodo.postAjax = function(strForm, strControl, strEvent, strParameter, strWaitIconControlId, strToggleEnableControlIds) {
// Only add if we're not unloaded
if (!qc.unloadFlag) {
if (qc.beforeUnloadFlag) {
@@ -78,7 +78,7 @@
blnQueueEmpty = true;
// Enqueue the AJAX Request
- qcodo.ajaxQueue.push(new Array(strForm, strControl, strEvent, strParameter, strWaitIconControlId));
+ qcodo.ajaxQueue.push(new Array(strForm, strControl, strEvent, strParameter, strWaitIconControlId, strToggleEnableControlIds));
// If the Queue was originally empty, call the Dequeue
if (blnQueueEmpty)
@@ -92,6 +92,7 @@
qcodo.objAjaxWaitIcon = null;
qcodo.ajaxRequest = null;
+ qcodo.arrToggleEnableControlIds = [];
qcodo.handleAjaxResponse = function(objEvent, objIframeResponse) {
var objRequest;
@@ -172,6 +173,11 @@
if (qcodo.objAjaxWaitIcon)
qcodo.objAjaxWaitIcon.style.display = 'none';
+ // Toggle enabled/disabled controls (if applicable)
+ for (var i = 0; i < qcodo.arrToggleEnableControlIds.length; i++) {
+ qcodo.getWrapper(qcodo.arrToggleEnableControlIds[i]).toggleEnabled();
+ }
+
// If there are still AjaxEvents in the queue, go ahead and process/dequeue them
if (qcodo.ajaxQueue.length > 0)
qcodo.dequeueAjaxQueue();
@@ -185,6 +191,7 @@
strEvent = this.ajaxQueue[0][2];
strParameter = this.ajaxQueue[0][3];
strWaitIconControlId = this.ajaxQueue[0][4];
+ strToggleEnableControlIds = this.ajaxQueue[0][5];
// Display WaitIcon (if applicable)
if (strWaitIconControlId) {
@@ -193,6 +200,19 @@
this.objAjaxWaitIcon.style.display = 'inline';
};
+ // Toggle enabled/disabled controls (if applicable)
+ if (strToggleEnableControlIds) {
+ this.arrToggleEnableControlIds = [];
+ var arrToggleEnableControlIds = strToggleEnableControlIds.split(',');
+ for (var i = 0; i < arrToggleEnableControlIds.length; i++) {
+ var objToggleEnableControl = document.getElementById(arrToggleEnableControlIds[i]);
+ if (objToggleEnableControl) {
+ this.arrToggleEnableControlIds.push(arrToggleEnableControlIds[i]);
+ this.getWrapper(arrToggleEnableControlIds[i]).toggleEnabled();
+ }
+ }
+ };
+
var objForm = document.getElementById(strForm);
objForm.Qform__FormControl.value = strControl;
objForm.Qform__FormEvent.value = strEvent;

0 comments on commit baed297

Please sign in to comment.