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

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