Skip to content

Commit

Permalink
Merge pull request #28 from romcart/master
Browse files Browse the repository at this point in the history
Feature to disable controls during AJAX actions
  • Loading branch information
mikeho committed Jun 25, 2013
2 parents cba4958 + cc96d7a commit baed297
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
25 changes: 20 additions & 5 deletions includes/qcodo/_core/qform/_actions.inc.php
Expand Up @@ -105,11 +105,13 @@ class QAjaxAction extends QAction {
protected $strMethodName; protected $strMethodName;
protected $objWaitIconControl; protected $objWaitIconControl;
protected $mixCausesValidationOverride; 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->strMethodName = $strMethodName;
$this->objWaitIconControl = $objWaitIconControl; $this->objWaitIconControl = $objWaitIconControl;
$this->mixCausesValidationOverride = $mixCausesValidationOverride; $this->mixCausesValidationOverride = $mixCausesValidationOverride;
$this->mixToggleEnableControls = $mixToggleEnableControls;
} }


public function __get($strName) { public function __get($strName) {
Expand All @@ -120,6 +122,8 @@ public function __get($strName) {
return $this->objWaitIconControl; return $this->objWaitIconControl;
case 'CausesValidationOverride': case 'CausesValidationOverride':
return $this->mixCausesValidationOverride; return $this->mixCausesValidationOverride;
case 'ToggleEnableControls':
return $this->mixToggleEnableControls;
default: default:
try { try {
return parent::__get($strName); return parent::__get($strName);
Expand All @@ -139,8 +143,19 @@ public function RenderScript(QControl $objControl) {
$strWaitIconControlId = $this->objWaitIconControl->ControlId; $strWaitIconControlId = $this->objWaitIconControl->ControlId;
} }


return sprintf("qc.pA('%s', '%s', '%s', '%s', '%s');", $strToggleEnableControlIds = null;
$objControl->Form->FormId, $objControl->ControlId, get_class($this->objEvent), addslashes($objControl->ActionParameter), $strWaitIconControlId); 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);
} }
} }


Expand All @@ -151,8 +166,8 @@ public function __construct(QControl $objControl, $strMethodName, $mixCausesVali
} }


class QAjaxControlAction extends QAjaxAction { class QAjaxControlAction extends QAjaxAction {
public function __construct(QControl $objControl, $strMethodName, $objWaitIconControl = 'default', $mixCausesValidationOverride = null) { public function __construct(QControl $objControl, $strMethodName, $objWaitIconControl = 'default', $mixCausesValidationOverride = null, $mixToggleEnableControls = null) {
parent::__construct($objControl->ControlId . ':' . $strMethodName, $objWaitIconControl, $mixCausesValidationOverride); parent::__construct($objControl->ControlId . ':' . $strMethodName, $objWaitIconControl, $mixCausesValidationOverride, $mixToggleEnableControls);
} }
} }


Expand Down
24 changes: 22 additions & 2 deletions www/assets/js/_core/post.js
Expand Up @@ -65,7 +65,7 @@


qcodo.ajaxQueue = new Array(); 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 // Only add if we're not unloaded
if (!qc.unloadFlag) { if (!qc.unloadFlag) {
if (qc.beforeUnloadFlag) { if (qc.beforeUnloadFlag) {
Expand All @@ -78,7 +78,7 @@
blnQueueEmpty = true; blnQueueEmpty = true;


// Enqueue the AJAX Request // 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 the Queue was originally empty, call the Dequeue
if (blnQueueEmpty) if (blnQueueEmpty)
Expand All @@ -92,6 +92,7 @@


qcodo.objAjaxWaitIcon = null; qcodo.objAjaxWaitIcon = null;
qcodo.ajaxRequest = null; qcodo.ajaxRequest = null;
qcodo.arrToggleEnableControlIds = [];


qcodo.handleAjaxResponse = function(objEvent, objIframeResponse) { qcodo.handleAjaxResponse = function(objEvent, objIframeResponse) {
var objRequest; var objRequest;
Expand Down Expand Up @@ -172,6 +173,11 @@
if (qcodo.objAjaxWaitIcon) if (qcodo.objAjaxWaitIcon)
qcodo.objAjaxWaitIcon.style.display = 'none'; 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 there are still AjaxEvents in the queue, go ahead and process/dequeue them
if (qcodo.ajaxQueue.length > 0) if (qcodo.ajaxQueue.length > 0)
qcodo.dequeueAjaxQueue(); qcodo.dequeueAjaxQueue();
Expand All @@ -185,6 +191,7 @@
strEvent = this.ajaxQueue[0][2]; strEvent = this.ajaxQueue[0][2];
strParameter = this.ajaxQueue[0][3]; strParameter = this.ajaxQueue[0][3];
strWaitIconControlId = this.ajaxQueue[0][4]; strWaitIconControlId = this.ajaxQueue[0][4];
strToggleEnableControlIds = this.ajaxQueue[0][5];


// Display WaitIcon (if applicable) // Display WaitIcon (if applicable)
if (strWaitIconControlId) { if (strWaitIconControlId) {
Expand All @@ -193,6 +200,19 @@
this.objAjaxWaitIcon.style.display = 'inline'; 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); var objForm = document.getElementById(strForm);
objForm.Qform__FormControl.value = strControl; objForm.Qform__FormControl.value = strControl;
objForm.Qform__FormEvent.value = strEvent; objForm.Qform__FormEvent.value = strEvent;
Expand Down

0 comments on commit baed297

Please sign in to comment.