Dialogs.js 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301
  1. /**
  2. * Copyright (c) 2006-2012, JGraph Ltd
  3. */
  4. /**
  5. * Constructs a new dialog.
  6. */
  7. function Dialog(editorUi, elt, w, h, modal, closable, onClose)
  8. {
  9. var dx = 0;
  10. if (mxClient.IS_VML && (document.documentMode == null || document.documentMode < 8))
  11. {
  12. // Adds padding as a workaround for box model in older IE versions
  13. // This needs to match the total padding of geDialog in CSS
  14. dx = 80;
  15. }
  16. w += dx;
  17. h += dx;
  18. var left = Math.max(0, Math.round((document.body.scrollWidth - w) / 2));
  19. var top = Math.max(0, Math.round((Math.max(document.body.scrollHeight, document.documentElement.scrollHeight) - h - editorUi.footerHeight) / 3));
  20. // Increments zIndex to put subdialogs and background over existing dialogs and background
  21. if (editorUi.dialogs.length > 0)
  22. {
  23. this.zIndex += editorUi.dialogs.length * 2;
  24. }
  25. var div = editorUi.createDiv('geDialog');
  26. div.style.width = w + 'px';
  27. div.style.height = h + 'px';
  28. div.style.left = left + 'px';
  29. div.style.top = top + 'px';
  30. div.style.zIndex = this.zIndex;
  31. if (this.bg == null)
  32. {
  33. this.bg = editorUi.createDiv('background');
  34. this.bg.style.position = 'absolute';
  35. this.bg.style.background = 'white';
  36. this.bg.style.left = '0px';
  37. this.bg.style.top = '0px';
  38. this.bg.style.bottom = '0px';
  39. this.bg.style.right = '0px';
  40. this.bg.style.zIndex = this.zIndex - 2;
  41. mxUtils.setOpacity(this.bg, this.bgOpacity);
  42. if (mxClient.IS_QUIRKS)
  43. {
  44. new mxDivResizer(this.bg);
  45. }
  46. }
  47. if (modal)
  48. {
  49. document.body.appendChild(this.bg);
  50. }
  51. div.appendChild(elt);
  52. document.body.appendChild(div);
  53. if (closable)
  54. {
  55. var img = document.createElement('img');
  56. img.setAttribute('src', Dialog.prototype.closeImage);
  57. img.setAttribute('title', mxResources.get('close'));
  58. img.className = 'geDialogClose';
  59. img.style.top = (top + 14) + 'px';
  60. img.style.left = (left + w + 38 - dx) + 'px';
  61. img.style.zIndex = this.zIndex;
  62. mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
  63. {
  64. editorUi.hideDialog(true);
  65. }));
  66. document.body.appendChild(img);
  67. this.dialogImg = img;
  68. mxEvent.addListener(this.bg, 'click', mxUtils.bind(this, function()
  69. {
  70. editorUi.hideDialog(true);
  71. }));
  72. }
  73. this.onDialogClose = onClose;
  74. this.container = div;
  75. editorUi.editor.fireEvent(new mxEventObject('showDialog'));
  76. };
  77. /**
  78. *
  79. */
  80. Dialog.prototype.zIndex = mxPopupMenu.prototype.zIndex - 1;
  81. /**
  82. *
  83. */
  84. Dialog.prototype.noColorImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/nocolor.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkEzRDlBMUUwODYxMTExRTFCMzA4RDdDMjJBMEMxRDM3IiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkEzRDlBMUUxODYxMTExRTFCMzA4RDdDMjJBMEMxRDM3Ij4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6QTNEOUExREU4NjExMTFFMUIzMDhEN0MyMkEwQzFEMzciIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6QTNEOUExREY4NjExMTFFMUIzMDhEN0MyMkEwQzFEMzciLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz5xh3fmAAAABlBMVEX////MzMw46qqDAAAAGElEQVR42mJggAJGKGAYIIGBth8KAAIMAEUQAIElnLuQAAAAAElFTkSuQmCC';
  85. /**
  86. *
  87. */
  88. Dialog.prototype.closeImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/close.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJAQMAAADaX5RTAAAABlBMVEV7mr3///+wksspAAAAAnRSTlP/AOW3MEoAAAAdSURBVAgdY9jXwCDDwNDRwHCwgeExmASygSL7GgB12QiqNHZZIwAAAABJRU5ErkJggg==';
  89. /**
  90. *
  91. */
  92. Dialog.prototype.clearImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/clear.gif' : 'data:image/gif;base64,R0lGODlhDQAKAIABAMDAwP///yH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4wLWMwNjAgNjEuMTM0Nzc3LCAyMDEwLzAyLzEyLTE3OjMyOjAwICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6OUIzOEM1NzI4NjEyMTFFMUEzMkNDMUE3NjZERDE2QjIiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6OUIzOEM1NzM4NjEyMTFFMUEzMkNDMUE3NjZERDE2QjIiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5QjM4QzU3MDg2MTIxMUUxQTMyQ0MxQTc2NkREMTZCMiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo5QjM4QzU3MTg2MTIxMUUxQTMyQ0MxQTc2NkREMTZCMiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PgH//v38+/r5+Pf29fTz8vHw7+7t7Ovq6ejn5uXk4+Lh4N/e3dzb2tnY19bV1NPS0dDPzs3My8rJyMfGxcTDwsHAv769vLu6ubi3trW0s7KxsK+urayrqqmop6alpKOioaCfnp2cm5qZmJeWlZSTkpGQj46NjIuKiYiHhoWEg4KBgH9+fXx7enl4d3Z1dHNycXBvbm1sa2ppaGdmZWRjYmFgX15dXFtaWVhXVlVUU1JRUE9OTUxLSklIR0ZFRENCQUA/Pj08Ozo5ODc2NTQzMjEwLy4tLCsqKSgnJiUkIyIhIB8eHRwbGhkYFxYVFBMSERAPDg0MCwoJCAcGBQQDAgEAACH5BAEAAAEALAAAAAANAAoAAAIXTGCJebD9jEOTqRlttXdrB32PJ2ncyRQAOw==';
  93. /**
  94. *
  95. */
  96. Dialog.prototype.lockedImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/locked.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzdDMDZCODExNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MzdDMDZCODIxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozN0MwNkI3RjE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozN0MwNkI4MDE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PvqMCFYAAAAVUExURZmZmb+/v7KysqysrMzMzLGxsf///4g8N1cAAAAHdFJOU////////wAaSwNGAAAAPElEQVR42lTMQQ4AIQgEwUa0//9kTQirOweYOgDqAMbZUr10AGlAwx4/BJ2QJ4U0L5brYjovvpv32xZgAHZaATFtMbu4AAAAAElFTkSuQmCC';
  97. /**
  98. *
  99. */
  100. Dialog.prototype.unlockedImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/unlocked.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzdDMDZCN0QxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MzdDMDZCN0UxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozN0MwNkI3QjE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozN0MwNkI3QzE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PkKMpVwAAAAYUExURZmZmbKysr+/v6ysrOXl5czMzLGxsf///zHN5lwAAAAIdFJOU/////////8A3oO9WQAAADxJREFUeNpUzFESACAEBNBVsfe/cZJU+8Mzs8CIABCidtfGOndnYsT40HDSiCcbPdoJo10o9aI677cpwACRoAF3dFNlswAAAABJRU5ErkJggg==';
  101. /**
  102. * Removes the dialog from the DOM.
  103. */
  104. Dialog.prototype.bgOpacity = 80;
  105. /**
  106. * Removes the dialog from the DOM.
  107. */
  108. Dialog.prototype.close = function(cancel)
  109. {
  110. if (this.onDialogClose != null)
  111. {
  112. this.onDialogClose(cancel);
  113. this.onDialogClose = null;
  114. }
  115. if (this.dialogImg != null)
  116. {
  117. this.dialogImg.parentNode.removeChild(this.dialogImg);
  118. this.dialogImg = null;
  119. }
  120. if (this.bg != null && this.bg.parentNode != null)
  121. {
  122. this.bg.parentNode.removeChild(this.bg);
  123. }
  124. this.container.parentNode.removeChild(this.container);
  125. };
  126. /**
  127. * Constructs a new open dialog.
  128. */
  129. var OpenDialog = function()
  130. {
  131. var iframe = document.createElement('iframe');
  132. iframe.style.backgroundColor = 'transparent';
  133. iframe.allowTransparency = 'true';
  134. iframe.style.borderStyle = 'none';
  135. iframe.style.borderWidth = '0px';
  136. iframe.style.overflow = 'hidden';
  137. iframe.frameBorder = '0';
  138. // Adds padding as a workaround for box model in older IE versions
  139. var dx = (mxClient.IS_VML && (document.documentMode == null || document.documentMode < 8)) ? 20 : 0;
  140. iframe.setAttribute('width', (((Editor.useLocalStorage) ? 640 : 320) + dx) + 'px');
  141. iframe.setAttribute('height', (((Editor.useLocalStorage) ? 480 : 220) + dx) + 'px');
  142. iframe.setAttribute('src', OPEN_FORM);
  143. this.container = iframe;
  144. };
  145. /**
  146. * Constructs a new color dialog.
  147. */
  148. var ColorDialog = function(editorUi, color, apply, cancelFn)
  149. {
  150. this.editorUi = editorUi;
  151. var input = document.createElement('input');
  152. input.style.marginBottom = '10px';
  153. input.style.width = '216px';
  154. // Required for picker to render in IE
  155. if (mxClient.IS_IE)
  156. {
  157. input.style.marginTop = '10px';
  158. document.body.appendChild(input);
  159. }
  160. this.init = function()
  161. {
  162. if (!mxClient.IS_TOUCH)
  163. {
  164. input.focus();
  165. }
  166. };
  167. var picker = new jscolor.color(input);
  168. picker.pickerOnfocus = false;
  169. picker.showPicker();
  170. var div = document.createElement('div');
  171. jscolor.picker.box.style.position = 'relative';
  172. jscolor.picker.box.style.width = '230px';
  173. jscolor.picker.box.style.height = '100px';
  174. jscolor.picker.box.style.paddingBottom = '10px';
  175. div.appendChild(jscolor.picker.box);
  176. var center = document.createElement('center');
  177. function createRecentColorTable()
  178. {
  179. var table = addPresets((ColorDialog.recentColors.length == 0) ? ['FFFFFF'] :
  180. ColorDialog.recentColors, 11, 'FFFFFF', true);
  181. table.style.marginBottom = '8px';
  182. return table;
  183. };
  184. function addPresets(presets, rowLength, defaultColor, addResetOption)
  185. {
  186. rowLength = (rowLength != null) ? rowLength : 12;
  187. var table = document.createElement('table');
  188. table.style.borderCollapse = 'collapse';
  189. table.setAttribute('cellspacing', '0');
  190. table.style.marginBottom = '20px';
  191. table.style.cellSpacing = '0px';
  192. var tbody = document.createElement('tbody');
  193. table.appendChild(tbody);
  194. var rows = presets.length / rowLength;
  195. for (var row = 0; row < rows; row++)
  196. {
  197. var tr = document.createElement('tr');
  198. for (var i = 0; i < rowLength; i++)
  199. {
  200. (function(clr)
  201. {
  202. var td = document.createElement('td');
  203. td.style.border = '1px solid black';
  204. td.style.padding = '0px';
  205. td.style.width = '16px';
  206. td.style.height = '16px';
  207. if (clr == null)
  208. {
  209. clr = defaultColor;
  210. }
  211. if (clr == 'none')
  212. {
  213. td.style.background = 'url(\'' + Dialog.prototype.noColorImage + '\')';
  214. }
  215. else
  216. {
  217. td.style.backgroundColor = '#' + clr;
  218. }
  219. tr.appendChild(td);
  220. if (clr != null)
  221. {
  222. td.style.cursor = 'pointer';
  223. mxEvent.addListener(td, 'click', function()
  224. {
  225. if (clr == 'none')
  226. {
  227. picker.fromString('ffffff');
  228. input.value = 'none';
  229. }
  230. else
  231. {
  232. picker.fromString(clr);
  233. }
  234. });
  235. }
  236. })(presets[row * rowLength + i]);
  237. }
  238. tbody.appendChild(tr);
  239. }
  240. if (addResetOption)
  241. {
  242. var td = document.createElement('td');
  243. td.setAttribute('title', mxResources.get('reset'));
  244. td.style.border = '1px solid black';
  245. td.style.padding = '0px';
  246. td.style.width = '16px';
  247. td.style.height = '16px';
  248. td.style.backgroundImage = 'url(\'' + Dialog.prototype.closeImage + '\')';
  249. td.style.backgroundPosition = 'center center';
  250. td.style.backgroundRepeat = 'no-repeat';
  251. td.style.cursor = 'pointer';
  252. tr.appendChild(td);
  253. mxEvent.addListener(td, 'click', function()
  254. {
  255. ColorDialog.resetRecentColors();
  256. table.parentNode.replaceChild(createRecentColorTable(), table);
  257. });
  258. }
  259. center.appendChild(table);
  260. return table;
  261. };
  262. div.appendChild(input);
  263. mxUtils.br(div);
  264. // Adds recent colors
  265. createRecentColorTable();
  266. // Adds presets
  267. var table = addPresets(['E6D0DE', 'CDA2BE', 'B5739D', 'E1D5E7', 'C3ABD0', 'A680B8', 'D4E1F5', 'A9C4EB', '7EA6E0', 'D5E8D4', '9AC7BF', '67AB9F', 'D5E8D4', 'B9E0A5', '97D077', 'FFF2CC', 'FFE599', 'FFD966', 'FFF4C3', 'FFCE9F', 'FFB570', 'F8CECC', 'F19C99', 'EA6B66'], 12);
  268. table.style.marginBottom = '8px';
  269. table = addPresets(['none', 'FFFFFF', 'E6E6E6', 'CCCCCC', 'B3B3B3', '999999', '808080', '666666', '4D4D4D', '333333', '1A1A1A', '000000', 'FFCCCC', 'FFE6CC', 'FFFFCC', 'E6FFCC', 'CCFFCC', 'CCFFE6', 'CCFFFF', 'CCE5FF', 'CCCCFF', 'E5CCFF', 'FFCCFF', 'FFCCE6', 'FF9999', 'FFCC99', 'FFFF99', 'CCFF99', '99FF99', '99FFCC', '99FFFF', '99CCFF', '9999FF', 'CC99FF', 'FF99FF', 'FF99CC', 'FF6666', 'FFB366', 'FFFF66', 'B3FF66', '66FF66', '66FFB3', '66FFFF', '66B2FF', '6666FF', 'B266FF', 'FF66FF', 'FF66B3', 'FF3333', 'FF9933', 'FFFF33', '99FF33', '33FF33', '33FF99', '33FFFF', '3399FF', '3333FF', '9933FF', 'FF33FF', 'FF3399', 'FF0000', 'FF8000', 'FFFF00', '80FF00', '00FF00', '00FF80', '00FFFF', '007FFF', '0000FF', '7F00FF', 'FF00FF', 'FF0080', 'CC0000', 'CC6600', 'CCCC00', '66CC00', '00CC00', '00CC66', '00CCCC', '0066CC', '0000CC', '6600CC', 'CC00CC', 'CC0066', '990000', '994C00', '999900', '4D9900', '009900', '00994D', '009999', '004C99', '000099', '4C0099', '990099', '99004D', '660000', '663300', '666600', '336600', '006600', '006633', '006666', '003366', '000066', '330066', '660066', '660033', '330000', '331A00', '333300', '1A3300', '003300', '00331A', '003333', '001933', '000033', '190033', '330033', '33001A']);
  270. table.style.marginBottom = '16px';
  271. div.appendChild(center);
  272. var buttons = document.createElement('div');
  273. buttons.style.textAlign = 'right';
  274. buttons.style.whiteSpace = 'nowrap';
  275. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  276. {
  277. editorUi.hideDialog();
  278. if (cancelFn != null)
  279. {
  280. cancelFn();
  281. }
  282. });
  283. cancelBtn.className = 'geBtn';
  284. if (editorUi.editor.cancelFirst)
  285. {
  286. buttons.appendChild(cancelBtn);
  287. }
  288. var applyFunction = (apply != null) ? apply : this.createApplyFunction();
  289. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  290. {
  291. var color = input.value;
  292. ColorDialog.addRecentColor(color, 12);
  293. if (color != 'none' && color.charAt(0) != '#')
  294. {
  295. color = '#' + color;
  296. }
  297. applyFunction(color);
  298. editorUi.hideDialog();
  299. });
  300. applyBtn.className = 'geBtn gePrimaryBtn';
  301. buttons.appendChild(applyBtn);
  302. if (!editorUi.editor.cancelFirst)
  303. {
  304. buttons.appendChild(cancelBtn);
  305. }
  306. if (color != null)
  307. {
  308. if (color == 'none')
  309. {
  310. picker.fromString('ffffff');
  311. input.value = 'none';
  312. }
  313. else
  314. {
  315. picker.fromString(color);
  316. }
  317. }
  318. div.appendChild(buttons);
  319. this.picker = picker;
  320. this.colorInput = input;
  321. // LATER: Only fires if input if focused, should always
  322. // fire if this dialog is showing.
  323. mxEvent.addListener(div, 'keydown', function(e)
  324. {
  325. if (e.keyCode == 27)
  326. {
  327. editorUi.hideDialog();
  328. if (cancelFn != null)
  329. {
  330. cancelFn();
  331. }
  332. mxEvent.consume(e);
  333. }
  334. });
  335. this.container = div;
  336. };
  337. /* Creates function to apply value */
  338. ColorDialog.prototype.createApplyFunction = function()
  339. {
  340. return mxUtils.bind(this, function(color)
  341. {
  342. var graph = this.editorUi.editor.graph;
  343. graph.getModel().beginUpdate();
  344. try
  345. {
  346. graph.setCellStyles(this.currentColorKey, color);
  347. this.editorUi.fireEvent(new mxEventObject('styleChanged', 'keys', [this.currentColorKey],
  348. 'values', [color], 'cells', graph.getSelectionCells()));
  349. }
  350. finally
  351. {
  352. graph.getModel().endUpdate();
  353. }
  354. });
  355. };
  356. /**
  357. *
  358. */
  359. ColorDialog.recentColors = [];
  360. /**
  361. * Adds recent color for later use.
  362. */
  363. ColorDialog.addRecentColor = function(color, max)
  364. {
  365. if (color != null)
  366. {
  367. mxUtils.remove(color, ColorDialog.recentColors);
  368. ColorDialog.recentColors.splice(0, 0, color);
  369. if (ColorDialog.recentColors.length > max)
  370. {
  371. ColorDialog.recentColors.pop();
  372. }
  373. }
  374. };
  375. /**
  376. * Adds recent color for later use.
  377. */
  378. ColorDialog.resetRecentColors = function()
  379. {
  380. ColorDialog.recentColors = [];
  381. };
  382. /**
  383. * Constructs a new about dialog.
  384. */
  385. var AboutDialog = function(editorUi)
  386. {
  387. var div = document.createElement('div');
  388. div.setAttribute('align', 'center');
  389. var h3 = document.createElement('h3');
  390. mxUtils.write(h3, mxResources.get('about') + ' GraphEditor');
  391. div.appendChild(h3);
  392. var img = document.createElement('img');
  393. img.style.border = '0px';
  394. img.setAttribute('width', '176');
  395. img.setAttribute('width', '151');
  396. img.setAttribute('src', IMAGE_PATH + '/logo.png');
  397. div.appendChild(img);
  398. mxUtils.br(div);
  399. mxUtils.write(div, 'Powered by mxGraph ' + mxClient.VERSION);
  400. mxUtils.br(div);
  401. var link = document.createElement('a');
  402. link.setAttribute('href', 'http://www.jgraph.com/');
  403. link.setAttribute('target', '_blank');
  404. mxUtils.write(link, 'www.jgraph.com');
  405. div.appendChild(link);
  406. mxUtils.br(div);
  407. mxUtils.br(div);
  408. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  409. {
  410. editorUi.hideDialog();
  411. });
  412. closeBtn.className = 'geBtn gePrimaryBtn';
  413. div.appendChild(closeBtn);
  414. this.container = div;
  415. };
  416. /**
  417. * Constructs a new page setup dialog.
  418. */
  419. var PageSetupDialog = function(editorUi)
  420. {
  421. var graph = editorUi.editor.graph;
  422. var row, td;
  423. var table = document.createElement('table');
  424. table.style.width = '100%';
  425. table.style.height = '100%';
  426. var tbody = document.createElement('tbody');
  427. row = document.createElement('tr');
  428. td = document.createElement('td');
  429. td.style.verticalAlign = 'top';
  430. td.style.fontSize = '10pt';
  431. mxUtils.write(td, mxResources.get('paperSize') + ':');
  432. row.appendChild(td);
  433. td = document.createElement('td');
  434. td.style.verticalAlign = 'top';
  435. td.style.fontSize = '10pt';
  436. var accessor = PageSetupDialog.addPageFormatPanel(td, 'pagesetupdialog', graph.pageFormat);
  437. row.appendChild(td);
  438. tbody.appendChild(row);
  439. row = document.createElement('tr');
  440. td = document.createElement('td');
  441. mxUtils.write(td, mxResources.get('background') + ':');
  442. row.appendChild(td);
  443. td = document.createElement('td');
  444. td.style.whiteSpace = 'nowrap';
  445. var backgroundInput = document.createElement('input');
  446. backgroundInput.setAttribute('type', 'text');
  447. var backgroundButton = document.createElement('button');
  448. backgroundButton.style.width = '18px';
  449. backgroundButton.style.height = '18px';
  450. backgroundButton.style.marginRight = '20px';
  451. backgroundButton.style.backgroundPosition = 'center center';
  452. backgroundButton.style.backgroundRepeat = 'no-repeat';
  453. var newBackgroundColor = graph.background;
  454. function updateBackgroundColor()
  455. {
  456. if (newBackgroundColor == null || newBackgroundColor == mxConstants.NONE)
  457. {
  458. backgroundButton.style.backgroundColor = '';
  459. backgroundButton.style.backgroundImage = 'url(\'' + Dialog.prototype.noColorImage + '\')';
  460. }
  461. else
  462. {
  463. backgroundButton.style.backgroundColor = newBackgroundColor;
  464. backgroundButton.style.backgroundImage = '';
  465. }
  466. };
  467. updateBackgroundColor();
  468. mxEvent.addListener(backgroundButton, 'click', function(evt)
  469. {
  470. editorUi.pickColor(newBackgroundColor || 'none', function(color)
  471. {
  472. newBackgroundColor = color;
  473. updateBackgroundColor();
  474. });
  475. mxEvent.consume(evt);
  476. });
  477. td.appendChild(backgroundButton);
  478. mxUtils.write(td, mxResources.get('gridSize') + ':');
  479. var gridSizeInput = document.createElement('input');
  480. gridSizeInput.setAttribute('type', 'number');
  481. gridSizeInput.setAttribute('min', '0');
  482. gridSizeInput.style.width = '40px';
  483. gridSizeInput.style.marginLeft = '6px';
  484. gridSizeInput.value = graph.getGridSize();
  485. td.appendChild(gridSizeInput);
  486. mxEvent.addListener(gridSizeInput, 'change', function()
  487. {
  488. var value = parseInt(gridSizeInput.value);
  489. gridSizeInput.value = Math.max(1, (isNaN(value)) ? graph.getGridSize() : value);
  490. });
  491. row.appendChild(td);
  492. tbody.appendChild(row);
  493. row = document.createElement('tr');
  494. td = document.createElement('td');
  495. mxUtils.write(td, mxResources.get('image') + ':');
  496. row.appendChild(td);
  497. td = document.createElement('td');
  498. var changeImageLink = document.createElement('a');
  499. changeImageLink.style.textDecoration = 'underline';
  500. changeImageLink.style.cursor = 'pointer';
  501. changeImageLink.style.color = '#a0a0a0';
  502. var newBackgroundImage = graph.backgroundImage;
  503. function updateBackgroundImage()
  504. {
  505. if (newBackgroundImage == null)
  506. {
  507. changeImageLink.removeAttribute('title');
  508. changeImageLink.style.fontSize = '';
  509. changeImageLink.innerHTML = mxResources.get('change') + '...';
  510. }
  511. else
  512. {
  513. changeImageLink.setAttribute('title', newBackgroundImage.src);
  514. changeImageLink.style.fontSize = '11px';
  515. changeImageLink.innerHTML = newBackgroundImage.src.substring(0, 42) + '...';
  516. }
  517. };
  518. mxEvent.addListener(changeImageLink, 'click', function(evt)
  519. {
  520. editorUi.showBackgroundImageDialog(function(image)
  521. {
  522. newBackgroundImage = image;
  523. updateBackgroundImage();
  524. });
  525. mxEvent.consume(evt);
  526. });
  527. updateBackgroundImage();
  528. td.appendChild(changeImageLink);
  529. row.appendChild(td);
  530. tbody.appendChild(row);
  531. row = document.createElement('tr');
  532. td = document.createElement('td');
  533. td.colSpan = 2;
  534. td.style.paddingTop = '16px';
  535. td.setAttribute('align', 'right');
  536. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  537. {
  538. editorUi.hideDialog();
  539. });
  540. cancelBtn.className = 'geBtn';
  541. if (editorUi.editor.cancelFirst)
  542. {
  543. td.appendChild(cancelBtn);
  544. }
  545. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  546. {
  547. editorUi.hideDialog();
  548. editorUi.setPageFormat(accessor.get());
  549. if (graph.background != newBackgroundColor)
  550. {
  551. editorUi.setBackgroundColor(newBackgroundColor);
  552. }
  553. if (graph.backgroundImage !== newBackgroundImage)
  554. {
  555. editorUi.setBackgroundImage(newBackgroundImage);
  556. }
  557. if (graph.gridSize !== gridSizeInput.value)
  558. {
  559. graph.setGridSize(parseInt(gridSizeInput.value));
  560. }
  561. });
  562. applyBtn.className = 'geBtn gePrimaryBtn';
  563. td.appendChild(applyBtn);
  564. if (!editorUi.editor.cancelFirst)
  565. {
  566. td.appendChild(cancelBtn);
  567. }
  568. row.appendChild(td);
  569. tbody.appendChild(row);
  570. table.appendChild(tbody);
  571. this.container = table;
  572. };
  573. /**
  574. *
  575. */
  576. PageSetupDialog.addPageFormatPanel = function(div, namePostfix, pageFormat, pageFormatListener)
  577. {
  578. var formatName = 'format-' + namePostfix;
  579. var portraitCheckBox = document.createElement('input');
  580. portraitCheckBox.setAttribute('name', formatName);
  581. portraitCheckBox.setAttribute('type', 'radio');
  582. portraitCheckBox.setAttribute('value', 'portrait');
  583. var landscapeCheckBox = document.createElement('input');
  584. landscapeCheckBox.setAttribute('name', formatName);
  585. landscapeCheckBox.setAttribute('type', 'radio');
  586. landscapeCheckBox.setAttribute('value', 'landscape');
  587. var paperSizeSelect = document.createElement('select');
  588. paperSizeSelect.style.marginBottom = '8px';
  589. paperSizeSelect.style.width = '202px';
  590. var formatDiv = document.createElement('div');
  591. formatDiv.style.marginLeft = '4px';
  592. formatDiv.style.width = '210px';
  593. formatDiv.style.height = '24px';
  594. portraitCheckBox.style.marginRight = '6px';
  595. formatDiv.appendChild(portraitCheckBox);
  596. var portraitSpan = document.createElement('span');
  597. portraitSpan.style.maxWidth = '100px';
  598. mxUtils.write(portraitSpan, mxResources.get('portrait'));
  599. formatDiv.appendChild(portraitSpan);
  600. landscapeCheckBox.style.marginLeft = '10px';
  601. landscapeCheckBox.style.marginRight = '6px';
  602. formatDiv.appendChild(landscapeCheckBox);
  603. var landscapeSpan = document.createElement('span');
  604. landscapeSpan.style.width = '100px';
  605. mxUtils.write(landscapeSpan, mxResources.get('landscape'));
  606. formatDiv.appendChild(landscapeSpan)
  607. var customDiv = document.createElement('div');
  608. customDiv.style.marginLeft = '4px';
  609. customDiv.style.width = '210px';
  610. customDiv.style.height = '24px';
  611. var widthInput = document.createElement('input');
  612. widthInput.setAttribute('size', '6');
  613. widthInput.setAttribute('value', pageFormat.width);
  614. customDiv.appendChild(widthInput);
  615. mxUtils.write(customDiv, ' x ');
  616. var heightInput = document.createElement('input');
  617. heightInput.setAttribute('size', '6');
  618. heightInput.setAttribute('value', pageFormat.height);
  619. customDiv.appendChild(heightInput);
  620. mxUtils.write(customDiv, ' pt');
  621. formatDiv.style.display = 'none';
  622. customDiv.style.display = 'none';
  623. var pf = new Object();
  624. var formats = PageSetupDialog.getFormats();
  625. for (var i = 0; i < formats.length; i++)
  626. {
  627. var f = formats[i];
  628. pf[f.key] = f;
  629. var paperSizeOption = document.createElement('option');
  630. paperSizeOption.setAttribute('value', f.key);
  631. mxUtils.write(paperSizeOption, f.title);
  632. paperSizeSelect.appendChild(paperSizeOption);
  633. }
  634. var customSize = false;
  635. function listener(sender, evt, force)
  636. {
  637. if (force || (widthInput != document.activeElement && heightInput != document.activeElement))
  638. {
  639. var detected = false;
  640. for (var i = 0; i < formats.length; i++)
  641. {
  642. var f = formats[i];
  643. // Special case where custom was chosen
  644. if (customSize)
  645. {
  646. if (f.key == 'custom')
  647. {
  648. paperSizeSelect.value = f.key;
  649. customSize = false;
  650. }
  651. }
  652. else if (f.format != null)
  653. {
  654. if (pageFormat.width == f.format.width && pageFormat.height == f.format.height)
  655. {
  656. paperSizeSelect.value = f.key;
  657. portraitCheckBox.setAttribute('checked', 'checked');
  658. portraitCheckBox.defaultChecked = true;
  659. portraitCheckBox.checked = true;
  660. landscapeCheckBox.removeAttribute('checked');
  661. landscapeCheckBox.defaultChecked = false;
  662. landscapeCheckBox.checked = false;
  663. detected = true;
  664. }
  665. else if (pageFormat.width == f.format.height && pageFormat.height == f.format.width)
  666. {
  667. paperSizeSelect.value = f.key;
  668. portraitCheckBox.removeAttribute('checked');
  669. portraitCheckBox.defaultChecked = false;
  670. portraitCheckBox.checked = false;
  671. landscapeCheckBox.setAttribute('checked', 'checked');
  672. landscapeCheckBox.defaultChecked = true;
  673. landscapeCheckBox.checked = true;
  674. detected = true;
  675. }
  676. }
  677. }
  678. // Selects custom format which is last in list
  679. if (!detected)
  680. {
  681. widthInput.value = pageFormat.width;
  682. heightInput.value = pageFormat.height;
  683. paperSizeOption.setAttribute('selected', 'selected');
  684. portraitCheckBox.setAttribute('checked', 'checked');
  685. portraitCheckBox.defaultChecked = true;
  686. formatDiv.style.display = 'none';
  687. customDiv.style.display = '';
  688. }
  689. else
  690. {
  691. formatDiv.style.display = '';
  692. customDiv.style.display = 'none';
  693. }
  694. }
  695. };
  696. listener();
  697. div.appendChild(paperSizeSelect);
  698. mxUtils.br(div);
  699. div.appendChild(formatDiv);
  700. div.appendChild(customDiv);
  701. var currentPageFormat = pageFormat;
  702. var update = function()
  703. {
  704. var f = pf[paperSizeSelect.value];
  705. if (f.format != null)
  706. {
  707. widthInput.value = f.format.width;
  708. heightInput.value = f.format.height;
  709. customDiv.style.display = 'none';
  710. formatDiv.style.display = '';
  711. }
  712. else
  713. {
  714. formatDiv.style.display = 'none';
  715. customDiv.style.display = '';
  716. }
  717. var newPageFormat = new mxRectangle(0, 0, parseInt(widthInput.value), parseInt(heightInput.value));
  718. if (paperSizeSelect.value != 'custom' && landscapeCheckBox.checked)
  719. {
  720. newPageFormat = new mxRectangle(0, 0, newPageFormat.height, newPageFormat.width);
  721. }
  722. if (newPageFormat.width != currentPageFormat.width || newPageFormat.height != currentPageFormat.height)
  723. {
  724. currentPageFormat = newPageFormat;
  725. if (pageFormatListener != null)
  726. {
  727. pageFormatListener(currentPageFormat);
  728. }
  729. }
  730. };
  731. mxEvent.addListener(portraitSpan, 'click', function(evt)
  732. {
  733. portraitCheckBox.checked = true;
  734. update();
  735. mxEvent.consume(evt);
  736. });
  737. mxEvent.addListener(landscapeSpan, 'click', function(evt)
  738. {
  739. landscapeCheckBox.checked = true;
  740. update();
  741. mxEvent.consume(evt);
  742. });
  743. mxEvent.addListener(widthInput, 'blur', update);
  744. mxEvent.addListener(widthInput, 'click', update);
  745. mxEvent.addListener(heightInput, 'blur', update);
  746. mxEvent.addListener(heightInput, 'click', update);
  747. mxEvent.addListener(landscapeCheckBox, 'change', update);
  748. mxEvent.addListener(portraitCheckBox, 'change', update);
  749. mxEvent.addListener(paperSizeSelect, 'change', function()
  750. {
  751. // Handles special case where custom was chosen
  752. customSize = paperSizeSelect.value == 'custom';
  753. update();
  754. });
  755. update();
  756. return {set: function(value)
  757. {
  758. pageFormat = value;
  759. listener(null, null, true);
  760. },get: function()
  761. {
  762. return currentPageFormat;
  763. }, widthInput: widthInput,
  764. heightInput: heightInput};
  765. };
  766. /**
  767. *
  768. */
  769. PageSetupDialog.getFormats = function()
  770. {
  771. return [{key: 'letter', title: 'US-Letter (8,5" x 11")', format: mxConstants.PAGE_FORMAT_LETTER_PORTRAIT},
  772. {key: 'legal', title: 'US-Legal (8,5" x 14")', format: new mxRectangle(0, 0, 850, 1400)},
  773. {key: 'tabloid', title: 'US-Tabloid (279 mm x 432 mm)', format: new mxRectangle(0, 0, 1100, 1700)},
  774. {key: 'a3', title: 'A3 (297 mm x 420 mm)', format: new mxRectangle(0, 0, 1169, 1652)},
  775. {key: 'a4', title: 'A4 (210 mm x 297 mm)', format: mxConstants.PAGE_FORMAT_A4_PORTRAIT},
  776. {key: 'a5', title: 'A5 (148 mm x 210 mm)', format: new mxRectangle(0, 0, 584, 826)},
  777. {key: 'custom', title: mxResources.get('custom'), format: null}];
  778. };
  779. /**
  780. * Constructs a new print dialog.
  781. */
  782. var PrintDialog = function(editorUi)
  783. {
  784. this.create(editorUi);
  785. };
  786. /**
  787. * Constructs a new print dialog.
  788. */
  789. PrintDialog.prototype.create = function(editorUi)
  790. {
  791. var graph = editorUi.editor.graph;
  792. var row, td;
  793. var table = document.createElement('table');
  794. table.style.width = '100%';
  795. table.style.height = '100%';
  796. var tbody = document.createElement('tbody');
  797. row = document.createElement('tr');
  798. var onePageCheckBox = document.createElement('input');
  799. onePageCheckBox.setAttribute('type', 'checkbox');
  800. td = document.createElement('td');
  801. td.setAttribute('colspan', '2');
  802. td.style.fontSize = '10pt';
  803. td.appendChild(onePageCheckBox);
  804. var span = document.createElement('span');
  805. mxUtils.write(span, ' ' + mxResources.get('fitPage'));
  806. td.appendChild(span);
  807. mxEvent.addListener(span, 'click', function(evt)
  808. {
  809. onePageCheckBox.checked = !onePageCheckBox.checked;
  810. pageCountCheckBox.checked = !onePageCheckBox.checked;
  811. mxEvent.consume(evt);
  812. });
  813. mxEvent.addListener(onePageCheckBox, 'change', function()
  814. {
  815. pageCountCheckBox.checked = !onePageCheckBox.checked;
  816. });
  817. row.appendChild(td);
  818. tbody.appendChild(row);
  819. row = row.cloneNode(false);
  820. var pageCountCheckBox = document.createElement('input');
  821. pageCountCheckBox.setAttribute('type', 'checkbox');
  822. td = document.createElement('td');
  823. td.style.fontSize = '10pt';
  824. td.appendChild(pageCountCheckBox);
  825. var span = document.createElement('span');
  826. mxUtils.write(span, ' ' + mxResources.get('posterPrint') + ':');
  827. td.appendChild(span);
  828. mxEvent.addListener(span, 'click', function(evt)
  829. {
  830. pageCountCheckBox.checked = !pageCountCheckBox.checked;
  831. onePageCheckBox.checked = !pageCountCheckBox.checked;
  832. mxEvent.consume(evt);
  833. });
  834. row.appendChild(td);
  835. var pageCountInput = document.createElement('input');
  836. pageCountInput.setAttribute('value', '1');
  837. pageCountInput.setAttribute('type', 'number');
  838. pageCountInput.setAttribute('min', '1');
  839. pageCountInput.setAttribute('size', '4');
  840. pageCountInput.setAttribute('disabled', 'disabled');
  841. pageCountInput.style.width = '50px';
  842. td = document.createElement('td');
  843. td.style.fontSize = '10pt';
  844. td.appendChild(pageCountInput);
  845. mxUtils.write(td, ' ' + mxResources.get('pages') + ' (max)');
  846. row.appendChild(td);
  847. tbody.appendChild(row);
  848. mxEvent.addListener(pageCountCheckBox, 'change', function()
  849. {
  850. if (pageCountCheckBox.checked)
  851. {
  852. pageCountInput.removeAttribute('disabled');
  853. }
  854. else
  855. {
  856. pageCountInput.setAttribute('disabled', 'disabled');
  857. }
  858. onePageCheckBox.checked = !pageCountCheckBox.checked;
  859. });
  860. row = row.cloneNode(false);
  861. td = document.createElement('td');
  862. mxUtils.write(td, mxResources.get('pageScale') + ':');
  863. row.appendChild(td);
  864. td = document.createElement('td');
  865. var pageScaleInput = document.createElement('input');
  866. pageScaleInput.setAttribute('value', '100 %');
  867. pageScaleInput.setAttribute('size', '5');
  868. pageScaleInput.style.width = '50px';
  869. td.appendChild(pageScaleInput);
  870. row.appendChild(td);
  871. tbody.appendChild(row);
  872. row = document.createElement('tr');
  873. td = document.createElement('td');
  874. td.colSpan = 2;
  875. td.style.paddingTop = '20px';
  876. td.setAttribute('align', 'right');
  877. // Overall scale for print-out to account for print borders in dialogs etc
  878. function preview(print)
  879. {
  880. var autoOrigin = onePageCheckBox.checked || pageCountCheckBox.checked;
  881. var printScale = parseInt(pageScaleInput.value) / 100;
  882. if (isNaN(printScale))
  883. {
  884. printScale = 1;
  885. pageScaleInput.value = '100%';
  886. }
  887. // Workaround to match available paper size in actual print output
  888. printScale *= 0.75;
  889. var pf = graph.pageFormat || mxConstants.PAGE_FORMAT_A4_PORTRAIT;
  890. var scale = 1 / graph.pageScale;
  891. if (autoOrigin)
  892. {
  893. var pageCount = (onePageCheckBox.checked) ? 1 : parseInt(pageCountInput.value);
  894. if (!isNaN(pageCount))
  895. {
  896. scale = mxUtils.getScaleForPageCount(pageCount, graph, pf);
  897. }
  898. }
  899. // Negative coordinates are cropped or shifted if page visible
  900. var gb = graph.getGraphBounds();
  901. var border = 0;
  902. var x0 = 0;
  903. var y0 = 0;
  904. // Applies print scale
  905. pf = mxRectangle.fromRectangle(pf);
  906. pf.width = Math.ceil(pf.width * printScale);
  907. pf.height = Math.ceil(pf.height * printScale);
  908. scale *= printScale;
  909. // Starts at first visible page
  910. if (!autoOrigin && graph.pageVisible)
  911. {
  912. var layout = graph.getPageLayout();
  913. x0 -= layout.x * pf.width;
  914. y0 -= layout.y * pf.height;
  915. }
  916. else
  917. {
  918. autoOrigin = true;
  919. }
  920. var preview = PrintDialog.createPrintPreview(graph, scale, pf, border, x0, y0, autoOrigin);
  921. preview.open();
  922. if (print)
  923. {
  924. PrintDialog.printPreview(preview);
  925. }
  926. };
  927. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  928. {
  929. editorUi.hideDialog();
  930. });
  931. cancelBtn.className = 'geBtn';
  932. if (editorUi.editor.cancelFirst)
  933. {
  934. td.appendChild(cancelBtn);
  935. }
  936. if (!mxClient.IS_CHROMEAPP)
  937. {
  938. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  939. {
  940. editorUi.hideDialog();
  941. preview(false);
  942. });
  943. previewBtn.className = 'geBtn';
  944. td.appendChild(previewBtn);
  945. }
  946. var printBtn = mxUtils.button(mxResources.get((mxClient.IS_CHROMEAPP) ? 'ok' : 'print'), function()
  947. {
  948. editorUi.hideDialog();
  949. preview(true);
  950. });
  951. printBtn.className = 'geBtn gePrimaryBtn';
  952. td.appendChild(printBtn);
  953. if (!editorUi.editor.cancelFirst)
  954. {
  955. td.appendChild(cancelBtn);
  956. }
  957. row.appendChild(td);
  958. tbody.appendChild(row);
  959. table.appendChild(tbody);
  960. this.container = table;
  961. };
  962. /**
  963. * Constructs a new print dialog.
  964. */
  965. PrintDialog.printPreview = function(preview)
  966. {
  967. if (preview.wnd != null)
  968. {
  969. var printFn = function()
  970. {
  971. preview.wnd.focus();
  972. preview.wnd.print();
  973. preview.wnd.close();
  974. };
  975. // Workaround for Google Chrome which needs a bit of a
  976. // delay in order to render the SVG contents
  977. // Needs testing in production
  978. if (mxClient.IS_GC)
  979. {
  980. window.setTimeout(printFn, 500);
  981. }
  982. else
  983. {
  984. printFn();
  985. }
  986. }
  987. };
  988. /**
  989. * Constructs a new print dialog.
  990. */
  991. PrintDialog.createPrintPreview = function(graph, scale, pf, border, x0, y0, autoOrigin)
  992. {
  993. var preview = new mxPrintPreview(graph, scale, pf, border, x0, y0);
  994. preview.title = mxResources.get('preview');
  995. preview.printBackgroundImage = true;
  996. preview.autoOrigin = autoOrigin;
  997. var bg = graph.background;
  998. if (bg == null || bg == '' || bg == mxConstants.NONE)
  999. {
  1000. bg = '#ffffff';
  1001. }
  1002. preview.backgroundColor = bg;
  1003. var writeHead = preview.writeHead;
  1004. // Adds a border in the preview
  1005. preview.writeHead = function(doc)
  1006. {
  1007. writeHead.apply(this, arguments);
  1008. doc.writeln('<style type="text/css">');
  1009. doc.writeln('@media screen {');
  1010. doc.writeln(' body > div { padding:30px;box-sizing:content-box; }');
  1011. doc.writeln('}');
  1012. doc.writeln('</style>');
  1013. };
  1014. return preview;
  1015. };
  1016. /**
  1017. * Constructs a new filename dialog.
  1018. */
  1019. var FilenameDialog = function(editorUi, filename, buttonText, fn, label, validateFn, content, helpLink, closeOnBtn)
  1020. {
  1021. closeOnBtn = (closeOnBtn != null) ? closeOnBtn : true;
  1022. var row, td;
  1023. var table = document.createElement('table');
  1024. var tbody = document.createElement('tbody');
  1025. table.style.marginTop = '8px';
  1026. row = document.createElement('tr');
  1027. td = document.createElement('td');
  1028. td.style.fontSize = '10pt';
  1029. td.style.width = '120px';
  1030. mxUtils.write(td, (label || mxResources.get('filename')) + ':');
  1031. row.appendChild(td);
  1032. var nameInput = document.createElement('input');
  1033. nameInput.setAttribute('value', filename || '');
  1034. nameInput.style.width = '180px';
  1035. var genericBtn = mxUtils.button(buttonText, function()
  1036. {
  1037. if (validateFn == null || validateFn(nameInput.value))
  1038. {
  1039. if (closeOnBtn)
  1040. {
  1041. editorUi.hideDialog();
  1042. }
  1043. fn(nameInput.value);
  1044. }
  1045. });
  1046. genericBtn.className = 'geBtn gePrimaryBtn';
  1047. this.init = function()
  1048. {
  1049. if (label == null && content != null)
  1050. {
  1051. return;
  1052. }
  1053. nameInput.focus();
  1054. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1055. {
  1056. nameInput.select();
  1057. }
  1058. else
  1059. {
  1060. document.execCommand('selectAll', false, null);
  1061. }
  1062. // Installs drag and drop handler for links
  1063. if (Graph.fileSupport)
  1064. {
  1065. // Setup the dnd listeners
  1066. var dlg = table.parentNode;
  1067. var graph = editorUi.editor.graph;
  1068. var dropElt = null;
  1069. mxEvent.addListener(dlg, 'dragleave', function(evt)
  1070. {
  1071. if (dropElt != null)
  1072. {
  1073. dropElt.style.backgroundColor = '';
  1074. dropElt = null;
  1075. }
  1076. evt.stopPropagation();
  1077. evt.preventDefault();
  1078. });
  1079. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  1080. {
  1081. // IE 10 does not implement pointer-events so it can't have a drop highlight
  1082. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  1083. {
  1084. dropElt = nameInput;
  1085. dropElt.style.backgroundColor = '#ebf2f9';
  1086. }
  1087. evt.stopPropagation();
  1088. evt.preventDefault();
  1089. }));
  1090. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  1091. {
  1092. if (dropElt != null)
  1093. {
  1094. dropElt.style.backgroundColor = '';
  1095. dropElt = null;
  1096. }
  1097. if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  1098. {
  1099. nameInput.value = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
  1100. genericBtn.click();
  1101. }
  1102. evt.stopPropagation();
  1103. evt.preventDefault();
  1104. }));
  1105. }
  1106. };
  1107. td = document.createElement('td');
  1108. td.appendChild(nameInput);
  1109. row.appendChild(td);
  1110. if (label != null || content == null)
  1111. {
  1112. tbody.appendChild(row);
  1113. }
  1114. if (content != null)
  1115. {
  1116. row = document.createElement('tr');
  1117. td = document.createElement('td');
  1118. td.colSpan = 2;
  1119. td.appendChild(content);
  1120. row.appendChild(td);
  1121. tbody.appendChild(row);
  1122. }
  1123. row = document.createElement('tr');
  1124. td = document.createElement('td');
  1125. td.colSpan = 2;
  1126. td.style.paddingTop = '20px';
  1127. td.style.whiteSpace = 'nowrap';
  1128. td.setAttribute('align', 'right');
  1129. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1130. {
  1131. editorUi.hideDialog();
  1132. });
  1133. cancelBtn.className = 'geBtn';
  1134. if (editorUi.editor.cancelFirst)
  1135. {
  1136. td.appendChild(cancelBtn);
  1137. }
  1138. if (helpLink != null)
  1139. {
  1140. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  1141. {
  1142. window.open(helpLink);
  1143. });
  1144. helpBtn.className = 'geBtn';
  1145. td.appendChild(helpBtn);
  1146. }
  1147. mxEvent.addListener(nameInput, 'keypress', function(e)
  1148. {
  1149. if (e.keyCode == 13)
  1150. {
  1151. genericBtn.click();
  1152. }
  1153. });
  1154. td.appendChild(genericBtn);
  1155. if (!editorUi.editor.cancelFirst)
  1156. {
  1157. td.appendChild(cancelBtn);
  1158. }
  1159. row.appendChild(td);
  1160. tbody.appendChild(row);
  1161. table.appendChild(tbody);
  1162. this.container = table;
  1163. };
  1164. /**
  1165. * Constructs a new textarea dialog.
  1166. */
  1167. var TextareaDialog = function(editorUi, title, url, fn, cancelFn, cancelTitle, w, h, addButtons, noHide)
  1168. {
  1169. w = (w != null) ? w : 300;
  1170. h = (h != null) ? h : 120;
  1171. noHide = (noHide != null) ? noHide : false;
  1172. var row, td;
  1173. var table = document.createElement('table');
  1174. var tbody = document.createElement('tbody');
  1175. row = document.createElement('tr');
  1176. td = document.createElement('td');
  1177. td.style.fontSize = '10pt';
  1178. td.style.width = '100px';
  1179. mxUtils.write(td, title);
  1180. row.appendChild(td);
  1181. tbody.appendChild(row);
  1182. row = document.createElement('tr');
  1183. td = document.createElement('td');
  1184. var nameInput = document.createElement('textarea');
  1185. mxUtils.write(nameInput, url || '');
  1186. nameInput.style.resize = 'none';
  1187. nameInput.style.width = w + 'px';
  1188. nameInput.style.height = h + 'px';
  1189. this.textarea = nameInput;
  1190. this.init = function()
  1191. {
  1192. nameInput.focus();
  1193. nameInput.scrollTop = 0;
  1194. };
  1195. td.appendChild(nameInput);
  1196. row.appendChild(td);
  1197. tbody.appendChild(row);
  1198. row = document.createElement('tr');
  1199. td = document.createElement('td');
  1200. td.style.paddingTop = '14px';
  1201. td.style.whiteSpace = 'nowrap';
  1202. td.setAttribute('align', 'right');
  1203. var cancelBtn = mxUtils.button(cancelTitle || mxResources.get('cancel'), function()
  1204. {
  1205. editorUi.hideDialog();
  1206. if (cancelFn != null)
  1207. {
  1208. cancelFn();
  1209. }
  1210. });
  1211. cancelBtn.className = 'geBtn';
  1212. if (editorUi.editor.cancelFirst)
  1213. {
  1214. td.appendChild(cancelBtn);
  1215. }
  1216. if (addButtons != null)
  1217. {
  1218. addButtons(td);
  1219. }
  1220. if (fn != null)
  1221. {
  1222. var genericBtn = mxUtils.button(mxResources.get('apply'), function()
  1223. {
  1224. if (!noHide)
  1225. {
  1226. editorUi.hideDialog();
  1227. }
  1228. fn(nameInput.value);
  1229. });
  1230. genericBtn.className = 'geBtn gePrimaryBtn';
  1231. td.appendChild(genericBtn);
  1232. }
  1233. if (!editorUi.editor.cancelFirst)
  1234. {
  1235. td.appendChild(cancelBtn);
  1236. }
  1237. row.appendChild(td);
  1238. tbody.appendChild(row);
  1239. table.appendChild(tbody);
  1240. this.container = table;
  1241. };
  1242. /**
  1243. * Constructs a new edit file dialog.
  1244. */
  1245. var EditDiagramDialog = function(editorUi)
  1246. {
  1247. var div = document.createElement('div');
  1248. div.style.textAlign = 'right';
  1249. var textarea = document.createElement('textarea');
  1250. textarea.setAttribute('wrap', 'off');
  1251. textarea.style.overflow = 'auto';
  1252. textarea.style.resize = 'none';
  1253. textarea.style.width = '600px';
  1254. textarea.style.height = '370px';
  1255. textarea.style.marginBottom = '16px';
  1256. textarea.value = mxUtils.getPrettyXml(editorUi.editor.getGraphXml());
  1257. div.appendChild(textarea);
  1258. this.init = function()
  1259. {
  1260. textarea.focus();
  1261. };
  1262. // Enables dropping files
  1263. if (Graph.fileSupport)
  1264. {
  1265. function handleDrop(evt)
  1266. {
  1267. evt.stopPropagation();
  1268. evt.preventDefault();
  1269. if (evt.dataTransfer.files.length > 0)
  1270. {
  1271. var file = evt.dataTransfer.files[0];
  1272. var reader = new FileReader();
  1273. reader.onload = function(e)
  1274. {
  1275. textarea.value = e.target.result;
  1276. };
  1277. reader.readAsText(file);
  1278. }
  1279. else
  1280. {
  1281. textarea.value = editorUi.extractGraphModelFromEvent(evt);
  1282. }
  1283. };
  1284. function handleDragOver(evt)
  1285. {
  1286. evt.stopPropagation();
  1287. evt.preventDefault();
  1288. };
  1289. // Setup the dnd listeners.
  1290. textarea.addEventListener('dragover', handleDragOver, false);
  1291. textarea.addEventListener('drop', handleDrop, false);
  1292. }
  1293. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1294. {
  1295. editorUi.hideDialog();
  1296. });
  1297. cancelBtn.className = 'geBtn';
  1298. if (editorUi.editor.cancelFirst)
  1299. {
  1300. div.appendChild(cancelBtn);
  1301. }
  1302. var select = document.createElement('select');
  1303. select.style.width = '180px';
  1304. select.className = 'geBtn';
  1305. if (editorUi.editor.graph.isEnabled())
  1306. {
  1307. var replaceOption = document.createElement('option');
  1308. replaceOption.setAttribute('value', 'replace');
  1309. mxUtils.write(replaceOption, mxResources.get('replaceExistingDrawing'));
  1310. select.appendChild(replaceOption);
  1311. }
  1312. var newOption = document.createElement('option');
  1313. newOption.setAttribute('value', 'new');
  1314. mxUtils.write(newOption, mxResources.get('openInNewWindow'));
  1315. var chromeApp = window.chrome != null && chrome.app != null && chrome.app.runtime != null;
  1316. if (!chromeApp)
  1317. {
  1318. select.appendChild(newOption);
  1319. }
  1320. if (editorUi.editor.graph.isEnabled())
  1321. {
  1322. var importOption = document.createElement('option');
  1323. importOption.setAttribute('value', 'import');
  1324. mxUtils.write(importOption, mxResources.get('addToExistingDrawing'));
  1325. select.appendChild(importOption);
  1326. }
  1327. div.appendChild(select);
  1328. var okBtn = mxUtils.button(mxResources.get('ok'), function()
  1329. {
  1330. // Removes all illegal control characters before parsing
  1331. var data = editorUi.editor.graph.zapGremlins(mxUtils.trim(textarea.value));
  1332. var error = null;
  1333. if (select.value == 'new')
  1334. {
  1335. window.openFile = new OpenFile(function()
  1336. {
  1337. editorUi.hideDialog();
  1338. window.openFile = null;
  1339. });
  1340. window.openFile.setData(data, null);
  1341. window.open(editorUi.getUrl());
  1342. }
  1343. else if (select.value == 'replace')
  1344. {
  1345. editorUi.editor.graph.model.beginUpdate();
  1346. try
  1347. {
  1348. editorUi.editor.setGraphXml(mxUtils.parseXml(data).documentElement);
  1349. // LATER: Why is hideDialog between begin-/endUpdate faster?
  1350. editorUi.hideDialog();
  1351. }
  1352. catch (e)
  1353. {
  1354. error = e;
  1355. }
  1356. finally
  1357. {
  1358. editorUi.editor.graph.model.endUpdate();
  1359. }
  1360. }
  1361. else if (select.value == 'import')
  1362. {
  1363. editorUi.editor.graph.model.beginUpdate();
  1364. try
  1365. {
  1366. var doc = mxUtils.parseXml(data);
  1367. var model = new mxGraphModel();
  1368. var codec = new mxCodec(doc);
  1369. codec.decode(doc.documentElement, model);
  1370. var children = model.getChildren(model.getChildAt(model.getRoot(), 0));
  1371. editorUi.editor.graph.setSelectionCells(editorUi.editor.graph.importCells(children));
  1372. // LATER: Why is hideDialog between begin-/endUpdate faster?
  1373. editorUi.hideDialog();
  1374. }
  1375. catch (e)
  1376. {
  1377. error = e;
  1378. }
  1379. finally
  1380. {
  1381. editorUi.editor.graph.model.endUpdate();
  1382. }
  1383. }
  1384. if (error != null)
  1385. {
  1386. mxUtils.alert(error.message);
  1387. }
  1388. });
  1389. okBtn.className = 'geBtn gePrimaryBtn';
  1390. div.appendChild(okBtn);
  1391. if (!editorUi.editor.cancelFirst)
  1392. {
  1393. div.appendChild(cancelBtn);
  1394. }
  1395. this.container = div;
  1396. };
  1397. /**
  1398. * Constructs a new export dialog.
  1399. */
  1400. var ExportDialog = function(editorUi)
  1401. {
  1402. var graph = editorUi.editor.graph;
  1403. var bounds = graph.getGraphBounds();
  1404. var scale = graph.view.scale;
  1405. var width = Math.ceil(bounds.width / scale);
  1406. var height = Math.ceil(bounds.height / scale);
  1407. var row, td;
  1408. var table = document.createElement('table');
  1409. var tbody = document.createElement('tbody');
  1410. row = document.createElement('tr');
  1411. td = document.createElement('td');
  1412. td.style.fontSize = '10pt';
  1413. td.style.width = '100px';
  1414. mxUtils.write(td, mxResources.get('filename') + ':');
  1415. row.appendChild(td);
  1416. var nameInput = document.createElement('input');
  1417. nameInput.setAttribute('value', editorUi.editor.getOrCreateFilename());
  1418. nameInput.style.width = '180px';
  1419. td = document.createElement('td');
  1420. td.appendChild(nameInput);
  1421. row.appendChild(td);
  1422. tbody.appendChild(row);
  1423. row = document.createElement('tr');
  1424. td = document.createElement('td');
  1425. td.style.fontSize = '10pt';
  1426. mxUtils.write(td, mxResources.get('format') + ':');
  1427. row.appendChild(td);
  1428. var imageFormatSelect = document.createElement('select');
  1429. imageFormatSelect.style.width = '180px';
  1430. var pngOption = document.createElement('option');
  1431. pngOption.setAttribute('value', 'png');
  1432. mxUtils.write(pngOption, mxResources.get('formatPng'));
  1433. imageFormatSelect.appendChild(pngOption);
  1434. var gifOption = document.createElement('option');
  1435. if (ExportDialog.showGifOption)
  1436. {
  1437. gifOption.setAttribute('value', 'gif');
  1438. mxUtils.write(gifOption, mxResources.get('formatGif'));
  1439. imageFormatSelect.appendChild(gifOption);
  1440. }
  1441. var jpgOption = document.createElement('option');
  1442. jpgOption.setAttribute('value', 'jpg');
  1443. mxUtils.write(jpgOption, mxResources.get('formatJpg'));
  1444. imageFormatSelect.appendChild(jpgOption);
  1445. var pdfOption = document.createElement('option');
  1446. pdfOption.setAttribute('value', 'pdf');
  1447. mxUtils.write(pdfOption, mxResources.get('formatPdf'));
  1448. imageFormatSelect.appendChild(pdfOption);
  1449. var svgOption = document.createElement('option');
  1450. svgOption.setAttribute('value', 'svg');
  1451. mxUtils.write(svgOption, mxResources.get('formatSvg'));
  1452. imageFormatSelect.appendChild(svgOption);
  1453. if (ExportDialog.showXmlOption)
  1454. {
  1455. var xmlOption = document.createElement('option');
  1456. xmlOption.setAttribute('value', 'xml');
  1457. mxUtils.write(xmlOption, mxResources.get('formatXml'));
  1458. imageFormatSelect.appendChild(xmlOption);
  1459. }
  1460. td = document.createElement('td');
  1461. td.appendChild(imageFormatSelect);
  1462. row.appendChild(td);
  1463. tbody.appendChild(row);
  1464. row = document.createElement('tr');
  1465. td = document.createElement('td');
  1466. td.style.fontSize = '10pt';
  1467. mxUtils.write(td, mxResources.get('backgroundColor') + ':');
  1468. row.appendChild(td);
  1469. var backgroundInput = document.createElement('input');
  1470. var tmp = (graph.background == null || graph.background == mxConstants.NONE) ? '#ffffff' : graph.background;
  1471. backgroundInput.setAttribute('value', tmp);
  1472. backgroundInput.style.width = '80px';
  1473. var backgroundCheckbox = document.createElement('input');
  1474. backgroundCheckbox.setAttribute('type', 'checkbox');
  1475. backgroundCheckbox.checked = graph.background == null || graph.background == mxConstants.NONE;
  1476. td = document.createElement('td');
  1477. td.appendChild(backgroundInput);
  1478. td.appendChild(backgroundCheckbox);
  1479. mxUtils.write(td, mxResources.get('transparent'));
  1480. row.appendChild(td);
  1481. tbody.appendChild(row);
  1482. row = document.createElement('tr');
  1483. td = document.createElement('td');
  1484. td.style.fontSize = '10pt';
  1485. mxUtils.write(td, mxResources.get('width') + ':');
  1486. row.appendChild(td);
  1487. var widthInput = document.createElement('input');
  1488. widthInput.setAttribute('value', width);
  1489. widthInput.style.width = '180px';
  1490. td = document.createElement('td');
  1491. td.appendChild(widthInput);
  1492. row.appendChild(td);
  1493. tbody.appendChild(row);
  1494. row = document.createElement('tr');
  1495. td = document.createElement('td');
  1496. td.style.fontSize = '10pt';
  1497. mxUtils.write(td, mxResources.get('height') + ':');
  1498. row.appendChild(td);
  1499. var heightInput = document.createElement('input');
  1500. heightInput.setAttribute('value', height);
  1501. heightInput.style.width = '180px';
  1502. td = document.createElement('td');
  1503. td.appendChild(heightInput);
  1504. row.appendChild(td);
  1505. tbody.appendChild(row);
  1506. row = document.createElement('tr');
  1507. td = document.createElement('td');
  1508. td.style.fontSize = '10pt';
  1509. mxUtils.write(td, mxResources.get('borderWidth') + ':');
  1510. row.appendChild(td);
  1511. var borderInput = document.createElement('input');
  1512. borderInput.setAttribute('value', width);
  1513. borderInput.style.width = '180px';
  1514. borderInput.value = '0';
  1515. td = document.createElement('td');
  1516. td.appendChild(borderInput);
  1517. row.appendChild(td);
  1518. tbody.appendChild(row);
  1519. table.appendChild(tbody);
  1520. // Handles changes in the export format
  1521. function formatChanged()
  1522. {
  1523. var name = nameInput.value;
  1524. var dot = name.lastIndexOf('.');
  1525. if (dot > 0)
  1526. {
  1527. nameInput.value = name.substring(0, dot + 1) + imageFormatSelect.value;
  1528. }
  1529. else
  1530. {
  1531. nameInput.value = name + '.' + imageFormatSelect.value;
  1532. }
  1533. if (imageFormatSelect.value === 'xml')
  1534. {
  1535. widthInput.setAttribute('disabled', 'true');
  1536. heightInput.setAttribute('disabled', 'true');
  1537. borderInput.setAttribute('disabled', 'true');
  1538. }
  1539. else
  1540. {
  1541. widthInput.removeAttribute('disabled');
  1542. heightInput.removeAttribute('disabled');
  1543. borderInput.removeAttribute('disabled');
  1544. }
  1545. if (imageFormatSelect.value === 'png' || imageFormatSelect.value === 'svg')
  1546. {
  1547. backgroundCheckbox.removeAttribute('disabled');
  1548. }
  1549. else
  1550. {
  1551. backgroundCheckbox.setAttribute('disabled', 'disabled');
  1552. }
  1553. };
  1554. mxEvent.addListener(imageFormatSelect, 'change', formatChanged);
  1555. formatChanged();
  1556. function checkValues()
  1557. {
  1558. if (widthInput.value * heightInput.value > MAX_AREA || widthInput.value <= 0)
  1559. {
  1560. widthInput.style.backgroundColor = 'red';
  1561. }
  1562. else
  1563. {
  1564. widthInput.style.backgroundColor = '';
  1565. }
  1566. if (widthInput.value * heightInput.value > MAX_AREA || heightInput.value <= 0)
  1567. {
  1568. heightInput.style.backgroundColor = 'red';
  1569. }
  1570. else
  1571. {
  1572. heightInput.style.backgroundColor = '';
  1573. }
  1574. };
  1575. mxEvent.addListener(widthInput, 'change', function()
  1576. {
  1577. if (width > 0)
  1578. {
  1579. heightInput.value = Math.ceil(parseInt(widthInput.value) * height / width);
  1580. }
  1581. else
  1582. {
  1583. heightInput.value = '0';
  1584. }
  1585. checkValues();
  1586. });
  1587. mxEvent.addListener(heightInput, 'change', function()
  1588. {
  1589. if (height > 0)
  1590. {
  1591. widthInput.value = Math.ceil(parseInt(heightInput.value) * width / height);
  1592. }
  1593. else
  1594. {
  1595. widthInput.value = '0';
  1596. }
  1597. checkValues();
  1598. });
  1599. // Resuable image export instance
  1600. var imgExport = new mxImageExport();
  1601. function getSvg()
  1602. {
  1603. var b = Math.max(0, parseInt(borderInput.value)) + 1;
  1604. var scale = parseInt(widthInput.value) / width;
  1605. var bg = null;
  1606. if (backgroundInput.value != '' && backgroundInput.value != mxConstants.NONE && !backgroundCheckbox.checked)
  1607. {
  1608. bg = backgroundInput.value;
  1609. }
  1610. return graph.getSvg(bg, scale, b);
  1611. };
  1612. function getXml()
  1613. {
  1614. return mxUtils.getXml(editorUi.editor.getGraphXml());
  1615. };
  1616. row = document.createElement('tr');
  1617. td = document.createElement('td');
  1618. td.setAttribute('align', 'right');
  1619. td.style.paddingTop = '24px';
  1620. td.colSpan = 2;
  1621. var saveBtn = mxUtils.button(mxResources.get('export'), mxUtils.bind(this, function()
  1622. {
  1623. if (parseInt(widthInput.value) <= 0 && parseInt(heightInput.value) <= 0)
  1624. {
  1625. mxUtils.alert(mxResources.get('drawingEmpty'));
  1626. }
  1627. else
  1628. {
  1629. var format = imageFormatSelect.value;
  1630. var name = nameInput.value;
  1631. if (format == 'xml')
  1632. {
  1633. editorUi.hideDialog();
  1634. ExportDialog.saveLocalFile(getXml(), name, format);
  1635. }
  1636. else if (format == 'svg')
  1637. {
  1638. var xml = mxUtils.getXml(getSvg());
  1639. if (xml.length < MAX_REQUEST_SIZE)
  1640. {
  1641. editorUi.hideDialog();
  1642. ExportDialog.saveLocalFile(xml, name, format);
  1643. }
  1644. else
  1645. {
  1646. mxUtils.alert(mxResources.get('drawingTooLarge'));
  1647. mxUtils.popup(xml);
  1648. }
  1649. }
  1650. else
  1651. {
  1652. var param = null;
  1653. var w = parseInt(widthInput.value) || 0;
  1654. var h = parseInt(heightInput.value) || 0;
  1655. var b = Math.max(0, parseInt(borderInput.value)) + 1;
  1656. var exp = ExportDialog.getExportParameter(editorUi, format);
  1657. if (typeof exp == 'function')
  1658. {
  1659. param = exp();
  1660. }
  1661. else
  1662. {
  1663. var scale = parseInt(widthInput.value) / width;
  1664. var bounds = graph.getGraphBounds();
  1665. var vs = graph.view.scale;
  1666. // New image export
  1667. var xmlDoc = mxUtils.createXmlDocument();
  1668. var root = xmlDoc.createElement('output');
  1669. xmlDoc.appendChild(root);
  1670. // Renders graph. Offset will be multiplied with state's scale when painting state.
  1671. var xmlCanvas = new mxXmlCanvas2D(root);
  1672. xmlCanvas.translate(Math.floor((b / scale - bounds.x) / vs), Math.floor((b / scale - bounds.y) / vs));
  1673. xmlCanvas.scale(scale / vs);
  1674. imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
  1675. // Puts request data together
  1676. w = Math.ceil(bounds.width * scale / vs + 2 * b);
  1677. h = Math.ceil(bounds.height * scale / vs + 2 * b);
  1678. param = 'xml=' + encodeURIComponent(mxUtils.getXml(root));
  1679. }
  1680. // Requests image if request is valid
  1681. if (param != null && param.length <= MAX_REQUEST_SIZE && w * h < MAX_AREA)
  1682. {
  1683. var bg = '&bg=none';
  1684. if (backgroundInput.value != '' && backgroundInput.value != mxConstants.NONE &&
  1685. (format != 'png' || !backgroundCheckbox.checked))
  1686. {
  1687. bg = '&bg=' + backgroundInput.value;
  1688. }
  1689. editorUi.hideDialog();
  1690. var data = decodeURIComponent(param.substring(param.indexOf('=') + 1));
  1691. ExportDialog.saveRequest(data, name, format,
  1692. function(newTitle, base64)
  1693. {
  1694. // Base64 not used in this example
  1695. return new mxXmlRequest(EXPORT_URL, 'format=' + format + '&base64=' + (base64 || '0') +
  1696. ((newTitle != null) ? '&filename=' + encodeURIComponent(newTitle) : '') +
  1697. bg + '&w=' + w + '&h=' + h + '&border=' + b + '&' + param);
  1698. });
  1699. }
  1700. else
  1701. {
  1702. mxUtils.alert(mxResources.get('drawingTooLarge'));
  1703. }
  1704. }
  1705. }
  1706. }));
  1707. saveBtn.className = 'geBtn gePrimaryBtn';
  1708. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1709. {
  1710. editorUi.hideDialog();
  1711. });
  1712. cancelBtn.className = 'geBtn';
  1713. if (editorUi.editor.cancelFirst)
  1714. {
  1715. td.appendChild(cancelBtn);
  1716. td.appendChild(saveBtn);
  1717. }
  1718. else
  1719. {
  1720. td.appendChild(saveBtn);
  1721. td.appendChild(cancelBtn);
  1722. }
  1723. row.appendChild(td);
  1724. tbody.appendChild(row);
  1725. table.appendChild(tbody);
  1726. this.container = table;
  1727. };
  1728. /**
  1729. * Global switches for the export dialog.
  1730. */
  1731. ExportDialog.showGifOption = true;
  1732. /**
  1733. * Global switches for the export dialog.
  1734. */
  1735. ExportDialog.showXmlOption = true;
  1736. /**
  1737. * Hook for getting the export format. Returns null for the default
  1738. * intermediate XML export format or a function that returns the
  1739. * parameter and value to be used in the request in the form
  1740. * key=value, where value should be URL encoded.
  1741. */
  1742. ExportDialog.saveLocalFile = function(data, filename, format)
  1743. {
  1744. new mxXmlRequest(SAVE_URL, 'xml=' + encodeURIComponent(data) + '&filename=' +
  1745. encodeURIComponent(filename) + '&format=' + format).simulate(document, '_blank');
  1746. };
  1747. /**
  1748. * Hook for getting the export format. Returns null for the default
  1749. * intermediate XML export format or a function that returns the
  1750. * parameter and value to be used in the request in the form
  1751. * key=value, where value should be URL encoded.
  1752. */
  1753. ExportDialog.saveRequest = function(data, filename, format, fn)
  1754. {
  1755. fn(filename).simulate(document, '_blank');
  1756. };
  1757. /**
  1758. * Hook for getting the export format. Returns null for the default
  1759. * intermediate XML export format or a function that returns the
  1760. * parameter and value to be used in the request in the form
  1761. * key=value, where value should be URL encoded.
  1762. */
  1763. ExportDialog.getExportParameter = function(ui, format)
  1764. {
  1765. return null;
  1766. };
  1767. /**
  1768. * Constructs a new metadata dialog.
  1769. */
  1770. var EditDataDialog = function(ui, cell)
  1771. {
  1772. var div = document.createElement('div');
  1773. var graph = ui.editor.graph;
  1774. div.style.height = '310px';
  1775. div.style.overflow = 'auto';
  1776. var value = graph.getModel().getValue(cell);
  1777. // Converts the value to an XML node
  1778. if (!mxUtils.isNode(value))
  1779. {
  1780. var doc = mxUtils.createXmlDocument();
  1781. var obj = doc.createElement('object');
  1782. obj.setAttribute('label', value || '');
  1783. value = obj;
  1784. }
  1785. // Creates the dialog contents
  1786. var form = new mxForm('properties');
  1787. form.table.style.width = '100%';
  1788. form.table.style.paddingRight = '20px';
  1789. var attrs = value.attributes;
  1790. var names = [];
  1791. var texts = [];
  1792. var count = 0;
  1793. // FIXME: Fix remove button for quirks mode
  1794. var addRemoveButton = function(text, name)
  1795. {
  1796. text.parentNode.style.marginRight = '12px';
  1797. var removeAttr = document.createElement('a');
  1798. var img = mxUtils.createImage(Dialog.prototype.closeImage);
  1799. img.style.height = '9px';
  1800. img.style.fontSize = '9px';
  1801. img.style.marginBottom = '7px';
  1802. removeAttr.className = 'geButton';
  1803. removeAttr.setAttribute('title', mxResources.get('delete'));
  1804. removeAttr.style.margin = '0px';
  1805. removeAttr.style.width = '14px';
  1806. removeAttr.style.height = '14px';
  1807. removeAttr.style.fontSize = '14px';
  1808. removeAttr.style.cursor = 'pointer';
  1809. removeAttr.style.marginLeft = '6px';
  1810. removeAttr.appendChild(img);
  1811. var removeAttrFn = (function(name)
  1812. {
  1813. return function()
  1814. {
  1815. var count = 0;
  1816. for (var j = 0; j < names.length; j++)
  1817. {
  1818. if (names[j] == name)
  1819. {
  1820. texts[j] = null;
  1821. form.table.deleteRow(count);
  1822. break;
  1823. }
  1824. if (texts[j] != null)
  1825. {
  1826. count++;
  1827. }
  1828. }
  1829. };
  1830. })(name);
  1831. mxEvent.addListener(removeAttr, 'click', removeAttrFn);
  1832. text.parentNode.style.whiteSpace = 'nowrap';
  1833. text.parentNode.appendChild(removeAttr);
  1834. };
  1835. var addTextArea = function(index, name, value)
  1836. {
  1837. names[index] = name;
  1838. texts[index] = form.addTextarea(names[count] + ':', value, 2);
  1839. texts[index].style.width = '100%';
  1840. addRemoveButton(texts[index], name);
  1841. };
  1842. for (var i = 0; i < attrs.length; i++)
  1843. {
  1844. if (attrs[i].nodeName != 'label' && attrs[i].nodeName != 'placeholders')
  1845. {
  1846. addTextArea(count, attrs[i].nodeName, attrs[i].nodeValue);
  1847. count++;
  1848. }
  1849. }
  1850. div.appendChild(form.table);
  1851. var newProp = document.createElement('div');
  1852. newProp.style.whiteSpace = 'nowrap';
  1853. newProp.style.marginTop = '6px';
  1854. var nameInput = document.createElement('input');
  1855. nameInput.setAttribute('placeholder', mxResources.get('enterPropertyName'));
  1856. nameInput.setAttribute('type', 'text');
  1857. nameInput.setAttribute('size', (mxClient.IS_QUIRKS) ? '18' : '22');
  1858. nameInput.style.marginLeft = '2px';
  1859. newProp.appendChild(nameInput);
  1860. div.appendChild(newProp);
  1861. var addBtn = mxUtils.button(mxResources.get('addProperty'), function()
  1862. {
  1863. if (nameInput.value.length > 0)
  1864. {
  1865. var name = nameInput.value;
  1866. if (name != null && name.length > 0 && name != 'label' && name != 'placeholders')
  1867. {
  1868. try
  1869. {
  1870. var idx = mxUtils.indexOf(names, name);
  1871. if (idx >= 0 && texts[idx] != null)
  1872. {
  1873. texts[idx].focus();
  1874. }
  1875. else
  1876. {
  1877. // Checks if the name is valid
  1878. var clone = value.cloneNode(false);
  1879. clone.setAttribute(name, '');
  1880. if (idx >= 0)
  1881. {
  1882. names.splice(idx, 1);
  1883. texts.splice(idx, 1);
  1884. }
  1885. names.push(name);
  1886. var text = form.addTextarea(name + ':', '', 2);
  1887. text.style.width = '100%';
  1888. texts.push(text);
  1889. addRemoveButton(text, name);
  1890. text.focus();
  1891. }
  1892. nameInput.value = '';
  1893. }
  1894. catch (e)
  1895. {
  1896. mxUtils.alert(e);
  1897. }
  1898. }
  1899. }
  1900. else
  1901. {
  1902. mxUtils.alert(mxResources.get('invalidName'));
  1903. }
  1904. });
  1905. this.init = function()
  1906. {
  1907. if (texts.length > 0)
  1908. {
  1909. texts[0].focus();
  1910. }
  1911. else
  1912. {
  1913. nameInput.focus();
  1914. }
  1915. };
  1916. addBtn.setAttribute('disabled', 'disabled');
  1917. addBtn.style.marginLeft = '10px';
  1918. addBtn.style.width = '144px';
  1919. newProp.appendChild(addBtn);
  1920. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1921. {
  1922. ui.hideDialog.apply(ui, arguments);
  1923. });
  1924. cancelBtn.className = 'geBtn';
  1925. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  1926. {
  1927. try
  1928. {
  1929. ui.hideDialog.apply(ui, arguments);
  1930. // Clones and updates the value
  1931. value = value.cloneNode(true);
  1932. for (var i = 0; i < names.length; i++)
  1933. {
  1934. if (texts[i] == null)
  1935. {
  1936. value.removeAttribute(names[i]);
  1937. }
  1938. else
  1939. {
  1940. value.setAttribute(names[i], texts[i].value);
  1941. }
  1942. }
  1943. // Updates the value of the cell (undoable)
  1944. graph.getModel().setValue(cell, value);
  1945. }
  1946. catch (e)
  1947. {
  1948. mxUtils.alert(e);
  1949. }
  1950. });
  1951. applyBtn.className = 'geBtn gePrimaryBtn';
  1952. function updateAddBtn()
  1953. {
  1954. if (nameInput.value.length > 0)
  1955. {
  1956. addBtn.removeAttribute('disabled');
  1957. }
  1958. else
  1959. {
  1960. addBtn.setAttribute('disabled', 'disabled');
  1961. }
  1962. };
  1963. mxEvent.addListener(nameInput, 'keyup', updateAddBtn);
  1964. // Catches all changes that don't fire a keyup (such as paste via mouse)
  1965. mxEvent.addListener(nameInput, 'change', updateAddBtn);
  1966. var buttons = document.createElement('div');
  1967. buttons.style.marginTop = '18px';
  1968. buttons.style.textAlign = 'right';
  1969. if (ui.editor.graph.getModel().isVertex(cell) || ui.editor.graph.getModel().isEdge(cell))
  1970. {
  1971. var replace = document.createElement('span');
  1972. replace.style.marginRight = '10px';
  1973. var input = document.createElement('input');
  1974. input.setAttribute('type', 'checkbox');
  1975. input.style.marginRight = '6px';
  1976. if (value.getAttribute('placeholders') == '1')
  1977. {
  1978. input.setAttribute('checked', 'checked');
  1979. input.defaultChecked = true;
  1980. }
  1981. mxEvent.addListener(input, 'click', function()
  1982. {
  1983. if (value.getAttribute('placeholders') == '1')
  1984. {
  1985. value.removeAttribute('placeholders');
  1986. }
  1987. else
  1988. {
  1989. value.setAttribute('placeholders', '1');
  1990. }
  1991. });
  1992. replace.appendChild(input);
  1993. mxUtils.write(replace, mxResources.get('placeholders'));
  1994. if (EditDataDialog.placeholderHelpLink != null)
  1995. {
  1996. var link = document.createElement('a');
  1997. link.setAttribute('href', EditDataDialog.placeholderHelpLink);
  1998. link.setAttribute('title', mxResources.get('help'));
  1999. link.setAttribute('target', '_blank');
  2000. link.style.marginLeft = '10px';
  2001. link.style.cursor = 'help';
  2002. var icon = document.createElement('img');
  2003. icon.setAttribute('border', '0');
  2004. icon.setAttribute('valign', 'middle');
  2005. icon.style.marginTop = '-4px';
  2006. icon.setAttribute('src', Editor.helpImage);
  2007. link.appendChild(icon);
  2008. replace.appendChild(link);
  2009. }
  2010. buttons.appendChild(replace);
  2011. }
  2012. if (ui.editor.cancelFirst)
  2013. {
  2014. buttons.appendChild(cancelBtn);
  2015. buttons.appendChild(applyBtn);
  2016. }
  2017. else
  2018. {
  2019. buttons.appendChild(applyBtn);
  2020. buttons.appendChild(cancelBtn);
  2021. }
  2022. div.appendChild(buttons);
  2023. this.container = div;
  2024. };
  2025. /**
  2026. * Optional help link.
  2027. */
  2028. EditDataDialog.placeholderHelpLink = null;
  2029. /**
  2030. * Constructs a new link dialog.
  2031. */
  2032. var LinkDialog = function(editorUi, initialValue, btnLabel, fn)
  2033. {
  2034. var div = document.createElement('div');
  2035. mxUtils.write(div, mxResources.get('editLink') + ':');
  2036. var inner = document.createElement('div');
  2037. inner.className = 'geTitle';
  2038. inner.style.backgroundColor = 'transparent';
  2039. inner.style.borderColor = 'transparent';
  2040. inner.style.whiteSpace = 'nowrap';
  2041. inner.style.textOverflow = 'clip';
  2042. inner.style.cursor = 'default';
  2043. if (!mxClient.IS_VML)
  2044. {
  2045. inner.style.paddingRight = '20px';
  2046. }
  2047. var linkInput = document.createElement('input');
  2048. linkInput.setAttribute('value', initialValue);
  2049. linkInput.setAttribute('placeholder', 'http://www.example.com/');
  2050. linkInput.setAttribute('type', 'text');
  2051. linkInput.style.marginTop = '6px';
  2052. linkInput.style.width = '400px';
  2053. linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
  2054. linkInput.style.backgroundRepeat = 'no-repeat';
  2055. linkInput.style.backgroundPosition = '100% 50%';
  2056. linkInput.style.paddingRight = '14px';
  2057. var cross = document.createElement('div');
  2058. cross.setAttribute('title', mxResources.get('reset'));
  2059. cross.style.position = 'relative';
  2060. cross.style.left = '-16px';
  2061. cross.style.width = '12px';
  2062. cross.style.height = '14px';
  2063. cross.style.cursor = 'pointer';
  2064. // Workaround for inline-block not supported in IE
  2065. cross.style.display = (mxClient.IS_VML) ? 'inline' : 'inline-block';
  2066. cross.style.top = ((mxClient.IS_VML) ? 0 : 3) + 'px';
  2067. // Needed to block event transparency in IE
  2068. cross.style.background = 'url(' + IMAGE_PATH + '/transparent.gif)';
  2069. mxEvent.addListener(cross, 'click', function()
  2070. {
  2071. linkInput.value = '';
  2072. linkInput.focus();
  2073. });
  2074. inner.appendChild(linkInput);
  2075. inner.appendChild(cross);
  2076. div.appendChild(inner);
  2077. this.init = function()
  2078. {
  2079. linkInput.focus();
  2080. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  2081. {
  2082. linkInput.select();
  2083. }
  2084. else
  2085. {
  2086. document.execCommand('selectAll', false, null);
  2087. }
  2088. };
  2089. var btns = document.createElement('div');
  2090. btns.style.marginTop = '18px';
  2091. btns.style.textAlign = 'right';
  2092. mxEvent.addListener(linkInput, 'keypress', function(e)
  2093. {
  2094. if (e.keyCode == 13)
  2095. {
  2096. editorUi.hideDialog();
  2097. fn(linkInput.value);
  2098. }
  2099. });
  2100. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  2101. {
  2102. editorUi.hideDialog();
  2103. });
  2104. cancelBtn.className = 'geBtn';
  2105. if (editorUi.editor.cancelFirst)
  2106. {
  2107. btns.appendChild(cancelBtn);
  2108. }
  2109. var mainBtn = mxUtils.button(btnLabel, function()
  2110. {
  2111. editorUi.hideDialog();
  2112. fn(linkInput.value);
  2113. });
  2114. mainBtn.className = 'geBtn gePrimaryBtn';
  2115. btns.appendChild(mainBtn);
  2116. if (!editorUi.editor.cancelFirst)
  2117. {
  2118. btns.appendChild(cancelBtn);
  2119. }
  2120. div.appendChild(btns);
  2121. this.container = div;
  2122. };
  2123. /**
  2124. *
  2125. */
  2126. var OutlineWindow = function(editorUi, x, y, w, h)
  2127. {
  2128. var graph = editorUi.editor.graph;
  2129. var div = document.createElement('div');
  2130. div.style.position = 'absolute';
  2131. div.style.width = '100%';
  2132. div.style.height = '100%';
  2133. div.style.border = '1px solid whiteSmoke';
  2134. div.style.overflow = 'hidden';
  2135. this.window = new mxWindow(mxResources.get('outline'), div, x, y, w, h, true, true);
  2136. this.window.destroyOnClose = false;
  2137. this.window.setMaximizable(false);
  2138. this.window.setResizable(true);
  2139. this.window.setClosable(true);
  2140. this.window.setVisible(true);
  2141. this.window.setLocation = function(x, y)
  2142. {
  2143. x = Math.max(0, x);
  2144. y = Math.max(0, y);
  2145. mxWindow.prototype.setLocation.apply(this, arguments);
  2146. };
  2147. mxEvent.addListener(window, 'resize', mxUtils.bind(this, function()
  2148. {
  2149. var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  2150. var ih = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  2151. var x = this.window.getX();
  2152. var y = this.window.getY();
  2153. if (x + this.window.table.clientWidth > iw)
  2154. {
  2155. x = Math.max(0, iw - this.window.table.clientWidth);
  2156. }
  2157. if (y + this.window.table.clientHeight > ih)
  2158. {
  2159. y = Math.max(0, ih - this.window.table.clientHeight);
  2160. }
  2161. if (this.window.getX() != x || this.window.getY() != y)
  2162. {
  2163. this.window.setLocation(x, y);
  2164. }
  2165. }));
  2166. var outline = editorUi.createOutline(this.window);
  2167. this.window.addListener(mxEvent.RESIZE, mxUtils.bind(this, function()
  2168. {
  2169. outline.update(false);
  2170. outline.outline.sizeDidChange();
  2171. }));
  2172. this.window.addListener(mxEvent.SHOW, mxUtils.bind(this, function()
  2173. {
  2174. outline.suspended = false;
  2175. outline.outline.refresh();
  2176. outline.update();
  2177. }));
  2178. this.window.addListener(mxEvent.HIDE, mxUtils.bind(this, function()
  2179. {
  2180. outline.suspended = true;
  2181. }));
  2182. this.window.addListener(mxEvent.NORMALIZE, mxUtils.bind(this, function()
  2183. {
  2184. outline.suspended = false;
  2185. outline.update();
  2186. }));
  2187. this.window.addListener(mxEvent.MINIMIZE, mxUtils.bind(this, function()
  2188. {
  2189. outline.suspended = true;
  2190. }));
  2191. var outlineCreateGraph = outline.createGraph;
  2192. outline.createGraph = function(container)
  2193. {
  2194. var g = outlineCreateGraph.apply(this, arguments);
  2195. g.gridEnabled = false;
  2196. g.pageScale = graph.pageScale;
  2197. g.pageFormat = graph.pageFormat;
  2198. g.background = graph.background;
  2199. g.pageVisible = graph.pageVisible;
  2200. var current = mxUtils.getCurrentStyle(graph.container);
  2201. div.style.backgroundColor = current.backgroundColor;
  2202. return g;
  2203. };
  2204. function update()
  2205. {
  2206. outline.outline.pageScale = graph.pageScale;
  2207. outline.outline.pageFormat = graph.pageFormat;
  2208. outline.outline.pageVisible = graph.pageVisible;
  2209. outline.outline.background = graph.background;
  2210. var current = mxUtils.getCurrentStyle(graph.container);
  2211. div.style.backgroundColor = current.backgroundColor;
  2212. if (graph.view.backgroundPageShape != null && outline.outline.view.backgroundPageShape != null)
  2213. {
  2214. outline.outline.view.backgroundPageShape.fill = graph.view.backgroundPageShape.fill;
  2215. }
  2216. outline.outline.refresh();
  2217. };
  2218. outline.init(div);
  2219. editorUi.editor.addListener('resetGraphView', update);
  2220. editorUi.addListener('pageFormatChanged', update);
  2221. editorUi.addListener('backgroundColorChanged', update);
  2222. editorUi.addListener('backgroundImageChanged', update);
  2223. editorUi.addListener('pageViewChanged', function()
  2224. {
  2225. update();
  2226. outline.update(true);
  2227. });
  2228. if (outline.outline.dialect == mxConstants.DIALECT_SVG)
  2229. {
  2230. var zoomInAction = editorUi.actions.get('zoomIn');
  2231. var zoomOutAction = editorUi.actions.get('zoomOut');
  2232. mxEvent.addMouseWheelListener(function(evt, up)
  2233. {
  2234. var outlineWheel = false;
  2235. var source = mxEvent.getSource(evt);
  2236. while (source != null)
  2237. {
  2238. if (source == outline.outline.view.canvas.ownerSVGElement)
  2239. {
  2240. outlineWheel = true;
  2241. break;
  2242. }
  2243. source = source.parentNode;
  2244. }
  2245. if (outlineWheel)
  2246. {
  2247. if (up)
  2248. {
  2249. zoomInAction.funct();
  2250. }
  2251. else
  2252. {
  2253. zoomOutAction.funct();
  2254. }
  2255. mxEvent.consume(evt);
  2256. }
  2257. });
  2258. }
  2259. };
  2260. /**
  2261. *
  2262. */
  2263. var LayersWindow = function(editorUi, x, y, w, h)
  2264. {
  2265. var graph = editorUi.editor.graph;
  2266. var div = document.createElement('div');
  2267. div.style.userSelect = 'none';
  2268. div.style.background = 'whiteSmoke';
  2269. div.style.border = '1px solid whiteSmoke';
  2270. div.style.height = '100%';
  2271. div.style.marginBottom = '10px';
  2272. div.style.overflow = 'auto';
  2273. var tbarHeight = (!EditorUi.compactUi) ? '30px' : '26px';
  2274. var listDiv = document.createElement('div')
  2275. listDiv.style.backgroundColor = '#e5e5e5';
  2276. listDiv.style.position = 'absolute';
  2277. listDiv.style.overflow = 'auto';
  2278. listDiv.style.left = '0px';
  2279. listDiv.style.right = '0px';
  2280. listDiv.style.top = '0px';
  2281. listDiv.style.bottom = tbarHeight;
  2282. div.appendChild(listDiv);
  2283. var dragSource = null;
  2284. var dropIndex = null;
  2285. mxEvent.addListener(div, 'dragover', function(evt)
  2286. {
  2287. evt.dataTransfer.dropEffect = 'move';
  2288. dropIndex = null;
  2289. evt.stopPropagation();
  2290. evt.preventDefault();
  2291. });
  2292. var layerCount = null;
  2293. var selectionLayer = null;
  2294. var ldiv = document.createElement('div');
  2295. ldiv.className = 'geToolbarContainer';
  2296. ldiv.style.position = 'absolute';
  2297. ldiv.style.bottom = '0px';
  2298. ldiv.style.left = '0px';
  2299. ldiv.style.right = '0px';
  2300. ldiv.style.height = tbarHeight;
  2301. ldiv.style.overflow = 'hidden';
  2302. ldiv.style.padding = (!EditorUi.compactUi) ? '1px' : '4px 0px 3px 0px';
  2303. ldiv.style.backgroundColor = 'whiteSmoke';
  2304. ldiv.style.borderWidth = '1px 0px 0px 0px';
  2305. ldiv.style.borderColor = '#c3c3c3';
  2306. ldiv.style.borderStyle = 'solid';
  2307. ldiv.style.display = 'block';
  2308. ldiv.style.whiteSpace = 'nowrap';
  2309. if (mxClient.IS_QUIRKS)
  2310. {
  2311. ldiv.style.filter = 'none';
  2312. }
  2313. var link = document.createElement('a');
  2314. link.className = 'geButton';
  2315. if (mxClient.IS_QUIRKS)
  2316. {
  2317. link.style.filter = 'none';
  2318. }
  2319. var removeLink = link.cloneNode();
  2320. removeLink.innerHTML = '<div class="geSprite geSprite-delete" style="display:inline-block;"></div>';
  2321. mxEvent.addListener(removeLink, 'click', function(evt)
  2322. {
  2323. if (graph.isEnabled())
  2324. {
  2325. graph.model.beginUpdate();
  2326. try
  2327. {
  2328. var index = graph.model.root.getIndex(selectionLayer);
  2329. graph.removeCells([selectionLayer], false);
  2330. // Creates default layer if no layer exists
  2331. if (graph.model.getChildCount(graph.model.root) == 0)
  2332. {
  2333. graph.model.add(graph.model.root, new mxCell());
  2334. graph.setDefaultParent(null);
  2335. }
  2336. else if (index > 0 && index <= graph.model.getChildCount(graph.model.root))
  2337. {
  2338. graph.setDefaultParent(graph.model.getChildAt(graph.model.root, index - 1));
  2339. }
  2340. else
  2341. {
  2342. graph.setDefaultParent(null);
  2343. }
  2344. }
  2345. finally
  2346. {
  2347. graph.model.endUpdate();
  2348. }
  2349. }
  2350. mxEvent.consume(evt);
  2351. });
  2352. if (!graph.isEnabled())
  2353. {
  2354. removeLink.className = 'geButton mxDisabled';
  2355. }
  2356. ldiv.appendChild(removeLink);
  2357. var insertLink = link.cloneNode();
  2358. insertLink.innerHTML = '<div class="geSprite geSprite-insert" style="display:inline-block;"></div>';
  2359. mxEvent.addListener(insertLink, 'click', function(evt)
  2360. {
  2361. if (graph.isEnabled() && !graph.isSelectionEmpty())
  2362. {
  2363. graph.moveCells(graph.getSelectionCells(), 0, 0, false, selectionLayer);
  2364. }
  2365. });
  2366. ldiv.appendChild(insertLink);
  2367. var renameLink = link.cloneNode();
  2368. renameLink.innerHTML = '<div class="geSprite geSprite-dots" style="display:inline-block;"></div>';
  2369. renameLink.setAttribute('title', mxResources.get('rename'));
  2370. function renameLayer(layer)
  2371. {
  2372. if (graph.isEnabled() && layer != null)
  2373. {
  2374. var dlg = new FilenameDialog(editorUi, layer.value || mxResources.get('background'), mxResources.get('rename'), mxUtils.bind(this, function(newValue)
  2375. {
  2376. if (newValue != null)
  2377. {
  2378. graph.getModel().setValue(layer, newValue);
  2379. }
  2380. }), mxResources.get('enterName'));
  2381. editorUi.showDialog(dlg.container, 300, 100, true, true);
  2382. dlg.init();
  2383. }
  2384. };
  2385. mxEvent.addListener(renameLink, 'click', function(evt)
  2386. {
  2387. if (graph.isEnabled())
  2388. {
  2389. renameLayer(selectionLayer);
  2390. }
  2391. mxEvent.consume(evt);
  2392. });
  2393. if (!graph.isEnabled())
  2394. {
  2395. renameLink.className = 'geButton mxDisabled';
  2396. }
  2397. ldiv.appendChild(renameLink);
  2398. var duplicateLink = link.cloneNode();
  2399. duplicateLink.innerHTML = '<div class="geSprite geSprite-duplicate" style="display:inline-block;"></div>';
  2400. mxEvent.addListener(duplicateLink, 'click', function(evt)
  2401. {
  2402. if (graph.isEnabled())
  2403. {
  2404. var newCell = null;
  2405. graph.model.beginUpdate();
  2406. try
  2407. {
  2408. newCell = graph.cloneCells([selectionLayer])[0];
  2409. newCell.value = mxResources.get('untitledLayer');
  2410. newCell.setVisible(true);
  2411. newCell = graph.addCell(newCell, graph.model.root);
  2412. graph.setDefaultParent(newCell);
  2413. }
  2414. finally
  2415. {
  2416. graph.model.endUpdate();
  2417. }
  2418. if (newCell != null && !graph.isCellLocked(newCell))
  2419. {
  2420. graph.selectAll(newCell);
  2421. }
  2422. }
  2423. });
  2424. if (!graph.isEnabled())
  2425. {
  2426. duplicateLink.className = 'geButton mxDisabled';
  2427. }
  2428. ldiv.appendChild(duplicateLink);
  2429. var addLink = link.cloneNode();
  2430. addLink.innerHTML = '<div class="geSprite geSprite-plus" style="display:inline-block;"></div>';
  2431. addLink.setAttribute('title', mxResources.get('addLayer'));
  2432. mxEvent.addListener(addLink, 'click', function(evt)
  2433. {
  2434. if (graph.isEnabled())
  2435. {
  2436. graph.model.beginUpdate();
  2437. try
  2438. {
  2439. var cell = graph.addCell(new mxCell(mxResources.get('untitledLayer')), graph.model.root);
  2440. graph.setDefaultParent(cell);
  2441. }
  2442. finally
  2443. {
  2444. graph.model.endUpdate();
  2445. }
  2446. }
  2447. mxEvent.consume(evt);
  2448. });
  2449. if (!graph.isEnabled())
  2450. {
  2451. addLink.className = 'geButton mxDisabled';
  2452. }
  2453. ldiv.appendChild(addLink);
  2454. div.appendChild(ldiv);
  2455. function refresh()
  2456. {
  2457. layerCount = graph.model.getChildCount(graph.model.root)
  2458. listDiv.innerHTML = '';
  2459. function addLayer(index, label, child, defaultParent)
  2460. {
  2461. var ldiv = document.createElement('div');
  2462. ldiv.className = 'geToolbarContainer';
  2463. ldiv.style.overflow = 'hidden';
  2464. ldiv.style.position = 'relative';
  2465. ldiv.style.padding = '4px';
  2466. ldiv.style.height = '22px';
  2467. ldiv.style.display = 'block';
  2468. ldiv.style.backgroundColor = 'whiteSmoke';
  2469. ldiv.style.borderWidth = '0px 0px 1px 0px';
  2470. ldiv.style.borderColor = '#c3c3c3';
  2471. ldiv.style.borderStyle = 'solid';
  2472. ldiv.style.whiteSpace = 'nowrap';
  2473. var left = document.createElement('div');
  2474. left.style.display = 'inline-block';
  2475. left.style.width = '100%';
  2476. left.style.textOverflow = 'ellipsis';
  2477. left.style.overflow = 'hidden';
  2478. mxEvent.addListener(ldiv, 'dragover', function(evt)
  2479. {
  2480. evt.dataTransfer.dropEffect = 'move';
  2481. dropIndex = index;
  2482. evt.stopPropagation();
  2483. evt.preventDefault();
  2484. });
  2485. mxEvent.addListener(ldiv, 'dragstart', function(evt)
  2486. {
  2487. dragSource = ldiv;
  2488. // Workaround for no DnD on DIV in FF
  2489. if (mxClient.IS_FF)
  2490. {
  2491. // LATER: Check what triggers a parse as XML on this in FF after drop
  2492. evt.dataTransfer.setData('Text', '<layer/>');
  2493. }
  2494. });
  2495. mxEvent.addListener(ldiv, 'dragend', function(evt)
  2496. {
  2497. if (dragSource != null)
  2498. {
  2499. graph.addCell(child, graph.model.root, dropIndex);
  2500. dragSource = null;
  2501. dropIndex = null;
  2502. }
  2503. evt.stopPropagation();
  2504. evt.preventDefault();
  2505. });
  2506. var btn = document.createElement('img');
  2507. btn.setAttribute('draggable', 'false');
  2508. btn.setAttribute('align', 'top');
  2509. btn.setAttribute('border', '0');
  2510. btn.style.cursor = 'pointer';
  2511. btn.style.padding = '4px';
  2512. btn.setAttribute('title', mxResources.get('lockUnlock'));
  2513. var state = graph.view.getState(child);
  2514. var style = (state != null) ? state.style : graph.getCellStyle(child);
  2515. if (mxUtils.getValue(style, 'locked', '0') == '1')
  2516. {
  2517. btn.setAttribute('src', Dialog.prototype.lockedImage);
  2518. }
  2519. else
  2520. {
  2521. btn.setAttribute('src', Dialog.prototype.unlockedImage);
  2522. }
  2523. mxEvent.addListener(btn, 'click', function(evt)
  2524. {
  2525. if (graph.isEnabled())
  2526. {
  2527. var value = null;
  2528. graph.getModel().beginUpdate();
  2529. try
  2530. {
  2531. value = (mxUtils.getValue(style, 'locked', '0') == '1') ? null : '1';
  2532. graph.setCellStyles('locked', value, [child]);
  2533. }
  2534. finally
  2535. {
  2536. graph.getModel().endUpdate();
  2537. }
  2538. if (value == '1')
  2539. {
  2540. graph.removeSelectionCells(graph.getModel().getDescendants(child));
  2541. }
  2542. mxEvent.consume(evt);
  2543. }
  2544. });
  2545. left.appendChild(btn);
  2546. var inp = document.createElement('input');
  2547. inp.setAttribute('type', 'checkbox');
  2548. inp.setAttribute('title', mxResources.get('hideIt', [child.value || mxResources.get('background')]));
  2549. inp.style.marginLeft = '4px';
  2550. inp.style.marginRight = '6px';
  2551. inp.style.marginTop = '4px';
  2552. left.appendChild(inp);
  2553. if (!graph.isEnabled())
  2554. {
  2555. inp.setAttribute('disabled', 'disabled');
  2556. }
  2557. if (graph.model.isVisible(child))
  2558. {
  2559. inp.setAttribute('checked', 'checked');
  2560. inp.defaultChecked = true;
  2561. }
  2562. mxEvent.addListener(inp, 'click', function(evt)
  2563. {
  2564. if (graph.isEnabled())
  2565. {
  2566. graph.model.setVisible(child, !graph.model.isVisible(child));
  2567. mxEvent.consume(evt);
  2568. }
  2569. });
  2570. mxUtils.write(left, label);
  2571. ldiv.appendChild(left);
  2572. if (graph.isEnabled())
  2573. {
  2574. // Fallback if no drag and drop is available
  2575. if (mxClient.IS_TOUCH || mxClient.IS_POINTER || mxClient.IS_VML ||
  2576. (mxClient.IS_IE && document.documentMode < 10))
  2577. {
  2578. var right = document.createElement('div');
  2579. right.style.display = 'block';
  2580. right.style.textAlign = 'right';
  2581. right.style.whiteSpace = 'nowrap';
  2582. right.style.position = 'absolute';
  2583. right.style.right = '6px';
  2584. right.style.top = '6px';
  2585. // Poor man's change layer order
  2586. if (index > 0)
  2587. {
  2588. var img2 = document.createElement('a');
  2589. img2.setAttribute('title', mxResources.get('toBack'));
  2590. img2.className = 'geButton';
  2591. img2.style.cssFloat = 'none';
  2592. img2.innerHTML = '&#9650;';
  2593. img2.style.width = '14px';
  2594. img2.style.height = '14px';
  2595. img2.style.fontSize = '14px';
  2596. img2.style.margin = '0px';
  2597. img2.style.marginTop = '-1px';
  2598. right.appendChild(img2);
  2599. mxEvent.addListener(img2, 'click', function(evt)
  2600. {
  2601. if (graph.isEnabled())
  2602. {
  2603. graph.addCell(child, graph.model.root, index - 1);
  2604. }
  2605. mxEvent.consume(evt);
  2606. });
  2607. }
  2608. if (index >= 0 && index < layerCount - 1)
  2609. {
  2610. var img1 = document.createElement('a');
  2611. img1.setAttribute('title', mxResources.get('toFront'));
  2612. img1.className = 'geButton';
  2613. img1.style.cssFloat = 'none';
  2614. img1.innerHTML = '&#9660;';
  2615. img1.style.width = '14px';
  2616. img1.style.height = '14px';
  2617. img1.style.fontSize = '14px';
  2618. img1.style.margin = '0px';
  2619. img1.style.marginTop = '-1px';
  2620. right.appendChild(img1);
  2621. mxEvent.addListener(img1, 'click', function(evt)
  2622. {
  2623. if (graph.isEnabled())
  2624. {
  2625. graph.addCell(child, graph.model.root, index + 1);
  2626. }
  2627. mxEvent.consume(evt);
  2628. });
  2629. }
  2630. ldiv.appendChild(right);
  2631. }
  2632. if (mxClient.IS_SVG && (!mxClient.IS_IE || document.documentMode >= 10))
  2633. {
  2634. ldiv.setAttribute('draggable', 'true');
  2635. ldiv.style.cursor = 'move';
  2636. }
  2637. }
  2638. mxEvent.addListener(ldiv, 'dblclick', function(evt)
  2639. {
  2640. var nodeName = mxEvent.getSource(evt).nodeName;
  2641. if (nodeName != 'INPUT' && nodeName != 'IMG')
  2642. {
  2643. renameLayer(child);
  2644. mxEvent.consume(evt);
  2645. }
  2646. });
  2647. if (graph.getDefaultParent() == child)
  2648. {
  2649. ldiv.style.background = '#e6eff8';
  2650. selectionLayer = child;
  2651. }
  2652. else
  2653. {
  2654. mxEvent.addListener(ldiv, 'click', function(evt)
  2655. {
  2656. if (graph.isEnabled())
  2657. {
  2658. graph.setDefaultParent(defaultParent);
  2659. graph.view.setCurrentRoot(null);
  2660. refresh();
  2661. }
  2662. });
  2663. }
  2664. listDiv.appendChild(ldiv);
  2665. };
  2666. // Cannot be moved or deleted
  2667. for (var i = 0; i < layerCount; i++)
  2668. {
  2669. (mxUtils.bind(this, function(child)
  2670. {
  2671. addLayer(i, child.value || mxResources.get('background'), child, child);
  2672. }))(graph.model.getChildAt(graph.model.root, i));
  2673. }
  2674. removeLink.setAttribute('title', mxResources.get('removeIt', [selectionLayer.value || mxResources.get('background')]));
  2675. insertLink.setAttribute('title', mxResources.get('moveSelectionTo', [selectionLayer.value || mxResources.get('background')]));
  2676. duplicateLink.setAttribute('title', mxResources.get('duplicateIt', [selectionLayer.value || mxResources.get('background')]));
  2677. renameLink.setAttribute('title', mxResources.get('renameIt', [selectionLayer.value || mxResources.get('background')]));
  2678. if (graph.isSelectionEmpty())
  2679. {
  2680. insertLink.className = 'geButton mxDisabled';
  2681. }
  2682. };
  2683. refresh();
  2684. graph.model.addListener(mxEvent.CHANGE, function()
  2685. {
  2686. refresh();
  2687. });
  2688. graph.selectionModel.addListener(mxEvent.CHANGE, function()
  2689. {
  2690. if (graph.isSelectionEmpty())
  2691. {
  2692. insertLink.className = 'geButton mxDisabled';
  2693. }
  2694. else
  2695. {
  2696. insertLink.className = 'geButton';
  2697. }
  2698. });
  2699. this.window = new mxWindow(mxResources.get('layers'), div, x, y, w, h, true, true);
  2700. this.window.destroyOnClose = false;
  2701. this.window.setMaximizable(false);
  2702. this.window.setResizable(true);
  2703. this.window.setClosable(true);
  2704. this.window.setVisible(true);
  2705. // Make refresh available via instance
  2706. this.refreshLayers = refresh;
  2707. this.window.setLocation = function(x, y)
  2708. {
  2709. x = Math.max(0, x);
  2710. y = Math.max(0, y);
  2711. mxWindow.prototype.setLocation.apply(this, arguments);
  2712. };
  2713. mxEvent.addListener(window, 'resize', mxUtils.bind(this, function()
  2714. {
  2715. var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  2716. var ih = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  2717. var x = this.window.getX();
  2718. var y = this.window.getY();
  2719. if (x + this.window.table.clientWidth > iw)
  2720. {
  2721. x = Math.max(0, iw - this.window.table.clientWidth);
  2722. }
  2723. if (y + this.window.table.clientHeight > ih)
  2724. {
  2725. y = Math.max(0, ih - this.window.table.clientHeight);
  2726. }
  2727. if (this.window.getX() != x || this.window.getY() != y)
  2728. {
  2729. this.window.setLocation(x, y);
  2730. }
  2731. }));
  2732. };