crmCxn - Add enable/disable buttons (forward port #6932)
authorCiviCRM <info@civicrm.org>
Thu, 7 Jan 2016 23:48:23 +0000 (15:48 -0800)
committerCiviCRM <info@civicrm.org>
Thu, 7 Jan 2016 23:48:23 +0000 (15:48 -0800)
ang/crmCxn/ManageCtrl.html
ang/crmCxn/ManageCtrl.js
api/v3/Cxn.php

index a595143855eea6d095f3ad73407ade7dab7fa98e..03fb095064b6452497283b740adaf14fbb59ada6 100644 (file)
             >{{cxn.app_meta.title}}</a>
       </td>
       <td><div ng-bind-html="cxn.app_meta.desc"></div></td>
-      <td>{{cxn.is_active ? ts('Enabled') : ts('Disabled')}}</td>
+      <td>{{cxn.is_active=="1" ? ts('Enabled') : ts('Disabled')}}</td>
       <td>
         <span>
-            <!--
-            <a class="action-item crm-hover-button" ng-click="toggleCxn(cxn)">{{cxn.is_active ? ts('Disable') : ts('Enable') }}</a>
-            -->
             <a class="action-item crm-hover-button" ng-click="openLink(cxn.app_meta, 'settings', {title: ts('%1: Settings (External)', {1: cxn.app_meta.title})})" ng-show="cxn.app_meta.links.settings">{{ts('Settings')}}</a>
             <span class="btn-slide crm-hover-button">{{ts('more')}}
               <ul class="panel" style="display: none;">
@@ -57,6 +54,9 @@
                     {{ts('Support')}}
                   </a>
                 </li>
+                <li>
+                  <a class="action-item crm-hover-button" ng-click="toggleCxn(cxn)">{{ cxn.is_active=="1" ? ts('Disable') : ts('Enable')}}</a>
+                </li>
                 <li>
                   <a class="action-item crm-hover-button"
                      crm-confirm='{width: "65%", resizable: true, title:ts("%1: Reconnect", {1: cxn.app_meta.title}), templateUrl: "~/crmCxn/ConfirmReconnectCtrl.html", export: {cxn: cxn, appMeta: findAppByAppId(cxn.app_guid)}}'
index 634b67853070973582141767b7d6c5b775969aff..12bba3c4e5aad7d5954e2270edd802845af68050 100644 (file)
@@ -90,8 +90,9 @@
     };
 
     $scope.toggleCxn = function toggleCxn(cxn) {
-      var reg = crmApi('Cxn', 'create', {id: cxn.id, is_active: !cxn.is_active, debug: 1}).then(function(){
-        cxn.is_active = !cxn.is_active;
+      var is_active = (cxn.is_active=="1" ? 0 : 1); // we switch the flag
+      var reg = crmApi('Cxn', 'create', {id: cxn.id, app_guid: cxn.app_meta.appId, is_active: is_active, debug: 1}).then(function(){
+        cxn.is_active = is_active;
       });
       return block(crmStatus({start: ts('Saving...'), success: ts('Saved')}, reg));
     };
index af39133707fafa59531660913a65021790e15247..25d9ee9f5a0151719c7dbf880b130c2e204a93de 100644 (file)
@@ -284,3 +284,52 @@ function civicrm_api3_cxn_getcfg($params) {
     'page' => $params['page'],
   ));
 }
+
+/**
+ * Creates or modifies a Cxn row.
+ *
+ * @param array $params
+ *   Array with keys:
+ *   - id, cxn_guid OR app_guid: string.
+ *   - is_active: boolean.
+ *   - options: JSON
+ * @return page
+ * @throws Exception
+ */
+function civicrm_api3_cxn_create($params) {
+  $result = "";
+
+  try {
+    // get the ID
+    if (!empty($params['id'])) {
+      $cxnId = $params['id'];
+    }
+    else {
+      $cxnId = _civicrm_api3_cxn_parseCxnId($params);
+    }
+
+    // see if it's sth to update
+    if (isset($params['options']) || isset($params['is_active'])) {
+
+      $dao = new CRM_Cxn_DAO_Cxn();
+      $dao->id = $cxnId;
+
+      if ($dao->find()) {
+        if (isset($params['is_active'])) {
+          $dao->is_active = (int) $params['is_active'];
+        }
+        if (isset($params['options'])) {
+          $dao->options = $params['options'];
+        }
+
+        $result = $dao->save();
+      }
+
+    }
+    return civicrm_api3_create_success($result, $params, 'Cxn', 'create');
+
+  }
+  catch(Exception $ex){
+    throw $ex;
+  }
+}