Dialogs.js 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315
  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. table.setAttribute('cellpadding', (mxClient.IS_SF) ? '0' : '2');
  1411. row = document.createElement('tr');
  1412. td = document.createElement('td');
  1413. td.style.fontSize = '10pt';
  1414. td.style.width = '100px';
  1415. mxUtils.write(td, mxResources.get('filename') + ':');
  1416. row.appendChild(td);
  1417. var nameInput = document.createElement('input');
  1418. nameInput.setAttribute('value', editorUi.editor.getOrCreateFilename());
  1419. nameInput.style.width = '180px';
  1420. td = document.createElement('td');
  1421. td.appendChild(nameInput);
  1422. row.appendChild(td);
  1423. tbody.appendChild(row);
  1424. row = document.createElement('tr');
  1425. td = document.createElement('td');
  1426. td.style.fontSize = '10pt';
  1427. mxUtils.write(td, mxResources.get('format') + ':');
  1428. row.appendChild(td);
  1429. var imageFormatSelect = document.createElement('select');
  1430. imageFormatSelect.style.width = '180px';
  1431. var pngOption = document.createElement('option');
  1432. pngOption.setAttribute('value', 'png');
  1433. mxUtils.write(pngOption, mxResources.get('formatPng'));
  1434. imageFormatSelect.appendChild(pngOption);
  1435. var gifOption = document.createElement('option');
  1436. if (ExportDialog.showGifOption)
  1437. {
  1438. gifOption.setAttribute('value', 'gif');
  1439. mxUtils.write(gifOption, mxResources.get('formatGif'));
  1440. imageFormatSelect.appendChild(gifOption);
  1441. }
  1442. var jpgOption = document.createElement('option');
  1443. jpgOption.setAttribute('value', 'jpg');
  1444. mxUtils.write(jpgOption, mxResources.get('formatJpg'));
  1445. imageFormatSelect.appendChild(jpgOption);
  1446. var pdfOption = document.createElement('option');
  1447. pdfOption.setAttribute('value', 'pdf');
  1448. mxUtils.write(pdfOption, mxResources.get('formatPdf'));
  1449. imageFormatSelect.appendChild(pdfOption);
  1450. var svgOption = document.createElement('option');
  1451. svgOption.setAttribute('value', 'svg');
  1452. mxUtils.write(svgOption, mxResources.get('formatSvg'));
  1453. imageFormatSelect.appendChild(svgOption);
  1454. if (ExportDialog.showXmlOption)
  1455. {
  1456. var xmlOption = document.createElement('option');
  1457. xmlOption.setAttribute('value', 'xml');
  1458. mxUtils.write(xmlOption, mxResources.get('formatXml'));
  1459. imageFormatSelect.appendChild(xmlOption);
  1460. }
  1461. td = document.createElement('td');
  1462. td.appendChild(imageFormatSelect);
  1463. row.appendChild(td);
  1464. tbody.appendChild(row);
  1465. row = document.createElement('tr');
  1466. td = document.createElement('td');
  1467. td.style.fontSize = '10pt';
  1468. mxUtils.write(td, mxResources.get('zoom') + ' (%):');
  1469. row.appendChild(td);
  1470. var zoomInput = document.createElement('input');
  1471. zoomInput.setAttribute('type', 'number');
  1472. zoomInput.setAttribute('value', '100');
  1473. zoomInput.style.width = '180px';
  1474. td = document.createElement('td');
  1475. td.appendChild(zoomInput);
  1476. row.appendChild(td);
  1477. tbody.appendChild(row);
  1478. row = document.createElement('tr');
  1479. td = document.createElement('td');
  1480. td.style.fontSize = '10pt';
  1481. mxUtils.write(td, mxResources.get('width') + ':');
  1482. row.appendChild(td);
  1483. var widthInput = document.createElement('input');
  1484. widthInput.setAttribute('value', width);
  1485. widthInput.style.width = '180px';
  1486. td = document.createElement('td');
  1487. td.appendChild(widthInput);
  1488. row.appendChild(td);
  1489. tbody.appendChild(row);
  1490. row = document.createElement('tr');
  1491. td = document.createElement('td');
  1492. td.style.fontSize = '10pt';
  1493. mxUtils.write(td, mxResources.get('height') + ':');
  1494. row.appendChild(td);
  1495. var heightInput = document.createElement('input');
  1496. heightInput.setAttribute('value', height);
  1497. heightInput.style.width = '180px';
  1498. td = document.createElement('td');
  1499. td.appendChild(heightInput);
  1500. row.appendChild(td);
  1501. tbody.appendChild(row);
  1502. row = document.createElement('tr');
  1503. td = document.createElement('td');
  1504. td.style.fontSize = '10pt';
  1505. mxUtils.write(td, mxResources.get('background') + ':');
  1506. row.appendChild(td);
  1507. var transparentCheckbox = document.createElement('input');
  1508. transparentCheckbox.setAttribute('type', 'checkbox');
  1509. transparentCheckbox.checked = graph.background == null || graph.background == mxConstants.NONE;
  1510. td = document.createElement('td');
  1511. td.appendChild(transparentCheckbox);
  1512. mxUtils.write(td, mxResources.get('transparent'));
  1513. row.appendChild(td);
  1514. tbody.appendChild(row);
  1515. row = document.createElement('tr');
  1516. td = document.createElement('td');
  1517. td.style.fontSize = '10pt';
  1518. mxUtils.write(td, mxResources.get('borderWidth') + ':');
  1519. row.appendChild(td);
  1520. var borderInput = document.createElement('input');
  1521. borderInput.setAttribute('type', 'number');
  1522. borderInput.setAttribute('value', '0');
  1523. borderInput.style.width = '180px';
  1524. td = document.createElement('td');
  1525. td.appendChild(borderInput);
  1526. row.appendChild(td);
  1527. tbody.appendChild(row);
  1528. table.appendChild(tbody);
  1529. // Handles changes in the export format
  1530. function formatChanged()
  1531. {
  1532. var name = nameInput.value;
  1533. var dot = name.lastIndexOf('.');
  1534. if (dot > 0)
  1535. {
  1536. nameInput.value = name.substring(0, dot + 1) + imageFormatSelect.value;
  1537. }
  1538. else
  1539. {
  1540. nameInput.value = name + '.' + imageFormatSelect.value;
  1541. }
  1542. if (imageFormatSelect.value === 'xml')
  1543. {
  1544. zoomInput.setAttribute('disabled', 'true');
  1545. widthInput.setAttribute('disabled', 'true');
  1546. heightInput.setAttribute('disabled', 'true');
  1547. borderInput.setAttribute('disabled', 'true');
  1548. }
  1549. else
  1550. {
  1551. zoomInput.removeAttribute('disabled');
  1552. widthInput.removeAttribute('disabled');
  1553. heightInput.removeAttribute('disabled');
  1554. borderInput.removeAttribute('disabled');
  1555. }
  1556. if (imageFormatSelect.value === 'png' || imageFormatSelect.value === 'svg')
  1557. {
  1558. transparentCheckbox.removeAttribute('disabled');
  1559. }
  1560. else
  1561. {
  1562. transparentCheckbox.setAttribute('disabled', 'disabled');
  1563. }
  1564. };
  1565. mxEvent.addListener(imageFormatSelect, 'change', formatChanged);
  1566. formatChanged();
  1567. function checkValues()
  1568. {
  1569. if (widthInput.value * heightInput.value > MAX_AREA || widthInput.value <= 0)
  1570. {
  1571. widthInput.style.backgroundColor = 'red';
  1572. }
  1573. else
  1574. {
  1575. widthInput.style.backgroundColor = '';
  1576. }
  1577. if (widthInput.value * heightInput.value > MAX_AREA || heightInput.value <= 0)
  1578. {
  1579. heightInput.style.backgroundColor = 'red';
  1580. }
  1581. else
  1582. {
  1583. heightInput.style.backgroundColor = '';
  1584. }
  1585. };
  1586. mxEvent.addListener(zoomInput, 'change', function()
  1587. {
  1588. var s = Math.max(0, parseFloat(zoomInput.value) || 100) / 100;
  1589. zoomInput.value = parseFloat((s * 100).toFixed(2));
  1590. if (width > 0)
  1591. {
  1592. widthInput.value = Math.floor(width * s);
  1593. heightInput.value = Math.floor(height * s);
  1594. }
  1595. else
  1596. {
  1597. zoomInput.value = '100';
  1598. widthInput.value = width;
  1599. heightInput.value = height;
  1600. }
  1601. checkValues();
  1602. });
  1603. mxEvent.addListener(widthInput, 'change', function()
  1604. {
  1605. var s = parseInt(widthInput.value) / width;
  1606. if (s > 0)
  1607. {
  1608. zoomInput.value = parseFloat((s * 100).toFixed(2));
  1609. heightInput.value = Math.floor(height * s);
  1610. }
  1611. else
  1612. {
  1613. zoomInput.value = '100';
  1614. widthInput.value = width;
  1615. heightInput.value = height;
  1616. }
  1617. checkValues();
  1618. });
  1619. mxEvent.addListener(heightInput, 'change', function()
  1620. {
  1621. var s = parseInt(heightInput.value) / height;
  1622. if (s > 0)
  1623. {
  1624. zoomInput.value = parseFloat((s * 100).toFixed(2));
  1625. widthInput.value = Math.floor(width * s);
  1626. }
  1627. else
  1628. {
  1629. zoomInput.value = '100';
  1630. widthInput.value = width;
  1631. heightInput.value = height;
  1632. }
  1633. checkValues();
  1634. });
  1635. row = document.createElement('tr');
  1636. td = document.createElement('td');
  1637. td.setAttribute('align', 'right');
  1638. td.style.paddingTop = '22px';
  1639. td.colSpan = 2;
  1640. var saveBtn = mxUtils.button(mxResources.get('export'), mxUtils.bind(this, function()
  1641. {
  1642. if (parseInt(zoomInput.value) <= 0)
  1643. {
  1644. mxUtils.alert(mxResources.get('drawingEmpty'));
  1645. }
  1646. else
  1647. {
  1648. var name = nameInput.value;
  1649. var format = imageFormatSelect.value;
  1650. var s = Math.max(0, parseFloat(zoomInput.value) || 100) / 100;
  1651. var b = Math.max(0, parseInt(borderInput.value));
  1652. var bg = graph.background;
  1653. if ((format == 'svg' || format == 'png') && transparentCheckbox.checked)
  1654. {
  1655. bg = null;
  1656. }
  1657. else if (bg == null || bg == mxConstants.NONE)
  1658. {
  1659. bg = '#ffffff';
  1660. }
  1661. ExportDialog.exportFile(editorUi, name, format, bg, s, b);
  1662. }
  1663. }));
  1664. saveBtn.className = 'geBtn gePrimaryBtn';
  1665. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1666. {
  1667. editorUi.hideDialog();
  1668. });
  1669. cancelBtn.className = 'geBtn';
  1670. if (editorUi.editor.cancelFirst)
  1671. {
  1672. td.appendChild(cancelBtn);
  1673. td.appendChild(saveBtn);
  1674. }
  1675. else
  1676. {
  1677. td.appendChild(saveBtn);
  1678. td.appendChild(cancelBtn);
  1679. }
  1680. row.appendChild(td);
  1681. tbody.appendChild(row);
  1682. table.appendChild(tbody);
  1683. this.container = table;
  1684. };
  1685. /**
  1686. * Global switches for the export dialog.
  1687. */
  1688. ExportDialog.showGifOption = true;
  1689. /**
  1690. * Global switches for the export dialog.
  1691. */
  1692. ExportDialog.showXmlOption = true;
  1693. /**
  1694. * Hook for getting the export format. Returns null for the default
  1695. * intermediate XML export format or a function that returns the
  1696. * parameter and value to be used in the request in the form
  1697. * key=value, where value should be URL encoded.
  1698. */
  1699. ExportDialog.exportFile = function(editorUi, name, format, bg, s, b)
  1700. {
  1701. var graph = editorUi.editor.graph;
  1702. if (format == 'xml')
  1703. {
  1704. ExportDialog.saveLocalFile(editorUi, mxUtils.getXml(editorUi.editor.getGraphXml()), name, format);
  1705. }
  1706. else if (format == 'svg')
  1707. {
  1708. ExportDialog.saveLocalFile(editorUi, mxUtils.getXml(graph.getSvg(bg, s, b)), name, format);
  1709. }
  1710. else
  1711. {
  1712. var bounds = graph.getGraphBounds();
  1713. // New image export
  1714. var xmlDoc = mxUtils.createXmlDocument();
  1715. var root = xmlDoc.createElement('output');
  1716. xmlDoc.appendChild(root);
  1717. // Renders graph. Offset will be multiplied with state's scale when painting state.
  1718. var xmlCanvas = new mxXmlCanvas2D(root);
  1719. xmlCanvas.translate(Math.floor((b / s - bounds.x) / graph.view.scale),
  1720. Math.floor((b / s - bounds.y) / graph.view.scale));
  1721. xmlCanvas.scale(s / graph.view.scale);
  1722. var imgExport = new mxImageExport()
  1723. imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
  1724. // Puts request data together
  1725. var param = 'xml=' + encodeURIComponent(mxUtils.getXml(root));
  1726. var w = Math.ceil(bounds.width * s / graph.view.scale + 2 * b);
  1727. var h = Math.ceil(bounds.height * s / graph.view.scale + 2 * b);
  1728. // Requests image if request is valid
  1729. if (param.length <= MAX_REQUEST_SIZE && w * h < MAX_AREA)
  1730. {
  1731. editorUi.hideDialog();
  1732. var req = new mxXmlRequest(EXPORT_URL, 'format=' + format +
  1733. '&filename=' + encodeURIComponent(name) +
  1734. '&bg=' + ((bg != null) ? bg : 'none') +
  1735. '&w=' + w + '&h=' + h + '&' + param);
  1736. req.simulate(document, '_blank');
  1737. }
  1738. else
  1739. {
  1740. mxUtils.alert(mxResources.get('drawingTooLarge'));
  1741. }
  1742. }
  1743. };
  1744. /**
  1745. * Hook for getting the export format. Returns null for the default
  1746. * intermediate XML export format or a function that returns the
  1747. * parameter and value to be used in the request in the form
  1748. * key=value, where value should be URL encoded.
  1749. */
  1750. ExportDialog.saveLocalFile = function(editorUi, data, filename, format)
  1751. {
  1752. if (data.length < MAX_REQUEST_SIZE)
  1753. {
  1754. editorUi.hideDialog();
  1755. var req = new mxXmlRequest(SAVE_URL, 'xml=' + encodeURIComponent(data) + '&filename=' +
  1756. encodeURIComponent(filename) + '&format=' + format);
  1757. req.simulate(document, '_blank');
  1758. }
  1759. else
  1760. {
  1761. mxUtils.alert(mxResources.get('drawingTooLarge'));
  1762. mxUtils.popup(xml);
  1763. }
  1764. };
  1765. /**
  1766. * Constructs a new metadata dialog.
  1767. */
  1768. var EditDataDialog = function(ui, cell)
  1769. {
  1770. var div = document.createElement('div');
  1771. var graph = ui.editor.graph;
  1772. div.style.height = '310px';
  1773. div.style.overflow = 'auto';
  1774. var value = graph.getModel().getValue(cell);
  1775. // Converts the value to an XML node
  1776. if (!mxUtils.isNode(value))
  1777. {
  1778. var doc = mxUtils.createXmlDocument();
  1779. var obj = doc.createElement('object');
  1780. obj.setAttribute('label', value || '');
  1781. value = obj;
  1782. }
  1783. // Creates the dialog contents
  1784. var form = new mxForm('properties');
  1785. form.table.style.width = '100%';
  1786. form.table.style.paddingRight = '20px';
  1787. var attrs = value.attributes;
  1788. var names = [];
  1789. var texts = [];
  1790. var count = 0;
  1791. // FIXME: Fix remove button for quirks mode
  1792. var addRemoveButton = function(text, name)
  1793. {
  1794. text.parentNode.style.marginRight = '12px';
  1795. var removeAttr = document.createElement('a');
  1796. var img = mxUtils.createImage(Dialog.prototype.closeImage);
  1797. img.style.height = '9px';
  1798. img.style.fontSize = '9px';
  1799. img.style.marginBottom = '7px';
  1800. removeAttr.className = 'geButton';
  1801. removeAttr.setAttribute('title', mxResources.get('delete'));
  1802. removeAttr.style.margin = '0px';
  1803. removeAttr.style.width = '14px';
  1804. removeAttr.style.height = '14px';
  1805. removeAttr.style.fontSize = '14px';
  1806. removeAttr.style.cursor = 'pointer';
  1807. removeAttr.style.marginLeft = '6px';
  1808. removeAttr.appendChild(img);
  1809. var removeAttrFn = (function(name)
  1810. {
  1811. return function()
  1812. {
  1813. var count = 0;
  1814. for (var j = 0; j < names.length; j++)
  1815. {
  1816. if (names[j] == name)
  1817. {
  1818. texts[j] = null;
  1819. form.table.deleteRow(count);
  1820. break;
  1821. }
  1822. if (texts[j] != null)
  1823. {
  1824. count++;
  1825. }
  1826. }
  1827. };
  1828. })(name);
  1829. mxEvent.addListener(removeAttr, 'click', removeAttrFn);
  1830. text.parentNode.style.whiteSpace = 'nowrap';
  1831. text.parentNode.appendChild(removeAttr);
  1832. };
  1833. var addTextArea = function(index, name, value)
  1834. {
  1835. names[index] = name;
  1836. texts[index] = form.addTextarea(names[count] + ':', value, 2);
  1837. texts[index].style.width = '100%';
  1838. addRemoveButton(texts[index], name);
  1839. };
  1840. for (var i = 0; i < attrs.length; i++)
  1841. {
  1842. if (attrs[i].nodeName != 'label' && attrs[i].nodeName != 'placeholders')
  1843. {
  1844. addTextArea(count, attrs[i].nodeName, attrs[i].nodeValue);
  1845. count++;
  1846. }
  1847. }
  1848. div.appendChild(form.table);
  1849. var newProp = document.createElement('div');
  1850. newProp.style.whiteSpace = 'nowrap';
  1851. newProp.style.marginTop = '6px';
  1852. var nameInput = document.createElement('input');
  1853. nameInput.setAttribute('placeholder', mxResources.get('enterPropertyName'));
  1854. nameInput.setAttribute('type', 'text');
  1855. nameInput.setAttribute('size', (mxClient.IS_QUIRKS) ? '18' : '22');
  1856. nameInput.style.marginLeft = '2px';
  1857. newProp.appendChild(nameInput);
  1858. div.appendChild(newProp);
  1859. var addBtn = mxUtils.button(mxResources.get('addProperty'), function()
  1860. {
  1861. var name = nameInput.value;
  1862. if (name.length > 0 && name != 'label' && name != 'placeholders')
  1863. {
  1864. try
  1865. {
  1866. var idx = mxUtils.indexOf(names, name);
  1867. if (idx >= 0 && texts[idx] != null)
  1868. {
  1869. texts[idx].focus();
  1870. }
  1871. else
  1872. {
  1873. // Checks if the name is valid
  1874. var clone = value.cloneNode(false);
  1875. clone.setAttribute(name, '');
  1876. if (idx >= 0)
  1877. {
  1878. names.splice(idx, 1);
  1879. texts.splice(idx, 1);
  1880. }
  1881. names.push(name);
  1882. var text = form.addTextarea(name + ':', '', 2);
  1883. text.style.width = '100%';
  1884. texts.push(text);
  1885. addRemoveButton(text, name);
  1886. text.focus();
  1887. }
  1888. nameInput.value = '';
  1889. }
  1890. catch (e)
  1891. {
  1892. mxUtils.alert(e);
  1893. }
  1894. }
  1895. else
  1896. {
  1897. mxUtils.alert(mxResources.get('invalidName'));
  1898. }
  1899. });
  1900. this.init = function()
  1901. {
  1902. if (texts.length > 0)
  1903. {
  1904. texts[0].focus();
  1905. }
  1906. else
  1907. {
  1908. nameInput.focus();
  1909. }
  1910. };
  1911. addBtn.setAttribute('disabled', 'disabled');
  1912. addBtn.style.marginLeft = '10px';
  1913. addBtn.style.width = '144px';
  1914. newProp.appendChild(addBtn);
  1915. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1916. {
  1917. ui.hideDialog.apply(ui, arguments);
  1918. });
  1919. cancelBtn.className = 'geBtn';
  1920. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  1921. {
  1922. try
  1923. {
  1924. ui.hideDialog.apply(ui, arguments);
  1925. // Clones and updates the value
  1926. value = value.cloneNode(true);
  1927. var removeLabel = false;
  1928. for (var i = 0; i < names.length; i++)
  1929. {
  1930. if (texts[i] == null)
  1931. {
  1932. value.removeAttribute(names[i]);
  1933. }
  1934. else
  1935. {
  1936. value.setAttribute(names[i], texts[i].value);
  1937. removeLabel = removeLabel || (names[i] == 'placeholder' &&
  1938. value.getAttribute('placeholders') == '1');
  1939. }
  1940. }
  1941. // Removes label if placeholder is assigned
  1942. if (removeLabel)
  1943. {
  1944. value.removeAttribute('label');
  1945. }
  1946. // Updates the value of the cell (undoable)
  1947. graph.getModel().setValue(cell, value);
  1948. }
  1949. catch (e)
  1950. {
  1951. mxUtils.alert(e);
  1952. }
  1953. });
  1954. applyBtn.className = 'geBtn gePrimaryBtn';
  1955. function updateAddBtn()
  1956. {
  1957. if (nameInput.value.length > 0)
  1958. {
  1959. addBtn.removeAttribute('disabled');
  1960. }
  1961. else
  1962. {
  1963. addBtn.setAttribute('disabled', 'disabled');
  1964. }
  1965. };
  1966. mxEvent.addListener(nameInput, 'keyup', updateAddBtn);
  1967. // Catches all changes that don't fire a keyup (such as paste via mouse)
  1968. mxEvent.addListener(nameInput, 'change', updateAddBtn);
  1969. var buttons = document.createElement('div');
  1970. buttons.style.marginTop = '18px';
  1971. buttons.style.textAlign = 'right';
  1972. if (ui.editor.graph.getModel().isVertex(cell) || ui.editor.graph.getModel().isEdge(cell))
  1973. {
  1974. var replace = document.createElement('span');
  1975. replace.style.marginRight = '10px';
  1976. var input = document.createElement('input');
  1977. input.setAttribute('type', 'checkbox');
  1978. input.style.marginRight = '6px';
  1979. if (value.getAttribute('placeholders') == '1')
  1980. {
  1981. input.setAttribute('checked', 'checked');
  1982. input.defaultChecked = true;
  1983. }
  1984. mxEvent.addListener(input, 'click', function()
  1985. {
  1986. if (value.getAttribute('placeholders') == '1')
  1987. {
  1988. value.removeAttribute('placeholders');
  1989. }
  1990. else
  1991. {
  1992. value.setAttribute('placeholders', '1');
  1993. }
  1994. });
  1995. replace.appendChild(input);
  1996. mxUtils.write(replace, mxResources.get('placeholders'));
  1997. if (EditDataDialog.placeholderHelpLink != null)
  1998. {
  1999. var link = document.createElement('a');
  2000. link.setAttribute('href', EditDataDialog.placeholderHelpLink);
  2001. link.setAttribute('title', mxResources.get('help'));
  2002. link.setAttribute('target', '_blank');
  2003. link.style.marginLeft = '10px';
  2004. link.style.cursor = 'help';
  2005. var icon = document.createElement('img');
  2006. icon.setAttribute('border', '0');
  2007. icon.setAttribute('valign', 'middle');
  2008. icon.style.marginTop = '-4px';
  2009. icon.setAttribute('src', Editor.helpImage);
  2010. link.appendChild(icon);
  2011. replace.appendChild(link);
  2012. }
  2013. buttons.appendChild(replace);
  2014. }
  2015. if (ui.editor.cancelFirst)
  2016. {
  2017. buttons.appendChild(cancelBtn);
  2018. buttons.appendChild(applyBtn);
  2019. }
  2020. else
  2021. {
  2022. buttons.appendChild(applyBtn);
  2023. buttons.appendChild(cancelBtn);
  2024. }
  2025. div.appendChild(buttons);
  2026. this.container = div;
  2027. };
  2028. /**
  2029. * Optional help link.
  2030. */
  2031. EditDataDialog.placeholderHelpLink = null;
  2032. /**
  2033. * Constructs a new link dialog.
  2034. */
  2035. var LinkDialog = function(editorUi, initialValue, btnLabel, fn)
  2036. {
  2037. var div = document.createElement('div');
  2038. mxUtils.write(div, mxResources.get('editLink') + ':');
  2039. var inner = document.createElement('div');
  2040. inner.className = 'geTitle';
  2041. inner.style.backgroundColor = 'transparent';
  2042. inner.style.borderColor = 'transparent';
  2043. inner.style.whiteSpace = 'nowrap';
  2044. inner.style.textOverflow = 'clip';
  2045. inner.style.cursor = 'default';
  2046. if (!mxClient.IS_VML)
  2047. {
  2048. inner.style.paddingRight = '20px';
  2049. }
  2050. var linkInput = document.createElement('input');
  2051. linkInput.setAttribute('value', initialValue);
  2052. linkInput.setAttribute('placeholder', 'http://www.example.com/');
  2053. linkInput.setAttribute('type', 'text');
  2054. linkInput.style.marginTop = '6px';
  2055. linkInput.style.width = '400px';
  2056. linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
  2057. linkInput.style.backgroundRepeat = 'no-repeat';
  2058. linkInput.style.backgroundPosition = '100% 50%';
  2059. linkInput.style.paddingRight = '14px';
  2060. var cross = document.createElement('div');
  2061. cross.setAttribute('title', mxResources.get('reset'));
  2062. cross.style.position = 'relative';
  2063. cross.style.left = '-16px';
  2064. cross.style.width = '12px';
  2065. cross.style.height = '14px';
  2066. cross.style.cursor = 'pointer';
  2067. // Workaround for inline-block not supported in IE
  2068. cross.style.display = (mxClient.IS_VML) ? 'inline' : 'inline-block';
  2069. cross.style.top = ((mxClient.IS_VML) ? 0 : 3) + 'px';
  2070. // Needed to block event transparency in IE
  2071. cross.style.background = 'url(' + IMAGE_PATH + '/transparent.gif)';
  2072. mxEvent.addListener(cross, 'click', function()
  2073. {
  2074. linkInput.value = '';
  2075. linkInput.focus();
  2076. });
  2077. inner.appendChild(linkInput);
  2078. inner.appendChild(cross);
  2079. div.appendChild(inner);
  2080. this.init = function()
  2081. {
  2082. linkInput.focus();
  2083. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  2084. {
  2085. linkInput.select();
  2086. }
  2087. else
  2088. {
  2089. document.execCommand('selectAll', false, null);
  2090. }
  2091. };
  2092. var btns = document.createElement('div');
  2093. btns.style.marginTop = '18px';
  2094. btns.style.textAlign = 'right';
  2095. mxEvent.addListener(linkInput, 'keypress', function(e)
  2096. {
  2097. if (e.keyCode == 13)
  2098. {
  2099. editorUi.hideDialog();
  2100. fn(linkInput.value);
  2101. }
  2102. });
  2103. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  2104. {
  2105. editorUi.hideDialog();
  2106. });
  2107. cancelBtn.className = 'geBtn';
  2108. if (editorUi.editor.cancelFirst)
  2109. {
  2110. btns.appendChild(cancelBtn);
  2111. }
  2112. var mainBtn = mxUtils.button(btnLabel, function()
  2113. {
  2114. editorUi.hideDialog();
  2115. fn(linkInput.value);
  2116. });
  2117. mainBtn.className = 'geBtn gePrimaryBtn';
  2118. btns.appendChild(mainBtn);
  2119. if (!editorUi.editor.cancelFirst)
  2120. {
  2121. btns.appendChild(cancelBtn);
  2122. }
  2123. div.appendChild(btns);
  2124. this.container = div;
  2125. };
  2126. /**
  2127. *
  2128. */
  2129. var OutlineWindow = function(editorUi, x, y, w, h)
  2130. {
  2131. var graph = editorUi.editor.graph;
  2132. var div = document.createElement('div');
  2133. div.style.position = 'absolute';
  2134. div.style.width = '100%';
  2135. div.style.height = '100%';
  2136. div.style.border = '1px solid whiteSmoke';
  2137. div.style.overflow = 'hidden';
  2138. this.window = new mxWindow(mxResources.get('outline'), div, x, y, w, h, true, true);
  2139. this.window.destroyOnClose = false;
  2140. this.window.setMaximizable(false);
  2141. this.window.setResizable(true);
  2142. this.window.setClosable(true);
  2143. this.window.setVisible(true);
  2144. this.window.setLocation = function(x, y)
  2145. {
  2146. x = Math.max(0, x);
  2147. y = Math.max(0, y);
  2148. mxWindow.prototype.setLocation.apply(this, arguments);
  2149. };
  2150. mxEvent.addListener(window, 'resize', mxUtils.bind(this, function()
  2151. {
  2152. var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  2153. var ih = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  2154. var x = this.window.getX();
  2155. var y = this.window.getY();
  2156. if (x + this.window.table.clientWidth > iw)
  2157. {
  2158. x = Math.max(0, iw - this.window.table.clientWidth);
  2159. }
  2160. if (y + this.window.table.clientHeight > ih)
  2161. {
  2162. y = Math.max(0, ih - this.window.table.clientHeight);
  2163. }
  2164. if (this.window.getX() != x || this.window.getY() != y)
  2165. {
  2166. this.window.setLocation(x, y);
  2167. }
  2168. }));
  2169. var outline = editorUi.createOutline(this.window);
  2170. this.window.addListener(mxEvent.RESIZE, mxUtils.bind(this, function()
  2171. {
  2172. outline.update(false);
  2173. outline.outline.sizeDidChange();
  2174. }));
  2175. this.window.addListener(mxEvent.SHOW, mxUtils.bind(this, function()
  2176. {
  2177. outline.suspended = false;
  2178. outline.outline.refresh();
  2179. outline.update();
  2180. }));
  2181. this.window.addListener(mxEvent.HIDE, mxUtils.bind(this, function()
  2182. {
  2183. outline.suspended = true;
  2184. }));
  2185. this.window.addListener(mxEvent.NORMALIZE, mxUtils.bind(this, function()
  2186. {
  2187. outline.suspended = false;
  2188. outline.update();
  2189. }));
  2190. this.window.addListener(mxEvent.MINIMIZE, mxUtils.bind(this, function()
  2191. {
  2192. outline.suspended = true;
  2193. }));
  2194. var outlineCreateGraph = outline.createGraph;
  2195. outline.createGraph = function(container)
  2196. {
  2197. var g = outlineCreateGraph.apply(this, arguments);
  2198. g.gridEnabled = false;
  2199. g.pageScale = graph.pageScale;
  2200. g.pageFormat = graph.pageFormat;
  2201. g.background = graph.background;
  2202. g.pageVisible = graph.pageVisible;
  2203. var current = mxUtils.getCurrentStyle(graph.container);
  2204. div.style.backgroundColor = current.backgroundColor;
  2205. return g;
  2206. };
  2207. function update()
  2208. {
  2209. outline.outline.pageScale = graph.pageScale;
  2210. outline.outline.pageFormat = graph.pageFormat;
  2211. outline.outline.pageVisible = graph.pageVisible;
  2212. outline.outline.background = graph.background;
  2213. var current = mxUtils.getCurrentStyle(graph.container);
  2214. div.style.backgroundColor = current.backgroundColor;
  2215. if (graph.view.backgroundPageShape != null && outline.outline.view.backgroundPageShape != null)
  2216. {
  2217. outline.outline.view.backgroundPageShape.fill = graph.view.backgroundPageShape.fill;
  2218. }
  2219. outline.outline.refresh();
  2220. };
  2221. outline.init(div);
  2222. editorUi.editor.addListener('resetGraphView', update);
  2223. editorUi.addListener('pageFormatChanged', update);
  2224. editorUi.addListener('backgroundColorChanged', update);
  2225. editorUi.addListener('backgroundImageChanged', update);
  2226. editorUi.addListener('pageViewChanged', function()
  2227. {
  2228. update();
  2229. outline.update(true);
  2230. });
  2231. if (outline.outline.dialect == mxConstants.DIALECT_SVG)
  2232. {
  2233. var zoomInAction = editorUi.actions.get('zoomIn');
  2234. var zoomOutAction = editorUi.actions.get('zoomOut');
  2235. mxEvent.addMouseWheelListener(function(evt, up)
  2236. {
  2237. var outlineWheel = false;
  2238. var source = mxEvent.getSource(evt);
  2239. while (source != null)
  2240. {
  2241. if (source == outline.outline.view.canvas.ownerSVGElement)
  2242. {
  2243. outlineWheel = true;
  2244. break;
  2245. }
  2246. source = source.parentNode;
  2247. }
  2248. if (outlineWheel)
  2249. {
  2250. if (up)
  2251. {
  2252. zoomInAction.funct();
  2253. }
  2254. else
  2255. {
  2256. zoomOutAction.funct();
  2257. }
  2258. mxEvent.consume(evt);
  2259. }
  2260. });
  2261. }
  2262. };
  2263. /**
  2264. *
  2265. */
  2266. var LayersWindow = function(editorUi, x, y, w, h)
  2267. {
  2268. var graph = editorUi.editor.graph;
  2269. var div = document.createElement('div');
  2270. div.style.userSelect = 'none';
  2271. div.style.background = 'whiteSmoke';
  2272. div.style.border = '1px solid whiteSmoke';
  2273. div.style.height = '100%';
  2274. div.style.marginBottom = '10px';
  2275. div.style.overflow = 'auto';
  2276. var tbarHeight = (!EditorUi.compactUi) ? '30px' : '26px';
  2277. var listDiv = document.createElement('div')
  2278. listDiv.style.backgroundColor = '#e5e5e5';
  2279. listDiv.style.position = 'absolute';
  2280. listDiv.style.overflow = 'auto';
  2281. listDiv.style.left = '0px';
  2282. listDiv.style.right = '0px';
  2283. listDiv.style.top = '0px';
  2284. listDiv.style.bottom = (parseInt(tbarHeight) + 7) + 'px';
  2285. div.appendChild(listDiv);
  2286. var dragSource = null;
  2287. var dropIndex = null;
  2288. mxEvent.addListener(div, 'dragover', function(evt)
  2289. {
  2290. evt.dataTransfer.dropEffect = 'move';
  2291. dropIndex = 0;
  2292. evt.stopPropagation();
  2293. evt.preventDefault();
  2294. });
  2295. // Workaround for "no element found" error in FF
  2296. mxEvent.addListener(div, 'drop', function(evt)
  2297. {
  2298. evt.stopPropagation();
  2299. evt.preventDefault();
  2300. });
  2301. var layerCount = null;
  2302. var selectionLayer = null;
  2303. var ldiv = document.createElement('div');
  2304. ldiv.className = 'geToolbarContainer';
  2305. ldiv.style.position = 'absolute';
  2306. ldiv.style.bottom = '0px';
  2307. ldiv.style.left = '0px';
  2308. ldiv.style.right = '0px';
  2309. ldiv.style.height = tbarHeight;
  2310. ldiv.style.overflow = 'hidden';
  2311. ldiv.style.padding = (!EditorUi.compactUi) ? '1px' : '4px 0px 3px 0px';
  2312. ldiv.style.backgroundColor = 'whiteSmoke';
  2313. ldiv.style.borderWidth = '1px 0px 0px 0px';
  2314. ldiv.style.borderColor = '#c3c3c3';
  2315. ldiv.style.borderStyle = 'solid';
  2316. ldiv.style.display = 'block';
  2317. ldiv.style.whiteSpace = 'nowrap';
  2318. if (mxClient.IS_QUIRKS)
  2319. {
  2320. ldiv.style.filter = 'none';
  2321. }
  2322. var link = document.createElement('a');
  2323. link.className = 'geButton';
  2324. if (mxClient.IS_QUIRKS)
  2325. {
  2326. link.style.filter = 'none';
  2327. }
  2328. var removeLink = link.cloneNode();
  2329. removeLink.innerHTML = '<div class="geSprite geSprite-delete" style="display:inline-block;"></div>';
  2330. mxEvent.addListener(removeLink, 'click', function(evt)
  2331. {
  2332. if (graph.isEnabled())
  2333. {
  2334. graph.model.beginUpdate();
  2335. try
  2336. {
  2337. var index = graph.model.root.getIndex(selectionLayer);
  2338. graph.removeCells([selectionLayer], false);
  2339. // Creates default layer if no layer exists
  2340. if (graph.model.getChildCount(graph.model.root) == 0)
  2341. {
  2342. graph.model.add(graph.model.root, new mxCell());
  2343. graph.setDefaultParent(null);
  2344. }
  2345. else if (index > 0 && index <= graph.model.getChildCount(graph.model.root))
  2346. {
  2347. graph.setDefaultParent(graph.model.getChildAt(graph.model.root, index - 1));
  2348. }
  2349. else
  2350. {
  2351. graph.setDefaultParent(null);
  2352. }
  2353. }
  2354. finally
  2355. {
  2356. graph.model.endUpdate();
  2357. }
  2358. }
  2359. mxEvent.consume(evt);
  2360. });
  2361. if (!graph.isEnabled())
  2362. {
  2363. removeLink.className = 'geButton mxDisabled';
  2364. }
  2365. ldiv.appendChild(removeLink);
  2366. var insertLink = link.cloneNode();
  2367. insertLink.innerHTML = '<div class="geSprite geSprite-insert" style="display:inline-block;"></div>';
  2368. mxEvent.addListener(insertLink, 'click', function(evt)
  2369. {
  2370. if (graph.isEnabled() && !graph.isSelectionEmpty())
  2371. {
  2372. graph.moveCells(graph.getSelectionCells(), 0, 0, false, selectionLayer);
  2373. }
  2374. });
  2375. ldiv.appendChild(insertLink);
  2376. var renameLink = link.cloneNode();
  2377. renameLink.innerHTML = '<div class="geSprite geSprite-dots" style="display:inline-block;"></div>';
  2378. renameLink.setAttribute('title', mxResources.get('rename'));
  2379. function renameLayer(layer)
  2380. {
  2381. if (graph.isEnabled() && layer != null)
  2382. {
  2383. var dlg = new FilenameDialog(editorUi, layer.value || mxResources.get('background'), mxResources.get('rename'), mxUtils.bind(this, function(newValue)
  2384. {
  2385. if (newValue != null)
  2386. {
  2387. graph.getModel().setValue(layer, newValue);
  2388. }
  2389. }), mxResources.get('enterName'));
  2390. editorUi.showDialog(dlg.container, 300, 100, true, true);
  2391. dlg.init();
  2392. }
  2393. };
  2394. mxEvent.addListener(renameLink, 'click', function(evt)
  2395. {
  2396. if (graph.isEnabled())
  2397. {
  2398. renameLayer(selectionLayer);
  2399. }
  2400. mxEvent.consume(evt);
  2401. });
  2402. if (!graph.isEnabled())
  2403. {
  2404. renameLink.className = 'geButton mxDisabled';
  2405. }
  2406. ldiv.appendChild(renameLink);
  2407. var duplicateLink = link.cloneNode();
  2408. duplicateLink.innerHTML = '<div class="geSprite geSprite-duplicate" style="display:inline-block;"></div>';
  2409. mxEvent.addListener(duplicateLink, 'click', function(evt)
  2410. {
  2411. if (graph.isEnabled())
  2412. {
  2413. var newCell = null;
  2414. graph.model.beginUpdate();
  2415. try
  2416. {
  2417. newCell = graph.cloneCells([selectionLayer])[0];
  2418. newCell.value = mxResources.get('untitledLayer');
  2419. newCell.setVisible(true);
  2420. newCell = graph.addCell(newCell, graph.model.root);
  2421. graph.setDefaultParent(newCell);
  2422. }
  2423. finally
  2424. {
  2425. graph.model.endUpdate();
  2426. }
  2427. if (newCell != null && !graph.isCellLocked(newCell))
  2428. {
  2429. graph.selectAll(newCell);
  2430. }
  2431. }
  2432. });
  2433. if (!graph.isEnabled())
  2434. {
  2435. duplicateLink.className = 'geButton mxDisabled';
  2436. }
  2437. ldiv.appendChild(duplicateLink);
  2438. var addLink = link.cloneNode();
  2439. addLink.innerHTML = '<div class="geSprite geSprite-plus" style="display:inline-block;"></div>';
  2440. addLink.setAttribute('title', mxResources.get('addLayer'));
  2441. mxEvent.addListener(addLink, 'click', function(evt)
  2442. {
  2443. if (graph.isEnabled())
  2444. {
  2445. graph.model.beginUpdate();
  2446. try
  2447. {
  2448. var cell = graph.addCell(new mxCell(mxResources.get('untitledLayer')), graph.model.root);
  2449. graph.setDefaultParent(cell);
  2450. }
  2451. finally
  2452. {
  2453. graph.model.endUpdate();
  2454. }
  2455. }
  2456. mxEvent.consume(evt);
  2457. });
  2458. if (!graph.isEnabled())
  2459. {
  2460. addLink.className = 'geButton mxDisabled';
  2461. }
  2462. ldiv.appendChild(addLink);
  2463. div.appendChild(ldiv);
  2464. function refresh()
  2465. {
  2466. layerCount = graph.model.getChildCount(graph.model.root)
  2467. listDiv.innerHTML = '';
  2468. function addLayer(index, label, child, defaultParent)
  2469. {
  2470. var ldiv = document.createElement('div');
  2471. ldiv.className = 'geToolbarContainer';
  2472. ldiv.style.overflow = 'hidden';
  2473. ldiv.style.position = 'relative';
  2474. ldiv.style.padding = '4px';
  2475. ldiv.style.height = '22px';
  2476. ldiv.style.display = 'block';
  2477. ldiv.style.backgroundColor = 'whiteSmoke';
  2478. ldiv.style.borderWidth = '0px 0px 1px 0px';
  2479. ldiv.style.borderColor = '#c3c3c3';
  2480. ldiv.style.borderStyle = 'solid';
  2481. ldiv.style.whiteSpace = 'nowrap';
  2482. var left = document.createElement('div');
  2483. left.style.display = 'inline-block';
  2484. left.style.width = '100%';
  2485. left.style.textOverflow = 'ellipsis';
  2486. left.style.overflow = 'hidden';
  2487. mxEvent.addListener(ldiv, 'dragover', function(evt)
  2488. {
  2489. evt.dataTransfer.dropEffect = 'move';
  2490. dropIndex = index;
  2491. evt.stopPropagation();
  2492. evt.preventDefault();
  2493. });
  2494. mxEvent.addListener(ldiv, 'dragstart', function(evt)
  2495. {
  2496. dragSource = ldiv;
  2497. // Workaround for no DnD on DIV in FF
  2498. if (mxClient.IS_FF)
  2499. {
  2500. // LATER: Check what triggers a parse as XML on this in FF after drop
  2501. evt.dataTransfer.setData('Text', '<layer/>');
  2502. }
  2503. });
  2504. mxEvent.addListener(ldiv, 'dragend', function(evt)
  2505. {
  2506. if (dragSource != null && dropIndex != null)
  2507. {
  2508. graph.addCell(child, graph.model.root, dropIndex);
  2509. }
  2510. dragSource = null;
  2511. dropIndex = null;
  2512. evt.stopPropagation();
  2513. evt.preventDefault();
  2514. });
  2515. var btn = document.createElement('img');
  2516. btn.setAttribute('draggable', 'false');
  2517. btn.setAttribute('align', 'top');
  2518. btn.setAttribute('border', '0');
  2519. btn.style.cursor = 'pointer';
  2520. btn.style.padding = '4px';
  2521. btn.setAttribute('title', mxResources.get('lockUnlock'));
  2522. var state = graph.view.getState(child);
  2523. var style = (state != null) ? state.style : graph.getCellStyle(child);
  2524. if (mxUtils.getValue(style, 'locked', '0') == '1')
  2525. {
  2526. btn.setAttribute('src', Dialog.prototype.lockedImage);
  2527. }
  2528. else
  2529. {
  2530. btn.setAttribute('src', Dialog.prototype.unlockedImage);
  2531. }
  2532. mxEvent.addListener(btn, 'click', function(evt)
  2533. {
  2534. if (graph.isEnabled())
  2535. {
  2536. var value = null;
  2537. graph.getModel().beginUpdate();
  2538. try
  2539. {
  2540. value = (mxUtils.getValue(style, 'locked', '0') == '1') ? null : '1';
  2541. graph.setCellStyles('locked', value, [child]);
  2542. }
  2543. finally
  2544. {
  2545. graph.getModel().endUpdate();
  2546. }
  2547. if (value == '1')
  2548. {
  2549. graph.removeSelectionCells(graph.getModel().getDescendants(child));
  2550. }
  2551. mxEvent.consume(evt);
  2552. }
  2553. });
  2554. left.appendChild(btn);
  2555. var inp = document.createElement('input');
  2556. inp.setAttribute('type', 'checkbox');
  2557. inp.setAttribute('title', mxResources.get('hideIt', [child.value || mxResources.get('background')]));
  2558. inp.style.marginLeft = '4px';
  2559. inp.style.marginRight = '6px';
  2560. inp.style.marginTop = '4px';
  2561. left.appendChild(inp);
  2562. if (!graph.isEnabled())
  2563. {
  2564. inp.setAttribute('disabled', 'disabled');
  2565. }
  2566. if (graph.model.isVisible(child))
  2567. {
  2568. inp.setAttribute('checked', 'checked');
  2569. inp.defaultChecked = true;
  2570. }
  2571. mxEvent.addListener(inp, 'click', function(evt)
  2572. {
  2573. if (graph.isEnabled())
  2574. {
  2575. graph.model.setVisible(child, !graph.model.isVisible(child));
  2576. mxEvent.consume(evt);
  2577. }
  2578. });
  2579. mxUtils.write(left, label);
  2580. ldiv.appendChild(left);
  2581. if (graph.isEnabled())
  2582. {
  2583. // Fallback if no drag and drop is available
  2584. if (mxClient.IS_TOUCH || mxClient.IS_POINTER || mxClient.IS_VML ||
  2585. (mxClient.IS_IE && document.documentMode < 10))
  2586. {
  2587. var right = document.createElement('div');
  2588. right.style.display = 'block';
  2589. right.style.textAlign = 'right';
  2590. right.style.whiteSpace = 'nowrap';
  2591. right.style.position = 'absolute';
  2592. right.style.right = '6px';
  2593. right.style.top = '6px';
  2594. // Poor man's change layer order
  2595. if (index > 0)
  2596. {
  2597. var img2 = document.createElement('a');
  2598. img2.setAttribute('title', mxResources.get('toBack'));
  2599. img2.className = 'geButton';
  2600. img2.style.cssFloat = 'none';
  2601. img2.innerHTML = '&#9660;';
  2602. img2.style.width = '14px';
  2603. img2.style.height = '14px';
  2604. img2.style.fontSize = '14px';
  2605. img2.style.margin = '0px';
  2606. img2.style.marginTop = '-1px';
  2607. right.appendChild(img2);
  2608. mxEvent.addListener(img2, 'click', function(evt)
  2609. {
  2610. if (graph.isEnabled())
  2611. {
  2612. graph.addCell(child, graph.model.root, index - 1);
  2613. }
  2614. mxEvent.consume(evt);
  2615. });
  2616. }
  2617. if (index >= 0 && index < layerCount - 1)
  2618. {
  2619. var img1 = document.createElement('a');
  2620. img1.setAttribute('title', mxResources.get('toFront'));
  2621. img1.className = 'geButton';
  2622. img1.style.cssFloat = 'none';
  2623. img1.innerHTML = '&#9650;';
  2624. img1.style.width = '14px';
  2625. img1.style.height = '14px';
  2626. img1.style.fontSize = '14px';
  2627. img1.style.margin = '0px';
  2628. img1.style.marginTop = '-1px';
  2629. right.appendChild(img1);
  2630. mxEvent.addListener(img1, 'click', function(evt)
  2631. {
  2632. if (graph.isEnabled())
  2633. {
  2634. graph.addCell(child, graph.model.root, index + 1);
  2635. }
  2636. mxEvent.consume(evt);
  2637. });
  2638. }
  2639. ldiv.appendChild(right);
  2640. }
  2641. if (mxClient.IS_SVG && (!mxClient.IS_IE || document.documentMode >= 10))
  2642. {
  2643. ldiv.setAttribute('draggable', 'true');
  2644. ldiv.style.cursor = 'move';
  2645. }
  2646. }
  2647. mxEvent.addListener(ldiv, 'dblclick', function(evt)
  2648. {
  2649. var nodeName = mxEvent.getSource(evt).nodeName;
  2650. if (nodeName != 'INPUT' && nodeName != 'IMG')
  2651. {
  2652. renameLayer(child);
  2653. mxEvent.consume(evt);
  2654. }
  2655. });
  2656. if (graph.getDefaultParent() == child)
  2657. {
  2658. ldiv.style.background = '#e6eff8';
  2659. ldiv.style.fontWeight = 'bold';
  2660. selectionLayer = child;
  2661. }
  2662. else
  2663. {
  2664. mxEvent.addListener(ldiv, 'click', function(evt)
  2665. {
  2666. if (graph.isEnabled())
  2667. {
  2668. graph.setDefaultParent(defaultParent);
  2669. graph.view.setCurrentRoot(null);
  2670. refresh();
  2671. }
  2672. });
  2673. }
  2674. listDiv.appendChild(ldiv);
  2675. };
  2676. // Cannot be moved or deleted
  2677. for (var i = layerCount - 1; i >= 0; i--)
  2678. {
  2679. (mxUtils.bind(this, function(child)
  2680. {
  2681. addLayer(i, child.value || mxResources.get('background'), child, child);
  2682. }))(graph.model.getChildAt(graph.model.root, i));
  2683. }
  2684. removeLink.setAttribute('title', mxResources.get('removeIt', [selectionLayer.value || mxResources.get('background')]));
  2685. insertLink.setAttribute('title', mxResources.get('moveSelectionTo', [selectionLayer.value || mxResources.get('background')]));
  2686. duplicateLink.setAttribute('title', mxResources.get('duplicateIt', [selectionLayer.value || mxResources.get('background')]));
  2687. renameLink.setAttribute('title', mxResources.get('renameIt', [selectionLayer.value || mxResources.get('background')]));
  2688. if (graph.isSelectionEmpty())
  2689. {
  2690. insertLink.className = 'geButton mxDisabled';
  2691. }
  2692. };
  2693. refresh();
  2694. graph.model.addListener(mxEvent.CHANGE, function()
  2695. {
  2696. refresh();
  2697. });
  2698. graph.selectionModel.addListener(mxEvent.CHANGE, function()
  2699. {
  2700. if (graph.isSelectionEmpty())
  2701. {
  2702. insertLink.className = 'geButton mxDisabled';
  2703. }
  2704. else
  2705. {
  2706. insertLink.className = 'geButton';
  2707. }
  2708. });
  2709. this.window = new mxWindow(mxResources.get('layers'), div, x, y, w, h, true, true);
  2710. this.window.destroyOnClose = false;
  2711. this.window.setMaximizable(false);
  2712. this.window.setResizable(true);
  2713. this.window.setClosable(true);
  2714. this.window.setVisible(true);
  2715. // Make refresh available via instance
  2716. this.refreshLayers = refresh;
  2717. this.window.setLocation = function(x, y)
  2718. {
  2719. x = Math.max(0, x);
  2720. y = Math.max(0, y);
  2721. mxWindow.prototype.setLocation.apply(this, arguments);
  2722. };
  2723. mxEvent.addListener(window, 'resize', mxUtils.bind(this, function()
  2724. {
  2725. var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  2726. var ih = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  2727. var x = this.window.getX();
  2728. var y = this.window.getY();
  2729. if (x + this.window.table.clientWidth > iw)
  2730. {
  2731. x = Math.max(0, iw - this.window.table.clientWidth);
  2732. }
  2733. if (y + this.window.table.clientHeight > ih)
  2734. {
  2735. y = Math.max(0, ih - this.window.table.clientHeight);
  2736. }
  2737. if (this.window.getX() != x || this.window.getY() != y)
  2738. {
  2739. this.window.setLocation(x, y);
  2740. }
  2741. }));
  2742. };