RoadFlow2.1 临时演示

workflow.js 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. var wf_r = null; //画板对象
  2. var wf_steps = []; //步骤数组
  3. var wf_texts = []; //文本数组
  4. var wf_conns = []; //连线数组
  5. var wf_option = ""; //当前操作
  6. var wf_focusObj = null; //当前焦点对象
  7. var wf_width = 108; //步骤宽度
  8. var wf_height = 50; //步骤高度
  9. var wf_rect = 8; //圆角大小
  10. var wf_designer = true; //是否是设计模式(查看流程图时不帮定双击事件)
  11. var wf_connColor = "#898a89"; //连线的常规颜色
  12. var wf_nodeBorderColor = "#587aa9"; //节点边框颜色
  13. var wf_noteColor = "#efeff0"; //节点填充颜色
  14. var wf_stepDefaultName = "新步骤";//默认步骤名称
  15. var tempArrPath = []; //临时连线
  16. var mouseX = 0;
  17. var mouseY = 0;
  18. var wf_json = {}; //设计json
  19. var wf_id = "";//当前流程ID
  20. var links_tables_fields = [];//当前流程的所有连接所有表和字段
  21. $(function ()
  22. {
  23. wf_r = Raphael("flowdiv", $(window).width(), $(window).height() - 28);
  24. wf_r.customAttributes.type1 = function () { };
  25. wf_r.customAttributes.fromid = function () { };
  26. wf_r.customAttributes.toid = function () { };
  27. });
  28. //添加步骤
  29. function addStep(x, y, text, id, addToJSON, type1, bordercolor, bgcolor)
  30. {
  31. var guid = getGuid();
  32. var xy = getNewXY();
  33. x = x || xy.x;
  34. y = y || xy.y;
  35. text = text || wf_stepDefaultName;
  36. id = id || guid;
  37. var rect = wf_r.rect(x, y, wf_width, wf_height, wf_rect);
  38. rect.attr({ "fill": bgcolor || wf_noteColor, "stroke": bordercolor || wf_nodeBorderColor, "stroke-width": 1.4, "cursor": "default"});
  39. rect.id = id;
  40. rect.type1 = type1 ? type1 : "normal";
  41. rect.drag(move, dragger, up);
  42. if (wf_designer)
  43. {
  44. rect.click(click);
  45. if ("normal" == rect.type1)
  46. {
  47. rect.dblclick(stepSetting);
  48. }
  49. else if ("subflow" == rect.type1)
  50. {
  51. rect.dblclick(subflowSetting);
  52. }
  53. }
  54. wf_steps.push(rect);
  55. var text2 = text.length > 8 ? text.substr(0, 7) + "..." : text;
  56. var text1 = wf_r.text(x + 52, y + 25, text2);
  57. text1.attr({ "font-size": "12px" });
  58. if (text.length > 8) text1.attr({ "title": text });
  59. text1.id = "text_" + id;
  60. text1.type1 = "text";
  61. wf_texts.push(text1);
  62. if (addToJSON == undefined || addToJSON == null) addToJSON = true;
  63. if (addToJSON)
  64. {
  65. var step = {};
  66. step.id = guid;
  67. step.type = type1 ? type1 : "normal";
  68. step.name = text;
  69. step.position = { x: x, y: y, width: wf_width, height: wf_height };
  70. if (rect.type1 == "normal")
  71. {
  72. step.opinionDisplay = "";
  73. step.expiredPrompt = "";
  74. step.signatureType = "";
  75. step.workTime = "";
  76. step.limitTime = "";
  77. step.otherTime = "";
  78. step.archives = "";
  79. step.archivesParams = "";
  80. step.note = "";
  81. step.behavior = {
  82. flowType: "",
  83. runSelect: "",
  84. handlerType: "",
  85. selectRange: "",
  86. handlerStep: "",
  87. valueField: "",
  88. defaultHandler: "",
  89. hanlderModel: "",
  90. backModel: "",
  91. backStep: "",
  92. backType: "",
  93. percentage: ""
  94. };
  95. step.forms = [];
  96. step.buttons = [];
  97. step.fieldStatus = [];
  98. step.event = {
  99. submitBefore: "",
  100. submitAfter: "",
  101. backBefore: "",
  102. backAfter: ""
  103. };
  104. }
  105. else if (rect.type1 == "subflow")
  106. {
  107. step.flowid = "";
  108. step.handler = "";
  109. step.strategy = 0;
  110. }
  111. addStep1(step);
  112. }
  113. }
  114. //添加子流程节点
  115. function addSubFlow()
  116. {
  117. addStep(null, null, "子流程步骤", null, null, "subflow", null, null)
  118. }
  119. //复制当前选中步骤
  120. function copyStep()
  121. {
  122. if (wf_focusObj == null || !isStepObj(wf_focusObj))
  123. {
  124. alert("请选择要复制的步骤");
  125. return;
  126. }
  127. var json = null;
  128. var text = "";
  129. var id = getGuid();
  130. if (wf_json && wf_json.steps)
  131. {
  132. for (var i = 0; i < wf_json.steps.length; i++)
  133. {
  134. if (wf_json.steps[i].id == wf_focusObj.id)
  135. {
  136. json = wf_json.steps[i];
  137. json.id = id;
  138. text = json.name;
  139. json.name = text;
  140. break;
  141. }
  142. }
  143. }
  144. addStep(undefined, undefined, text, id, false);
  145. }
  146. //设置步骤文本
  147. function setStepText(id, txt)
  148. {
  149. var stepText = wf_r.getById("text_" + id);
  150. if (stepText != null)
  151. {
  152. if (txt.length > 8)
  153. {
  154. stepText.attr({ "title": txt });
  155. txt = txt.substr(0, 7) + "...";
  156. }
  157. stepText.attr({ "text": txt });
  158. }
  159. }
  160. function setLineText(id, txt)
  161. {
  162. var line;
  163. for (var i = 0; i < wf_conns.length; i++)
  164. {
  165. if (wf_conns[i].id == id)
  166. {
  167. line = wf_conns[i];
  168. break;
  169. }
  170. }
  171. if (!line)
  172. {
  173. return;
  174. }
  175. var bbox = line.arrPath.getBBox();
  176. var txt_x = (bbox.x + bbox.x2) / 2;
  177. var txt_y = (bbox.y + bbox.y2) / 2;
  178. var lineText = wf_r.getById("line_" + id);
  179. if (lineText != null)
  180. {
  181. if (!txt)
  182. {
  183. lineText.remove();
  184. }
  185. else
  186. {
  187. lineText.attr("x", txt_x);
  188. lineText.attr("y", txt_y);
  189. lineText.attr("text", txt || "");
  190. }
  191. return;
  192. }
  193. if (txt)
  194. {
  195. var textObj = wf_r.text(txt_x, txt_y, txt);
  196. textObj.type1 = "line";
  197. textObj.id = "line_" + id;
  198. wf_texts.push(textObj);
  199. }
  200. //line.arrPath.attr("title", txt);
  201. }
  202. //删除当前焦点及其附属对象
  203. function removeObj()
  204. {
  205. if (!wf_focusObj)
  206. {
  207. alert("请选择要删除的对象!");
  208. }
  209. else if (!confirm('您真的要删除选定对象吗?'))
  210. {
  211. return false;
  212. }
  213. if (isStepObj(wf_focusObj))//如果选中的是步骤
  214. {
  215. if (wf_focusObj.id)
  216. {
  217. for (var i = 0; i < wf_texts.length; i++)
  218. {
  219. if (wf_texts[i].id == "text_" + wf_focusObj.id)
  220. {
  221. wf_texts.remove(i);
  222. var text = wf_r.getById("text_" + wf_focusObj.id);
  223. if (text) text.remove();
  224. }
  225. }
  226. }
  227. var deleteConnIndex = new Array();
  228. for (var j = 0; j < wf_conns.length; j++)
  229. {
  230. if (wf_conns[j].arrPath && (wf_conns[j].obj1.id == wf_focusObj.id || wf_conns[j].obj2.id == wf_focusObj.id))
  231. {
  232. deleteLine(wf_conns[j].id, wf_conns[j].arrPath.id);
  233. deleteConnIndex.push(j);
  234. wf_conns[j].arrPath.remove();
  235. }
  236. }
  237. for (var m = deleteConnIndex.length; m--;)
  238. {
  239. wf_conns.remove(deleteConnIndex[m]);
  240. }
  241. deleteConnIndex = new Array();
  242. for (var k = 0; k < wf_steps.length; k++)
  243. {
  244. if (wf_steps[k].id == wf_focusObj.id)
  245. {
  246. wf_steps.remove(k);
  247. deleteStep(wf_focusObj.id);
  248. }
  249. }
  250. wf_focusObj.remove();
  251. }
  252. else//如果选中的是线
  253. {
  254. for (var j = 0; j < wf_conns.length; j++)
  255. {
  256. if (wf_conns[j].arrPath && wf_conns[j].arrPath.id == wf_focusObj.id)
  257. {
  258. deleteLine(wf_conns[j].id, wf_conns[j].arrPath.id);
  259. wf_conns.remove(j);
  260. }
  261. }
  262. wf_focusObj.remove();
  263. }
  264. }
  265. //得到新步骤的XY
  266. function getNewXY()
  267. {
  268. var x = 10, y = 50;
  269. if (wf_steps.length > 0)
  270. {
  271. var step = wf_steps[wf_steps.length - 1];
  272. x = parseInt(step.attr("x")) + 170;
  273. y = parseInt(step.attr("y"));
  274. if (x > wf_r.width - wf_width)
  275. {
  276. x = 10;
  277. y = y + 100;
  278. }
  279. if (y > wf_r.height - wf_height)
  280. {
  281. y = wf_r.height - wf_height;
  282. }
  283. }
  284. return { x: x, y: y };
  285. }
  286. //添加连线
  287. function addConn()
  288. {
  289. if (!wf_focusObj || !isStepObj(wf_focusObj))
  290. {
  291. alert("请选择要连接的步骤!"); return false;
  292. }
  293. wf_option = "line";
  294. document.body.onmousemove = mouseMove;
  295. document.body.onmousedown = function ()
  296. {
  297. for (var i = 0; i < tempArrPath.length; i++)
  298. {
  299. tempArrPath[i].arrPath.remove();
  300. }
  301. tempArrPath = [];
  302. document.body.onmousemove = null;
  303. };
  304. }
  305. function mouseMove(ev)
  306. {
  307. ev = ev || window.event;
  308. var mousePos = mouseCoords(ev);
  309. mouseX = mousePos.x;
  310. mouseY = mousePos.y;
  311. var obj = { obj1: wf_focusObj, obj2: null };
  312. wf_r.drawArr(obj);
  313. }
  314. function mouseCoords(ev)
  315. {
  316. if (ev.pageX || ev.pageY)
  317. {
  318. return { x: ev.pageX, y: ev.pageY };
  319. }
  320. return {
  321. x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
  322. y: ev.clientY + document.body.scrollTop - document.body.clientTop
  323. };
  324. }
  325. //连接对象
  326. function connObj(obj, addToJSON, title)
  327. {
  328. if (addToJSON == undefined || addToJSON == null) addToJSON = true;
  329. if (isLine(obj))
  330. {
  331. var newline = wf_r.drawArr(obj);
  332. wf_conns.push(newline);
  333. if (addToJSON)
  334. {
  335. var line = {};
  336. line.id = obj.id;
  337. line.text = title || "";
  338. line.from = obj.obj1.id;
  339. line.to = obj.obj2.id;
  340. line.customMethod = "";
  341. line.sql = "";
  342. line.noaccordMsg = "";
  343. addLine(line);
  344. }
  345. else
  346. {
  347. setLineText(obj.id, title);
  348. }
  349. }
  350. }
  351. //单击事件执行相关操作
  352. function click()
  353. {
  354. var o = this;
  355. switch (wf_option)
  356. {
  357. case "line":
  358. var obj = { id: getGuid(), obj1: wf_focusObj, obj2: o };
  359. connObj(obj);
  360. break;
  361. default:
  362. changeStyle(o);
  363. break;
  364. }
  365. wf_option = "";
  366. wf_focusObj = this;
  367. }
  368. //连线单击事件
  369. function connClick()
  370. {
  371. for (var i = 0; i < wf_conns.length; i++)
  372. {
  373. if (wf_conns[i].arrPath === this)
  374. {
  375. wf_conns[i].arrPath.attr({ "stroke": "#db0f14", "fill": "#db0f14" });
  376. }
  377. else
  378. {
  379. wf_conns[i].arrPath.attr({ "stroke": wf_connColor, "fill": wf_connColor });
  380. }
  381. }
  382. for (var i = 0; i < wf_steps.length; i++)
  383. {
  384. wf_steps[i].attr("fill", "#efeff0");
  385. wf_steps[i].attr("stroke", "#23508e");
  386. }
  387. wf_focusObj = this;
  388. }
  389. //判断一个节点与另一个节点之间是否可以连线
  390. function isLine(obj)
  391. {
  392. if (!obj || !obj.obj1 || !obj.obj2)
  393. {
  394. return false;
  395. }
  396. if (obj.obj1 === obj.obj2)
  397. {
  398. return false;
  399. }
  400. if (!isStepObj(obj.obj1) || !isStepObj(obj.obj2))
  401. {
  402. return false;
  403. }
  404. for (var i = 0; i < wf_conns.length; i++)
  405. {
  406. if (obj.obj1 === obj.obj2 || (wf_conns[i].obj1 === obj.obj1 && wf_conns[i].obj2 === obj.obj2))
  407. {
  408. return false;
  409. }
  410. }
  411. return true;
  412. }
  413. //判断一个对象是否是步骤对象
  414. function isStepObj(obj)
  415. {
  416. return obj && obj.type1 && (obj.type1.toString() == "normal" || obj.type1.toString() == "subflow");
  417. }
  418. //得到XML DOM
  419. function getXmlDoc()
  420. {
  421. var xmlDoc = RoadUI.Core.getXmlDoc();
  422. xmlDoc.async = false;
  423. return xmlDoc
  424. }
  425. //得到GUID
  426. function getGuid()
  427. {
  428. return Raphael.createUUID().toLowerCase();
  429. }
  430. //改变节点样式
  431. function changeStyle(obj)
  432. {
  433. if (!obj)
  434. {
  435. return;
  436. }
  437. for (var i = 0; i < wf_steps.length; i++)
  438. {
  439. if (wf_steps[i].id == obj.id)
  440. {
  441. wf_steps[i].attr("fill", wf_noteColor);
  442. wf_steps[i].attr("stroke", "#cc0000");
  443. }
  444. else
  445. {
  446. wf_steps[i].attr("fill", wf_noteColor);
  447. wf_steps[i].attr("stroke", wf_nodeBorderColor);
  448. }
  449. }
  450. for (var i = 0; i < wf_conns.length; i++)
  451. {
  452. if (wf_conns[i].arrPath)
  453. {
  454. wf_conns[i].arrPath.attr({ "stroke": wf_connColor, "fill": wf_connColor });
  455. }
  456. }
  457. //obj.animate({ }, 500);
  458. }
  459. //拖动节点开始时的事件
  460. function dragger()
  461. {
  462. this.ox = this.attr("x");
  463. this.oy = this.attr("y");
  464. changeStyle(this);
  465. };
  466. //拖动事件
  467. function move(dx, dy)
  468. {
  469. var x = this.ox + dx;
  470. var y = this.oy + dy;
  471. if (x < 0)
  472. {
  473. x = 0;
  474. }
  475. else if (x > wf_r.width - wf_width)
  476. {
  477. x = wf_r.width - wf_width;
  478. }
  479. if (y < 0)
  480. {
  481. y = 0;
  482. }
  483. else if (y > wf_r.height - wf_height)
  484. {
  485. y = wf_r.height - wf_height;
  486. }
  487. this.attr("x", x);
  488. this.attr("y", y);
  489. if (this.id)
  490. {
  491. var text = wf_r.getById('text_' + this.id);
  492. if (text)
  493. {
  494. text.attr("x", x + 52);
  495. text.attr("y", y + 25);
  496. }
  497. }
  498. for (var j = wf_conns.length; j--;)
  499. {
  500. if (wf_conns[j].obj1.id == this.id || wf_conns[j].obj2.id == this.id)
  501. {
  502. for (var n = 0; n < wf_json.lines.length; n++)
  503. {
  504. if (wf_json.lines[n].id == wf_conns[j].arrPath.id)
  505. {
  506. setLineText(wf_json.lines[n].id, wf_json.lines[n].text);
  507. break;
  508. }
  509. }
  510. wf_r.drawArr(wf_conns[j]);
  511. }
  512. }
  513. wf_r.safari();
  514. };
  515. //拖动结束后的事件
  516. function up()
  517. {
  518. changeStyle(this);
  519. //记录移动后的位置
  520. if (isStepObj(this))
  521. {
  522. var bbox = this.getBBox();
  523. if (bbox)
  524. {
  525. var steps = wf_json.steps;
  526. if (steps && steps.length > 0)
  527. {
  528. for (var i = 0; i < steps.length; i++)
  529. {
  530. if (steps[i].id == this.id)
  531. {
  532. steps[i].position = { "x": bbox.x, "y": bbox.y, "width": bbox.width, "height": bbox.height };
  533. break;
  534. }
  535. }
  536. }
  537. }
  538. }
  539. };
  540. //随着节点位置的改变动态改变箭头
  541. Raphael.fn.drawArr = function (obj)
  542. {
  543. if (!obj || !obj.obj1)
  544. {
  545. return;
  546. }
  547. if (!obj.obj2)
  548. {
  549. var point1 = getStartEnd(obj.obj1, obj.obj2);
  550. var path2 = getArr(point1.start.x, point1.start.y, mouseX, mouseY, 7);
  551. for (var i = 0; i < tempArrPath.length; i++)
  552. {
  553. tempArrPath[i].arrPath.remove();
  554. }
  555. tempArrPath = [];
  556. obj.arrPath = this.path(path2);
  557. obj.arrPath.attr({ "stroke-width": 1.7, "stroke": wf_connColor, "fill": wf_connColor });
  558. tempArrPath.push(obj);
  559. return;
  560. }
  561. var point = getStartEnd(obj.obj1, obj.obj2);
  562. var path1 = getArr(point.start.x, point.start.y, point.end.x, point.end.y, 7);
  563. try
  564. {
  565. if (obj.arrPath)
  566. {
  567. obj.arrPath.attr({ path: path1 });
  568. }
  569. else
  570. {
  571. obj.arrPath = this.path(path1);
  572. obj.arrPath.attr({ "stroke-width": 1.7, "stroke": wf_connColor, "fill": wf_connColor, "x": point.start.x, "y": point.start.y, "x1": point.end.x, "y1": point.end.y });
  573. if (wf_designer)
  574. {
  575. obj.arrPath.click(connClick);
  576. obj.arrPath.dblclick(connSetting);
  577. obj.arrPath.id = obj.id;
  578. obj.arrPath.fromid = obj.obj1.id;
  579. obj.arrPath.toid = obj.obj2.id;
  580. }
  581. }
  582. } catch (e) { }
  583. return obj;
  584. };
  585. function getStartEnd(obj1, obj2)
  586. {
  587. var bb1 = obj1 ? obj1.getBBox() : null;
  588. var bb2 = obj2 ? obj2.getBBox() : null;
  589. var p = [
  590. { x: bb1.x + bb1.width / 2, y: bb1.y - 1 },
  591. { x: bb1.x + bb1.width / 2, y: bb1.y + bb1.height + 1 },
  592. { x: bb1.x - 1, y: bb1.y + bb1.height / 2 },
  593. { x: bb1.x + bb1.width + 1, y: bb1.y + bb1.height / 2 },
  594. bb2 ? { x: bb2.x + bb2.width / 2, y: bb2.y - 1 } : {},
  595. bb2 ? { x: bb2.x + bb2.width / 2, y: bb2.y + bb2.height + 1 } : {},
  596. bb2 ? { x: bb2.x - 1, y: bb2.y + bb2.height / 2 } : {},
  597. bb2 ? { x: bb2.x + bb2.width + 1, y: bb2.y + bb2.height / 2 } : {}
  598. ];
  599. var d = {}, dis = [];
  600. for (var i = 0; i < 4; i++)
  601. {
  602. for (var j = 4; j < 8; j++)
  603. {
  604. var dx = Math.abs(p[i].x - p[j].x),
  605. dy = Math.abs(p[i].y - p[j].y);
  606. if (
  607. (i == j - 4) ||
  608. (((i != 3 && j != 6) || p[i].x < p[j].x) &&
  609. ((i != 2 && j != 7) || p[i].x > p[j].x) &&
  610. ((i != 0 && j != 5) || p[i].y > p[j].y) &&
  611. ((i != 1 && j != 4) || p[i].y < p[j].y))
  612. )
  613. {
  614. dis.push(dx + dy);
  615. d[dis[dis.length - 1]] = [i, j];
  616. }
  617. }
  618. }
  619. if (dis.length == 0)
  620. {
  621. var res = [0, 4];
  622. } else
  623. {
  624. res = d[Math.min.apply(Math, dis)];
  625. }
  626. var result = {};
  627. result.start = {};
  628. result.end = {};
  629. result.start.x = p[res[0]].x;
  630. result.start.y = p[res[0]].y;
  631. result.end.x = p[res[1]].x;
  632. result.end.y = p[res[1]].y;
  633. return result;
  634. }
  635. function getArr(x1, y1, x2, y2, size)
  636. {
  637. var angle = Raphael.angle(x1, y1, x2, y2);
  638. var a45 = Raphael.rad(angle - 28);
  639. var a45m = Raphael.rad(angle + 28);
  640. var x2a = x2 + Math.cos(a45) * size;
  641. var y2a = y2 + Math.sin(a45) * size;
  642. var x2b = x2 + Math.cos(a45m) * size;
  643. var y2b = y2 + Math.sin(a45m) * size;
  644. return ["M", x1, y1, "L", x2, y2, "M", x2, y2, "L", x2b, y2b, "L", x2a, y2a, "z"].join(",");
  645. }
  646. function initwf()
  647. {
  648. wf_json = {};
  649. wf_steps = new Array();
  650. wf_texts = new Array();
  651. wf_conns = new Array();
  652. wf_r.clear();
  653. }
  654. //删除数组中元素
  655. Array.prototype.remove = function (n)
  656. {
  657. if (isNaN(n) || n > this.length) { return false; }
  658. this.splice(n, 1);
  659. }
  660. function removeArray(array, n)
  661. {
  662. if (isNaN(n) || n > array.length) { return false; }
  663. array.splice(n, 1);
  664. }
  665. //得到一连接的所有表
  666. function getTables(connid)
  667. {
  668. var tables = [];
  669. $.ajax({
  670. url: top.rootdir + "/Platform/WorkFlowDesigner/GetTables.ashx?connid=" + connid, dataType: "json", async: false, cache:false, success: function (json)
  671. {
  672. for (var i = 0; i < json.length; i++)
  673. {
  674. tables.push(json[i]);
  675. }
  676. }
  677. });
  678. return tables;
  679. }
  680. //得到一个表所有字段
  681. function getFields(connid, table)
  682. {
  683. var fields = [];
  684. $.ajax({
  685. url: top.rootdir + "/Platform/WorkFlowDesigner/GetFields.ashx?connid=" + connid + "&table=" + table, dataType: "json", async: false, cache:false, success: function (json)
  686. {
  687. for (var i = 0; i < json.length; i++)
  688. {
  689. fields.push(json[i]);
  690. }
  691. }
  692. });
  693. return fields;
  694. }
  695. //载入当前数据连接的所有表和字段
  696. function initLinks_Tables_Fields(databases)
  697. {
  698. if (!databases || databases.length == 0)
  699. {
  700. return;
  701. }
  702. links_tables_fields = [];
  703. for (var i = 0; i < databases.length; i++)
  704. {
  705. var fields = getFields(databases[i].link, databases[i].table);
  706. for (var k = 0; k < fields.length; k++)
  707. {
  708. links_tables_fields.push({ link: databases[i].link, linkName: databases[i].linkName, table: databases[i].table, field: fields[k].name, fieldNote:fields[k].note });
  709. }
  710. }
  711. }
  712. //添加步骤
  713. function addStep1(step)
  714. {
  715. if (!step) return;
  716. if (!wf_json.steps) wf_json.steps = [];
  717. var isup = false;
  718. for (var i = 0; i < wf_json.steps.length; i++)
  719. {
  720. if (wf_json.steps[i].id == step.id)
  721. {
  722. wf_json.steps[i] = step;
  723. isup = true;
  724. }
  725. }
  726. if (!isup)
  727. {
  728. wf_json.steps.push(step);
  729. }
  730. }
  731. //添加线
  732. function addLine(line)
  733. {
  734. if (!line || !line.from || !line.to) return;
  735. if (!wf_json.lines) wf_json.lines = [];
  736. var isup = false;
  737. for (var i = 0; i < wf_json.lines.length; i++)
  738. {
  739. if (wf_json.lines[i].id == line.id)
  740. {
  741. wf_json.lines[i] = line;
  742. isup = true;
  743. }
  744. }
  745. if (!isup)
  746. {
  747. wf_json.lines.push(line);
  748. }
  749. setLineText(line.id, line.text);
  750. }
  751. //根据当前JSON重载入流程
  752. function reloadFlow(json)
  753. {
  754. if (!json || !json.id || $.trim(json.id) == "") return false;
  755. wf_json = json;
  756. wf_id = wf_json.id;
  757. wf_r.clear();
  758. wf_steps = [];
  759. wf_conns = [];
  760. wf_texts = [];
  761. var steps = wf_json.steps;
  762. if (steps && steps.length > 0)
  763. {
  764. for (var i = 0; i < steps.length; i++)
  765. {
  766. addStep(steps[i].position.x, steps[i].position.y, steps[i].name, steps[i].id, false, steps[i].type);
  767. }
  768. }
  769. var lines = wf_json.lines;
  770. if (lines && lines.length > 0)
  771. {
  772. for (var i = 0; i < lines.length; i++)
  773. {
  774. connObj({ id: lines[i].id, obj1: wf_r.getById(lines[i].from), obj2: wf_r.getById(lines[i].to) }, false, lines[i].text);
  775. }
  776. }
  777. //初始化数据连接
  778. initLinks_Tables_Fields(wf_json.databases);
  779. }
  780. //从json中删除步骤
  781. function deleteStep(stepid)
  782. {
  783. var steps = wf_json.steps;
  784. if (steps && steps.length > 0)
  785. {
  786. for (var i = 0; i < steps.length; i++)
  787. {
  788. if (steps[i].id == stepid)
  789. {
  790. removeArray(steps, i);
  791. }
  792. }
  793. }
  794. }
  795. //从json中删除线
  796. function deleteLine(lineid, textid)
  797. {
  798. var lines = wf_json.lines;
  799. if (lines && lines.length > 0)
  800. {
  801. for (var i = 0; i < lines.length; i++)
  802. {
  803. if (lines[i].id == lineid)
  804. {
  805. removeArray(lines, i);
  806. }
  807. }
  808. }
  809. if (textid)
  810. {
  811. if (wf_texts && wf_texts.length > 0)
  812. {
  813. for (var i = 0; i < wf_texts.length; i++)
  814. {
  815. if (wf_texts[i].id == "line_" + textid)
  816. {
  817. wf_texts[i].remove();
  818. }
  819. }
  820. }
  821. }
  822. }
  823. //步骤属性设置
  824. function stepSetting()
  825. {
  826. var bbox = this.getBBox();
  827. var url = top.rootdir + "/Platform/WorkFlowDesigner/Set_Step.aspx?appid=" + appid + "&id=" + this.id + "&x=" + bbox.x + "&y=" + bbox.y + "&width=" + bbox.width + "&height=" + bbox.height;
  828. dialog.open({ title: "步骤参数设置", width: 700, height: 400, url: url, openerid: iframeid, resize: false });
  829. }
  830. //子流程设置
  831. function subflowSetting()
  832. {
  833. var bbox = this.getBBox();
  834. var url = top.rootdir + "/Platform/WorkFlowDesigner/Set_SubFlow.aspx?appid=" + appid + "&id=" + this.id + "&x=" + bbox.x + "&y=" + bbox.y + "&width=" + bbox.width + "&height=" + bbox.height;
  835. dialog.open({ title: "子流程步骤参数设置", width: 700, height: 400, url: url, openerid: iframeid, resize: false });
  836. }
  837. //流转条件设置
  838. function connSetting()
  839. {
  840. var url = top.rootdir + "/Platform/WorkFlowDesigner/Set_Line.aspx?appid=" + appid + "&id=" + this.id + "&from=" + this.fromid + "&to=" + this.toid;
  841. dialog.open({ title: "流转条件设置", width: 700, height: 400, url: url, openerid: iframeid, resize: false });
  842. }
  843. //流程属性设置
  844. function flowAttrSetting(isAdd)
  845. {
  846. var url = top.rootdir + "/Platform/WorkFlowDesigner/Set_Flow.aspx?appid=" + appid + "&isadd=" + (isAdd || 0).toString() + "&flowid=" + wf_json.id;
  847. dialog.open({ title: "流程属性设置", width: 550, height: 390, url: url, openerid: iframeid, resize: false });
  848. }
  849. //打开流程
  850. function openFlow()
  851. {
  852. var url = top.rootdir + "/Platform/WorkFlowDesigner/Open.aspx?appid=" + appid;
  853. dialog.open({ title: "打开流程", width: 850, height: 450, url: url, openerid: iframeid, resize: false });
  854. }
  855. function openFlow1(id)
  856. {
  857. var json = $.ajax({
  858. url: top.rootdir + "/Platform/WorkFlowDesigner/GetJSON.ashx?appid=" + appid + "&flowid=" + id, async: false, cache: false, dataType: "json", success: function (json)
  859. {
  860. reloadFlow(json);
  861. }
  862. });
  863. }
  864. //新建流程
  865. function addFlow()
  866. {
  867. flowAttrSetting(1);
  868. }
  869. //保存流程
  870. function saveFlow(op)
  871. {
  872. if (!wf_json)
  873. {
  874. alert("未设置流程!"); return false;
  875. }
  876. else if (!wf_json.id || $.trim(wf_json.id) == "")
  877. {
  878. alert("请先新建或打开流程!"); return false;
  879. }
  880. else if (!wf_json.name || $.trim(wf_json.name) == "")
  881. {
  882. alert("流程名称不能为空!"); return false;
  883. }
  884. if (op == "delete" && !confirm("您真的要删除该流程吗?"))
  885. {
  886. return;
  887. }
  888. var title = "";
  889. if (op == "save") title = "保存流程";
  890. else if (op == "install") title = "安装流程";
  891. else if (op == "uninstall") title = "卸载流程";
  892. else if (op == "delete") title = "删除流程";
  893. var url = top.rootdir + "/Platform/WorkFlowDesigner/Opation.aspx?appid=" + appid + "&flowid=" + wf_json.id + "&op=" + (op || "save");
  894. dialog.open({ title: title, width: 260, height: 120, url: url, openerid: iframeid, resize: false, showclose: false });
  895. }
  896. //另存为
  897. function saveAs()
  898. {
  899. if (!wf_json || !wf_json.id || $.trim(wf_json.id) == "")
  900. {
  901. alert("请先新建或打开一个流程!"); return false;
  902. }
  903. var url = top.rootdir + "/Platform/WorkFlowDesigner/SaveAs.aspx?appid=" + appid + "&flowid=" + wf_json.id;
  904. dialog.open({ title: "流程另存为", width: 600, height: 230, url: url, openerid: iframeid, resize: false });
  905. }