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

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