Always show parent/child nesting in group selectors
authorColeman Watts <coleman@civicrm.org>
Fri, 8 Aug 2014 00:23:42 +0000 (01:23 +0100)
committerColeman Watts <coleman@civicrm.org>
Fri, 8 Aug 2014 00:35:57 +0000 (01:35 +0100)
24 files changed:
CRM/Campaign/BAO/Query.php
CRM/Campaign/Form/Campaign.php
CRM/Campaign/Form/Task/Reserve.php
CRM/Contact/Form/DedupeFind.php
CRM/Contact/Form/Search/Custom/Basic.php
CRM/Contact/Form/Search/Custom/DateAdded.php
CRM/Contact/Form/Search/Custom/Group.php
CRM/Contact/Form/Search/Custom/MultipleValues.php
CRM/Contact/Form/Search/Custom/PostalMailing.php
CRM/Contact/Form/Search/Custom/Proximity.php
CRM/Contact/Form/Search/Custom/RandomSegment.php
CRM/Contact/Form/Task/AddToGroup.php
CRM/Contact/Form/Task/PickProfile.php
CRM/Contact/Form/Task/RemoveFromGroup.php
CRM/Contact/Import/Form/Preview.php
CRM/Contribute/Form/Search.php
CRM/Core/PseudoConstant.php
CRM/Event/Form/ManageEvent/ScheduleReminders.php
CRM/Export/Form/Select.php
CRM/Financial/Form/BatchTransaction.php
CRM/Mailing/Form/Group.php
CRM/Report/Form.php
CRM/SMS/Form/Group.php
templates/CRM/Report/Form/Actions.tpl

index 5b4d84124f0ee8f3acb942bdcb844b451f368abf..44563481efc0b51a56559e306b670c71964351c5 100755 (executable)
@@ -366,9 +366,9 @@ civicrm_activity_assignment.record_type_id = $assigneeID ) ";
     $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE,
       array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2')
     );
-    $groups = CRM_Core_PseudoConstant::group();
+    $groups = CRM_Core_PseudoConstant::nestedGroup();
     $form->add('select', 'group', ts('Groups'), $groups, FALSE,
-      array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2')
+      array('multiple' => 'multiple', 'class' => 'crm-select2')
     );
 
     $showInterviewer = FALSE;
index 2ea0a12bd9d80c0cd8261673da6d9d0fa447de12..dcfc4088787587520a5124e127941d7b141d7faf 100644 (file)
@@ -255,10 +255,8 @@ class CRM_Campaign_Form_Campaign extends CRM_Core_Form {
           '' => ts('- select Parent -')) + $campaigns
       );
     }
-
+$groups = CRM_Core_PseudoConstant::nestedGroup();
     //get the campaign groups.
