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

148 lines
4.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. var APP_DEFINITION_TOOLBAR = {
  15. ACTIONS: {
  16. saveModel: function (services) {
  17. _internalCreateModal({
  18. backdrop: true,
  19. keyboard: true,
  20. template: 'views/popup/app-definition-save-model.html?version=' + Date.now(),
  21. scope: services.$scope
  22. }, services.$modal, services.$scope);
  23. },
  24. help: function (services) {
  25. },
  26. feedback: function (services) {
  27. },
  28. closeEditor: function (services) {
  29. services.$location.path('/apps');
  30. }
  31. }
  32. };
  33. /** Custom controller for the save dialog */
  34. angular.module('flowableModeler').controller('SaveAppDefinitionCtrl',
  35. [ '$rootScope', '$scope', '$http', '$route', '$location', '$translate',
  36. function ($rootScope, $scope, $http, $route, $location, $translate) {
  37. var description = '';
  38. if ($rootScope.currentAppDefinition.description) {
  39. description = $rootScope.currentAppDefinition.description;
  40. }
  41. var saveDialog = {
  42. name: $rootScope.currentAppDefinition.name,
  43. key: $rootScope.currentAppDefinition.key,
  44. description: description,
  45. publish: false
  46. };
  47. $scope.saveDialog = saveDialog;
  48. $scope.status = {
  49. loading: false
  50. };
  51. $scope.cancel = function () {
  52. $scope.$hide();
  53. };
  54. $scope.saveAndClose = function (force) {
  55. $scope.save(function() {
  56. $location.path('/apps');
  57. }, force);
  58. };
  59. $scope.save = function (saveCallback, force) {
  60. if (!$scope.saveDialog.name || $scope.saveDialog.name.length == 0 ||
  61. !$scope.saveDialog.key || $scope.saveDialog.key.length == 0) {
  62. return;
  63. }
  64. // Indicator spinner image
  65. $scope.status.loading = true;
  66. var data = {
  67. appDefinition: $rootScope.currentAppDefinition,
  68. publish: $scope.saveDialog.publish
  69. };
  70. data.appDefinition.name = $scope.saveDialog.name;
  71. if ($scope.saveDialog.description && $scope.saveDialog.description.length > 0) {
  72. data.appDefinition.description = $scope.saveDialog.description;
  73. }
  74. if (force !== undefined && force !== null && force === true) {
  75. data.force = true;
  76. }
  77. delete $scope.conflict;
  78. $http({method: 'PUT', url: FLOWABLE.APP_URL.getAppDefinitionUrl($rootScope.currentAppDefinition.id), data: data}).
  79. success(function(response, status, headers, config) {
  80. // Regular error
  81. if (response.error) {
  82. $scope.status.loading = false;
  83. $scope.saveDialog.errorMessage = response.errorDescription;
  84. } else {
  85. $scope.$hide();
  86. $rootScope.addAlert($translate.instant('APP.POPUP.SAVE-APP-SAVE-SUCCESS', 'info'));
  87. if (saveCallback) {
  88. saveCallback();
  89. }
  90. }
  91. }).
  92. error(function(data, status, headers, config) {
  93. $scope.status.loading = false;
  94. $scope.saveDialog.errorMessage = data.message;
  95. });
  96. };
  97. $scope.isOkButtonDisabled = function() {
  98. if ($scope.status.loading) {
  99. return false;
  100. } else if ($scope.error && $scope.error.hasCustomStencilItem) {
  101. return false;
  102. }
  103. return true;
  104. };
  105. $scope.okClicked = function() {
  106. if ($scope.error) {
  107. if ($scope.error.conflictResolveAction === 'discardChanges') {
  108. $scope.close();
  109. $route.reload();
  110. } else if ($scope.error.conflictResolveAction === 'overwrite'
  111. || $scope.error.conflictResolveAction === 'newVersion') {
  112. $scope.save();
  113. } else if($scope.error.conflictResolveAction === 'saveAs') {
  114. $scope.save(function() {
  115. $rootScope.ignoreChanges = true; // Otherwise will get pop up that changes are not saved.
  116. $location.path('/apps');
  117. });
  118. }
  119. }
  120. };
  121. }]);