|
| 1 | +function($scope, $uibModal, $timeout, spUtil) { |
| 2 | + var c = this; |
| 3 | + var reportId = c.options.report_id || ''; |
| 4 | + c.rectangleId = c.widget.rectangle_id || c.data.rectangleId; |
| 5 | + c.showTitle = (c.options.show_title === true || c.options.show_title === 'true'); |
| 6 | + c.title = c.options.title || ''; |
| 7 | + |
| 8 | + if (c.options.widget_parameters) { |
| 9 | + c.initialMessage = c.data.ch.i18n.building; |
| 10 | + window.chartHelpers = window.chartHelpers || {}; |
| 11 | + $.extend(window.chartHelpers, c.data.ch); |
| 12 | + |
| 13 | + $timeout(function() { |
| 14 | + var targetEl = $("#report-widget-" + c.rectangleId); |
| 15 | + embedReportById(targetEl, reportId); |
| 16 | + |
| 17 | + $timeout(function() { |
| 18 | + targetEl.off('click', 'a[href*="change_request.do?sys_id"]'); |
| 19 | + |
| 20 | + targetEl.on('click', 'a[href*="change_request.do?sys_id"]', function(event) { |
| 21 | + event.preventDefault(); |
| 22 | + var href = $(this).attr('href') || ''; |
| 23 | + var match = href.match(/sys_id=([a-f0-9]{32})/i); |
| 24 | + var sysId = match ? match[1] : ''; |
| 25 | + |
| 26 | + var modalData = { |
| 27 | + number: '', |
| 28 | + short_description: '', |
| 29 | + description: '', |
| 30 | + sys_id: sysId |
| 31 | + }; |
| 32 | + |
| 33 | + // Open modal immediately |
| 34 | + $uibModal.open({ |
| 35 | + controller: function($scope, $uibModalInstance, $sce) { |
| 36 | + $scope.data = modalData; |
| 37 | + |
| 38 | + $scope.getTrustedDescription = function() { |
| 39 | + if (!$scope.data.description) return ''; |
| 40 | + var text = $scope.data.description; |
| 41 | + |
| 42 | + // Convert line breaks to <br> |
| 43 | + text = text.replace(/\n/g, '<br>'); |
| 44 | + |
| 45 | + // Convert URLs to links |
| 46 | + var urlRegex = /(\bhttps?:\/\/[^\s<]+)/gi; |
| 47 | + text = text.replace(urlRegex, function(url) { |
| 48 | + return '<a href="' + url + '" target="_blank" rel="noopener noreferrer">' + url + '</a>'; |
| 49 | + }); |
| 50 | + |
| 51 | + // Convert emails to mailto links |
| 52 | + var emailRegex = /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})/gi; |
| 53 | + text = text.replace(emailRegex, function(email) { |
| 54 | + return '<a href="mailto:' + email + '">' + email + '</a>'; |
| 55 | + }); |
| 56 | + |
| 57 | + return $sce.trustAsHtml(text); |
| 58 | + }; |
| 59 | + |
| 60 | + $scope.close = function() { |
| 61 | + $uibModalInstance.dismiss('cancel'); |
| 62 | + }; |
| 63 | + }, |
| 64 | + resolve: { |
| 65 | + $sce: function() { |
| 66 | + return angular.injector(['ng']).get('$sce'); |
| 67 | + } |
| 68 | + }, |
| 69 | + template: '<div class="modal-header">' + |
| 70 | + '<h4 class="modal-title">Change Details</h4>' + |
| 71 | + '</div>' + |
| 72 | + '<div class="modal-body">' + |
| 73 | + '<p><strong>Change Number:</strong> {{data.number}}</p>' + |
| 74 | + '<p><strong>Short Description:</strong> {{data.short_description}}</p>' + |
| 75 | + '<p><strong>Description:</strong></p>' + |
| 76 | + '<p ng-bind-html="getTrustedDescription()"></p>' + |
| 77 | + '</div>' + |
| 78 | + '<div class="modal-footer">' + |
| 79 | + '<a class="btn btn-primary" ng-href="/change_request.do?sys_id={{data.sys_id}}" target="_blank">View Record</a>' + |
| 80 | + '<button class="btn btn-default" ng-click="close()">Close</button>' + |
| 81 | + '</div>' |
| 82 | + }); |
| 83 | + |
| 84 | + // Populate modal data via server |
| 85 | + spUtil.get(c.widget.sys_id, { |
| 86 | + action: 'getChangeDetails', |
| 87 | + sys_id: sysId |
| 88 | + }).then(function(response) { |
| 89 | + if (response.data.changeDetails && !response.data.changeDetails.error) { |
| 90 | + modalData.number = response.data.changeDetails.number; |
| 91 | + modalData.short_description = response.data.changeDetails.short_description; |
| 92 | + modalData.description = response.data.changeDetails.description; |
| 93 | + } |
| 94 | + }); |
| 95 | + }); |
| 96 | + }, 1000); |
| 97 | + }); |
| 98 | + } else { |
| 99 | + c.initialMessage = c.data.ch.i18n.selectReport; |
| 100 | + } |
| 101 | +} |
0 commit comments