Merge pull request #10806 from JMAConsulting/CRM-20610-2
[civicrm-core.git] / ang / crmCxn / ManageCtrl.js
index 634b67853070973582141767b7d6c5b775969aff..cd843c3304ae7a70508bef764e9dbff60be9131c 100644 (file)
     };
 
     $scope.register = function(appMeta) {
-      var reg = crmApi('Cxn', 'register', {app_guid: appMeta.appId}).then($scope.refreshCxns);
+      var reg = crmApi('Cxn', 'register', {app_guid: appMeta.appId}).then($scope.refreshCxns).then(function() {
+        if (appMeta.links.welcome) {
+          return $scope.openLink(appMeta, 'welcome', {title: ts('%1: Welcome (External)', {1: appMeta.title})});
+        }
+      });
       return block(crmStatus({start: ts('Connecting...'), success: ts('Connected')}, reg));
     };
 
     $scope.reregister = function(appMeta) {
-      var reg = crmApi('Cxn', 'register', {app_guid: appMeta.appId}).then($scope.refreshCxns);
+      var reg = crmApi('Cxn', 'register', {app_guid: appMeta.appId}).then($scope.refreshCxns).then(function() {
+        if (appMeta.links.welcome) {
+          return $scope.openLink(appMeta, 'welcome', {title: ts('%1: Welcome (External)', {1: appMeta.title})});
+        }
+      });
       return block(crmStatus({start: ts('Reconnecting...'), success: ts('Reconnected')}, reg));
     };
 
     };
 
     $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));
     };
 
     $scope.openLink = function openLink(appMeta, page, options) {
-      var promise = crmApi('Cxn', 'getlink', {app_guid: appMeta.appId, page: page}).then(function(result) {
+      var promise = crmApi('Cxn', 'getlink', {app_guid: appMeta.appId, page_name: page}).then(function(result) {
         var mode = result.values.mode ? result.values.mode : 'popup';
         switch (result.values.mode) {
           case 'iframe':