-    $groups = CRM_Core_PseudoConstant::group();
-
     $this->add('select', 'includeGroups',
       ts('Include Group(s)'),
       $groups,
index 87e50870586cb3924b94c5d2df0e11db359fae5a..bdee47493ec140b0322ccafa25c6ea13d0d0e6c6 100644 (file)
@@ -164,12 +164,12 @@ class CRM_Campaign_Form_Task_Reserve extends CRM_Campaign_Form_Task {
     $this->addElement('text', 'ActivityType', ts('Activity Type'));
     $this->addElement('text', 'newGroupName', ts('Name for new group'));
     $this->addElement('text', 'newGroupDesc', ts('Description of new group'));
-    $groups = CRM_Core_PseudoConstant::group();
+    $groups = CRM_Core_PseudoConstant::nestedGroup();
     $hasExistingGroups = FALSE;
     if (is_array($groups) && !empty($groups)) {
       $hasExistingGroups = TRUE;
       $this->addElement('select', 'groups', ts('Add respondent(s) to existing group(s)'),
-        $groups, array('multiple' => "multiple", 'size' => 5)
+        $groups, array('multiple' => "multiple", 'class' => 'crm-select2')
       );
     }
     $this->assign('hasExistingGroups', $hasExistingGroups);
index 6fd1a9063fb06cba11f0c8ed486e1917d31e391c..bd654dd4bbcb8855db389bb1093919ae91172d50 100644 (file)
@@ -63,9 +63,7 @@ class CRM_Contact_Form_DedupeFind extends CRM_Admin_Form {
    */
   public function buildQuickForm() {
 
-    $groupList = CRM_Core_PseudoConstant::group();
-    $groupList[''] = ts('- All Contacts -');
-    asort($groupList);
+    $groupList = array('' => ts('- All Contacts -')) + CRM_Core_PseudoConstant::nestedGroup();
 
     $this->add('select', 'group_id', ts('Select Group'), $groupList, FALSE, array('class' => 'crm-select2 huge'));
     $this->addButtons(array(
index 97ab38508bc9eb3d5dd5d06a60c28fb03bac950c..2261ce29e6e58206bd7c74dc11208753ae71e42e 100644 (file)
@@ -118,15 +118,15 @@ class CRM_Contact_Form_Search_Custom_Basic extends CRM_Contact_Form_Search_Custo
     // this is loaded onto then replace with something like '__' & test
     $separator = CRM_Core_DAO::VALUE_SEPARATOR;
     $contactTypes = array('' => ts('- any contact type -')) + CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, $separator);
-    $form->add('select', 'contact_type', ts('Find...'), $contactTypes);
+    $form->add('select', 'contact_type', ts('Find...'), $contactTypes, FALSE, array('class' => 'crm-select2 huge'));
 
     // add select for groups
-    $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::group();
-    $form->addElement('select', 'group', ts('in'), $group);
+    $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::nestedGroup();
+    $form->addElement('select', 'group', ts('in'), $group, array('class' => 'crm-select2 huge'));
 
     // add select for categories
     $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
-    $form->addElement('select', 'tag', ts('Tagged'), $tag);
+    $form->addElement('select', 'tag', ts('Tagged'), $tag, array('class' => 'crm-select2 huge'));
 
     // text for sort_name
     $form->add('text', 'sort_name', ts('Name'));
index 716b1333fcd864860787ae223fd5fd6d0545ccc6..f0565c0bfdd7f91364fe5ee0fc5dce99ba151b8d 100644 (file)
@@ -60,7 +60,7 @@ class CRM_Contact_Form_Search_Custom_DateAdded extends CRM_Contact_Form_Search_C
     $form->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'custom'));
     $form->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'custom'));
 
-    $groups = CRM_Core_PseudoConstant::group();
+    $groups = CRM_Core_PseudoConstant::nestedGroup();
 
     $select2style = array(
       'multiple' => TRUE,
index 51fd1908f4256da30af73cdb2031a20782497e5b..fa25d7df5d68536c65634265128f08177f0b4614 100644 (file)
@@ -97,7 +97,7 @@ class CRM_Contact_Form_Search_Custom_Group
 
     $this->setTitle(ts('Include / Exclude Search'));
 
-    $groups = CRM_Core_PseudoConstant::group();
+    $groups = CRM_Core_PseudoConstant::nestedGroup();
 
     $tags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     if (count($groups) == 0 || count($tags) == 0) {
index caf43231edd249416ed7b2b3e5f9e77eff482b4f..df3b9e92b10fe533a5728ccce90c05a2c1087471 100644 (file)
@@ -108,15 +108,15 @@ class CRM_Contact_Form_Search_Custom_MultipleValues extends CRM_Contact_Form_Sea
     // this is loaded onto then replace with something like '__' & test
     $separator = CRM_Core_DAO::VALUE_SEPARATOR;
     $contactTypes = array('' => ts('- any contact type -')) + CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, $separator);
-    $form->add('select', 'contact_type', ts('Find...'), $contactTypes);
+    $form->add('select', 'contact_type', ts('Find...'), $contactTypes, array('class' => 'crm-select2 huge'));
 
     // add select for groups
     $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::group();
-    $form->addElement('select', 'group', ts('in'), $group);
+    $form->addElement('select', 'group', ts('in'), $group, array('class' => 'crm-select2 huge'));
 
     // add select for tags
     $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
-    $form->addElement('select', 'tag', ts('Tagged'), $tag);
+    $form->addElement('select', 'tag', ts('Tagged'), $tag, array('class' => 'crm-select2 huge'));
 
     if (empty($this->_groupTree)) {
       CRM_Core_Error::statusBounce(ts("Atleast one Custom Group must be present, for Custom Group search."),
index 3bc66a380cf5ddb99f0ef355dc6648a8022a52e3..09b36e36a5ee95c2329fecae220080e8452183e6 100644 (file)
@@ -52,8 +52,8 @@ class CRM_Contact_Form_Search_Custom_PostalMailing extends CRM_Contact_Form_Sear
    * @param $form
    */
   function buildForm(&$form) {
-    $groups = array('' => ts('- select group -')) + CRM_Core_PseudoConstant::allGroup();
-    $form->addElement('select', 'group_id', ts('Group'), $groups);
+    $groups = array('' => ts('- select group -')) + CRM_Core_PseudoConstant::nestedGroup(FALSE);
+    $form->addElement('select', 'group_id', ts('Group'), $groups, array('class' => 'crm-select2 huge'));
 
     /**
      * if you are using the standard template, this array tells the template what elements
index 6bf658b34e5f5a54985ed88fb81755354d9e0414..c9d1dfcd4d7e245825cbaf2360c583dbfdd847b2 100644 (file)
@@ -136,16 +136,16 @@ class CRM_Contact_Form_Search_Custom_Proximity extends CRM_Contact_Form_Search_C
     else {
       $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
     }
-    $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
+    $form->add('select', 'state_province_id', ts('State/Province'), $stateProvince, FALSE, array('class' => 'crm-select2 huge'));
 
     $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
-    $form->add('select', 'country_id', ts('Country'), $country, TRUE);
+    $form->add('select', 'country_id', ts('Country'), $country, TRUE, array('class' => 'crm-select2 huge'));
 
-    $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::group();
-    $form->addElement('select', 'group', ts('Group'), $group);
+    $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::nestedGroup();
+    $form->addElement('select', 'group', ts('Group'), $group, array('class' => 'crm-select2 huge'));
 
     $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
-    $form->addElement('select', 'tag', ts('Tag'), $tag);
+    $form->addElement('select', 'tag', ts('Tag'), $tag, array('class' => 'crm-select2 huge'));
 
 
     // state country js, CRM-5233
index 5718a7f3c9e133b8488ffa82f066113e28da8e0c..2d5223ec251b5f9b4bf76e08efbbb1bb06f205fc 100644 (file)
@@ -83,7 +83,7 @@ class CRM_Contact_Form_Search_Custom_RandomSegment extends CRM_Contact_Form_Sear
       TRUE
     );
 
-    $groups = CRM_Core_PseudoConstant::group();
+    $groups = CRM_Core_PseudoConstant::nestedGroup();
 
     $select2style = array(
       'multiple' => TRUE,
index dac5896230349f6c849fb3e6988a22f042b78571..593f28dc0c05fdc84030763affddac4162b2cc93 100644 (file)
@@ -125,7 +125,7 @@ class CRM_Contact_Form_Task_AddToGroup extends CRM_Contact_Form_Task {
     }
 
     // add select for groups
-    $group = array('' => ts('- select group -')) + CRM_Core_PseudoConstant::group();
+    $group = array('' => ts('- select group -')) + CRM_Core_PseudoConstant::nestedGroup();
 
     $groupElement = $this->add('select', 'group_id', ts('Select Group'), $group, FALSE, array('class' => 'crm-select2 huge'));
 
index 8035110f3eb18c739cd6b1db29b0080eb985076e..8714544bfdb1c58511653ac9c54c128af92414a0 100644 (file)
@@ -120,7 +120,7 @@ class CRM_Contact_Form_Task_PickProfile extends CRM_Contact_Form_Task {
       CRM_Core_Session::setStatus(ts("The contact type selected for Batch Update does not have a corresponding profile. Please set up a profile for %1s and try again.", array(1 => $types)), ts('No Profile Available'), 'error');
       CRM_Utils_System::redirect($this->_userContext);
     }
-    $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'), array('' => ts('- select profile -')) + $profiles, TRUE);
+    $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'), array('' => ts('- select profile -')) + $profiles, TRUE, array('class' => 'crm-select2 huge'));
 
     $this->addDefaultButtons(ts('Continue >>'));
   }
index a75b0918ca697528050ebc27bdfc8ee371e199c6..152b5a59a7c5e4c78094836e4267d5915986ca85 100644 (file)
@@ -49,7 +49,7 @@ class CRM_Contact_Form_Task_RemoveFromGroup extends CRM_Contact_Form_Task {
    */
   function buildQuickForm() {
     // add select for groups
-    $group = array('' => ts('- select group -')) + CRM_Core_PseudoConstant::group();
+    $group = array('' => ts('- select group -')) + CRM_Core_PseudoConstant::nestedGroup();
     $groupElement = $this->add('select', 'group_id', ts('Select Group'), $group, TRUE, array('class' => 'crm-select2 huge'));
 
     CRM_Utils_System::setTitle(ts('Remove Contacts from Group'));
index 70fdd82071a49ac9d12d2ec33b2ec65c773cf1d4..1dd11b5c9897c8e19fa3e04ad993b0277c1f5b66 100644 (file)
@@ -69,7 +69,7 @@ class CRM_Contact_Import_Form_Preview extends CRM_Import_Form_Preview {
 
     $this->assign('rowDisplayCount', 2);
 
-    $groups = CRM_Core_PseudoConstant::group();
+    $groups = CRM_Core_PseudoConstant::nestedGroup();
     $this->set('groups', $groups);
 
     $tag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
@@ -139,7 +139,7 @@ class CRM_Contact_Import_Form_Preview extends CRM_Import_Form_Preview {
     $groups = $this->get('groups');
 
     if (!empty($groups)) {
-      $this->addElement('select', 'groups', ts('Add imported records to existing group(s)'), $groups, array('multiple' => "multiple", 'size' => 5));
+      $this->addElement('select', 'groups', ts('Add imported records to existing group(s)'), $groups, array('multiple' => "multiple", 'class' => 'crm-select2'));
     }
 
     //display new tag
index 5e18535aeea385410d08505ad3e4a4baa8e3fcc3..5a8a86f08f0e273868ba12d1d8e39b903a3df0ad 100644 (file)
@@ -191,7 +191,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search {
       )
     );
 
-    $this->_group = CRM_Core_PseudoConstant::group();
+    $this->_group = CRM_Core_PseudoConstant::nestedGroup();
 
     // multiselect for groups
     if ($this->_group) {
index a93e07f59e0265a9cbc897ee223c4f9e8ab9c925..dfed28d604be8a32e22f85593ff2a7ab1b69a46c 100644 (file)
@@ -980,8 +980,6 @@ WHERE  id = %1";
   }
 
   /**
-   * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
-   *
    * Get all permissioned groups from database
    *
    * The static array group is returned, and if it's
@@ -991,7 +989,7 @@ WHERE  id = %1";
    * Note: any database errors will be trapped by the DAO.
    *
    * @param string $groupType type of group(Access/Mailing)
-   * @param bool|\boolen $excludeHidden exclude hidden groups.
+   * @param bool $excludeHidden exclude hidden groups.
    *
    * @access public
    * @static
@@ -1002,6 +1000,18 @@ WHERE  id = %1";
     return CRM_Core_Permission::group($groupType, $excludeHidden);
   }
 
+  /**
+   * Fetch groups in a nested format suitable for use in select form element
+   * @param bool $checkPermissions
+   * @param string|null $groupType
+   * @param bool $excludeHidden
+   * @return array
+   */
+  public static function nestedGroup($checkPermissions = TRUE, $groupType = NULL, $excludeHidden = TRUE) {
+    $groups = $checkPermissions ? self::group($groupType, $excludeHidden) : self::allGroup($groupType, $excludeHidden);
+    return CRM_Contact_BAO_Group::getGroupsHierarchy($groups, NULL, '&nbsp;&nbsp;', TRUE);
+  }
+
   /**
    * Get all permissioned groups from database
    *
index 690bee73e507c77ccccaa9083c2acd088537e870..f0c468883436db48a5d69280f25a8d02584e4672 100755 (executable)
@@ -199,8 +199,9 @@ class CRM_Event_Form_ManageEvent_ScheduleReminders extends CRM_Event_Form_Manage
 
     $this->addEntityRef('recipient_manual_id', ts('Manual Recipients'), array('multiple' => true));
 
+    $groups = CRM_Contact_BAO_Group::getGroupsHierarchy(CRM_Core_PseudoConstant::staticGroup(), NULL, '&nbsp;&nbsp;', TRUE);
     $this->add('select', 'group_id', ts('Group'),
-      CRM_Core_PseudoConstant::staticGroup(), FALSE, array('class' => 'crm-select2 huge')
+      $groups, FALSE, array('class' => 'crm-select2 huge')
     );
 
     CRM_Mailing_BAO_Mailing::commonCompose($this);
index 03dcb9912808eb9ce2e0e8630696b1600f4ab60a..e5a88fe3baa50e04726bd08a5fa16ca1ca0ac277 100644 (file)
@@ -302,7 +302,8 @@ FROM   {$this->_componentTable}
       $this->addGroup($postalMailing, 'postal_mailing_export', ts('Postal Mailing Export'), '<br/>');
 
       $this->addElement('select', 'additional_group', ts('Additional Group for Export'),
-        array('' => ts('- select group -')) + CRM_Core_PseudoConstant::group()
+        array('' => ts('- select group -')) + CRM_Core_PseudoConstant::nestedGroup(),
+        array('class' => 'crm-select2 huge')
       );
     }
 
index acebc2ae35c4ab0a93712b59e240c9385d932190..71cd443bcc877cb04dd27735b63e1853f33c12e1 100644 (file)
@@ -101,7 +101,7 @@ class CRM_Financial_Form_BatchTransaction extends CRM_Contribute_Form {
       )
     );
 
-    $this->_group = CRM_Core_PseudoConstant::group();
+    $this->_group = CRM_Core_PseudoConstant::nestedGroup();
 
     // multiselect for groups
     if ($this->_group) {
index e0621be85dc7e9cd123941e975861cb84a38ba31..4fd9df591065d71ddf80d82eeecf5386853d0990 100644 (file)
@@ -214,7 +214,7 @@ class CRM_Mailing_Form_Group extends CRM_Contact_Form_Task {
     $this->addElement('checkbox', 'dedupe_email', ts('Remove duplicate emails?'));
 
     //get the mailing groups.
-    $groups = CRM_Core_PseudoConstant::group('Mailing');
+    $groups = CRM_Core_PseudoConstant::nestedGroup('Mailing');
     if ($hiddenMailingGroup) {
       $groups[$hiddenMailingGroup] =
         CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $hiddenMailingGroup, 'title');
@@ -235,7 +235,7 @@ class CRM_Mailing_Form_Group extends CRM_Contact_Form_Task {
       $this->add('select', 'baseGroup',
         ts('Unsubscription Group'),
         array(
-          '' => ts('- select -')) + $staticGroups,
+          '' => ts('- select -')) + CRM_Contact_BAO_Group::getGroupsHierarchy($staticGroups, NULL, '&nbsp;&nbsp;', TRUE),
         TRUE,
         array('class' => 'crm-select2 huge')
       );
index 85ae9302c7020aa01205edce05890aa26dc9e437..2e70b5ac93310771c70b58d07ecc48f8d6afbeb9 100644 (file)
@@ -1108,13 +1108,13 @@ class CRM_Report_Form extends CRM_Core_Form {
 
     if (CRM_Core_Permission::check('administer Reports') && $this->_add2groupSupported) {
       $this->addElement('select', 'groups', ts('Group'),
-        array('' => ts('- select group -')) + CRM_Core_PseudoConstant::staticGroup()
+        array('' => ts('Add Contacts to Group')) + CRM_Core_PseudoConstant::nestedGroup(),
+        array('class' => 'crm-select2 crm-action-menu action-icon-plus huge')
       );
       $this->assign('group', TRUE);
     }
 
-    $label = ts('Add These Contacts to Group');
-    $this->addElement('submit', $this->_groupButtonName, $label, array('onclick' => 'return checkGroup();'));
+    $this->addElement('submit', $this->_groupButtonName, '', array('style' => 'display: none;'));
 
     $this->addChartOptions();
     $this->addButtons(array(
index 6270e4fe31e05b82a88214e623b746d06becdd00..ca4ac6d06cb6afaf20ca3ee923e3f6fffc5c2e1c 100644 (file)
@@ -121,7 +121,7 @@ class CRM_SMS_Form_Group extends CRM_Contact_Form_Task {
     );
 
     //get the mailing groups.
-    $groups = CRM_Core_PseudoConstant::group('Mailing');
+    $groups = CRM_Core_PseudoConstant::nestedGroup('Mailing');
 
     //get the sms mailing list
     $mailings = CRM_Mailing_PseudoConstant::completed('sms');
index 70c4fb49600777e60f4ff2670e1e0c7f3cdef195..0cba19d649577c28e2b296a126710f52ebe596c2 100644 (file)
                         {/if}
                         {if $form.groups}
                             <tr>
-                                <td>{$form.groups.html|crmAddClass:big}</td>
-                                <td align="right">{$form.$group.html}</td>
+                                <td>
+                                  {$form.groups.html}{$form.$group.html}
+                                  <script type="text/javascript">
+                                    {literal}
+                                    (function($) {
+                                      $('#groups').val('').change(function() {
+                                        CRM.confirm({
+                                          message: ts({/literal}'{ts escape='js' 1='<em>%1</em>'}Add all contacts to %1 group?{/ts}'{literal}, {1: $('option:selected', '#groups').text()})
+                                        })
+                                          .on('crmConfirm:yes', function() {
+                                            $('#groups').siblings(':submit').click();
+                                          });
+                                        $('#groups').select2('val', '');
+                                      });
+                                    })(CRM.$);
+                                    {/literal}
+                                  </script>
+                                </td>
                             </tr>
                         {/if}
                     </table>