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

295 lines
8.9 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. 'use strict';
  14. angular.module('flowableModeler')
  15. .controller('ProcessesCtrl', ['$rootScope', '$scope', '$translate', '$http', '$timeout','$location', '$modal', function ($rootScope, $scope, $translate, $http, $timeout, $location, $modal) {
  16. // Main page (needed for visual indicator of current page)
  17. $rootScope.setMainPageById('processes');
  18. $rootScope.formItems = undefined;
  19. // get latest thumbnails
  20. $scope.imageVersion = Date.now();
  21. $scope.model = {
  22. filters: [
  23. {id: 'processes', labelKey: 'PROCESSES'}
  24. ],
  25. sorts: [
  26. {id: 'modifiedDesc', labelKey: 'MODIFIED-DESC'},
  27. {id: 'modifiedAsc', labelKey: 'MODIFIED-ASC'},
  28. {id: 'nameAsc', labelKey: 'NAME-ASC'},
  29. {id: 'nameDesc', labelKey: 'NAME-DESC'}
  30. ]
  31. };
  32. if ($rootScope.modelFilter) {
  33. $scope.model.activeFilter = $rootScope.modelFilter.filter;
  34. $scope.model.activeSort = $rootScope.modelFilter.sort;
  35. $scope.model.filterText = $rootScope.modelFilter.filterText;
  36. } else {
  37. // By default, show first filter and use first sort
  38. $scope.model.activeFilter = $scope.model.filters[0];
  39. $scope.model.activeSort = $scope.model.sorts[0];
  40. $rootScope.modelFilter = {
  41. filter: $scope.model.activeFilter,
  42. sort: $scope.model.activeSort,
  43. filterText: ''
  44. };
  45. }
  46. $scope.activateFilter = function(filter) {
  47. $scope.model.activeFilter = filter;
  48. $rootScope.modelFilter.filter = filter;
  49. $scope.loadProcesses();
  50. };
  51. $scope.activateSort = function(sort) {
  52. $scope.model.activeSort = sort;
  53. $rootScope.modelFilter.sort = sort;
  54. $scope.loadProcesses();
  55. };
  56. $scope.loadProcesses = function() {
  57. $scope.model.loading = true;
  58. var params = {
  59. filter: $scope.model.activeFilter.id,
  60. sort: $scope.model.activeSort.id,
  61. modelType: 0
  62. };
  63. if ($scope.model.filterText && $scope.model.filterText != '') {
  64. params.filterText = $scope.model.filterText;
  65. }
  66. $http({method: 'GET', url: FLOWABLE.APP_URL.getModelsUrl(), params: params}).
  67. success(function(data, status, headers, config) {
  68. $scope.model.processes = data;
  69. $scope.model.loading = false;
  70. }).
  71. error(function(data, status, headers, config) {
  72. console.log('Something went wrong: ' + data);
  73. $scope.model.loading = false;
  74. });
  75. };
  76. var timeoutFilter = function() {
  77. $scope.model.isFilterDelayed = true;
  78. $timeout(function() {
  79. $scope.model.isFilterDelayed = false;
  80. if ($scope.model.isFilterUpdated) {
  81. $scope.model.isFilterUpdated = false;
  82. timeoutFilter();
  83. } else {
  84. $scope.model.filterText = $scope.model.pendingFilterText;
  85. $rootScope.modelFilter.filterText = $scope.model.filterText;
  86. $scope.loadProcesses();
  87. }
  88. }, 500);
  89. };
  90. $scope.filterDelayed = function() {
  91. if ($scope.model.isFilterDelayed) {
  92. $scope.model.isFilterUpdated = true;
  93. } else {
  94. timeoutFilter();
  95. }
  96. };
  97. $scope.createProcess = function(mode) {
  98. var modalInstance = _internalCreateModal({
  99. template: 'views/popup/process-create.html?version=' + Date.now()
  100. }, $modal, $scope);
  101. };
  102. $scope.importProcess = function () {
  103. _internalCreateModal({
  104. template: 'views/popup/process-import.html?version=' + Date.now()
  105. }, $modal, $scope);
  106. };
  107. $scope.showProcessDetails = function(process) {
  108. if (process) {
  109. $rootScope.editorHistory = [];
  110. $location.path("/processes/" + process.id);
  111. }
  112. };
  113. $scope.editProcessDetails = function(process) {
  114. if (process) {
  115. $rootScope.editorHistory = [];
  116. $location.path("/editor/" + process.id);
  117. }
  118. };
  119. // Finally, load initial processes
  120. $scope.loadProcesses();
  121. }]);
  122. angular.module('flowableModeler')
  123. .controller('CreateNewProcessModelCtrl', ['$rootScope', '$scope', '$modal', '$http', '$location',
  124. function ($rootScope, $scope, $modal, $http, $location) {
  125. $scope.model = {
  126. loading: false,
  127. process: {
  128. name: '',
  129. key: '',
  130. description: '',
  131. modelType: 0
  132. }
  133. };
  134. if ($scope.initialModelType !== undefined) {
  135. $scope.model.process.modelType = $scope.initialModelType;
  136. }
  137. $scope.ok = function () {
  138. if (!$scope.model.process.name || $scope.model.process.name.length == 0 ||
  139. !$scope.model.process.key || $scope.model.process.key.length == 0) {
  140. return;
  141. }
  142. $scope.model.loading = true;
  143. $http({method: 'POST', url: FLOWABLE.APP_URL.getModelsUrl(), data: $scope.model.process}).
  144. success(function(data) {
  145. $scope.$hide();
  146. $scope.model.loading = false;
  147. $rootScope.editorHistory = [];
  148. $location.path("/editor/" + data.id);
  149. }).
  150. error(function(data, status, headers, config) {
  151. $scope.model.loading = false;
  152. $scope.model.errorMessage = data.message;
  153. });
  154. };
  155. $scope.cancel = function () {
  156. if(!$scope.model.loading) {
  157. $scope.$hide();
  158. }
  159. };
  160. }]);
  161. angular.module('flowableModeler')
  162. .controller('DuplicateProcessModelCtrl', ['$rootScope', '$scope', '$modal', '$http', '$location',
  163. function ($rootScope, $scope, $modal, $http, $location) {
  164. $scope.model = {
  165. loading: false,
  166. process: {
  167. name: '',
  168. key: '',
  169. description: ''
  170. }
  171. };
  172. if ($scope.originalModel) {
  173. //clone the model
  174. $scope.model.process.name = $scope.originalModel.process.name;
  175. $scope.model.process.key = $scope.originalModel.process.key;
  176. $scope.model.process.description = $scope.originalModel.process.description;
  177. $scope.model.process.id = $scope.originalModel.process.id;
  178. $scope.model.process.modelType = $scope.originalModel.process.modelType;
  179. }
  180. $scope.ok = function () {
  181. if (!$scope.model.process.name || $scope.model.process.name.length == 0 ||
  182. !$scope.model.process.key || $scope.model.process.key.length == 0) {
  183. return;
  184. }
  185. $scope.model.loading = true;
  186. $http({method: 'POST', url: FLOWABLE.APP_URL.getCloneModelsUrl($scope.model.process.id), data: $scope.model.process}).
  187. success(function(data) {
  188. $scope.$hide();
  189. $scope.model.loading = false;
  190. $rootScope.editorHistory = [];
  191. $location.path("/editor/" + data.id);
  192. }).
  193. error(function(data, status, headers, config) {
  194. $scope.model.loading = false;
  195. $scope.model.errorMessage = data.message;
  196. });
  197. };
  198. $scope.cancel = function () {
  199. if(!$scope.model.loading) {
  200. $scope.$hide();
  201. }
  202. };
  203. }]);
  204. angular.module('flowableModeler')
  205. .controller('ImportProcessModelCtrl', ['$rootScope', '$scope', '$http', 'Upload', '$location', function ($rootScope, $scope, $http, Upload, $location) {
  206. $scope.model = {
  207. loading: false
  208. };
  209. $scope.onFileSelect = function($files, isIE) {
  210. for (var i = 0; i < $files.length; i++) {
  211. var file = $files[i];
  212. var url;
  213. if (isIE) {
  214. url = FLOWABLE.APP_URL.getImportProcessModelTextUrl();
  215. } else {
  216. url = FLOWABLE.APP_URL.getImportProcessModelUrl();
  217. }
  218. Upload.upload({
  219. url: url,
  220. method: 'POST',
  221. file: file
  222. }).progress(function(evt) {
  223. $scope.model.loading = true;
  224. $scope.model.uploadProgress = parseInt(100.0 * evt.loaded / evt.total);
  225. }).success(function(data) {
  226. $scope.model.loading = false;
  227. $location.path("/editor/" + data.id);
  228. $scope.$hide();
  229. }).error(function(data) {
  230. if (data && data.message) {
  231. $scope.model.errorMessage = data.message;
  232. }
  233. $scope.model.error = true;
  234. $scope.model.loading = false;
  235. });
  236. }
  237. };
  238. $scope.cancel = function () {
  239. if(!$scope.model.loading) {
  240. $scope.$hide();
  241. }
  242. };
  243. }]);