人民医院前端

myflow.js 61KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678
  1. var hps = [],
  2. wps = [],
  3. hlp,
  4. wlp; (function (b) {
  5. var a = {};
  6. a.config = {
  7. editable: true,
  8. lineHeight: 15,
  9. basePath: "",
  10. rect: {
  11. attr: {
  12. x: 10,
  13. y: 10,
  14. width: 100,
  15. height: 50,
  16. r: 5,
  17. fill: "90-#fff-#C0C0C0",
  18. stroke: "#000",
  19. "stroke-width": 1
  20. },
  21. showType: "image&text",
  22. type: "state",
  23. name: {
  24. text: "state",
  25. "font-style": "italic"
  26. },
  27. text: {
  28. text: "状态",
  29. "font-size": 13
  30. },
  31. margin: 5,
  32. props: [],
  33. img: {}
  34. },
  35. path: {
  36. attr: {
  37. path: {
  38. path: "M10 10L100 100",
  39. stroke: "#808080",
  40. fill: "none",
  41. "stroke-width": 2
  42. },
  43. arrow: {
  44. path: "M10 10L10 10",
  45. stroke: "#808080",
  46. fill: "#808080",
  47. "stroke-width": 2,
  48. radius: 4
  49. },
  50. fromDot: {
  51. width: 5,
  52. height: 5,
  53. stroke: "#fff",
  54. fill: "#000",
  55. cursor: "move",
  56. "stroke-width": 2
  57. },
  58. toDot: {
  59. width: 5,
  60. height: 5,
  61. stroke: "#fff",
  62. fill: "#000",
  63. cursor: "move",
  64. "stroke-width": 2
  65. },
  66. bigDot: {
  67. width: 5,
  68. height: 5,
  69. stroke: "#fff",
  70. fill: "#000",
  71. cursor: "move",
  72. "stroke-width": 2
  73. },
  74. smallDot: {
  75. width: 5,
  76. height: 5,
  77. stroke: "#fff",
  78. fill: "#000",
  79. cursor: "move",
  80. "stroke-width": 3
  81. }
  82. },
  83. text: {
  84. text: "",
  85. cursor: "move",
  86. background: "#000"
  87. },
  88. textPos: {
  89. x: 0,
  90. y: -10
  91. },
  92. props: {
  93. text: {
  94. name: "text",
  95. label: "显示",
  96. value: "",
  97. editor: function () {
  98. return new a.editors.checkboxEditor()
  99. }
  100. }
  101. }
  102. },
  103. tools: {
  104. attr: {
  105. left: 10,
  106. top: 10
  107. },
  108. pointer: {},
  109. path: {},
  110. states: {},
  111. save: function (c) {
  112. alert(c)
  113. }
  114. },
  115. props: {
  116. attr: {
  117. top: 10,
  118. right: 30
  119. },
  120. props: {}
  121. },
  122. restore: "",
  123. activeRects: {
  124. rects: [],
  125. rectAttr: {
  126. stroke: "#ff0000",
  127. "stroke-width": 2
  128. }
  129. },
  130. historyRects: {
  131. rects: [],
  132. pathAttr: {
  133. path: {
  134. stroke: "#00ff00"
  135. },
  136. arrow: {
  137. stroke: "#00ff00",
  138. fill: "#00ff00"
  139. }
  140. }
  141. }
  142. };
  143. a.util = {
  144. isLine: function (g, f, e) {
  145. var d, c;
  146. if ((g.x - e.x) == 0) {
  147. d = 1
  148. } else {
  149. d = (g.y - e.y) / (g.x - e.x)
  150. }
  151. c = (f.x - e.x) * d + e.y;
  152. if ((f.y - c) < 10 && (f.y - c) > -10) {
  153. f.y = c;
  154. return true
  155. }
  156. return false
  157. },
  158. center: function (d, c) {
  159. return {
  160. x: (d.x - c.x) / 2 + c.x,
  161. y: (d.y - c.y) / 2 + c.y
  162. }
  163. },
  164. nextId: (function () {
  165. var c = 0;
  166. return function () {
  167. return ++c
  168. }
  169. })(),
  170. connPoint: function (j, d) {
  171. var c = d,
  172. e = {
  173. x: j.x + j.width / 2,
  174. y: j.y + j.height / 2
  175. };
  176. var l = (e.y - c.y) / (e.x - c.x);
  177. l = isNaN(l) ? 0 : l;
  178. var k = j.height / j.width;
  179. var h = c.y < e.y ? -1 : 1,
  180. f = c.x < e.x ? -1 : 1,
  181. g,
  182. i;
  183. if (Math.abs(l) > k && h == -1) {
  184. g = e.y - j.height / 2;
  185. i = e.x + h * j.height / 2 / l
  186. } else {
  187. if (Math.abs(l) > k && h == 1) {
  188. g = e.y + j.height / 2;
  189. i = e.x + h * j.height / 2 / l
  190. } else {
  191. if (Math.abs(l) < k && f == -1) {
  192. g = e.y + f * j.width / 2 * l;
  193. i = e.x - j.width / 2
  194. } else {
  195. if (Math.abs(l) < k && f == 1) {
  196. g = e.y + j.width / 2 * l;
  197. i = e.x + j.width / 2
  198. }
  199. }
  200. }
  201. }
  202. return {
  203. x: i,
  204. y: g
  205. }
  206. },
  207. arrow: function (l, k, d) {
  208. var g = Math.atan2(l.y - k.y, k.x - l.x) * (180 / Math.PI);
  209. var h = k.x - d * Math.cos(g * (Math.PI / 180));
  210. var f = k.y + d * Math.sin(g * (Math.PI / 180));
  211. var e = h + d * Math.cos((g + 120) * (Math.PI / 180));
  212. var j = f - d * Math.sin((g + 120) * (Math.PI / 180));
  213. var c = h + d * Math.cos((g + 240) * (Math.PI / 180));
  214. var i = f - d * Math.sin((g + 240) * (Math.PI / 180));
  215. return [k, {
  216. x: e,
  217. y: j
  218. },
  219. {
  220. x: c,
  221. y: i
  222. }]
  223. }
  224. };
  225. a.rect = function (p, m) {
  226. var u = this,
  227. g = "rect" + a.util.nextId(),
  228. E = b.extend(true, {},
  229. a.config.rect, p),
  230. C = m,
  231. t,
  232. e,
  233. n,
  234. f,
  235. x,
  236. v,
  237. hl,
  238. wl;
  239. t = C.rect(E.attr.x, E.attr.y, E.attr.width, E.attr.height, E.attr.r).hide().attr(E.attr);
  240. e = C.image(a.config.basePath + E.img.src, E.attr.x + E.img.width / 2, E.attr.y + (E.attr.height - E.img.height) / 2, E.img.width, E.img.height).hide();
  241. n = C.text(E.attr.x + E.img.width + (E.attr.width - E.img.width) / 2, E.attr.y + a.config.lineHeight / 2, E.name.text).hide().attr(E.name);
  242. f = C.text(E.attr.x + E.img.width + (E.attr.width - E.img.width) / 2, E.attr.y + (E.attr.height - a.config.lineHeight) / 2 + a.config.lineHeight, E.text.text).hide().attr(E.text);
  243. t.drag(function (r, o) {
  244. A(r, o)
  245. },
  246. function () {
  247. z()
  248. },
  249. function () {
  250. l()
  251. });
  252. e.drag(function (r, o) {
  253. A(r, o)
  254. },
  255. function () {
  256. z()
  257. },
  258. function () {
  259. l()
  260. });
  261. n.drag(function (r, o) {
  262. A(r, o)
  263. },
  264. function () {
  265. z()
  266. },
  267. function () {
  268. l()
  269. });
  270. f.drag(function (r, o) {
  271. A(r, o)
  272. },
  273. function () {
  274. z()
  275. },
  276. function () {
  277. l()
  278. });
  279. hps.push(E.attr.y * 1 + E.attr.height * 1 / 2);
  280. wps.push(E.attr.x * 1 + E.attr.width * 1 / 2);
  281. var A = function (F, r) {
  282. if (!a.config.editable) {
  283. return
  284. }
  285. var o = (x + F);
  286. var G = (v + r);
  287. q.x = o - E.margin;
  288. q.y = G - E.margin;
  289. B();
  290. hl = -1,
  291. wl = -1;
  292. $(hps).each(function (i, n) {
  293. if (Math.abs(n - (G + E.attr.height / 2)) < 5) {
  294. hl = n;
  295. return true
  296. }
  297. });
  298. $(wps).each(function (i, n) {
  299. if (Math.abs(n - (o + E.attr.width / 2)) < 5) {
  300. wl = n;
  301. return true
  302. }
  303. });
  304. if (wl > 0) {
  305. if (!hlp) {
  306. hlp = C.path("M" + wl + " " + 0 + " L" + wl + " " + b(document).height() * 1.5).attr({
  307. "stroke": "red",
  308. "stroke-width": 0.7,
  309. "stroke-dasharray": "--"
  310. })
  311. }
  312. } else {
  313. if (hlp) {
  314. hlp.remove();
  315. hlp = null
  316. }
  317. wl = -1
  318. }
  319. if (hl > 0) {
  320. if (!wlp) {
  321. wlp = C.path("M" + 0 + " " + hl + " L" + (b(window).width() - 20) + " " + hl).attr({
  322. "stroke": "red",
  323. "stroke-width": 0.7,
  324. "stroke-dasharray": "--"
  325. })
  326. }
  327. } else {
  328. if (wlp) {
  329. wlp.remove();
  330. wlp = null
  331. }
  332. hl = -1
  333. }
  334. };
  335. var z = function () {
  336. x = t.attr("x");
  337. v = t.attr("y");
  338. t.attr({
  339. opacity: 0.5
  340. });
  341. e.attr({
  342. opacity: 0.5
  343. });
  344. f.attr({
  345. opacity: 0.5
  346. });
  347. hps.remove(v + E.attr.height / 2);
  348. wps.remove(x + E.attr.width / 2)
  349. };
  350. var l = function () {
  351. t.attr({
  352. opacity: 1
  353. });
  354. e.attr({
  355. opacity: 1
  356. });
  357. f.attr({
  358. opacity: 1
  359. });
  360. if (hl > 0) q.y = hl - E.attr.height / 2 - E.margin;
  361. if (wl > 0) q.x = wl - E.attr.width / 2 - E.margin;
  362. if (hl > 0 || wl > 0) {
  363. B()
  364. }
  365. if (hlp) {
  366. hlp.remove();
  367. hlp = null
  368. }
  369. if (wlp) {
  370. wlp.remove();
  371. wlp = null
  372. }
  373. hps.push(q.y + E.attr.height / 2 + E.margin);
  374. wps.push(q.x + E.attr.width / 2 + E.margin);
  375. b(C).trigger("rectresize", u)
  376. };
  377. var s, i = {},
  378. h = 5,
  379. q = {
  380. x: E.attr.x - E.margin,
  381. y: E.attr.y - E.margin,
  382. width: E.attr.width + E.margin * 2,
  383. height: E.attr.height + E.margin * 2
  384. };
  385. s = C.path("M0 0L1 1").hide();
  386. i.t = C.rect(0, 0, h, h).attr({
  387. fill: "#000",
  388. stroke: "#fff",
  389. cursor: "s-resize"
  390. }).hide().drag(function (r, o) {
  391. D(r, o, "t")
  392. },
  393. function () {
  394. k(this.attr("x") + h / 2, this.attr("y") + h / 2, "t")
  395. },
  396. function () { });
  397. i.lt = C.rect(0, 0, h, h).attr({
  398. fill: "#000",
  399. stroke: "#fff",
  400. cursor: "nw-resize"
  401. }).hide().drag(function (r, o) {
  402. D(r, o, "lt")
  403. },
  404. function () {
  405. k(this.attr("x") + h / 2, this.attr("y") + h / 2, "lt")
  406. },
  407. function () { });
  408. i.l = C.rect(0, 0, h, h).attr({
  409. fill: "#000",
  410. stroke: "#fff",
  411. cursor: "w-resize"
  412. }).hide().drag(function (r, o) {
  413. D(r, o, "l")
  414. },
  415. function () {
  416. k(this.attr("x") + h / 2, this.attr("y") + h / 2, "l")
  417. },
  418. function () { });
  419. i.lb = C.rect(0, 0, h, h).attr({
  420. fill: "#000",
  421. stroke: "#fff",
  422. cursor: "sw-resize"
  423. }).hide().drag(function (r, o) {
  424. D(r, o, "lb")
  425. },
  426. function () {
  427. k(this.attr("x") + h / 2, this.attr("y") + h / 2, "lb")
  428. },
  429. function () { });
  430. i.b = C.rect(0, 0, h, h).attr({
  431. fill: "#000",
  432. stroke: "#fff",
  433. cursor: "s-resize"
  434. }).hide().drag(function (r, o) {
  435. D(r, o, "b")
  436. },
  437. function () {
  438. k(this.attr("x") + h / 2, this.attr("y") + h / 2, "b")
  439. },
  440. function () { });
  441. i.rb = C.rect(0, 0, h, h).attr({
  442. fill: "#000",
  443. stroke: "#fff",
  444. cursor: "se-resize"
  445. }).hide().drag(function (r, o) {
  446. D(r, o, "rb")
  447. },
  448. function () {
  449. k(this.attr("x") + h / 2, this.attr("y") + h / 2, "rb")
  450. },
  451. function () { });
  452. i.r = C.rect(0, 0, h, h).attr({
  453. fill: "#000",
  454. stroke: "#fff",
  455. cursor: "w-resize"
  456. }).hide().drag(function (r, o) {
  457. D(r, o, "r")
  458. },
  459. function () {
  460. k(this.attr("x") + h / 2, this.attr("y") + h / 2, "r")
  461. },
  462. function () { });
  463. i.rt = C.rect(0, 0, h, h).attr({
  464. fill: "#000",
  465. stroke: "#fff",
  466. cursor: "ne-resize"
  467. }).hide().drag(function (r, o) {
  468. D(r, o, "rt")
  469. },
  470. function () {
  471. k(this.attr("x") + h / 2, this.attr("y") + h / 2, "rt")
  472. },
  473. function () { });
  474. var D = function (F, r, G) {
  475. if (!a.config.editable) {
  476. return
  477. };
  478. var o = _bx + F,
  479. H = _by + r;
  480. switch (G) {
  481. case "t":
  482. q.height += q.y - H;
  483. q.y = H;
  484. break;
  485. case "lt":
  486. q.width += q.x - o;
  487. q.height += q.y - H;
  488. q.x = o;
  489. q.y = H;
  490. break;
  491. case "l":
  492. q.width += q.x - o;
  493. q.x = o;
  494. break;
  495. case "lb":
  496. q.height = H - q.y;
  497. q.width += q.x - o;
  498. q.x = o;
  499. break;
  500. case "b":
  501. q.height = H - q.y;
  502. break;
  503. case "rb":
  504. q.height = H - q.y;
  505. q.width = o - q.x;
  506. break;
  507. case "r":
  508. q.width = o - q.x;
  509. break;
  510. case "rt":
  511. q.width = o - q.x;
  512. q.height += q.y - H;
  513. q.y = H;
  514. break
  515. };
  516. B()
  517. };
  518. var k = function (r, o, F) {
  519. _bx = r;
  520. _by = o
  521. };
  522. b([t.node, f.node, n.node, e.node]).bind("click",
  523. function () {
  524. if (!a.config.editable) {
  525. return
  526. };
  527. w();
  528. var o = b(C).data("mod");
  529. switch (o) {
  530. case "pointer":
  531. break;
  532. case "path":
  533. var r = b(C).data("currNode");
  534. if (r && r.getId().substring(0, 4) == "rect") {
  535. b(C).trigger("addpath", [r, u])
  536. };
  537. break
  538. }
  539. b(C).trigger("click", u);
  540. b(C).data("currNode", u);
  541. return false
  542. });
  543. var j = function (o, r) {
  544. if (!a.config.editable) {
  545. return
  546. }
  547. if (r.getId() == g) {
  548. b(C).trigger("showprops", [E.props, r])
  549. } else {
  550. d()
  551. }
  552. };
  553. b(C).bind("click", j);
  554. var c = function (o, F, r) {
  555. if (r.getId() == g) {
  556. f.attr({
  557. text: F
  558. })
  559. }
  560. };
  561. b(C).bind("textchange", c);
  562. function y() {
  563. return "M" + q.x + " " + q.y + "L" + q.x + " " + (q.y + q.height) + "L" + (q.x + q.width) + " " + (q.y + q.height) + "L" + (q.x + q.width) + " " + q.y + "L" + q.x + " " + q.y
  564. }
  565. function w() {
  566. s.show();
  567. for (var o in i) {
  568. i[o].show()
  569. }
  570. }
  571. function d() {
  572. s.hide();
  573. for (var o in i) {
  574. i[o].hide()
  575. }
  576. }
  577. function B() {
  578. var F = q.x + E.margin,
  579. r = q.y + E.margin,
  580. G = q.width - E.margin * 2,
  581. o = q.height - E.margin * 2;
  582. t.attr({
  583. x: F,
  584. y: r,
  585. width: G,
  586. height: o
  587. });
  588. switch (E.showType) {
  589. case "image":
  590. e.attr({
  591. x:
  592. F + (G - E.img.width) / 2,
  593. y: r + (o - E.img.height) / 2
  594. }).show();
  595. break;
  596. case "text":
  597. t.show();
  598. f.attr({
  599. x:
  600. F + G / 2,
  601. y: r + o / 2
  602. }).show();
  603. break;
  604. case "image&text":
  605. t.show();
  606. n.attr({
  607. x:
  608. F + E.img.width + (G - E.img.width) / 2,
  609. y: r + a.config.lineHeight / 2
  610. }).show();
  611. f.attr({
  612. x: F + E.img.width + (G - E.img.width) / 2,
  613. y: r + (o - a.config.lineHeight) / 2 + a.config.lineHeight
  614. }).show();
  615. e.attr({
  616. x: F + E.img.width / 2,
  617. y: r + (o - E.img.height) / 2
  618. }).show();
  619. break
  620. }
  621. i.t.attr({
  622. x: q.x + q.width / 2 - h / 2,
  623. y: q.y - h / 2
  624. });
  625. i.lt.attr({
  626. x: q.x - h / 2,
  627. y: q.y - h / 2
  628. });
  629. i.l.attr({
  630. x: q.x - h / 2,
  631. y: q.y - h / 2 + q.height / 2
  632. });
  633. i.lb.attr({
  634. x: q.x - h / 2,
  635. y: q.y - h / 2 + q.height
  636. });
  637. i.b.attr({
  638. x: q.x - h / 2 + q.width / 2,
  639. y: q.y - h / 2 + q.height
  640. });
  641. i.rb.attr({
  642. x: q.x - h / 2 + q.width,
  643. y: q.y - h / 2 + q.height
  644. });
  645. i.r.attr({
  646. x: q.x - h / 2 + q.width,
  647. y: q.y - h / 2 + q.height / 2
  648. });
  649. i.rt.attr({
  650. x: q.x - h / 2 + q.width,
  651. y: q.y - h / 2
  652. });
  653. s.attr({
  654. path: y()
  655. })
  656. }
  657. this.toJson = function () {
  658. var a = {};
  659. for (var o in E.props) {
  660. a[o] = {
  661. value: E.props[o].value
  662. }
  663. }
  664. var r = {
  665. type: E.type,
  666. text: {
  667. text: f.attr("text")
  668. },
  669. attr: {
  670. x: Math.round(t.attr("x")),
  671. y: Math.round(t.attr("y")),
  672. width: Math.round(t.attr("width")),
  673. height: Math.round(t.attr("height"))
  674. },
  675. props: a
  676. };
  677. return r
  678. };
  679. this.getFlows = function () {
  680. return E.flows
  681. };
  682. this.restore = function (o) {
  683. var r = o;
  684. E = b.extend(true, E, o);
  685. f.attr({
  686. text: r.text.text
  687. });
  688. B()
  689. };
  690. this.click = function () {
  691. if (!a.config.editable) {
  692. return
  693. }
  694. w();
  695. b(C).trigger("click", u);
  696. b(C).data("currNode", u);
  697. return false
  698. };
  699. this.getBBox = function () {
  700. return q
  701. };
  702. this.getId = function () {
  703. return g
  704. };
  705. this.remove = function () {
  706. hps.remove(t.attr("y") + E.attr.height / 2);
  707. wps.remove(t.attr("x") + E.attr.width / 2);
  708. t.remove();
  709. f.remove();
  710. n.remove();
  711. e.remove();
  712. s.remove();
  713. for (var o in i) {
  714. i[o].remove()
  715. }
  716. };
  717. this.text = function () {
  718. return f.attr("text")
  719. };
  720. this.type = function () {
  721. return E.type
  722. };
  723. this.props = function () {
  724. return E.props
  725. };
  726. this.attr = function (o) {
  727. if (o) {
  728. t.attr(o)
  729. }
  730. };
  731. B()
  732. };
  733. a.path = function (q, n, u, e) {
  734. var v = this,
  735. z = n,
  736. B = b.extend(true, {},
  737. a.config.path),
  738. i,
  739. t,
  740. f,
  741. h = B.textPos,
  742. y,
  743. w,
  744. k = u,
  745. s = e,
  746. g = "path" + u.getId() + "_" + e.getId(),
  747. x;
  748. function p(G, H, D, L) {
  749. var F = this,
  750. M = G,
  751. r, o = D,
  752. O = L,
  753. K, I, N = H;
  754. switch (M) {
  755. case "from":
  756. r = z.rect(H.x - B.attr.fromDot.width / 2, H.y - B.attr.fromDot.height / 2, B.attr.fromDot.width, B.attr.fromDot.height).attr(B.attr.fromDot);
  757. break;
  758. case "big":
  759. r = z.rect(H.x - B.attr.bigDot.width / 2, H.y - B.attr.bigDot.height / 2, B.attr.bigDot.width, B.attr.bigDot.height).attr(B.attr.bigDot);
  760. break;
  761. case "small":
  762. r = z.rect(H.x - B.attr.smallDot.width / 2, H.y - B.attr.smallDot.height / 2, B.attr.smallDot.width, B.attr.smallDot.height).attr(B.attr.smallDot);
  763. break;
  764. case "to":
  765. r = z.rect(H.x - B.attr.toDot.width / 2, H.y - B.attr.toDot.height / 2, B.attr.toDot.width, B.attr.toDot.height).attr(B.attr.toDot);
  766. break
  767. }
  768. if (r && (M == "big" || M == "small")) {
  769. r.drag(function (Q, P) {
  770. C(Q, P)
  771. },
  772. function () {
  773. J()
  774. },
  775. function () {
  776. E()
  777. });
  778. var C = function (R, Q) {
  779. var P = (K + R),
  780. S = (I + Q);
  781. F.moveTo(P, S)
  782. };
  783. var J = function () {
  784. if (M == "big") {
  785. K = r.attr("x") + B.attr.bigDot.width / 2;
  786. I = r.attr("y") + B.attr.bigDot.height / 2
  787. }
  788. if (M == "small") {
  789. K = r.attr("x") + B.attr.smallDot.width / 2;
  790. I = r.attr("y") + B.attr.smallDot.height / 2
  791. }
  792. };
  793. var E = function () { }
  794. }
  795. this.type = function (P) {
  796. if (P) {
  797. M = P
  798. } else {
  799. return M
  800. }
  801. };
  802. this.node = function (P) {
  803. if (P) {
  804. r = P
  805. } else {
  806. return r
  807. }
  808. };
  809. this.left = function (P) {
  810. if (P) {
  811. o = P
  812. } else {
  813. return o
  814. }
  815. };
  816. this.right = function (P) {
  817. if (P) {
  818. O = P
  819. } else {
  820. return O
  821. }
  822. };
  823. this.remove = function () {
  824. o = null;
  825. O = null;
  826. r.remove()
  827. };
  828. this.pos = function (P) {
  829. if (P) {
  830. N = P;
  831. r.attr({
  832. x: N.x - r.attr("width") / 2,
  833. y: N.y - r.attr("height") / 2
  834. });
  835. return this
  836. } else {
  837. return N
  838. }
  839. };
  840. this.moveTo = function (Q, T) {
  841. this.pos({
  842. x: Q,
  843. y: T
  844. });
  845. switch (M) {
  846. case "from":
  847. if (O && O.right() && O.right().type() == "to") {
  848. O.right().pos(a.util.connPoint(s.getBBox(), N))
  849. }
  850. if (O && O.right()) {
  851. O.pos(a.util.center(N, O.right().pos()))
  852. }
  853. break;
  854. case "big":
  855. if (O && O.right() && O.right().type() == "to") {
  856. O.right().pos(a.util.connPoint(s.getBBox(), N))
  857. }
  858. if (o && o.left() && o.left().type() == "from") {
  859. o.left().pos(a.util.connPoint(k.getBBox(), N))
  860. }
  861. if (O && O.right()) {
  862. O.pos(a.util.center(N, O.right().pos()))
  863. }
  864. if (o && o.left()) {
  865. o.pos(a.util.center(N, o.left().pos()))
  866. }
  867. var S = {
  868. x: N.x,
  869. y: N.y
  870. };
  871. if (a.util.isLine(o.left().pos(), S, O.right().pos())) {
  872. M = "small";
  873. r.attr(B.attr.smallDot);
  874. this.pos(S);
  875. var P = o;
  876. o.left().right(o.right());
  877. o = o.left();
  878. P.remove();
  879. var R = O;
  880. O.right().left(O.left());
  881. O = O.right();
  882. R.remove()
  883. }
  884. break;
  885. case "small":
  886. if (o && O && !a.util.isLine(o.pos(), {
  887. x: N.x,
  888. y: N.y
  889. },
  890. O.pos())) {
  891. M = "big";
  892. r.attr(B.attr.bigDot);
  893. var P = new p("small", a.util.center(o.pos(), N), o, o.right());
  894. o.right(P);
  895. o = P;
  896. var R = new p("small", a.util.center(O.pos(), N), O.left(), O);
  897. O.left(R);
  898. O = R
  899. }
  900. break;
  901. case "to":
  902. if (o && o.left() && o.left().type() == "from") {
  903. var b = a.util.connPoint(k.getBBox(), N);
  904. if (k && s && k.getId() == s.getId()) {
  905. b.y = b.y - 10;
  906. var c = a.util.connPoint(s.getBBox(), N);
  907. c.y = c.y + 10;
  908. o.right().pos(c)
  909. }
  910. o.left().pos(b)
  911. };
  912. if (o && o.left()) {
  913. var d = a.util.center(N, o.left().pos());
  914. if (k && s && k.getId() == s.getId()) {
  915. d.x = d.x + 20
  916. }
  917. o.pos(d)
  918. };
  919. break
  920. }
  921. m()
  922. }
  923. }
  924. function j() {
  925. var D, C, E = k.getBBox(),
  926. F = s.getBBox(),
  927. r,
  928. o,
  929. rn = 0;
  930. r = a.util.connPoint(E, {
  931. x: F.x + F.width / 2,
  932. y: F.y + F.height / 2
  933. });
  934. if (E == F) {
  935. r.y = r.y - 10;
  936. rn = 20
  937. }
  938. o = a.util.connPoint(F, r);
  939. if (E == F) {
  940. o.y = o.y + 20
  941. }
  942. D = new p("from", r, null, new p("small", {
  943. x: (r.x + o.x) / 2 + rn,
  944. y: (r.y + o.y) / 2
  945. }));
  946. D.right().left(D);
  947. C = new p("to", o, D.right(), null);
  948. D.right().right(C);
  949. this.toPathString = function () {
  950. if (!D) {
  951. return ""
  952. }
  953. var J = D,
  954. I = "M" + J.pos().x + " " + J.pos().y,
  955. H = "";
  956. while (J.right()) {
  957. J = J.right();
  958. I += "L" + J.pos().x + " " + J.pos().y
  959. }
  960. var G = a.util.arrow(J.left().pos(), J.pos(), B.attr.arrow.radius);
  961. H = "M" + G[0].x + " " + G[0].y + "L" + G[1].x + " " + G[1].y + "L" + G[2].x + " " + G[2].y + "z";
  962. return [I, H]
  963. };
  964. this.toJson = function () {
  965. var G = [],
  966. H = D;
  967. while (H) {
  968. if (H.type() == "big") {
  969. G.push({
  970. x: Math.round(H.pos().x),
  971. y: Math.round(H.pos().y)
  972. })
  973. }
  974. H = H.right()
  975. }
  976. return G
  977. };
  978. this.restore = function (H) {
  979. var I = H,
  980. J = D.right();
  981. for (var G = 0; G < I.length; G++) {
  982. J.moveTo(I[G].x, I[G].y);
  983. J.moveTo(I[G].x, I[G].y);
  984. J = J.right()
  985. }
  986. this.hide()
  987. };
  988. this.fromDot = function () {
  989. return D
  990. };
  991. this.toDot = function () {
  992. return C
  993. };
  994. this.midDot = function () {
  995. var H = D.right(),
  996. G = D.right().right();
  997. while (G.right() && G.right().right()) {
  998. G = G.right().right();
  999. H = H.right()
  1000. }
  1001. return H
  1002. };
  1003. this.show = function () {
  1004. var G = D;
  1005. while (G) {
  1006. G.node().show();
  1007. G = G.right()
  1008. }
  1009. };
  1010. this.hide = function () {
  1011. var G = D;
  1012. while (G) {
  1013. G.node().hide();
  1014. G = G.right()
  1015. }
  1016. };
  1017. this.remove = function () {
  1018. var G = D;
  1019. while (G) {
  1020. if (G.right()) {
  1021. G = G.right();
  1022. G.left().remove()
  1023. } else {
  1024. G.remove();
  1025. G = null
  1026. }
  1027. }
  1028. }
  1029. }
  1030. B = b.extend(true, B, q);
  1031. i = z.path(B.attr.path.path).attr(B.attr.path);
  1032. t = z.path(B.attr.arrow.path).attr(B.attr.arrow);
  1033. x = new j();
  1034. x.hide();
  1035. if (B.props.text.value) {
  1036. var U = '';
  1037. $(B.props.text.value.split(',')).each(function (i, n) {
  1038. var c;
  1039. $(k.getFlows()).each(function (a, b) {
  1040. if (b.value == n) {
  1041. c = b.name;
  1042. return true
  1043. }
  1044. });
  1045. if (!c) c = n;
  1046. if (U) {
  1047. U += ',' + c
  1048. } else {
  1049. U += c
  1050. }
  1051. });
  1052. B.text.text = U
  1053. } else {
  1054. if (k.getFlows().length == 1) {
  1055. B.props.text.value = k.getFlows()[0].value;
  1056. B.text.text = k.getFlows()[0].name
  1057. }
  1058. };
  1059. f = z.text(0, 0, B.text.text);
  1060. f.drag(function (r, o) {
  1061. if (!a.config.editable) {
  1062. return
  1063. }
  1064. f.attr({
  1065. x: y + r,
  1066. y: w + o
  1067. })
  1068. },
  1069. function () {
  1070. y = f.attr("x");
  1071. w = f.attr("y")
  1072. },
  1073. function () {
  1074. var o = x.midDot().pos();
  1075. h = {
  1076. x: f.attr("x") - o.x,
  1077. y: f.attr("y") - o.y
  1078. }
  1079. });
  1080. f.click(function (e) {
  1081. e.stopPropagation();
  1082. if (!a.config.editable) {
  1083. return
  1084. };
  1085. b(z).trigger("click", v);
  1086. b(z).data("currNode", v);
  1087. return false
  1088. });
  1089. m();
  1090. b([i.node, t.node]).bind("click",
  1091. function () {
  1092. if (!a.config.editable) {
  1093. return
  1094. }
  1095. b(z).trigger("click", v);
  1096. b(z).data("currNode", v);
  1097. return false
  1098. });
  1099. var l = function (e, C) {
  1100. if (!a.config.editable) {
  1101. return
  1102. }
  1103. if (C && C.getId() == g) {
  1104. x.show();
  1105. b(z).trigger("showprops", [B.props, v])
  1106. } else {
  1107. x.hide()
  1108. }
  1109. var o = b(z).data("mod");
  1110. switch (o) {
  1111. case "pointer":
  1112. break;
  1113. case "path":
  1114. break
  1115. }
  1116. };
  1117. b(z).bind("click", l);
  1118. var A = function (o, r) {
  1119. if (!a.config.editable) {
  1120. return
  1121. }
  1122. if (r && (r.getId() == k.getId() || r.getId() == s.getId())) {
  1123. b(z).trigger("removepath", v)
  1124. }
  1125. };
  1126. b(z).bind("removerect", A);
  1127. var d = function (C, D) {
  1128. if (!a.config.editable) {
  1129. return
  1130. }
  1131. if (k && k.getId() == D.getId()) {
  1132. var o;
  1133. if (x.fromDot().right().right().type() == "to") {
  1134. o = {
  1135. x: s.getBBox().x + s.getBBox().width / 2,
  1136. y: s.getBBox().y + s.getBBox().height / 2
  1137. }
  1138. } else {
  1139. o = x.fromDot().right().right().pos()
  1140. }
  1141. var r = a.util.connPoint(k.getBBox(), o);
  1142. x.fromDot().moveTo(r.x, r.y);
  1143. m()
  1144. }
  1145. if (s && s.getId() == D.getId()) {
  1146. var o;
  1147. if (x.toDot().left().left().type() == "from") {
  1148. o = {
  1149. x: k.getBBox().x + k.getBBox().width / 2,
  1150. y: k.getBBox().y + k.getBBox().height / 2
  1151. }
  1152. } else {
  1153. o = x.toDot().left().left().pos()
  1154. }
  1155. var r = a.util.connPoint(s.getBBox(), o);
  1156. x.toDot().moveTo(r.x, r.y);
  1157. m()
  1158. }
  1159. };
  1160. b(z).bind("rectresize", d);
  1161. var c = function (r, o, C) {
  1162. if (C.getId() == g) {
  1163. f.attr({
  1164. text: o
  1165. })
  1166. }
  1167. };
  1168. b(z).bind("textchange", c);
  1169. this.from = function () {
  1170. return k
  1171. };
  1172. this.to = function () {
  1173. return s
  1174. };
  1175. this.toJson = function () {
  1176. var a = {};
  1177. for (var o in B.props) {
  1178. a[o] = {
  1179. value: B.props[o].value
  1180. }
  1181. }
  1182. var r = {
  1183. from: k.getId(),
  1184. to: s.getId(),
  1185. dots: x.toJson(),
  1186. text: {
  1187. text: f.attr("text")
  1188. },
  1189. textPos: {
  1190. x: Math.round(h.x),
  1191. y: Math.round(h.y)
  1192. },
  1193. props: a
  1194. };
  1195. return r
  1196. };
  1197. this.restore = function (o) {
  1198. var r = o;
  1199. B = b.extend(true, B, o);
  1200. x.restore(r.dots)
  1201. };
  1202. this.remove = function () {
  1203. x.remove();
  1204. i.remove();
  1205. t.remove();
  1206. f.remove();
  1207. try {
  1208. b(z).unbind("click", l)
  1209. } catch (o) { }
  1210. try {
  1211. b(z).unbind("removerect", A)
  1212. } catch (o) { }
  1213. try {
  1214. b(z).unbind("rectresize", d)
  1215. } catch (o) { }
  1216. try {
  1217. b(z).unbind("textchange", c)
  1218. } catch (o) { }
  1219. };
  1220. function m() {
  1221. var r = x.toPathString(),
  1222. o = x.midDot().pos();
  1223. i.attr({
  1224. path: r[0]
  1225. });
  1226. t.attr({
  1227. path: r[1]
  1228. });
  1229. f.attr({
  1230. x: o.x + h.x,
  1231. y: o.y + h.y
  1232. })
  1233. };
  1234. this.click = function () {
  1235. if (!a.config.editable) {
  1236. return
  1237. }
  1238. b(z).trigger("click", v);
  1239. b(z).data("currNode", v);
  1240. return false
  1241. };
  1242. this.getId = function () {
  1243. return g
  1244. };
  1245. this.text = function () {
  1246. return f.attr("text")
  1247. };
  1248. this.props = function () {
  1249. return B.props
  1250. };
  1251. this.attr = function (o) {
  1252. if (o && o.path) {
  1253. i.attr(o.path)
  1254. }
  1255. if (o && o.arrow) {
  1256. t.attr(o.arrow)
  1257. }
  1258. }
  1259. };
  1260. a.props = function (h, f) {
  1261. var j = this,
  1262. c = b("#myflow_props").hide().draggable({
  1263. handle: "#myflow_props_handle"
  1264. }).resizable().css(a.config.props.attr).bind("click",
  1265. function () {
  1266. return false
  1267. }),
  1268. e = c.find("#myflow_props_table"),
  1269. g = f,
  1270. i;
  1271. var d = function (n, m, o) {
  1272. var d = '属性';
  1273. switch (o.getId().substring(0, 4)) {
  1274. case 'rect':
  1275. d += '【' + a.config.tools.states[o.type()].text.text + '】';
  1276. break;
  1277. case 'path':
  1278. d += '【' + o.from().text() + '→' + o.to().text() + '】';
  1279. break;
  1280. case '0000':
  1281. d += '【流程】';
  1282. break
  1283. }
  1284. b("#myflow_props_handle").text(d);
  1285. if (i && i.getId() == o.getId()) {
  1286. return
  1287. }
  1288. i = o;
  1289. b(e).find(".editor").each(function () {
  1290. var k = b(this).data("editor");
  1291. if (k) {
  1292. k.destroy()
  1293. }
  1294. });
  1295. e.empty();
  1296. c.show();
  1297. for (var l in m) {
  1298. e.append("<tr><th>" + m[l].label + '</th><td><div id="p' + l + '" class="editor"></div></td></tr>');
  1299. if (m[l].editor) {
  1300. m[l].editor().init(m, l, "p" + l, o, g)
  1301. }
  1302. }
  1303. };
  1304. b(g).bind("showprops", d)
  1305. };
  1306. a.editors = {
  1307. textEditor: function () {
  1308. var d, e, c, g, f;
  1309. this.init = function (i, h, m, l, j) {
  1310. d = i;
  1311. e = h;
  1312. c = m;
  1313. g = l;
  1314. f = j;
  1315. b('<input style="width:calc(100% - 6px);"/>').val(g.text()).change(function () {
  1316. i[e].value = b(this).val();
  1317. b(f).trigger("textchange", [b(this).val(), g])
  1318. }).appendTo("#" + c);
  1319. b("#" + c).data("editor", this)
  1320. };
  1321. this.destroy = function () {
  1322. b("#" + c + " input").each(function () {
  1323. d[e].value = b(this).val();
  1324. b(f).trigger("textchange", [b(this).val(), g])
  1325. })
  1326. }
  1327. },
  1328. checkboxEditor: function () {
  1329. var d, e, c, g, f, k = this;
  1330. this.init = function (i, h, m, l, j) {
  1331. d = i;
  1332. e = h;
  1333. c = m;
  1334. g = l;
  1335. f = j;
  1336. var a = JSON.parse(JSON.stringify(l.from().getFlows()));
  1337. if (l.from().type() == 'CELL_BRANCH') {
  1338. $(JSON.parse(l.from().props().Branch.value)).each(function (i, n) {
  1339. a.push({
  1340. value: n.Value,
  1341. name: n.Value
  1342. })
  1343. })
  1344. };
  1345. for (var o = 0; o < a.length; o++) {
  1346. $('<label style="display:flex"><input type="checkbox" value="' + a[o].value + '" ' + (i[e].value.split(',').indexOf(a[o].value) == -1 ? '' : 'checked="checked"') + ' />' + a[o].name + '</label>').click(function (e) {
  1347. e.stopPropagation()
  1348. }).appendTo("#" + c).find("input").click(function (e) {
  1349. e.stopPropagation()
  1350. }).change(function () {
  1351. k.destroy()
  1352. })
  1353. };
  1354. b("#" + c).data('editor', this)
  1355. };
  1356. this.destroy = function () {
  1357. var a = '',
  1358. tt = '';
  1359. b('#' + c + ' input:checked').each(function () {
  1360. if (a) {
  1361. a += ',' + $(this).val();
  1362. tt += ',' + $(this).parent().text()
  1363. } else {
  1364. a += $(this).val();
  1365. tt += $(this).parent().text()
  1366. }
  1367. });
  1368. d[e].value = a;
  1369. b(f).trigger("textchange", [tt, g])
  1370. }
  1371. }
  1372. };
  1373. a.init = function (x, r) {
  1374. var v = b(window).width(),
  1375. e = b(window).height(),
  1376. y = Raphael(x, v - 20, e * 1.5),
  1377. q = {},
  1378. g = {};
  1379. b.extend(true, a.config, r);
  1380. b(document).keydown(function (i) {
  1381. if (!a.config.editable) {
  1382. return
  1383. }
  1384. if (i.keyCode == 46) {
  1385. var j = b(y).data("currNode");
  1386. if (j) {
  1387. if (j.getId().substring(0, 4) == "rect") {
  1388. b(y).trigger("removerect", j)
  1389. } else {
  1390. if (j.getId().substring(0, 4) == "path") {
  1391. b(y).trigger("removepath", j)
  1392. }
  1393. }
  1394. b(y).removeData("currNode")
  1395. }
  1396. }
  1397. });
  1398. b(document).find("svg").click(function () {
  1399. b(y).data("currNode", null);
  1400. b(y).trigger("click", {
  1401. getId: function () {
  1402. return "00000000"
  1403. }
  1404. });
  1405. b(y).trigger("showprops", [a.config.props.props, {
  1406. getId: function () {
  1407. return "00000000"
  1408. }
  1409. }])
  1410. });
  1411. var w = function (c, i) {
  1412. if (!a.config.editable) {
  1413. return
  1414. }
  1415. if (i.getId().substring(0, 4) == "rect") {
  1416. if (i.type() == "CELL_START") C = false;
  1417. if (i.type() == "CELL_END") ed = false;
  1418. q[i.getId()] = null;
  1419. i.remove()
  1420. } else {
  1421. if (i.getId().substring(0, 4) == "path") {
  1422. g[i.getId()] = null;
  1423. i.remove()
  1424. }
  1425. }
  1426. };
  1427. b(y).bind("removepath", w);
  1428. b(y).bind("removerect", w);
  1429. var C = false,
  1430. ed = false;
  1431. b(y).bind("addrect",
  1432. function (j, c, k) {
  1433. if (c == "CELL_START") {
  1434. if (C) return;
  1435. else C = true
  1436. }
  1437. if (c == "CELL_END") {
  1438. if (ed) return;
  1439. else ed = true
  1440. }
  1441. var i = new a.rect(b.extend(true, {},
  1442. a.config.tools.states[c], k), y);
  1443. q[i.getId()] = i
  1444. });
  1445. var f = function (i, k, j) {
  1446. if (!g["path" + k.getId() + "_" + j.getId()]) {
  1447. var c = new a.path({},
  1448. y, k, j);
  1449. g[c.getId()] = c
  1450. }
  1451. };
  1452. b(y).bind("addpath", f);
  1453. b(y).data("mod", "point");
  1454. if (a.config.editable) {
  1455. b("#myflow_tools").draggable({
  1456. handle: "#myflow_tools_handle"
  1457. }).css(a.config.tools.attr);
  1458. b("#myflow_tools .node").hover(function () {
  1459. b(this).addClass("mover")
  1460. },
  1461. function () {
  1462. b(this).removeClass("mover")
  1463. });
  1464. b("#myflow_tools .selectable").click(function () {
  1465. b(".selected").removeClass("selected");
  1466. b(this).addClass("selected");
  1467. b(y).data("mod", this.id)
  1468. });
  1469. b("#myflow_tools .state").each(function () {
  1470. b(this).draggable({
  1471. helper: "clone"
  1472. })
  1473. });
  1474. b(x).droppable({
  1475. accept: ".state",
  1476. drop: function (c, i) {
  1477. b(y).trigger("addrect", [i.helper.attr("type"), {
  1478. attr: {
  1479. x: i.helper.offset().left,
  1480. y: i.helper.offset().top
  1481. }
  1482. }])
  1483. }
  1484. });
  1485. b("#myflow_save").click(function () {
  1486. if (Object.getOwnPropertyNames(q).length == 0) {
  1487. alert("不能保存空流程");
  1488. return
  1489. }
  1490. var i = '<?xml version="1.0" encoding="utf-8"?>\r\n <ivr>\r\n <flow ';
  1491. for (var c in a.config.props.props) {
  1492. i += c + '="' + a.config.props.props[c].value + '" '
  1493. }
  1494. i += '>\r\n';
  1495. var h = {},
  1496. rps = {};
  1497. for (var c in g) {
  1498. if (g[c]) {
  1499. var f = g[c].props().text.value;
  1500. if (f) {
  1501. var k = g[c].from(),
  1502. pfid = k.getId(),
  1503. ptid = g[c].to().getId(),
  1504. isreapt = false;
  1505. $(f.split(',')).each(function (j, n) {
  1506. if (k.type() == 'CELL_BRANCH') {
  1507. var d = false;
  1508. $(k.getFlows()).each(function (a, b) {
  1509. if (b.value == n) {
  1510. d = true;
  1511. return true
  1512. }
  1513. });
  1514. if (!d) {
  1515. var e = pfid + "_" + n;
  1516. if (!h[e]) h[e] = '';
  1517. h[e] += ' Pos="' + ptid.substr(4) + '" ';
  1518. if (!rps[pfid]) rps[pfid] = [];
  1519. rps[pfid].push(n);
  1520. return true
  1521. }
  1522. }
  1523. if (!h[pfid]) h[pfid] = '';
  1524. h[pfid] += n + '="' + ptid.substr(4) + '" ';
  1525. if (!rps[pfid]) {
  1526. rps[pfid] = []
  1527. } else if (rps[pfid].indexOf(n) != -1) {
  1528. g[c].click();
  1529. isreapt = true;
  1530. return
  1531. }
  1532. rps[pfid].push(n)
  1533. });
  1534. if (isreapt) {
  1535. alert("重复流转");
  1536. return
  1537. }
  1538. } else {
  1539. g[c].click();
  1540. alert("请选择");
  1541. return
  1542. }
  1543. }
  1544. }
  1545. var l = '';
  1546. for (var c in q) {
  1547. if (q[c]) {
  1548. var m = (q[c].props()["Branch"]) ? JSON.parse(q[c].props()["Branch"].value).length : 0;
  1549. if (q[c].getFlows().length + m == (rps[c] ? rps[c].length : 0)) {
  1550. var s = q[c].getBBox();
  1551. var r = ' <cell Name="' + q[c].type() + '" Pos="' + c.substr(4) + '" ' + (h[c] ? h[c] : '') + ' X="' + (s.x + 5) + '" Y="' + (s.y + 5) + '" ';
  1552. var j = '';
  1553. var t = false;
  1554. var u = ['DefVar', 'Map', 'Branch', 'BandData'];
  1555. for (var o in q[c].props()) {
  1556. if (u.indexOf(o) == -1) {
  1557. r += o + '="' + q[c].props()[o].value.replace(/</g, "&lt;").replace(/>/g, "&gt;") + '" '
  1558. } else {
  1559. t = true;
  1560. if (q[c].props()[o].value) {
  1561. $(JSON.parse(q[c].props()[o].value)).each(function (i, n) {
  1562. j += ' <' + o + ' ';
  1563. for (var p in n) {
  1564. j += p + '="' + n[p] + '" '
  1565. }
  1566. if (o == "Branch") {
  1567. j += (h[c + "_" + n["Value"]] ? h[c + "_" + n["Value"]] : '')
  1568. }
  1569. j += ' />\r\n'
  1570. })
  1571. }
  1572. }
  1573. }
  1574. if (t) {
  1575. r += ' >\r\n' + j + ' </cell>\r\n'
  1576. } else {
  1577. r += ' />\r\n'
  1578. }
  1579. l += r
  1580. } else {
  1581. q[c].click();
  1582. alert("未全部流转");
  1583. return
  1584. }
  1585. }
  1586. }
  1587. if (!l) {
  1588. alert("不能保存空流程");
  1589. return
  1590. }
  1591. i += l;
  1592. i += ' </flow>\r\n </ivr>\r\n';
  1593. a.config.tools.save(i, a.config.props.props.Name.value)
  1594. });
  1595. new a.props({},
  1596. y)
  1597. }
  1598. if (r.restore) {
  1599. var B = r.restore;
  1600. var z = {};
  1601. if (B.props) {
  1602. for (var p in a.config.props.props) {
  1603. a.config.props.props[p].value = B.props.props[p].value
  1604. }
  1605. }
  1606. if (B.states) {
  1607. for (var s in B.states) {
  1608. if (B.states[s].type == "CELL_START") C = true;
  1609. if (B.states[s].type == "CELL_END") ed = true;
  1610. var d = new a.rect(b.extend(true, {},
  1611. a.config.tools.states[B.states[s].type], B.states[s]), y);
  1612. d.restore(B.states[s]);
  1613. z[s] = d;
  1614. q[d.getId()] = d
  1615. }
  1616. var D = Object.getOwnPropertyNames(B.states).length / 5 * 200;
  1617. if (D > e * 1.5) {
  1618. b(document).find("svg")[0].setAttribute("height", D)
  1619. }
  1620. }
  1621. if (B.paths) {
  1622. for (var s in B.paths) {
  1623. var n = new a.path(b.extend(true, {},
  1624. a.config.tools.path, B.paths[s]), y, z[B.paths[s].from], z[B.paths[s].to]);
  1625. n.restore(B.paths[s]);
  1626. g[n.getId()] = n
  1627. }
  1628. }
  1629. }
  1630. var A = a.config.historyRects,
  1631. l = a.config.activeRects;
  1632. if (A.rects.length || l.rects.length) {
  1633. var m = {},
  1634. z = {};
  1635. for (var h in g) {
  1636. if (!z[g[h].from().text()]) {
  1637. z[g[h].from().text()] = {
  1638. rect: g[h].from(),
  1639. paths: {}
  1640. }
  1641. };
  1642. z[g[h].from().text()].paths[g[h].text()] = g[h];
  1643. if (!z[g[h].to().text()]) {
  1644. z[g[h].to().text()] = {
  1645. rect: g[h].to(),
  1646. paths: {}
  1647. }
  1648. }
  1649. };
  1650. for (var u = 0; u < A.rects.length; u++) {
  1651. if (z[A.rects[u].name]) {
  1652. z[A.rects[u].name].rect.attr(A.rectAttr)
  1653. };
  1654. for (var t = 0; t < A.rects[u].paths.length; t++) {
  1655. if (z[A.rects[u].name].paths[A.rects[u].paths[t]]) {
  1656. z[A.rects[u].name].paths[A.rects[u].paths[t]].attr(A.pathAttr)
  1657. }
  1658. }
  1659. };
  1660. for (var u = 0; u < l.rects.length; u++) {
  1661. if (z[l.rects[u].name]) {
  1662. z[l.rects[u].name].rect.attr(l.rectAttr)
  1663. };
  1664. for (var t = 0; t < l.rects[u].paths.length; t++) {
  1665. if (z[l.rects[u].name].paths[l.rects[u].paths[t]]) {
  1666. z[l.rects[u].name].paths[l.rects[u].paths[t]].attr(l.pathAttr)
  1667. }
  1668. }
  1669. }
  1670. }
  1671. };
  1672. b.fn.myflow = function (c) {
  1673. return this.each(function () {
  1674. a.init(this, c)
  1675. })
  1676. };
  1677. b.myflow = a
  1678. })(jQuery);