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

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