Dialogs.js 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347
  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.addGestureListeners(this.bg, null, null, mxUtils.bind(this, function(evt)
  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, title)
  783. {
  784. this.create(editorUi, title);
  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, cancelFn)
  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.whiteSpace = 'nowrap';
  1029. td.style.fontSize = '10pt';
  1030. td.style.width = '120px';
  1031. mxUtils.write(td, (label || mxResources.get('filename')) + ':');
  1032. row.appendChild(td);
  1033. var nameInput = document.createElement('input');
  1034. nameInput.setAttribute('value', filename || '');
  1035. nameInput.style.marginLeft = '4px';
  1036. nameInput.style.width = '180px';
  1037. var genericBtn = mxUtils.button(buttonText, function()
  1038. {
  1039. if (validateFn == null || validateFn(nameInput.value))
  1040. {
  1041. if (closeOnBtn)
  1042. {
  1043. editorUi.hideDialog();
  1044. }
  1045. fn(nameInput.value);
  1046. }
  1047. });
  1048. genericBtn.className = 'geBtn gePrimaryBtn';
  1049. this.init = function()
  1050. {
  1051. if (label == null && content != null)
  1052. {
  1053. return;
  1054. }
  1055. nameInput.focus();
  1056. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1057. {
  1058. nameInput.select();
  1059. }
  1060. else
  1061. {
  1062. document.execCommand('selectAll', false, null);
  1063. }
  1064. // Installs drag and drop handler for links
  1065. if (Graph.fileSupport)
  1066. {
  1067. // Setup the dnd listeners
  1068. var dlg = table.parentNode;
  1069. var graph = editorUi.editor.graph;
  1070. var dropElt = null;
  1071. mxEvent.addListener(dlg, 'dragleave', function(evt)
  1072. {
  1073. if (dropElt != null)
  1074. {
  1075. dropElt.style.backgroundColor = '';
  1076. dropElt = null;
  1077. }
  1078. evt.stopPropagation();
  1079. evt.preventDefault();
  1080. });
  1081. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  1082. {
  1083. // IE 10 does not implement pointer-events so it can't have a drop highlight
  1084. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  1085. {
  1086. dropElt = nameInput;
  1087. dropElt.style.backgroundColor = '#ebf2f9';
  1088. }
  1089. evt.stopPropagation();
  1090. evt.preventDefault();
  1091. }));
  1092. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  1093. {
  1094. if (dropElt != null)
  1095. {
  1096. dropElt.style.backgroundColor = '';
  1097. dropElt = null;
  1098. }
  1099. if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  1100. {
  1101. nameInput.value = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
  1102. genericBtn.click();
  1103. }
  1104. evt.stopPropagation();
  1105. evt.preventDefault();
  1106. }));
  1107. }
  1108. };
  1109. td = document.createElement('td');
  1110. td.appendChild(nameInput);
  1111. row.appendChild(td);
  1112. if (label != null || content == null)
  1113. {
  1114. tbody.appendChild(row);
  1115. }
  1116. if (content != null)
  1117. {
  1118. row = document.createElement('tr');
  1119. td = document.createElement('td');
  1120. td.colSpan = 2;
  1121. td.appendChild(content);
  1122. row.appendChild(td);
  1123. tbody.appendChild(row);
  1124. }
  1125. row = document.createElement('tr');
  1126. td = document.createElement('td');
  1127. td.colSpan = 2;
  1128. td.style.paddingTop = '20px';
  1129. td.style.whiteSpace = 'nowrap';
  1130. td.setAttribute('align', 'right');
  1131. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1132. {
  1133. editorUi.hideDialog();
  1134. if (cancelFn != null)
  1135. {
  1136. cancelFn();
  1137. }
  1138. });
  1139. cancelBtn.className = 'geBtn';
  1140. if (editorUi.editor.cancelFirst)
  1141. {
  1142. td.appendChild(cancelBtn);
  1143. }
  1144. if (helpLink != null)
  1145. {
  1146. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  1147. {
  1148. window.open(helpLink);
  1149. });
  1150. helpBtn.className = 'geBtn';
  1151. td.appendChild(helpBtn);
  1152. }
  1153. mxEvent.addListener(nameInput, 'keypress', function(e)
  1154. {
  1155. if (e.keyCode == 13)
  1156. {
  1157. genericBtn.click();
  1158. }
  1159. });
  1160. td.appendChild(genericBtn);
  1161. if (!editorUi.editor.cancelFirst)
  1162. {
  1163. td.appendChild(cancelBtn);
  1164. }
  1165. row.appendChild(td);
  1166. tbody.appendChild(row);
  1167. table.appendChild(tbody);
  1168. this.container = table;
  1169. };
  1170. /**
  1171. * Constructs a new textarea dialog.
  1172. */
  1173. var TextareaDialog = function(editorUi, title, url, fn, cancelFn, cancelTitle, w, h, addButtons, noHide, noWrap, applyTitle)
  1174. {
  1175. w = (w != null) ? w : 300;
  1176. h = (h != null) ? h : 120;
  1177. noHide = (noHide != null) ? noHide : false;
  1178. var row, td;
  1179. var table = document.createElement('table');
  1180. var tbody = document.createElement('tbody');
  1181. row = document.createElement('tr');
  1182. td = document.createElement('td');
  1183. td.style.fontSize = '10pt';
  1184. td.style.width = '100px';
  1185. mxUtils.write(td, title);
  1186. row.appendChild(td);
  1187. tbody.appendChild(row);
  1188. row = document.createElement('tr');
  1189. td = document.createElement('td');
  1190. var nameInput = document.createElement('textarea');
  1191. if (noWrap)
  1192. {
  1193. nameInput.setAttribute('wrap', 'off');
  1194. }
  1195. mxUtils.write(nameInput, url || '');
  1196. nameInput.style.resize = 'none';
  1197. nameInput.style.width = w + 'px';
  1198. nameInput.style.height = h + 'px';
  1199. this.textarea = nameInput;
  1200. this.init = function()
  1201. {
  1202. nameInput.focus();
  1203. nameInput.scrollTop = 0;
  1204. };
  1205. td.appendChild(nameInput);
  1206. row.appendChild(td);
  1207. tbody.appendChild(row);
  1208. row = document.createElement('tr');
  1209. td = document.createElement('td');
  1210. td.style.paddingTop = '14px';
  1211. td.style.whiteSpace = 'nowrap';
  1212. td.setAttribute('align', 'right');
  1213. var cancelBtn = mxUtils.button(cancelTitle || mxResources.get('cancel'), function()
  1214. {
  1215. editorUi.hideDialog();
  1216. if (cancelFn != null)
  1217. {
  1218. cancelFn();
  1219. }
  1220. });
  1221. cancelBtn.className = 'geBtn';
  1222. if (editorUi.editor.cancelFirst)
  1223. {
  1224. td.appendChild(cancelBtn);
  1225. }
  1226. if (addButtons != null)
  1227. {
  1228. addButtons(td);
  1229. }
  1230. if (fn != null)
  1231. {
  1232. var genericBtn = mxUtils.button(applyTitle || mxResources.get('apply'), function()
  1233. {
  1234. if (!noHide)
  1235. {
  1236. editorUi.hideDialog();
  1237. }
  1238. fn(nameInput.value);
  1239. });
  1240. genericBtn.className = 'geBtn gePrimaryBtn';
  1241. td.appendChild(genericBtn);
  1242. }
  1243. if (!editorUi.editor.cancelFirst)
  1244. {
  1245. td.appendChild(cancelBtn);
  1246. }
  1247. row.appendChild(td);
  1248. tbody.appendChild(row);
  1249. table.appendChild(tbody);
  1250. this.container = table;
  1251. };
  1252. /**
  1253. * Constructs a new edit file dialog.
  1254. */
  1255. var EditDiagramDialog = function(editorUi)
  1256. {
  1257. var div = document.createElement('div');
  1258. div.style.textAlign = 'right';
  1259. var textarea = document.createElement('textarea');
  1260. textarea.setAttribute('wrap', 'off');
  1261. textarea.style.overflow = 'auto';
  1262. textarea.style.resize = 'none';
  1263. textarea.style.width = '600px';
  1264. textarea.style.height = '370px';
  1265. textarea.style.marginBottom = '16px';
  1266. textarea.value = mxUtils.getPrettyXml(editorUi.editor.getGraphXml());
  1267. div.appendChild(textarea);
  1268. this.init = function()
  1269. {
  1270. textarea.focus();
  1271. };
  1272. // Enables dropping files
  1273. if (Graph.fileSupport)
  1274. {
  1275. function handleDrop(evt)
  1276. {
  1277. evt.stopPropagation();
  1278. evt.preventDefault();
  1279. if (evt.dataTransfer.files.length > 0)
  1280. {
  1281. var file = evt.dataTransfer.files[0];
  1282. var reader = new FileReader();
  1283. reader.onload = function(e)
  1284. {
  1285. textarea.value = e.target.result;
  1286. };
  1287. reader.readAsText(file);
  1288. }
  1289. else
  1290. {
  1291. textarea.value = editorUi.extractGraphModelFromEvent(evt);
  1292. }
  1293. };
  1294. function handleDragOver(evt)
  1295. {
  1296. evt.stopPropagation();
  1297. evt.preventDefault();
  1298. };
  1299. // Setup the dnd listeners.
  1300. textarea.addEventListener('dragover', handleDragOver, false);
  1301. textarea.addEventListener('drop', handleDrop, false);
  1302. }
  1303. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1304. {
  1305. editorUi.hideDialog();
  1306. });
  1307. cancelBtn.className = 'geBtn';
  1308. if (editorUi.editor.cancelFirst)
  1309. {
  1310. div.appendChild(cancelBtn);
  1311. }
  1312. var select = document.createElement('select');
  1313. select.style.width = '180px';
  1314. select.className = 'geBtn';
  1315. if (editorUi.editor.graph.isEnabled())
  1316. {
  1317. var replaceOption = document.createElement('option');
  1318. replaceOption.setAttribute('value', 'replace');
  1319. mxUtils.write(replaceOption, mxResources.get('replaceExistingDrawing'));
  1320. select.appendChild(replaceOption);
  1321. }
  1322. var newOption = document.createElement('option');
  1323. newOption.setAttribute('value', 'new');
  1324. mxUtils.write(newOption, mxResources.get('openInNewWindow'));
  1325. var chromeApp = window.chrome != null && chrome.app != null && chrome.app.runtime != null;
  1326. if (!chromeApp)
  1327. {
  1328. select.appendChild(newOption);
  1329. }
  1330. if (editorUi.editor.graph.isEnabled())
  1331. {
  1332. var importOption = document.createElement('option');
  1333. importOption.setAttribute('value', 'import');
  1334. mxUtils.write(importOption, mxResources.get('addToExistingDrawing'));
  1335. select.appendChild(importOption);
  1336. }
  1337. div.appendChild(select);
  1338. var okBtn = mxUtils.button(mxResources.get('ok'), function()
  1339. {
  1340. // Removes all illegal control characters before parsing
  1341. var data = editorUi.editor.graph.zapGremlins(mxUtils.trim(textarea.value));
  1342. var error = null;
  1343. if (select.value == 'new')
  1344. {
  1345. window.openFile = new OpenFile(function()
  1346. {
  1347. editorUi.hideDialog();
  1348. window.openFile = null;
  1349. });
  1350. window.openFile.setData(data, null);
  1351. window.open(editorUi.getUrl());
  1352. }
  1353. else if (select.value == 'replace')
  1354. {
  1355. editorUi.editor.graph.model.beginUpdate();
  1356. try
  1357. {
  1358. editorUi.editor.setGraphXml(mxUtils.parseXml(data).documentElement);
  1359. // LATER: Why is hideDialog between begin-/endUpdate faster?
  1360. editorUi.hideDialog();
  1361. }
  1362. catch (e)
  1363. {
  1364. error = e;
  1365. }
  1366. finally
  1367. {
  1368. editorUi.editor.graph.model.endUpdate();
  1369. }
  1370. }
  1371. else if (select.value == 'import')
  1372. {
  1373. editorUi.editor.graph.model.beginUpdate();
  1374. try
  1375. {
  1376. var doc = mxUtils.parseXml(data);
  1377. var model = new mxGraphModel();
  1378. var codec = new mxCodec(doc);
  1379. codec.decode(doc.documentElement, model);
  1380. var children = model.getChildren(model.getChildAt(model.getRoot(), 0));
  1381. editorUi.editor.graph.setSelectionCells(editorUi.editor.graph.importCells(children));
  1382. // LATER: Why is hideDialog between begin-/endUpdate faster?
  1383. editorUi.hideDialog();
  1384. }
  1385. catch (e)
  1386. {
  1387. error = e;
  1388. }
  1389. finally
  1390. {
  1391. editorUi.editor.graph.model.endUpdate();
  1392. }
  1393. }
  1394. if (error != null)
  1395. {
  1396. mxUtils.alert(error.message);
  1397. }
  1398. });
  1399. okBtn.className = 'geBtn gePrimaryBtn';
  1400. div.appendChild(okBtn);
  1401. if (!editorUi.editor.cancelFirst)
  1402. {
  1403. div.appendChild(cancelBtn);
  1404. }
  1405. this.container = div;
  1406. };
  1407. /**
  1408. * Constructs a new export dialog.
  1409. */
  1410. var ExportDialog = function(editorUi)
  1411. {
  1412. var graph = editorUi.editor.graph;
  1413. var bounds = graph.getGraphBounds();
  1414. var scale = graph.view.scale;
  1415. var width = Math.ceil(bounds.width / scale);
  1416. var height = Math.ceil(bounds.height / scale);
  1417. var row, td;
  1418. var table = document.createElement('table');
  1419. var tbody = document.createElement('tbody');
  1420. table.setAttribute('cellpadding', (mxClient.IS_SF) ? '0' : '2');
  1421. row = document.createElement('tr');
  1422. td = document.createElement('td');
  1423. td.style.fontSize = '10pt';
  1424. td.style.width = '100px';
  1425. mxUtils.write(td, mxResources.get('filename') + ':');
  1426. row.appendChild(td);
  1427. var nameInput = document.createElement('input');
  1428. nameInput.setAttribute('value', editorUi.editor.getOrCreateFilename());
  1429. nameInput.style.width = '180px';
  1430. td = document.createElement('td');
  1431. td.appendChild(nameInput);
  1432. row.appendChild(td);
  1433. tbody.appendChild(row);
  1434. row = document.createElement('tr');
  1435. td = document.createElement('td');
  1436. td.style.fontSize = '10pt';
  1437. mxUtils.write(td, mxResources.get('format') + ':');
  1438. row.appendChild(td);
  1439. var imageFormatSelect = document.createElement('select');
  1440. imageFormatSelect.style.width = '180px';
  1441. var pngOption = document.createElement('option');
  1442. pngOption.setAttribute('value', 'png');
  1443. mxUtils.write(pngOption, mxResources.get('formatPng'));
  1444. imageFormatSelect.appendChild(pngOption);
  1445. var gifOption = document.createElement('option');
  1446. if (ExportDialog.showGifOption)
  1447. {
  1448. gifOption.setAttribute('value', 'gif');
  1449. mxUtils.write(gifOption, mxResources.get('formatGif'));
  1450. imageFormatSelect.appendChild(gifOption);
  1451. }
  1452. var jpgOption = document.createElement('option');
  1453. jpgOption.setAttribute('value', 'jpg');
  1454. mxUtils.write(jpgOption, mxResources.get('formatJpg'));
  1455. imageFormatSelect.appendChild(jpgOption);
  1456. var pdfOption = document.createElement('option');
  1457. pdfOption.setAttribute('value', 'pdf');
  1458. mxUtils.write(pdfOption, mxResources.get('formatPdf'));
  1459. imageFormatSelect.appendChild(pdfOption);
  1460. var svgOption = document.createElement('option');
  1461. svgOption.setAttribute('value', 'svg');
  1462. mxUtils.write(svgOption, mxResources.get('formatSvg'));
  1463. imageFormatSelect.appendChild(svgOption);
  1464. if (ExportDialog.showXmlOption)
  1465. {
  1466. var xmlOption = document.createElement('option');
  1467. xmlOption.setAttribute('value', 'xml');
  1468. mxUtils.write(xmlOption, mxResources.get('formatXml'));
  1469. imageFormatSelect.appendChild(xmlOption);
  1470. }
  1471. td = document.createElement('td');
  1472. td.appendChild(imageFormatSelect);
  1473. row.appendChild(td);
  1474. tbody.appendChild(row);
  1475. row = document.createElement('tr');
  1476. td = document.createElement('td');
  1477. td.style.fontSize = '10pt';
  1478. mxUtils.write(td, mxResources.get('zoom') + ' (%):');
  1479. row.appendChild(td);
  1480. var zoomInput = document.createElement('input');
  1481. zoomInput.setAttribute('type', 'number');
  1482. zoomInput.setAttribute('value', '100');
  1483. zoomInput.style.width = '180px';
  1484. td = document.createElement('td');
  1485. td.appendChild(zoomInput);
  1486. row.appendChild(td);
  1487. tbody.appendChild(row);
  1488. row = document.createElement('tr');
  1489. td = document.createElement('td');
  1490. td.style.fontSize = '10pt';
  1491. mxUtils.write(td, mxResources.get('width') + ':');
  1492. row.appendChild(td);
  1493. var widthInput = document.createElement('input');
  1494. widthInput.setAttribute('value', width);
  1495. widthInput.style.width = '180px';
  1496. td = document.createElement('td');
  1497. td.appendChild(widthInput);
  1498. row.appendChild(td);
  1499. tbody.appendChild(row);
  1500. row = document.createElement('tr');
  1501. td = document.createElement('td');
  1502. td.style.fontSize = '10pt';
  1503. mxUtils.write(td, mxResources.get('height') + ':');
  1504. row.appendChild(td);
  1505. var heightInput = document.createElement('input');
  1506. heightInput.setAttribute('value', height);
  1507. heightInput.style.width = '180px';
  1508. td = document.createElement('td');
  1509. td.appendChild(heightInput);
  1510. row.appendChild(td);
  1511. tbody.appendChild(row);
  1512. row = document.createElement('tr');
  1513. td = document.createElement('td');
  1514. td.style.fontSize = '10pt';
  1515. mxUtils.write(td, mxResources.get('background') + ':');
  1516. row.appendChild(td);
  1517. var transparentCheckbox = document.createElement('input');
  1518. transparentCheckbox.setAttribute('type', 'checkbox');
  1519. transparentCheckbox.checked = graph.background == null || graph.background == mxConstants.NONE;
  1520. td = document.createElement('td');
  1521. td.appendChild(transparentCheckbox);
  1522. mxUtils.write(td, mxResources.get('transparent'));
  1523. row.appendChild(td);
  1524. tbody.appendChild(row);
  1525. row = document.createElement('tr');
  1526. td = document.createElement('td');
  1527. td.style.fontSize = '10pt';
  1528. mxUtils.write(td, mxResources.get('borderWidth') + ':');
  1529. row.appendChild(td);
  1530. var borderInput = document.createElement('input');
  1531. borderInput.setAttribute('type', 'number');
  1532. borderInput.setAttribute('value', ExportDialog.lastBorderValue);
  1533. borderInput.style.width = '180px';
  1534. td = document.createElement('td');
  1535. td.appendChild(borderInput);
  1536. row.appendChild(td);
  1537. tbody.appendChild(row);
  1538. table.appendChild(tbody);
  1539. // Handles changes in the export format
  1540. function formatChanged()
  1541. {
  1542. var name = nameInput.value;
  1543. var dot = name.lastIndexOf('.');
  1544. if (dot > 0)
  1545. {
  1546. nameInput.value = name.substring(0, dot + 1) + imageFormatSelect.value;
  1547. }
  1548. else
  1549. {
  1550. nameInput.value = name + '.' + imageFormatSelect.value;
  1551. }
  1552. if (imageFormatSelect.value === 'xml')
  1553. {
  1554. zoomInput.setAttribute('disabled', 'true');
  1555. widthInput.setAttribute('disabled', 'true');
  1556. heightInput.setAttribute('disabled', 'true');
  1557. borderInput.setAttribute('disabled', 'true');
  1558. }
  1559. else
  1560. {
  1561. zoomInput.removeAttribute('disabled');
  1562. widthInput.removeAttribute('disabled');
  1563. heightInput.removeAttribute('disabled');
  1564. borderInput.removeAttribute('disabled');
  1565. }
  1566. if (imageFormatSelect.value === 'png' || imageFormatSelect.value === 'svg')
  1567. {
  1568. transparentCheckbox.removeAttribute('disabled');
  1569. }
  1570. else
  1571. {
  1572. transparentCheckbox.setAttribute('disabled', 'disabled');
  1573. }
  1574. };
  1575. mxEvent.addListener(imageFormatSelect, 'change', formatChanged);
  1576. formatChanged();
  1577. function checkValues()
  1578. {
  1579. if (widthInput.value * heightInput.value > MAX_AREA || widthInput.value <= 0)
  1580. {
  1581. widthInput.style.backgroundColor = 'red';
  1582. }
  1583. else
  1584. {
  1585. widthInput.style.backgroundColor = '';
  1586. }
  1587. if (widthInput.value * heightInput.value > MAX_AREA || heightInput.value <= 0)
  1588. {
  1589. heightInput.style.backgroundColor = 'red';
  1590. }
  1591. else
  1592. {
  1593. heightInput.style.backgroundColor = '';
  1594. }
  1595. };
  1596. mxEvent.addListener(zoomInput, 'change', function()
  1597. {
  1598. var s = Math.max(0, parseFloat(zoomInput.value) || 100) / 100;
  1599. zoomInput.value = parseFloat((s * 100).toFixed(2));
  1600. if (width > 0)
  1601. {
  1602. widthInput.value = Math.floor(width * s);
  1603. heightInput.value = Math.floor(height * s);
  1604. }
  1605. else
  1606. {
  1607. zoomInput.value = '100';
  1608. widthInput.value = width;
  1609. heightInput.value = height;
  1610. }
  1611. checkValues();
  1612. });
  1613. mxEvent.addListener(widthInput, 'change', function()
  1614. {
  1615. var s = parseInt(widthInput.value) / width;
  1616. if (s > 0)
  1617. {
  1618. zoomInput.value = parseFloat((s * 100).toFixed(2));
  1619. heightInput.value = Math.floor(height * s);
  1620. }
  1621. else
  1622. {
  1623. zoomInput.value = '100';
  1624. widthInput.value = width;
  1625. heightInput.value = height;
  1626. }
  1627. checkValues();
  1628. });
  1629. mxEvent.addListener(heightInput, 'change', function()
  1630. {
  1631. var s = parseInt(heightInput.value) / height;
  1632. if (s > 0)
  1633. {
  1634. zoomInput.value = parseFloat((s * 100).toFixed(2));
  1635. widthInput.value = Math.floor(width * s);
  1636. }
  1637. else
  1638. {
  1639. zoomInput.value = '100';
  1640. widthInput.value = width;
  1641. heightInput.value = height;
  1642. }
  1643. checkValues();
  1644. });
  1645. row = document.createElement('tr');
  1646. td = document.createElement('td');
  1647. td.setAttribute('align', 'right');
  1648. td.style.paddingTop = '22px';
  1649. td.colSpan = 2;
  1650. var saveBtn = mxUtils.button(mxResources.get('export'), mxUtils.bind(this, function()
  1651. {
  1652. if (parseInt(zoomInput.value) <= 0)
  1653. {
  1654. mxUtils.alert(mxResources.get('drawingEmpty'));
  1655. }
  1656. else
  1657. {
  1658. var name = nameInput.value;
  1659. var format = imageFormatSelect.value;
  1660. var s = Math.max(0, parseFloat(zoomInput.value) || 100) / 100;
  1661. var b = Math.max(0, parseInt(borderInput.value));
  1662. var bg = graph.background;
  1663. if ((format == 'svg' || format == 'png') && transparentCheckbox.checked)
  1664. {
  1665. bg = null;
  1666. }
  1667. else if (bg == null || bg == mxConstants.NONE)
  1668. {
  1669. bg = '#ffffff';
  1670. }
  1671. ExportDialog.lastBorderValue = b;
  1672. ExportDialog.exportFile(editorUi, name, format, bg, s, b);
  1673. }
  1674. }));
  1675. saveBtn.className = 'geBtn gePrimaryBtn';
  1676. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1677. {
  1678. editorUi.hideDialog();
  1679. });
  1680. cancelBtn.className = 'geBtn';
  1681. if (editorUi.editor.cancelFirst)
  1682. {
  1683. td.appendChild(cancelBtn);
  1684. td.appendChild(saveBtn);
  1685. }
  1686. else
  1687. {
  1688. td.appendChild(saveBtn);
  1689. td.appendChild(cancelBtn);
  1690. }
  1691. row.appendChild(td);
  1692. tbody.appendChild(row);
  1693. table.appendChild(tbody);
  1694. this.container = table;
  1695. };
  1696. /**
  1697. * Remembers last value for border.
  1698. */
  1699. ExportDialog.lastBorderValue = 0;
  1700. /**
  1701. * Global switches for the export dialog.
  1702. */
  1703. ExportDialog.showGifOption = true;
  1704. /**
  1705. * Global switches for the export dialog.
  1706. */
  1707. ExportDialog.showXmlOption = true;
  1708. /**
  1709. * Hook for getting the export format. Returns null for the default
  1710. * intermediate XML export format or a function that returns the
  1711. * parameter and value to be used in the request in the form
  1712. * key=value, where value should be URL encoded.
  1713. */
  1714. ExportDialog.exportFile = function(editorUi, name, format, bg, s, b)
  1715. {
  1716. var graph = editorUi.editor.graph;
  1717. if (format == 'xml')
  1718. {
  1719. ExportDialog.saveLocalFile(editorUi, mxUtils.getXml(editorUi.editor.getGraphXml()), name, format);
  1720. }
  1721. else if (format == 'svg')
  1722. {
  1723. ExportDialog.saveLocalFile(editorUi, mxUtils.getXml(graph.getSvg(bg, s, b)), name, format);
  1724. }
  1725. else
  1726. {
  1727. var bounds = graph.getGraphBounds();
  1728. // New image export
  1729. var xmlDoc = mxUtils.createXmlDocument();
  1730. var root = xmlDoc.createElement('output');
  1731. xmlDoc.appendChild(root);
  1732. // Renders graph. Offset will be multiplied with state's scale when painting state.
  1733. var xmlCanvas = new mxXmlCanvas2D(root);
  1734. xmlCanvas.translate(Math.floor((b / s - bounds.x) / graph.view.scale),
  1735. Math.floor((b / s - bounds.y) / graph.view.scale));
  1736. xmlCanvas.scale(s / graph.view.scale);
  1737. var imgExport = new mxImageExport()
  1738. imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
  1739. // Puts request data together
  1740. var param = 'xml=' + encodeURIComponent(mxUtils.getXml(root));
  1741. var w = Math.ceil(bounds.width * s / graph.view.scale + 2 * b);
  1742. var h = Math.ceil(bounds.height * s / graph.view.scale + 2 * b);
  1743. // Requests image if request is valid
  1744. if (param.length <= MAX_REQUEST_SIZE && w * h < MAX_AREA)
  1745. {
  1746. editorUi.hideDialog();
  1747. var req = new mxXmlRequest(EXPORT_URL, 'format=' + format +
  1748. '&filename=' + encodeURIComponent(name) +
  1749. '&bg=' + ((bg != null) ? bg : 'none') +
  1750. '&w=' + w + '&h=' + h + '&' + param);
  1751. req.simulate(document, '_blank');
  1752. }
  1753. else
  1754. {
  1755. mxUtils.alert(mxResources.get('drawingTooLarge'));
  1756. }
  1757. }
  1758. };
  1759. /**
  1760. * Hook for getting the export format. Returns null for the default
  1761. * intermediate XML export format or a function that returns the
  1762. * parameter and value to be used in the request in the form
  1763. * key=value, where value should be URL encoded.
  1764. */
  1765. ExportDialog.saveLocalFile = function(editorUi, data, filename, format)
  1766. {
  1767. if (data.length < MAX_REQUEST_SIZE)
  1768. {
  1769. editorUi.hideDialog();
  1770. var req = new mxXmlRequest(SAVE_URL, 'xml=' + encodeURIComponent(data) + '&filename=' +
  1771. encodeURIComponent(filename) + '&format=' + format);
  1772. req.simulate(document, '_blank');
  1773. }
  1774. else
  1775. {
  1776. mxUtils.alert(mxResources.get('drawingTooLarge'));
  1777. mxUtils.popup(xml);
  1778. }
  1779. };
  1780. /**
  1781. * Constructs a new metadata dialog.
  1782. */
  1783. var EditDataDialog = function(ui, cell)
  1784. {
  1785. var div = document.createElement('div');
  1786. var graph = ui.editor.graph;
  1787. div.style.height = '310px';
  1788. div.style.overflow = 'auto';
  1789. var value = graph.getModel().getValue(cell);
  1790. // Converts the value to an XML node
  1791. if (!mxUtils.isNode(value))
  1792. {
  1793. var doc = mxUtils.createXmlDocument();
  1794. var obj = doc.createElement('object');
  1795. obj.setAttribute('label', value || '');
  1796. value = obj;
  1797. }
  1798. // Creates the dialog contents
  1799. var form = new mxForm('properties');
  1800. form.table.style.width = '100%';
  1801. form.table.style.paddingRight = '20px';
  1802. var attrs = value.attributes;
  1803. var names = [];
  1804. var texts = [];
  1805. var count = 0;
  1806. // FIXME: Fix remove button for quirks mode
  1807. var addRemoveButton = function(text, name)
  1808. {
  1809. text.parentNode.style.marginRight = '12px';
  1810. var removeAttr = document.createElement('a');
  1811. var img = mxUtils.createImage(Dialog.prototype.closeImage);
  1812. img.style.height = '9px';
  1813. img.style.fontSize = '9px';
  1814. img.style.marginBottom = '7px';
  1815. removeAttr.className = 'geButton';
  1816. removeAttr.setAttribute('title', mxResources.get('delete'));
  1817. removeAttr.style.margin = '0px';
  1818. removeAttr.style.width = '14px';
  1819. removeAttr.style.height = '14px';
  1820. removeAttr.style.fontSize = '14px';
  1821. removeAttr.style.cursor = 'pointer';
  1822. removeAttr.style.marginLeft = '6px';
  1823. removeAttr.appendChild(img);
  1824. var removeAttrFn = (function(name)
  1825. {
  1826. return function()
  1827. {
  1828. var count = 0;
  1829. for (var j = 0; j < names.length; j++)
  1830. {
  1831. if (names[j] == name)
  1832. {
  1833. texts[j] = null;
  1834. form.table.deleteRow(count);
  1835. break;
  1836. }
  1837. if (texts[j] != null)
  1838. {
  1839. count++;
  1840. }
  1841. }
  1842. };
  1843. })(name);
  1844. mxEvent.addListener(removeAttr, 'click', removeAttrFn);
  1845. text.parentNode.style.whiteSpace = 'nowrap';
  1846. text.parentNode.appendChild(removeAttr);
  1847. };
  1848. var addTextArea = function(index, name, value)
  1849. {
  1850. names[index] = name;
  1851. texts[index] = form.addTextarea(names[count] + ':', value, 2);
  1852. texts[index].style.width = '100%';
  1853. addRemoveButton(texts[index], name);
  1854. };
  1855. var temp = [];
  1856. for (var i = 0; i < attrs.length; i++)
  1857. {
  1858. if (attrs[i].nodeName != 'label' && attrs[i].nodeName != 'placeholders')
  1859. {
  1860. temp.push({name: attrs[i].nodeName, value: attrs[i].nodeValue});
  1861. }
  1862. }
  1863. // Sorts by name
  1864. temp.sort(function(a, b)
  1865. {
  1866. return ~~(a.name > b.name);
  1867. });
  1868. for (var i = 0; i < temp.length; i++)
  1869. {
  1870. addTextArea(count, temp[i].name, temp[i].value);
  1871. count++;
  1872. }
  1873. div.appendChild(form.table);
  1874. var newProp = document.createElement('div');
  1875. newProp.style.whiteSpace = 'nowrap';
  1876. newProp.style.marginTop = '6px';
  1877. var nameInput = document.createElement('input');
  1878. nameInput.setAttribute('placeholder', mxResources.get('enterPropertyName'));
  1879. nameInput.setAttribute('type', 'text');
  1880. nameInput.setAttribute('size', (mxClient.IS_QUIRKS) ? '18' : '22');
  1881. nameInput.style.marginLeft = '2px';
  1882. newProp.appendChild(nameInput);
  1883. div.appendChild(newProp);
  1884. var addBtn = mxUtils.button(mxResources.get('addProperty'), function()
  1885. {
  1886. var name = nameInput.value;
  1887. if (name.length > 0 && name != 'label' && name != 'placeholders')
  1888. {
  1889. try
  1890. {
  1891. var idx = mxUtils.indexOf(names, name);
  1892. if (idx >= 0 && texts[idx] != null)
  1893. {
  1894. texts[idx].focus();
  1895. }
  1896. else
  1897. {
  1898. // Checks if the name is valid
  1899. var clone = value.cloneNode(false);
  1900. clone.setAttribute(name, '');
  1901. if (idx >= 0)
  1902. {
  1903. names.splice(idx, 1);
  1904. texts.splice(idx, 1);
  1905. }
  1906. names.push(name);
  1907. var text = form.addTextarea(name + ':', '', 2);
  1908. text.style.width = '100%';
  1909. texts.push(text);
  1910. addRemoveButton(text, name);
  1911. text.focus();
  1912. }
  1913. nameInput.value = '';
  1914. }
  1915. catch (e)
  1916. {
  1917. mxUtils.alert(e);
  1918. }
  1919. }
  1920. else
  1921. {
  1922. mxUtils.alert(mxResources.get('invalidName'));
  1923. }
  1924. });
  1925. this.init = function()
  1926. {
  1927. if (texts.length > 0)
  1928. {
  1929. texts[0].focus();
  1930. }
  1931. else
  1932. {
  1933. nameInput.focus();
  1934. }
  1935. };
  1936. addBtn.setAttribute('disabled', 'disabled');
  1937. addBtn.style.marginLeft = '10px';
  1938. addBtn.style.width = '144px';
  1939. newProp.appendChild(addBtn);
  1940. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1941. {
  1942. ui.hideDialog.apply(ui, arguments);
  1943. });
  1944. cancelBtn.className = 'geBtn';
  1945. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  1946. {
  1947. try
  1948. {
  1949. ui.hideDialog.apply(ui, arguments);
  1950. // Clones and updates the value
  1951. value = value.cloneNode(true);
  1952. var removeLabel = false;
  1953. for (var i = 0; i < names.length; i++)
  1954. {
  1955. if (texts[i] == null)
  1956. {
  1957. value.removeAttribute(names[i]);
  1958. }
  1959. else
  1960. {
  1961. value.setAttribute(names[i], texts[i].value);
  1962. removeLabel = removeLabel || (names[i] == 'placeholder' &&
  1963. value.getAttribute('placeholders') == '1');
  1964. }
  1965. }
  1966. // Removes label if placeholder is assigned
  1967. if (removeLabel)
  1968. {
  1969. value.removeAttribute('label');
  1970. }
  1971. // Updates the value of the cell (undoable)
  1972. graph.getModel().setValue(cell, value);
  1973. }
  1974. catch (e)
  1975. {
  1976. mxUtils.alert(e);
  1977. }
  1978. });
  1979. applyBtn.className = 'geBtn gePrimaryBtn';
  1980. function updateAddBtn()
  1981. {
  1982. if (nameInput.value.length > 0)
  1983. {
  1984. addBtn.removeAttribute('disabled');
  1985. }
  1986. else
  1987. {
  1988. addBtn.setAttribute('disabled', 'disabled');
  1989. }
  1990. };
  1991. mxEvent.addListener(nameInput, 'keyup', updateAddBtn);
  1992. // Catches all changes that don't fire a keyup (such as paste via mouse)
  1993. mxEvent.addListener(nameInput, 'change', updateAddBtn);
  1994. var buttons = document.createElement('div');
  1995. buttons.style.marginTop = '18px';
  1996. buttons.style.textAlign = 'right';
  1997. if (ui.editor.graph.getModel().isVertex(cell) || ui.editor.graph.getModel().isEdge(cell))
  1998. {
  1999. var replace = document.createElement('span');
  2000. replace.style.marginRight = '10px';
  2001. var input = document.createElement('input');
  2002. input.setAttribute('type', 'checkbox');
  2003. input.style.marginRight = '6px';
  2004. if (value.getAttribute('placeholders') == '1')
  2005. {
  2006. input.setAttribute('checked', 'checked');
  2007. input.defaultChecked = true;
  2008. }
  2009. mxEvent.addListener(input, 'click', function()
  2010. {
  2011. if (value.getAttribute('placeholders') == '1')
  2012. {
  2013. value.removeAttribute('placeholders');
  2014. }
  2015. else
  2016. {
  2017. value.setAttribute('placeholders', '1');
  2018. }
  2019. });
  2020. replace.appendChild(input);
  2021. mxUtils.write(replace, mxResources.get('placeholders'));
  2022. if (EditDataDialog.placeholderHelpLink != null)
  2023. {
  2024. var link = document.createElement('a');
  2025. link.setAttribute('href', EditDataDialog.placeholderHelpLink);
  2026. link.setAttribute('title', mxResources.get('help'));
  2027. link.setAttribute('target', '_blank');
  2028. link.style.marginLeft = '10px';
  2029. link.style.cursor = 'help';
  2030. var icon = document.createElement('img');
  2031. icon.setAttribute('border', '0');
  2032. icon.setAttribute('valign', 'middle');
  2033. icon.style.marginTop = '-4px';
  2034. icon.setAttribute('src', Editor.helpImage);
  2035. link.appendChild(icon);
  2036. replace.appendChild(link);
  2037. }
  2038. buttons.appendChild(replace);
  2039. }
  2040. if (ui.editor.cancelFirst)
  2041. {
  2042. buttons.appendChild(cancelBtn);
  2043. buttons.appendChild(applyBtn);
  2044. }
  2045. else
  2046. {
  2047. buttons.appendChild(applyBtn);
  2048. buttons.appendChild(cancelBtn);
  2049. }
  2050. div.appendChild(buttons);
  2051. this.container = div;
  2052. };
  2053. /**
  2054. * Optional help link.
  2055. */
  2056. EditDataDialog.placeholderHelpLink = null;
  2057. /**
  2058. * Constructs a new link dialog.
  2059. */
  2060. var LinkDialog = function(editorUi, initialValue, btnLabel, fn)
  2061. {
  2062. var div = document.createElement('div');
  2063. mxUtils.write(div, mxResources.get('editLink') + ':');
  2064. var inner = document.createElement('div');
  2065. inner.className = 'geTitle';
  2066. inner.style.backgroundColor = 'transparent';
  2067. inner.style.borderColor = 'transparent';
  2068. inner.style.whiteSpace = 'nowrap';
  2069. inner.style.textOverflow = 'clip';
  2070. inner.style.cursor = 'default';
  2071. if (!mxClient.IS_VML)
  2072. {
  2073. inner.style.paddingRight = '20px';
  2074. }
  2075. var linkInput = document.createElement('input');
  2076. linkInput.setAttribute('value', initialValue);
  2077. linkInput.setAttribute('placeholder', 'http://www.example.com/');
  2078. linkInput.setAttribute('type', 'text');
  2079. linkInput.style.marginTop = '6px';
  2080. linkInput.style.width = '400px';
  2081. linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
  2082. linkInput.style.backgroundRepeat = 'no-repeat';
  2083. linkInput.style.backgroundPosition = '100% 50%';
  2084. linkInput.style.paddingRight = '14px';
  2085. var cross = document.createElement('div');
  2086. cross.setAttribute('title', mxResources.get('reset'));
  2087. cross.style.position = 'relative';
  2088. cross.style.left = '-16px';
  2089. cross.style.width = '12px';
  2090. cross.style.height = '14px';
  2091. cross.style.cursor = 'pointer';
  2092. // Workaround for inline-block not supported in IE
  2093. cross.style.display = (mxClient.IS_VML) ? 'inline' : 'inline-block';
  2094. cross.style.top = ((mxClient.IS_VML) ? 0 : 3) + 'px';
  2095. // Needed to block event transparency in IE
  2096. cross.style.background = 'url(' + IMAGE_PATH + '/transparent.gif)';
  2097. mxEvent.addListener(cross, 'click', function()
  2098. {
  2099. linkInput.value = '';
  2100. linkInput.focus();
  2101. });
  2102. inner.appendChild(linkInput);
  2103. inner.appendChild(cross);
  2104. div.appendChild(inner);
  2105. this.init = function()
  2106. {
  2107. linkInput.focus();
  2108. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  2109. {
  2110. linkInput.select();
  2111. }
  2112. else
  2113. {
  2114. document.execCommand('selectAll', false, null);
  2115. }
  2116. };
  2117. var btns = document.createElement('div');
  2118. btns.style.marginTop = '18px';
  2119. btns.style.textAlign = 'right';
  2120. mxEvent.addListener(linkInput, 'keypress', function(e)
  2121. {
  2122. if (e.keyCode == 13)
  2123. {
  2124. editorUi.hideDialog();
  2125. fn(linkInput.value);
  2126. }
  2127. });
  2128. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  2129. {
  2130. editorUi.hideDialog();
  2131. });
  2132. cancelBtn.className = 'geBtn';
  2133. if (editorUi.editor.cancelFirst)
  2134. {
  2135. btns.appendChild(cancelBtn);
  2136. }
  2137. var mainBtn = mxUtils.button(btnLabel, function()
  2138. {
  2139. editorUi.hideDialog();
  2140. fn(linkInput.value);
  2141. });
  2142. mainBtn.className = 'geBtn gePrimaryBtn';
  2143. btns.appendChild(mainBtn);
  2144. if (!editorUi.editor.cancelFirst)
  2145. {
  2146. btns.appendChild(cancelBtn);
  2147. }
  2148. div.appendChild(btns);
  2149. this.container = div;
  2150. };
  2151. /**
  2152. *
  2153. */
  2154. var OutlineWindow = function(editorUi, x, y, w, h)
  2155. {
  2156. var graph = editorUi.editor.graph;
  2157. var div = document.createElement('div');
  2158. div.style.position = 'absolute';
  2159. div.style.width = '100%';
  2160. div.style.height = '100%';
  2161. div.style.border = '1px solid whiteSmoke';
  2162. div.style.overflow = 'hidden';
  2163. this.window = new mxWindow(mxResources.get('outline'), div, x, y, w, h, true, true);
  2164. this.window.destroyOnClose = false;
  2165. this.window.setMaximizable(false);
  2166. this.window.setResizable(true);
  2167. this.window.setClosable(true);
  2168. this.window.setVisible(true);
  2169. this.window.setLocation = function(x, y)
  2170. {
  2171. x = Math.max(0, x);
  2172. y = Math.max(0, y);
  2173. mxWindow.prototype.setLocation.apply(this, arguments);
  2174. };
  2175. mxEvent.addListener(window, 'resize', mxUtils.bind(this, function()
  2176. {
  2177. var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  2178. var ih = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  2179. var x = this.window.getX();
  2180. var y = this.window.getY();
  2181. if (x + this.window.table.clientWidth > iw)
  2182. {
  2183. x = Math.max(0, iw - this.window.table.clientWidth);
  2184. }
  2185. if (y + this.window.table.clientHeight > ih)
  2186. {
  2187. y = Math.max(0, ih - this.window.table.clientHeight);
  2188. }
  2189. if (this.window.getX() != x || this.window.getY() != y)
  2190. {
  2191. this.window.setLocation(x, y);
  2192. }
  2193. }));
  2194. var outline = editorUi.createOutline(this.window);
  2195. this.window.addListener(mxEvent.RESIZE, mxUtils.bind(this, function()
  2196. {
  2197. outline.update(false);
  2198. outline.outline.sizeDidChange();
  2199. }));
  2200. this.window.addListener(mxEvent.SHOW, mxUtils.bind(this, function()
  2201. {
  2202. outline.suspended = false;
  2203. outline.outline.refresh();
  2204. outline.update();
  2205. }));
  2206. this.window.addListener(mxEvent.HIDE, mxUtils.bind(this, function()
  2207. {
  2208. outline.suspended = true;
  2209. }));
  2210. this.window.addListener(mxEvent.NORMALIZE, mxUtils.bind(this, function()
  2211. {
  2212. outline.suspended = false;
  2213. outline.update();
  2214. }));
  2215. this.window.addListener(mxEvent.MINIMIZE, mxUtils.bind(this, function()
  2216. {
  2217. outline.suspended = true;
  2218. }));
  2219. var outlineCreateGraph = outline.createGraph;
  2220. outline.createGraph = function(container)
  2221. {
  2222. var g = outlineCreateGraph.apply(this, arguments);
  2223. g.gridEnabled = false;
  2224. g.pageScale = graph.pageScale;
  2225. g.pageFormat = graph.pageFormat;
  2226. g.background = graph.background;
  2227. g.pageVisible = graph.pageVisible;
  2228. var current = mxUtils.getCurrentStyle(graph.container);
  2229. div.style.backgroundColor = current.backgroundColor;
  2230. return g;
  2231. };
  2232. function update()
  2233. {
  2234. outline.outline.pageScale = graph.pageScale;
  2235. outline.outline.pageFormat = graph.pageFormat;
  2236. outline.outline.pageVisible = graph.pageVisible;
  2237. outline.outline.background = graph.background;
  2238. var current = mxUtils.getCurrentStyle(graph.container);
  2239. div.style.backgroundColor = current.backgroundColor;
  2240. if (graph.view.backgroundPageShape != null && outline.outline.view.backgroundPageShape != null)
  2241. {
  2242. outline.outline.view.backgroundPageShape.fill = graph.view.backgroundPageShape.fill;
  2243. }
  2244. outline.outline.refresh();
  2245. };
  2246. outline.init(div);
  2247. editorUi.editor.addListener('resetGraphView', update);
  2248. editorUi.addListener('pageFormatChanged', update);
  2249. editorUi.addListener('backgroundColorChanged', update);
  2250. editorUi.addListener('backgroundImageChanged', update);
  2251. editorUi.addListener('pageViewChanged', function()
  2252. {
  2253. update();
  2254. outline.update(true);
  2255. });
  2256. if (outline.outline.dialect == mxConstants.DIALECT_SVG)
  2257. {
  2258. var zoomInAction = editorUi.actions.get('zoomIn');
  2259. var zoomOutAction = editorUi.actions.get('zoomOut');
  2260. mxEvent.addMouseWheelListener(function(evt, up)
  2261. {
  2262. var outlineWheel = false;
  2263. var source = mxEvent.getSource(evt);
  2264. while (source != null)
  2265. {
  2266. if (source == outline.outline.view.canvas.ownerSVGElement)
  2267. {
  2268. outlineWheel = true;
  2269. break;
  2270. }
  2271. source = source.parentNode;
  2272. }
  2273. if (outlineWheel)
  2274. {
  2275. if (up)
  2276. {
  2277. zoomInAction.funct();
  2278. }
  2279. else
  2280. {
  2281. zoomOutAction.funct();
  2282. }
  2283. mxEvent.consume(evt);
  2284. }
  2285. });
  2286. }
  2287. };
  2288. /**
  2289. *
  2290. */
  2291. var LayersWindow = function(editorUi, x, y, w, h)
  2292. {
  2293. var graph = editorUi.editor.graph;
  2294. var div = document.createElement('div');
  2295. div.style.userSelect = 'none';
  2296. div.style.background = 'whiteSmoke';
  2297. div.style.border = '1px solid whiteSmoke';
  2298. div.style.height = '100%';
  2299. div.style.marginBottom = '10px';
  2300. div.style.overflow = 'auto';
  2301. var tbarHeight = (!EditorUi.compactUi) ? '30px' : '26px';
  2302. var listDiv = document.createElement('div')
  2303. listDiv.style.backgroundColor = '#e5e5e5';
  2304. listDiv.style.position = 'absolute';
  2305. listDiv.style.overflow = 'auto';
  2306. listDiv.style.left = '0px';
  2307. listDiv.style.right = '0px';
  2308. listDiv.style.top = '0px';
  2309. listDiv.style.bottom = (parseInt(tbarHeight) + 7) + 'px';
  2310. div.appendChild(listDiv);
  2311. var dragSource = null;
  2312. var dropIndex = null;
  2313. mxEvent.addListener(div, 'dragover', function(evt)
  2314. {
  2315. evt.dataTransfer.dropEffect = 'move';
  2316. dropIndex = 0;
  2317. evt.stopPropagation();
  2318. evt.preventDefault();
  2319. });
  2320. // Workaround for "no element found" error in FF
  2321. mxEvent.addListener(div, 'drop', function(evt)
  2322. {
  2323. evt.stopPropagation();
  2324. evt.preventDefault();
  2325. });
  2326. var layerCount = null;
  2327. var selectionLayer = null;
  2328. var ldiv = document.createElement('div');
  2329. ldiv.className = 'geToolbarContainer';
  2330. ldiv.style.position = 'absolute';
  2331. ldiv.style.bottom = '0px';
  2332. ldiv.style.left = '0px';
  2333. ldiv.style.right = '0px';
  2334. ldiv.style.height = tbarHeight;
  2335. ldiv.style.overflow = 'hidden';
  2336. ldiv.style.padding = (!EditorUi.compactUi) ? '1px' : '4px 0px 3px 0px';
  2337. ldiv.style.backgroundColor = 'whiteSmoke';
  2338. ldiv.style.borderWidth = '1px 0px 0px 0px';
  2339. ldiv.style.borderColor = '#c3c3c3';
  2340. ldiv.style.borderStyle = 'solid';
  2341. ldiv.style.display = 'block';
  2342. ldiv.style.whiteSpace = 'nowrap';
  2343. if (mxClient.IS_QUIRKS)
  2344. {
  2345. ldiv.style.filter = 'none';
  2346. }
  2347. var link = document.createElement('a');
  2348. link.className = 'geButton';
  2349. if (mxClient.IS_QUIRKS)
  2350. {
  2351. link.style.filter = 'none';
  2352. }
  2353. var removeLink = link.cloneNode();
  2354. removeLink.innerHTML = '<div class="geSprite geSprite-delete" style="display:inline-block;"></div>';
  2355. mxEvent.addListener(removeLink, 'click', function(evt)
  2356. {
  2357. if (graph.isEnabled())
  2358. {
  2359. graph.model.beginUpdate();
  2360. try
  2361. {
  2362. var index = graph.model.root.getIndex(selectionLayer);
  2363. graph.removeCells([selectionLayer], false);
  2364. // Creates default layer if no layer exists
  2365. if (graph.model.getChildCount(graph.model.root) == 0)
  2366. {
  2367. graph.model.add(graph.model.root, new mxCell());
  2368. graph.setDefaultParent(null);
  2369. }
  2370. else if (index > 0 && index <= graph.model.getChildCount(graph.model.root))
  2371. {
  2372. graph.setDefaultParent(graph.model.getChildAt(graph.model.root, index - 1));
  2373. }
  2374. else
  2375. {
  2376. graph.setDefaultParent(null);
  2377. }
  2378. }
  2379. finally
  2380. {
  2381. graph.model.endUpdate();
  2382. }
  2383. }
  2384. mxEvent.consume(evt);
  2385. });
  2386. if (!graph.isEnabled())
  2387. {
  2388. removeLink.className = 'geButton mxDisabled';
  2389. }
  2390. ldiv.appendChild(removeLink);
  2391. var insertLink = link.cloneNode();
  2392. insertLink.innerHTML = '<div class="geSprite geSprite-insert" style="display:inline-block;"></div>';
  2393. mxEvent.addListener(insertLink, 'click', function(evt)
  2394. {
  2395. if (graph.isEnabled() && !graph.isSelectionEmpty())
  2396. {
  2397. graph.moveCells(graph.getSelectionCells(), 0, 0, false, selectionLayer);
  2398. }
  2399. });
  2400. ldiv.appendChild(insertLink);
  2401. var renameLink = link.cloneNode();
  2402. renameLink.innerHTML = '<div class="geSprite geSprite-dots" style="display:inline-block;"></div>';
  2403. renameLink.setAttribute('title', mxResources.get('rename'));
  2404. function renameLayer(layer)
  2405. {
  2406. if (graph.isEnabled() && layer != null)
  2407. {
  2408. var dlg = new FilenameDialog(editorUi, layer.value || mxResources.get('background'), mxResources.get('rename'), mxUtils.bind(this, function(newValue)
  2409. {
  2410. if (newValue != null)
  2411. {
  2412. graph.getModel().setValue(layer, newValue);
  2413. }
  2414. }), mxResources.get('enterName'));
  2415. editorUi.showDialog(dlg.container, 300, 100, true, true);
  2416. dlg.init();
  2417. }
  2418. };
  2419. mxEvent.addListener(renameLink, 'click', function(evt)
  2420. {
  2421. if (graph.isEnabled())
  2422. {
  2423. renameLayer(selectionLayer);
  2424. }
  2425. mxEvent.consume(evt);
  2426. });
  2427. if (!graph.isEnabled())
  2428. {
  2429. renameLink.className = 'geButton mxDisabled';
  2430. }
  2431. ldiv.appendChild(renameLink);
  2432. var duplicateLink = link.cloneNode();
  2433. duplicateLink.innerHTML = '<div class="geSprite geSprite-duplicate" style="display:inline-block;"></div>';
  2434. mxEvent.addListener(duplicateLink, 'click', function(evt)
  2435. {
  2436. if (graph.isEnabled())
  2437. {
  2438. var newCell = null;
  2439. graph.model.beginUpdate();
  2440. try
  2441. {
  2442. newCell = graph.cloneCells([selectionLayer])[0];
  2443. newCell.value = mxResources.get('untitledLayer');
  2444. newCell.setVisible(true);
  2445. newCell = graph.addCell(newCell, graph.model.root);
  2446. graph.setDefaultParent(newCell);
  2447. }
  2448. finally
  2449. {
  2450. graph.model.endUpdate();
  2451. }
  2452. if (newCell != null && !graph.isCellLocked(newCell))
  2453. {
  2454. graph.selectAll(newCell);
  2455. }
  2456. }
  2457. });
  2458. if (!graph.isEnabled())
  2459. {
  2460. duplicateLink.className = 'geButton mxDisabled';
  2461. }
  2462. ldiv.appendChild(duplicateLink);
  2463. var addLink = link.cloneNode();
  2464. addLink.innerHTML = '<div class="geSprite geSprite-plus" style="display:inline-block;"></div>';
  2465. addLink.setAttribute('title', mxResources.get('addLayer'));
  2466. mxEvent.addListener(addLink, 'click', function(evt)
  2467. {
  2468. if (graph.isEnabled())
  2469. {
  2470. graph.model.beginUpdate();
  2471. try
  2472. {
  2473. var cell = graph.addCell(new mxCell(mxResources.get('untitledLayer')), graph.model.root);
  2474. graph.setDefaultParent(cell);
  2475. }
  2476. finally
  2477. {
  2478. graph.model.endUpdate();
  2479. }
  2480. }
  2481. mxEvent.consume(evt);
  2482. });
  2483. if (!graph.isEnabled())
  2484. {
  2485. addLink.className = 'geButton mxDisabled';
  2486. }
  2487. ldiv.appendChild(addLink);
  2488. div.appendChild(ldiv);
  2489. function refresh()
  2490. {
  2491. layerCount = graph.model.getChildCount(graph.model.root)
  2492. listDiv.innerHTML = '';
  2493. function addLayer(index, label, child, defaultParent)
  2494. {
  2495. var ldiv = document.createElement('div');
  2496. ldiv.className = 'geToolbarContainer';
  2497. ldiv.style.overflow = 'hidden';
  2498. ldiv.style.position = 'relative';
  2499. ldiv.style.padding = '4px';
  2500. ldiv.style.height = '22px';
  2501. ldiv.style.display = 'block';
  2502. ldiv.style.backgroundColor = 'whiteSmoke';
  2503. ldiv.style.borderWidth = '0px 0px 1px 0px';
  2504. ldiv.style.borderColor = '#c3c3c3';
  2505. ldiv.style.borderStyle = 'solid';
  2506. ldiv.style.whiteSpace = 'nowrap';
  2507. var left = document.createElement('div');
  2508. left.style.display = 'inline-block';
  2509. left.style.width = '100%';
  2510. left.style.textOverflow = 'ellipsis';
  2511. left.style.overflow = 'hidden';
  2512. mxEvent.addListener(ldiv, 'dragover', function(evt)
  2513. {
  2514. evt.dataTransfer.dropEffect = 'move';
  2515. dropIndex = index;
  2516. evt.stopPropagation();
  2517. evt.preventDefault();
  2518. });
  2519. mxEvent.addListener(ldiv, 'dragstart', function(evt)
  2520. {
  2521. dragSource = ldiv;
  2522. // Workaround for no DnD on DIV in FF
  2523. if (mxClient.IS_FF)
  2524. {
  2525. // LATER: Check what triggers a parse as XML on this in FF after drop
  2526. evt.dataTransfer.setData('Text', '<layer/>');
  2527. }
  2528. });
  2529. mxEvent.addListener(ldiv, 'dragend', function(evt)
  2530. {
  2531. if (dragSource != null && dropIndex != null)
  2532. {
  2533. graph.addCell(child, graph.model.root, dropIndex);
  2534. }
  2535. dragSource = null;
  2536. dropIndex = null;
  2537. evt.stopPropagation();
  2538. evt.preventDefault();
  2539. });
  2540. var btn = document.createElement('img');
  2541. btn.setAttribute('draggable', 'false');
  2542. btn.setAttribute('align', 'top');
  2543. btn.setAttribute('border', '0');
  2544. btn.style.cursor = 'pointer';
  2545. btn.style.padding = '4px';
  2546. btn.setAttribute('title', mxResources.get('lockUnlock'));
  2547. var state = graph.view.getState(child);
  2548. var style = (state != null) ? state.style : graph.getCellStyle(child);
  2549. if (mxUtils.getValue(style, 'locked', '0') == '1')
  2550. {
  2551. btn.setAttribute('src', Dialog.prototype.lockedImage);
  2552. }
  2553. else
  2554. {
  2555. btn.setAttribute('src', Dialog.prototype.unlockedImage);
  2556. }
  2557. mxEvent.addListener(btn, 'click', function(evt)
  2558. {
  2559. if (graph.isEnabled())
  2560. {
  2561. var value = null;
  2562. graph.getModel().beginUpdate();
  2563. try
  2564. {
  2565. value = (mxUtils.getValue(style, 'locked', '0') == '1') ? null : '1';
  2566. graph.setCellStyles('locked', value, [child]);
  2567. }
  2568. finally
  2569. {
  2570. graph.getModel().endUpdate();
  2571. }
  2572. if (value == '1')
  2573. {
  2574. graph.removeSelectionCells(graph.getModel().getDescendants(child));
  2575. }
  2576. mxEvent.consume(evt);
  2577. }
  2578. });
  2579. left.appendChild(btn);
  2580. var inp = document.createElement('input');
  2581. inp.setAttribute('type', 'checkbox');
  2582. inp.setAttribute('title', mxResources.get('hideIt', [child.value || mxResources.get('background')]));
  2583. inp.style.marginLeft = '4px';
  2584. inp.style.marginRight = '6px';
  2585. inp.style.marginTop = '4px';
  2586. left.appendChild(inp);
  2587. if (!graph.isEnabled())
  2588. {
  2589. inp.setAttribute('disabled', 'disabled');
  2590. }
  2591. if (graph.model.isVisible(child))
  2592. {
  2593. inp.setAttribute('checked', 'checked');
  2594. inp.defaultChecked = true;
  2595. }
  2596. mxEvent.addListener(inp, 'click', function(evt)
  2597. {
  2598. if (graph.isEnabled())
  2599. {
  2600. graph.model.setVisible(child, !graph.model.isVisible(child));
  2601. mxEvent.consume(evt);
  2602. }
  2603. });
  2604. mxUtils.write(left, label);
  2605. ldiv.appendChild(left);
  2606. if (graph.isEnabled())
  2607. {
  2608. // Fallback if no drag and drop is available
  2609. if (mxClient.IS_TOUCH || mxClient.IS_POINTER || mxClient.IS_VML ||
  2610. (mxClient.IS_IE && document.documentMode < 10))
  2611. {
  2612. var right = document.createElement('div');
  2613. right.style.display = 'block';
  2614. right.style.textAlign = 'right';
  2615. right.style.whiteSpace = 'nowrap';
  2616. right.style.position = 'absolute';
  2617. right.style.right = '6px';
  2618. right.style.top = '6px';
  2619. // Poor man's change layer order
  2620. if (index > 0)
  2621. {
  2622. var img2 = document.createElement('a');
  2623. img2.setAttribute('title', mxResources.get('toBack'));
  2624. img2.className = 'geButton';
  2625. img2.style.cssFloat = 'none';
  2626. img2.innerHTML = '&#9660;';
  2627. img2.style.width = '14px';
  2628. img2.style.height = '14px';
  2629. img2.style.fontSize = '14px';
  2630. img2.style.margin = '0px';
  2631. img2.style.marginTop = '-1px';
  2632. right.appendChild(img2);
  2633. mxEvent.addListener(img2, 'click', function(evt)
  2634. {
  2635. if (graph.isEnabled())
  2636. {
  2637. graph.addCell(child, graph.model.root, index - 1);
  2638. }
  2639. mxEvent.consume(evt);
  2640. });
  2641. }
  2642. if (index >= 0 && index < layerCount - 1)
  2643. {
  2644. var img1 = document.createElement('a');
  2645. img1.setAttribute('title', mxResources.get('toFront'));
  2646. img1.className = 'geButton';
  2647. img1.style.cssFloat = 'none';
  2648. img1.innerHTML = '&#9650;';
  2649. img1.style.width = '14px';
  2650. img1.style.height = '14px';
  2651. img1.style.fontSize = '14px';
  2652. img1.style.margin = '0px';
  2653. img1.style.marginTop = '-1px';
  2654. right.appendChild(img1);
  2655. mxEvent.addListener(img1, 'click', function(evt)
  2656. {
  2657. if (graph.isEnabled())
  2658. {
  2659. graph.addCell(child, graph.model.root, index + 1);
  2660. }
  2661. mxEvent.consume(evt);
  2662. });
  2663. }
  2664. ldiv.appendChild(right);
  2665. }
  2666. if (mxClient.IS_SVG && (!mxClient.IS_IE || document.documentMode >= 10))
  2667. {
  2668. ldiv.setAttribute('draggable', 'true');
  2669. ldiv.style.cursor = 'move';
  2670. }
  2671. }
  2672. mxEvent.addListener(ldiv, 'dblclick', function(evt)
  2673. {
  2674. var nodeName = mxEvent.getSource(evt).nodeName;
  2675. if (nodeName != 'INPUT' && nodeName != 'IMG')
  2676. {
  2677. renameLayer(child);
  2678. mxEvent.consume(evt);
  2679. }
  2680. });
  2681. if (graph.getDefaultParent() == child)
  2682. {
  2683. ldiv.style.background = '#e6eff8';
  2684. ldiv.style.fontWeight = 'bold';
  2685. selectionLayer = child;
  2686. }
  2687. else
  2688. {
  2689. mxEvent.addListener(ldiv, 'click', function(evt)
  2690. {
  2691. if (graph.isEnabled())
  2692. {
  2693. graph.setDefaultParent(defaultParent);
  2694. graph.view.setCurrentRoot(null);
  2695. refresh();
  2696. }
  2697. });
  2698. }
  2699. listDiv.appendChild(ldiv);
  2700. };
  2701. // Cannot be moved or deleted
  2702. for (var i = layerCount - 1; i >= 0; i--)
  2703. {
  2704. (mxUtils.bind(this, function(child)
  2705. {
  2706. addLayer(i, child.value || mxResources.get('background'), child, child);
  2707. }))(graph.model.getChildAt(graph.model.root, i));
  2708. }
  2709. removeLink.setAttribute('title', mxResources.get('removeIt', [selectionLayer.value || mxResources.get('background')]));
  2710. insertLink.setAttribute('title', mxResources.get('moveSelectionTo', [selectionLayer.value || mxResources.get('background')]));
  2711. duplicateLink.setAttribute('title', mxResources.get('duplicateIt', [selectionLayer.value || mxResources.get('background')]));
  2712. renameLink.setAttribute('title', mxResources.get('renameIt', [selectionLayer.value || mxResources.get('background')]));
  2713. if (graph.isSelectionEmpty())
  2714. {
  2715. insertLink.className = 'geButton mxDisabled';
  2716. }
  2717. };
  2718. refresh();
  2719. graph.model.addListener(mxEvent.CHANGE, function()
  2720. {
  2721. refresh();
  2722. });
  2723. graph.selectionModel.addListener(mxEvent.CHANGE, function()
  2724. {
  2725. if (graph.isSelectionEmpty())
  2726. {
  2727. insertLink.className = 'geButton mxDisabled';
  2728. }
  2729. else
  2730. {
  2731. insertLink.className = 'geButton';
  2732. }
  2733. });
  2734. this.window = new mxWindow(mxResources.get('layers'), div, x, y, w, h, true, true);
  2735. this.window.destroyOnClose = false;
  2736. this.window.setMaximizable(false);
  2737. this.window.setResizable(true);
  2738. this.window.setClosable(true);
  2739. this.window.setVisible(true);
  2740. // Make refresh available via instance
  2741. this.refreshLayers = refresh;
  2742. this.window.setLocation = function(x, y)
  2743. {
  2744. x = Math.max(0, x);
  2745. y = Math.max(0, y);
  2746. mxWindow.prototype.setLocation.apply(this, arguments);
  2747. };
  2748. mxEvent.addListener(window, 'resize', mxUtils.bind(this, function()
  2749. {
  2750. var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  2751. var ih = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  2752. var x = this.window.getX();
  2753. var y = this.window.getY();
  2754. if (x + this.window.table.clientWidth > iw)
  2755. {
  2756. x = Math.max(0, iw - this.window.table.clientWidth);
  2757. }
  2758. if (y + this.window.table.clientHeight > ih)
  2759. {
  2760. y = Math.max(0, ih - this.window.table.clientHeight);
  2761. }
  2762. if (this.window.getX() != x || this.window.getY() != y)
  2763. {
  2764. this.window.setLocation(x, y);
  2765. }
  2766. }));
  2767. };