图书馆智能管理系统
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.

272 lines
7.6 KiB

5 months ago
  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 TEXT_COLOR= "#373e48";
  18. var CURRENT_COLOR= "#017501";
  19. var HOVER_COLOR= "#666666";
  20. var ACTIVITY_STROKE_COLOR = "#bbbbbb";
  21. var ACTIVITY_FILL_COLOR = "#f9f9f9";
  22. var WHITE_FILL_COLOR = "#ffffff";
  23. var MAIN_STROKE_COLOR = "#585858";
  24. var TEXT_PADDING = 3;
  25. var ARROW_WIDTH = 4;
  26. var MARKER_WIDTH = 12;
  27. var TASK_FONT = {font: "11px Arial", opacity: 1, fill: Raphael.rgb(0, 0, 0)};
  28. // icons
  29. var ICON_SIZE = 16;
  30. var ICON_PADDING = 4;
  31. var INITIAL_CANVAS_WIDTH;
  32. var INITIAL_CANVAS_HEIGHT;
  33. var paper;
  34. var viewBox;
  35. var viewBoxWidth;
  36. var viewBoxHeight;
  37. var canvasWidth;
  38. var canvasHeight;
  39. var modelDiv = jQuery('#cmmnModel');
  40. var modelId = modelDiv.attr('data-model-id');
  41. var historyModelId = modelDiv.attr('data-history-id');
  42. var caseDefinitionId = modelDiv.attr('data-case-definition-id');
  43. var modelType = modelDiv.attr('data-model-type');
  44. var elementsAdded = new Array();
  45. var elementsRemoved = new Array();
  46. function _showTip(htmlNode, element)
  47. {
  48. // Default tooltip, no custom tool tip set
  49. if (documentation === undefined) {
  50. var documentation = "";
  51. if (element.name && element.name.length > 0) {
  52. documentation += "<b>Name</b>: <i>" + element.name + "</i><br/><br/>";
  53. }
  54. if (element.properties) {
  55. for (var i = 0; i < element.properties.length; i++) {
  56. var propName = element.properties[i].name;
  57. if (element.properties[i].type && element.properties[i].type === 'list') {
  58. documentation += '<b>' + propName + '</b>:<br/>';
  59. for (var j = 0; j < element.properties[i].value.length; j++) {
  60. documentation += '<i>' + element.properties[i].value[j] + '</i><br/>';
  61. }
  62. }
  63. else {
  64. documentation += '<b>' + propName + '</b>: <i>' + element.properties[i].value + '</i><br/>';
  65. }
  66. }
  67. }
  68. }
  69. var text = element.type + " ";
  70. if (element.name && element.name.length > 0)
  71. {
  72. text += element.name;
  73. }
  74. else
  75. {
  76. text += element.id;
  77. }
  78. htmlNode.qtip({
  79. content: {
  80. text: documentation,
  81. title: {
  82. text: text
  83. }
  84. },
  85. position: {
  86. my: 'top left',
  87. at: 'bottom center',
  88. viewport: jQuery('#cmmnModel')
  89. },
  90. hide: {
  91. fixed: true, delay: 500,
  92. event: 'click mouseleave'
  93. },
  94. style: {
  95. classes: 'ui-tooltip-flowable-cmmn'
  96. }
  97. });
  98. }
  99. function _addHoverLogic(element, type, defaultColor)
  100. {
  101. var strokeColor = _cmmnGetColor(element, defaultColor);
  102. var topBodyRect = null;
  103. if (type === "rect")
  104. {
  105. topBodyRect = paper.rect(element.x, element.y, element.width, element.height);
  106. }
  107. else if (type === "circle")
  108. {
  109. var x = element.x + (element.width / 2);
  110. var y = element.y + (element.height / 2);
  111. topBodyRect = paper.circle(x, y, 15);
  112. }
  113. else if (type === "rhombus")
  114. {
  115. topBodyRect = paper.path("M" + element.x + " " + (element.y + (element.height / 2)) +
  116. "L" + (element.x + (element.width / 2)) + " " + (element.y + element.height) +
  117. "L" + (element.x + element.width) + " " + (element.y + (element.height / 2)) +
  118. "L" + (element.x + (element.width / 2)) + " " + element.y + "z"
  119. );
  120. }
  121. var opacity = 0;
  122. var fillColor = "#ffffff";
  123. if (jQuery.inArray(element.id, elementsAdded) >= 0)
  124. {
  125. opacity = 0.2;
  126. fillColor = "green";
  127. }
  128. if (jQuery.inArray(element.id, elementsRemoved) >= 0)
  129. {
  130. opacity = 0.2;
  131. fillColor = "red";
  132. }
  133. topBodyRect.attr({
  134. "opacity": opacity,
  135. "stroke" : "none",
  136. "fill" : fillColor
  137. });
  138. _showTip(jQuery(topBodyRect.node), element);
  139. topBodyRect.mouseover(function() {
  140. paper.getById(element.id).attr({"stroke":HOVER_COLOR});
  141. });
  142. topBodyRect.mouseout(function() {
  143. paper.getById(element.id).attr({"stroke":strokeColor});
  144. });
  145. }
  146. function _zoom(zoomIn)
  147. {
  148. var tmpCanvasWidth, tmpCanvasHeight;
  149. if (zoomIn)
  150. {
  151. tmpCanvasWidth = canvasWidth * (1.0/0.90);
  152. tmpCanvasHeight = canvasHeight * (1.0/0.90);
  153. }
  154. else
  155. {
  156. tmpCanvasWidth = canvasWidth * (1.0/1.10);
  157. tmpCanvasHeight = canvasHeight * (1.0/1.10);
  158. }
  159. if (tmpCanvasWidth != canvasWidth || tmpCanvasHeight != canvasHeight)
  160. {
  161. canvasWidth = tmpCanvasWidth;
  162. canvasHeight = tmpCanvasHeight;
  163. paper.setSize(canvasWidth, canvasHeight);
  164. }
  165. }
  166. var modelUrl;
  167. if (modelType == 'runtime') {
  168. if (historyModelId) {
  169. modelUrl = FLOWABLE.APP_URL.getCaseInstancesHistoryModelJsonUrl(historyModelId);
  170. } else {
  171. modelUrl = FLOWABLE.APP_URL.getCaseInstancesModelJsonUrl(modelId);
  172. }
  173. } else if (modelType == 'design') {
  174. if (historyModelId) {
  175. modelUrl = FLOWABLE.APP_URL.getModelHistoryModelJsonUrl(modelId, historyModelId);
  176. } else {
  177. modelUrl = FLOWABLE.APP_URL.getModelModelJsonUrl(modelId);
  178. }
  179. } else if (modelType == 'case-definition') {
  180. modelUrl = FLOWABLE.APP_URL.getCaseDefinitionModelJsonUrl(caseDefinitionId);
  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('#cmmnModel').css('marginTop', offsetY);
  210. }
  211. jQuery('#cmmnModel').width(INITIAL_CANVAS_WIDTH);
  212. jQuery('#cmmnModel').height(INITIAL_CANVAS_HEIGHT);
  213. paper = Raphael(document.getElementById('cmmnModel'), 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. _drawAssociation(flow);
  231. }
  232. }
  233. });
  234. request.error(function(jqXHR, textStatus, errorThrown) {
  235. alert("error");
  236. });