5 .module("nero.app.external-services")
6 .directive("connectorDirective", connectorDirective);
8 function connectorDirective() {
15 templateUrl: Global.Theme.getURLPortal() + Liferay.ThemeDisplay.getPathJavaScript() + "/angularjs/app-external-services/connector/connector.html?t="+Liferay.extTimestamp,
16 controller: ConnectorController,
17 controllerAs: "ConnectorCtrl",
18 bindToController: true
22 ConnectorController.$inject = ["$window", "$sce", "toastr", "connectorService"];
24 function ConnectorController($window, $sce, toastr, connectorService) {
27 vm.contextPath = contextPath;
32 vm.getIframeUrl = getIframeUrl;
33 vm.onChangeUrl = onChangeUrl;
34 vm.openInNewTab = openInNewTab;
36 var serviceWindow = null;
38 // Load current service configuration
39 connectorService.loadConnectorConfig().then(function(config) {
40 vm.serviceSchoolUrls = config.serviceSchoolUrls;
41 if (vm.serviceSchoolUrls.length > 0) {
42 vm.selectedUrl = vm.serviceSchoolUrls[0].serviceUrl;
43 if (vm.page != undefined && vm.page.length > 0) {
44 vm.selectedUrl += "?page="+vm.page;
48 vm.serviceName = config.serviceName;
49 vm.serviceKey = config.serviceKey;
51 ["catch"](function(message) {
52 toastr.error(message);
56 Return url to display in iframe (need to check it before display)
58 function getIframeUrl() {
59 return $sce.trustAsResourceUrl(vm.selectedUrl);
63 Return true if the current URL is secure
70 // Check if url start with https
71 if (vm.selectedUrl.lastIndexOf("https", 0) != 0) {
74 else if (vm.selectedUrl.indexOf("login?service=") != -1) {
75 return (vm.selectedUrl.indexOf("service=https") != -1);
83 If the current URL is not secure open it in new tab
85 function onChangeUrl() {
92 Open current URL in new tab
94 function openInNewTab() {
95 if(serviceWindow == null || serviceWindow.closed) {
96 serviceWindow = $window.open(vm.selectedUrl, "_blank");
99 serviceWindow.location = vm.selectedUrl;