Dialogs.js 86 KB

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