CRM-15842 - Custom group form cleanup
authorColeman Watts <coleman@civicrm.org>
Tue, 20 Jan 2015 15:03:49 +0000 (10:03 -0500)
committerColeman Watts <coleman@civicrm.org>
Tue, 20 Jan 2015 16:26:11 +0000 (11:26 -0500)
----------------------------------------
* CRM-15842: Custom field form improvements
  https://issues.civicrm.org/jira/browse/CRM-15842

CRM/Core/Form.php
CRM/Custom/Form/Group.php
templates/CRM/Custom/Form/Group.tpl

index b62ce0277ac259aba68049bd4ffbfb17e5e0cec5..1877210f4ccfcf7be599790fa4f6ed75f471e34c 100644 (file)
@@ -513,6 +513,10 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     foreach ($params as $button) {
       $attrs = array('class' => 'crm-form-submit') + (array) CRM_Utils_Array::value('js', $button);
 
+      if (!empty($button['class'])) {
+        $attrs['class'] .= ' ' . $button['class'];
+      }
+
       if (!empty($button['isDefault'])) {
         $attrs['class'] .= ' default';
       }
index 61b90ecd109750a81340d1a96687850356ce619c..7bcee88ffd3910f552c3e6978905323914ff9b84 100644 (file)
@@ -387,7 +387,7 @@ class CRM_Custom_Form_Group extends CRM_Core_Form {
       ),
     );
     if (!$this->_isGroupEmpty && !empty($this->_subtypes)) {
-      $buttons[0]['js'] = array('onclick' => "return warnDataLoss()");
+      $buttons[0]['class'] = 'crm-warnDataLoss';
     }
     $this->addButtons($buttons);
 
index 998f3ebc166fe7ebfbc83dc6c1a1c6400d2f460e..6ef11d74f5f2ad6f468c713ce35af3cec82d8d37 100644 (file)
 <script type="text/Javascript">
 CRM.$(function($) {
 
-  showHideStyle();
-  $('#extends_0').change(function() {
-    showHideStyle();
-  });
+  $('#extends_0').each(showHideStyle).change(showHideStyle);
 
-  var  isGroupEmpty = "{/literal}{$isGroupEmpty}{literal}";
+  var isGroupEmpty = "{/literal}{$isGroupEmpty}{literal}";
   if (isGroupEmpty) {
     showRange(true);
   }
-  $('#is_multiple').click(function() {
-    showRange();
-  });
+  $('#is_multiple').click(showRange);
 
   function showHideStyle() {
-    var isShow  = false;
-    var extend  = $('#extends_0').val();
-
-    var contactTypes    = {/literal}{$contactTypes}{literal};
-    var showStyle       = "{/literal}{$showStyle}{literal}";
-    var showMultiple    = "{/literal}{$showMultiple}{literal}";
-    var showMaxMultiple = "{/literal}{$showMaxMultiple}{literal}";
-
-    if ($.inArray(extend, contactTypes) >= 0) {
-      isShow  = true;
-    }
+    var
+      extend = $(this).val(),
+      contactTypes = {/literal}{$contactTypes}{literal},
+      showStyle = "{/literal}{$showStyle}{literal}",
+      showMultiple = "{/literal}{$showMultiple}{literal}",
+      showMaxMultiple = "{/literal}{$showMaxMultiple}{literal}",
+      isShow = ($.inArray(extend, contactTypes) >= 0);
 
     if (isShow) {
-      $("tr#style").show();
-      $("tr#is_multiple").show();
+      $("tr#style, tr#is_multiple").show();
       if ($('#is_multiple :checked').length) {
         $("tr#multiple").show();
       }
     }
     else {
-      $("tr#style").hide();
-      $("tr#is_multiple").hide();
-      $("tr#multiple").hide();
+      $("tr#style, tr#is_multiple, tr#multiple").hide();
     }
 
     if (showStyle) {
@@ -131,14 +119,13 @@ CRM.$(function($) {
     }
 
     if (showMultiple) {
-      $("tr#style").show();
-      $("tr#is_multiple").show();
+      $("tr#style, tr#is_multiple").show();
     }
 
     if (!showMaxMultiple) {
       $("tr#multiple").hide();
     }
-    else if($( '#is_multiple').prop('checked')) {
+    else if ($('#is_multiple').prop('checked')) {
       $("tr#multiple").show();
     }
   }
@@ -152,7 +139,7 @@ CRM.$(function($) {
     else {
       $('#collapse_display').prop('checked', 'checked');
       $("tr#multiple").hide();
-      if (!onFormLoad) {
+      if (onFormLoad !== true) {
         $("select#style option[value='Inline']").prop("selected", true);
       }
     }
@@ -169,23 +156,24 @@ CRM.$(function($) {
       subtypes.style.display = 'inline';
     }
   }
-});
 
-function warnDataLoss() {
-  var submittedSubtypes = cj('#extends_1').val();
-  var defaultSubtypes   = {/literal}{$defaultSubtypes}{literal};
+  // When removing sub-types
+  $('.crm-warnDataLoss').on('click', function() {
+    var submittedSubtypes = $('#extends_1').val();
+    var defaultSubtypes = {/literal}{$defaultSubtypes}{literal};
+
+    var warning = false;
+    $.each(defaultSubtypes, function(index, subtype) {
+      if ($.inArray(subtype, submittedSubtypes) < 0) {
+        warning = true;
+      }
+    });
 
-  var warning = false;
-  cj.each(defaultSubtypes, function(index, subtype) {
-    if (cj.inArray(subtype, submittedSubtypes) < 0) {
-      warning = true;
+    if (warning) {
+      return confirm({/literal}'{ts escape='js'}Warning: You have chosen to remove one or more subtypes. This will cause any custom data records associated with those subtypes to be removed.{/ts}'{literal});
     }
+    return true;
   });
-
-  if (warning) {
-    return confirm( 'One or more subtypes has been un-selected from the list. Any custom data associated with un-selected subtype would be removed. Click OK to proceed.' );
-  }
-  return true;
-}
+});
 </script>
 {/literal}