From 8188b8ae0f3478e21c23ab5e7865774f85a2da35 Mon Sep 17 00:00:00 2001 From: Helena Date: Sun, 11 Oct 2015 16:25:36 +0100 Subject: [PATCH] Enable/Disable switcher button added. --- ang/crmCxn/ManageCtrl.html | 6 ++--- ang/crmCxn/ManageCtrl.js | 5 ++-- api/v3/Cxn.php | 51 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/ang/crmCxn/ManageCtrl.html b/ang/crmCxn/ManageCtrl.html index 8a402e239b..b8a84fa0d7 100644 --- a/ang/crmCxn/ManageCtrl.html +++ b/ang/crmCxn/ManageCtrl.html @@ -25,12 +25,10 @@ {{cxn.app_meta.title}}
- {{cxn.is_active ? ts('Enabled') : ts('Disabled')}} + {{cxn.is_active=="1" ? ts('Enabled') : ts('Disabled')}} - {{ts('Settings')}} + {{ cxn.is_active=="1" ? ts('Disable') : ts('Enable')}} {{ts('Logs')}} {{ts('Docs')}} {{ts('Support')}} diff --git a/ang/crmCxn/ManageCtrl.js b/ang/crmCxn/ManageCtrl.js index 9e7d127c75..a0e90d80c4 100644 --- a/ang/crmCxn/ManageCtrl.js +++ b/ang/crmCxn/ManageCtrl.js @@ -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)); }; diff --git a/api/v3/Cxn.php b/api/v3/Cxn.php index cf1a1710f2..4bfa899701 100644 --- a/api/v3/Cxn.php +++ b/api/v3/Cxn.php @@ -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; + } +} -- 2.25.1