From 2a4718f6dcbbe7e5f2f056eae74008fcb1df35a9 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Thu, 3 May 2018 16:32:13 +0100 Subject: [PATCH] dev/core#101 Implement field spec pattern for advanced search form. By implementing the field spec pattern as detailed in dev/core#115 extension developers have more control over what is displayed in this template without needing to resort to overriding it --- CRM/Contact/Form/Search/Criteria.php | 70 ++++++- css/searchForm.css | 17 ++ .../Contact/Form/Search/Criteria/Basic.tpl | 184 ++---------------- .../Search/Criteria/Fields/contact_tags.tpl | 10 + .../Form/Search/Criteria/Fields/group.tpl | 51 +++++ .../Search/Criteria/Fields/phone_numeric.tpl | 9 + .../Fields/preferred_communication_method.tpl | 12 ++ .../Search/Criteria/Fields/privacy_toggle.tpl | 30 +++ .../Search/Criteria/Fields/tag_search.tpl | 4 + .../Form/Search/Criteria/Fields/uf_user.tpl | 7 + 10 files changed, 226 insertions(+), 168 deletions(-) create mode 100644 templates/CRM/Contact/Form/Search/Criteria/Fields/contact_tags.tpl create mode 100644 templates/CRM/Contact/Form/Search/Criteria/Fields/group.tpl create mode 100644 templates/CRM/Contact/Form/Search/Criteria/Fields/phone_numeric.tpl create mode 100644 templates/CRM/Contact/Form/Search/Criteria/Fields/preferred_communication_method.tpl create mode 100644 templates/CRM/Contact/Form/Search/Criteria/Fields/privacy_toggle.tpl create mode 100644 templates/CRM/Contact/Form/Search/Criteria/Fields/tag_search.tpl create mode 100644 templates/CRM/Contact/Form/Search/Criteria/Fields/uf_user.tpl diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index 3c1b3e7ea9fc..19baac794660 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -35,6 +35,8 @@ class CRM_Contact_Form_Search_Criteria { * @param CRM_Core_Form $form */ public static function basic(&$form) { + + self::setBasicSearchFields($form); $form->addElement('hidden', 'hidden_basic', 1); if ($form->_searchOptions['contactType']) { @@ -69,7 +71,7 @@ public static function basic(&$form) { $contactTags = CRM_Core_BAO_Tag::getTags(); if ($contactTags) { - $form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, + $form->add('select', 'contact_tags', ts('Select Tag(s)'), $contactTags, FALSE, array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;') ); } @@ -99,10 +101,10 @@ public static function basic(&$form) { } // add text box for last name, first name, street name, city - $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); + $form->addElement('text', 'sort_name', ts('Complete OR Partial Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); // add text box for last name, first name, street name, city - $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); + $form->add('text', 'email', ts('Complete OR Partial Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); //added contact source $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'contact_source')); @@ -248,6 +250,68 @@ public static function basic(&$form) { $form->add('select', 'phone_phone_type_id', ts('Phone Type'), array('' => ts('- any -')) + $phoneType, FALSE, array('class' => 'crm-select2')); } + /** + * Defines the fields that can be displayed for the basic search section. + * + * @param CRM_Core_Form $form + */ + protected static function setBasicSearchFields($form) { + $form->assign('basicSearchFields', [ + 'sort_name' => ['name' => 'sort_name'], + 'email' => ['name' => 'email'], + 'contact_type' => ['name' => 'contact_type'], + 'group' => [ + 'name' => 'group', + 'template' => 'CRM/Contact/Form/Search/Criteria/Fields/group.tpl', + ], + 'contact_tags' => [ + 'name' => 'contact_tags', + 'template' => 'CRM/Contact/Form/Search/Criteria/Fields/contact_tags.tpl', + ], + 'tag_search' => [ + 'name' => 'tag_search', + 'help' => ['id' => 'id-all-tags'] + ], + 'all_tag_types' => [ + 'name' => '', + 'help' => ['id' => 'id-all-tags'], + 'class' => 'search-field__span-3', + ], + 'phone_numeric' => [ + 'name' => 'phone_numeric', + 'template' => 'CRM/Contact/Form/Search/Criteria/Fields/phone_numeric.tpl', + ], + 'phone_location_type_id' => ['name' => 'phone_location_type_id'], + 'phone_phone_type_id' => ['name' => 'phone_phone_type_id'], + 'privacy_toggle' => [ + 'name' => 'privacy_toggle', + 'template' => 'CRM/Contact/Form/Search/Criteria/Fields/privacy_toggle.tpl', + ], + 'preferred_communication_method' => [ + 'name' => 'preferred_communication_method', + 'template' => 'CRM/Contact/Form/Search/Criteria/Fields/preferred_communication_method.tpl', + ], + 'contact_source' => [ + 'name' => 'contact_source', + 'help' => ['id' => 'id-source', 'file' => 'CRM/Contact/Form/Contact'], + ], + 'job_title' => ['name' => 'job_title'], + 'preferred_language' => ['name' => 'preferred_language'], + 'contact_id' => [ + 'name' => 'contact_id', + 'help' => ['id' => 'id-contact-id', 'file' => 'CRM/Contact/Form/Contact'], + ], + 'external_identifier' => [ + 'name' => 'external_identifier', + 'help' => ['id' => 'id-external-id', 'file' => 'CRM/Contact/Form/Contact'], + ], + 'uf_user' => [ + 'name' => 'uf_user', + 'template' => 'CRM/Contact/Form/Search/Criteria/Fields/uf_user.tpl' + ], + ]); + } + /** * @param CRM_Core_Form $form diff --git a/css/searchForm.css b/css/searchForm.css index bbafc5d745af..66cd36972868 100644 --- a/css/searchForm.css +++ b/css/searchForm.css @@ -62,3 +62,20 @@ color: #41477E; font-weight: bold; } + +.advanced-search-fields { + display: grid; + grid-template-columns: [col] repeat(3, calc(100% / 3 - 10px)); + width: 100%; +} + +.advanced-search-fields .search-field { + padding: 5px; +} + +.advanced-search-fields .search-field__span-2 { + grid-column: col / span 2; +} +.advanced-search-fields .search-field__span-3 { + grid-column: col / span 3; +} diff --git a/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl b/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl index ba59ec4468c9..10d96858d8c3 100644 --- a/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl +++ b/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl @@ -23,170 +23,24 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} - - - - - {if $form.contact_type} - - {else} - - {/if} - - - {if $form.group} - - {else} - - {/if} - {if $form.contact_tags} - - {else} - - {/if} - {if $isTagset} - - {/if} - - {if ! $isTagset} - - {/if} - - - {if $form.all_tag_types} - - - - {/if} - - - - - - - - - - - - - - - - - - - -

