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

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