Digital Office Automation System Backend
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

toolbar-default-actions.js 15KB

il y a 1 jour
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. /*
  2. * Activiti Modeler component part of the Activiti project
  3. * Copyright 2005-2014 Alfresco Software, Ltd. All rights reserved.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. 'use strict';
  19. var KISBPM = KISBPM || {};
  20. KISBPM.TOOLBAR = {
  21. ACTIONS: {
  22. saveModel: function (services) {
  23. var modal = services.$modal({
  24. backdrop: true,
  25. keyboard: true,
  26. template: 'editor-app/popups/save-model.html?version=' + Date.now(),
  27. scope: services.$scope
  28. });
  29. },
  30. undo: function (services) {
  31. // Get the last commands
  32. var lastCommands = services.$scope.undoStack.pop();
  33. if (lastCommands) {
  34. // Add the commands to the redo stack
  35. services.$scope.redoStack.push(lastCommands);
  36. // Force refresh of selection, might be that the undo command
  37. // impacts properties in the selected item
  38. if (services.$rootScope && services.$rootScope.forceSelectionRefresh)
  39. {
  40. services.$rootScope.forceSelectionRefresh = true;
  41. }
  42. // Rollback every command
  43. for (var i = lastCommands.length - 1; i >= 0; --i) {
  44. lastCommands[i].rollback();
  45. }
  46. // Update and refresh the canvas
  47. services.$scope.editor.handleEvents({
  48. type: ORYX.CONFIG.EVENT_UNDO_ROLLBACK,
  49. commands: lastCommands
  50. });
  51. // Update
  52. services.$scope.editor.getCanvas().update();
  53. services.$scope.editor.updateSelection();
  54. }
  55. var toggleUndo = false;
  56. if (services.$scope.undoStack.length == 0)
  57. {
  58. toggleUndo = true;
  59. }
  60. var toggleRedo = false;
  61. if (services.$scope.redoStack.length > 0)
  62. {
  63. toggleRedo = true;
  64. }
  65. if (toggleUndo || toggleRedo) {
  66. for (var i = 0; i < services.$scope.items.length; i++) {
  67. var item = services.$scope.items[i];
  68. if (toggleUndo && item.action === 'KISBPM.TOOLBAR.ACTIONS.undo') {
  69. services.$scope.safeApply(function () {
  70. item.enabled = false;
  71. });
  72. }
  73. else if (toggleRedo && item.action === 'KISBPM.TOOLBAR.ACTIONS.redo') {
  74. services.$scope.safeApply(function () {
  75. item.enabled = true;
  76. });
  77. }
  78. }
  79. }
  80. },
  81. redo: function (services) {
  82. // Get the last commands from the redo stack
  83. var lastCommands = services.$scope.redoStack.pop();
  84. if (lastCommands) {
  85. // Add this commands to the undo stack
  86. services.$scope.undoStack.push(lastCommands);
  87. // Force refresh of selection, might be that the redo command
  88. // impacts properties in the selected item
  89. if (services.$rootScope && services.$rootScope.forceSelectionRefresh)
  90. {
  91. services.$rootScope.forceSelectionRefresh = true;
  92. }
  93. // Execute those commands
  94. lastCommands.each(function (command) {
  95. command.execute();
  96. });
  97. // Update and refresh the canvas
  98. services.$scope.editor.handleEvents({
  99. type: ORYX.CONFIG.EVENT_UNDO_EXECUTE,
  100. commands: lastCommands
  101. });
  102. // Update
  103. services.$scope.editor.getCanvas().update();
  104. services.$scope.editor.updateSelection();
  105. }
  106. var toggleUndo = false;
  107. if (services.$scope.undoStack.length > 0) {
  108. toggleUndo = true;
  109. }
  110. var toggleRedo = false;
  111. if (services.$scope.redoStack.length == 0) {
  112. toggleRedo = true;
  113. }
  114. if (toggleUndo || toggleRedo) {
  115. for (var i = 0; i < services.$scope.items.length; i++) {
  116. var item = services.$scope.items[i];
  117. if (toggleUndo && item.action === 'KISBPM.TOOLBAR.ACTIONS.undo') {
  118. services.$scope.safeApply(function () {
  119. item.enabled = true;
  120. });
  121. }
  122. else if (toggleRedo && item.action === 'KISBPM.TOOLBAR.ACTIONS.redo') {
  123. services.$scope.safeApply(function () {
  124. item.enabled = false;
  125. });
  126. }
  127. }
  128. }
  129. },
  130. cut: function (services) {
  131. KISBPM.TOOLBAR.ACTIONS._getOryxEditPlugin(services.$scope).editCut();
  132. for (var i = 0; i < services.$scope.items.length; i++) {
  133. var item = services.$scope.items[i];
  134. if (item.action === 'KISBPM.TOOLBAR.ACTIONS.paste') {
  135. services.$scope.safeApply(function () {
  136. item.enabled = true;
  137. });
  138. }
  139. }
  140. },
  141. copy: function (services) {
  142. KISBPM.TOOLBAR.ACTIONS._getOryxEditPlugin(services.$scope).editCopy();
  143. for (var i = 0; i < services.$scope.items.length; i++) {
  144. var item = services.$scope.items[i];
  145. if (item.action === 'KISBPM.TOOLBAR.ACTIONS.paste') {
  146. services.$scope.safeApply(function () {
  147. item.enabled = true;
  148. });
  149. }
  150. }
  151. },
  152. paste: function (services) {
  153. KISBPM.TOOLBAR.ACTIONS._getOryxEditPlugin(services.$scope).editPaste();
  154. },
  155. deleteItem: function (services) {
  156. KISBPM.TOOLBAR.ACTIONS._getOryxEditPlugin(services.$scope).editDelete();
  157. },
  158. addBendPoint: function (services) {
  159. var dockerPlugin = KISBPM.TOOLBAR.ACTIONS._getOryxDockerPlugin(services.$scope);
  160. var enableAdd = !dockerPlugin.enabledAdd();
  161. dockerPlugin.setEnableAdd(enableAdd);
  162. if (enableAdd)
  163. {
  164. dockerPlugin.setEnableRemove(false);
  165. document.body.style.cursor = 'pointer';
  166. }
  167. else
  168. {
  169. document.body.style.cursor = 'default';
  170. }
  171. },
  172. removeBendPoint: function (services) {
  173. var dockerPlugin = KISBPM.TOOLBAR.ACTIONS._getOryxDockerPlugin(services.$scope);
  174. var enableRemove = !dockerPlugin.enabledRemove();
  175. dockerPlugin.setEnableRemove(enableRemove);
  176. if (enableRemove)
  177. {
  178. dockerPlugin.setEnableAdd(false);
  179. document.body.style.cursor = 'pointer';
  180. }
  181. else
  182. {
  183. document.body.style.cursor = 'default';
  184. }
  185. },
  186. /**
  187. * Helper method: fetches the Oryx Edit plugin from the provided scope,
  188. * if not on the scope, it is created and put on the scope for further use.
  189. *
  190. * It's important to reuse the same EditPlugin while the same scope is active,
  191. * as the clipboard is stored for the whole lifetime of the scope.
  192. */
  193. _getOryxEditPlugin: function ($scope) {
  194. if ($scope.oryxEditPlugin === undefined || $scope.oryxEditPlugin === null) {
  195. $scope.oryxEditPlugin = new ORYX.Plugins.Edit($scope.editor);
  196. }
  197. return $scope.oryxEditPlugin;
  198. },
  199. zoomIn: function (services) {
  200. KISBPM.TOOLBAR.ACTIONS._getOryxViewPlugin(services.$scope).zoom([1.0 + ORYX.CONFIG.ZOOM_OFFSET]);
  201. },
  202. zoomOut: function (services) {
  203. KISBPM.TOOLBAR.ACTIONS._getOryxViewPlugin(services.$scope).zoom([1.0 - ORYX.CONFIG.ZOOM_OFFSET]);
  204. },
  205. zoomActual: function (services) {
  206. KISBPM.TOOLBAR.ACTIONS._getOryxViewPlugin(services.$scope).setAFixZoomLevel(1);
  207. },
  208. zoomFit: function (services) {
  209. KISBPM.TOOLBAR.ACTIONS._getOryxViewPlugin(services.$scope).zoomFitToModel();
  210. },
  211. alignVertical: function (services) {
  212. KISBPM.TOOLBAR.ACTIONS._getOryxArrangmentPlugin(services.$scope).alignShapes([ORYX.CONFIG.EDITOR_ALIGN_MIDDLE]);
  213. },
  214. alignHorizontal: function (services) {
  215. KISBPM.TOOLBAR.ACTIONS._getOryxArrangmentPlugin(services.$scope).alignShapes([ORYX.CONFIG.EDITOR_ALIGN_CENTER]);
  216. },
  217. sameSize: function (services) {
  218. KISBPM.TOOLBAR.ACTIONS._getOryxArrangmentPlugin(services.$scope).alignShapes([ORYX.CONFIG.EDITOR_ALIGN_SIZE]);
  219. },
  220. closeEditor: function(services) {
  221. window.location.href = "./";
  222. },
  223. /**
  224. * Helper method: fetches the Oryx View plugin from the provided scope,
  225. * if not on the scope, it is created and put on the scope for further use.
  226. */
  227. _getOryxViewPlugin: function ($scope) {
  228. if ($scope.oryxViewPlugin === undefined || $scope.oryxViewPlugin === null) {
  229. $scope.oryxViewPlugin = new ORYX.Plugins.View($scope.editor);
  230. }
  231. return $scope.oryxViewPlugin;
  232. },
  233. _getOryxArrangmentPlugin: function ($scope) {
  234. if ($scope.oryxArrangmentPlugin === undefined || $scope.oryxArrangmentPlugin === null) {
  235. $scope.oryxArrangmentPlugin = new ORYX.Plugins.Arrangement($scope.editor);
  236. }
  237. return $scope.oryxArrangmentPlugin;
  238. },
  239. _getOryxDockerPlugin: function ($scope) {
  240. if ($scope.oryxDockerPlugin === undefined || $scope.oryxDockerPlugin === null) {
  241. $scope.oryxDockerPlugin = new ORYX.Plugins.AddDocker($scope.editor);
  242. }
  243. return $scope.oryxDockerPlugin;
  244. }
  245. }
  246. };
  247. /** Custom controller for the save dialog */
  248. var SaveModelCtrl = [ '$rootScope', '$scope', '$http', '$route', '$location',
  249. function ($rootScope, $scope, $http, $route, $location) {
  250. var modelMetaData = $scope.editor.getModelMetaData();
  251. var description = '';
  252. if (modelMetaData.description) {
  253. description = modelMetaData.description;
  254. }
  255. var saveDialog = { 'name' : modelMetaData.name,
  256. 'description' : description};
  257. $scope.saveDialog = saveDialog;
  258. var json = $scope.editor.getJSON();
  259. json = JSON.stringify(json);
  260. var params = {
  261. modeltype: modelMetaData.model.modelType,
  262. json_xml: json,
  263. name: 'model'
  264. };
  265. $scope.status = {
  266. loading: false
  267. };
  268. $scope.close = function () {
  269. $scope.$hide();
  270. };
  271. $scope.saveAndClose = function () {
  272. $scope.save(function() {
  273. window.location.href = "./";
  274. });
  275. };
  276. $scope.save = function (successCallback) {
  277. if (!$scope.saveDialog.name || $scope.saveDialog.name.length == 0) {
  278. return;
  279. }
  280. // Indicator spinner image
  281. $scope.status = {
  282. loading: true
  283. };
  284. modelMetaData.name = $scope.saveDialog.name;
  285. modelMetaData.description = $scope.saveDialog.description;
  286. var json = $scope.editor.getJSON();
  287. json = JSON.stringify(json);
  288. var selection = $scope.editor.getSelection();
  289. $scope.editor.setSelection([]);
  290. // Get the serialized svg image source
  291. var svgClone = $scope.editor.getCanvas().getSVGRepresentation(true);
  292. $scope.editor.setSelection(selection);
  293. if ($scope.editor.getCanvas().properties["oryx-showstripableelements"] === false) {
  294. var stripOutArray = jQuery(svgClone).find(".stripable-element");
  295. for (var i = stripOutArray.length - 1; i >= 0; i--) {
  296. stripOutArray[i].remove();
  297. }
  298. }
  299. // Remove all forced stripable elements
  300. var stripOutArray = jQuery(svgClone).find(".stripable-element-force");
  301. for (var i = stripOutArray.length - 1; i >= 0; i--) {
  302. stripOutArray[i].remove();
  303. }
  304. // Parse dom to string
  305. var svgDOM = DataManager.serialize(svgClone);
  306. var params = {
  307. json_xml: json,
  308. svg_xml: svgDOM,
  309. name: $scope.saveDialog.name,
  310. description: $scope.saveDialog.description
  311. };
  312. // Update
  313. $http({ method: 'PUT',
  314. data: params,
  315. ignoreErrors: true,
  316. headers: {'Accept': 'application/json',
  317. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
  318. transformRequest: function (obj) {
  319. var str = [];
  320. for (var p in obj) {
  321. str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
  322. }
  323. return str.join("&");
  324. },
  325. url: KISBPM.URL.putModel(modelMetaData.modelId)})
  326. .success(function (data, status, headers, config) {
  327. $scope.editor.handleEvents({
  328. type: ORYX.CONFIG.EVENT_SAVED
  329. });
  330. $scope.modelData.name = $scope.saveDialog.name;
  331. $scope.modelData.lastUpdated = data.lastUpdated;
  332. $scope.status.loading = false;
  333. $scope.$hide();
  334. // Fire event to all who is listening
  335. var saveEvent = {
  336. type: KISBPM.eventBus.EVENT_TYPE_MODEL_SAVED,
  337. model: params,
  338. modelId: modelMetaData.modelId,
  339. eventType: 'update-model'
  340. };
  341. KISBPM.eventBus.dispatch(KISBPM.eventBus.EVENT_TYPE_MODEL_SAVED, saveEvent);
  342. // Reset state
  343. $scope.error = undefined;
  344. $scope.status.loading = false;
  345. // Execute any callback
  346. if (successCallback) {
  347. successCallback();
  348. }
  349. })
  350. .error(function (data, status, headers, config) {
  351. $scope.error = {};
  352. console.log('Something went wrong when updating the process model:' + JSON.stringify(data));
  353. $scope.status.loading = false;
  354. });
  355. };
  356. }];