- {$form.sort_name.html} -
-
- {$form.email.html} -

- {$form.contact_type.html} -
 
-
-
- {$form.group.html} -
-
- -
- {$form.group_type.html} - {literal} - - {/literal} -
-
  - {$form.contact_tags.html} -  {include file="CRM/common/Tagset.tpl"}{$form.tag_search.label} {help id="id-all-tags"}
{$form.tag_search.html}
  
- {$form.all_tag_types.html} {$form.all_tag_types.label} {help id="id-all-tag-types"} -
-
- {$form.phone_numeric.label}
{$form.phone_numeric.html} -
-
- {ts}Punctuation and spaces are ignored.{/ts} -
-
{$form.phone_location_type_id.label}
{$form.phone_location_type_id.html}
{$form.phone_phone_type_id.label}
{$form.phone_phone_type_id.html}
- - - - - - - - -
- {$form.privacy_toggle.html} {help id="id-privacy"} -
- {$form.privacy_options.html} - -
{$form.privacy_operator.html} {help id="privacy-operator"}
-
- {literal} - - {/literal} -
- {$form.preferred_communication_method.label}
- {$form.preferred_communication_method.html}
-
- {$form.email_on_hold.html} {$form.email_on_hold.label} -
- {$form.contact_source.label} {help id="id-source" file="CRM/Contact/Form/Contact"}
- {$form.contact_source.html} -
- {$form.job_title.label}
- {$form.job_title.html} -
- {$form.preferred_language.label}
- {$form.preferred_language.html} -
- {$form.contact_id.label} {help id="id-internal-id" file="CRM/Contact/Form/Contact"}
- {$form.contact_id.html} -
- {$form.external_identifier.label} {help id="id-external-id" file="CRM/Contact/Form/Contact"}
- {$form.external_identifier.html} -
- {if $form.uf_user} - {$form.uf_user.label} {$form.uf_user.html} -
- {ts 1=$config->userFramework}Does the contact have a %1 Account?{/ts} -
+
+ {foreach from=$basicSearchFields item=fieldSpec} + {assign var=field value=$form[$fieldSpec.name]} + {if $field} + {if $fieldSpec.template} + {include file=$fieldSpec.template} {else} -   +
+ {$field.label} + {if $fieldSpec.help} + {assign var=help value=$fieldSpec.help} + {capture assign=helpFile}{if $fieldSpec.help}{$fieldSpec.help}{else}''{/if}{/capture} + {help id=$help.id file=$help.file} + {/if} +
+ {$field.html} +
{/if} -
+ {/if} + {/foreach} + diff --git a/templates/CRM/Contact/Form/Search/Criteria/Fields/contact_tags.tpl b/templates/CRM/Contact/Form/Search/Criteria/Fields/contact_tags.tpl new file mode 100644 index 000000000000..fa0aac4f3caa --- /dev/null +++ b/templates/CRM/Contact/Form/Search/Criteria/Fields/contact_tags.tpl @@ -0,0 +1,10 @@ +
+ {$form.contact_tags.label}
+ {$form.contact_tags.html} +
+ +{if $isTagset} +
+ {include file="CRM/common/Tagset.tpl"} +
+{/if} diff --git a/templates/CRM/Contact/Form/Search/Criteria/Fields/group.tpl b/templates/CRM/Contact/Form/Search/Criteria/Fields/group.tpl new file mode 100644 index 000000000000..47e01c246bbe --- /dev/null +++ b/templates/CRM/Contact/Form/Search/Criteria/Fields/group.tpl @@ -0,0 +1,51 @@ +
+
+ +
+ {$form.group.html} +
+
+ +
+ {$form.group_type.html} + {literal} + + {/literal} +
+
diff --git a/templates/CRM/Contact/Form/Search/Criteria/Fields/phone_numeric.tpl b/templates/CRM/Contact/Form/Search/Criteria/Fields/phone_numeric.tpl new file mode 100644 index 000000000000..9697daaddf35 --- /dev/null +++ b/templates/CRM/Contact/Form/Search/Criteria/Fields/phone_numeric.tpl @@ -0,0 +1,9 @@ +
+
+ {$form.phone_numeric.label}
+ {$form.phone_numeric.html} +
+
+ {ts}Punctuation and spaces are ignored.{/ts} +
+
diff --git a/templates/CRM/Contact/Form/Search/Criteria/Fields/preferred_communication_method.tpl b/templates/CRM/Contact/Form/Search/Criteria/Fields/preferred_communication_method.tpl new file mode 100644 index 000000000000..688f1d7de71d --- /dev/null +++ b/templates/CRM/Contact/Form/Search/Criteria/Fields/preferred_communication_method.tpl @@ -0,0 +1,12 @@ +
+ {$form.preferred_communication_method.label} +
+ {$form.preferred_communication_method.html} +
+ + {if $form.email_on_hold} +
+ {$form.email_on_hold.html} + {$form.email_on_hold.label} + {/if} +
diff --git a/templates/CRM/Contact/Form/Search/Criteria/Fields/privacy_toggle.tpl b/templates/CRM/Contact/Form/Search/Criteria/Fields/privacy_toggle.tpl new file mode 100644 index 000000000000..1b12030b8706 --- /dev/null +++ b/templates/CRM/Contact/Form/Search/Criteria/Fields/privacy_toggle.tpl @@ -0,0 +1,30 @@ +
+ + + + + + + + +
+ {$form.privacy_toggle.html} {help id="id-privacy"} +
+ {$form.privacy_options.html} + +
+ {$form.privacy_operator.html} {help id="privacy-operator"} +
+
+ {literal} + + {/literal} +
diff --git a/templates/CRM/Contact/Form/Search/Criteria/Fields/tag_search.tpl b/templates/CRM/Contact/Form/Search/Criteria/Fields/tag_search.tpl new file mode 100644 index 000000000000..2f5a2181fe20 --- /dev/null +++ b/templates/CRM/Contact/Form/Search/Criteria/Fields/tag_search.tpl @@ -0,0 +1,4 @@ +
+ {$form.tag_search.label} {help id="id-all-tags"}
+ {$form.tag_search.html} +
diff --git a/templates/CRM/Contact/Form/Search/Criteria/Fields/uf_user.tpl b/templates/CRM/Contact/Form/Search/Criteria/Fields/uf_user.tpl new file mode 100644 index 000000000000..57cf654cfbce --- /dev/null +++ b/templates/CRM/Contact/Form/Search/Criteria/Fields/uf_user.tpl @@ -0,0 +1,7 @@ +
+ {$form.uf_user.label} + {$form.uf_user.html} +
+ {ts 1=$config->userFramework}Does the contact have a %1 Account?{/ts} +
+