From 830b3e83d5b1f6997cf283c7dc9f4f857f5791d4 Mon Sep 17 00:00:00 2001 From: kurund Date: Fri, 8 Aug 2014 19:31:58 +0530 Subject: [PATCH] form rule fixes and js cleanup --- CRM/Contribute/Form/Task/Invoice.php | 41 +++++---- CRM/Contribute/Form/Task/PDF.php | 4 +- .../CRM/Contribute/Form/Task/Invoice.tpl | 83 ++++++++++--------- 3 files changed, 70 insertions(+), 58 deletions(-) diff --git a/CRM/Contribute/Form/Task/Invoice.php b/CRM/Contribute/Form/Task/Invoice.php index 757165e076..b7f9da96d8 100644 --- a/CRM/Contribute/Form/Task/Invoice.php +++ b/CRM/Contribute/Form/Task/Invoice.php @@ -66,6 +66,11 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task { */ public $_invoiceTemplate; + /** + * selected output + */ + public $_selectedOutput; + /** * build all the data structures needed to build the form * @@ -119,7 +124,11 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task { ); CRM_Utils_System::appendBreadCrumb($breadCrumb); - if (in_array("email", $this->urlPath)) { + + $this->_selectedOutput = CRM_Utils_Request::retrieve('select', 'String', $this); + $this->assign('selectedOutput', $this->_selectedOutput); + + if ($this->_selectedOutput == 'email') { CRM_Utils_System::setTitle(ts('Email Invoice')); } else { @@ -163,11 +172,17 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task { $fromEmailAddress[$key] = htmlspecialchars($fromEmailAddress[$key]); } $fromEmail = CRM_Utils_Array::crmArrayMerge($emails, $fromEmailAddress); - - $this->addElement('radio', 'output', NULL, ts('Email Invoice'), 'email_invoice'); - $this->addElement('radio', 'output', NULL, ts('PDF Invoice'), 'pdf_invoice'); $this->add('select', 'from_email_address', ts('From Email Address'), array('' => '- select -') + $fromEmail); - $this->addFormRule(array('CRM_Contribute_Form_Task_Invoice', 'formRule')); + if ($this->_selectedOutput != 'email') { + $this->addElement('radio', 'output', NULL, ts('Email Invoice'), 'email_invoice'); + $this->addElement('radio', 'output', NULL, ts('PDF Invoice'), 'pdf_invoice'); + $this->addRule('output', ts('Selection required'), 'required'); + $this->addFormRule(array('CRM_Contribute_Form_Task_Invoice', 'formRule')); + } + else { + $this->addRule('from_email_address', ts('From Email Address is required'), 'required'); + } + $this->addWysiwyg('email_comment', ts('If you would like to add personal message to email please add it here. (If sending to more then one receipient the same message will be sent to each contact.)'), array( 'rows' => 2, 'cols' => 40 @@ -216,19 +231,11 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task { */ static function formRule($values) { $errors = array(); - if (!$values['from_email_address']) { - if (in_array("Email Invoice", $values)) { - $errors['from_email_address'] = ts("From Email Address is required"); - } - else { - if (in_array("email_invoice", $values)) { - $errors['from_email_address'] = ts("From Email Address is required"); - } - else { - $errors['output'] = ts("Selection required"); - } - } + + if ($values['output'] == 'email_invoice' && empty($values['from_email_address'])) { + $errors['from_email_address'] = ts("From Email Address is required"); } + return $errors; } diff --git a/CRM/Contribute/Form/Task/PDF.php b/CRM/Contribute/Form/Task/PDF.php index 33f6eafac6..e3cd688a7d 100644 --- a/CRM/Contribute/Form/Task/PDF.php +++ b/CRM/Contribute/Form/Task/PDF.php @@ -256,7 +256,8 @@ AND {$this->_componentClause}"; $pdfElements['params'] = $params; $pdfElements['createPdf'] = FALSE; - if ($pdfElements['params']['output'] == "pdf_invoice" || $pdfElements['params']['output'] == "pdf_receipt") { + if (!empty($pdfElements['params']['output']) && + ($pdfElements['params']['output'] == "pdf_invoice" || $pdfElements['params']['output'] == "pdf_receipt")) { $pdfElements['createPdf'] = TRUE; } @@ -271,6 +272,7 @@ AND {$this->_componentClause}"; list($contactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, $returnProperties, FALSE, FALSE); $pdfElements['suppressedEmails'] = 0; + $suppressedEmails = 0; foreach ($contactDetails as $id => $values) { if (empty($values['email']) || !empty($values['do_not_email']) || CRM_Utils_Array::value('is_deceased', $values) || !empty($values['on_hold'])) { diff --git a/templates/CRM/Contribute/Form/Task/Invoice.tpl b/templates/CRM/Contribute/Form/Task/Invoice.tpl index 72222ddefd..cfb5fe470a 100644 --- a/templates/CRM/Contribute/Form/Task/Invoice.tpl +++ b/templates/CRM/Contribute/Form/Task/Invoice.tpl @@ -25,65 +25,68 @@ *}
- {include file="CRM/Contribute/Form/Task.tpl"} + {include file="CRM/Contribute/Form/Task.tpl"}
-{if $smarty.get.select != 'email' || $smarty.get.q != 'civicrm/contribute/invoice/email'} -
- {ts}You may choose to email invoice to contributors OR download a PDF file containing one invoice per page to your local computer by clicking Process Invoice(s). Your browser may display the file for you automatically, or you may need to open it for printing using any PDF reader (such as Adobe® Reader).{/ts} -
+{if $selectedOutput ne 'email'} +
+ {ts}You may choose to email invoice to contributors OR download a PDF file containing one invoice per page to your local computer by clicking + Process Invoice(s) + . Your browser may display the file for you automatically, or you may need to open it for printing using any PDF reader (such as Adobe® Reader).{/ts} +
{/if} - - {if $smarty.get.select == 'email' || $smarty.get.q == 'civicrm/contribute/invoice/email'} - {literal} - - {/literal} - {/if} - - {literal} - - {/literal} - - {if $smarty.get.select != 'email' && $smarty.get.q != 'civicrm/contribute/invoice/email'} +
+ {if $selectedOutput ne 'email'} {/if} - + - + - {if $smarty.get.select != 'email' && $smarty.get.q != 'civicrm/contribute/invoice/email'} + {if $selectedOutput ne 'email'} {/if} - +
{$form.output.email_invoice.html}
{$form.output.pdf_invoice.html}
{$form.pdf_format_id.html} {$form.pdf_format_id.label}
- {$form.buttons.html} + {$form.buttons.html}
+ + + + -- 2.25.1