电子档案
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.

173 lines
6.2 KiB

  1. /* Licensed under the Apache License, Version 2.0 (the "License");
  2. * you may not use this file except in compliance with the License.
  3. * You may obtain a copy of the License at
  4. *
  5. * http://www.apache.org/licenses/LICENSE-2.0
  6. *
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. angular.module('flowableModeler')
  14. .controller('ProcessCtrl', ['$rootScope', '$scope', '$translate', '$http', '$location', '$routeParams','$modal', '$popover', '$timeout', 'ResourceService',
  15. function ($rootScope, $scope, $translate, $http, $location, $routeParams, $modal, $popover, $timeout, ResourceService) {
  16. // Main page (needed for visual indicator of current page)
  17. $rootScope.setMainPageById('processes');
  18. // Initialize model
  19. $scope.model = {
  20. // Store the main model id, this points to the current version of a model,
  21. // even when we're showing history
  22. latestModelId: $routeParams.modelId
  23. };
  24. $scope.loadProcess = function() {
  25. var url;
  26. if ($routeParams.modelHistoryId) {
  27. url = FLOWABLE.APP_URL.getModelUrl($routeParams.modelId) + '/history/' + $routeParams.modelHistoryId;
  28. } else {
  29. url = FLOWABLE.APP_URL.getModelUrl($routeParams.modelId);
  30. }
  31. $http({method: 'GET', url: url}).
  32. success(function(data, status, headers, config) {
  33. $scope.model.process = data;
  34. $scope.loadVersions();
  35. $scope.model.bpmn20DownloadUrl = $routeParams.modelHistoryId == undefined ?
  36. FLOWABLE.APP_URL.getModelBpmn20ExportUrl($routeParams.modelId) :
  37. FLOWABLE.APP_URL.getModelHistoryBpmn20ExportUrl($routeParams.modelId, $routeParams.modelHistoryId);
  38. $rootScope.$on('$routeChangeStart', function(event, next, current) {
  39. jQuery('.qtip').qtip('destroy', true);
  40. });
  41. $timeout(function() {
  42. jQuery("#bpmnModel").attr('data-model-id', $routeParams.modelId);
  43. jQuery("#bpmnModel").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.process.latestVersion) {
  46. jQuery("#bpmnModel").attr('data-history-id', $routeParams.modelHistoryId);
  47. }
  48. var viewerUrl = "display/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.process.latestVersion
  73. };
  74. $http({method: 'GET', url: FLOWABLE.APP_URL.getModelHistoriesUrl($scope.model.latestModelId), params: params}).
  75. success(function(data, status, headers, config) {
  76. if ($scope.model.process.latestVersion) {
  77. if (!data.data) {
  78. data.data = [];
  79. }
  80. data.data.unshift($scope.model.process);
  81. }
  82. $scope.model.versions = data;
  83. });
  84. };
  85. $scope.showVersion = function(version) {
  86. if(version) {
  87. if(version.latestVersion) {
  88. $location.path("/processes/" + $scope.model.latestModelId);
  89. } else{
  90. // Show latest version, no history-suffix needed in URL
  91. $location.path("/processes/" + $scope.model.latestModelId + "/history/" + version.id);
  92. }
  93. }
  94. };
  95. $scope.returnToList = function() {
  96. $location.path("/processes/");
  97. };
  98. $scope.editProcess = function() {
  99. _internalCreateModal({
  100. template: 'views/popup/model-edit.html',
  101. scope: $scope
  102. }, $modal, $scope);
  103. };
  104. $scope.duplicateProcess = function() {
  105. var modalInstance = _internalCreateModal({
  106. template: 'views/popup/process-duplicate.html?version=' + Date.now()
  107. }, $modal, $scope);
  108. modalInstance.$scope.originalModel = $scope.model;
  109. };
  110. $scope.deleteProcess = function() {
  111. _internalCreateModal({
  112. template: 'views/popup/model-delete.html',
  113. scope: $scope
  114. }, $modal, $scope);
  115. };
  116. $scope.openEditor = function() {
  117. if ($scope.model.process) {
  118. $location.path("/editor/" + $scope.model.process.id);
  119. }
  120. };
  121. $scope.toggleHistory = function($event) {
  122. if(!$scope.historyState) {
  123. var state = {};
  124. $scope.historyState = state;
  125. // Create popover
  126. state.popover = $popover(angular.element($event.target), {
  127. template: 'views/popover/history.html',
  128. placement: 'bottom-right',
  129. show: true,
  130. scope: $scope,
  131. container: 'body'
  132. });
  133. var destroy = function() {
  134. state.popover.destroy();
  135. delete $scope.historyState;
  136. }
  137. // When popup is hidden or scope is destroyed, hide popup
  138. state.popover.$scope.$on('tooltip.hide', destroy);
  139. $scope.$on('$destroy', destroy);
  140. }
  141. };
  142. $scope.loadProcess();
  143. }]);