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

316 lines
9.2 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. var NORMAL_STROKE = 1;
  14. var SEQUENCEFLOW_STROKE = 1.5;
  15. var ASSOCIATION_STROKE = 2;
  16. var TASK_STROKE = 1;
  17. var TASK_HIGHLIGHT_STROKE = 2;
  18. var CALL_ACTIVITY_STROKE = 2;
  19. var ENDEVENT_STROKE = 3;
  20. var COMPLETED_COLOR= "#2632aa";
  21. var TEXT_COLOR= "#373e48";
  22. var CURRENT_COLOR= "#017501";
  23. var HOVER_COLOR= "#666666";
  24. var ACTIVITY_STROKE_COLOR = "#bbbbbb";
  25. var ACTIVITY_FILL_COLOR = "#f9f9f9";
  26. var MAIN_STROKE_COLOR = "#585858";
  27. var TEXT_PADDING = 3;
  28. var ARROW_WIDTH = 4;
  29. var MARKER_WIDTH = 12;
  30. var TASK_FONT = {font: "11px Arial", opacity: 1, fill: Raphael.rgb(0, 0, 0)};
  31. // icons
  32. var ICON_SIZE = 16;
  33. var ICON_PADDING = 4;
  34. var INITIAL_CANVAS_WIDTH;
  35. var INITIAL_CANVAS_HEIGHT;
  36. var paper;
  37. var viewBox;
  38. var viewBoxWidth;
  39. var viewBoxHeight;
  40. var canvasWidth;
  41. var canvasHeight;
  42. var modelDiv = jQuery('#bpmnModel');
  43. var modelId = modelDiv.attr('data-model-id');
  44. var historyModelId = modelDiv.attr('data-history-id');
  45. var processDefinitionId = modelDiv.attr('data-process-definition-id');
  46. var modelType = modelDiv.attr('data-model-type');
  47. // Support for custom background colors for activities
  48. var customActivityColors = modelDiv.attr('data-activity-color-mapping');
  49. if (customActivityColors !== null && customActivityColors !== undefined && customActivityColors.length > 0) {
  50. // Stored on the attribute as a string
  51. customActivityColors = JSON.parse(customActivityColors);
  52. }
  53. var customActivityToolTips = modelDiv.attr('data-activity-tooltips');
  54. if (customActivityToolTips !== null && customActivityToolTips !== undefined && customActivityToolTips.length > 0) {
  55. // Stored on the attribute as a string
  56. customActivityToolTips = JSON.parse(customActivityToolTips);
  57. }
  58. // Support for custom opacity for activity backgrounds
  59. var customActivityBackgroundOpacity = modelDiv.attr('data-activity-opacity');
  60. var elementsAdded = new Array();
  61. var elementsRemoved = new Array();
  62. function _showTip(htmlNode, element)
  63. {
  64. // Custom tooltip
  65. var documentation = undefined;
  66. if (customActivityToolTips) {
  67. if (customActivityToolTips[element.name]) {
  68. documentation = customActivityToolTips[element.name];
  69. } else if (customActivityToolTips[element.id]) {
  70. documentation = customActivityToolTips[element.id];
  71. } else {
  72. documentation = ''; // Show nothing if custom tool tips are enabled
  73. }
  74. }
  75. // Default tooltip, no custom tool tip set
  76. if (documentation === undefined) {
  77. var documentation = "";
  78. if (element.name && element.name.length > 0) {
  79. documentation += "<b>Name</b>: <i>" + element.name + "</i><br/><br/>";
  80. }
  81. if (element.properties) {
  82. for (var i = 0; i < element.properties.length; i++) {
  83. var propName = element.properties[i].name;
  84. if (element.properties[i].type && element.properties[i].type === 'list') {
  85. documentation += '<b>' + propName + '</b>:<br/>';
  86. for (var j = 0; j < element.properties[i].value.length; j++) {
  87. documentation += '<i>' + element.properties[i].value[j] + '</i><br/>';
  88. }
  89. }
  90. else {
  91. documentation += '<b>' + propName + '</b>: <i>' + element.properties[i].value + '</i><br/>';
  92. }
  93. }
  94. }
  95. }
  96. var text = element.type + " ";
  97. if (element.name && element.name.length > 0)
  98. {
  99. text += element.name;
  100. }
  101. else
  102. {
  103. text += element.id;
  104. }
  105. htmlNode.qtip({
  106. content: {
  107. text: documentation,
  108. title: {
  109. text: text
  110. }
  111. },
  112. position: {
  113. my: 'top left',
  114. at: 'bottom center',
  115. viewport: jQuery('#bpmnModel')
  116. },
  117. hide: {
  118. fixed: true, delay: 500,
  119. event: 'click mouseleave'
  120. },
  121. style: {
  122. classes: 'ui-tooltip-kisbpm-bpmn'
  123. }
  124. });
  125. }
  126. function _addHoverLogic(element, type, defaultColor)
  127. {
  128. var strokeColor = _bpmnGetColor(element, defaultColor);
  129. var topBodyRect = null;
  130. if (type === "rect")
  131. {
  132. topBodyRect = paper.rect(element.x, element.y, element.width, element.height);
  133. }
  134. else if (type === "circle")
  135. {
  136. var x = element.x + (element.width / 2);
  137. var y = element.y + (element.height / 2);
  138. topBodyRect = paper.circle(x, y, 15);
  139. }
  140. else if (type === "rhombus")
  141. {
  142. topBodyRect = paper.path("M" + element.x + " " + (element.y + (element.height / 2)) +
  143. "L" + (element.x + (element.width / 2)) + " " + (element.y + element.height) +
  144. "L" + (element.x + element.width) + " " + (element.y + (element.height / 2)) +
  145. "L" + (element.x + (element.width / 2)) + " " + element.y + "z"
  146. );
  147. }
  148. var opacity = 0;
  149. var fillColor = "#ffffff";
  150. if (jQuery.inArray(element.id, elementsAdded) >= 0)
  151. {
  152. opacity = 0.2;
  153. fillColor = "green";
  154. }
  155. if (jQuery.inArray(element.id, elementsRemoved) >= 0)
  156. {
  157. opacity = 0.2;
  158. fillColor = "red";
  159. }
  160. topBodyRect.attr({
  161. "opacity": opacity,
  162. "stroke" : "none",
  163. "fill" : fillColor
  164. });
  165. _showTip(jQuery(topBodyRect.node), element);
  166. topBodyRect.mouseover(function() {
  167. paper.getById(element.id).attr({"stroke":HOVER_COLOR});
  168. });
  169. topBodyRect.mouseout(function() {
  170. paper.getById(element.id).attr({"stroke":strokeColor});
  171. });
  172. }
  173. function _zoom(zoomIn)
  174. {
  175. var tmpCanvasWidth, tmpCanvasHeight;
  176. if (zoomIn)
  177. {
  178. tmpCanvasWidth = canvasWidth * (1.0/0.90);
  179. tmpCanvasHeight = canvasHeight * (1.0/0.90);
  180. }
  181. else
  182. {
  183. tmpCanvasWidth = canvasWidth * (1.0/1.10);
  184. tmpCanvasHeight = canvasHeight * (1.0/1.10);
  185. }
  186. if (tmpCanvasWidth != canvasWidth || tmpCanvasHeight != canvasHeight)
  187. {
  188. canvasWidth = tmpCanvasWidth;
  189. canvasHeight = tmpCanvasHeight;
  190. paper.setSize(canvasWidth, canvasHeight);
  191. }
  192. }
  193. var modelUrl;
  194. if (modelType == 'runtime') {
  195. if (historyModelId) {
  196. modelUrl = FLOWABLE.APP_URL.getProcessInstanceModelJsonHistoryUrl(historyModelId);
  197. } else {
  198. modelUrl = FLOWABLE.APP_URL.getProcessInstanceModelJsonUrl(modelId);
  199. }
  200. } else if (modelType == 'design') {
  201. if (historyModelId) {
  202. modelUrl = FLOWABLE.APP_URL.getModelHistoryModelJsonUrl(modelId, historyModelId);
  203. } else {
  204. modelUrl = FLOWABLE.APP_URL.getModelModelJsonUrl(modelId);
  205. }
  206. } else if (modelType == 'process-definition') {
  207. modelUrl = FLOWABLE.APP_URL.getProcessDefinitionModelJsonUrl(processDefinitionId);
  208. }
  209. var request = jQuery.ajax({
  210. type: 'get',
  211. url: modelUrl + '?nocaching=' + new Date().getTime()
  212. });
  213. request.success(function(data, textStatus, jqXHR) {
  214. if ((!data.elements || data.elements.length == 0) && (!data.pools || data.pools.length == 0)) return;
  215. INITIAL_CANVAS_WIDTH = data.diagramWidth;
  216. if (modelType == 'design') {
  217. INITIAL_CANVAS_WIDTH += 20;
  218. } else {
  219. INITIAL_CANVAS_WIDTH += 30;
  220. }
  221. INITIAL_CANVAS_HEIGHT = data.diagramHeight + 50;
  222. canvasWidth = INITIAL_CANVAS_WIDTH;
  223. canvasHeight = INITIAL_CANVAS_HEIGHT;
  224. viewBoxWidth = INITIAL_CANVAS_WIDTH;
  225. viewBoxHeight = INITIAL_CANVAS_HEIGHT;
  226. if (modelType == 'design') {
  227. var headerBarHeight = 170;
  228. var offsetY = 0;
  229. if (jQuery(window).height() > (canvasHeight + headerBarHeight))
  230. {
  231. offsetY = (jQuery(window).height() - headerBarHeight - canvasHeight) / 2;
  232. }
  233. if (offsetY > 50) {
  234. offsetY = 50;
  235. }
  236. jQuery('#bpmnModel').css('marginTop', offsetY);
  237. }
  238. jQuery('#bpmnModel').width(INITIAL_CANVAS_WIDTH);
  239. jQuery('#bpmnModel').height(INITIAL_CANVAS_HEIGHT);
  240. paper = Raphael(document.getElementById('bpmnModel'), canvasWidth, canvasHeight);
  241. paper.setViewBox(0, 0, viewBoxWidth, viewBoxHeight, false);
  242. paper.renderfix();
  243. if (data.pools)
  244. {
  245. for (var i = 0; i < data.pools.length; i++)
  246. {
  247. var pool = data.pools[i];
  248. _drawPool(pool);
  249. }
  250. }
  251. var modelElements = data.elements;
  252. for (var i = 0; i < modelElements.length; i++)
  253. {
  254. var element = modelElements[i];
  255. //try {
  256. var drawFunction = eval("_draw" + element.type);
  257. drawFunction(element);
  258. //} catch(err) {console.log(err);}
  259. }
  260. if (data.flows)
  261. {
  262. for (var i = 0; i < data.flows.length; i++)
  263. {
  264. var flow = data.flows[i];
  265. if (flow.type === 'sequenceFlow') {
  266. _drawFlow(flow);
  267. } else if (flow.type === 'association') {
  268. _drawAssociation(flow);
  269. }
  270. }
  271. }
  272. });
  273. request.error(function(jqXHR, textStatus, errorThrown) {
  274. alert("error");
  275. });