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

171 lines
6.0 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('CaseModelCtrl', ['$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('casemodels');
  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.loadCaseModel = function() {
  25. var url;
  26. if ($routeParams.modelHistoryId) {
  27. url = FLOWABLE.APP_URL.getModelHistoryUrl($routeParams.modelId, $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.caseModel = data;
  34. $scope.loadVersions();
  35. $scope.model.cmmnDownloadUrl = FLOWABLE.APP_URL.getCmmnModelDownloadUrl($routeParams.modelId, $routeParams.modelHistoryId);
  36. $rootScope.$on('$routeChangeStart', function(event, next, current) {
  37. jQuery('.qtip').qtip('destroy', true);
  38. });
  39. $timeout(function() {
  40. jQuery("#cmmnModel").attr('data-model-id', $routeParams.modelId);
  41. jQuery("#cmmnModel").attr('data-model-type', 'design');
  42. // in case we want to show a historic model, include additional attribute on the div
  43. if(!$scope.model.caseModel.latestVersion) {
  44. jQuery("#cmmnModel").attr('data-history-id', $routeParams.modelHistoryId);
  45. }
  46. var viewerUrl = "display-cmmn/displaymodel.html?version=" + Date.now();
  47. // If Flowable has been deployed inside an AMD environment Raphael will fail to register
  48. // itself globally until displaymodel.js (which depends ona global Raphael variable) is running,
  49. // therefore remove AMD's define method until we have loaded in Raphael and displaymodel.js
  50. // and assume/hope its not used during.
  51. var amdDefine = window.define;
  52. window.define = undefined;
  53. ResourceService.loadFromHtml(viewerUrl, function(){
  54. // Restore AMD's define method again
  55. window.define = amdDefine;
  56. });
  57. });
  58. }).error(function(data, status, headers, config) {
  59. $scope.returnToList();
  60. });
  61. };
  62. $scope.useAsNewVersion = function() {
  63. _internalCreateModal({
  64. template: 'views/popup/model-use-as-new-version.html',
  65. scope: $scope
  66. }, $modal, $scope);
  67. };
  68. $scope.loadVersions = function() {
  69. var params = {
  70. includeLatestVersion: !$scope.model.caseModel.latestVersion
  71. };
  72. $http({method: 'GET', url: FLOWABLE.APP_URL.getModelHistoriesUrl($scope.model.latestModelId), params: params}).
  73. success(function(data, status, headers, config) {
  74. if ($scope.model.caseModel.latestVersion) {
  75. if (!data.data) {
  76. data.data = [];
  77. }
  78. data.data.unshift($scope.model.caseModel);
  79. }
  80. $scope.model.versions = data;
  81. });
  82. };
  83. $scope.showVersion = function(version) {
  84. if(version) {
  85. if(version.latestVersion) {
  86. $location.path("/casemodels/" + $scope.model.latestModelId);
  87. } else{
  88. // Show latest version, no history-suffix needed in URL
  89. $location.path("/casemodels/" + $scope.model.latestModelId + "/history/" + version.id);
  90. }
  91. }
  92. };
  93. $scope.returnToList = function() {
  94. $location.path("/casemodels/");
  95. };
  96. $scope.editCaseModel = function() {
  97. _internalCreateModal({
  98. template: 'views/popup/model-edit.html',
  99. scope: $scope
  100. }, $modal, $scope);
  101. };
  102. $scope.duplicateCaseModel = function() {
  103. var modalInstance = _internalCreateModal({
  104. template: 'views/popup/casemodel-duplicate.html?version=' + Date.now()
  105. }, $modal, $scope);
  106. modalInstance.$scope.originalModel = $scope.model;
  107. };
  108. $scope.deleteCaseModel = function() {
  109. _internalCreateModal({
  110. template: 'views/popup/model-delete.html',
  111. scope: $scope
  112. }, $modal, $scope);
  113. };
  114. $scope.openEditor = function() {
  115. if ($scope.model.caseModel) {
  116. $location.path("/editor/" + $scope.model.caseModel.id);
  117. }
  118. };
  119. $scope.toggleHistory = function($event) {
  120. if(!$scope.historyState) {
  121. var state = {};
  122. $scope.historyState = state;
  123. // Create popover
  124. state.popover = $popover(angular.element($event.target), {
  125. template: 'views/popover/history.html',
  126. placement: 'bottom-right',
  127. show: true,
  128. scope: $scope,
  129. container: 'body'
  130. });
  131. var destroy = function() {
  132. state.popover.destroy();
  133. delete $scope.historyState;
  134. }
  135. // When popup is hidden or scope is destroyed, hide popup
  136. state.popover.$scope.$on('tooltip.hide', destroy);
  137. $scope.$on('$destroy', destroy);
  138. }
  139. };
  140. $scope.loadCaseModel();
  141. }]);