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

512 lines
14 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. function _cmmnGetColor(element, defaultColor)
  14. {
  15. var strokeColor;
  16. if(element.current) {
  17. strokeColor = CURRENT_COLOR;
  18. } else if(element.completed) {
  19. strokeColor = COMPLETED_COLOR;
  20. } else {
  21. strokeColor = defaultColor;
  22. }
  23. return strokeColor;
  24. }
  25. function _drawPlanModel(planModel)
  26. {
  27. var rect = paper.rect(planModel.x, planModel.y, planModel.width, planModel.height);
  28. rect.attr({"stroke-width": 1,
  29. "stroke": "#000000",
  30. "fill": "white"
  31. });
  32. if (planModel.name)
  33. {
  34. var planModelName = paper.text(planModel.x + 14, planModel.y + (planModel.height / 2), planModel.name).attr({
  35. "text-anchor" : "middle",
  36. "font-family" : "Arial",
  37. "font-size" : "12",
  38. "fill" : "#000000"
  39. });
  40. planModelName.transform("r270");
  41. }
  42. }
  43. function _drawSubProcess(element)
  44. {
  45. var rect = paper.rect(element.x, element.y, element.width, element.height, 4);
  46. var strokeColor = _cmmnGetColor(element, MAIN_STROKE_COLOR);
  47. rect.attr({"stroke-width": 1,
  48. "stroke": strokeColor,
  49. "fill": "white"
  50. });
  51. }
  52. function _drawServiceTaskTypeIcon(element)
  53. {
  54. _drawTask(element);
  55. if (element.taskType === "mail")
  56. {
  57. _drawSendTaskIcon(paper, element.x + 4, element.y + 4);
  58. }
  59. else if (element.taskType === "camel")
  60. {
  61. _drawCamelTaskIcon(paper, element.x + 4, element.y + 4);
  62. }
  63. else if (element.taskType === "mule")
  64. {
  65. _drawMuleTaskIcon(paper, element.x + 4, element.y + 4);
  66. }
  67. else if (element.taskType === "http")
  68. {
  69. _drawHttpTaskIcon(paper, element.x + 4, element.y + 4);
  70. }
  71. else if (element.stencilIconId)
  72. {
  73. paper.image("../service/stencilitem/" + element.stencilIconId + "/icon", element.x + 4, element.y + 4, 16, 16);
  74. }
  75. else
  76. {
  77. _drawServiceTaskIcon(paper, element.x + 4, element.y + 4);
  78. }
  79. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  80. }
  81. function _drawHttpServiceTask(element)
  82. {
  83. _drawTask(element);
  84. _drawHttpTaskIcon(paper, element.x + 4, element.y + 4);
  85. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  86. }
  87. function _drawHumanTask(element)
  88. {
  89. _drawTask(element);
  90. _drawHumanTaskIcon(paper, element.x + 4, element.y + 4);
  91. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  92. }
  93. function _drawCaseTask(element)
  94. {
  95. _drawTask(element);
  96. _drawCaseTaskIcon(paper, element.x + 1, element.y + 1);
  97. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  98. }
  99. function _drawProcessTask(element)
  100. {
  101. _drawTask(element);
  102. _drawProcessTaskIcon(paper, element.x + 1, element.y + 1);
  103. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  104. }
  105. function _drawScriptTaskIcon(paper, startX, startY)
  106. {
  107. var path1 = paper.path("m 5,2 0,0.094 c 0.23706,0.064 0.53189,0.1645 0.8125,0.375 0.5582,0.4186 1.05109,1.228 1.15625,2.5312 l 8.03125,0 1,0 1,0 c 0,-3 -2,-3 -2,-3 l -10,0 z M 4,3 4,13 2,13 c 0,3 2,3 2,3 l 9,0 c 0,0 2,0 2,-3 L 15,6 6,6 6,5.5 C 6,4.1111 5.5595,3.529 5.1875,3.25 4.8155,2.971 4.5,3 4.5,3 L 4,3 z");
  108. path1.attr({
  109. "opacity": 1,
  110. "stroke": "none",
  111. "fill": "#72a7d0"
  112. });
  113. var scriptTaskIcon = paper.set();
  114. scriptTaskIcon.push(path1);
  115. scriptTaskIcon.transform("T" + startX + "," + startY);
  116. }
  117. function _drawScriptServiceTask(element)
  118. {
  119. _drawTask(element);
  120. _drawScriptTaskIcon(paper, element.x + 4, element.y + 4);
  121. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  122. }
  123. function _drawSendEventServiceTask(element)
  124. {
  125. _drawTask(element);
  126. _drawSendTaskIcon(paper, element.x + 4, element.y + 4);
  127. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  128. }
  129. function _drawExternalWorkerServiceTask(element)
  130. {
  131. _drawTask(element);
  132. _drawServiceTaskIcon(paper, element.x + 4, element.y + 4);
  133. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  134. }
  135. function _drawDecisionTask(element)
  136. {
  137. _drawTask(element);
  138. _drawDecisionTaskIcon(paper, element.x + 1, element.y + 1);
  139. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  140. }
  141. function _drawServiceTask(element)
  142. {
  143. _drawTask(element);
  144. _drawServiceTaskTypeIcon(element);
  145. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  146. }
  147. function _drawTask(element)
  148. {
  149. var rectAttrs = {};
  150. // Stroke
  151. var strokeColor = _cmmnGetColor(element, ACTIVITY_STROKE_COLOR);
  152. rectAttrs['stroke'] = strokeColor;
  153. var strokeWidth;
  154. if (strokeColor === ACTIVITY_STROKE_COLOR) {
  155. strokeWidth = TASK_STROKE;
  156. } else {
  157. strokeWidth = TASK_HIGHLIGHT_STROKE;
  158. }
  159. var width = element.width - (strokeWidth / 2);
  160. var height = element.height - (strokeWidth / 2);
  161. var rect = paper.rect(element.x, element.y, width, height, 4);
  162. rectAttrs['stroke-width'] = strokeWidth;
  163. // Fill
  164. rectAttrs['fill'] = ACTIVITY_FILL_COLOR;
  165. rect.attr(rectAttrs);
  166. rect.id = element.id;
  167. if (element.name) {
  168. this._drawMultilineText(element.name, element.x, element.y, element.width, element.height, "middle", "middle", 11);
  169. }
  170. }
  171. function _drawTimerEventListener(element)
  172. {
  173. _drawEventListener(element);
  174. _drawTimerEventListenerIcon(paper, element);
  175. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  176. }
  177. function _drawUserEventListener(element)
  178. {
  179. _drawEventListener(element);
  180. _drawUserEventListenerIcon(paper, element);
  181. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  182. }
  183. function _drawVariableEventListener(element)
  184. {
  185. _drawEventListener(element);
  186. _drawVariableEventListenerIcon(paper, element);
  187. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  188. }
  189. function _drawGenericEventListener(element)
  190. {
  191. _drawEventListener(element);
  192. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  193. }
  194. function _drawEventListener(element)
  195. {
  196. var x = element.x + (element.width / 2);
  197. var y = element.y + (element.height / 2);
  198. var circle = paper.circle(x, y, 15);
  199. circle.attr({"stroke-width": 1,
  200. "stroke": "black",
  201. "fill": "white"
  202. });
  203. circle.id = element.id;
  204. }
  205. function _drawMilestone(element)
  206. {
  207. var rectAttrs = {};
  208. // Stroke
  209. var strokeColor = _cmmnGetColor(element, ACTIVITY_STROKE_COLOR);
  210. rectAttrs['stroke'] = strokeColor;
  211. var strokeWidth;
  212. if (strokeColor === ACTIVITY_STROKE_COLOR) {
  213. strokeWidth = TASK_STROKE;
  214. } else {
  215. strokeWidth = TASK_HIGHLIGHT_STROKE;
  216. }
  217. var width = element.width - (strokeWidth / 2);
  218. var height = element.height - (strokeWidth / 2);
  219. var rect = paper.rect(element.x, element.y, width, height, 24);
  220. rectAttrs['stroke-width'] = strokeWidth;
  221. // Fill
  222. rectAttrs['fill'] = WHITE_FILL_COLOR;
  223. rect.attr(rectAttrs);
  224. rect.id = element.id;
  225. if (element.name) {
  226. this._drawMultilineText(element.name, element.x, element.y, element.width, element.height, "middle", "middle", 11);
  227. }
  228. }
  229. function _drawStage(element)
  230. {
  231. var rectAttrs = {};
  232. // Stroke
  233. var strokeColor = _cmmnGetColor(element, ACTIVITY_STROKE_COLOR);
  234. rectAttrs['stroke'] = strokeColor;
  235. var strokeWidth;
  236. if (strokeColor === ACTIVITY_STROKE_COLOR) {
  237. strokeWidth = TASK_STROKE;
  238. } else {
  239. strokeWidth = TASK_HIGHLIGHT_STROKE;
  240. }
  241. var width = element.width - (strokeWidth / 2);
  242. var height = element.height - (strokeWidth / 2);
  243. var rect = paper.rect(element.x, element.y, width, height, 16);
  244. rectAttrs['stroke-width'] = strokeWidth;
  245. // Fill
  246. rectAttrs['fill'] = WHITE_FILL_COLOR;
  247. rect.attr(rectAttrs);
  248. rect.id = element.id;
  249. if (element.name) {
  250. this._drawMultilineText(element.name, element.x + 10, element.y + 5, element.width, element.height, "start", "top", 11);
  251. }
  252. }
  253. function _drawPlanModel(element)
  254. {
  255. var rectAttrs = {};
  256. // Stroke
  257. var strokeColor = _cmmnGetColor(element, ACTIVITY_STROKE_COLOR);
  258. rectAttrs['stroke'] = strokeColor;
  259. var strokeWidth;
  260. if (strokeColor === ACTIVITY_STROKE_COLOR) {
  261. strokeWidth = TASK_STROKE;
  262. } else {
  263. strokeWidth = TASK_HIGHLIGHT_STROKE;
  264. }
  265. var width = element.width - (strokeWidth / 2);
  266. var height = element.height - (strokeWidth / 2);
  267. var rect = paper.rect(element.x, element.y, width, height, 4);
  268. rectAttrs['stroke-width'] = strokeWidth;
  269. // Fill
  270. rectAttrs['fill'] = WHITE_FILL_COLOR;
  271. rect.attr(rectAttrs);
  272. rect.id = element.id;
  273. var path1 = paper.path("M20 55 L37 34 L275 34 L291 55");
  274. path1.attr({
  275. "opacity": 1,
  276. "stroke": strokeColor,
  277. "fill": "#ffffff"
  278. });
  279. var planModelHeader = paper.set();
  280. planModelHeader.push(path1);
  281. planModelHeader.translate(element.x, element.y - 55);
  282. if (element.name) {
  283. this._drawMultilineText(element.name, element.x + 10, element.y - 16, 275, element.height, "middle", "top", 11);
  284. }
  285. }
  286. function _drawEntryCriterion(element)
  287. {
  288. var strokeColor = _cmmnGetColor(element, MAIN_STROKE_COLOR);
  289. var rhombus = paper.path("M" + element.x + " " + (element.y + (element.height / 2)) +
  290. "L" + (element.x + (element.width / 2)) + " " + (element.y + element.height) +
  291. "L" + (element.x + element.width) + " " + (element.y + (element.height / 2)) +
  292. "L" + (element.x + (element.width / 2)) + " " + element.y + "z"
  293. );
  294. // Fill
  295. var gatewayFillColor = WHITE_FILL_COLOR;
  296. // Opacity
  297. var gatewayOpacity = 1.0;
  298. rhombus.attr("stroke-width", 1);
  299. rhombus.attr("stroke", strokeColor);
  300. rhombus.attr("fill", gatewayFillColor);
  301. rhombus.attr("fill-opacity", gatewayOpacity);
  302. rhombus.id = element.id;
  303. }
  304. function _drawExitCriterion(element)
  305. {
  306. var strokeColor = _cmmnGetColor(element, MAIN_STROKE_COLOR);
  307. var rhombus = paper.path("M" + element.x + " " + (element.y + (element.height / 2)) +
  308. "L" + (element.x + (element.width / 2)) + " " + (element.y + element.height) +
  309. "L" + (element.x + element.width) + " " + (element.y + (element.height / 2)) +
  310. "L" + (element.x + (element.width / 2)) + " " + element.y + "z"
  311. );
  312. // Fill
  313. var gatewayFillColor = '#000000';
  314. // Opacity
  315. var gatewayOpacity = 1.0;
  316. rhombus.attr("stroke-width", 1);
  317. rhombus.attr("stroke", strokeColor);
  318. rhombus.attr("fill", gatewayFillColor);
  319. rhombus.attr("fill-opacity", gatewayOpacity);
  320. rhombus.id = element.id;
  321. }
  322. function _drawMultilineText(text, x, y, boxWidth, boxHeight, horizontalAnchor, verticalAnchor, fontSize)
  323. {
  324. if (!text || text == "")
  325. {
  326. return;
  327. }
  328. var textBoxX, textBoxY;
  329. var width = boxWidth - (2 * TEXT_PADDING);
  330. if (horizontalAnchor === "middle")
  331. {
  332. textBoxX = x + (boxWidth / 2);
  333. }
  334. else if (horizontalAnchor === "start")
  335. {
  336. textBoxX = x;
  337. }
  338. textBoxY = y + (boxHeight / 2);
  339. var t = paper.text(textBoxX + TEXT_PADDING, textBoxY + TEXT_PADDING).attr({
  340. "text-anchor" : horizontalAnchor,
  341. "font-family" : "Arial",
  342. "font-size" : fontSize,
  343. "fill" : "#373e48"
  344. });
  345. var abc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  346. t.attr({
  347. "text" : abc
  348. });
  349. var letterWidth = t.getBBox().width / abc.length;
  350. t.attr({
  351. "text" : text
  352. });
  353. var removedLineBreaks = text.split("\n");
  354. var x = 0, s = [];
  355. for (var r = 0; r < removedLineBreaks.length; r++)
  356. {
  357. var words = removedLineBreaks[r].split(" ");
  358. for ( var i = 0; i < words.length; i++) {
  359. var l = words[i].length;
  360. if (x + (l * letterWidth) > width) {
  361. s.push("\n");
  362. x = 0;
  363. }
  364. x += l * letterWidth;
  365. s.push(words[i] + " ");
  366. }
  367. s.push("\n");
  368. x = 0;
  369. }
  370. t.attr({
  371. "text" : s.join("")
  372. });
  373. if (verticalAnchor && verticalAnchor === "top")
  374. {
  375. t.attr({"y": y + (t.getBBox().height / 2)});
  376. }
  377. }
  378. function _drawAssociation(flow){
  379. var polyline = new Polyline(flow.id, flow.waypoints, ASSOCIATION_STROKE, paper);
  380. polyline.element = paper.path(polyline.path);
  381. polyline.element.attr({"stroke-width": ASSOCIATION_STROKE});
  382. polyline.element.attr({"stroke-dasharray": ". "});
  383. polyline.element.attr({"stroke":"#585858"});
  384. polyline.element.id = flow.id;
  385. var polylineInvisible = new Polyline(flow.id, flow.waypoints, ASSOCIATION_STROKE, paper);
  386. polylineInvisible.element = paper.path(polyline.path);
  387. polylineInvisible.element.attr({
  388. "opacity": 0,
  389. "stroke-width": 8,
  390. "stroke" : "#000000"
  391. });
  392. _showTip(jQuery(polylineInvisible.element.node), flow);
  393. polylineInvisible.element.mouseover(function() {
  394. paper.getById(polyline.element.id).attr({"stroke":"blue"});
  395. });
  396. polylineInvisible.element.mouseout(function() {
  397. paper.getById(polyline.element.id).attr({"stroke":"#585858"});
  398. });
  399. }
  400. function _drawArrowHead(line, connectionType)
  401. {
  402. var doubleArrowWidth = 2 * ARROW_WIDTH;
  403. var arrowHead = paper.path("M0 0L-" + (ARROW_WIDTH / 2 + .5) + " -" + doubleArrowWidth + "L" + (ARROW_WIDTH/2 + .5) + " -" + doubleArrowWidth + "z");
  404. // anti smoothing
  405. if (this.strokeWidth%2 == 1)
  406. line.x2 += .5, line.y2 += .5;
  407. arrowHead.transform("t" + line.x2 + "," + line.y2 + "");
  408. arrowHead.transform("...r" + Raphael.deg(line.angle - Math.PI / 2) + " " + 0 + " " + 0);
  409. arrowHead.attr("fill", "#585858");
  410. arrowHead.attr("stroke-width", SEQUENCEFLOW_STROKE);
  411. arrowHead.attr("stroke", "#585858");
  412. return arrowHead;
  413. }