Update SMS providers form for 4.5
authorColeman Watts <coleman@civicrm.org>
Fri, 15 Aug 2014 19:20:54 +0000 (20:20 +0100)
committerColeman Watts <coleman@civicrm.org>
Fri, 15 Aug 2014 19:20:54 +0000 (20:20 +0100)
CRM/SMS/Form/Provider.php
templates/CRM/SMS/Form/Provider.tpl

index b6dd2230cac6b93ea3af957f62f6af37cba9f52f..6ec36832fb64c08715ce0246aa84068bcc0572a2 100644 (file)
@@ -70,42 +70,29 @@ class CRM_SMS_Form_Provider extends CRM_Core_Form {
   public function buildQuickForm() {
     parent::buildQuickForm();
 
+    $this->addButtons(array(
+        array(
+          'type' => 'next',
+          'name' => $this->_action & CRM_Core_Action::DELETE ? ts('Delete') : ts('Save'),
+          'isDefault' => TRUE,
+        ),
+        array(
+          'type' => 'cancel',
+          'name' => ts('Cancel'),
+        ),
+      )
+    );
+
     if ($this->_action & CRM_Core_Action::DELETE) {
-      $this->addButtons(array(
-          array(
-            'type' => 'next',
-            'name' => ts('Delete'),
-            'isDefault' => TRUE,
-          ),
-          array(
-            'type' => 'cancel',
-            'name' => ts('Cancel'),
-          ),
-        )
-      );
       return;
     }
-    else {
-      $this->addButtons(array(
-          array(
-            'type' => 'next',
-            'name' => ts('Save'),
-            'isDefault' => TRUE,
-          ),
-          array(
-            'type' => 'cancel',
-            'name' => ts('Cancel'),
-          ),
-        )
-      );
-    }
 
     $attributes = CRM_Core_DAO::getAttribute('CRM_SMS_DAO_Provider');
 
     $providerNames = CRM_Core_OptionGroup::values('sms_provider_name', FALSE, FALSE, FALSE, NULL, 'label');
     $apiTypes = CRM_Core_OptionGroup::values('sms_api_type', FALSE, FALSE, FALSE, NULL, 'label');
 
-    $this->add('select', 'name', ts('Name'), array('' => '- select -') + $providerNames, TRUE, array('onchange' => "reload(true)"));
+    $this->add('select', 'name', ts('Name'), array('' => '- select -') + $providerNames, TRUE);
 
     $this->add('text', 'title', ts('Title'),
       $attributes['title'], TRUE
index f75e6f1af8860dd85e89ce882a36ec0148cb89c7..a27b1360cceb222f4bb46161bc7bdb841aad988b 100644 (file)
 {if $action eq 1  or $action eq 2}
 <script type="text/javascript" >
 {literal}
-    function reload(refresh) {
-        var provider = document.getElementById("name");
-        var url = {/literal}"{$refreshURL}"{literal}
-        var post = url + "&key=" + provider.value;
-        if( refresh ) {
-            window.location.href = post;
-        }
-    }
+  CRM.$(function($) {
+    var $form = $("#{/literal}{$form.formName}{literal}");
+    $('select[name=name]', $form).change(function() {
+      var url = {/literal}"{$refreshURL}"{literal} + "&key=" + this.value;
+      $(this).closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet({url: url}).crmSnippet('refresh');
+    });
+  });
 {/literal}
 </script>
 {/if}