电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
7.4 KiB

  1. /* Copyright 2005-2015 Alfresco Software, Ltd.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. var extScope;
  16. angular.module('flowableModeler')
  17. .controller('DecisionServiceDetailsCtrl', ['$rootScope', '$scope', '$translate', '$http', '$location', '$routeParams', '$modal', '$timeout', '$popover', 'ResourceService',
  18. function ($rootScope, $scope, $translate, $http, $location, $routeParams, $modal, $timeout, $popover, ResourceService) {
  19. // Main page (needed for visual indicator of current page)
  20. $rootScope.setMainPageById('decisions');
  21. // Initialize model
  22. $scope.model = {
  23. // Store the main model id, this points to the current version of a model,
  24. // even when we're showing history
  25. latestModelId: $routeParams.modelId
  26. };
  27. $scope.loadDecisionService = function () {
  28. var url;
  29. if ($routeParams.modelHistoryId) {
  30. url = FLOWABLE.APP_URL.getModelUrl($routeParams.modelId) + '/history/' + $routeParams.modelHistoryId;
  31. } else {
  32. url = FLOWABLE.APP_URL.getModelUrl($routeParams.modelId);
  33. }
  34. $http({method: 'GET', url: url}).success(function (data, status, headers, config) {
  35. $scope.model.decisionService = data;
  36. $scope.loadVersions();
  37. $scope.model.decisionDownloadUrl = FLOWABLE.APP_URL.getDmnModelDownloadUrl($routeParams.modelId, $routeParams.modelHistoryId);
  38. $rootScope.$on('$routeChangeStart', function (event, next, current) {
  39. jQuery('.qtip').qtip('destroy', true);
  40. });
  41. $timeout(function () {
  42. jQuery("#dmnModel").attr('data-model-id', $routeParams.modelId);
  43. jQuery("#dmnModel").attr('data-model-type', 'design');
  44. // in case we want to show a historic model, include additional attribute on the div
  45. if (!$scope.model.decisionService.latestVersion) {
  46. jQuery("#dmnModel").attr('data-history-id', $routeParams.modelHistoryId);
  47. }
  48. var viewerUrl = "display-dmn/displaymodel.html?version=" + Date.now();
  49. // If Flowable has been deployed inside an AMD environment Raphael will fail to register
  50. // itself globally until displaymodel.js (which depends ona global Raphale variable) is running,
  51. // therefore remove AMD's define method until we have loaded in Raphael and displaymodel.js
  52. // and assume/hope its not used during.
  53. var amdDefine = window.define;
  54. window.define = undefined;
  55. ResourceService.loadFromHtml(viewerUrl, function () {
  56. // Restore AMD's define method again
  57. window.define = amdDefine;
  58. });
  59. });
  60. }).error(function (data, status, headers, config) {
  61. $scope.returnToList();
  62. });
  63. };
  64. $scope.useAsNewVersion = function () {
  65. _internalCreateModal({
  66. template: 'views/popup/model-use-as-new-version.html',
  67. scope: $scope
  68. }, $modal, $scope);
  69. };
  70. $scope.loadVersions = function () {
  71. var params = {
  72. includeLatestVersion: !$scope.model.decisionService.latestVersion
  73. };
  74. $http({
  75. method: 'GET',
  76. url: FLOWABLE.APP_URL.getModelHistoriesUrl($scope.model.latestModelId),
  77. params: params
  78. }).success(function (data, status, headers, config) {
  79. if ($scope.model.decisionService.latestVersion) {
  80. if (!data.data) {
  81. data.data = [];
  82. }
  83. data.data.unshift($scope.model.decisionService);
  84. }
  85. $scope.model.versions = data;
  86. });
  87. };
  88. $scope.showVersion = function (version) {
  89. if (version) {
  90. if (version.latestVersion) {
  91. $location.path("/decision-services/" + $scope.model.latestModelId);
  92. } else {
  93. // Show latest version, no history-suffix needed in URL
  94. $location.path("/decision-services/" + $scope.model.latestModelId + "/history/" + version.id);
  95. }
  96. }
  97. };
  98. $scope.returnToList = function () {
  99. $location.path("/decision-services/");
  100. };
  101. $scope.editDecisionService = function () {
  102. _internalCreateModal({
  103. template: 'views/popup/model-edit.html',
  104. scope: $scope
  105. }, $modal, $scope);
  106. };
  107. $scope.duplicateDecisionService = function () {
  108. var modalInstance = _internalCreateModal({
  109. template: 'views/popup/decision-service-duplicate.html?version=' + Date.now()
  110. }, $modal, $scope);
  111. modalInstance.$scope.originalModel = $scope.model;
  112. };
  113. $scope.deleteDecisionService = function () {
  114. _internalCreateModal({
  115. template: 'views/popup/model-delete.html',
  116. scope: $scope
  117. }, $modal, $scope);
  118. };
  119. $scope.openEditor = function () {
  120. if ($scope.model.decisionService) {
  121. $location.path("/decision-service-editor/" + $scope.model.decisionService.id);
  122. }
  123. };
  124. $scope.toggleHistory = function ($event) {
  125. if (!$scope.historyState) {
  126. var state = {};
  127. $scope.historyState = state;
  128. // Create popover
  129. state.popover = $popover(angular.element($event.target), {
  130. template: 'views/popover/history.html',
  131. placement: 'bottom-right',
  132. show: true,
  133. scope: $scope,
  134. container: 'body'
  135. });
  136. var destroy = function () {
  137. state.popover.destroy();
  138. delete $scope.historyState;
  139. }
  140. // When popup is hidden or scope is destroyed, hide popup
  141. state.popover.$scope.$on('tooltip.hide', destroy);
  142. $scope.$on('$destroy', destroy);
  143. }
  144. };
  145. $scope.loadDecisionService();
  146. }]);