| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678 |
- var hps = [],
- wps = [],
- hlp,
- wlp; (function (b) {
- var a = {};
- a.config = {
- editable: true,
- lineHeight: 15,
- basePath: "",
- rect: {
- attr: {
- x: 10,
- y: 10,
- width: 100,
- height: 50,
- r: 5,
- fill: "90-#fff-#C0C0C0",
- stroke: "#000",
- "stroke-width": 1
- },
- showType: "image&text",
- type: "state",
- name: {
- text: "state",
- "font-style": "italic"
- },
- text: {
- text: "状态",
- "font-size": 13
- },
- margin: 5,
- props: [],
- img: {}
- },
- path: {
- attr: {
- path: {
- path: "M10 10L100 100",
- stroke: "#808080",
- fill: "none",
- "stroke-width": 2
- },
- arrow: {
- path: "M10 10L10 10",
- stroke: "#808080",
- fill: "#808080",
- "stroke-width": 2,
- radius: 4
- },
- fromDot: {
- width: 5,
- height: 5,
- stroke: "#fff",
- fill: "#000",
- cursor: "move",
- "stroke-width": 2
- },
- toDot: {
- width: 5,
- height: 5,
- stroke: "#fff",
- fill: "#000",
- cursor: "move",
- "stroke-width": 2
- },
- bigDot: {
- width: 5,
- height: 5,
- stroke: "#fff",
- fill: "#000",
- cursor: "move",
- "stroke-width": 2
- },
- smallDot: {
- width: 5,
- height: 5,
- stroke: "#fff",
- fill: "#000",
- cursor: "move",
- "stroke-width": 3
- }
- },
- text: {
- text: "",
- cursor: "move",
- background: "#000"
- },
- textPos: {
- x: 0,
- y: -10
- },
- props: {
- text: {
- name: "text",
- label: "显示",
- value: "",
- editor: function () {
- return new a.editors.checkboxEditor()
- }
- }
- }
- },
- tools: {
- attr: {
- left: 10,
- top: 10
- },
- pointer: {},
- path: {},
- states: {},
- save: function (c) {
- alert(c)
- }
- },
- props: {
- attr: {
- top: 10,
- right: 30
- },
- props: {}
- },
- restore: "",
- activeRects: {
- rects: [],
- rectAttr: {
- stroke: "#ff0000",
- "stroke-width": 2
- }
- },
- historyRects: {
- rects: [],
- pathAttr: {
- path: {
- stroke: "#00ff00"
- },
- arrow: {
- stroke: "#00ff00",
- fill: "#00ff00"
- }
- }
- }
- };
- a.util = {
- isLine: function (g, f, e) {
- var d, c;
- if ((g.x - e.x) == 0) {
- d = 1
- } else {
- d = (g.y - e.y) / (g.x - e.x)
- }
- c = (f.x - e.x) * d + e.y;
- if ((f.y - c) < 10 && (f.y - c) > -10) {
- f.y = c;
- return true
- }
- return false
- },
- center: function (d, c) {
- return {
- x: (d.x - c.x) / 2 + c.x,
- y: (d.y - c.y) / 2 + c.y
- }
- },
- nextId: (function () {
- var c = 0;
- return function () {
- return ++c
- }
- })(),
- connPoint: function (j, d) {
- var c = d,
- e = {
- x: j.x + j.width / 2,
- y: j.y + j.height / 2
- };
- var l = (e.y - c.y) / (e.x - c.x);
- l = isNaN(l) ? 0 : l;
- var k = j.height / j.width;
- var h = c.y < e.y ? -1 : 1,
- f = c.x < e.x ? -1 : 1,
- g,
- i;
- if (Math.abs(l) > k && h == -1) {
- g = e.y - j.height / 2;
- i = e.x + h * j.height / 2 / l
- } else {
- if (Math.abs(l) > k && h == 1) {
- g = e.y + j.height / 2;
- i = e.x + h * j.height / 2 / l
- } else {
- if (Math.abs(l) < k && f == -1) {
- g = e.y + f * j.width / 2 * l;
- i = e.x - j.width / 2
- } else {
- if (Math.abs(l) < k && f == 1) {
- g = e.y + j.width / 2 * l;
- i = e.x + j.width / 2
- }
- }
- }
- }
- return {
- x: i,
- y: g
- }
- },
- arrow: function (l, k, d) {
- var g = Math.atan2(l.y - k.y, k.x - l.x) * (180 / Math.PI);
- var h = k.x - d * Math.cos(g * (Math.PI / 180));
- var f = k.y + d * Math.sin(g * (Math.PI / 180));
- var e = h + d * Math.cos((g + 120) * (Math.PI / 180));
- var j = f - d * Math.sin((g + 120) * (Math.PI / 180));
- var c = h + d * Math.cos((g + 240) * (Math.PI / 180));
- var i = f - d * Math.sin((g + 240) * (Math.PI / 180));
- return [k, {
- x: e,
- y: j
- },
- {
- x: c,
- y: i
- }]
- }
- };
- a.rect = function (p, m) {
- var u = this,
- g = "rect" + a.util.nextId(),
- E = b.extend(true, {},
- a.config.rect, p),
- C = m,
- t,
- e,
- n,
- f,
- x,
- v,
- hl,
- wl;
- t = C.rect(E.attr.x, E.attr.y, E.attr.width, E.attr.height, E.attr.r).hide().attr(E.attr);
- 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();
- 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);
- 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);
- t.drag(function (r, o) {
- A(r, o)
- },
- function () {
- z()
- },
- function () {
- l()
- });
- e.drag(function (r, o) {
- A(r, o)
- },
- function () {
- z()
- },
- function () {
- l()
- });
- n.drag(function (r, o) {
- A(r, o)
- },
- function () {
- z()
- },
- function () {
- l()
- });
- f.drag(function (r, o) {
- A(r, o)
- },
- function () {
- z()
- },
- function () {
- l()
- });
- hps.push(E.attr.y * 1 + E.attr.height * 1 / 2);
- wps.push(E.attr.x * 1 + E.attr.width * 1 / 2);
- var A = function (F, r) {
- if (!a.config.editable) {
- return
- }
- var o = (x + F);
- var G = (v + r);
- q.x = o - E.margin;
- q.y = G - E.margin;
- B();
- hl = -1,
- wl = -1;
- $(hps).each(function (i, n) {
- if (Math.abs(n - (G + E.attr.height / 2)) < 5) {
- hl = n;
- return true
- }
- });
- $(wps).each(function (i, n) {
- if (Math.abs(n - (o + E.attr.width / 2)) < 5) {
- wl = n;
- return true
- }
- });
- if (wl > 0) {
- if (!hlp) {
- hlp = C.path("M" + wl + " " + 0 + " L" + wl + " " + b(document).height() * 1.5).attr({
- "stroke": "red",
- "stroke-width": 0.7,
- "stroke-dasharray": "--"
- })
- }
- } else {
- if (hlp) {
- hlp.remove();
- hlp = null
- }
- wl = -1
- }
- if (hl > 0) {
- if (!wlp) {
- wlp = C.path("M" + 0 + " " + hl + " L" + (b(window).width() - 20) + " " + hl).attr({
- "stroke": "red",
- "stroke-width": 0.7,
- "stroke-dasharray": "--"
- })
- }
- } else {
- if (wlp) {
- wlp.remove();
- wlp = null
- }
- hl = -1
- }
- };
- var z = function () {
- x = t.attr("x");
- v = t.attr("y");
- t.attr({
- opacity: 0.5
- });
- e.attr({
- opacity: 0.5
- });
- f.attr({
- opacity: 0.5
- });
- hps.remove(v + E.attr.height / 2);
- wps.remove(x + E.attr.width / 2)
- };
- var l = function () {
- t.attr({
- opacity: 1
- });
- e.attr({
- opacity: 1
- });
- f.attr({
- opacity: 1
- });
- if (hl > 0) q.y = hl - E.attr.height / 2 - E.margin;
- if (wl > 0) q.x = wl - E.attr.width / 2 - E.margin;
- if (hl > 0 || wl > 0) {
- B()
- }
- if (hlp) {
- hlp.remove();
- hlp = null
- }
- if (wlp) {
- wlp.remove();
- wlp = null
- }
- hps.push(q.y + E.attr.height / 2 + E.margin);
- wps.push(q.x + E.attr.width / 2 + E.margin);
- b(C).trigger("rectresize", u)
- };
- var s, i = {},
- h = 5,
- q = {
- x: E.attr.x - E.margin,
- y: E.attr.y - E.margin,
- width: E.attr.width + E.margin * 2,
- height: E.attr.height + E.margin * 2
- };
- s = C.path("M0 0L1 1").hide();
- i.t = C.rect(0, 0, h, h).attr({
- fill: "#000",
- stroke: "#fff",
- cursor: "s-resize"
- }).hide().drag(function (r, o) {
- D(r, o, "t")
- },
- function () {
- k(this.attr("x") + h / 2, this.attr("y") + h / 2, "t")
- },
- function () { });
- i.lt = C.rect(0, 0, h, h).attr({
- fill: "#000",
- stroke: "#fff",
- cursor: "nw-resize"
- }).hide().drag(function (r, o) {
- D(r, o, "lt")
- },
- function () {
- k(this.attr("x") + h / 2, this.attr("y") + h / 2, "lt")
- },
- function () { });
- i.l = C.rect(0, 0, h, h).attr({
- fill: "#000",
- stroke: "#fff",
- cursor: "w-resize"
- }).hide().drag(function (r, o) {
- D(r, o, "l")
- },
- function () {
- k(this.attr("x") + h / 2, this.attr("y") + h / 2, "l")
- },
- function () { });
- i.lb = C.rect(0, 0, h, h).attr({
- fill: "#000",
- stroke: "#fff",
- cursor: "sw-resize"
- }).hide().drag(function (r, o) {
- D(r, o, "lb")
- },
- function () {
- k(this.attr("x") + h / 2, this.attr("y") + h / 2, "lb")
- },
- function () { });
- i.b = C.rect(0, 0, h, h).attr({
- fill: "#000",
- stroke: "#fff",
- cursor: "s-resize"
- }).hide().drag(function (r, o) {
- D(r, o, "b")
- },
- function () {
- k(this.attr("x") + h / 2, this.attr("y") + h / 2, "b")
- },
- function () { });
- i.rb = C.rect(0, 0, h, h).attr({
- fill: "#000",
- stroke: "#fff",
- cursor: "se-resize"
- }).hide().drag(function (r, o) {
- D(r, o, "rb")
- },
- function () {
- k(this.attr("x") + h / 2, this.attr("y") + h / 2, "rb")
- },
- function () { });
- i.r = C.rect(0, 0, h, h).attr({
- fill: "#000",
- stroke: "#fff",
- cursor: "w-resize"
- }).hide().drag(function (r, o) {
- D(r, o, "r")
- },
- function () {
- k(this.attr("x") + h / 2, this.attr("y") + h / 2, "r")
- },
- function () { });
- i.rt = C.rect(0, 0, h, h).attr({
- fill: "#000",
- stroke: "#fff",
- cursor: "ne-resize"
- }).hide().drag(function (r, o) {
- D(r, o, "rt")
- },
- function () {
- k(this.attr("x") + h / 2, this.attr("y") + h / 2, "rt")
- },
- function () { });
- var D = function (F, r, G) {
- if (!a.config.editable) {
- return
- };
- var o = _bx + F,
- H = _by + r;
- switch (G) {
- case "t":
- q.height += q.y - H;
- q.y = H;
- break;
- case "lt":
- q.width += q.x - o;
- q.height += q.y - H;
- q.x = o;
- q.y = H;
- break;
- case "l":
- q.width += q.x - o;
- q.x = o;
- break;
- case "lb":
- q.height = H - q.y;
- q.width += q.x - o;
- q.x = o;
- break;
- case "b":
- q.height = H - q.y;
- break;
- case "rb":
- q.height = H - q.y;
- q.width = o - q.x;
- break;
- case "r":
- q.width = o - q.x;
- break;
- case "rt":
- q.width = o - q.x;
- q.height += q.y - H;
- q.y = H;
- break
- };
- B()
- };
- var k = function (r, o, F) {
- _bx = r;
- _by = o
- };
- b([t.node, f.node, n.node, e.node]).bind("click",
- function () {
- if (!a.config.editable) {
- return
- };
- w();
- var o = b(C).data("mod");
- switch (o) {
- case "pointer":
- break;
- case "path":
- var r = b(C).data("currNode");
- if (r && r.getId().substring(0, 4) == "rect") {
- b(C).trigger("addpath", [r, u])
- };
- break
- }
- b(C).trigger("click", u);
- b(C).data("currNode", u);
- return false
- });
- var j = function (o, r) {
- if (!a.config.editable) {
- return
- }
- if (r.getId() == g) {
- b(C).trigger("showprops", [E.props, r])
- } else {
- d()
- }
- };
- b(C).bind("click", j);
- var c = function (o, F, r) {
- if (r.getId() == g) {
- f.attr({
- text: F
- })
- }
- };
- b(C).bind("textchange", c);
- function y() {
- 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
- }
- function w() {
- s.show();
- for (var o in i) {
- i[o].show()
- }
- }
- function d() {
- s.hide();
- for (var o in i) {
- i[o].hide()
- }
- }
- function B() {
- var F = q.x + E.margin,
- r = q.y + E.margin,
- G = q.width - E.margin * 2,
- o = q.height - E.margin * 2;
- t.attr({
- x: F,
- y: r,
- width: G,
- height: o
- });
- switch (E.showType) {
- case "image":
- e.attr({
- x:
- F + (G - E.img.width) / 2,
- y: r + (o - E.img.height) / 2
- }).show();
- break;
- case "text":
- t.show();
- f.attr({
- x:
- F + G / 2,
- y: r + o / 2
- }).show();
- break;
- case "image&text":
- t.show();
- n.attr({
- x:
- F + E.img.width + (G - E.img.width) / 2,
- y: r + a.config.lineHeight / 2
- }).show();
- f.attr({
- x: F + E.img.width + (G - E.img.width) / 2,
- y: r + (o - a.config.lineHeight) / 2 + a.config.lineHeight
- }).show();
- e.attr({
- x: F + E.img.width / 2,
- y: r + (o - E.img.height) / 2
- }).show();
- break
- }
- i.t.attr({
- x: q.x + q.width / 2 - h / 2,
- y: q.y - h / 2
- });
- i.lt.attr({
- x: q.x - h / 2,
- y: q.y - h / 2
- });
- i.l.attr({
- x: q.x - h / 2,
- y: q.y - h / 2 + q.height / 2
- });
- i.lb.attr({
- x: q.x - h / 2,
- y: q.y - h / 2 + q.height
- });
- i.b.attr({
- x: q.x - h / 2 + q.width / 2,
- y: q.y - h / 2 + q.height
- });
- i.rb.attr({
- x: q.x - h / 2 + q.width,
- y: q.y - h / 2 + q.height
- });
- i.r.attr({
- x: q.x - h / 2 + q.width,
- y: q.y - h / 2 + q.height / 2
- });
- i.rt.attr({
- x: q.x - h / 2 + q.width,
- y: q.y - h / 2
- });
- s.attr({
- path: y()
- })
- }
- this.toJson = function () {
- var a = {};
- for (var o in E.props) {
- a[o] = {
- value: E.props[o].value
- }
- }
- var r = {
- type: E.type,
- text: {
- text: f.attr("text")
- },
- attr: {
- x: Math.round(t.attr("x")),
- y: Math.round(t.attr("y")),
- width: Math.round(t.attr("width")),
- height: Math.round(t.attr("height"))
- },
- props: a
- };
- return r
- };
- this.getFlows = function () {
- return E.flows
- };
- this.restore = function (o) {
- var r = o;
- E = b.extend(true, E, o);
- f.attr({
- text: r.text.text
- });
- B()
- };
- this.click = function () {
- if (!a.config.editable) {
- return
- }
- w();
- b(C).trigger("click", u);
- b(C).data("currNode", u);
- return false
- };
- this.getBBox = function () {
- return q
- };
- this.getId = function () {
- return g
- };
- this.remove = function () {
- hps.remove(t.attr("y") + E.attr.height / 2);
- wps.remove(t.attr("x") + E.attr.width / 2);
- t.remove();
- f.remove();
- n.remove();
- e.remove();
- s.remove();
- for (var o in i) {
- i[o].remove()
- }
- };
- this.text = function () {
- return f.attr("text")
- };
- this.type = function () {
- return E.type
- };
- this.props = function () {
- return E.props
- };
- this.attr = function (o) {
- if (o) {
- t.attr(o)
- }
- };
- B()
- };
- a.path = function (q, n, u, e) {
- var v = this,
- z = n,
- B = b.extend(true, {},
- a.config.path),
- i,
- t,
- f,
- h = B.textPos,
- y,
- w,
- k = u,
- s = e,
- g = "path" + u.getId() + "_" + e.getId(),
- x;
- function p(G, H, D, L) {
- var F = this,
- M = G,
- r, o = D,
- O = L,
- K, I, N = H;
- switch (M) {
- case "from":
- 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);
- break;
- case "big":
- 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);
- break;
- case "small":
- 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);
- break;
- case "to":
- 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);
- break
- }
- if (r && (M == "big" || M == "small")) {
- r.drag(function (Q, P) {
- C(Q, P)
- },
- function () {
- J()
- },
- function () {
- E()
- });
- var C = function (R, Q) {
- var P = (K + R),
- S = (I + Q);
- F.moveTo(P, S)
- };
- var J = function () {
- if (M == "big") {
- K = r.attr("x") + B.attr.bigDot.width / 2;
- I = r.attr("y") + B.attr.bigDot.height / 2
- }
- if (M == "small") {
- K = r.attr("x") + B.attr.smallDot.width / 2;
- I = r.attr("y") + B.attr.smallDot.height / 2
- }
- };
- var E = function () { }
- }
- this.type = function (P) {
- if (P) {
- M = P
- } else {
- return M
- }
- };
- this.node = function (P) {
- if (P) {
- r = P
- } else {
- return r
- }
- };
- this.left = function (P) {
- if (P) {
- o = P
- } else {
- return o
- }
- };
- this.right = function (P) {
- if (P) {
- O = P
- } else {
- return O
- }
- };
- this.remove = function () {
- o = null;
- O = null;
- r.remove()
- };
- this.pos = function (P) {
- if (P) {
- N = P;
- r.attr({
- x: N.x - r.attr("width") / 2,
- y: N.y - r.attr("height") / 2
- });
- return this
- } else {
- return N
- }
- };
- this.moveTo = function (Q, T) {
- this.pos({
- x: Q,
- y: T
- });
- switch (M) {
- case "from":
- if (O && O.right() && O.right().type() == "to") {
- O.right().pos(a.util.connPoint(s.getBBox(), N))
- }
- if (O && O.right()) {
- O.pos(a.util.center(N, O.right().pos()))
- }
- break;
- case "big":
- if (O && O.right() && O.right().type() == "to") {
- O.right().pos(a.util.connPoint(s.getBBox(), N))
- }
- if (o && o.left() && o.left().type() == "from") {
- o.left().pos(a.util.connPoint(k.getBBox(), N))
- }
- if (O && O.right()) {
- O.pos(a.util.center(N, O.right().pos()))
- }
- if (o && o.left()) {
- o.pos(a.util.center(N, o.left().pos()))
- }
- var S = {
- x: N.x,
- y: N.y
- };
- if (a.util.isLine(o.left().pos(), S, O.right().pos())) {
- M = "small";
- r.attr(B.attr.smallDot);
- this.pos(S);
- var P = o;
- o.left().right(o.right());
- o = o.left();
- P.remove();
- var R = O;
- O.right().left(O.left());
- O = O.right();
- R.remove()
- }
- break;
- case "small":
- if (o && O && !a.util.isLine(o.pos(), {
- x: N.x,
- y: N.y
- },
- O.pos())) {
- M = "big";
- r.attr(B.attr.bigDot);
- var P = new p("small", a.util.center(o.pos(), N), o, o.right());
- o.right(P);
- o = P;
- var R = new p("small", a.util.center(O.pos(), N), O.left(), O);
- O.left(R);
- O = R
- }
- break;
- case "to":
- if (o && o.left() && o.left().type() == "from") {
- var b = a.util.connPoint(k.getBBox(), N);
- if (k && s && k.getId() == s.getId()) {
- b.y = b.y - 10;
- var c = a.util.connPoint(s.getBBox(), N);
- c.y = c.y + 10;
- o.right().pos(c)
- }
- o.left().pos(b)
- };
- if (o && o.left()) {
- var d = a.util.center(N, o.left().pos());
- if (k && s && k.getId() == s.getId()) {
- d.x = d.x + 20
- }
- o.pos(d)
- };
- break
- }
- m()
- }
- }
- function j() {
- var D, C, E = k.getBBox(),
- F = s.getBBox(),
- r,
- o,
- rn = 0;
- r = a.util.connPoint(E, {
- x: F.x + F.width / 2,
- y: F.y + F.height / 2
- });
- if (E == F) {
- r.y = r.y - 10;
- rn = 20
- }
- o = a.util.connPoint(F, r);
- if (E == F) {
- o.y = o.y + 20
- }
- D = new p("from", r, null, new p("small", {
- x: (r.x + o.x) / 2 + rn,
- y: (r.y + o.y) / 2
- }));
- D.right().left(D);
- C = new p("to", o, D.right(), null);
- D.right().right(C);
- this.toPathString = function () {
- if (!D) {
- return ""
- }
- var J = D,
- I = "M" + J.pos().x + " " + J.pos().y,
- H = "";
- while (J.right()) {
- J = J.right();
- I += "L" + J.pos().x + " " + J.pos().y
- }
- var G = a.util.arrow(J.left().pos(), J.pos(), B.attr.arrow.radius);
- H = "M" + G[0].x + " " + G[0].y + "L" + G[1].x + " " + G[1].y + "L" + G[2].x + " " + G[2].y + "z";
- return [I, H]
- };
- this.toJson = function () {
- var G = [],
- H = D;
- while (H) {
- if (H.type() == "big") {
- G.push({
- x: Math.round(H.pos().x),
- y: Math.round(H.pos().y)
- })
- }
- H = H.right()
- }
- return G
- };
- this.restore = function (H) {
- var I = H,
- J = D.right();
- for (var G = 0; G < I.length; G++) {
- J.moveTo(I[G].x, I[G].y);
- J.moveTo(I[G].x, I[G].y);
- J = J.right()
- }
- this.hide()
- };
- this.fromDot = function () {
- return D
- };
- this.toDot = function () {
- return C
- };
- this.midDot = function () {
- var H = D.right(),
- G = D.right().right();
- while (G.right() && G.right().right()) {
- G = G.right().right();
- H = H.right()
- }
- return H
- };
- this.show = function () {
- var G = D;
- while (G) {
- G.node().show();
- G = G.right()
- }
- };
- this.hide = function () {
- var G = D;
- while (G) {
- G.node().hide();
- G = G.right()
- }
- };
- this.remove = function () {
- var G = D;
- while (G) {
- if (G.right()) {
- G = G.right();
- G.left().remove()
- } else {
- G.remove();
- G = null
- }
- }
- }
- }
- B = b.extend(true, B, q);
- i = z.path(B.attr.path.path).attr(B.attr.path);
- t = z.path(B.attr.arrow.path).attr(B.attr.arrow);
- x = new j();
- x.hide();
- if (B.props.text.value) {
- var U = '';
- $(B.props.text.value.split(',')).each(function (i, n) {
- var c;
- $(k.getFlows()).each(function (a, b) {
- if (b.value == n) {
- c = b.name;
- return true
- }
- });
- if (!c) c = n;
- if (U) {
- U += ',' + c
- } else {
- U += c
- }
- });
- B.text.text = U
- } else {
- if (k.getFlows().length == 1) {
- B.props.text.value = k.getFlows()[0].value;
- B.text.text = k.getFlows()[0].name
- }
- };
- f = z.text(0, 0, B.text.text);
- f.drag(function (r, o) {
- if (!a.config.editable) {
- return
- }
- f.attr({
- x: y + r,
- y: w + o
- })
- },
- function () {
- y = f.attr("x");
- w = f.attr("y")
- },
- function () {
- var o = x.midDot().pos();
- h = {
- x: f.attr("x") - o.x,
- y: f.attr("y") - o.y
- }
- });
- f.click(function (e) {
- e.stopPropagation();
- if (!a.config.editable) {
- return
- };
- b(z).trigger("click", v);
- b(z).data("currNode", v);
- return false
- });
- m();
- b([i.node, t.node]).bind("click",
- function () {
- if (!a.config.editable) {
- return
- }
- b(z).trigger("click", v);
- b(z).data("currNode", v);
- return false
- });
- var l = function (e, C) {
- if (!a.config.editable) {
- return
- }
- if (C && C.getId() == g) {
- x.show();
- b(z).trigger("showprops", [B.props, v])
- } else {
- x.hide()
- }
- var o = b(z).data("mod");
- switch (o) {
- case "pointer":
- break;
- case "path":
- break
- }
- };
- b(z).bind("click", l);
- var A = function (o, r) {
- if (!a.config.editable) {
- return
- }
- if (r && (r.getId() == k.getId() || r.getId() == s.getId())) {
- b(z).trigger("removepath", v)
- }
- };
- b(z).bind("removerect", A);
- var d = function (C, D) {
- if (!a.config.editable) {
- return
- }
- if (k && k.getId() == D.getId()) {
- var o;
- if (x.fromDot().right().right().type() == "to") {
- o = {
- x: s.getBBox().x + s.getBBox().width / 2,
- y: s.getBBox().y + s.getBBox().height / 2
- }
- } else {
- o = x.fromDot().right().right().pos()
- }
- var r = a.util.connPoint(k.getBBox(), o);
- x.fromDot().moveTo(r.x, r.y);
- m()
- }
- if (s && s.getId() == D.getId()) {
- var o;
- if (x.toDot().left().left().type() == "from") {
- o = {
- x: k.getBBox().x + k.getBBox().width / 2,
- y: k.getBBox().y + k.getBBox().height / 2
- }
- } else {
- o = x.toDot().left().left().pos()
- }
- var r = a.util.connPoint(s.getBBox(), o);
- x.toDot().moveTo(r.x, r.y);
- m()
- }
- };
- b(z).bind("rectresize", d);
- var c = function (r, o, C) {
- if (C.getId() == g) {
- f.attr({
- text: o
- })
- }
- };
- b(z).bind("textchange", c);
- this.from = function () {
- return k
- };
- this.to = function () {
- return s
- };
- this.toJson = function () {
- var a = {};
- for (var o in B.props) {
- a[o] = {
- value: B.props[o].value
- }
- }
- var r = {
- from: k.getId(),
- to: s.getId(),
- dots: x.toJson(),
- text: {
- text: f.attr("text")
- },
- textPos: {
- x: Math.round(h.x),
- y: Math.round(h.y)
- },
- props: a
- };
- return r
- };
- this.restore = function (o) {
- var r = o;
- B = b.extend(true, B, o);
- x.restore(r.dots)
- };
- this.remove = function () {
- x.remove();
- i.remove();
- t.remove();
- f.remove();
- try {
- b(z).unbind("click", l)
- } catch (o) { }
- try {
- b(z).unbind("removerect", A)
- } catch (o) { }
- try {
- b(z).unbind("rectresize", d)
- } catch (o) { }
- try {
- b(z).unbind("textchange", c)
- } catch (o) { }
- };
- function m() {
- var r = x.toPathString(),
- o = x.midDot().pos();
- i.attr({
- path: r[0]
- });
- t.attr({
- path: r[1]
- });
- f.attr({
- x: o.x + h.x,
- y: o.y + h.y
- })
- };
- this.click = function () {
- if (!a.config.editable) {
- return
- }
- b(z).trigger("click", v);
- b(z).data("currNode", v);
- return false
- };
- this.getId = function () {
- return g
- };
- this.text = function () {
- return f.attr("text")
- };
- this.props = function () {
- return B.props
- };
- this.attr = function (o) {
- if (o && o.path) {
- i.attr(o.path)
- }
- if (o && o.arrow) {
- t.attr(o.arrow)
- }
- }
- };
- a.props = function (h, f) {
- var j = this,
- c = b("#myflow_props").hide().draggable({
- handle: "#myflow_props_handle"
- }).resizable().css(a.config.props.attr).bind("click",
- function () {
- return false
- }),
- e = c.find("#myflow_props_table"),
- g = f,
- i;
- var d = function (n, m, o) {
- var d = '属性';
- switch (o.getId().substring(0, 4)) {
- case 'rect':
- d += '【' + a.config.tools.states[o.type()].text.text + '】';
- break;
- case 'path':
- d += '【' + o.from().text() + '→' + o.to().text() + '】';
- break;
- case '0000':
- d += '【流程】';
- break
- }
- b("#myflow_props_handle").text(d);
- if (i && i.getId() == o.getId()) {
- return
- }
- i = o;
- b(e).find(".editor").each(function () {
- var k = b(this).data("editor");
- if (k) {
- k.destroy()
- }
- });
- e.empty();
- c.show();
- for (var l in m) {
- e.append("<tr><th>" + m[l].label + '</th><td><div id="p' + l + '" class="editor"></div></td></tr>');
- if (m[l].editor) {
- m[l].editor().init(m, l, "p" + l, o, g)
- }
- }
- };
- b(g).bind("showprops", d)
- };
- a.editors = {
- textEditor: function () {
- var d, e, c, g, f;
- this.init = function (i, h, m, l, j) {
- d = i;
- e = h;
- c = m;
- g = l;
- f = j;
- b('<input style="width:calc(100% - 6px);"/>').val(g.text()).change(function () {
- i[e].value = b(this).val();
- b(f).trigger("textchange", [b(this).val(), g])
- }).appendTo("#" + c);
- b("#" + c).data("editor", this)
- };
- this.destroy = function () {
- b("#" + c + " input").each(function () {
- d[e].value = b(this).val();
- b(f).trigger("textchange", [b(this).val(), g])
- })
- }
- },
- checkboxEditor: function () {
- var d, e, c, g, f, k = this;
- this.init = function (i, h, m, l, j) {
- d = i;
- e = h;
- c = m;
- g = l;
- f = j;
- var a = JSON.parse(JSON.stringify(l.from().getFlows()));
- if (l.from().type() == 'CELL_BRANCH') {
- $(JSON.parse(l.from().props().Branch.value)).each(function (i, n) {
- a.push({
- value: n.Value,
- name: n.Value
- })
- })
- };
- for (var o = 0; o < a.length; o++) {
- $('<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) {
- e.stopPropagation()
- }).appendTo("#" + c).find("input").click(function (e) {
- e.stopPropagation()
- }).change(function () {
- k.destroy()
- })
- };
- b("#" + c).data('editor', this)
- };
- this.destroy = function () {
- var a = '',
- tt = '';
- b('#' + c + ' input:checked').each(function () {
- if (a) {
- a += ',' + $(this).val();
- tt += ',' + $(this).parent().text()
- } else {
- a += $(this).val();
- tt += $(this).parent().text()
- }
- });
- d[e].value = a;
- b(f).trigger("textchange", [tt, g])
- }
- }
- };
- a.init = function (x, r) {
- var v = b(window).width(),
- e = b(window).height(),
- y = Raphael(x, v - 20, e * 1.5),
- q = {},
- g = {};
- b.extend(true, a.config, r);
- b(document).keydown(function (i) {
- if (!a.config.editable) {
- return
- }
- if (i.keyCode == 46) {
- var j = b(y).data("currNode");
- if (j) {
- if (j.getId().substring(0, 4) == "rect") {
- b(y).trigger("removerect", j)
- } else {
- if (j.getId().substring(0, 4) == "path") {
- b(y).trigger("removepath", j)
- }
- }
- b(y).removeData("currNode")
- }
- }
- });
- b(document).find("svg").click(function () {
- b(y).data("currNode", null);
- b(y).trigger("click", {
- getId: function () {
- return "00000000"
- }
- });
- b(y).trigger("showprops", [a.config.props.props, {
- getId: function () {
- return "00000000"
- }
- }])
- });
- var w = function (c, i) {
- if (!a.config.editable) {
- return
- }
- if (i.getId().substring(0, 4) == "rect") {
- if (i.type() == "CELL_START") C = false;
- if (i.type() == "CELL_END") ed = false;
- q[i.getId()] = null;
- i.remove()
- } else {
- if (i.getId().substring(0, 4) == "path") {
- g[i.getId()] = null;
- i.remove()
- }
- }
- };
- b(y).bind("removepath", w);
- b(y).bind("removerect", w);
- var C = false,
- ed = false;
- b(y).bind("addrect",
- function (j, c, k) {
- if (c == "CELL_START") {
- if (C) return;
- else C = true
- }
- if (c == "CELL_END") {
- if (ed) return;
- else ed = true
- }
- var i = new a.rect(b.extend(true, {},
- a.config.tools.states[c], k), y);
- q[i.getId()] = i
- });
- var f = function (i, k, j) {
- if (!g["path" + k.getId() + "_" + j.getId()]) {
- var c = new a.path({},
- y, k, j);
- g[c.getId()] = c
- }
- };
- b(y).bind("addpath", f);
- b(y).data("mod", "point");
- if (a.config.editable) {
- b("#myflow_tools").draggable({
- handle: "#myflow_tools_handle"
- }).css(a.config.tools.attr);
- b("#myflow_tools .node").hover(function () {
- b(this).addClass("mover")
- },
- function () {
- b(this).removeClass("mover")
- });
- b("#myflow_tools .selectable").click(function () {
- b(".selected").removeClass("selected");
- b(this).addClass("selected");
- b(y).data("mod", this.id)
- });
- b("#myflow_tools .state").each(function () {
- b(this).draggable({
- helper: "clone"
- })
- });
- b(x).droppable({
- accept: ".state",
- drop: function (c, i) {
- b(y).trigger("addrect", [i.helper.attr("type"), {
- attr: {
- x: i.helper.offset().left,
- y: i.helper.offset().top
- }
- }])
- }
- });
- b("#myflow_save").click(function () {
- if (Object.getOwnPropertyNames(q).length == 0) {
- alert("不能保存空流程");
- return
- }
- var i = '<?xml version="1.0" encoding="utf-8"?>\r\n <ivr>\r\n <flow ';
- for (var c in a.config.props.props) {
- i += c + '="' + a.config.props.props[c].value + '" '
- }
- i += '>\r\n';
- var h = {},
- rps = {};
- for (var c in g) {
- if (g[c]) {
- var f = g[c].props().text.value;
- if (f) {
- var k = g[c].from(),
- pfid = k.getId(),
- ptid = g[c].to().getId(),
- isreapt = false;
- $(f.split(',')).each(function (j, n) {
- if (k.type() == 'CELL_BRANCH') {
- var d = false;
- $(k.getFlows()).each(function (a, b) {
- if (b.value == n) {
- d = true;
- return true
- }
- });
- if (!d) {
- var e = pfid + "_" + n;
- if (!h[e]) h[e] = '';
- h[e] += ' Pos="' + ptid.substr(4) + '" ';
- if (!rps[pfid]) rps[pfid] = [];
- rps[pfid].push(n);
- return true
- }
- }
- if (!h[pfid]) h[pfid] = '';
- h[pfid] += n + '="' + ptid.substr(4) + '" ';
- if (!rps[pfid]) {
- rps[pfid] = []
- } else if (rps[pfid].indexOf(n) != -1) {
- g[c].click();
- isreapt = true;
- return
- }
- rps[pfid].push(n)
- });
- if (isreapt) {
- alert("重复流转");
- return
- }
- } else {
- g[c].click();
- alert("请选择");
- return
- }
- }
- }
- var l = '';
- for (var c in q) {
- if (q[c]) {
- var m = (q[c].props()["Branch"]) ? JSON.parse(q[c].props()["Branch"].value).length : 0;
- if (q[c].getFlows().length + m == (rps[c] ? rps[c].length : 0)) {
- var s = q[c].getBBox();
- var r = ' <cell Name="' + q[c].type() + '" Pos="' + c.substr(4) + '" ' + (h[c] ? h[c] : '') + ' X="' + (s.x + 5) + '" Y="' + (s.y + 5) + '" ';
- var j = '';
- var t = false;
- var u = ['DefVar', 'Map', 'Branch', 'BandData'];
- for (var o in q[c].props()) {
- if (u.indexOf(o) == -1) {
- r += o + '="' + q[c].props()[o].value.replace(/</g, "<").replace(/>/g, ">") + '" '
- } else {
- t = true;
- if (q[c].props()[o].value) {
- $(JSON.parse(q[c].props()[o].value)).each(function (i, n) {
- j += ' <' + o + ' ';
- for (var p in n) {
- j += p + '="' + n[p] + '" '
- }
- if (o == "Branch") {
- j += (h[c + "_" + n["Value"]] ? h[c + "_" + n["Value"]] : '')
- }
- j += ' />\r\n'
- })
- }
- }
- }
- if (t) {
- r += ' >\r\n' + j + ' </cell>\r\n'
- } else {
- r += ' />\r\n'
- }
- l += r
- } else {
- q[c].click();
- alert("未全部流转");
- return
- }
- }
- }
- if (!l) {
- alert("不能保存空流程");
- return
- }
- i += l;
- i += ' </flow>\r\n </ivr>\r\n';
- a.config.tools.save(i, a.config.props.props.Name.value)
- });
- new a.props({},
- y)
- }
- if (r.restore) {
- var B = r.restore;
- var z = {};
- if (B.props) {
- for (var p in a.config.props.props) {
- a.config.props.props[p].value = B.props.props[p].value
- }
- }
- if (B.states) {
- for (var s in B.states) {
- if (B.states[s].type == "CELL_START") C = true;
- if (B.states[s].type == "CELL_END") ed = true;
- var d = new a.rect(b.extend(true, {},
- a.config.tools.states[B.states[s].type], B.states[s]), y);
- d.restore(B.states[s]);
- z[s] = d;
- q[d.getId()] = d
- }
- var D = Object.getOwnPropertyNames(B.states).length / 5 * 200;
- if (D > e * 1.5) {
- b(document).find("svg")[0].setAttribute("height", D)
- }
- }
- if (B.paths) {
- for (var s in B.paths) {
- var n = new a.path(b.extend(true, {},
- a.config.tools.path, B.paths[s]), y, z[B.paths[s].from], z[B.paths[s].to]);
- n.restore(B.paths[s]);
- g[n.getId()] = n
- }
- }
- }
- var A = a.config.historyRects,
- l = a.config.activeRects;
- if (A.rects.length || l.rects.length) {
- var m = {},
- z = {};
- for (var h in g) {
- if (!z[g[h].from().text()]) {
- z[g[h].from().text()] = {
- rect: g[h].from(),
- paths: {}
- }
- };
- z[g[h].from().text()].paths[g[h].text()] = g[h];
- if (!z[g[h].to().text()]) {
- z[g[h].to().text()] = {
- rect: g[h].to(),
- paths: {}
- }
- }
- };
- for (var u = 0; u < A.rects.length; u++) {
- if (z[A.rects[u].name]) {
- z[A.rects[u].name].rect.attr(A.rectAttr)
- };
- for (var t = 0; t < A.rects[u].paths.length; t++) {
- if (z[A.rects[u].name].paths[A.rects[u].paths[t]]) {
- z[A.rects[u].name].paths[A.rects[u].paths[t]].attr(A.pathAttr)
- }
- }
- };
- for (var u = 0; u < l.rects.length; u++) {
- if (z[l.rects[u].name]) {
- z[l.rects[u].name].rect.attr(l.rectAttr)
- };
- for (var t = 0; t < l.rects[u].paths.length; t++) {
- if (z[l.rects[u].name].paths[l.rects[u].paths[t]]) {
- z[l.rects[u].name].paths[l.rects[u].paths[t]].attr(l.pathAttr)
- }
- }
- }
- }
- };
- b.fn.myflow = function (c) {
- return this.each(function () {
- a.init(this, c)
- })
- };
- b.myflow = a
- })(jQuery);
|