Enable/Disable switcher button added.
authorHelena <hgarcia@es.amnesty.org>
Sun, 11 Oct 2015 15:25:36 +0000 (16:25 +0100)
committerHelena <hgarcia@es.amnesty.org>
Sun, 11 Oct 2015 16:11:41 +0000 (17:11 +0100)
ang/crmCxn/ManageCtrl.html
ang/crmCxn/ManageCtrl.js
api/v3/Cxn.php

index 8a402e239b6070598c1b3cdcc87ad20537637d7d..b8a84fa0d732b67570435f927d33890e05bbd4ad 100644 (file)
     <tr ng-repeat="cxn in cxns  | orderBy:cxnOrder.get()">
       <td>{{cxn.app_meta.title}}</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>
-        <!--
-        <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>
+        <a class="action-item crm-hover-button" ng-click="toggleCxn(cxn)">{{ cxn.is_active=="1" ? ts('Disable') : ts('Enable')}}</a>
         <a class="action-item crm-hover-button" ng-click="openLink(cxn.app_meta, 'logs', {title: ts('%1: Logs (External)', {1: cxn.app_meta.title})})" ng-show="cxn.app_meta.links.logs">{{ts('Logs')}}</a>
         <a class="action-item crm-hover-button" ng-click="openLink(cxn.app_meta, 'docs', {title: ts('%1: Documentation (External)', {1: cxn.app_meta.title})})" ng-show="cxn.app_meta.links.docs">{{ts('Docs')}}</a>
         <a class="action-item crm-hover-button" ng-click="openLink(cxn.app_meta, 'support', {title: ts('%1: Support (External)', {1: cxn.app_meta.title})})" ng-show="cxn.app_meta.links.support">{{ts('Support')}}</a>
index 9e7d127c7545da1c1cb6ec056c19af38b79c1137..a0e90d80c47be68523c0cf9bd9e7f12d21841fca 100644 (file)
@@ -62,8 +62,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 cf1a1710f20c7f03557903260d8da970ec3f5643..4bfa899701778f4f1b9ee27df9f755023398a21c 100644 (file)
@@ -245,3 +245,54 @@ function civicrm_api3_cxn_getlink($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();
+      }
+      else {
+        //TODO: create?
+      }
+
+    }
+    return civicrm_api3_create_success($result, $params, 'Cxn', 'create');
+
+  } catch( Exception $ex){      
+    throw $ex;
+  }
+}