From 229b180c6e09a43357bf7b877890b22b3d042190 Mon Sep 17 00:00:00 2001 From: yashodha Date: Sat, 13 May 2017 09:38:08 +0530 Subject: [PATCH] CRM-20552 - code cleanup --- CRM/Contact/Form/Task/AddToHousehold.php | 50 +------- CRM/Contact/Form/Task/AddToIndividual.php | 52 +------- CRM/Contact/Form/Task/AddToOrganization.php | 53 +-------- CRM/Contact/Form/Task/AddToParentClass.php | 52 ++++++++ .../CRM/Contact/Form/Task/AddToHousehold.tpl | 84 +------------ .../CRM/Contact/Form/Task/AddToIndividual.tpl | 84 +------------ .../Contact/Form/Task/AddToOrganization.tpl | 85 +------------- .../Contact/Form/Task/AddToParentClass.tpl | 111 ++++++++++++++++++ 8 files changed, 175 insertions(+), 396 deletions(-) create mode 100644 templates/CRM/Contact/Form/Task/AddToParentClass.tpl diff --git a/CRM/Contact/Form/Task/AddToHousehold.php b/CRM/Contact/Form/Task/AddToHousehold.php index 72ab77fb7f..8a46908383 100644 --- a/CRM/Contact/Form/Task/AddToHousehold.php +++ b/CRM/Contact/Form/Task/AddToHousehold.php @@ -34,53 +34,9 @@ class CRM_Contact_Form_Task_AddToHousehold extends CRM_Contact_Form_Task_AddToPa * Build the form object. */ public function buildQuickForm() { - - CRM_Utils_System::setTitle(ts('Add Members to Household')); - $this->addElement('text', 'name', ts('Find Target Household')); - - $this->add('select', 'relationship_type_id', ts('Relationship Type'), - array( - '' => ts('- select -'), - ) + - CRM_Contact_BAO_Relationship::getRelationType("Household"), TRUE - ); - - $searchRows = $this->get('searchRows'); - $searchCount = $this->get('searchCount'); - if ($searchRows) { - $checkBoxes = array(); - $checkFlag = 0; - foreach ($searchRows as $id => $row) { - if (!$checkFlag) { - $checkFlag = $id; - } - $checkBoxes[$id] = $this->createElement('radio', NULL, NULL, NULL, $id); - } - $this->addGroup($checkBoxes, 'contact_check'); - if ($checkFlag) { - $checkBoxes[$checkFlag]->setChecked(TRUE); - } - $this->assign('searchRows', $searchRows); - } - - $this->assign('searchCount', $searchCount); - $this->assign('searchDone', $this->get('searchDone')); - $this->assign('contact_type_display', ts('Household')); - $this->addElement('submit', $this->getButtonName('refresh'), ts('Search'), array('class' => 'crm-form-submit')); - $this->addElement('submit', $this->getButtonName('cancel'), ts('Cancel'), array('class' => 'crm-form-submit')); - - $this->addButtons(array( - array( - 'type' => 'next', - 'name' => ts('Add to Household'), - 'isDefault' => TRUE, - ), - array( - 'type' => 'cancel', - 'name' => ts('Cancel'), - ), - ) - ); + $this->set('contactType', 'Household'); + $this->assign('contactType', 'Household'); + parent::buildQuickForm(); } /** diff --git a/CRM/Contact/Form/Task/AddToIndividual.php b/CRM/Contact/Form/Task/AddToIndividual.php index df8da26684..c008d6fb7d 100644 --- a/CRM/Contact/Form/Task/AddToIndividual.php +++ b/CRM/Contact/Form/Task/AddToIndividual.php @@ -40,55 +40,9 @@ class CRM_Contact_Form_Task_AddToIndividual extends CRM_Contact_Form_Task_AddToP * Build the form object. */ public function buildQuickForm() { - CRM_Utils_System::setTitle(ts('Add Contacts to Individual')); - $this->addElement('text', 'name', ts('Find Target Individual')); - - $this->add('select', - 'relationship_type_id', - ts('Relationship Type'), - array( - '' => ts('- select -'), - ) + - CRM_Contact_BAO_Relationship::getRelationType("Individual"), TRUE - ); - - $searchRows = $this->get('searchRows'); - $searchCount = $this->get('searchCount'); - if ($searchRows) { - $checkBoxes = array(); - $chekFlag = 0; - foreach ($searchRows as $id => $row) { - if (!$chekFlag) { - $chekFlag = $id; - } - - $checkBoxes[$id] = $this->createElement('radio', NULL, NULL, NULL, $id); - } - - $this->addGroup($checkBoxes, 'contact_check'); - if ($chekFlag) { - $checkBoxes[$chekFlag]->setChecked(TRUE); - } - $this->assign('searchRows', $searchRows); - } - - $this->assign('searchCount', $searchCount); - $this->assign('searchDone', $this->get('searchDone')); - $this->assign('contact_type_display', ts('Individual')); - $this->addElement('submit', $this->getButtonName('refresh'), ts('Search'), array('class' => 'crm-form-submit')); - $this->addElement('submit', $this->getButtonName('cancel'), ts('Cancel'), array('class' => 'crm-form-submit')); - $this->addButtons(array( - array( - 'type' => 'next', - 'name' => ts('Add to Individual'), - 'isDefault' => TRUE, - ), - array( - 'type' => 'cancel', - 'name' => ts('Cancel'), - ), - ) - ); + $this->set('contactType', 'Individual'); + $this->assign('contactType', 'Individual'); + parent::buildQuickForm(); } /** diff --git a/CRM/Contact/Form/Task/AddToOrganization.php b/CRM/Contact/Form/Task/AddToOrganization.php index 6f99e1fddf..af28efe4bc 100644 --- a/CRM/Contact/Form/Task/AddToOrganization.php +++ b/CRM/Contact/Form/Task/AddToOrganization.php @@ -40,56 +40,9 @@ class CRM_Contact_Form_Task_AddToOrganization extends CRM_Contact_Form_Task_AddT * Build the form object. */ public function buildQuickForm() { - CRM_Utils_System::setTitle(ts('Add Contacts to Organization')); - $this->addElement('text', 'name', ts('Find Target Organization')); - - $this->add('select', - 'relationship_type_id', - ts('Relationship Type'), - array( - '' => ts('- select -'), - ) + - CRM_Contact_BAO_Relationship::getRelationType("Organization"), TRUE - ); - - $searchRows = $this->get('searchRows'); - $searchCount = $this->get('searchCount'); - if ($searchRows) { - $checkBoxes = array(); - $chekFlag = 0; - foreach ($searchRows as $id => $row) { - if (!$chekFlag) { - $chekFlag = $id; - } - - $checkBoxes[$id] = $this->createElement('radio', NULL, NULL, NULL, $id); - } - - $this->addGroup($checkBoxes, 'contact_check'); - if ($chekFlag) { - $checkBoxes[$chekFlag]->setChecked(TRUE); - } - $this->assign('searchRows', $searchRows); - } - - $this->assign('searchCount', $searchCount); - $this->assign('searchDone', $this->get('searchDone')); - $this->assign('contact_type_display', ts('Organization')); - $this->addElement('submit', $this->getButtonName('refresh'), ts('Search'), array('class' => 'crm-form-submit')); - $this->addElement('submit', $this->getButtonName('cancel'), ts('Cancel'), array('class' => 'crm-form-submit')); - - $this->addButtons(array( - array( - 'type' => 'next', - 'name' => ts('Add to Organization'), - 'isDefault' => TRUE, - ), - array( - 'type' => 'cancel', - 'name' => ts('Cancel'), - ), - ) - ); + $this->set('contactType', 'Organization'); + $this->assign('contactType', 'Organization'); + parent::buildQuickForm(); } /** diff --git a/CRM/Contact/Form/Task/AddToParentClass.php b/CRM/Contact/Form/Task/AddToParentClass.php index 3274eddc80..8e84414d83 100644 --- a/CRM/Contact/Form/Task/AddToParentClass.php +++ b/CRM/Contact/Form/Task/AddToParentClass.php @@ -44,6 +44,58 @@ class CRM_Contact_Form_Task_AddToParentClass extends CRM_Contact_Form_Task { parent::preProcess(); } + public function buildQuickForm() { + $contactType = $this->get('contactType'); + CRM_Utils_System::setTitle(ts('Add Contacts to %1', array(1 => $contactType))); + $this->addElement('text', 'name', ts('Find Target %1', array(1 => $contactType))); + + $this->add('select', + 'relationship_type_id', + ts('Relationship Type'), + array( + '' => ts('- select -'), + ) + + CRM_Contact_BAO_Relationship::getRelationType($contactType), TRUE + ); + + $searchRows = $this->get('searchRows'); + $searchCount = $this->get('searchCount'); + if ($searchRows) { + $checkBoxes = array(); + $chekFlag = 0; + foreach ($searchRows as $id => $row) { + if (!$chekFlag) { + $chekFlag = $id; + } + + $checkBoxes[$id] = $this->createElement('radio', NULL, NULL, NULL, $id); + } + + $this->addGroup($checkBoxes, 'contact_check'); + if ($chekFlag) { + $checkBoxes[$chekFlag]->setChecked(TRUE); + } + $this->assign('searchRows', $searchRows); + } + + $this->assign('searchCount', $searchCount); + $this->assign('searchDone', $this->get('searchDone')); + $this->assign('contact_type_display', ts($contactType)); + $this->addElement('submit', $this->getButtonName('refresh'), ts('Search'), array('class' => 'crm-form-submit')); + $this->addElement('submit', $this->getButtonName('cancel'), ts('Cancel'), array('class' => 'crm-form-submit')); + $this->addButtons(array( + array( + 'type' => 'next', + 'name' => ts('Add to %1', array(1 => $contactType)), + 'isDefault' => TRUE, + ), + array( + 'type' => 'cancel', + 'name' => ts('Cancel'), + ), + ) + ); + } /** * Add relationships from form. */ diff --git a/templates/CRM/Contact/Form/Task/AddToHousehold.tpl b/templates/CRM/Contact/Form/Task/AddToHousehold.tpl index a27a52c8ee..c48d57431e 100644 --- a/templates/CRM/Contact/Form/Task/AddToHousehold.tpl +++ b/templates/CRM/Contact/Form/Task/AddToHousehold.tpl @@ -23,86 +23,4 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -
-
- {ts}Choose Relationship Type and Target Household{/ts} -
- - - {if $action EQ 2} {* action = update *} - - {else} {* action = add *} - - - - - - - - - - -
{include file="CRM/Contact/Form/Task.tpl"}
{$form.relationship_type_id.label}{$form.relationship_type_id.html}
{$form.name.label}{$form.name.html}
{$form._qf_AddToHousehold_refresh.html}  {$form._qf_AddToHousehold_cancel.html}
- {if $searchDone } {* Search button clicked *} - {if $searchCount} - {if $searchRows} {* we've got rows to display *} -
{ts}Mark Target Contact(s) for this Relationship{/ts} -
- {ts}Mark the target contact(s) for this relationship if it appears below. Otherwise you may modify the search name above and click Search again.{/ts} -
- {strip} - - - - - - - - - - {foreach from=$searchRows item=row} - - - - - - - - - {/foreach} -
 {ts}Name{/ts}{ts}City{/ts}{ts}State{/ts}{ts}Email{/ts}{ts}Phone{/ts}
{$form.contact_check[$row.id].html}{$row.type} {$row.name}{$row.city}{$row.state}{$row.email}{$row.phone}
- {/strip} -
- {else} {* too many results - we're only displaying 50 *} -
- {capture assign=infoTitle}{ts}Too many matching results{/ts}{/capture} - {capture assign=infoMessage}{ts}Please narrow your search by entering a more complete target contact name.{/ts}{/capture} - {include file="CRM/common/info.tpl"} - {/if} - {else} {* no valid matches for name + contact_type *} - - {capture assign=infoTitle}{ts}No matching results for{/ts}{/capture} - {capture assign=infoMessage}{ts}Check your spelling, or try fewer letters for the target contact name.{/ts}{/capture} - {include file="CRM/common/info.tpl"} - {/if} {* end if searchCount *} - {else} - - {/if} {* end if searchDone *} - {/if} {* end action = add *} - - {* Only show buttons if action=update, OR if we have $contacts (results)*} - {if $searchRows OR $action EQ 2} -
- -
- -
-
{include file="CRM/common/formButtons.tpl"}
-
-
- {$form.status.label} {$form.status.html} -
- - - - {/if} +{include file="CRM/Contact/Form/Task/AddToParentClass.tpl"} \ No newline at end of file diff --git a/templates/CRM/Contact/Form/Task/AddToIndividual.tpl b/templates/CRM/Contact/Form/Task/AddToIndividual.tpl index dc32624b5e..f9c3741eae 100644 --- a/templates/CRM/Contact/Form/Task/AddToIndividual.tpl +++ b/templates/CRM/Contact/Form/Task/AddToIndividual.tpl @@ -23,86 +23,4 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -
-
- {ts}Choose Relationship Type and Target Individual{/ts} -
- - - {if $action EQ 2} {* action = update *} - - {else} {* action = add *} - - - - - - - - - - -
{include file="CRM/Contact/Form/Task.tpl"}
{$form.relationship_type_id.label}{$form.relationship_type_id.html}
{$form.name.label}{$form.name.html}
{$form._qf_AddToIndividual_refresh.html}  {$form._qf_AddToIndividual_cancel.html}
- {if $searchDone } {* Search button clicked *} - {if $searchCount} - {if $searchRows} {* we've got rows to display *} -
{ts}Mark Target Contact(s) for this Relationship{/ts} -
- {ts}Mark the target contact(s) for this relationship if it appears below. Otherwise you may modify the search name above and click Search again.{/ts} -
- {strip} - - - - - - - - - - {foreach from=$searchRows item=row} - - - - - - - - - {/foreach} -
 {ts}Name{/ts}{ts}City{/ts}{ts}State{/ts}{ts}Email{/ts}{ts}Phone{/ts}
{$form.contact_check[$row.id].html}{$row.type} {$row.name}{$row.city}{$row.state}{$row.email}{$row.phone}
- {/strip} -
- {else} {* too many results - we're only displaying 50 *} -
- {capture assign=infoTitle}{ts}Too many matching results{/ts}{/capture} - {capture assign=infoMessage}{ts}Please narrow your search by entering a more complete target contact name.{/ts}{/capture} - {include file="CRM/common/info.tpl"} - {/if} - {else} {* no valid matches for name + contact_type *} - - {capture assign=infoTitle}{ts}No matching results for{/ts}{/capture} - {capture assign=infoMessage}{ts}Check your spelling, or try fewer letters for the target contact name.{/ts}{/capture} - {include file="CRM/common/info.tpl"} - {/if} {* end if searchCount *} - {else} - - {/if} {* end if searchDone *} - {/if} {* end action = add *} - - {* Only show buttons if action=update, OR if we have $contacts (results)*} - {if $searchRows OR $action EQ 2} -
- -
- -
-
{include file="CRM/common/formButtons.tpl"}
-
-
- {$form.status.label} {$form.status.html} -
- - - - {/if} +{include file="CRM/Contact/Form/Task/AddToParentClass.tpl"} \ No newline at end of file diff --git a/templates/CRM/Contact/Form/Task/AddToOrganization.tpl b/templates/CRM/Contact/Form/Task/AddToOrganization.tpl index 607319ed67..c48d57431e 100644 --- a/templates/CRM/Contact/Form/Task/AddToOrganization.tpl +++ b/templates/CRM/Contact/Form/Task/AddToOrganization.tpl @@ -23,87 +23,4 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -
-
- {ts}Choose Relationship Type and Target Organization{/ts} -
- - - {if $action EQ 2} {* action = update *} - - {else} {* action = add *} - - - - - - - - -
{include file="CRM/Contact/Form/Task.tpl"}
{$form.relationship_type_id.label}{$form.relationship_type_id.html}
{$form.name.label}{$form.name.html}
{$form._qf_AddToOrganization_refresh.html}  {$form._qf_AddToOrganization_cancel.html}
-{if $searchDone } {* Search button clicked *} - {if $searchCount} - {if $searchRows} {* we've got rows to display *} -
{ts}Mark Target Contact(s) for this Relationship{/ts} -
- {ts}Mark the target contact(s) for this relationship if it appears below. Otherwise you may modify the search name above and click Search again.{/ts} -
- {strip} - - - - - - - - - - {foreach from=$searchRows item=row} - - - - - - - - - {/foreach} -
 {ts}Name{/ts}{ts}City{/ts}{ts}State{/ts}{ts}Email{/ts}{ts}Phone{/ts}
{$form.contact_check[$row.id].html}{$row.type} {$row.name}{$row.city}{$row.state}{$row.email}{$row.phone}
- {/strip} -
- {else} {* too many results - we're only displaying 50 *} -
- {capture assign=infoTitle}{ts}Too many matching results{/ts}{/capture} - {capture assign=infoMessage}{ts}Please narrow your search by entering a more complete target contact name.{/ts}{/capture} - {include file="CRM/common/info.tpl"} - {/if} - {else} {* no valid matches for name + contact_type *} - - {capture assign=infoTitle}{ts}No matching results for{/ts}{/capture} - {capture assign=infoMessage}{ts}Check your spelling, or try fewer letters for the target contact name.{/ts}{/capture} - {include file="CRM/common/info.tpl"} - {/if} {* end if searchCount *} - {else} - - {/if} {* end if searchDone *} - {/if} {* end action = add *} - - {* Only show start/end date and buttons if action=update, OR if we have $contacts (results)*} - {if $searchRows OR $action EQ 2} -
- -
- -
-
{include file="CRM/common/formButtons.tpl" location="bottom"}
-
-
- {$form.status.label} {$form.status.html} -
- - - - {/if} - - - +{include file="CRM/Contact/Form/Task/AddToParentClass.tpl"} \ No newline at end of file diff --git a/templates/CRM/Contact/Form/Task/AddToParentClass.tpl b/templates/CRM/Contact/Form/Task/AddToParentClass.tpl new file mode 100644 index 0000000000..090c65b9a3 --- /dev/null +++ b/templates/CRM/Contact/Form/Task/AddToParentClass.tpl @@ -0,0 +1,111 @@ +{* + +--------------------------------------------------------------------+ + | CiviCRM version 4.7 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2017 | + +--------------------------------------------------------------------+ + | This file is a part of CiviCRM. | + | | + | CiviCRM is free software; you can copy, modify, and distribute it | + | under the terms of the GNU affero General Public License | + | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | + | | + | CiviCRM is distributed in the hope that it will be useful, but | + | WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | + | See the GNU Affero General Public License for more details. | + | | + | You should have received a copy of the GNU Affero General Public | + | License and the CiviCRM Licensing Exception along | + | with this program; if not, contact CiviCRM LLC | + | at info[AT]civicrm[DOT]org. If you have questions about the | + | GNU Affero General Public License or the licensing of CiviCRM, | + | see the CiviCRM license FAQ at http://civicrm.org/licensing | + +--------------------------------------------------------------------+ +*} +{assign var="class" value="_qf_AddTo"|cat:$contactType} +{assign var="refresh" value="$class"|cat:"_refresh"} +{assign var="cancel" value="$class"|cat:"_cancel"} +
+
+ {ts 1=$contactType}Choose Relationship Type and Target %1{/ts} +
+ + + {if $action EQ 2} {* action = update *} + + {else} {* action = add *} + + + + + + + + + + +
{include file="CRM/Contact/Form/Task.tpl"}
{$form.relationship_type_id.label}{$form.relationship_type_id.html}
{$form.name.label}{$form.name.html}
{$form.$refresh.html}  {$form.$cancel.html}
+ {if $searchDone } {* Search button clicked *} + {if $searchCount} + {if $searchRows} {* we've got rows to display *} +
{ts}Mark Target Contact(s) for this Relationship{/ts} +
+ {ts}Mark the target contact(s) for this relationship if it appears below. Otherwise you may modify the search name above and click Search again.{/ts} +
+ {strip} + + + + + + + + + + {foreach from=$searchRows item=row} + + + + + + + + + {/foreach} +
 {ts}Name{/ts}{ts}City{/ts}{ts}State{/ts}{ts}Email{/ts}{ts}Phone{/ts}
{$form.contact_check[$row.id].html}{$row.type} {$row.name}{$row.city}{$row.state}{$row.email}{$row.phone}
+ {/strip} +
+ {else} {* too many results - we're only displaying 50 *} +
+ {capture assign=infoTitle}{ts}Too many matching results{/ts}{/capture} + {capture assign=infoMessage}{ts}Please narrow your search by entering a more complete target contact name.{/ts}{/capture} + {include file="CRM/common/info.tpl"} + {/if} + {else} {* no valid matches for name + contact_type *} + + {capture assign=infoTitle}{ts}No matching results for{/ts}{/capture} + {capture assign=infoMessage}{ts}Check your spelling, or try fewer letters for the target contact name.{/ts}{/capture} + {include file="CRM/common/info.tpl"} + {/if} {* end if searchCount *} + {else} + + {/if} {* end if searchDone *} + {/if} {* end action = add *} + + {* Only show buttons if action=update, OR if we have $contacts (results)*} + {if $searchRows OR $action EQ 2} +
+ +
+ +
+
{include file="CRM/common/formButtons.tpl"}
+
+
+ {$form.status.label} {$form.status.html} +
+ + + + {/if} -- 2.25.1