crmCxnManageCtrl - Show links for settings, docs, support, logs
authorTim Otten <totten@civicrm.org>
Mon, 29 Jun 2015 07:23:39 +0000 (00:23 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 14 Jul 2015 04:00:08 +0000 (21:00 -0700)
ang/crmCxn/ManageCtrl.html
ang/crmCxn/ManageCtrl.js

index e6c0331da4507748bc3f40225333d99ad07a2e50..8a402e239b6070598c1b3cdcc87ad20537637d7d 100644 (file)
         <!--
         <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="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>
         <a class="action-item crm-hover-button"
            crm-confirm='{width: "65%", resizable: true, title: ts("Disconnect"), message: ts("Are you sure you want to disconnect \"%1?\". Doing so may permanently destroy data linkage.", {1: cxn.app_meta.title})}'
            on-yes="unregister(cxn.app_meta)"
index a0eb90386a6b6de21c8c59dd223e8a83b6163c74..794646f75f58e6606d7e10da140f63d92281b9d4 100644 (file)
@@ -1,6 +1,6 @@
 (function(angular, $, _) {
 
-  angular.module('crmCxn').controller('CrmCxnManageCtrl', function CrmCxnManageCtrl($scope, apiCalls, crmApi, crmUiAlert, crmBlocker, crmStatus, $timeout) {
+  angular.module('crmCxn').controller('CrmCxnManageCtrl', function CrmCxnManageCtrl($scope, apiCalls, crmApi, crmUiAlert, crmBlocker, crmStatus, $timeout, dialogService) {
     var ts = $scope.ts = CRM.ts(null);
     $scope.appMetas = apiCalls.appMetas.values;
     $scope.cxns = apiCalls.cxns.values;
       });
       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 mode = result.values.mode ? result.values.mode : 'popup';
+        switch (result.values.mode) {
+          case 'iframe':
+            var passThrus = ['height', 'width']; // Options influenced by remote server.
+            options = angular.extend(_.pick(result.values, passThrus), options);
+            $scope.openIframe(result.values.url, options);
+            break;
+          case 'popup':
+            CRM.alert(ts('The page "%1" will open in a popup. If it does not appear automatically, check your browser for notifications.', {1: options.title}), '', 'info');
+            window.open(result.values.url, 'cxnSettings', 'resizable,scrollbars,status');
+            break;
+          case 'redirect':
+            window.location = result.values.url;
+            break;
+          default:
+            CRM.alert(ts('Cannot open link. Unrecognized mode.'), '', 'error');
+        }
+      });
+      return block(crmStatus({start: ts('Opening...'), success: ''}, promise));
+    };
+
+    // @param Object options -- see dialogService.open
+    $scope.openIframe = function openIframe(url, options) {
+      var model = {
+        url: url
+      };
+      options = CRM.utils.adjustDialogDefaults(angular.extend(
+        {
+          autoOpen: false,
+          height: 'auto',
+          width: '40%',
+          title: ts('External Link')
+        },
+        options
+      ));
+      return dialogService.open('cxnLinkDialog', '~/crmCxn/LinkDialogCtrl.html', model, options)
+        .then(function(item) {
+          mailing.msg_template_id = item.id;
+          return item;
+        });
+    };
   });
 
 })(angular, CRM.$, CRM._);