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.

editor-utils.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. /**
  19. * Utility methods are grouped together here.
  20. */
  21. var EDITOR = EDITOR || {};
  22. EDITOR.UTIL = {
  23. getParameterByName: function (name) {
  24. name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  25. var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
  26. results = regex.exec(location.search);
  27. return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  28. },
  29. /**
  30. * Starts at the provided start element, and walks all preceding elements in the graph.
  31. * Each element is tested to have a certain property and, if it has, adds this property value
  32. * to the return result list.
  33. */
  34. collectPropertiesFromPrecedingElements: function (startElement, propertyType) {
  35. var visitedElements = [];
  36. var collectedProperties = [];
  37. EDITOR.UTIL._visitElementAndCollectProperty(startElement, propertyType, visitedElements, collectedProperties);
  38. return collectedProperties;
  39. },
  40. /**
  41. * Starts at the provided start element, and walks all preceding elements in the graph.
  42. * Each element is tested to be a specific stencil id and, if it has, adds the element
  43. * to the return result list.
  44. */
  45. collectElementsFromPrecedingElements: function (startElement, stencilId) {
  46. var visitedElements = [];
  47. var collectedElements = [];
  48. var incomingShapesIterator = startElement.getIncomingShapes();
  49. if (incomingShapesIterator) {
  50. for (var i = 0; i < incomingShapesIterator.length; i++) {
  51. var incomingShape = incomingShapesIterator[i];
  52. if (visitedElements.indexOf(incomingShape.id) < 0) {
  53. EDITOR.UTIL._visitElementAndCollectElement(incomingShape, stencilId, visitedElements, collectedElements);
  54. }
  55. }
  56. }
  57. return collectedElements;
  58. },
  59. _visitElementAndCollectProperty: function (element, propertyType, visitedElementsArray, collectedProperties) {
  60. visitedElementsArray.push(element.id);
  61. var property = element.properties[propertyType]
  62. if (property) {
  63. collectedProperties.push(property);
  64. }
  65. var incomingShapesIterator = element.getIncomingShapes();
  66. if (incomingShapesIterator) {
  67. for (var i = 0; i < incomingShapesIterator.length; i++) {
  68. var incomingShape = incomingShapesIterator[i];
  69. if (visitedElementsArray.indexOf(incomingShape.id) < 0) {
  70. EDITOR.UTIL._visitElementAndCollectProperty(incomingShape, propertyType, visitedElementsArray, collectedProperties);
  71. }
  72. }
  73. }
  74. },
  75. _visitElementAndCollectElement: function (element, stencilId, visitedElementsArray, collectedElements) {
  76. visitedElementsArray.push(element.id);
  77. var elementStencilId = element.getStencil().id();
  78. if (elementStencilId && elementStencilId.indexOf(stencilId) >= 0) {
  79. collectedElements.push(element);
  80. }
  81. var incomingShapesIterator = element.getIncomingShapes();
  82. if (incomingShapesIterator) {
  83. for (var i = 0; i < incomingShapesIterator.length; i++) {
  84. var incomingShape = incomingShapesIterator[i];
  85. if (visitedElementsArray.indexOf(incomingShape.id) < 0) {
  86. EDITOR.UTIL._visitElementAndCollectElement(incomingShape, stencilId, visitedElementsArray, collectedElements);
  87. }
  88. }
  89. }
  90. },
  91. /**
  92. * Goes up the chain of parents of the provided element.
  93. * When the property is encountered, its value is immediately returned.
  94. * If the chain of parents is completely walked through, undefined is returned.
  95. */
  96. getPropertyFromParent: function (element, propertyType) {
  97. if (element.parent) {
  98. return EDITOR.UTIL._getPropertyFromParent(element.parent, propertyType);
  99. } else {
  100. return undefined;
  101. }
  102. },
  103. _getPropertyFromParent: function (parentElement, propertyType) {
  104. var property = parentElement.properties[propertyType];
  105. if (property) {
  106. return property;
  107. }
  108. if (parentElement.parent) {
  109. return EDITOR.UTIL._getPropertyFromParent(parentElement.parent, propertyType);
  110. } else {
  111. return undefined;
  112. }
  113. }
  114. };