diff --git a/CRM/Contact/Form/Task/EmailCommon.php b/CRM/Contact/Form/Task/EmailCommon.php index ca503ddb90609cd4442b8608306e961b4ba4f4dd..caf285c01d1b3512235d4b170bafc9d469d25e68 100644 --- a/CRM/Contact/Form/Task/EmailCommon.php +++ b/CRM/Contact/Form/Task/EmailCommon.php @@ -121,6 +121,8 @@ class CRM_Contact_Form_Task_EmailCommon { * * @access public * + * @param $form + * * @return void */ static function buildQuickForm(&$form) { @@ -270,6 +272,7 @@ class CRM_Contact_Form_Task_EmailCommon { } $form->addFormRule(array('CRM_Contact_Form_Task_EmailCommon', 'formRule'), $form); + CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Core/Form.js'); CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Contact/Form/Task/EmailCommon.js'); } @@ -307,6 +310,8 @@ class CRM_Contact_Form_Task_EmailCommon { * * @access public * + * @param $form + * * @return None */ static function postProcess(&$form) { diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 33e67ccccf438117e577b5627c5e2527facaf977..8e7ee1e63d1cec629b493a16dbc051ecd20523a2 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -494,7 +494,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr 'name' => $contribButton, 'spacing' => ' ', 'isDefault' => TRUE, - 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"), ), array( 'type' => 'back', @@ -557,6 +556,8 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $this->setDefaults($defaults); $this->freeze(); + + parent::buildQuickForm(); } /** diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 358a90de472e636c6d77f5795d0f043352496c86..190ccdc8f31164afb70cce6c6d5d3e4702fd2644 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -556,6 +556,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this); + parent::buildQuickForm(); } /** diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 5167ab339dbf02bae15e1837e61ee0d10c0ee761..e81c6f42baddf212259b2881d3ad345d75db534e 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -285,7 +285,14 @@ class CRM_Core_Form extends HTML_QuickForm_Page { * @return void * */ - function buildQuickForm() {} + function buildQuickForm() { + // @todo less cautious approach would be to add this to addButtons. + // it would be good to make this switch at the early stage of a release cycle. + // @ the moment of the 106 uses of parent::buildQuickForm only a handle are direct descendents + // of this class - including the contribution forms per CRM-13397 & the (tested) sms provider form. + //(I checked maybe another 20 directly that weren't & was also able to rule out about 40 more by virtue of common patterns + CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Core/Form.js'); + } /** * This virtual function is used to set the default values of @@ -398,10 +405,10 @@ class CRM_Core_Form extends HTML_QuickForm_Page { $js = CRM_Utils_Array::value('js', $button); $isDefault = CRM_Utils_Array::value('isDefault', $button, FALSE); if ($isDefault) { - $attrs = array('class' => 'form-submit default'); + $attrs = array('class' => 'form-submit default crm-form-button-' . $button['type']); } else { - $attrs = array('class' => 'form-submit'); + $attrs = array('class' => 'form-submit crm-form-button-' . $button['type']); } if ($js) { diff --git a/js/Common.js b/js/Common.js index efd5140b2c1f6b796e66bd8d55adb14b394ade16..8770917b036466d8502b10a72772dee06021924f 100644 --- a/js/Common.js +++ b/js/Common.js @@ -396,8 +396,13 @@ function unselectRadio(fieldName, form) { * @return null */ var submitcount = 0; -/* Changes button label on submit, and disables button after submit for newer browsers. - Puts up alert for older browsers. */ +/** + * @deprecated + * Changes button label on submit, and disables button after submit for newer browsers. + * Puts up alert for older browsers. + * @todo CRM-13397 replaces this with an alternate (jquery) mechanism - to use the jquery mechanism add + * parent::buildQuickForm to make buttons 'protected' + * */ function submitOnce(obj, formId, procText) { // if named button clicked, change text if (obj.value != null) { diff --git a/templates/CRM/Contact/Form/Task/EmailCommon.js b/templates/CRM/Contact/Form/Task/EmailCommon.js index bb7610e4c909b21dd44172ace5c3e43993d660e6..1c4dfa0f0235645f8ad269591f1eae9cf09a6c4f 100644 --- a/templates/CRM/Contact/Form/Task/EmailCommon.js +++ b/templates/CRM/Contact/Form/Task/EmailCommon.js @@ -2,14 +2,4 @@ cj(function ($) { //do not copy & paste this - find a way to generalise it 'use strict'; $().crmAccordions(); - // NOTE: Might be safer to say $('[name=_qf_Email_upload]') - $('.form-submit').not('.cancel').on("click", function() { - $('.form-submit').not('.cancel').attr({value: ts('Processing')}); - // CRM-13449 : setting a 0 ms timeout is needed - // for some browsers like chrome. Used for purpose of - // submit the form and stop accidental multiple clicks - setTimeout(function(){ - $('.form-submit').not('.cancel').attr({disabled: 'disabled'}); - }, 0); - }); }); diff --git a/templates/CRM/Core/Form.js b/templates/CRM/Core/Form.js new file mode 100644 index 0000000000000000000000000000000000000000..4b27202a6e5f900b2e27961bce5d5d1030a0da09 --- /dev/null +++ b/templates/CRM/Core/Form.js @@ -0,0 +1,15 @@ +cj(function ($) { + 'use strict'; + $('.form-submit').on("click", function() { + $('.form-submit').attr({value: ts('Processing'), disabled : 'disabled'}); + $('.crm-form-button-back ').closest('span').hide(); + $('.crm-form-button-cancel').closest('span').hide(); + // CRM-13449 : setting a 0 ms timeout is needed + // for some browsers like chrome. Used for purpose of + // submit the form and stop accidental multiple clicks + setTimeout(function(){ + $('.form-submit').not('.cancel').attr({disabled: 'disabled'}); + }, 0); + }); +}); +