copyright and version fixes
[civicrm-core.git] / CRM / Group / Form / Edit.php
index d0c026dbd04c8a2cdce3d7f20e9bc12b19e24c87..ff4a18e62acbd6d3825ea578dd39f78763497fc2 100644 (file)
@@ -225,6 +225,11 @@ class CRM_Group_Form_Edit extends CRM_Core_Form {
       return;
     }
 
+    // We want the "new group" form to redirect the user
+    if ($this->_action == CRM_Core_Action::ADD) {
+      $this->preventAjaxSubmit();
+    }
+
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'title', ts('Name') . ' ',
       CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'), TRUE
@@ -250,51 +255,9 @@ class CRM_Group_Form_Edit extends CRM_Core_Form {
 
     $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::groupVisibility(), TRUE);
 
-    $groupNames = CRM_Core_PseudoConstant::group();
+    //CRM-14190
+    $parentGroups = self::buildParentGroups($this);
 
-    $parentGroups = $parentGroupElements = array();
-    if (isset($this->_id) && !empty($this->_groupValues['parents'])) {
-      $parentGroupIds = explode(',', $this->_groupValues['parents']);
-      foreach ($parentGroupIds as $parentGroupId) {
-        $parentGroups[$parentGroupId] = $groupNames[$parentGroupId];
-        if (array_key_exists($parentGroupId, $groupNames)) {
-          $parentGroupElements[$parentGroupId] = $groupNames[$parentGroupId];
-          $this->addElement('checkbox', "remove_parent_group_$parentGroupId",
-            $groupNames[$parentGroupId]
-          );
-        }
-      }
-    }
-    $this->assign_by_ref('parent_groups', $parentGroupElements);
-
-    if (isset($this->_id)) {
-      $potentialParentGroupIds = CRM_Contact_BAO_GroupNestingCache::getPotentialCandidates($this->_id,
-        $groupNames
-      );
-    }
-    else {
-      $potentialParentGroupIds = array_keys($groupNames);
-    }
-
-    $parentGroupSelectValues = array('' => '- ' . ts('select') . ' -');
-    foreach ($potentialParentGroupIds as $potentialParentGroupId) {
-      if (array_key_exists($potentialParentGroupId, $groupNames)) {
-        $parentGroupSelectValues[$potentialParentGroupId] = $groupNames[$potentialParentGroupId];
-      }
-    }
-
-    if (count($parentGroupSelectValues) > 1) {
-      if (CRM_Core_Permission::isMultisiteEnabled()) {
-        $required = empty($parentGroups) ? TRUE : FALSE;
-        $required = (($this->_id && CRM_Core_BAO_Domain::isDomainGroup($this->_id)) ||
-          !isset($this->_id)
-        ) ? FALSE : $required;
-      }
-      else {
-        $required = FALSE;
-      }
-      $this->add('select', 'parents', ts('Add Parent'), $parentGroupSelectValues, $required);
-    }
     if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) {
       //group organization Element
       $props = array('api' => array('params' => array('contact_type' => 'Organization')));
@@ -438,8 +401,8 @@ WHERE  title = %1
       $group = CRM_Contact_BAO_Group::create($params);
 
       /*
-             * Remove any parent groups requested to be removed
-             */
+       * Remove any parent groups requested to be removed
+       */
 
       if (!empty($this->_groupValues['parents'])) {
         $parentGroupIds = explode(',', $this->_groupValues['parents']);
@@ -471,5 +434,65 @@ WHERE  title = %1
       CRM_Contact_BAO_GroupNestingCache::update();
     }
   }
+
+  /*
+   * Build parent groups form elements
+   *
+   * @obj form object passed by reference
+   *
+   * @return parent groups array
+   * @static
+   * @access public
+   */
+  static function buildParentGroups( &$obj ) {
+    $groupNames = CRM_Core_PseudoConstant::group();
+    $parentGroups = $parentGroupElements = array();
+    if (isset($obj->_id) &&
+      CRM_Utils_Array::value('parents', $obj->_groupValues)
+    ) {
+      $parentGroupIds = explode(',', $obj->_groupValues['parents']);
+      foreach ($parentGroupIds as $parentGroupId) {
+        $parentGroups[$parentGroupId] = $groupNames[$parentGroupId];
+        if (array_key_exists($parentGroupId, $groupNames)) {
+          $parentGroupElements[$parentGroupId] = $groupNames[$parentGroupId];
+          $obj->addElement('checkbox', "remove_parent_group_$parentGroupId",
+            $groupNames[$parentGroupId]
+          );
+        }
+      }
+    }
+    $obj->assign_by_ref('parent_groups', $parentGroupElements);
+
+    if (isset($obj->_id)) {
+      $potentialParentGroupIds = CRM_Contact_BAO_GroupNestingCache::getPotentialCandidates($obj->_id,
+        $groupNames
+      );
+    }
+    else {
+      $potentialParentGroupIds = array_keys($groupNames);
+    }
+
+    $parentGroupSelectValues = array('' => '- ' . ts('select group') . ' -');
+    foreach ($potentialParentGroupIds as $potentialParentGroupId) {
+      if (array_key_exists($potentialParentGroupId, $groupNames)) {
+        $parentGroupSelectValues[$potentialParentGroupId] = $groupNames[$potentialParentGroupId];
+      }
+    }
+
+    if (count($parentGroupSelectValues) > 1) {
+      if (CRM_Core_Permission::isMultisiteEnabled()) {
+        $required = empty($parentGroups) ? TRUE : FALSE;
+        $required = (($obj->_id && CRM_Core_BAO_Domain::isDomainGroup($obj->_id)) ||
+          !isset($obj->_id)
+        ) ? FALSE : $required;
+      }
+      else {
+        $required = FALSE;
+      }
+      $obj->add('select', 'parents', ts('Add Parent'), $parentGroupSelectValues, $required, array('class' => 'crm-select2'));
+    }
+
+    return $parentGroups;
+  }
 }