<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>
};
$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));
};
'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;
+ }
+}