图书馆智能管理系统
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.

225 lines
8.7 KiB

5 months ago
  1. /* Copyright 2005-2015 Alfresco Software, Ltd.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. var DECISION_TABLE_TOOLBAR = {
  17. ACTIONS: {
  18. saveModel: function (services) {
  19. _internalCreateModal({
  20. backdrop: true,
  21. keyboard: true,
  22. template: 'views/popup/decision-table-save-model.html?version=' + Date.now(),
  23. scope: services.$scope
  24. }, services.$modal, services.$scope);
  25. },
  26. help: function (services) {
  27. },
  28. feedback: function (services) {
  29. },
  30. closeEditor: function (services) {
  31. var callback = function() {
  32. services.$rootScope.decisiontableChanges = false;
  33. if (services.$rootScope.editorHistory.length > 0) {
  34. var navigationObject = services.$rootScope.editorHistory.pop();
  35. var additionalParameters = '';
  36. if (navigationObject.subProcessId && navigationObject.subProcessId.length > 0) {
  37. additionalParameters = '?subProcessId=' + navigationObject.subProcessId;
  38. }
  39. services.$location.url('/editor/' + navigationObject.id + additionalParameters);
  40. } else {
  41. services.$location.path('/decision-tables');
  42. }
  43. };
  44. if (services.$rootScope.decisiontableChanges == true) {
  45. services.$scope.$emit("decisionTableChangesEvent");
  46. var unbindMustSave = services.$scope.$on("mustSaveEvent", function(){
  47. //save the decision table data
  48. var description = '';
  49. if (services.$rootScope.currentDecisionTable.description) {
  50. description = services.$rootScope.currentDecisionTable.description;
  51. }
  52. var data = {
  53. newVersion: false
  54. };
  55. unbindEvents();
  56. services.DecisionTableBuilderService.saveDecisionTable(data, services.$rootScope.currentDecisionTable.name,
  57. null, description, callback);
  58. });
  59. var unbindDiscardDataEvent = services.$scope.$on("discardDataEvent", function() {
  60. unbindEvents();
  61. callback();
  62. });
  63. var unbindContinueEditingEvent = services.$scope.$on("continueEditingEvent", function () {
  64. unbindEvents();
  65. });
  66. } else {
  67. callback();
  68. }
  69. var unbindEvents = function () {
  70. unbindContinueEditingEvent();
  71. unbindMustSave();
  72. unbindDiscardDataEvent();
  73. };
  74. }
  75. }
  76. };
  77. /** Custom controller for the save dialog */
  78. angular.module('flowableModeler')
  79. .controller('SaveDecisionTableCtrl', [ '$rootScope', '$scope', '$http', '$route', '$location', '$translate', 'DecisionTableService', 'hotRegisterer',
  80. function ($rootScope, $scope, $http, $route, $location, $translate, DecisionTableService, hotRegisterer) {
  81. var description = '';
  82. if ($rootScope.currentDecisionTableModel.description) {
  83. description = $rootScope.currentDecisionTableModel.description;
  84. }
  85. $scope.saveDialog = {
  86. name: $rootScope.currentDecisionTableModel.name,
  87. key: $rootScope.currentDecisionTableModel.key,
  88. description: description,
  89. newVersion: false,
  90. comment: '',
  91. forceDMN11: $rootScope.currentDecisionTable.forceDMN11
  92. };
  93. $scope.keyFieldPattern = /^[a-zA-Z_]\w*$/;
  94. $scope.status = {
  95. loading: false
  96. };
  97. $scope.cancel = function () {
  98. $scope.$hide();
  99. };
  100. $scope.saveAndClose = function () {
  101. $scope.save(function() {
  102. if ($rootScope.editorHistory.length > 0) {
  103. var navigationObject = $rootScope.editorHistory.pop();
  104. var additionalParameters = '';
  105. if (navigationObject.subProcessId && navigationObject.subProcessId.length > 0) {
  106. additionalParameters = '?subProcessId=' + navigationObject.subProcessId;
  107. }
  108. $location.url('/editor/' + navigationObject.id + additionalParameters);
  109. } else {
  110. $location.path('/decision-tables');
  111. }
  112. });
  113. };
  114. $scope.save = function (additionalSaveCallback) {
  115. if (!$scope.saveDialog.name || $scope.saveDialog.name.length == 0 || !$scope.saveDialog.key || $scope.saveDialog.key.length == 0) {
  116. return;
  117. }
  118. // Indicator spinner image
  119. $scope.status = {
  120. loading: true
  121. };
  122. var data = {
  123. reusable: $scope.saveDialog.reusable,
  124. newVersion: $scope.saveDialog.newVersion,
  125. comment: $scope.saveDialog.comment,
  126. forceDMN11: $scope.saveDialog.forceDMN11
  127. };
  128. $rootScope.currentDecisionTableRules = $scope.model.rulesData;
  129. var saveCallback = function() {
  130. $scope.$hide();
  131. $rootScope.currentDecisionTableModel.name = $scope.saveDialog.name;
  132. $rootScope.currentDecisionTableModel.key = $scope.saveDialog.key;
  133. $rootScope.currentDecisionTableModel.description = $scope.saveDialog.description;
  134. $rootScope.currentDecisionTable.forceDMN11 = $scope.saveDialog.forceDMN11;
  135. $rootScope.addAlertPromise($translate('DECISION-TABLE-EDITOR.ALERT.SAVE-CONFIRM', {name: $scope.saveDialog.name}), 'info');
  136. if (additionalSaveCallback) {
  137. additionalSaveCallback();
  138. }
  139. $rootScope.decisionTableChanges = false;
  140. };
  141. var errorCallback = function(errorMessage) {
  142. $scope.status.loading = false;
  143. $scope.saveDialog.errorMessage = errorMessage.message;
  144. };
  145. // deselect cells before thumbnail generations
  146. var hotDecisionTableEditorInstance = hotRegisterer.getInstance('decision-table-editor');
  147. if (hotDecisionTableEditorInstance) {
  148. hotDecisionTableEditorInstance.deselectCell();
  149. }
  150. DecisionTableService.saveDecisionTable(data, $scope.saveDialog.name, $scope.saveDialog.key,
  151. $scope.saveDialog.description, saveCallback, errorCallback);
  152. };
  153. $scope.isOkButtonDisabled = function() {
  154. if ($scope.status.loading) {
  155. return false;
  156. } else if ($scope.error && $scope.error.conflictResolveAction) {
  157. if ($scope.error.conflictResolveAction === 'saveAs') {
  158. return !$scope.error.saveAs || $scope.error.saveAs.length == 0;
  159. } else {
  160. return false;
  161. }
  162. }
  163. return true;
  164. };
  165. $scope.okClicked = function() {
  166. if ($scope.error) {
  167. if ($scope.error.conflictResolveAction === 'discardChanges') {
  168. $scope.close();
  169. $route.reload();
  170. } else if ($scope.error.conflictResolveAction === 'overwrite'
  171. || $scope.error.conflictResolveAction === 'newVersion') {
  172. $scope.save();
  173. } else if($scope.error.conflictResolveAction === 'saveAs') {
  174. $scope.save(function() {
  175. $rootScope.ignoreChanges = true; // Otherwise will get pop up that changes are not saved.
  176. $location.path('/decision-tables');
  177. });
  178. }
  179. }
  180. };
  181. }]);