Dialogs.js 190 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494
  1. /**
  2. * Copyright (c) 2006-2017, JGraph Ltd
  3. * Copyright (c) 2006-2017, Gaudenz Alder
  4. */
  5. var StorageDialog = function(editorUi, fn, rowLimit)
  6. {
  7. rowLimit = (rowLimit != null) ? rowLimit : 3;
  8. var div = document.createElement('div');
  9. div.style.textAlign = 'center';
  10. div.style.whiteSpace = 'nowrap';
  11. div.style.paddingTop = '0px';
  12. div.style.paddingBottom = '20px';
  13. var elt = editorUi.addLanguageMenu(div);
  14. var bottom = '28px';
  15. if (elt != null)
  16. {
  17. elt.style.bottom = bottom;
  18. }
  19. if (!editorUi.isOffline() && editorUi.getServiceCount() > 1)
  20. {
  21. var help = document.createElement('a');
  22. help.setAttribute('href', 'https://support.draw.io/display/DO/Selecting+Storage');
  23. help.setAttribute('title', mxResources.get('help'));
  24. help.setAttribute('target', '_blank');
  25. help.style.position = 'absolute';
  26. help.style.textDecoration = 'none';
  27. help.style.cursor = 'pointer';
  28. help.style.fontSize = '12px';
  29. help.style.bottom = bottom;
  30. help.style.left = '26px';
  31. help.style.color = 'gray';
  32. var icon = document.createElement('img');
  33. icon.setAttribute('border', '0');
  34. icon.setAttribute('valign', 'bottom');
  35. icon.setAttribute('src', Editor.helpImage);
  36. icon.style.marginRight = '2px';
  37. help.appendChild(icon);
  38. mxUtils.write(help, mxResources.get('help'));
  39. div.appendChild(help);
  40. }
  41. var demo = document.createElement('div');
  42. demo.style.position = 'absolute';
  43. demo.style.cursor = 'pointer';
  44. demo.style.fontSize = '12px';
  45. demo.style.bottom = bottom;
  46. demo.style.color = 'gray';
  47. mxUtils.write(demo, mxResources.get('decideLater'));
  48. if (editorUi.isOfflineApp())
  49. {
  50. demo.style.right = '20px';
  51. }
  52. else
  53. {
  54. mxUtils.setPrefixedStyle(demo.style, 'transform', 'translate(-50%,0)');
  55. demo.style.left = '50%';
  56. }
  57. this.init = function()
  58. {
  59. if (mxClient.IS_QUIRKS || document.documentMode == 8)
  60. {
  61. demo.style.marginLeft = -Math.round(demo.clientWidth / 2) + 'px';
  62. }
  63. };
  64. div.appendChild(demo);
  65. mxEvent.addListener(demo, 'click', function()
  66. {
  67. editorUi.hideDialog();
  68. var prev = Editor.useLocalStorage;
  69. editorUi.createFile(editorUi.defaultFilename, null, null, null, null, null, null, true);
  70. Editor.useLocalStorage = prev;
  71. });
  72. var buttons = document.createElement('div');
  73. if (mxClient.IS_QUIRKS)
  74. {
  75. buttons.style.whiteSpace = 'nowrap';
  76. buttons.style.cssFloat = 'left';
  77. }
  78. buttons.style.border = '1px solid #d3d3d3';
  79. buttons.style.borderWidth = '1px 0px 1px 0px';
  80. buttons.style.padding = '18px 0px 18px 0px';
  81. var cb = document.createElement('input');
  82. cb.setAttribute('type', 'checkbox');
  83. cb.setAttribute('checked', 'checked');
  84. cb.defaultChecked = true;
  85. var count = 0;
  86. function addLogo(img, title, mode, clientName)
  87. {
  88. var button = document.createElement('a');
  89. button.style.overflow = 'hidden';
  90. var logo = document.createElement('img');
  91. logo.setAttribute('src', img);
  92. logo.setAttribute('border', '0');
  93. logo.setAttribute('align', 'absmiddle');
  94. logo.style.width = '60px';
  95. logo.style.height = '60px';
  96. logo.style.paddingBottom = '6px';
  97. button.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  98. button.className = 'geBaseButton';
  99. button.style.position = 'relative';
  100. button.style.margin = '4px';
  101. button.style.padding = '8px 10px 12px 10px';
  102. button.style.whiteSpace = 'nowrap';
  103. // Workaround for quirks is a vertical list (limited to max 2 items)
  104. if (mxClient.IS_QUIRKS)
  105. {
  106. button.style.cssFloat = 'left';
  107. button.style.zoom = '1';
  108. }
  109. button.appendChild(logo);
  110. var label = document.createElement('div');
  111. button.appendChild(label);
  112. mxUtils.write(label, title);
  113. function initButton()
  114. {
  115. mxEvent.addListener(button, 'click', function()
  116. {
  117. // Special case: Redirect all drive users to draw.io pro
  118. if (mode == App.MODE_GOOGLE && !editorUi.isDriveDomain())
  119. {
  120. window.location.hostname = DriveClient.prototype.newAppHostname;
  121. }
  122. else if (mode == App.MODE_GOOGLE && editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  123. {
  124. // Tries immediate authentication
  125. editorUi.drive.checkToken(mxUtils.bind(this, function()
  126. {
  127. editorUi.spinner.stop();
  128. editorUi.setMode(mode, cb.checked);
  129. fn();
  130. }));
  131. }
  132. else
  133. {
  134. editorUi.setMode(mode, cb.checked);
  135. fn();
  136. }
  137. });
  138. };
  139. // Supports lazy loading
  140. if (clientName != null && editorUi[clientName] == null)
  141. {
  142. logo.style.visibility = 'hidden';
  143. mxUtils.setOpacity(label, 10);
  144. var size = 12;
  145. var spinner = new Spinner({
  146. lines: 12, // The number of lines to draw
  147. length: size, // The length of each line
  148. width: 5, // The line thickness
  149. radius: 10, // The radius of the inner circle
  150. rotate: 0, // The rotation offset
  151. color: '#000', // #rgb or #rrggbb
  152. speed: 1.5, // Rounds per second
  153. trail: 60, // Afterglow percentage
  154. shadow: false, // Whether to render a shadow
  155. hwaccel: false, // Whether to use hardware acceleration
  156. top: '40%',
  157. zIndex: 2e9 // The z-index (defaults to 2000000000)
  158. });
  159. spinner.spin(button);
  160. // Timeout after 30 secs
  161. var timeout = window.setTimeout(function()
  162. {
  163. if (editorUi[clientName] == null)
  164. {
  165. spinner.stop();
  166. button.style.display = 'none';
  167. }
  168. }, 30000);
  169. editorUi.addListener('clientLoaded', mxUtils.bind(this, function()
  170. {
  171. if (editorUi[clientName] != null)
  172. {
  173. window.clearTimeout(timeout);
  174. mxUtils.setOpacity(label, 100);
  175. logo.style.visibility = '';
  176. spinner.stop();
  177. initButton();
  178. }
  179. }));
  180. }
  181. else
  182. {
  183. initButton();
  184. }
  185. buttons.appendChild(button);
  186. if (++count >= rowLimit)
  187. {
  188. mxUtils.br(buttons);
  189. count = 0;
  190. }
  191. };
  192. var hd = document.createElement('p');
  193. hd.style.fontSize = '16pt';
  194. hd.style.padding = '0px';
  195. hd.style.paddingTop = '4px';
  196. hd.style.paddingBottom = '16px';
  197. hd.style.margin = '0px';
  198. hd.style.color = 'gray';
  199. mxUtils.write(hd, mxResources.get('saveDiagramsTo') + ':');
  200. div.appendChild(hd);
  201. if (typeof window.DriveClient === 'function')
  202. {
  203. addLogo(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googleDrive'), App.MODE_GOOGLE, 'drive');
  204. }
  205. if (editorUi.gitHub != null)
  206. {
  207. addLogo(IMAGE_PATH + '/github-logo.svg', mxResources.get('github'), App.MODE_GITHUB, 'gitHub');
  208. }
  209. if (typeof window.DropboxClient === 'function')
  210. {
  211. addLogo(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), App.MODE_DROPBOX, 'dropbox');
  212. }
  213. if (typeof window.OneDriveClient === 'function')
  214. {
  215. addLogo(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), App.MODE_ONEDRIVE, 'oneDrive');
  216. }
  217. if (!mxClient.IS_IOS || urlParams['storage'] == 'device')
  218. {
  219. addLogo(IMAGE_PATH + '/osa_drive-harddisk.png', mxResources.get('device'), App.MODE_DEVICE);
  220. }
  221. if (isLocalStorage && (urlParams['browser'] == '1' || urlParams['offline'] == '1'))
  222. {
  223. addLogo(IMAGE_PATH + '/osa_database.png', mxResources.get('browser'), App.MODE_BROWSER);
  224. }
  225. div.appendChild(buttons);
  226. var p2 = document.createElement('p');
  227. p2.style.marginTop = '12px';
  228. p2.style.marginBottom = '10px';
  229. p2.appendChild(cb);
  230. var span = document.createElement('span');
  231. span.style.color = 'gray';
  232. span.style.fontSize = '12px';
  233. mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
  234. p2.appendChild(span);
  235. mxUtils.br(p2);
  236. var recent = editorUi.getRecent();
  237. if (recent != null && recent.length > 0)
  238. {
  239. var recentSelect = document.createElement('select');
  240. recentSelect.style.marginTop = '14px';
  241. recentSelect.style.width = '140px';
  242. var titleOption = document.createElement('option');
  243. titleOption.setAttribute('value', '');
  244. titleOption.setAttribute('selected', 'selected');
  245. titleOption.style.textAlign = 'center';
  246. mxUtils.write(titleOption, mxResources.get('openRecent') + '...');
  247. recentSelect.appendChild(titleOption);
  248. for (var i = 0; i < recent.length; i++)
  249. {
  250. (function(entry)
  251. {
  252. var modeKey = entry.mode;
  253. // Google and oneDrive use different keys
  254. if (modeKey == App.MODE_GOOGLE)
  255. {
  256. modeKey = 'googleDrive';
  257. }
  258. else if (modeKey == App.MODE_ONEDRIVE)
  259. {
  260. modeKey = 'oneDrive';
  261. }
  262. var entryOption = document.createElement('option');
  263. entryOption.setAttribute('value', entry.id);
  264. mxUtils.write(entryOption, entry.title + ' (' + mxResources.get(modeKey) + ')');
  265. recentSelect.appendChild(entryOption);
  266. })(recent[i]);
  267. }
  268. p2.appendChild(recentSelect);
  269. mxEvent.addListener(recentSelect, 'change', function(evt)
  270. {
  271. if (recentSelect.value != '')
  272. {
  273. editorUi.loadFile(recentSelect.value);
  274. }
  275. });
  276. }
  277. else
  278. {
  279. p2.style.marginTop = '20px';
  280. buttons.style.padding = '30px 0px 26px 0px';
  281. }
  282. buttons.appendChild(p2);
  283. mxEvent.addListener(span, 'click', function(evt)
  284. {
  285. cb.checked = !cb.checked;
  286. mxEvent.consume(evt);
  287. });
  288. // Checks if Google Drive is missing after a 5 sec delay
  289. if (mxClient.IS_SVG && isLocalStorage && urlParams['gapi'] != '0' &&
  290. (document.documentMode == null || document.documentMode >= 10))
  291. {
  292. window.setTimeout(function()
  293. {
  294. if (editorUi.drive == null)
  295. {
  296. // To check for Disconnect plugin in chrome use mxClient.IS_GC and check for URL:
  297. // chrome-extension://jeoacafpbcihiomhlakheieifhpjdfeo/scripts/vendor/jquery/jquery-2.0.3.min.map
  298. var p3 = document.createElement('p');
  299. p3.style.padding = '8px';
  300. p3.style.fontSize = '9pt';
  301. p3.style.marginTop = '-14px';
  302. p3.innerHTML = '<a style="background-color:#dcdcdc;padding:5px;color:black;text-decoration:none;" ' +
  303. 'href="https://plus.google.com/u/0/+DrawIo1/posts/1HTrfsb5wDN" target="_blank">' +
  304. '<img border="0" src="' + mxGraph.prototype.warningImage.src + '" align="top"> ' +
  305. mxResources.get('googleDriveMissingClickHere') + '</a>';
  306. div.appendChild(p3);
  307. }
  308. }, 5000);
  309. }
  310. this.container = div;
  311. };
  312. /**
  313. * Constructs a dialog for creating new files from templates.
  314. */
  315. var SplashDialog = function(editorUi)
  316. {
  317. var div = document.createElement('div');
  318. div.style.textAlign = 'center';
  319. editorUi.addLanguageMenu(div);
  320. var help = null;
  321. var serviceCount = editorUi.getServiceCount();
  322. if (!editorUi.isOffline() && serviceCount > 1)
  323. {
  324. help = document.createElement('a');
  325. help.setAttribute('href', 'https://support.draw.io/display/DO/Selecting+Storage');
  326. help.setAttribute('title', mxResources.get('help'));
  327. help.setAttribute('target', '_blank');
  328. help.style.position = 'absolute';
  329. help.style.fontSize = '12px';
  330. help.style.textDecoration = 'none';
  331. help.style.cursor = 'pointer';
  332. help.style.bottom = '22px';
  333. help.style.left = '26px';
  334. help.style.color = 'gray';
  335. var icon = document.createElement('img');
  336. icon.setAttribute('border', '0');
  337. icon.setAttribute('valign', 'bottom');
  338. icon.setAttribute('src', Editor.helpImage);
  339. icon.style.marginRight = '2px';
  340. help.appendChild(icon);
  341. mxUtils.write(help, mxResources.get('help'));
  342. div.appendChild(help);
  343. }
  344. var hd = document.createElement('p');
  345. hd.style.fontSize = '16pt';
  346. hd.style.padding = '0px';
  347. hd.style.paddingTop = '2px';
  348. hd.style.margin = '0px';
  349. hd.style.color = 'gray';
  350. var logo = document.createElement('img');
  351. logo.setAttribute('border', '0');
  352. logo.setAttribute('align', 'absmiddle');
  353. logo.style.width = '40px';
  354. logo.style.height = '40px';
  355. logo.style.marginRight = '12px';
  356. logo.style.paddingBottom = '4px';
  357. var service = '';
  358. if (editorUi.mode == App.MODE_GOOGLE)
  359. {
  360. logo.src = IMAGE_PATH + '/google-drive-logo.svg';
  361. service = mxResources.get('googleDrive');
  362. if (help != null)
  363. {
  364. help.setAttribute('href', 'https://support.draw.io/display/DO/Using+draw.io+with+Google+Drive');
  365. }
  366. }
  367. else if (editorUi.mode == App.MODE_DROPBOX)
  368. {
  369. logo.src = IMAGE_PATH + '/dropbox-logo.svg';
  370. service = mxResources.get('dropbox');
  371. if (help != null)
  372. {
  373. help.setAttribute('href', 'https://support.draw.io/display/DO/Using+draw.io+with+Dropbox');
  374. }
  375. }
  376. else if (editorUi.mode == App.MODE_ONEDRIVE)
  377. {
  378. logo.src = IMAGE_PATH + '/onedrive-logo.svg';
  379. service = mxResources.get('oneDrive');
  380. if (help != null)
  381. {
  382. help.setAttribute('href', 'https://support.draw.io/display/DO/Using+draw.io+with+OneDrive');
  383. }
  384. }
  385. else if (editorUi.mode == App.MODE_GITHUB)
  386. {
  387. logo.src = IMAGE_PATH + '/github-logo.svg';
  388. service = mxResources.get('github');
  389. }
  390. else if (editorUi.mode == App.MODE_BROWSER)
  391. {
  392. logo.src = IMAGE_PATH + '/osa_database.png';
  393. service = mxResources.get('browser');
  394. }
  395. else
  396. {
  397. logo.src = IMAGE_PATH + '/osa_drive-harddisk.png';
  398. service = mxResources.get('device');
  399. }
  400. hd.appendChild(logo);
  401. mxUtils.write(hd, service);
  402. div.appendChild(hd);
  403. var buttons = document.createElement('div');
  404. if (mxClient.IS_QUIRKS)
  405. {
  406. buttons.style.whiteSpace = 'nowrap';
  407. buttons.style.cssFloat = 'left';
  408. }
  409. buttons.style.border = '1px solid #d3d3d3';
  410. buttons.style.borderWidth = '1px 0px 1px 0px';
  411. buttons.style.padding = '18px 0px 24px 0px';
  412. buttons.style.margin = '4px 0px 0px 0px';
  413. var btn = document.createElement('button');
  414. btn.className = 'geBigButton';
  415. btn.style.marginBottom = '8px';
  416. btn.style.overflow = 'hidden';
  417. btn.style.width = '340px';
  418. if (mxClient.IS_QUIRKS)
  419. {
  420. btn.style.width = '340px';
  421. }
  422. mxUtils.write(btn, mxResources.get('createNewDiagram'));
  423. mxEvent.addListener(btn, 'click', function()
  424. {
  425. editorUi.hideDialog();
  426. editorUi.actions.get('new').funct();
  427. });
  428. buttons.appendChild(btn);
  429. mxUtils.br(buttons);
  430. var btn = document.createElement('button');
  431. btn.className = 'geBigButton';
  432. btn.style.marginBottom = '22px';
  433. btn.style.overflow = 'hidden';
  434. btn.style.width = '340px';
  435. if (mxClient.IS_QUIRKS)
  436. {
  437. btn.style.width = '340px';
  438. }
  439. mxUtils.write(btn, mxResources.get('openExistingDiagram'));
  440. mxEvent.addListener(btn, 'click', function()
  441. {
  442. editorUi.actions.get('open').funct();
  443. });
  444. buttons.appendChild(btn);
  445. var storage = 'undefined';
  446. if (editorUi.mode == App.MODE_GOOGLE)
  447. {
  448. storage = mxResources.get('googleDrive');
  449. }
  450. else if (editorUi.mode == App.MODE_DROPBOX)
  451. {
  452. storage = mxResources.get('dropbox');
  453. }
  454. else if (editorUi.mode == App.MODE_ONEDRIVE)
  455. {
  456. storage = mxResources.get('oneDrive');
  457. }
  458. else if (editorUi.mode == App.MODE_GITHUB)
  459. {
  460. storage = mxResources.get('github');
  461. }
  462. else if (editorUi.mode == App.MODE_DEVICE)
  463. {
  464. storage = mxResources.get('device');
  465. }
  466. else if (editorUi.mode == App.MODE_BROWSER)
  467. {
  468. storage = mxResources.get('browser');
  469. }
  470. if (!mxClient.IS_CHROMEAPP)
  471. {
  472. var driveUser = (editorUi.drive != null) ? editorUi.drive.getUser() : null;
  473. function addLogout(logout)
  474. {
  475. btn.style.marginBottom = '24px';
  476. var link = document.createElement('a');
  477. link.setAttribute('href', 'javascript:void(0)');
  478. link.style.display = 'block';
  479. link.style.marginTop = '6px';
  480. mxUtils.write(link, mxResources.get('signOut'));
  481. // Makes room after last big buttons
  482. btn.style.marginBottom = '16px';
  483. buttons.style.paddingBottom = '18px';
  484. mxEvent.addListener(link, 'click', function()
  485. {
  486. editorUi.confirm(mxResources.get('areYouSure'), function()
  487. {
  488. logout();
  489. });
  490. });
  491. buttons.appendChild(link);
  492. };
  493. if (editorUi.mode == App.MODE_GOOGLE && driveUser != null)
  494. {
  495. btn.style.marginBottom = '24px';
  496. var link = document.createElement('a');
  497. link.setAttribute('href', 'javascript:void(0)');
  498. link.style.display = 'block';
  499. link.style.marginTop = '6px';
  500. mxUtils.write(link, mxResources.get('changeUser') + ' (' + driveUser.displayName + ')');
  501. // Makes room after last big buttons
  502. btn.style.marginBottom = '16px';
  503. buttons.style.paddingBottom = '18px';
  504. mxEvent.addListener(link, 'click', function()
  505. {
  506. editorUi.hideDialog();
  507. editorUi.drive.clearUserId();
  508. editorUi.drive.setUser(null);
  509. gapi.auth.signOut();
  510. // Restores current dialog after clearing user
  511. editorUi.setMode(App.MODE_GOOGLE);
  512. editorUi.hideDialog();
  513. editorUi.showSplash();
  514. // FIXME: Does not force showing the auth dialog if only one user is logged in
  515. editorUi.drive.authorize(false, mxUtils.bind(this, mxUtils.bind(this, function()
  516. {
  517. editorUi.hideDialog();
  518. editorUi.showSplash();
  519. })), mxUtils.bind(this, function(resp)
  520. {
  521. editorUi.handleError(resp, null, function()
  522. {
  523. editorUi.hideDialog();
  524. editorUi.showSplash();
  525. });
  526. }));
  527. });
  528. buttons.appendChild(link);
  529. }
  530. else if (editorUi.mode == App.MODE_ONEDRIVE && editorUi.oneDrive != null)
  531. {
  532. addLogout(function()
  533. {
  534. editorUi.oneDrive.logout();
  535. });
  536. }
  537. else if (editorUi.mode == App.MODE_GITHUB && editorUi.gitHub != null)
  538. {
  539. addLogout(function()
  540. {
  541. editorUi.gitHub.logout();
  542. window.open('https://www.github.com/logout');
  543. });
  544. }
  545. else if (editorUi.mode == App.MODE_DROPBOX && editorUi.dropbox != null)
  546. {
  547. // NOTE: Dropbox has a logout option in the picker
  548. addLogout(function()
  549. {
  550. editorUi.dropbox.logout();
  551. window.open('https://www.dropbox.com/logout');
  552. });
  553. }
  554. if (serviceCount > 1)
  555. {
  556. var link = document.createElement('a');
  557. link.setAttribute('href', 'javascript:void(0)');
  558. link.style.display = 'block';
  559. link.style.marginTop = '8px';
  560. mxUtils.write(link, mxResources.get('notUsingService', [storage]));
  561. mxEvent.addListener(link, 'click', function()
  562. {
  563. editorUi.hideDialog(false);
  564. editorUi.setMode(null);
  565. editorUi.clearMode();
  566. editorUi.showSplash(true);
  567. });
  568. buttons.appendChild(link);
  569. }
  570. }
  571. div.appendChild(buttons);
  572. // Changes Chrome App dialog
  573. if (serviceCount < 2)
  574. {
  575. hd.style.paddingTop = '12px';
  576. hd.innerHTML = '';
  577. mxUtils.write(hd, mxResources.get('chooseAnOption') + ':');
  578. buttons.style.border = 'none';
  579. buttons.style.padding = '16px 0px 0px 0px';
  580. btn.style.marginBottom = '0px';
  581. }
  582. this.container = div;
  583. };
  584. /**
  585. *
  586. */
  587. var ConfirmDialog = function(editorUi, message, okFn, cancelFn, okLabel, cancelLabel)
  588. {
  589. var div = document.createElement('div');
  590. div.style.textAlign = 'center';
  591. var p2 = document.createElement('div');
  592. p2.style.padding = '6px';
  593. p2.style.overflow = 'auto';
  594. p2.style.maxHeight = '40px';
  595. if (mxClient.IS_QUIRKS)
  596. {
  597. p2.style.height = '60px';
  598. }
  599. mxUtils.write(p2, message);
  600. div.appendChild(p2);
  601. var btns = document.createElement('div');
  602. btns.style.marginTop = '16px';
  603. btns.style.textAlign = 'center';
  604. var cancelBtn = mxUtils.button(cancelLabel || mxResources.get('cancel'), function()
  605. {
  606. editorUi.hideDialog();
  607. if (cancelFn != null)
  608. {
  609. cancelFn();
  610. }
  611. });
  612. cancelBtn.className = 'geBtn';
  613. if (editorUi.editor.cancelFirst)
  614. {
  615. btns.appendChild(cancelBtn);
  616. }
  617. var okBtn = mxUtils.button(okLabel || mxResources.get('ok'), function()
  618. {
  619. editorUi.hideDialog();
  620. if (okFn != null)
  621. {
  622. okFn();
  623. }
  624. });
  625. btns.appendChild(okBtn);
  626. okBtn.className = 'geBtn gePrimaryBtn';
  627. if (!editorUi.editor.cancelFirst)
  628. {
  629. btns.appendChild(cancelBtn);
  630. }
  631. div.appendChild(btns);
  632. this.container = div;
  633. };
  634. /**
  635. *
  636. */
  637. var ErrorDialog = function(editorUi, title, message, buttonText, fn, retry, buttonText2, fn2, hide)
  638. {
  639. hide = (hide != null) ? hide : true;
  640. var div = document.createElement('div');
  641. div.style.textAlign = 'center';
  642. if (title != null)
  643. {
  644. var hd = document.createElement('div');
  645. hd.style.padding = '0px';
  646. hd.style.margin = '0px';
  647. hd.style.fontSize = '18px';
  648. hd.style.paddingBottom = '16px';
  649. hd.style.marginBottom = '16px';
  650. hd.style.borderBottom = '1px solid #c0c0c0';
  651. hd.style.color = 'gray';
  652. mxUtils.write(hd, title);
  653. div.appendChild(hd);
  654. }
  655. var p2 = document.createElement('div');
  656. p2.style.padding = '6px';
  657. p2.innerHTML = message;
  658. div.appendChild(p2);
  659. var btns = document.createElement('div');
  660. btns.style.marginTop = '16px';
  661. btns.style.textAlign = 'right';
  662. if (retry != null)
  663. {
  664. var retryBtn = mxUtils.button(mxResources.get('tryAgain'), function()
  665. {
  666. editorUi.hideDialog();
  667. retry();
  668. });
  669. retryBtn.className = 'geBtn';
  670. btns.appendChild(retryBtn);
  671. btns.style.textAlign = 'center';
  672. }
  673. var btn = mxUtils.button(buttonText, function()
  674. {
  675. if (hide)
  676. {
  677. editorUi.hideDialog();
  678. }
  679. if (fn != null)
  680. {
  681. fn();
  682. }
  683. });
  684. btn.className = 'geBtn';
  685. btns.appendChild(btn);
  686. if (buttonText2 != null)
  687. {
  688. var mainBtn = mxUtils.button(buttonText2, function()
  689. {
  690. if (hide)
  691. {
  692. editorUi.hideDialog();
  693. }
  694. if (fn2 != null)
  695. {
  696. fn2();
  697. }
  698. });
  699. mainBtn.className = 'geBtn gePrimaryBtn';
  700. btns.appendChild(mainBtn);
  701. }
  702. this.init = function()
  703. {
  704. btn.focus();
  705. };
  706. div.appendChild(btns);
  707. this.container = div;
  708. };
  709. /**
  710. * Constructs a new embed dialog
  711. */
  712. var EmbedDialog = function(editorUi, result, timeout, ignoreSize, previewFn)
  713. {
  714. var div = document.createElement('div');
  715. var maxSize = 500000;
  716. var maxFbSize = 51200;
  717. var maxTwitterSize = 7168;
  718. // Checks if result is a link
  719. var validUrl = /^https?:\/\//.test(result) || /^mailto:\/\//.test(result);
  720. mxUtils.write(div, mxResources.get((result.length < maxSize) ?
  721. ((validUrl) ? 'link' : 'mainEmbedNotice') : 'preview') + ':');
  722. mxUtils.br(div);
  723. var size = document.createElement('div');
  724. size.style.position = 'absolute';
  725. size.style.top = '30px';
  726. size.style.right = '30px';
  727. size.style.color = 'gray';
  728. mxUtils.write(size, editorUi.formatFileSize(result.length));
  729. div.appendChild(size);
  730. // Using DIV for faster rendering
  731. var text = document.createElement('textarea');
  732. text.setAttribute('autocomplete', 'off');
  733. text.setAttribute('autocorrect', 'off');
  734. text.setAttribute('autocapitalize', 'off');
  735. text.setAttribute('spellcheck', 'false');
  736. text.style.marginTop = '10px';
  737. text.style.resize = 'none';
  738. text.style.height = '150px';
  739. text.style.width = '440px';
  740. text.style.border = '1px solid gray';
  741. text.value = mxResources.get('updatingDocument');
  742. div.appendChild(text);
  743. mxUtils.br(div);
  744. this.init = function()
  745. {
  746. window.setTimeout(function()
  747. {
  748. if (result.length < maxSize)
  749. {
  750. text.value = result;
  751. text.focus();
  752. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  753. {
  754. text.select();
  755. }
  756. else
  757. {
  758. document.execCommand('selectAll', false, null);
  759. }
  760. }
  761. else
  762. {
  763. text.setAttribute('readonly', 'true');
  764. text.value = result.substring(0, 340) + '... (' + mxResources.get('drawingTooLarge') + ')';
  765. }
  766. }, 0);
  767. };
  768. var buttons = document.createElement('div');
  769. buttons.style.position = 'absolute';
  770. buttons.style.bottom = '36px';
  771. buttons.style.right = '32px';
  772. var previewBtn = null;
  773. // Loads forever in IE9
  774. if (!mxClient.IS_CHROMEAPP && !navigator.standalone && (validUrl ||
  775. (mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9))))
  776. {
  777. previewBtn = mxUtils.button(mxResources.get((result.length < maxSize) ? 'preview' : 'openInNewWindow'), function()
  778. {
  779. var value = (result.length < maxSize) ? text.value : result;
  780. if (previewFn != null)
  781. {
  782. previewFn(value);
  783. }
  784. else
  785. {
  786. if (validUrl)
  787. {
  788. try
  789. {
  790. var win = window.open(value);
  791. if (timeout == null || timeout > 0)
  792. {
  793. window.setTimeout(mxUtils.bind(this, function()
  794. {
  795. if (win != null && win.location.href != null &&
  796. win.location.href.substring(0, 8) != value.substring(0, 8))
  797. {
  798. win.close();
  799. editorUi.handleError({message: mxResources.get('drawingTooLarge')});
  800. }
  801. }), timeout || 500);
  802. }
  803. }
  804. catch (e)
  805. {
  806. editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
  807. }
  808. }
  809. else
  810. {
  811. var wnd = window.open();
  812. var doc = wnd.document;
  813. doc.writeln('<html><head><title>' + encodeURIComponent(mxResources.get('preview')) +
  814. '</title><meta charset="utf-8"></head>' +
  815. '<body>' + result + '</body></html>');
  816. doc.close();
  817. }
  818. }
  819. });
  820. previewBtn.className = 'geBtn';
  821. buttons.appendChild(previewBtn);
  822. }
  823. if (!validUrl || result.length > 7500)
  824. {
  825. var downloadBtn = mxUtils.button(mxResources.get('download'), function()
  826. {
  827. editorUi.saveData('embed.txt', 'txt', result, 'text/plain');
  828. });
  829. downloadBtn.className = 'geBtn';
  830. buttons.appendChild(downloadBtn);
  831. }
  832. // Twitter-intent does not allow more characters, must be pasted manually
  833. if (validUrl && !editorUi.isOffline())
  834. {
  835. if (result.length < maxFbSize)
  836. {
  837. var fbBtn = mxUtils.button('', function()
  838. {
  839. try
  840. {
  841. var url = 'https://www.facebook.com/sharer.php?p[url]=' +
  842. encodeURIComponent(text.value);
  843. window.open(url);
  844. }
  845. catch (e)
  846. {
  847. editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
  848. }
  849. });
  850. var img = document.createElement('img');
  851. img.setAttribute('src', Editor.facebookImage);
  852. img.setAttribute('border', '0');
  853. fbBtn.appendChild(img);
  854. fbBtn.setAttribute('title', mxResources.get('facebook') + ' (' +
  855. editorUi.formatFileSize(maxFbSize) + ' max)');
  856. fbBtn.style.verticalAlign = 'bottom';
  857. fbBtn.style.paddingTop = '4px';
  858. fbBtn.style.minWidth = '46px'
  859. fbBtn.className = 'geBtn';
  860. buttons.appendChild(fbBtn);
  861. }
  862. if (result.length < maxTwitterSize)
  863. {
  864. var tweetBtn = mxUtils.button('', function()
  865. {
  866. try
  867. {
  868. var url = 'https://twitter.com/intent/tweet?text=' +
  869. encodeURIComponent('Check out the diagram I made using @drawio') +
  870. '&url=' + encodeURIComponent(text.value);
  871. window.open(url);
  872. }
  873. catch (e)
  874. {
  875. editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
  876. }
  877. });
  878. var img = document.createElement('img');
  879. img.setAttribute('src', Editor.tweetImage);
  880. img.setAttribute('border', '0');
  881. img.style.marginBottom = '5px'
  882. tweetBtn.appendChild(img);
  883. tweetBtn.setAttribute('title', mxResources.get('twitter') + ' (' +
  884. editorUi.formatFileSize(maxTwitterSize) + ' max)');
  885. tweetBtn.style.verticalAlign = 'bottom';
  886. tweetBtn.style.paddingTop = '4px';
  887. tweetBtn.style.minWidth = '46px'
  888. tweetBtn.className = 'geBtn';
  889. buttons.appendChild(tweetBtn);
  890. }
  891. }
  892. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  893. {
  894. editorUi.hideDialog();
  895. });
  896. buttons.appendChild(closeBtn);
  897. var copyBtn = mxUtils.button(mxResources.get('copy'), function()
  898. {
  899. text.focus();
  900. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  901. {
  902. text.select();
  903. }
  904. else
  905. {
  906. document.execCommand('selectAll', false, null);
  907. }
  908. document.execCommand('copy');
  909. editorUi.alert(mxResources.get('copiedToClipboard'));
  910. });
  911. if (result.length < maxSize)
  912. {
  913. // Does not work in Safari and shows annoying dialog for IE11-
  914. if (!mxClient.IS_SF && document.documentMode == null)
  915. {
  916. buttons.appendChild(copyBtn);
  917. copyBtn.className = 'geBtn gePrimaryBtn';
  918. closeBtn.className = 'geBtn';
  919. }
  920. else
  921. {
  922. closeBtn.className = 'geBtn gePrimaryBtn';
  923. }
  924. }
  925. else
  926. {
  927. buttons.appendChild(previewBtn);
  928. closeBtn.className = 'geBtn';
  929. previewBtn.className = 'geBtn gePrimaryBtn';
  930. }
  931. div.appendChild(buttons);
  932. this.container = div;
  933. };
  934. /**
  935. * Constructs a dialog for embedding the diagram in Google Sites.
  936. */
  937. var GoogleSitesDialog = function(editorUi, publicUrl)
  938. {
  939. var div = document.createElement('div');
  940. var graph = editorUi.editor.graph;
  941. var bounds = graph.getGraphBounds();
  942. var scale = graph.view.scale;
  943. var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
  944. var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
  945. mxUtils.write(div, mxResources.get('googleGadget') + ':');
  946. mxUtils.br(div);
  947. var gadgetInput = document.createElement('input');
  948. gadgetInput.setAttribute('type', 'text');
  949. gadgetInput.style.marginBottom = '8px';
  950. gadgetInput.style.marginTop = '2px';
  951. gadgetInput.style.width = '410px';
  952. div.appendChild(gadgetInput);
  953. mxUtils.br(div);
  954. this.init = function()
  955. {
  956. gadgetInput.focus();
  957. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  958. {
  959. gadgetInput.select();
  960. }
  961. else
  962. {
  963. document.execCommand('selectAll', false, null);
  964. }
  965. };
  966. mxUtils.write(div, mxResources.get('top') + ':');
  967. var topInput = document.createElement('input');
  968. topInput.setAttribute('type', 'text');
  969. topInput.setAttribute('size', '4');
  970. topInput.style.marginRight = '16px';
  971. topInput.style.marginLeft = '4px';
  972. topInput.value = x0;
  973. div.appendChild(topInput);
  974. mxUtils.write(div, mxResources.get('height') + ':');
  975. var heightInput = document.createElement('input');
  976. heightInput.setAttribute('type', 'text');
  977. heightInput.setAttribute('size', '4');
  978. heightInput.style.marginLeft = '4px';
  979. heightInput.value = Math.ceil(bounds.height / scale);
  980. div.appendChild(heightInput);
  981. mxUtils.br(div);
  982. var hr = document.createElement('hr');
  983. hr.setAttribute('size', '1');
  984. hr.style.marginBottom = '16px';
  985. hr.style.marginTop = '16px';
  986. div.appendChild(hr);
  987. mxUtils.write(div, mxResources.get('publicDiagramUrl') + ':');
  988. mxUtils.br(div);
  989. var urlInput = document.createElement('input');
  990. urlInput.setAttribute('type', 'text');
  991. urlInput.setAttribute('size', '28');
  992. urlInput.style.marginBottom = '8px';
  993. urlInput.style.marginTop = '2px';
  994. urlInput.style.width = '410px';
  995. urlInput.value = publicUrl || '';
  996. div.appendChild(urlInput);
  997. mxUtils.br(div);
  998. mxUtils.write(div, mxResources.get('borderWidth') + ':');
  999. var borderInput = document.createElement('input');
  1000. borderInput.setAttribute('type', 'text');
  1001. borderInput.setAttribute('size', '3');
  1002. borderInput.style.marginBottom = '8px';
  1003. borderInput.style.marginLeft = '4px';
  1004. borderInput.value = '0';
  1005. div.appendChild(borderInput);
  1006. mxUtils.br(div);
  1007. var panCheckBox = document.createElement('input');
  1008. panCheckBox.setAttribute('type', 'checkbox');
  1009. panCheckBox.setAttribute('checked', 'checked');
  1010. panCheckBox.defaultChecked = true;
  1011. panCheckBox.style.marginLeft = '16px';
  1012. div.appendChild(panCheckBox);
  1013. mxUtils.write(div, mxResources.get('pan') + ' ');
  1014. var zoomCheckBox = document.createElement('input');
  1015. zoomCheckBox.setAttribute('type', 'checkbox');
  1016. zoomCheckBox.setAttribute('checked', 'checked');
  1017. zoomCheckBox.defaultChecked = true;
  1018. zoomCheckBox.style.marginLeft = '8px';
  1019. div.appendChild(zoomCheckBox);
  1020. mxUtils.write(div, mxResources.get('zoom') + ' ');
  1021. var editCheckBox = document.createElement('input');
  1022. editCheckBox.setAttribute('type', 'checkbox');
  1023. editCheckBox.style.marginLeft = '8px';
  1024. editCheckBox.setAttribute('title', window.location.href);
  1025. div.appendChild(editCheckBox);
  1026. mxUtils.write(div, mxResources.get('edit') + ' ');
  1027. var editBlankCheckBox = document.createElement('input');
  1028. editBlankCheckBox.setAttribute('type', 'checkbox');
  1029. editBlankCheckBox.style.marginLeft = '8px';
  1030. div.appendChild(editBlankCheckBox);
  1031. mxUtils.write(div, mxResources.get('asNew') + ' ');
  1032. mxUtils.br(div);
  1033. var resizeCheckBox = document.createElement('input');
  1034. resizeCheckBox.setAttribute('type', 'checkbox');
  1035. resizeCheckBox.setAttribute('checked', 'checked');
  1036. resizeCheckBox.defaultChecked = true;
  1037. resizeCheckBox.style.marginLeft = '16px';
  1038. div.appendChild(resizeCheckBox);
  1039. mxUtils.write(div, mxResources.get('resize') + ' ');
  1040. var fitCheckBox = document.createElement('input');
  1041. fitCheckBox.setAttribute('type', 'checkbox');
  1042. fitCheckBox.style.marginLeft = '8px';
  1043. div.appendChild(fitCheckBox);
  1044. mxUtils.write(div, mxResources.get('fit') + ' ');
  1045. var embedCheckBox = document.createElement('input');
  1046. embedCheckBox.setAttribute('type', 'checkbox');
  1047. embedCheckBox.style.marginLeft = '8px';
  1048. div.appendChild(embedCheckBox);
  1049. mxUtils.write(div, mxResources.get('embed') + ' ');
  1050. var node = null;
  1051. var s = editorUi.getBasenames().join(';');
  1052. var file = editorUi.getCurrentFile();
  1053. function update()
  1054. {
  1055. var title = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1056. if (embedCheckBox.checked && urlInput.value != '')
  1057. {
  1058. var encUrl = encodeURIComponent(mxUtils.htmlEntities(urlInput.value));
  1059. var gurl = 'https://www.draw.io/gadget.xml?type=4&diagram=' + encUrl;
  1060. if (title != null)
  1061. {
  1062. gurl += '&title=' + encodeURIComponent(title);
  1063. }
  1064. if (s.length > 0)
  1065. {
  1066. gurl += '&s=' + s;
  1067. }
  1068. if (borderInput.value != '' && borderInput.value != '0')
  1069. {
  1070. gurl += '&border=' + borderInput.value;
  1071. }
  1072. if (heightInput.value != '')
  1073. {
  1074. gurl += '&height=' + heightInput.value;
  1075. }
  1076. gurl += '&pan=' + ((panCheckBox.checked) ? '1': '0');
  1077. gurl += '&zoom=' + ((zoomCheckBox.checked) ? '1': '0');
  1078. gurl += '&fit=' + ((fitCheckBox.checked) ? '1': '0');
  1079. gurl += '&resize=' + ((resizeCheckBox.checked) ? '1': '0');
  1080. gurl += '&x0=' + Number(topInput.value);
  1081. gurl += '&y0=' + y0;
  1082. if (graph.mathEnabled)
  1083. {
  1084. gurl += '&math=1';
  1085. }
  1086. if (editBlankCheckBox.checked)
  1087. {
  1088. gurl += '&edit=_blank';
  1089. }
  1090. else if (editCheckBox.checked)
  1091. {
  1092. gurl += '&edit=' + encodeURIComponent(mxUtils.htmlEntities(window.location.href));
  1093. }
  1094. gadgetInput.value = gurl;
  1095. }
  1096. else if (file.constructor == DriveFile || file.constructor == DropboxFile)
  1097. {
  1098. var gurl = 'https://www.draw.io/gadget.xml?embed=0&diagram=';
  1099. if (urlInput.value != '')
  1100. {
  1101. gurl += encodeURIComponent(mxUtils.htmlEntities(urlInput.value)) + '&type=3';
  1102. }
  1103. else
  1104. {
  1105. gurl += file.getHash().substring(1);
  1106. if (file.constructor == DropboxFile)
  1107. {
  1108. gurl += '&type=2';
  1109. }
  1110. else
  1111. {
  1112. gurl += '&type=1';
  1113. }
  1114. }
  1115. if (title != null)
  1116. {
  1117. gurl += '&title=' + encodeURIComponent(title);
  1118. }
  1119. if (heightInput.value != '')
  1120. {
  1121. var h = parseInt(heightInput.value) + parseInt(topInput.value);
  1122. gurl += '&height=' + h;
  1123. }
  1124. gadgetInput.value = gurl;
  1125. }
  1126. else
  1127. {
  1128. gadgetInput.value = '';
  1129. }
  1130. };
  1131. mxEvent.addListener(panCheckBox, 'change', update);
  1132. mxEvent.addListener(zoomCheckBox, 'change', update);
  1133. mxEvent.addListener(resizeCheckBox, 'change', update);
  1134. mxEvent.addListener(fitCheckBox, 'change', update);
  1135. mxEvent.addListener(editCheckBox, 'change', update);
  1136. mxEvent.addListener(editBlankCheckBox, 'change', update);
  1137. mxEvent.addListener(embedCheckBox, 'change', update);
  1138. mxEvent.addListener(heightInput, 'change', update);
  1139. mxEvent.addListener(topInput, 'change', update);
  1140. mxEvent.addListener(borderInput, 'change', update);
  1141. mxEvent.addListener(urlInput, 'change', update);
  1142. update();
  1143. mxEvent.addListener(gadgetInput, 'click', function()
  1144. {
  1145. gadgetInput.focus();
  1146. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1147. {
  1148. gadgetInput.select();
  1149. }
  1150. else
  1151. {
  1152. document.execCommand('selectAll', false, null);
  1153. }
  1154. });
  1155. var buttons = document.createElement('div');
  1156. buttons.style.paddingTop = '12px';
  1157. buttons.style.textAlign = 'right';
  1158. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  1159. {
  1160. editorUi.hideDialog();
  1161. });
  1162. closeBtn.className = 'geBtn gePrimaryBtn';
  1163. buttons.appendChild(closeBtn);
  1164. div.appendChild(buttons);
  1165. this.container = div;
  1166. };
  1167. /**
  1168. * Constructs a new parse dialog.
  1169. */
  1170. var CreateGraphDialog = function(editorUi, title, type)
  1171. {
  1172. var div = document.createElement('div');
  1173. div.style.textAlign = 'right';
  1174. this.init = function()
  1175. {
  1176. var container = document.createElement('div');
  1177. container.style.position = 'relative';
  1178. container.style.border = '1px solid gray';
  1179. container.style.width = '100%';
  1180. container.style.height = '360px';
  1181. container.style.overflow = 'hidden';
  1182. container.style.marginBottom = '16px';
  1183. mxEvent.disableContextMenu(container);
  1184. div.appendChild(container);
  1185. var graph = new Graph(container);
  1186. graph.setCellsCloneable(true);
  1187. graph.setPanning(true);
  1188. graph.setAllowDanglingEdges(false);
  1189. graph.connectionHandler.select = false;
  1190. graph.view.setTranslate(20, 20);
  1191. graph.border = 20;
  1192. graph.panningHandler.useLeftButtonForPanning = true;
  1193. var vertexStyle = 'rounded=1;';
  1194. var edgeStyle = 'curved=1;';
  1195. var startStyle = 'ellipse';
  1196. // FIXME: Does not work in iPad
  1197. var mxCellRendererInstallCellOverlayListeners = mxCellRenderer.prototype.installCellOverlayListeners;
  1198. graph.cellRenderer.installCellOverlayListeners = function(state, overlay, shape)
  1199. {
  1200. mxCellRenderer.prototype.installCellOverlayListeners.apply(this, arguments);
  1201. mxEvent.addListener(shape.node, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown', function (evt)
  1202. {
  1203. overlay.fireEvent(new mxEventObject('pointerdown', 'event', evt, 'state', state));
  1204. });
  1205. if (!mxClient.IS_POINTER && mxClient.IS_TOUCH)
  1206. {
  1207. mxEvent.addListener(shape.node, 'touchstart', function (evt)
  1208. {
  1209. overlay.fireEvent(new mxEventObject('pointerdown', 'event', evt, 'state', state));
  1210. });
  1211. }
  1212. };
  1213. graph.getAllConnectionConstraints = function()
  1214. {
  1215. return null;
  1216. };
  1217. // Keeps highlight behind overlays
  1218. graph.connectionHandler.marker.highlight.keepOnTop = false;
  1219. graph.connectionHandler.createEdgeState = function(me)
  1220. {
  1221. var edge = graph.createEdge(null, null, null, null, null, edgeStyle);
  1222. return new mxCellState(this.graph.view, edge, this.graph.getCellStyle(edge));
  1223. };
  1224. // Gets the default parent for inserting new cells. This
  1225. // is normally the first child of the root (ie. layer 0).
  1226. var parent = graph.getDefaultParent();
  1227. var addOverlay = mxUtils.bind(this, function(cell)
  1228. {
  1229. // Creates a new overlay with an image and a tooltip
  1230. var overlay = new mxCellOverlay(this.connectImage, 'Add outgoing');
  1231. overlay.cursor = 'hand';
  1232. // Installs a handler for clicks on the overlay
  1233. overlay.addListener(mxEvent.CLICK, function(sender, evt2)
  1234. {
  1235. // TODO: Add menu for picking next shape
  1236. graph.connectionHandler.reset();
  1237. graph.clearSelection();
  1238. var geo = graph.getCellGeometry(cell);
  1239. var v2;
  1240. executeLayout(function()
  1241. {
  1242. v2 = graph.insertVertex(parent, null, 'Entry', geo.x, geo.y, 80, 30, vertexStyle);
  1243. addOverlay(v2);
  1244. graph.view.refresh(v2);
  1245. var e1 = graph.insertEdge(parent, null, '', cell, v2, edgeStyle);
  1246. }, function()
  1247. {
  1248. graph.scrollCellToVisible(v2);
  1249. });
  1250. });
  1251. // FIXME: Does not work in iPad (inserts loop)
  1252. overlay.addListener('pointerdown', function(sender, eo)
  1253. {
  1254. var evt2 = eo.getProperty('event');
  1255. var state = eo.getProperty('state');
  1256. graph.popupMenuHandler.hideMenu();
  1257. graph.stopEditing(false);
  1258. var pt = mxUtils.convertPoint(graph.container,
  1259. mxEvent.getClientX(evt2), mxEvent.getClientY(evt2));
  1260. graph.connectionHandler.start(state, pt.x, pt.y);
  1261. graph.isMouseDown = true;
  1262. graph.isMouseTrigger = mxEvent.isMouseEvent(evt2);
  1263. mxEvent.consume(evt2);
  1264. });
  1265. // Sets the overlay for the cell in the graph
  1266. graph.addCellOverlay(cell, overlay);
  1267. });
  1268. // Adds cells to the model in a single step
  1269. graph.getModel().beginUpdate();
  1270. var v1;
  1271. try
  1272. {
  1273. v1 = graph.insertVertex(parent, null, 'Start', 0, 0, 80, 30, startStyle);
  1274. addOverlay(v1);
  1275. }
  1276. finally
  1277. {
  1278. // Updates the display
  1279. graph.getModel().endUpdate();
  1280. }
  1281. var layout;
  1282. if (type == 'horizontalTree')
  1283. {
  1284. layout = new mxCompactTreeLayout(graph);
  1285. layout.edgeRouting = false;
  1286. layout.levelDistance = 30;
  1287. edgeStyle = 'edgeStyle=elbowEdgeStyle;elbow=horizontal;';
  1288. }
  1289. else if (type == 'verticalTree')
  1290. {
  1291. layout = new mxCompactTreeLayout(graph, false);
  1292. layout.edgeRouting = false;
  1293. layout.levelDistance = 30;
  1294. edgeStyle = 'edgeStyle=elbowEdgeStyle;elbow=vertical;';
  1295. }
  1296. else if (type == 'verticalFlow')
  1297. {
  1298. layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_NORTH);
  1299. }
  1300. else if (type == 'horizontalFlow')
  1301. {
  1302. layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_WEST);
  1303. }
  1304. else if (type == 'organic')
  1305. {
  1306. layout = new mxFastOrganicLayout(graph, false);
  1307. layout.forceConstant = 80;
  1308. }
  1309. else if (type == 'circle')
  1310. {
  1311. layout = new mxCircleLayout(graph);
  1312. }
  1313. if (layout != null)
  1314. {
  1315. var executeLayout = function(change, post)
  1316. {
  1317. graph.getModel().beginUpdate();
  1318. try
  1319. {
  1320. if (change != null)
  1321. {
  1322. change();
  1323. }
  1324. layout.execute(graph.getDefaultParent(), v1);
  1325. }
  1326. catch (e)
  1327. {
  1328. throw e;
  1329. }
  1330. finally
  1331. {
  1332. // New API for animating graph layout results asynchronously
  1333. var morph = new mxMorphing(graph);
  1334. morph.addListener(mxEvent.DONE, mxUtils.bind(this, function()
  1335. {
  1336. graph.getModel().endUpdate();
  1337. if (post != null)
  1338. {
  1339. post();
  1340. }
  1341. }));
  1342. morph.startAnimation();
  1343. }
  1344. };
  1345. var edgeHandleConnect = mxEdgeHandler.prototype.connect;
  1346. mxEdgeHandler.prototype.connect = function(edge, terminal, isSource, isClone, me)
  1347. {
  1348. edgeHandleConnect.apply(this, arguments);
  1349. executeLayout();
  1350. };
  1351. graph.resizeCell = function()
  1352. {
  1353. mxGraph.prototype.resizeCell.apply(this, arguments);
  1354. executeLayout();
  1355. };
  1356. graph.connectionHandler.addListener(mxEvent.CONNECT, function()
  1357. {
  1358. executeLayout();
  1359. });
  1360. }
  1361. var cancelBtn = mxUtils.button(mxResources.get('close'), function()
  1362. {
  1363. editorUi.confirm(mxResources.get('areYouSure'), function()
  1364. {
  1365. if (container.parentNode != null)
  1366. {
  1367. graph.destroy();
  1368. container.parentNode.removeChild(container);
  1369. }
  1370. editorUi.hideDialog();
  1371. });
  1372. })
  1373. cancelBtn.className = 'geBtn';
  1374. if (editorUi.editor.cancelFirst)
  1375. {
  1376. div.appendChild(cancelBtn);
  1377. }
  1378. var okBtn = mxUtils.button(mxResources.get('insert'), function()
  1379. {
  1380. graph.clearCellOverlays();
  1381. // Computes unscaled, untranslated graph bounds
  1382. var pt = editorUi.editor.graph.getFreeInsertPoint();
  1383. var cells = editorUi.editor.graph.importCells(
  1384. graph.getModel().getChildren(graph.getDefaultParent()), pt.x, pt.y);
  1385. var view = editorUi.editor.graph.view;
  1386. var temp = view.getBounds(cells);
  1387. temp.x -= view.translate.x;
  1388. temp.y -= view.translate.y;
  1389. editorUi.editor.graph.scrollRectToVisible(temp);
  1390. editorUi.editor.graph.setSelectionCells(cells);
  1391. if (container.parentNode != null)
  1392. {
  1393. graph.destroy();
  1394. container.parentNode.removeChild(container);
  1395. }
  1396. editorUi.hideDialog();
  1397. });
  1398. div.appendChild(okBtn);
  1399. okBtn.className = 'geBtn gePrimaryBtn';
  1400. if (!editorUi.editor.cancelFirst)
  1401. {
  1402. div.appendChild(cancelBtn);
  1403. }
  1404. };
  1405. this.container = div;
  1406. };
  1407. /**
  1408. *
  1409. */
  1410. CreateGraphDialog.prototype.connectImage = new mxImage((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RjQ3OTk0QjMyRDcyMTFFNThGQThGNDVBMjNBMjFDMzkiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RjQ3OTk0QjQyRDcyMTFFNThGQThGNDVBMjNBMjFDMzkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDoyRjA0N0I2MjJENzExMUU1OEZBOEY0NUEyM0EyMUMzOSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpGNDc5OTRCMjJENzIxMUU1OEZBOEY0NUEyM0EyMUMzOSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PjIf+MgAAATlSURBVHjanFZraFxFFD735u4ru3ls0yZG26ShgmJoKK1J2vhIYzBgRdtIURHyw1hQUH9IxIgI2h8iCEUF/1RRlNQYCsYfCTHVhiTtNolpZCEStqSC22xIsrs1bDfu7t37Gs/cO3Ozxs1DBw73zpk555vzmHNGgJ0NYatFgmNLYUHYUoHASMz5ijmgVLmxgfKCUiBxC4ACJAeSG8nb1dVVOTc3dyoSibwWDofPBIPBJzo7O8vpGtvjpDICGztxkciECpF2LS0tvZtOpwNkk5FKpcYXFxffwL1+JuPgllPj8nk1F6RoaGjoKCqZ5ApljZDZO4SMRA0SuG2QUJIQRV8HxMOM9vf3H0ZZH9Nhg20MMl2QkFwjIyNHWlpahtADnuUMwLcRHX5aNSBjCJYEsSSLUeLEbhGe3ytCmQtA1/XY+Pj46dbW1iDuyCJp9BC5ycBj4hoeHq5ra2sbw0Xn1ZgBZ+dVkA1Lc+6p0Ck2p0QS4Ox9EhwpEylYcmBg4LH29vYQLilIOt0u5FhDfevNZDI/u93uw6PLOrwTUtjxrbPYbhD42WgMrF8JmR894ICmCgnQjVe8Xu8pXEkzMJKbuo5oNPomBbm1ZsD7s2kwFA1JZ6QBUXWT1nmGNc/qoMgavDcrQzxjQGFh4aOYIJ0sFAXcEtui4uLiVjr5KpSBVFYDDZVrWUaKRRWSAYeK0fmKykgDXbVoNaPChRuyqdDv97czL5nXxQbq6empQmsaklkDBiNpSwFVrmr2P6UyicD5piI4f8wHh0oEm8/p4h8pyGiEWvVQd3e3nxtjAzU1NR2jP7NRBWQ8GbdEzzJAmc0V3RR4cI8Dvmwuhc8fKUFA0d6/ltHg5p+Kuaejo6OeY0jcNJ/PV00ZS0nFUoZRvvFS1bZFsKHCCQ2Pl8H0chY+C96B6ZUsrCQ1qKtwQVFRURW/QhIXMAzDPAZ6BgOr8tTa8dDxCmiYGApaJbJMxSzV+brE8pdgWkcpY5dbMF1AR9XH8/xu2ilef48bvn92n82ZwHh+8ssqTEXS9p7dHisiiURikd8PbpExNTU1UVNTA3V3Y7lC16n0gpB/NwpNcZjfa7dScC4Qh0kOQCwnlEgi3F/hMVl9fX0zvKrzSk2lfXjRhj0eT/2rvWG4+Pta3oJY7XfC3hInXAv/ldeFLx8shQ+eqQL0UAAz7ylkpej5eNZRVBWL6BU6ef14OYiY1oqyTtmsavr/5koaRucT1pzx+ZpL1+GV5nLutksUgIcmtwTRiuuVZXnU5XId7A2swJkfFsymRWC91hHg1Viw6x23+7vn9sPJ+j20BE1hCXqSWaNSQ8ScbknRZWxub1PGCw/fBV+c3AeijlUbY5bBjEqr9GuYZP4jP41WudGSC6erTRCqdGZm5i1WvXWeDHnbBCZGc2Nj4wBl/hZOwrmBBfgmlID1HmGJutHaF+tKoevp/XCgstDkjo2NtWKLuc6AVN4mNjY+s1XQxoenOoFuDPHGtnRbJj9ej5GvL0dI7+giuRyMk1giazc+DP6vgUDgOJVlOv7R+PJ12QIeL6SyeDz+Kfp8ZrNWjgDTsVjsQ7qXyTjztXJhm9ePxFLfMTg4eG9tbe1RTP9KFFYQfHliYmIS69kCC7jKYmKwxxD5P88tkVkqbPPcIps9t4T/+HjcuJ/s5BFJgf4WYABCtxGuxIZ90gAAAABJRU5ErkJggg==' :
  1411. IMAGE_PATH + '/handle-connect.png', 26, 26);
  1412. /**
  1413. * Constructs a new parse dialog.
  1414. */
  1415. var BackgroundImageDialog = function(editorUi, applyFn)
  1416. {
  1417. var div = document.createElement('div');
  1418. div.style.whiteSpace = 'nowrap';
  1419. var h3 = document.createElement('h2');
  1420. mxUtils.write(h3, mxResources.get('backgroundImage'));
  1421. h3.style.marginTop = '0px';
  1422. div.appendChild(h3);
  1423. mxUtils.write(div, mxResources.get('image') + ' ' + mxResources.get('url') + ':');
  1424. mxUtils.br(div);
  1425. var img = editorUi.editor.graph.backgroundImage;
  1426. var urlInput = document.createElement('input');
  1427. urlInput.setAttribute('type', 'text');
  1428. urlInput.style.marginTop = '4px';
  1429. urlInput.style.marginBottom = '4px';
  1430. urlInput.style.width = '350px';
  1431. urlInput.value = (img != null) ? img.src : '';
  1432. var resetting = false;
  1433. var urlChanged = function()
  1434. {
  1435. if (!resetting && urlInput.value != '' && !editorUi.isOffline())
  1436. {
  1437. editorUi.loadImage(mxUtils.trim(urlInput.value), function(img)
  1438. {
  1439. widthInput.value = img.width;
  1440. heightInput.value = img.height;
  1441. }, function()
  1442. {
  1443. editorUi.showError(mxResources.get('error'), mxResources.get('fileNotFound'), mxResources.get('ok'));
  1444. urlInput.value = '';
  1445. widthInput.value = '';
  1446. heightInput.value = '';
  1447. });
  1448. }
  1449. else
  1450. {
  1451. widthInput.value = '';
  1452. heightInput.value = '';
  1453. }
  1454. };
  1455. this.init = function()
  1456. {
  1457. urlInput.focus();
  1458. // Installs drag and drop handler for local images and links
  1459. if (Graph.fileSupport)
  1460. {
  1461. urlInput.setAttribute('placeholder', mxResources.get('dragImagesHere'));
  1462. // Setup the dnd listeners
  1463. var dlg = div.parentNode;
  1464. var graph = editorUi.editor.graph;
  1465. var dropElt = null;
  1466. mxEvent.addListener(dlg, 'dragleave', function(evt)
  1467. {
  1468. if (dropElt != null)
  1469. {
  1470. dropElt.parentNode.removeChild(dropElt);
  1471. dropElt = null;
  1472. }
  1473. evt.stopPropagation();
  1474. evt.preventDefault();
  1475. });
  1476. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  1477. {
  1478. // IE 10 does not implement pointer-events so it can't have a drop highlight
  1479. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  1480. {
  1481. dropElt = editorUi.highlightElement(dlg);
  1482. }
  1483. evt.stopPropagation();
  1484. evt.preventDefault();
  1485. }));
  1486. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  1487. {
  1488. if (dropElt != null)
  1489. {
  1490. dropElt.parentNode.removeChild(dropElt);
  1491. dropElt = null;
  1492. }
  1493. if (evt.dataTransfer.files.length > 0)
  1494. {
  1495. editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxBackgroundSize, function(data, mimeType, x, y, w, h)
  1496. {
  1497. urlInput.value = data;
  1498. urlChanged();
  1499. }, function()
  1500. {
  1501. // No post processing
  1502. }, function(file)
  1503. {
  1504. // Handles only images
  1505. return file.type.substring(0, 6) == 'image/';
  1506. }, function(queue)
  1507. {
  1508. // Invokes elements of queue in order
  1509. for (var i = 0; i < queue.length; i++)
  1510. {
  1511. queue[i]();
  1512. }
  1513. }, true, editorUi.maxBackgroundBytes, editorUi.maxBackgroundBytes);
  1514. }
  1515. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  1516. {
  1517. var uri = evt.dataTransfer.getData('text/uri-list');
  1518. if ((/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(uri))
  1519. {
  1520. urlInput.value = decodeURIComponent(uri);
  1521. urlChanged();
  1522. }
  1523. }
  1524. evt.stopPropagation();
  1525. evt.preventDefault();
  1526. }), false);
  1527. }
  1528. };
  1529. div.appendChild(urlInput);
  1530. mxUtils.br(div);
  1531. mxUtils.br(div);
  1532. mxUtils.write(div, mxResources.get('width') + ':');
  1533. var widthInput = document.createElement('input');
  1534. widthInput.setAttribute('type', 'text');
  1535. widthInput.style.width = '60px';
  1536. widthInput.style.marginLeft = '4px';
  1537. widthInput.style.marginRight = '16px';
  1538. widthInput.value = (img != null) ? img.width : '';
  1539. div.appendChild(widthInput);
  1540. mxUtils.write(div, mxResources.get('height') + ':');
  1541. var heightInput = document.createElement('input');
  1542. heightInput.setAttribute('type', 'text');
  1543. heightInput.style.width = '60px';
  1544. heightInput.style.marginLeft = '4px';
  1545. heightInput.style.marginRight = '16px';
  1546. heightInput.value = (img != null) ? img.height : '';
  1547. div.appendChild(heightInput);
  1548. var resetBtn = mxUtils.button(mxResources.get('reset'), function()
  1549. {
  1550. urlInput.value = '';
  1551. widthInput.value = '';
  1552. heightInput.value = '';
  1553. resetting = false;
  1554. });
  1555. mxEvent.addListener(resetBtn, 'mousedown', function()
  1556. {
  1557. // Blocks processing a image URL while clicking reset
  1558. resetting = true;
  1559. });
  1560. mxEvent.addListener(resetBtn, 'touchstart', function()
  1561. {
  1562. // Blocks processing a image URL while clicking reset
  1563. resetting = true;
  1564. });
  1565. resetBtn.className = 'geBtn';
  1566. resetBtn.width = '100';
  1567. div.appendChild(resetBtn);
  1568. mxUtils.br(div);
  1569. mxEvent.addListener(urlInput, 'change', urlChanged);
  1570. ImageDialog.filePicked = function(data)
  1571. {
  1572. if (data.action == google.picker.Action.PICKED)
  1573. {
  1574. if (data.docs[0].thumbnails != null)
  1575. {
  1576. var thumb = data.docs[0].thumbnails[data.docs[0].thumbnails.length - 1];
  1577. if (thumb != null)
  1578. {
  1579. urlInput.value = thumb.url;
  1580. urlChanged();
  1581. }
  1582. }
  1583. }
  1584. urlInput.focus();
  1585. };
  1586. var btns = document.createElement('div');
  1587. btns.style.marginTop = '40px';
  1588. btns.style.textAlign = 'right';
  1589. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1590. {
  1591. editorUi.hideDialog();
  1592. });
  1593. cancelBtn.className = 'geBtn';
  1594. if (editorUi.editor.cancelFirst)
  1595. {
  1596. btns.appendChild(cancelBtn);
  1597. }
  1598. if (!editorUi.isOffline())
  1599. {
  1600. // Dialogs not allowed inside iframes
  1601. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined' && window.self === window.top)
  1602. {
  1603. var searchBtn = mxUtils.button(mxResources.get('search'), function()
  1604. {
  1605. // Creates one picker and reuses it to avoid polluting the DOM
  1606. if (editorUi.imageSearchPicker == null)
  1607. {
  1608. var picker = new google.picker.PickerBuilder()
  1609. .setLocale(mxLanguage)
  1610. .addView(google.picker.ViewId.IMAGE_SEARCH)
  1611. .enableFeature(google.picker.Feature.NAV_HIDDEN);
  1612. editorUi.imageSearchPicker = picker.setCallback(function(data)
  1613. {
  1614. ImageDialog.filePicked(data);
  1615. }).build();
  1616. }
  1617. editorUi.imageSearchPicker.setVisible(true);
  1618. editorUi.movePickersToTop();
  1619. });
  1620. searchBtn.className = 'geBtn';
  1621. btns.appendChild(searchBtn);
  1622. if (editorUi.drive != null && urlParams['photos'] == '1')
  1623. {
  1624. var gpBtn = mxUtils.button(mxResources.get('googlePlus'), function()
  1625. {
  1626. if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  1627. {
  1628. editorUi.drive.checkToken(mxUtils.bind(this, function()
  1629. {
  1630. editorUi.spinner.stop();
  1631. // Creates one picker and reuses it to avoid polluting the DOM
  1632. if (editorUi.photoPicker == null)
  1633. {
  1634. var token = gapi.auth.getToken().access_token;
  1635. var picker = new google.picker.PickerBuilder()
  1636. .setAppId(editorUi.drive.appId)
  1637. .setLocale(mxLanguage)
  1638. .setOAuthToken(token)
  1639. .addView(google.picker.ViewId.PHOTOS)
  1640. .addView(google.picker.ViewId.PHOTO_ALBUMS)
  1641. .addView(google.picker.ViewId.PHOTO_UPLOAD);
  1642. editorUi.photoPicker = picker.setCallback(function(data)
  1643. {
  1644. ImageDialog.filePicked(data);
  1645. }).build();
  1646. }
  1647. editorUi.photoPicker.setVisible(true);
  1648. editorUi.movePickersToTop();
  1649. }));
  1650. }
  1651. });
  1652. gpBtn.className = 'geBtn';
  1653. btns.appendChild(gpBtn);
  1654. }
  1655. }
  1656. }
  1657. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  1658. {
  1659. editorUi.hideDialog();
  1660. applyFn((urlInput.value != '') ? new mxImage(mxUtils.trim(urlInput.value), widthInput.value, heightInput.value) : null);
  1661. });
  1662. applyBtn.className = 'geBtn gePrimaryBtn';
  1663. btns.appendChild(applyBtn);
  1664. if (!editorUi.editor.cancelFirst)
  1665. {
  1666. btns.appendChild(cancelBtn);
  1667. }
  1668. div.appendChild(btns);
  1669. this.container = div;
  1670. };
  1671. /**
  1672. * Constructs a new parse dialog.
  1673. */
  1674. var ParseDialog = function(editorUi, title)
  1675. {
  1676. var insertPoint = editorUi.editor.graph.getFreeInsertPoint();
  1677. function parse(text, type)
  1678. {
  1679. var lines = text.split('\n');
  1680. if (type == 'plantUmlPng' || type == 'plantUmlSvg')
  1681. {
  1682. var plantUmlServerUrl = (type == 'plantUmlPng') ? 'https://exp.draw.io/plantuml2/png/' :
  1683. 'https://exp.draw.io/plantuml2/svg/';
  1684. var graph = editorUi.editor.graph;
  1685. // TODO: Change server to return base64 & accept POST request
  1686. if (editorUi.spinner.spin(document.body, mxResources.get('inserting')))
  1687. {
  1688. function encode64(data) {
  1689. r = "";
  1690. for (i=0; i<data.length; i+=3) {
  1691. if (i+2==data.length) {
  1692. r +=append3bytes(data.charCodeAt(i), data.charCodeAt(i+1), 0);
  1693. } else if (i+1==data.length) {
  1694. r += append3bytes(data.charCodeAt(i), 0, 0);
  1695. } else {
  1696. r += append3bytes(data.charCodeAt(i), data.charCodeAt(i+1),
  1697. data.charCodeAt(i+2));
  1698. }
  1699. }
  1700. return r;
  1701. }
  1702. function append3bytes(b1, b2, b3) {
  1703. c1 = b1 >> 2;
  1704. c2 = ((b1 & 0x3) << 4) | (b2 >> 4);
  1705. c3 = ((b2 & 0xF) << 2) | (b3 >> 6);
  1706. c4 = b3 & 0x3F;
  1707. r = "";
  1708. r += encode6bit(c1 & 0x3F);
  1709. r += encode6bit(c2 & 0x3F);
  1710. r += encode6bit(c3 & 0x3F);
  1711. r += encode6bit(c4 & 0x3F);
  1712. return r;
  1713. }
  1714. function encode6bit(b) {
  1715. if (b < 10) {
  1716. return String.fromCharCode(48 + b);
  1717. }
  1718. b -= 10;
  1719. if (b < 26) {
  1720. return String.fromCharCode(65 + b);
  1721. }
  1722. b -= 26;
  1723. if (b < 26) {
  1724. return String.fromCharCode(97 + b);
  1725. }
  1726. b -= 26;
  1727. if (b == 0) {
  1728. return '-';
  1729. }
  1730. if (b == 1) {
  1731. return '_';
  1732. }
  1733. return '?';
  1734. }
  1735. // TODO: Remove unescape, use btoa for compatibility with graph.compress
  1736. function compress(s)
  1737. {
  1738. return encode64(graph.bytesToString(pako.deflateRaw(unescape(encodeURIComponent(s)))));
  1739. }
  1740. var xhr = new XMLHttpRequest();
  1741. xhr.open('GET', plantUmlServerUrl + compress(text), true);
  1742. xhr.responseType = 'blob';
  1743. xhr.onload = function(e)
  1744. {
  1745. if (this.status >= 200 && this.status < 300)
  1746. {
  1747. var reader = new FileReader();
  1748. reader.readAsDataURL(this.response);
  1749. reader.onload = function(e)
  1750. {
  1751. var img = new Image();
  1752. img.onload = function()
  1753. {
  1754. editorUi.spinner.stop();
  1755. graph.getModel().beginUpdate();
  1756. try
  1757. {
  1758. cell = graph.insertVertex(null, null, text, insertPoint.x, insertPoint.y,
  1759. img.width, img.height, 'shape=image;noLabel=1;verticalAlign=top;aspect=fixed;imageAspect=0;' +
  1760. 'image=' + editorUi.convertDataUri(e.target.result) + ';');
  1761. }
  1762. finally
  1763. {
  1764. graph.getModel().endUpdate();
  1765. }
  1766. graph.setSelectionCell(cell);
  1767. graph.scrollCellToVisible(graph.getSelectionCell());
  1768. };
  1769. img.src = e.target.result;
  1770. };
  1771. reader.onerror = function(e)
  1772. {
  1773. editorUi.handleError(e);
  1774. };
  1775. }
  1776. else
  1777. {
  1778. editorUi.spinner.stop();
  1779. editorUi.handleError(e);
  1780. }
  1781. };
  1782. xhr.onerror = function(e)
  1783. {
  1784. editorUi.handleError(e);
  1785. };
  1786. xhr.send();
  1787. }
  1788. }
  1789. else if (type == 'list')
  1790. {
  1791. if (lines.length > 0)
  1792. {
  1793. var graph = editorUi.editor.graph;
  1794. var listCell = new mxCell(lines[0], new mxGeometry(0, 0, 160, 26 + 4),
  1795. 'swimlane;fontStyle=1;childLayout=stackLayout;horizontal=1;startSize=26;fillColor=none;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;swimlaneFillColor=#ffffff;');
  1796. listCell.vertex = true;
  1797. var size = graph.getPreferredSizeForCell(listCell);
  1798. if (size != null && listCell.geometry.width < size.width + 10)
  1799. {
  1800. listCell.geometry.width = size.width + 10;
  1801. }
  1802. if (lines.length > 1)
  1803. {
  1804. for (var i = 1; i < lines.length; i++)
  1805. {
  1806. if (lines[i] == '--')
  1807. {
  1808. var divider = new mxCell('', new mxGeometry(0, 0, 40, 8), 'line;strokeWidth=1;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=3;spacingRight=3;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;');
  1809. divider.vertex = true;
  1810. listCell.geometry.height += divider.geometry.height;
  1811. listCell.insert(divider);
  1812. }
  1813. else if (lines[i].length > 0 && lines[i].charAt(0) != ';')
  1814. {
  1815. var field = new mxCell(lines[i], new mxGeometry(0, 0, 60, 26), 'text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;');
  1816. field.vertex = true;
  1817. var size = graph.getPreferredSizeForCell(field);
  1818. if (size != null && field.geometry.width < size.width)
  1819. {
  1820. field.geometry.width = size.width;
  1821. }
  1822. listCell.geometry.width = Math.max(listCell.geometry.width, field.geometry.width);
  1823. listCell.geometry.height += field.geometry.height;
  1824. listCell.insert(field);
  1825. }
  1826. }
  1827. }
  1828. graph.setSelectionCells(graph.importCells([listCell], insertPoint.x, insertPoint.y));
  1829. graph.scrollCellToVisible(graph.getSelectionCell());
  1830. }
  1831. }
  1832. else
  1833. {
  1834. var vertices = new Object();
  1835. var cells = [];
  1836. function getOrCreateVertex(id)
  1837. {
  1838. var vertex = vertices[id];
  1839. if (vertex == null)
  1840. {
  1841. vertex = new mxCell(id, new mxGeometry(0, 0, 80, 30));
  1842. vertex.vertex = true;
  1843. vertices[id] = vertex;
  1844. cells.push(vertex);
  1845. }
  1846. return vertex;
  1847. };
  1848. for (var i = 0; i < lines.length; i++)
  1849. {
  1850. if (lines[i].charAt(0) != ';')
  1851. {
  1852. var values = lines[i].split('->');
  1853. if (values.length == 2)
  1854. {
  1855. var source = getOrCreateVertex(values[0]);
  1856. var target = getOrCreateVertex(values[1]);
  1857. var edge = new mxCell('', new mxGeometry());
  1858. edge.edge = true;
  1859. source.insertEdge(edge, true);
  1860. target.insertEdge(edge, false);
  1861. cells.push(edge);
  1862. }
  1863. }
  1864. }
  1865. if (cells.length > 0)
  1866. {
  1867. var container = document.createElement('div');
  1868. container.style.visibility = 'hidden';
  1869. document.body.appendChild(container);
  1870. // Temporary graph for running the layout
  1871. var graph = new Graph(container);
  1872. graph.getModel().beginUpdate();
  1873. try
  1874. {
  1875. cells = graph.importCells(cells);
  1876. for (var i = 0; i < cells.length; i++)
  1877. {
  1878. if (graph.getModel().isVertex(cells[i]))
  1879. {
  1880. var size = graph.getPreferredSizeForCell(cells[i]);
  1881. cells[i].geometry.width = Math.max(cells[i].geometry.width, size.width);
  1882. cells[i].geometry.height = Math.max(cells[i].geometry.height, size.height);
  1883. }
  1884. }
  1885. var layout = new mxFastOrganicLayout(graph);
  1886. layout.disableEdgeStyle = false;
  1887. layout.forceConstant = 120;
  1888. layout.execute(graph.getDefaultParent());
  1889. }
  1890. finally
  1891. {
  1892. graph.getModel().endUpdate();
  1893. }
  1894. graph.clearCellOverlays();
  1895. editorUi.editor.graph.setSelectionCells(editorUi.editor.graph.importCells(
  1896. graph.getModel().getChildren(graph.getDefaultParent()), insertPoint.x, insertPoint.y));
  1897. editorUi.editor.graph.scrollCellToVisible(editorUi.editor.graph.getSelectionCell());
  1898. graph.destroy();
  1899. container.parentNode.removeChild(container);
  1900. }
  1901. }
  1902. };
  1903. var div = document.createElement('div');
  1904. div.style.textAlign = 'right';
  1905. var textarea = document.createElement('textarea');
  1906. textarea.style.resize = 'none';
  1907. textarea.style.width = '100%';
  1908. textarea.style.height = '354px';
  1909. textarea.style.marginBottom = '16px';
  1910. var typeSelect = document.createElement('select');
  1911. var listOption = document.createElement('option');
  1912. listOption.setAttribute('value', 'list');
  1913. listOption.setAttribute('selected', 'selected');
  1914. mxUtils.write(listOption, mxResources.get('list'));
  1915. typeSelect.appendChild(listOption);
  1916. var diagramOption = document.createElement('option');
  1917. diagramOption.setAttribute('value', 'diagram');
  1918. mxUtils.write(diagramOption, mxResources.get('diagram'));
  1919. typeSelect.appendChild(diagramOption);
  1920. var plantUmlSvgOption = document.createElement('option');
  1921. plantUmlSvgOption.setAttribute('value', 'plantUmlSvg');
  1922. mxUtils.write(plantUmlSvgOption, mxResources.get('plantUml') + ' (' + mxResources.get('formatSvg') + ')');
  1923. var plantUmlPngOption = document.createElement('option');
  1924. plantUmlPngOption.setAttribute('value', 'plantUmlPng');
  1925. mxUtils.write(plantUmlPngOption, mxResources.get('plantUml') + ' (' + mxResources.get('formatPng') + ')');
  1926. // Disabled for invalid hosts via CORS headers
  1927. if (/.*\.draw\.io$/.test(window.location.hostname) && Graph.fileSupport && !editorUi.isOffline())
  1928. {
  1929. typeSelect.appendChild(plantUmlSvgOption);
  1930. typeSelect.appendChild(plantUmlPngOption);
  1931. }
  1932. function getDefaultValue()
  1933. {
  1934. return (typeSelect.value == 'list') ?
  1935. 'Person\n-name: String\n-birthDate: Date\n--\n+getName(): String\n+setName(String): void\n+isBirthday(): boolean' :
  1936. ((typeSelect.value == 'plantUmlPng') ? '@startuml\nskinparam backgroundcolor transparent\nskinparam shadowing false\nAlice -> Bob: Authentication Request\nBob --> Alice: Authentication Response\n\nAlice -> Bob: Another authentication Request\nAlice <-- Bob: another authentication Response\n@enduml' :
  1937. ((typeSelect.value == 'plantUmlSvg') ? '@startuml\nskinparam shadowing false\nAlice -> Bob: Authentication Request\nBob --> Alice: Authentication Response\n\nAlice -> Bob: Another authentication Request\nAlice <-- Bob: another authentication Response\n@enduml' :
  1938. ';Example:\na->b\nb->c\nc->a\n'));
  1939. };
  1940. var defaultValue = getDefaultValue();
  1941. textarea.value = defaultValue;
  1942. div.appendChild(textarea);
  1943. this.init = function()
  1944. {
  1945. textarea.focus();
  1946. };
  1947. // Enables dropping files
  1948. if (Graph.fileSupport)
  1949. {
  1950. function handleDrop(evt)
  1951. {
  1952. evt.stopPropagation();
  1953. evt.preventDefault();
  1954. if (evt.dataTransfer.files.length > 0)
  1955. {
  1956. var file = evt.dataTransfer.files[0];
  1957. var reader = new FileReader();
  1958. reader.onload = function(e) { textarea.value = e.target.result; };
  1959. reader.readAsText(file);
  1960. }
  1961. };
  1962. function handleDragOver(evt)
  1963. {
  1964. evt.stopPropagation();
  1965. evt.preventDefault();
  1966. };
  1967. // Setup the dnd listeners.
  1968. textarea.addEventListener('dragover', handleDragOver, false);
  1969. textarea.addEventListener('drop', handleDrop, false);
  1970. }
  1971. div.appendChild(typeSelect);
  1972. mxEvent.addListener(typeSelect, 'change', function()
  1973. {
  1974. var newDefaultValue = getDefaultValue();
  1975. if (textarea.value.length == 0 || textarea.value == defaultValue)
  1976. {
  1977. defaultValue = newDefaultValue;
  1978. textarea.value = defaultValue;
  1979. }
  1980. });
  1981. var cancelBtn = mxUtils.button(mxResources.get('close'), function()
  1982. {
  1983. if (textarea.value == defaultValue)
  1984. {
  1985. editorUi.hideDialog();
  1986. }
  1987. else
  1988. {
  1989. editorUi.confirm(mxResources.get('areYouSure'), function()
  1990. {
  1991. editorUi.hideDialog();
  1992. });
  1993. }
  1994. });
  1995. cancelBtn.className = 'geBtn';
  1996. if (editorUi.editor.cancelFirst)
  1997. {
  1998. div.appendChild(cancelBtn);
  1999. }
  2000. var okBtn = mxUtils.button(mxResources.get('insert'), function()
  2001. {
  2002. editorUi.hideDialog();
  2003. parse(textarea.value, typeSelect.value);
  2004. });
  2005. div.appendChild(okBtn);
  2006. okBtn.className = 'geBtn gePrimaryBtn';
  2007. if (!editorUi.editor.cancelFirst)
  2008. {
  2009. div.appendChild(cancelBtn);
  2010. }
  2011. this.container = div;
  2012. };
  2013. /**
  2014. * Constructs a new dialog for creating files from templates.
  2015. */
  2016. var NewDialog = function(editorUi, compact, showName, callback)
  2017. {
  2018. showName = (showName != null) ? showName : true;
  2019. var outer = document.createElement('div');
  2020. outer.style.height = '100%';
  2021. var header = document.createElement('div');
  2022. header.style.whiteSpace = 'nowrap';
  2023. header.style.height = '46px';
  2024. outer.appendChild(header);
  2025. var logo = document.createElement('img');
  2026. logo.setAttribute('border', '0');
  2027. logo.setAttribute('align', 'absmiddle');
  2028. logo.style.width = '40px';
  2029. logo.style.height = '40px';
  2030. logo.style.marginRight = '10px';
  2031. logo.style.paddingBottom = '4px';
  2032. if (editorUi.mode == App.MODE_GOOGLE)
  2033. {
  2034. logo.src = IMAGE_PATH + '/google-drive-logo.svg';
  2035. }
  2036. else if (editorUi.mode == App.MODE_DROPBOX)
  2037. {
  2038. logo.src = IMAGE_PATH + '/dropbox-logo.svg';
  2039. }
  2040. else if (editorUi.mode == App.MODE_ONEDRIVE)
  2041. {
  2042. logo.src = IMAGE_PATH + '/onedrive-logo.svg';
  2043. }
  2044. else if (editorUi.mode == App.MODE_GITHUB)
  2045. {
  2046. logo.src = IMAGE_PATH + '/github-logo.svg';
  2047. }
  2048. else if (editorUi.mode == App.MODE_BROWSER)
  2049. {
  2050. logo.src = IMAGE_PATH + '/osa_database.png';
  2051. }
  2052. else
  2053. {
  2054. logo.src = IMAGE_PATH + '/osa_drive-harddisk.png';
  2055. }
  2056. if (!compact && showName)
  2057. {
  2058. header.appendChild(logo);
  2059. }
  2060. if (showName)
  2061. {
  2062. mxUtils.write(header, ((editorUi.mode == null || editorUi.mode == App.MODE_GOOGLE ||
  2063. editorUi.mode == App.MODE_BROWSER) ? mxResources.get('diagramName') : mxResources.get('filename')) + ':');
  2064. }
  2065. var ext = '.xml';
  2066. if (editorUi.mode == App.MODE_GOOGLE && editorUi.drive != null)
  2067. {
  2068. ext = editorUi.drive.extension;
  2069. }
  2070. else if (editorUi.mode == App.MODE_DROPBOX && editorUi.dropbox != null)
  2071. {
  2072. ext = editorUi.dropbox.extension;
  2073. }
  2074. else if (editorUi.mode == App.MODE_ONEDRIVE && editorUi.oneDrive != null)
  2075. {
  2076. ext = editorUi.oneDrive.extension;
  2077. }
  2078. else if (editorUi.mode == App.MODE_GITHUB && editorUi.gitHub != null)
  2079. {
  2080. ext = editorUi.gitHub.extension;
  2081. }
  2082. var nameInput = document.createElement('input');
  2083. nameInput.setAttribute('value', editorUi.defaultFilename + ext);
  2084. nameInput.style.marginRight = '20px';
  2085. nameInput.style.marginLeft = '10px';
  2086. nameInput.style.width = (compact) ? '220px' : '450px';
  2087. this.init = function()
  2088. {
  2089. if (showName)
  2090. {
  2091. nameInput.focus();
  2092. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  2093. {
  2094. nameInput.select();
  2095. }
  2096. else
  2097. {
  2098. document.execCommand('selectAll', false, null);
  2099. }
  2100. }
  2101. };
  2102. if (showName)
  2103. {
  2104. header.appendChild(nameInput);
  2105. }
  2106. var templateLibs = null;
  2107. var templateXml = null;
  2108. var selectedElt = null;
  2109. function create()
  2110. {
  2111. if (callback)
  2112. {
  2113. if (!showName)
  2114. {
  2115. editorUi.hideDialog();
  2116. }
  2117. callback(templateXml, nameInput.value);
  2118. }
  2119. else
  2120. {
  2121. var title = nameInput.value;
  2122. if (title != null && title.length > 0)
  2123. {
  2124. var tempMode = (editorUi.mode == App.MODE_ONEDRIVE || (editorUi.mode == App.MODE_GOOGLE &&
  2125. (editorUi.stateArg == null || editorUi.stateArg.folderId == null))) ? editorUi.mode : null;
  2126. editorUi.pickFolder(tempMode, function(folderId)
  2127. {
  2128. editorUi.createFile(title, templateXml, (templateLibs != null && templateLibs.length > 0) ? templateLibs : null, null, function()
  2129. {
  2130. editorUi.hideDialog();
  2131. }, null, folderId);
  2132. }, tempMode != App.MODE_GOOGLE);
  2133. }
  2134. }
  2135. };
  2136. var createButton = mxUtils.button(mxResources.get('create'), function()
  2137. {
  2138. create();
  2139. });
  2140. createButton.className = 'geBtn gePrimaryBtn';
  2141. var div = document.createElement('div');
  2142. div.style.border = '1px solid #d3d3d3';
  2143. div.style.position = 'absolute';
  2144. div.style.left = '160px';
  2145. div.style.right = '34px';
  2146. div.style.top = (showName) ? '72px' : '40px';
  2147. div.style.bottom = '76px';
  2148. div.style.margin = '6px 0 0 -1px';
  2149. div.style.padding = '6px';
  2150. div.style.overflow = 'auto';
  2151. var list = document.createElement('div');
  2152. list.style.cssText = 'position:absolute;left:30px;width:128px;top:72px;bottom:76px;margin-top:6px;overflow:auto;border:1px solid #d3d3d3;';
  2153. if (!showName)
  2154. {
  2155. list.style.top = '40px';
  2156. }
  2157. var w = 140;
  2158. var h = 140;
  2159. function selectElement(elt, xml, libs)
  2160. {
  2161. if (selectedElt != null)
  2162. {
  2163. selectedElt.style.backgroundColor = 'transparent';
  2164. selectedElt.style.border = '1px solid transparent';
  2165. }
  2166. templateXml = xml;
  2167. templateLibs = libs;
  2168. selectedElt = elt;
  2169. selectedElt.style.backgroundColor = '#e6eff8';
  2170. selectedElt.style.border = '1px solid #ccd9ea';
  2171. };
  2172. function addButton(url, libs, title, tooltip, select)
  2173. {
  2174. var elt = document.createElement('div');
  2175. elt.className = 'geTemplate';
  2176. elt.style.height = w + 'px';
  2177. elt.style.width = h + 'px';
  2178. if (tooltip != null && tooltip.length > 0)
  2179. {
  2180. elt.setAttribute('title', tooltip);
  2181. }
  2182. if (url != null && url.length > 0)
  2183. {
  2184. var png = url.substring(0, url.length - 4) + '.png';
  2185. elt.style.backgroundImage = 'url(' + TEMPLATE_PATH + '/' + url.substring(0, url.length - 4) + '.png)';
  2186. elt.style.backgroundPosition = 'center center';
  2187. elt.style.backgroundRepeat = 'no-repeat';
  2188. var createIt = false;
  2189. mxEvent.addListener(elt, 'click', function(evt)
  2190. {
  2191. createButton.setAttribute('disabled', 'disabled');
  2192. elt.style.backgroundColor = 'transparent';
  2193. elt.style.border = '1px solid transparent';
  2194. mxUtils.get(TEMPLATE_PATH + '/' + url, mxUtils.bind(this, function(req)
  2195. {
  2196. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  2197. {
  2198. createButton.removeAttribute('disabled');
  2199. selectElement(elt, req.getText(), libs);
  2200. if (createIt)
  2201. {
  2202. create();
  2203. }
  2204. }
  2205. }));
  2206. });
  2207. mxEvent.addListener(elt, 'dblclick', function(evt)
  2208. {
  2209. // Asynchronous double click handling after loading template
  2210. createIt = true;
  2211. });
  2212. }
  2213. else
  2214. {
  2215. elt.innerHTML = '<table width="100%" height="100%"><tr><td align="center" valign="middle">' +
  2216. mxResources.get(title) + '</td></tr></table>';
  2217. if (select)
  2218. {
  2219. selectElement(elt);
  2220. }
  2221. mxEvent.addListener(elt, 'click', function(evt)
  2222. {
  2223. selectElement(elt);
  2224. });
  2225. mxEvent.addListener(elt, 'dblclick', function(evt)
  2226. {
  2227. create();
  2228. });
  2229. }
  2230. div.appendChild(elt);
  2231. };
  2232. var categories = {};
  2233. var categoryCount = 1;
  2234. // Adds local basic templates
  2235. categories['basic'] = [{title: 'blankDiagram', select: true}];
  2236. var templates = categories['basic'];
  2237. function initUi()
  2238. {
  2239. var i0 = 0;
  2240. // Dynamic loading
  2241. function addTemplates()
  2242. {
  2243. var first = true;
  2244. while (i0 < templates.length && (first || mxUtils.mod(i0, 30) != 0))
  2245. {
  2246. var tmp = templates[i0++];
  2247. addButton(tmp.url, tmp.libs, tmp.title, tmp.tooltip, tmp.select);
  2248. first = false;
  2249. }
  2250. };
  2251. mxEvent.addListener(div, 'scroll', function(evt)
  2252. {
  2253. if (div.scrollTop + div.clientHeight >= div.scrollHeight)
  2254. {
  2255. addTemplates();
  2256. mxEvent.consume(evt);
  2257. }
  2258. });
  2259. var currentEntry = null;
  2260. for (var cat in categories)
  2261. {
  2262. var entry = document.createElement('div');
  2263. var label = mxResources.get(cat);
  2264. var templateList = categories[cat];
  2265. if (label == null)
  2266. {
  2267. label = cat.substring(0, 1).toUpperCase() + cat.substring(1);
  2268. }
  2269. if (label.length > 18)
  2270. {
  2271. label = label.substring(0, 18) + '&hellip;';
  2272. }
  2273. entry.style.cssText = 'display:block;cursor:pointer;padding:6px;white-space:nowrap;margin-bottom:-1px;overflow:hidden;text-overflow:ellipsis;';
  2274. entry.setAttribute('title', label + ' (' + templateList.length + ')');
  2275. mxUtils.write(entry, entry.getAttribute('title'));
  2276. list.appendChild(entry);
  2277. if (currentEntry == null)
  2278. {
  2279. currentEntry = entry;
  2280. currentEntry.style.backgroundColor = '#ebf2f9';
  2281. }
  2282. (function(cat2, entry2)
  2283. {
  2284. mxEvent.addListener(entry, 'click', function()
  2285. {
  2286. if (currentEntry != entry2)
  2287. {
  2288. currentEntry.style.backgroundColor = '';
  2289. currentEntry = entry2;
  2290. currentEntry.style.backgroundColor = '#ebf2f9';
  2291. div.scrollTop = 0;
  2292. div.innerHTML = '';
  2293. i0 = 0;
  2294. templates = categories[cat2];
  2295. addTemplates();
  2296. }
  2297. });
  2298. })(cat, entry);
  2299. }
  2300. addTemplates();
  2301. }
  2302. if (!compact)
  2303. {
  2304. outer.appendChild(list);
  2305. outer.appendChild(div);
  2306. var indexLoaded = false;
  2307. mxUtils.get(TEMPLATE_PATH + '/index.xml', function(req)
  2308. {
  2309. // Workaround for index loaded 3 times in iOS offline mode
  2310. if (!indexLoaded)
  2311. {
  2312. indexLoaded = true;
  2313. var tmpDoc = req.getXml();
  2314. var node = tmpDoc.documentElement.firstChild;
  2315. while (node != null)
  2316. {
  2317. if (typeof(node.getAttribute) !== 'undefined')
  2318. {
  2319. var url = node.getAttribute('url');
  2320. if (url != null)
  2321. {
  2322. var slash = url.indexOf('/');
  2323. var category = url.substring(0, slash);
  2324. var list = categories[category];
  2325. if (list == null)
  2326. {
  2327. categoryCount++;
  2328. list = [];
  2329. categories[category] = list;
  2330. }
  2331. list.push({url: node.getAttribute('url'), libs: node.getAttribute('libs'),
  2332. title: node.getAttribute('title'), tooltip: node.getAttribute('url')});
  2333. }
  2334. }
  2335. node = node.nextSibling;
  2336. }
  2337. initUi();
  2338. }
  2339. });
  2340. }
  2341. mxEvent.addListener(nameInput, 'keypress', function(e)
  2342. {
  2343. if (e.keyCode == 13)
  2344. {
  2345. create();
  2346. }
  2347. });
  2348. var btns = document.createElement('div');
  2349. btns.style.marginTop = (compact) ? '4px' : '16px';
  2350. btns.style.textAlign = 'right';
  2351. btns.style.position = 'absolute';
  2352. btns.style.left = '40px';
  2353. btns.style.bottom = '30px';
  2354. btns.style.right = '40px';
  2355. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  2356. {
  2357. editorUi.hideDialog(true);
  2358. });
  2359. cancelBtn.className = 'geBtn';
  2360. if (editorUi.editor.cancelFirst)
  2361. {
  2362. btns.appendChild(cancelBtn);
  2363. }
  2364. if (!compact && !editorUi.isOffline() && showName && callback == null)
  2365. {
  2366. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  2367. {
  2368. window.open('https://support.draw.io/display/DO/Creating+and+Opening+Files');
  2369. });
  2370. helpBtn.className = 'geBtn';
  2371. btns.appendChild(helpBtn);
  2372. }
  2373. if (!compact && urlParams['embed'] != '1')
  2374. {
  2375. var fromTmpBtn = mxUtils.button(mxResources.get('fromTemplateUrl'), function()
  2376. {
  2377. var dlg = new FilenameDialog(editorUi, '', mxResources.get('create'), function(fileUrl)
  2378. {
  2379. if (fileUrl != null && fileUrl.length > 0)
  2380. {
  2381. var url = editorUi.getUrl(window.location.pathname + '?mode=' + editorUi.mode +
  2382. '&title=' + encodeURIComponent(nameInput.value) +
  2383. '&create=' + encodeURIComponent(fileUrl));
  2384. if (editorUi.getCurrentFile() == null)
  2385. {
  2386. window.location.href = url;
  2387. }
  2388. else
  2389. {
  2390. window.openWindow(url);
  2391. }
  2392. }
  2393. }, mxResources.get('url'));
  2394. editorUi.showDialog(dlg.container, 300, 80, true, true);
  2395. dlg.init();
  2396. });
  2397. fromTmpBtn.className = 'geBtn';
  2398. btns.appendChild(fromTmpBtn);
  2399. }
  2400. btns.appendChild(createButton);
  2401. if (!editorUi.editor.cancelFirst && callback == null)
  2402. {
  2403. btns.appendChild(cancelBtn);
  2404. }
  2405. outer.appendChild(btns);
  2406. this.container = outer;
  2407. };
  2408. /**
  2409. * Constructs a dialog for creating new files from a template URL.
  2410. */
  2411. var CreateDialog = function(editorUi, title, createFn, cancelFn, dlgTitle, btnLabel, overrideExtension,
  2412. allowBrowser, allowTab, helpLink, showDeviceButton, rowLimit)
  2413. {
  2414. overrideExtension = (overrideExtension != null) ? overrideExtension : true;
  2415. allowBrowser = (allowBrowser != null) ? allowBrowser : true;
  2416. rowLimit = (rowLimit != null) ? rowLimit : 3;
  2417. var div = document.createElement('div');
  2418. var showButtons = true;
  2419. if (cancelFn == null)
  2420. {
  2421. editorUi.addLanguageMenu(div);
  2422. }
  2423. var h3 = document.createElement('h2');
  2424. mxUtils.write(h3, dlgTitle || mxResources.get('create'));
  2425. h3.style.marginTop = '0px';
  2426. h3.style.marginBottom = '24px';
  2427. div.appendChild(h3);
  2428. mxUtils.write(div, mxResources.get('filename') + ':');
  2429. var nameInput = document.createElement('input');
  2430. nameInput.setAttribute('value', title);
  2431. nameInput.style.width = '280px';
  2432. nameInput.style.marginLeft = '10px';
  2433. nameInput.style.marginBottom = '20px';
  2434. this.init = function()
  2435. {
  2436. nameInput.focus();
  2437. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  2438. {
  2439. nameInput.select();
  2440. }
  2441. else
  2442. {
  2443. document.execCommand('selectAll', false, null);
  2444. }
  2445. };
  2446. div.appendChild(nameInput);
  2447. mxUtils.br(div);
  2448. var buttons = document.createElement('div');
  2449. buttons.style.textAlign = 'center';
  2450. var count = 0;
  2451. function addLogo(img, title, mode, clientName)
  2452. {
  2453. var button = document.createElement('a');
  2454. button.style.overflow = 'hidden';
  2455. var logo = document.createElement('img');
  2456. logo.src = img;
  2457. logo.setAttribute('border', '0');
  2458. logo.setAttribute('align', 'absmiddle');
  2459. logo.style.width = '60px';
  2460. logo.style.height = '60px';
  2461. logo.style.paddingBottom = '6px';
  2462. button.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  2463. button.className = 'geBaseButton';
  2464. button.style.position = 'relative';
  2465. button.style.margin = '4px';
  2466. button.style.padding = '8px 8px 10px 8px';
  2467. button.style.whiteSpace = 'nowrap';
  2468. button.appendChild(logo);
  2469. // Workaround for quirks is a vertical list (limited to max 2 items)
  2470. if (mxClient.IS_QUIRKS)
  2471. {
  2472. button.style.cssFloat = 'left';
  2473. button.style.zoom = '1';
  2474. }
  2475. button.style.color = 'gray';
  2476. button.style.fontSize = '11px';
  2477. var label = document.createElement('div');
  2478. button.appendChild(label);
  2479. mxUtils.write(label, title);
  2480. function initButton()
  2481. {
  2482. mxEvent.addListener(button, 'click', function()
  2483. {
  2484. // Updates extension
  2485. change(mode);
  2486. create(mode);
  2487. });
  2488. };
  2489. // Supports lazy loading
  2490. if (clientName != null && editorUi[clientName] == null)
  2491. {
  2492. logo.style.visibility = 'hidden';
  2493. mxUtils.setOpacity(label, 10);
  2494. var size = 12;
  2495. var spinner = new Spinner({
  2496. lines: 12, // The number of lines to draw
  2497. length: size, // The length of each line
  2498. width: 5, // The line thickness
  2499. radius: 10, // The radius of the inner circle
  2500. rotate: 0, // The rotation offset
  2501. color: '#000', // #rgb or #rrggbb
  2502. speed: 1.5, // Rounds per second
  2503. trail: 60, // Afterglow percentage
  2504. shadow: false, // Whether to render a shadow
  2505. hwaccel: false, // Whether to use hardware acceleration
  2506. top: '40%',
  2507. zIndex: 2e9 // The z-index (defaults to 2000000000)
  2508. });
  2509. spinner.spin(button);
  2510. // Timeout after 30 secs
  2511. var timeout = window.setTimeout(function()
  2512. {
  2513. if (editorUi[clientName] == null)
  2514. {
  2515. spinner.stop();
  2516. button.style.display = 'none';
  2517. }
  2518. }, 30000);
  2519. editorUi.addListener('clientLoaded', mxUtils.bind(this, function()
  2520. {
  2521. if (editorUi[clientName] != null)
  2522. {
  2523. window.clearTimeout(timeout);
  2524. mxUtils.setOpacity(label, 100);
  2525. logo.style.visibility = '';
  2526. spinner.stop();
  2527. initButton();
  2528. }
  2529. }));
  2530. }
  2531. else
  2532. {
  2533. initButton();
  2534. }
  2535. buttons.appendChild(button);
  2536. if (++count == rowLimit)
  2537. {
  2538. mxUtils.br(buttons);
  2539. count = 0;
  2540. }
  2541. };
  2542. if (!showButtons)
  2543. {
  2544. mxUtils.write(div, mxResources.get('chooseAnOption') + ':');
  2545. }
  2546. else
  2547. {
  2548. buttons.style.marginTop = '6px';
  2549. div.appendChild(buttons);
  2550. }
  2551. // Adds all papersize options
  2552. var serviceSelect = document.createElement('select');
  2553. serviceSelect.style.marginLeft = '10px';
  2554. if (!editorUi.isOfflineApp() && !editorUi.isOffline())
  2555. {
  2556. if (typeof window.DriveClient === 'function')
  2557. {
  2558. var googleOption = document.createElement('option');
  2559. googleOption.setAttribute('value', App.MODE_GOOGLE);
  2560. mxUtils.write(googleOption, mxResources.get('googleDrive'));
  2561. serviceSelect.appendChild(googleOption);
  2562. addLogo(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googleDrive'), App.MODE_GOOGLE, 'drive');
  2563. }
  2564. if (editorUi.gitHub != null)
  2565. {
  2566. var gitHubOption = document.createElement('option');
  2567. gitHubOption.setAttribute('value', App.MODE_GITHUB);
  2568. mxUtils.write(gitHubOption, mxResources.get('github'));
  2569. serviceSelect.appendChild(gitHubOption);
  2570. addLogo(IMAGE_PATH + '/github-logo.svg', mxResources.get('github'), App.MODE_GITHUB, 'gitHub');
  2571. }
  2572. if (typeof window.DropboxClient === 'function')
  2573. {
  2574. var dropboxOption = document.createElement('option');
  2575. dropboxOption.setAttribute('value', App.MODE_DROPBOX);
  2576. mxUtils.write(dropboxOption, mxResources.get('dropbox'));
  2577. serviceSelect.appendChild(dropboxOption);
  2578. if (editorUi.mode == App.MODE_DROPBOX)
  2579. {
  2580. dropboxOption.setAttribute('selected', 'selected');
  2581. }
  2582. addLogo(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), App.MODE_DROPBOX, 'dropbox');
  2583. }
  2584. if (typeof window.OneDriveClient === 'function')
  2585. {
  2586. var oneDriveOption = document.createElement('option');
  2587. oneDriveOption.setAttribute('value', App.MODE_ONEDRIVE);
  2588. mxUtils.write(oneDriveOption, mxResources.get('oneDrive'));
  2589. serviceSelect.appendChild(oneDriveOption);
  2590. if (editorUi.mode == App.MODE_ONEDRIVE)
  2591. {
  2592. oneDriveOption.setAttribute('selected', 'selected');
  2593. }
  2594. addLogo(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), App.MODE_ONEDRIVE, 'oneDrive');
  2595. }
  2596. }
  2597. if (!Editor.useLocalStorage || urlParams['storage'] == 'device' ||
  2598. (editorUi.getCurrentFile() != null && !mxClient.IS_IOS))
  2599. {
  2600. var deviceOption = document.createElement('option');
  2601. deviceOption.setAttribute('value', App.MODE_DEVICE);
  2602. mxUtils.write(deviceOption, mxResources.get('device'));
  2603. serviceSelect.appendChild(deviceOption);
  2604. if (editorUi.mode == App.MODE_DEVICE || !allowBrowser)
  2605. {
  2606. deviceOption.setAttribute('selected', 'selected');
  2607. }
  2608. if (showDeviceButton)
  2609. {
  2610. addLogo(IMAGE_PATH + '/osa_drive-harddisk.png', mxResources.get('device'), App.MODE_DEVICE);
  2611. }
  2612. }
  2613. if (allowBrowser && isLocalStorage && urlParams['browser'] != '0')
  2614. {
  2615. var browserOption = document.createElement('option');
  2616. browserOption.setAttribute('value', App.MODE_BROWSER);
  2617. mxUtils.write(browserOption, mxResources.get('browser'));
  2618. serviceSelect.appendChild(browserOption);
  2619. if (editorUi.mode == App.MODE_BROWSER)
  2620. {
  2621. browserOption.setAttribute('selected', 'selected');
  2622. }
  2623. addLogo(IMAGE_PATH + '/osa_database.png', mxResources.get('browser'), App.MODE_BROWSER);
  2624. }
  2625. function change(newMode)
  2626. {
  2627. if (overrideExtension)
  2628. {
  2629. var fn = nameInput.value;
  2630. var idx = fn.lastIndexOf('.');
  2631. if (title.lastIndexOf('.') < 0 && (!showButtons || idx < 0))
  2632. {
  2633. newMode = (newMode != null) ? newMode : serviceSelect.value;
  2634. var ext = '';
  2635. if (newMode == App.MODE_GOOGLE)
  2636. {
  2637. ext = editorUi.drive.extension;
  2638. }
  2639. else if (newMode == App.MODE_GITHUB)
  2640. {
  2641. ext = editorUi.gitHub.extension;
  2642. }
  2643. else if (newMode == App.MODE_DROPBOX)
  2644. {
  2645. ext = editorUi.dropbox.extension;
  2646. }
  2647. else if (newMode == App.MODE_ONEDRIVE)
  2648. {
  2649. ext = editorUi.oneDrive.extension;
  2650. }
  2651. else if (newMode == App.MODE_DEVICE)
  2652. {
  2653. ext = '.xml';
  2654. }
  2655. if (idx >= 0)
  2656. {
  2657. fn = fn.substring(0, idx);
  2658. }
  2659. nameInput.value = fn + ext;
  2660. }
  2661. }
  2662. };
  2663. var btns = document.createElement('div');
  2664. btns.style.marginTop = (showButtons) ? '26px' : '38px';
  2665. btns.style.textAlign = (showButtons) ? 'center' : 'right';
  2666. if (!showButtons)
  2667. {
  2668. div.appendChild(serviceSelect);
  2669. mxEvent.addListener(serviceSelect, 'change', change);
  2670. change();
  2671. }
  2672. if (helpLink != null)
  2673. {
  2674. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  2675. {
  2676. window.open(helpLink);
  2677. });
  2678. helpBtn.className = 'geBtn';
  2679. btns.appendChild(helpBtn);
  2680. }
  2681. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  2682. {
  2683. if (cancelFn != null)
  2684. {
  2685. cancelFn();
  2686. }
  2687. else
  2688. {
  2689. editorUi.fileLoaded(null);
  2690. editorUi.hideDialog();
  2691. window.close();
  2692. window.location.href = editorUi.getUrl();
  2693. }
  2694. });
  2695. cancelBtn.className = 'geBtn';
  2696. if (editorUi.editor.cancelFirst)
  2697. {
  2698. btns.appendChild(cancelBtn);
  2699. }
  2700. function create(mode)
  2701. {
  2702. var title = nameInput.value;
  2703. if (mode == null || (title != null && title.length > 0))
  2704. {
  2705. editorUi.hideDialog();
  2706. createFn(title, mode);
  2707. };
  2708. }
  2709. if (cancelFn == null)
  2710. {
  2711. var laterBtn = mxUtils.button(mxResources.get('decideLater'), function()
  2712. {
  2713. create(null);
  2714. });
  2715. laterBtn.className = 'geBtn';
  2716. btns.appendChild(laterBtn);
  2717. }
  2718. if (allowTab)
  2719. {
  2720. var openBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
  2721. {
  2722. create('_blank');
  2723. });
  2724. openBtn.className = 'geBtn';
  2725. btns.appendChild(openBtn);
  2726. }
  2727. if (!mxClient.IS_IOS || !showButtons)
  2728. {
  2729. var createBtn = mxUtils.button(btnLabel || mxResources.get('create'), function()
  2730. {
  2731. create((showDeviceButton) ? 'download' : ((showButtons) ? App.MODE_DEVICE : serviceSelect.value));
  2732. });
  2733. createBtn.className = 'geBtn gePrimaryBtn';
  2734. btns.appendChild(createBtn);
  2735. }
  2736. if (!editorUi.editor.cancelFirst)
  2737. {
  2738. btns.appendChild(cancelBtn);
  2739. }
  2740. mxEvent.addListener(nameInput, 'keypress', function(e)
  2741. {
  2742. if (e.keyCode == 13)
  2743. {
  2744. create((showButtons) ? App.MODE_DEVICE : serviceSelect.value);
  2745. }
  2746. else if (e.keyCode == 27)
  2747. {
  2748. editorUi.fileLoaded(null);
  2749. editorUi.hideDialog();
  2750. window.close();
  2751. }
  2752. });
  2753. div.appendChild(btns);
  2754. this.container = div;
  2755. };
  2756. /**
  2757. * Constructs a new popup dialog.
  2758. */
  2759. var PopupDialog = function(editorUi, url, pre, fallback, hideDialog)
  2760. {
  2761. hideDialog = (hideDialog != null) ? hideDialog : true;
  2762. var div = document.createElement('div');
  2763. div.style.textAlign = 'left';
  2764. mxUtils.write(div, mxResources.get('fileOpenLocation'));
  2765. mxUtils.br(div);
  2766. mxUtils.br(div);
  2767. var replaceBtn = mxUtils.button(mxResources.get('openInThisWindow'), function()
  2768. {
  2769. if (hideDialog)
  2770. {
  2771. editorUi.hideDialog();
  2772. }
  2773. if (fallback != null)
  2774. {
  2775. fallback();
  2776. }
  2777. });
  2778. replaceBtn.className = 'geBtn';
  2779. replaceBtn.style.marginBottom = '8px';
  2780. replaceBtn.style.width = '280px';
  2781. div.appendChild(replaceBtn);
  2782. mxUtils.br(div);
  2783. var wndBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
  2784. {
  2785. if (hideDialog)
  2786. {
  2787. editorUi.hideDialog();
  2788. }
  2789. if (pre != null)
  2790. {
  2791. pre();
  2792. }
  2793. window.open(url);
  2794. });
  2795. wndBtn.className = 'geBtn gePrimaryBtn';
  2796. wndBtn.style.width = replaceBtn.style.width;
  2797. div.appendChild(wndBtn);
  2798. mxUtils.br(div);
  2799. mxUtils.br(div);
  2800. mxUtils.write(div, mxResources.get('allowPopups'));
  2801. this.container = div;
  2802. };
  2803. /**
  2804. * Constructs a new image dialog.
  2805. */
  2806. var ImageDialog = function(editorUi, title, initialValue, fn, ignoreExisting, convertDataUri)
  2807. {
  2808. convertDataUri = (convertDataUri != null) ? convertDataUri : true;
  2809. var graph = editorUi.editor.graph;
  2810. var div = document.createElement('div');
  2811. mxUtils.write(div, title);
  2812. var inner = document.createElement('div');
  2813. inner.className = 'geTitle';
  2814. inner.style.backgroundColor = 'transparent';
  2815. inner.style.borderColor = 'transparent';
  2816. inner.style.whiteSpace = 'nowrap';
  2817. inner.style.textOverflow = 'clip';
  2818. inner.style.cursor = 'default';
  2819. if (!mxClient.IS_VML)
  2820. {
  2821. inner.style.paddingRight = '20px';
  2822. }
  2823. var linkInput = document.createElement('input');
  2824. linkInput.setAttribute('value', initialValue);
  2825. linkInput.setAttribute('type', 'text');
  2826. linkInput.setAttribute('spellcheck', 'false');
  2827. linkInput.setAttribute('autocorrect', 'off');
  2828. linkInput.setAttribute('autocomplete', 'off');
  2829. linkInput.setAttribute('autocapitalize', 'off');
  2830. linkInput.style.marginTop = '6px';
  2831. var realWidth = (Graph.fileSupport) ? 420 : 340;
  2832. linkInput.style.width = realWidth + ((mxClient.IS_QUIRKS) ? 20 : -20) + 'px';
  2833. linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
  2834. linkInput.style.backgroundRepeat = 'no-repeat';
  2835. linkInput.style.backgroundPosition = '100% 50%';
  2836. linkInput.style.paddingRight = '14px';
  2837. var cross = document.createElement('div');
  2838. cross.setAttribute('title', mxResources.get('reset'));
  2839. cross.style.position = 'relative';
  2840. cross.style.left = '-16px';
  2841. cross.style.width = '12px';
  2842. cross.style.height = '14px';
  2843. cross.style.cursor = 'pointer';
  2844. // Workaround for inline-block not supported in IE
  2845. cross.style.display = (mxClient.IS_VML) ? 'inline' : 'inline-block';
  2846. cross.style.top = ((mxClient.IS_VML) ? 0 : 3) + 'px';
  2847. // Needed to block event transparency in IE
  2848. cross.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
  2849. mxEvent.addListener(cross, 'click', function()
  2850. {
  2851. linkInput.value = '';
  2852. linkInput.focus();
  2853. });
  2854. inner.appendChild(linkInput);
  2855. inner.appendChild(cross);
  2856. div.appendChild(inner);
  2857. var insertImage = function(newValue, w, h)
  2858. {
  2859. var dataUri = newValue.substring(0, 5) == 'data:';
  2860. if ((!editorUi.isOffline() || (dataUri && typeof chrome === 'undefined')) &&
  2861. editorUi.spinner.spin(document.body, mxResources.get('inserting')))
  2862. {
  2863. var maxSize = 520;
  2864. editorUi.loadImage(newValue, function(img)
  2865. {
  2866. editorUi.spinner.stop();
  2867. editorUi.hideDialog();
  2868. var s = (w != null && h != null) ? Math.max(w / img.width, h / img.height) :
  2869. Math.min(1, Math.min(maxSize / img.width, maxSize / img.height));
  2870. // Handles special case of data URI which needs to be rewritten
  2871. // to be used in a cell style to remove the semicolon
  2872. if (convertDataUri)
  2873. {
  2874. newValue = editorUi.convertDataUri(newValue);
  2875. }
  2876. fn(newValue, Math.round(Number(img.width) * s), Math.round(Number(img.height) * s));
  2877. }, function()
  2878. {
  2879. editorUi.spinner.stop();
  2880. fn(null);
  2881. editorUi.showError(mxResources.get('error'), mxResources.get('fileNotFound'), mxResources.get('ok'));
  2882. });
  2883. }
  2884. else
  2885. {
  2886. newValue = editorUi.convertDataUri(newValue);
  2887. w = (w == null) ? 120 : w;
  2888. h = (h == null) ? 100 : h;
  2889. editorUi.hideDialog();
  2890. fn(newValue, w, h);
  2891. }
  2892. };
  2893. var apply = function(newValue)
  2894. {
  2895. if (newValue != null && newValue.length > 0)
  2896. {
  2897. var geo = (ignoreExisting) ? null : graph.getModel().getGeometry(graph.getSelectionCell());
  2898. // Reuses width and height of existing cell
  2899. if (geo != null)
  2900. {
  2901. insertImage(newValue, geo.width, geo.height);
  2902. }
  2903. else
  2904. {
  2905. insertImage(newValue);
  2906. }
  2907. }
  2908. else
  2909. {
  2910. editorUi.hideDialog();
  2911. fn(null);
  2912. }
  2913. };
  2914. this.init = function()
  2915. {
  2916. linkInput.focus();
  2917. // Installs drag and drop handler for local images and links
  2918. if (Graph.fileSupport)
  2919. {
  2920. linkInput.setAttribute('placeholder', mxResources.get('dragImagesHere'));
  2921. // Setup the dnd listeners
  2922. var dlg = div.parentNode;
  2923. var graph = editorUi.editor.graph;
  2924. var dropElt = null;
  2925. mxEvent.addListener(dlg, 'dragleave', function(evt)
  2926. {
  2927. if (dropElt != null)
  2928. {
  2929. dropElt.parentNode.removeChild(dropElt);
  2930. dropElt = null;
  2931. }
  2932. evt.stopPropagation();
  2933. evt.preventDefault();
  2934. });
  2935. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  2936. {
  2937. // IE 10 does not implement pointer-events so it can't have a drop highlight
  2938. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  2939. {
  2940. dropElt = editorUi.highlightElement(dlg);
  2941. }
  2942. evt.stopPropagation();
  2943. evt.preventDefault();
  2944. }));
  2945. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  2946. {
  2947. if (dropElt != null)
  2948. {
  2949. dropElt.parentNode.removeChild(dropElt);
  2950. dropElt = null;
  2951. }
  2952. if (evt.dataTransfer.files.length > 0)
  2953. {
  2954. editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h)
  2955. {
  2956. apply(data);
  2957. }, function()
  2958. {
  2959. // No post processing
  2960. }, function(file)
  2961. {
  2962. // Handles only images
  2963. return file.type.substring(0, 6) == 'image/';
  2964. }, function(queue)
  2965. {
  2966. // Invokes elements of queue in order
  2967. for (var i = 0; i < queue.length; i++)
  2968. {
  2969. queue[i]();
  2970. }
  2971. }, !mxEvent.isControlDown(evt));
  2972. }
  2973. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  2974. {
  2975. var uri = evt.dataTransfer.getData('text/uri-list');
  2976. if ((/\.(gif|jpg|jpeg|tiff|png|svg)($|\?)/i).test(uri))
  2977. {
  2978. apply(decodeURIComponent(uri));
  2979. }
  2980. }
  2981. evt.stopPropagation();
  2982. evt.preventDefault();
  2983. }), false);
  2984. }
  2985. };
  2986. var btns = document.createElement('div');
  2987. btns.style.marginTop = (mxClient.IS_QUIRKS) ? '22px' : '14px';
  2988. btns.style.textAlign = 'right';
  2989. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  2990. {
  2991. // Just in case a spinner is spinning, has no effect otherwise
  2992. editorUi.spinner.stop();
  2993. editorUi.hideDialog();
  2994. });
  2995. cancelBtn.className = 'geBtn';
  2996. if (editorUi.editor.cancelFirst)
  2997. {
  2998. btns.appendChild(cancelBtn);
  2999. }
  3000. ImageDialog.filePicked = function(data)
  3001. {
  3002. if (data.action == google.picker.Action.PICKED)
  3003. {
  3004. if (data.docs[0].thumbnails != null)
  3005. {
  3006. var thumb = data.docs[0].thumbnails[data.docs[0].thumbnails.length - 1];
  3007. if (thumb != null)
  3008. {
  3009. linkInput.value = thumb.url;
  3010. }
  3011. }
  3012. }
  3013. linkInput.focus();
  3014. };
  3015. if (Graph.fileSupport)
  3016. {
  3017. var fileInput = document.createElement('input');
  3018. fileInput.setAttribute('multiple', 'multiple');
  3019. fileInput.setAttribute('type', 'file');
  3020. if (document.documentMode == null)
  3021. {
  3022. mxEvent.addListener(fileInput, 'change', function(evt)
  3023. {
  3024. editorUi.importFiles(fileInput.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h)
  3025. {
  3026. apply(data);
  3027. }, function()
  3028. {
  3029. // No post processing
  3030. }, function(file)
  3031. {
  3032. // Handles only images
  3033. return file.type.substring(0, 6) == 'image/';
  3034. }, function(queue)
  3035. {
  3036. // Invokes elements of queue in order
  3037. for (var i = 0; i < queue.length; i++)
  3038. {
  3039. queue[i]();
  3040. }
  3041. }, true);
  3042. });
  3043. var btn = mxUtils.button(mxResources.get('open'), function()
  3044. {
  3045. fileInput.click();
  3046. });
  3047. btn.className = 'geBtn';
  3048. btns.appendChild(btn);
  3049. }
  3050. }
  3051. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined' && window.self === window.top)
  3052. {
  3053. var searchBtn = mxUtils.button(mxResources.get('search'), function()
  3054. {
  3055. // Creates one picker and reuses it to avoid polluting the DOM
  3056. if (editorUi.imageSearchPicker == null)
  3057. {
  3058. var picker = new google.picker.PickerBuilder()
  3059. .setLocale(mxLanguage)
  3060. .addView(google.picker.ViewId.IMAGE_SEARCH)
  3061. .enableFeature(google.picker.Feature.NAV_HIDDEN);
  3062. editorUi.imageSearchPicker = picker.setCallback(function(data)
  3063. {
  3064. ImageDialog.filePicked(data);
  3065. }).build();
  3066. }
  3067. editorUi.imageSearchPicker.setVisible(true);
  3068. editorUi.movePickersToTop();
  3069. });
  3070. searchBtn.className = 'geBtn';
  3071. btns.appendChild(searchBtn);
  3072. if (editorUi.drive != null && urlParams['photos'] == '1')
  3073. {
  3074. var gpBtn = mxUtils.button(mxResources.get('googlePlus'), function()
  3075. {
  3076. if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  3077. {
  3078. editorUi.drive.checkToken(mxUtils.bind(this, function()
  3079. {
  3080. editorUi.spinner.stop();
  3081. // Creates one picker and reuses it to avoid polluting the DOM
  3082. if (editorUi.photoPicker == null)
  3083. {
  3084. var token = gapi.auth.getToken().access_token;
  3085. var picker = new google.picker.PickerBuilder()
  3086. .setAppId(editorUi.drive.appId)
  3087. .setLocale(mxLanguage)
  3088. .setOAuthToken(token)
  3089. .addView(google.picker.ViewId.PHOTOS)
  3090. .addView(google.picker.ViewId.PHOTO_ALBUMS)
  3091. .addView(google.picker.ViewId.PHOTO_UPLOAD);
  3092. editorUi.photoPicker = picker.setCallback(function(data)
  3093. {
  3094. ImageDialog.filePicked(data);
  3095. }).build();
  3096. }
  3097. editorUi.photoPicker.setVisible(true);
  3098. editorUi.movePickersToTop();
  3099. }));
  3100. }
  3101. });
  3102. gpBtn.className = 'geBtn';
  3103. btns.appendChild(gpBtn);
  3104. }
  3105. }
  3106. mxEvent.addListener(linkInput, 'keypress', function(e)
  3107. {
  3108. if (e.keyCode == 13)
  3109. {
  3110. apply(linkInput.value);
  3111. }
  3112. });
  3113. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  3114. {
  3115. apply(linkInput.value);
  3116. });
  3117. applyBtn.className = 'geBtn gePrimaryBtn';
  3118. btns.appendChild(applyBtn);
  3119. if (!editorUi.editor.cancelFirst)
  3120. {
  3121. btns.appendChild(cancelBtn);
  3122. }
  3123. // Shows drop icon in dialog background
  3124. if (Graph.fileSupport)
  3125. {
  3126. btns.style.marginTop = '120px';
  3127. div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
  3128. div.style.backgroundPosition = 'center 65%';
  3129. div.style.backgroundRepeat = 'no-repeat';
  3130. var bg = document.createElement('div');
  3131. bg.style.position = 'absolute';
  3132. bg.style.width = '420px';
  3133. bg.style.top = '58%';
  3134. bg.style.textAlign = 'center';
  3135. bg.style.fontSize = '18px';
  3136. bg.style.color = '#a0c3ff';
  3137. mxUtils.write(bg, mxResources.get('dragImagesHere'));
  3138. div.appendChild(bg);
  3139. }
  3140. div.appendChild(btns);
  3141. this.container = div;
  3142. };
  3143. /**
  3144. * Overrides link dialog to add Google Picker.
  3145. */
  3146. var LinkDialog = function(editorUi, initialValue, btnLabel, fn, showPages)
  3147. {
  3148. var div = document.createElement('div');
  3149. mxUtils.write(div, mxResources.get('editLink') + ':');
  3150. var inner = document.createElement('div');
  3151. inner.className = 'geTitle';
  3152. inner.style.backgroundColor = 'transparent';
  3153. inner.style.borderColor = 'transparent';
  3154. inner.style.whiteSpace = 'nowrap';
  3155. inner.style.textOverflow = 'clip';
  3156. inner.style.cursor = 'default';
  3157. if (!mxClient.IS_VML)
  3158. {
  3159. inner.style.paddingRight = '20px';
  3160. }
  3161. var linkInput = document.createElement('input');
  3162. linkInput.setAttribute('placeholder', mxResources.get('dragUrlsHere'));
  3163. linkInput.setAttribute('type', 'text');
  3164. linkInput.style.marginTop = '6px';
  3165. linkInput.style.width = '400px';
  3166. linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
  3167. linkInput.style.backgroundRepeat = 'no-repeat';
  3168. linkInput.style.backgroundPosition = '100% 50%';
  3169. linkInput.style.paddingRight = '14px';
  3170. var cross = document.createElement('div');
  3171. cross.setAttribute('title', mxResources.get('reset'));
  3172. cross.style.position = 'relative';
  3173. cross.style.left = '-16px';
  3174. cross.style.width = '12px';
  3175. cross.style.height = '14px';
  3176. cross.style.cursor = 'pointer';
  3177. // Workaround for inline-block not supported in IE
  3178. cross.style.display = (mxClient.IS_VML) ? 'inline' : 'inline-block';
  3179. cross.style.top = ((mxClient.IS_VML) ? 0 : 3) + 'px';
  3180. // Needed to block event transparency in IE
  3181. cross.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
  3182. mxEvent.addListener(cross, 'click', function()
  3183. {
  3184. linkInput.value = '';
  3185. linkInput.focus();
  3186. });
  3187. var urlRadio = document.createElement('input');
  3188. urlRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  3189. urlRadio.setAttribute('value', 'url');
  3190. urlRadio.setAttribute('type', 'radio');
  3191. urlRadio.setAttribute('name', 'current-linkdialog');
  3192. var pageRadio = document.createElement('input');
  3193. pageRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  3194. pageRadio.setAttribute('value', 'url');
  3195. pageRadio.setAttribute('type', 'radio');
  3196. pageRadio.setAttribute('name', 'current-linkdialog');
  3197. var pageSelect = document.createElement('select');
  3198. pageSelect.style.width = '380px';
  3199. if (showPages && editorUi.pages != null)
  3200. {
  3201. if (initialValue != null && editorUi.editor.graph.isPageLink(initialValue))
  3202. {
  3203. pageRadio.setAttribute('checked', 'checked');
  3204. pageRadio.defaultChecked = true;
  3205. }
  3206. else
  3207. {
  3208. linkInput.setAttribute('value', initialValue);
  3209. urlRadio.setAttribute('checked', 'checked');
  3210. urlRadio.defaultChecked = true;
  3211. }
  3212. linkInput.style.width = '380px';
  3213. inner.appendChild(urlRadio);
  3214. inner.appendChild(linkInput);
  3215. inner.appendChild(cross);
  3216. mxUtils.br(inner);
  3217. inner.appendChild(pageRadio);
  3218. var pageFound = false;
  3219. for (var i = 0; i < editorUi.pages.length; i++)
  3220. {
  3221. var pageOption = document.createElement('option');
  3222. mxUtils.write(pageOption, editorUi.pages[i].getName() ||
  3223. mxResources.get('pageWithNumber', [i + 1]));
  3224. pageOption.setAttribute('value', 'data:page/id,' +
  3225. editorUi.pages[i].getId());
  3226. if (initialValue == pageOption.getAttribute('value'))
  3227. {
  3228. pageOption.setAttribute('selected', 'selected');
  3229. pageFound = true;
  3230. }
  3231. pageSelect.appendChild(pageOption);
  3232. }
  3233. if (!pageFound && pageRadio.checked)
  3234. {
  3235. var notFoundOption = document.createElement('option');
  3236. mxUtils.write(notFoundOption, mxResources.get('pageNotFound'));
  3237. notFoundOption.setAttribute('disabled', 'disabled');
  3238. notFoundOption.setAttribute('selected', 'selected');
  3239. notFoundOption.setAttribute('value', 'pageNotFound');
  3240. pageSelect.appendChild(notFoundOption);
  3241. mxEvent.addListener(pageSelect, 'change', function()
  3242. {
  3243. if (notFoundOption.parentNode != null && !notFoundOption.selected)
  3244. {
  3245. notFoundOption.parentNode.removeChild(notFoundOption);
  3246. }
  3247. });
  3248. }
  3249. inner.appendChild(pageSelect);
  3250. }
  3251. else
  3252. {
  3253. linkInput.setAttribute('value', initialValue);
  3254. inner.appendChild(linkInput);
  3255. inner.appendChild(cross);
  3256. }
  3257. div.appendChild(inner);
  3258. var mainBtn = mxUtils.button(btnLabel, function()
  3259. {
  3260. editorUi.hideDialog();
  3261. var value = (pageRadio.checked) ? ((pageSelect.value !== 'pageNotFound') ?
  3262. pageSelect.value : initialValue) : linkInput.value;
  3263. fn(value, LinkDialog.selectedDocs);
  3264. });
  3265. mainBtn.style.verticalAlign = 'middle';
  3266. mainBtn.className = 'geBtn gePrimaryBtn';
  3267. this.init = function()
  3268. {
  3269. if (pageRadio.checked)
  3270. {
  3271. pageSelect.focus();
  3272. }
  3273. else
  3274. {
  3275. linkInput.focus();
  3276. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  3277. {
  3278. linkInput.select();
  3279. }
  3280. else
  3281. {
  3282. document.execCommand('selectAll', false, null);
  3283. }
  3284. }
  3285. mxEvent.addListener(pageSelect, 'focus', function()
  3286. {
  3287. urlRadio.removeAttribute('checked');
  3288. pageRadio.setAttribute('checked', 'checked');
  3289. pageRadio.checked = true;
  3290. });
  3291. mxEvent.addListener(linkInput, 'focus', function()
  3292. {
  3293. pageRadio.removeAttribute('checked');
  3294. urlRadio.setAttribute('checked', 'checked');
  3295. urlRadio.checked = true;
  3296. });
  3297. // Installs drag and drop handler for links
  3298. if (Graph.fileSupport)
  3299. {
  3300. // Setup the dnd listeners
  3301. var dlg = div.parentNode;
  3302. var graph = editorUi.editor.graph;
  3303. var dropElt = null;
  3304. mxEvent.addListener(dlg, 'dragleave', function(evt)
  3305. {
  3306. if (dropElt != null)
  3307. {
  3308. dropElt.parentNode.removeChild(dropElt);
  3309. dropElt = null;
  3310. }
  3311. evt.stopPropagation();
  3312. evt.preventDefault();
  3313. });
  3314. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  3315. {
  3316. // IE 10 does not implement pointer-events so it can't have a drop highlight
  3317. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  3318. {
  3319. dropElt = editorUi.highlightElement(dlg);
  3320. }
  3321. evt.stopPropagation();
  3322. evt.preventDefault();
  3323. }));
  3324. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  3325. {
  3326. if (dropElt != null)
  3327. {
  3328. dropElt.parentNode.removeChild(dropElt);
  3329. dropElt = null;
  3330. }
  3331. if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  3332. {
  3333. linkInput.value = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
  3334. urlRadio.setAttribute('checked', 'checked');
  3335. urlRadio.checked = true;
  3336. mainBtn.click();
  3337. }
  3338. evt.stopPropagation();
  3339. evt.preventDefault();
  3340. }), false);
  3341. }
  3342. };
  3343. var btns = document.createElement('div');
  3344. btns.style.marginTop = '20px';
  3345. btns.style.textAlign = 'right';
  3346. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  3347. {
  3348. editorUi.hideDialog();
  3349. });
  3350. cancelBtn.style.verticalAlign = 'middle';
  3351. cancelBtn.className = 'geBtn';
  3352. if (editorUi.editor.cancelFirst)
  3353. {
  3354. btns.appendChild(cancelBtn);
  3355. }
  3356. LinkDialog.selectedDocs = null;
  3357. LinkDialog.filePicked = function(data)
  3358. {
  3359. if (data.action == google.picker.Action.PICKED)
  3360. {
  3361. LinkDialog.selectedDocs = data.docs;
  3362. var href = data.docs[0].url;
  3363. if (data.docs[0].mimeType == 'application/mxe' || data.docs[0].mimeType == 'application/vnd.jgraph.mxfile')
  3364. {
  3365. var domain = DriveClient.prototype.oldAppHostname;
  3366. href = 'https://' + domain + '/#G' + data.docs[0].id;
  3367. }
  3368. else if (data.docs[0].mimeType == 'application/mxr' || data.docs[0].mimeType == 'application/vnd.jgraph.mxfile.realtime')
  3369. {
  3370. var domain = DriveClient.prototype.newAppHostname;
  3371. href = 'https://' + domain + '/#G' + data.docs[0].id;
  3372. }
  3373. else if (data.docs[0].mimeType == 'application/vnd.google-apps.folder')
  3374. {
  3375. // Do not use folderview in data.docs[0].url link to Google Drive instead
  3376. href = 'https://drive.google.com/#folders/' + data.docs[0].id;
  3377. }
  3378. linkInput.value = href;
  3379. linkInput.focus();
  3380. }
  3381. else
  3382. {
  3383. LinkDialog.selectedDocs = null;
  3384. }
  3385. linkInput.focus();
  3386. };
  3387. function addButton(src, tooltip, fn)
  3388. {
  3389. var btn = mxUtils.button('', fn);
  3390. btn.className = 'geBtn';
  3391. btn.setAttribute('title', tooltip);
  3392. var img = document.createElement('img');
  3393. img.style.height = '26px';
  3394. img.style.width = '26px';
  3395. img.setAttribute('src', src);
  3396. btn.style.minWidth = '42px';
  3397. btn.style.verticalAlign = 'middle';
  3398. btn.appendChild(img);
  3399. btns.appendChild(btn);
  3400. };
  3401. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined' && editorUi.drive != null)
  3402. {
  3403. addButton(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googlePlus'), function()
  3404. {
  3405. if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  3406. {
  3407. editorUi.drive.checkToken(mxUtils.bind(this, function()
  3408. {
  3409. editorUi.spinner.stop();
  3410. // Creates one picker and reuses it to avoid polluting the DOM
  3411. if (editorUi.linkPicker == null)
  3412. {
  3413. var token = gapi.auth.getToken().access_token;
  3414. var view = new google.picker.DocsView(google.picker.ViewId.FOLDERS)
  3415. .setParent('root')
  3416. .setIncludeFolders(true)
  3417. .setSelectFolderEnabled(true);
  3418. var view2 = new google.picker.DocsView()
  3419. .setIncludeFolders(true)
  3420. .setSelectFolderEnabled(true);
  3421. var picker = new google.picker.PickerBuilder()
  3422. .setAppId(editorUi.drive.appId)
  3423. .setLocale(mxLanguage)
  3424. .setOAuthToken(token)
  3425. .addView(view)
  3426. .addView(view2)
  3427. .addView(google.picker.ViewId.RECENTLY_PICKED)
  3428. .addView(google.picker.ViewId.IMAGE_SEARCH)
  3429. .addView(google.picker.ViewId.VIDEO_SEARCH)
  3430. .addView(google.picker.ViewId.MAPS);
  3431. if (urlParams['photos'] == '1')
  3432. {
  3433. picker.addView(google.picker.ViewId.PHOTOS)
  3434. .addView(google.picker.ViewId.PHOTO_ALBUMS)
  3435. .addView(google.picker.ViewId.PHOTO_UPLOAD)
  3436. }
  3437. editorUi.linkPicker = picker.setCallback(function(data)
  3438. {
  3439. LinkDialog.filePicked(data);
  3440. }).build();
  3441. }
  3442. editorUi.linkPicker.setVisible(true);
  3443. editorUi.movePickersToTop();
  3444. }));
  3445. }
  3446. });
  3447. }
  3448. if (typeof(Dropbox) != 'undefined' && typeof(Dropbox.choose) != 'undefined')
  3449. {
  3450. addButton(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), function()
  3451. {
  3452. // Authentication will be carried out on open to make sure the
  3453. // autosave does not show an auth dialog. Showing it here will
  3454. // block the second dialog (the file picker) so it's too early.
  3455. Dropbox.choose(
  3456. {
  3457. linkType : 'direct',
  3458. cancel: function()
  3459. {
  3460. // do nothing
  3461. },
  3462. success : function(files)
  3463. {
  3464. linkInput.value = files[0].link;
  3465. linkInput.focus();
  3466. }
  3467. });
  3468. });
  3469. }
  3470. if (editorUi.oneDrive != null)
  3471. {
  3472. addButton(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), function()
  3473. {
  3474. editorUi.oneDrive.pickFile(function(files)
  3475. {
  3476. linkInput.value = files.value[0].webUrl;
  3477. linkInput.focus();
  3478. }, true);
  3479. });
  3480. }
  3481. if (editorUi.gitHub != null)
  3482. {
  3483. addButton(IMAGE_PATH + '/github-logo.svg', mxResources.get('github'), function()
  3484. {
  3485. editorUi.gitHub.pickFile(function(path)
  3486. {
  3487. if (path != null)
  3488. {
  3489. var tokens = path.split('/');
  3490. var org = tokens[0];
  3491. var repo = tokens[1];
  3492. var ref = tokens[2];
  3493. var path = tokens.slice(3, tokens.length).join('/');
  3494. linkInput.value = 'https://github.com/' + org + '/' +
  3495. repo + '/blob/' + ref + '/' + path;
  3496. linkInput.focus();
  3497. }
  3498. });
  3499. });
  3500. }
  3501. mxEvent.addListener(linkInput, 'keypress', function(e)
  3502. {
  3503. if (e.keyCode == 13)
  3504. {
  3505. editorUi.hideDialog();
  3506. var value = (pageRadio.checked) ? pageSelect.value : linkInput.value;
  3507. fn(value, LinkDialog.selectedDocs);
  3508. }
  3509. });
  3510. btns.appendChild(mainBtn);
  3511. if (!editorUi.editor.cancelFirst)
  3512. {
  3513. btns.appendChild(cancelBtn);
  3514. }
  3515. div.appendChild(btns);
  3516. this.container = div;
  3517. };
  3518. /**
  3519. * Constructs a new about dialog
  3520. */
  3521. var AboutDialog = function(editorUi)
  3522. {
  3523. var div = document.createElement('div');
  3524. div.style.marginTop = '6px';
  3525. div.setAttribute('align', 'center');
  3526. var img = document.createElement('img');
  3527. img.style.border = '0px';
  3528. img.setAttribute('width', '176');
  3529. img.setAttribute('width', '151');
  3530. img.style.width = '170px';
  3531. img.style.height = '219px';
  3532. img.setAttribute('src', IMAGE_PATH + '/logo-flat.png');
  3533. div.appendChild(img);
  3534. mxUtils.br(div);
  3535. var v = document.createElement('small');
  3536. v.innerHTML = 'v ' + EditorUi.VERSION;
  3537. v.style.color = '#505050';
  3538. div.appendChild(v);
  3539. mxUtils.br(div);
  3540. mxUtils.br(div);
  3541. var small = document.createElement('small');
  3542. small.style.color = '#505050';
  3543. small.innerHTML = '&copy; 2005-2017 <a href="https://www.jgraph.com/" style="color:inherit;" target="_blank">JGraph Ltd</a>.<br>All Rights Reserved.';
  3544. div.appendChild(small);
  3545. mxEvent.addListener(div, 'click', function(e)
  3546. {
  3547. if (mxEvent.getSource(e).nodeName != 'A')
  3548. {
  3549. editorUi.hideDialog();
  3550. }
  3551. });
  3552. this.container = div;
  3553. };
  3554. /**
  3555. * Constructs a new about dialog
  3556. */
  3557. var FeedbackDialog = function(editorUi)
  3558. {
  3559. var div = document.createElement('div');
  3560. var label = document.createElement('div');
  3561. mxUtils.write(label, mxResources.get('sendYourFeedbackToDrawIo'));
  3562. label.style.fontSize = '18px';
  3563. label.style.marginBottom = '18px';
  3564. div.appendChild(label);
  3565. label = document.createElement('div');
  3566. mxUtils.write(label, mxResources.get('yourEmailAddress') + ' (' + mxResources.get('required') + ')');
  3567. div.appendChild(label);
  3568. var email = document.createElement('input');
  3569. email.setAttribute('type', 'text');
  3570. email.style.marginTop = '6px';
  3571. email.style.width = '600px';
  3572. var sendButton = mxUtils.button(mxResources.get('sendMessage'), function()
  3573. {
  3574. var diagram = ((cb.checked) ? '\nDiagram:\n' + editorUi.getFileData() : '') +
  3575. '\nBrowser:\n' + navigator.userAgent;
  3576. if (diagram.length > FeedbackDialog.maxAttachmentSize)
  3577. {
  3578. editorUi.alert(mxResources.get('drawingTooLarge'));
  3579. }
  3580. else
  3581. {
  3582. editorUi.hideDialog();
  3583. if (editorUi.spinner.spin(document.body))
  3584. {
  3585. var postUrl = (FeedbackDialog.feedbackUrl != null) ? FeedbackDialog.feedbackUrl : '/email';
  3586. mxUtils.post(postUrl, 'email=' + encodeURIComponent(email.value) +
  3587. '&version=' + encodeURIComponent(EditorUi.VERSION) +
  3588. '&url=' + encodeURIComponent(window.location.href) +
  3589. '&body=' + encodeURIComponent('Feedback:\n' + textarea.value + diagram),
  3590. function(req)
  3591. {
  3592. editorUi.spinner.stop();
  3593. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  3594. {
  3595. editorUi.alert(mxResources.get('feedbackSent'));
  3596. }
  3597. else
  3598. {
  3599. editorUi.alert(mxResources.get('errorSendingFeedback'));
  3600. }
  3601. },
  3602. function()
  3603. {
  3604. editorUi.spinner.stop();
  3605. editorUi.alert(mxResources.get('errorSendingFeedback'));
  3606. });
  3607. }
  3608. }
  3609. });
  3610. sendButton.className = 'geBtn gePrimaryBtn';
  3611. sendButton.setAttribute('disabled', 'disabled');
  3612. var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  3613. mxEvent.addListener(email, 'change', function()
  3614. {
  3615. if (email.value.length > 0 && re.test(email.value) > 0)
  3616. {
  3617. sendButton.removeAttribute('disabled');
  3618. }
  3619. else
  3620. {
  3621. sendButton.setAttribute('disabled', 'disabled');
  3622. }
  3623. });
  3624. mxEvent.addListener(email, 'keyup', function()
  3625. {
  3626. if (email.value.length > 0 && re.test(email.value))
  3627. {
  3628. sendButton.removeAttribute('disabled');
  3629. }
  3630. else
  3631. {
  3632. sendButton.setAttribute('disabled', 'disabled');
  3633. }
  3634. });
  3635. div.appendChild(email);
  3636. this.init = function()
  3637. {
  3638. email.focus();
  3639. };
  3640. var cb = document.createElement('input');
  3641. cb.setAttribute('type', 'checkbox');
  3642. cb.setAttribute('checked', 'checked');
  3643. cb.defaultChecked = true;
  3644. var p2 = document.createElement('p');
  3645. p2.style.marginTop = '14px';
  3646. p2.appendChild(cb);
  3647. var span = document.createElement('span');
  3648. mxUtils.write(span, ' ' + mxResources.get('includeCopyOfMyDiagram'));
  3649. p2.appendChild(span);
  3650. mxEvent.addListener(span, 'click', function(evt)
  3651. {
  3652. cb.checked = !cb.checked;
  3653. mxEvent.consume(evt);
  3654. });
  3655. div.appendChild(p2);
  3656. label = document.createElement('div');
  3657. mxUtils.write(label, mxResources.get('feedback'));
  3658. div.appendChild(label);
  3659. var textarea = document.createElement('textarea');
  3660. textarea.style.resize = 'none';
  3661. textarea.style.width = '600px';
  3662. textarea.style.height = '140px';
  3663. textarea.style.marginTop = '6px';
  3664. textarea.setAttribute('placeholder', mxResources.get('commentsNotes'));
  3665. div.appendChild(textarea);
  3666. var buttons = document.createElement('div');
  3667. buttons.style.marginTop = '26px';
  3668. buttons.style.textAlign = 'right';
  3669. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  3670. {
  3671. editorUi.hideDialog();
  3672. });
  3673. cancelBtn.className = 'geBtn';
  3674. if (editorUi.editor.cancelFirst)
  3675. {
  3676. buttons.appendChild(cancelBtn);
  3677. buttons.appendChild(sendButton);
  3678. }
  3679. else
  3680. {
  3681. buttons.appendChild(sendButton);
  3682. buttons.appendChild(cancelBtn);
  3683. }
  3684. div.appendChild(buttons);
  3685. this.container = div;
  3686. };
  3687. /**
  3688. * Maximum size of attachments in bytes. Default is 1000000.
  3689. */
  3690. FeedbackDialog.maxAttachmentSize = 1000000;
  3691. /**
  3692. * Constructs a new revision dialog
  3693. */
  3694. var RevisionDialog = function(editorUi, revs)
  3695. {
  3696. var div = document.createElement('div');
  3697. var title = document.createElement('h3');
  3698. title.style.marginTop = '0px';
  3699. mxUtils.write(title, mxResources.get('revisionHistory'));
  3700. div.appendChild(title);
  3701. var list = document.createElement('div');
  3702. list.style.position = 'absolute';
  3703. list.style.overflow = 'auto';
  3704. list.style.width = '170px';
  3705. list.style.height = '378px';
  3706. div.appendChild(list);
  3707. var container = document.createElement('div');
  3708. container.style.position = 'absolute';
  3709. container.style.border = '1px solid lightGray';
  3710. container.style.left = '199px';
  3711. container.style.width = '470px';
  3712. container.style.height = '376px';
  3713. container.style.overflow = 'hidden';
  3714. mxEvent.disableContextMenu(container);
  3715. div.appendChild(container);
  3716. var graph = new Graph(container);
  3717. graph.setEnabled(false);
  3718. graph.setPanning(true);
  3719. graph.panningHandler.ignoreCell = true;
  3720. graph.panningHandler.useLeftButtonForPanning = true;
  3721. graph.minFitScale = null;
  3722. graph.maxFitScale = null;
  3723. graph.centerZoom = true;
  3724. // Handles placeholders for pages
  3725. var currentPage = 0;
  3726. var diagrams = null;
  3727. var realPage = 0;
  3728. var graphGetGlobalVariable = graph.getGlobalVariable;
  3729. graph.getGlobalVariable = function(name)
  3730. {
  3731. if (name == 'page' && diagrams != null && diagrams[realPage] != null)
  3732. {
  3733. return diagrams[realPage].getAttribute('name');
  3734. }
  3735. else if (name == 'pagenumber')
  3736. {
  3737. return realPage + 1;
  3738. }
  3739. return graphGetGlobalVariable.apply(this, arguments);
  3740. };
  3741. // Disables hyperlinks
  3742. graph.getLinkForCell = function()
  3743. {
  3744. return null;
  3745. };
  3746. if (Editor.MathJaxRender)
  3747. {
  3748. graph.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
  3749. {
  3750. // LATER: Math support is used if current graph has math enabled
  3751. // should use switch from history instead but requires setting the
  3752. // global mxClient.NO_FO switch
  3753. if (editorUi.editor.graph.mathEnabled)
  3754. {
  3755. Editor.MathJaxRender(graph.container);
  3756. }
  3757. }));
  3758. }
  3759. var opts = {
  3760. lines: 11, // The number of lines to draw
  3761. length: 15, // The length of each line
  3762. width: 6, // The line thickness
  3763. radius: 10, // The radius of the inner circle
  3764. corners: 1, // Corner roundness (0..1)
  3765. rotate: 0, // The rotation offset
  3766. direction: 1, // 1: clockwise, -1: counterclockwise
  3767. color: '#000', // #rgb or #rrggbb or array of colors
  3768. speed: 1.4, // Rounds per second
  3769. trail: 60, // Afterglow percentage
  3770. shadow: false, // Whether to render a shadow
  3771. hwaccel: false, // Whether to use hardware acceleration
  3772. className: 'spinner', // The CSS class to assign to the spinner
  3773. zIndex: 2e9, // The z-index (defaults to 2000000000)
  3774. top: '50%', // Top position relative to parent
  3775. left: '50%' // Left position relative to parent
  3776. };
  3777. var spinner = new Spinner(opts);
  3778. var file = editorUi.getCurrentFile();
  3779. var currentRow = null;
  3780. var currentRev = null;
  3781. var currentDoc = null;
  3782. var currentXml = null;
  3783. var zoomInBtn = mxUtils.button('', function()
  3784. {
  3785. if (currentDoc != null)
  3786. {
  3787. graph.zoomIn();
  3788. }
  3789. });
  3790. zoomInBtn.className = 'geSprite geSprite-zoomin';
  3791. zoomInBtn.setAttribute('title', mxResources.get('zoomIn'));
  3792. zoomInBtn.style.outline = 'none';
  3793. zoomInBtn.style.border = 'none';
  3794. zoomInBtn.style.margin = '2px';
  3795. zoomInBtn.setAttribute('disabled', 'disabled');
  3796. mxUtils.setOpacity(zoomInBtn, 20);
  3797. var zoomOutBtn = mxUtils.button('', function()
  3798. {
  3799. if (currentDoc != null)
  3800. {
  3801. graph.zoomOut();
  3802. }
  3803. });
  3804. zoomOutBtn.className = 'geSprite geSprite-zoomout';
  3805. zoomOutBtn.setAttribute('title', mxResources.get('zoomOut'));
  3806. zoomOutBtn.style.outline = 'none';
  3807. zoomOutBtn.style.border = 'none';
  3808. zoomOutBtn.style.margin = '2px';
  3809. zoomOutBtn.setAttribute('disabled', 'disabled');
  3810. mxUtils.setOpacity(zoomOutBtn, 20);
  3811. var zoomFitBtn = mxUtils.button('', function()
  3812. {
  3813. if (currentDoc != null)
  3814. {
  3815. graph.maxFitScale = 8;
  3816. graph.fit(8);
  3817. graph.center();
  3818. }
  3819. });
  3820. zoomFitBtn.className = 'geSprite geSprite-fit';
  3821. zoomFitBtn.setAttribute('title', mxResources.get('fit'));
  3822. zoomFitBtn.style.outline = 'none';
  3823. zoomFitBtn.style.border = 'none';
  3824. zoomFitBtn.style.margin = '2px';
  3825. zoomFitBtn.setAttribute('disabled', 'disabled');
  3826. mxUtils.setOpacity(zoomFitBtn, 20);
  3827. var zoomActualBtn = mxUtils.button('', function()
  3828. {
  3829. if (currentDoc != null)
  3830. {
  3831. graph.zoomActual();
  3832. graph.center();
  3833. }
  3834. });
  3835. zoomActualBtn.className = 'geSprite geSprite-actualsize';
  3836. zoomActualBtn.setAttribute('title', mxResources.get('actualSize'));
  3837. zoomActualBtn.style.outline = 'none';
  3838. zoomActualBtn.style.border = 'none';
  3839. zoomActualBtn.style.margin = '2px';
  3840. zoomActualBtn.setAttribute('disabled', 'disabled');
  3841. mxUtils.setOpacity(zoomActualBtn, 20);
  3842. var fileInfo = document.createElement('div');
  3843. fileInfo.style.position = 'absolute';
  3844. fileInfo.style.textAlign = 'right';
  3845. fileInfo.style.color = 'gray';
  3846. fileInfo.style.marginTop = '10px';
  3847. fileInfo.style.backgroundColor = 'transparent';
  3848. fileInfo.style.top = '440px';
  3849. fileInfo.style.right = '32px';
  3850. fileInfo.style.maxWidth = '380px';
  3851. fileInfo.style.cursor = 'default';
  3852. var downloadBtn = mxUtils.button(mxResources.get('download'), function()
  3853. {
  3854. if (currentDoc != null)
  3855. {
  3856. var file = editorUi.getCurrentFile();
  3857. var filename = (file != null && file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
  3858. var data = mxUtils.getXml(currentDoc.documentElement);
  3859. if (editorUi.isLocalFileSave())
  3860. {
  3861. editorUi.saveLocalFile(data, filename, 'text/xml');
  3862. }
  3863. else
  3864. {
  3865. var param = (typeof(pako) === 'undefined') ? '&xml=' + encodeURIComponent(data) :
  3866. '&data=' + encodeURIComponent(editorUi.editor.graph.compress(data));
  3867. new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(filename) +
  3868. '&format=xml' + param).simulate(document, '_blank');
  3869. }
  3870. }
  3871. });
  3872. downloadBtn.className = 'geBtn';
  3873. downloadBtn.setAttribute('disabled', 'disabled');
  3874. var restoreBtn = mxUtils.button(mxResources.get('restore'), function()
  3875. {
  3876. if (currentDoc != null && currentXml != null)
  3877. {
  3878. editorUi.confirm(mxResources.get('areYouSure'), function()
  3879. {
  3880. if (editorUi.spinner.spin(document.body, mxResources.get('restoring')))
  3881. {
  3882. file.save(true, function(resp)
  3883. {
  3884. editorUi.spinner.stop();
  3885. editorUi.replaceFileData(currentXml);
  3886. editorUi.hideDialog();
  3887. }, function(resp)
  3888. {
  3889. editorUi.spinner.stop();
  3890. editorUi.editor.setStatus('');
  3891. editorUi.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
  3892. });
  3893. }
  3894. });
  3895. }
  3896. });
  3897. restoreBtn.className = 'geBtn';
  3898. restoreBtn.setAttribute('disabled', 'disabled');
  3899. var pageSelect = document.createElement('select');
  3900. pageSelect.setAttribute('disabled', 'disabled');
  3901. pageSelect.style.maxWidth = '80px';
  3902. pageSelect.style.position = 'relative';
  3903. pageSelect.style.top = '-2px';
  3904. pageSelect.style.verticalAlign = 'bottom';
  3905. pageSelect.style.marginRight = '6px';
  3906. pageSelect.style.display = 'none';
  3907. var pageSelectFunction = null;
  3908. mxEvent.addListener(pageSelect, 'change', function(evt)
  3909. {
  3910. if (pageSelectFunction != null)
  3911. {
  3912. pageSelectFunction(evt);
  3913. mxEvent.consume(evt);
  3914. }
  3915. });
  3916. var newBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
  3917. {
  3918. if (currentDoc != null)
  3919. {
  3920. window.openFile = new OpenFile(function()
  3921. {
  3922. window.openFile = null;
  3923. });
  3924. window.openFile.setData(mxUtils.getXml(currentDoc.documentElement));
  3925. window.openWindow(editorUi.getUrl());
  3926. }
  3927. });
  3928. newBtn.className = 'geBtn';
  3929. newBtn.setAttribute('disabled', 'disabled');
  3930. var showBtn = mxUtils.button(mxResources.get('show'), function()
  3931. {
  3932. if (currentRev != null)
  3933. {
  3934. window.open(currentRev.getUrl());
  3935. }
  3936. });
  3937. showBtn.className = 'geBtn gePrimaryBtn';
  3938. showBtn.setAttribute('disabled', 'disabled');
  3939. var buttons = document.createElement('div');
  3940. buttons.style.position = 'absolute';
  3941. buttons.style.top = '482px';
  3942. buttons.style.width = '640px';
  3943. buttons.style.textAlign = 'right';
  3944. var tb = document.createElement('div');
  3945. tb.className = 'geToolbarContainer';
  3946. tb.style.backgroundColor = 'transparent';
  3947. tb.style.padding = '2px';
  3948. tb.style.border = 'none';
  3949. tb.style.left = '199px';
  3950. tb.style.top = '442px';
  3951. var currentElt = null;
  3952. if (file == null || (editorUi.drive == null && file.constructor == window.DriveFile) ||
  3953. (editorUi.dropbox == null && file.constructor == window.DropboxFile))
  3954. {
  3955. container.style.display = 'none';
  3956. tb.style.display = 'none';
  3957. mxUtils.write(list, mxResources.get('notAvailable'));
  3958. }
  3959. else
  3960. {
  3961. if (revs != null && revs.length > 0)
  3962. {
  3963. container.style.cursor = 'move';
  3964. var table = document.createElement('table');
  3965. table.style.border = '1px solid lightGray';
  3966. table.style.borderCollapse = 'collapse';
  3967. table.style.borderSpacing = '0px';
  3968. table.style.width = '100%';
  3969. var tbody = document.createElement('tbody');
  3970. var today = new Date().toDateString();
  3971. if (editorUi.currentPage != null && editorUi.pages != null)
  3972. {
  3973. currentPage = mxUtils.indexOf(editorUi.pages, editorUi.currentPage);
  3974. }
  3975. for (var i = revs.length - 1; i >= 0; i--)
  3976. {
  3977. var elt = (function(item)
  3978. {
  3979. var ts = new Date(item.modifiedDate);
  3980. var row = null;
  3981. var pd = '6px';
  3982. // Workaround for negative timestamps in Dropbox
  3983. if (ts.getTime() >= 0)
  3984. {
  3985. row = document.createElement('tr');
  3986. row.style.borderBottom = '1px solid lightGray';
  3987. row.style.fontSize = '12px';
  3988. row.style.cursor = 'pointer';
  3989. var date = document.createElement('td');
  3990. date.style.padding = pd;
  3991. date.style.whiteSpace = 'nowrap';
  3992. if (item == revs[revs.length - 1])
  3993. {
  3994. mxUtils.write(date, mxResources.get('current'));
  3995. }
  3996. else
  3997. {
  3998. if (ts.toDateString() === today)
  3999. {
  4000. mxUtils.write(date, ts.toLocaleTimeString());
  4001. }
  4002. else
  4003. {
  4004. mxUtils.write(date, ts.toLocaleDateString() + ' ' +
  4005. ts.toLocaleTimeString());
  4006. }
  4007. }
  4008. row.appendChild(date);
  4009. row.setAttribute('title', ts.toLocaleDateString() + ' ' +
  4010. ts.toLocaleTimeString() + ' ' +
  4011. editorUi.formatFileSize(parseInt(item.fileSize)) +
  4012. ((item.lastModifyingUserName != null) ? ' ' +
  4013. item.lastModifyingUserName : ''));
  4014. function updateGraph(xml)
  4015. {
  4016. spinner.stop();
  4017. var doc = mxUtils.parseXml(xml);
  4018. var node = editorUi.editor.extractGraphModel(doc.documentElement, true);
  4019. if (node != null)
  4020. {
  4021. pageSelect.style.display = 'none';
  4022. pageSelect.innerHTML = '';
  4023. currentDoc = doc;
  4024. currentXml = xml;
  4025. parseSelectFunction = null;
  4026. diagrams = null;
  4027. realPage = 0;
  4028. function parseGraphModel(dataNode)
  4029. {
  4030. var bg = dataNode.getAttribute('background');
  4031. if (bg == null || bg == '' || bg == mxConstants.NONE)
  4032. {
  4033. bg = '#ffffff';
  4034. }
  4035. container.style.backgroundColor = bg;
  4036. var codec = new mxCodec(dataNode.ownerDocument);
  4037. codec.decode(dataNode, graph.getModel());
  4038. graph.maxFitScale = 1;
  4039. graph.fit(8);
  4040. graph.center();
  4041. return dataNode;
  4042. }
  4043. function parseDiagram(diagramNode)
  4044. {
  4045. if (diagramNode != null)
  4046. {
  4047. diagramNode = parseGraphModel(mxUtils.parseXml(editorUi.editor.graph.decompress(
  4048. mxUtils.getTextContent(diagramNode))).documentElement);
  4049. }
  4050. return diagramNode;
  4051. }
  4052. if (node.nodeName == 'mxfile')
  4053. {
  4054. // Workaround for "invalid calling object" error in IE
  4055. var tmp = node.getElementsByTagName('diagram');
  4056. diagrams = [];
  4057. for (var i = 0; i < tmp.length; i++)
  4058. {
  4059. diagrams.push(tmp[i]);
  4060. }
  4061. realPage = Math.min(currentPage, diagrams.length - 1);
  4062. if (diagrams.length > 0)
  4063. {
  4064. parseDiagram(diagrams[realPage]);
  4065. }
  4066. if (diagrams.length > 1)
  4067. {
  4068. pageSelect.removeAttribute('disabled');
  4069. pageSelect.style.display = '';
  4070. for (var i = 0; i < diagrams.length; i++)
  4071. {
  4072. var pageOption = document.createElement('option');
  4073. mxUtils.write(pageOption, diagrams[i].getAttribute('name') ||
  4074. mxResources.get('pageWithNumber', [i + 1]));
  4075. pageOption.setAttribute('value', i);
  4076. if (i == realPage)
  4077. {
  4078. pageOption.setAttribute('selected', 'selected');
  4079. }
  4080. pageSelect.appendChild(pageOption);
  4081. }
  4082. }
  4083. pageSelectFunction = function()
  4084. {
  4085. currentPage = parseInt(pageSelect.value);
  4086. realPage = currentPage;
  4087. parseDiagram(diagrams[currentPage]);
  4088. }
  4089. }
  4090. else
  4091. {
  4092. parseGraphModel(node);
  4093. }
  4094. fileInfo.innerHTML = '';
  4095. mxUtils.write(fileInfo, ts.toLocaleDateString() + ' ' +
  4096. ts.toLocaleTimeString());
  4097. fileInfo.setAttribute('title', row.getAttribute('title'));
  4098. zoomInBtn.removeAttribute('disabled');
  4099. zoomOutBtn.removeAttribute('disabled');
  4100. zoomFitBtn.removeAttribute('disabled');
  4101. zoomActualBtn.removeAttribute('disabled');
  4102. if (file == null || !file.isRestricted())
  4103. {
  4104. if (editorUi.editor.graph.isEnabled())
  4105. {
  4106. restoreBtn.removeAttribute('disabled');
  4107. }
  4108. downloadBtn.removeAttribute('disabled');
  4109. showBtn.removeAttribute('disabled');
  4110. newBtn.removeAttribute('disabled');
  4111. }
  4112. mxUtils.setOpacity(zoomInBtn, 60);
  4113. mxUtils.setOpacity(zoomOutBtn, 60);
  4114. mxUtils.setOpacity(zoomFitBtn, 60);
  4115. mxUtils.setOpacity(zoomActualBtn, 60);
  4116. }
  4117. else
  4118. {
  4119. pageSelect.style.display = 'none';
  4120. pageSelect.innerHTML = '';
  4121. fileInfo.innerHTML = '';
  4122. mxUtils.write(fileInfo, mxResources.get('errorLoadingFile'));
  4123. }
  4124. };
  4125. mxEvent.addListener(row, 'click', function(evt)
  4126. {
  4127. if (currentRev != item)
  4128. {
  4129. spinner.stop();
  4130. if (currentRow != null)
  4131. {
  4132. currentRow.style.backgroundColor = '';
  4133. }
  4134. currentRev = item;
  4135. currentRow = row;
  4136. currentRow.style.backgroundColor = '#ebf2f9';
  4137. currentDoc = null;
  4138. currentXml = null;
  4139. fileInfo.removeAttribute('title');
  4140. fileInfo.innerHTML = mxResources.get('loading') + '...';
  4141. container.style.backgroundColor = '#ffffff';
  4142. graph.getModel().clear();
  4143. restoreBtn.setAttribute('disabled', 'disabled');
  4144. downloadBtn.setAttribute('disabled', 'disabled');
  4145. zoomInBtn.setAttribute('disabled', 'disabled');
  4146. zoomOutBtn.setAttribute('disabled', 'disabled');
  4147. zoomActualBtn.setAttribute('disabled', 'disabled');
  4148. zoomFitBtn.setAttribute('disabled', 'disabled');
  4149. newBtn.setAttribute('disabled', 'disabled');
  4150. showBtn.setAttribute('disabled', 'disabled');
  4151. pageSelect.setAttribute('disabled', 'disabled');
  4152. mxUtils.setOpacity(zoomInBtn, 20);
  4153. mxUtils.setOpacity(zoomOutBtn, 20);
  4154. mxUtils.setOpacity(zoomFitBtn, 20);
  4155. mxUtils.setOpacity(zoomActualBtn, 20);
  4156. spinner.spin(container);
  4157. item.getXml(function(xml)
  4158. {
  4159. if (currentRev == item)
  4160. {
  4161. updateGraph(xml);
  4162. }
  4163. }, function(err)
  4164. {
  4165. spinner.stop();
  4166. pageSelect.style.display = 'none';
  4167. pageSelect.innerHTML = '';
  4168. fileInfo.innerHTML = '';
  4169. mxUtils.write(fileInfo, mxResources.get('errorLoadingFile'));
  4170. });
  4171. mxEvent.consume(evt);
  4172. }
  4173. });
  4174. mxEvent.addListener(row, 'dblclick', function(evt)
  4175. {
  4176. showBtn.click();
  4177. if (window.getSelection)
  4178. {
  4179. window.getSelection().removeAllRanges();
  4180. }
  4181. else if (document.selection)
  4182. {
  4183. document.selection.empty();
  4184. }
  4185. mxEvent.consume(evt);
  4186. }, false);
  4187. tbody.appendChild(row);
  4188. }
  4189. return row;
  4190. })(revs[i]);
  4191. // Selects and loads first element in list (ie current version) after
  4192. // graph container was initialized since there is no loading delay
  4193. if (elt != null && i == revs.length - 1)
  4194. {
  4195. currentElt = elt;
  4196. }
  4197. }
  4198. table.appendChild(tbody);
  4199. list.appendChild(table);
  4200. }
  4201. else
  4202. {
  4203. container.style.display = 'none';
  4204. tb.style.display = 'none';
  4205. mxUtils.write(list, mxResources.get('noRevisions'));
  4206. }
  4207. }
  4208. this.init = function()
  4209. {
  4210. if (currentElt != null)
  4211. {
  4212. currentElt.click();
  4213. }
  4214. };
  4215. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  4216. {
  4217. editorUi.hideDialog();
  4218. });
  4219. closeBtn.className = 'geBtn';
  4220. tb.appendChild(pageSelect);
  4221. tb.appendChild(zoomInBtn);
  4222. tb.appendChild(zoomOutBtn);
  4223. tb.appendChild(zoomActualBtn);
  4224. tb.appendChild(zoomFitBtn);
  4225. if (editorUi.editor.cancelFirst)
  4226. {
  4227. buttons.appendChild(closeBtn);
  4228. buttons.appendChild(downloadBtn);
  4229. buttons.appendChild(newBtn);
  4230. buttons.appendChild(restoreBtn);
  4231. buttons.appendChild(showBtn);
  4232. }
  4233. else
  4234. {
  4235. buttons.appendChild(downloadBtn);
  4236. buttons.appendChild(newBtn);
  4237. buttons.appendChild(restoreBtn);
  4238. buttons.appendChild(showBtn);
  4239. buttons.appendChild(closeBtn);
  4240. }
  4241. div.appendChild(buttons);
  4242. div.appendChild(tb);
  4243. div.appendChild(fileInfo);
  4244. this.container = div;
  4245. };
  4246. /**
  4247. * Constructs a new revision dialog
  4248. */
  4249. var DraftDialog = function(editorUi, title, xml, editFn, discardFn, editLabel, discardLabel)
  4250. {
  4251. var div = document.createElement('div');
  4252. var titleDiv = document.createElement('div');
  4253. titleDiv.style.marginTop = '0px';
  4254. mxUtils.write(titleDiv, title);
  4255. div.appendChild(titleDiv);
  4256. var container = document.createElement('div');
  4257. container.style.position = 'absolute';
  4258. container.style.border = '1px solid lightGray';
  4259. container.style.marginTop = '10px';
  4260. container.style.width = '640px';
  4261. container.style.height = '386px';
  4262. container.style.overflow = 'hidden';
  4263. mxEvent.disableContextMenu(container);
  4264. div.appendChild(container);
  4265. var graph = new Graph(container);
  4266. graph.setEnabled(false);
  4267. graph.setPanning(true);
  4268. graph.panningHandler.ignoreCell = true;
  4269. graph.panningHandler.useLeftButtonForPanning = true;
  4270. graph.minFitScale = null;
  4271. graph.maxFitScale = null;
  4272. graph.centerZoom = true;
  4273. // Handles placeholders for pages
  4274. var doc = mxUtils.parseXml(xml);
  4275. var node = editorUi.editor.extractGraphModel(doc.documentElement, true);
  4276. var currentPage = 0;
  4277. var diagrams = null;
  4278. var graphGetGlobalVariable = graph.getGlobalVariable;
  4279. graph.getGlobalVariable = function(name)
  4280. {
  4281. if (name == 'page' && diagrams != null && diagrams[currentPage] != null)
  4282. {
  4283. return diagrams[currentPage].getAttribute('name');
  4284. }
  4285. else if (name == 'pagenumber')
  4286. {
  4287. return currentPage + 1;
  4288. }
  4289. return graphGetGlobalVariable.apply(this, arguments);
  4290. };
  4291. // Disables hyperlinks
  4292. graph.getLinkForCell = function()
  4293. {
  4294. return null;
  4295. };
  4296. // TODO: Enable per-page math
  4297. // if (Editor.MathJaxRender)
  4298. // {
  4299. // graph.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
  4300. // {
  4301. // // LATER: Math support is used if current graph has math enabled
  4302. // // should use switch from history instead but requires setting the
  4303. // // global mxClient.NO_FO switch
  4304. // if (editorUi.editor.graph.mathEnabled)
  4305. // {
  4306. // Editor.MathJaxRender(graph.container);
  4307. // }
  4308. // }));
  4309. // }
  4310. var zoomInBtn = mxUtils.button('', function()
  4311. {
  4312. graph.zoomIn();
  4313. });
  4314. zoomInBtn.className = 'geSprite geSprite-zoomin';
  4315. zoomInBtn.setAttribute('title', mxResources.get('zoomIn'));
  4316. zoomInBtn.style.outline = 'none';
  4317. zoomInBtn.style.border = 'none';
  4318. zoomInBtn.style.margin = '2px';
  4319. mxUtils.setOpacity(zoomInBtn, 60);
  4320. var zoomOutBtn = mxUtils.button('', function()
  4321. {
  4322. graph.zoomOut();
  4323. });
  4324. zoomOutBtn.className = 'geSprite geSprite-zoomout';
  4325. zoomOutBtn.setAttribute('title', mxResources.get('zoomOut'));
  4326. zoomOutBtn.style.outline = 'none';
  4327. zoomOutBtn.style.border = 'none';
  4328. zoomOutBtn.style.margin = '2px';
  4329. mxUtils.setOpacity(zoomOutBtn, 60);
  4330. var zoomFitBtn = mxUtils.button('', function()
  4331. {
  4332. graph.maxFitScale = 8;
  4333. graph.fit(8);
  4334. graph.center();
  4335. });
  4336. zoomFitBtn.className = 'geSprite geSprite-fit';
  4337. zoomFitBtn.setAttribute('title', mxResources.get('fit'));
  4338. zoomFitBtn.style.outline = 'none';
  4339. zoomFitBtn.style.border = 'none';
  4340. zoomFitBtn.style.margin = '2px';
  4341. mxUtils.setOpacity(zoomFitBtn, 60);
  4342. var zoomActualBtn = mxUtils.button('', function()
  4343. {
  4344. graph.zoomActual();
  4345. graph.center();
  4346. });
  4347. zoomActualBtn.className = 'geSprite geSprite-actualsize';
  4348. zoomActualBtn.setAttribute('title', mxResources.get('actualSize'));
  4349. zoomActualBtn.style.outline = 'none';
  4350. zoomActualBtn.style.border = 'none';
  4351. zoomActualBtn.style.margin = '2px';
  4352. mxUtils.setOpacity(zoomActualBtn, 60);
  4353. var restoreBtn = mxUtils.button(discardLabel || mxResources.get('discard'), discardFn);
  4354. restoreBtn.className = 'geBtn';
  4355. var pageSelect = document.createElement('select');
  4356. pageSelect.style.maxWidth = '80px';
  4357. pageSelect.style.position = 'relative';
  4358. pageSelect.style.top = '-2px';
  4359. pageSelect.style.verticalAlign = 'bottom';
  4360. pageSelect.style.marginRight = '6px';
  4361. pageSelect.style.display = 'none';
  4362. var showBtn = mxUtils.button(editLabel || mxResources.get('edit'), editFn);
  4363. showBtn.className = 'geBtn gePrimaryBtn';
  4364. var buttons = document.createElement('div');
  4365. buttons.style.position = 'absolute';
  4366. buttons.style.top = '470px';
  4367. buttons.style.width = '640px';
  4368. buttons.style.textAlign = 'right';
  4369. var tb = document.createElement('div');
  4370. tb.className = 'geToolbarContainer';
  4371. tb.style.cssText = 'box-shadow:none !important;background-color:transparent;' +
  4372. 'padding:2px;border-style:none !important;top:470px;';
  4373. this.init = function()
  4374. {
  4375. function parseGraphModel(dataNode)
  4376. {
  4377. if (dataNode != null)
  4378. {
  4379. var bg = dataNode.getAttribute('background');
  4380. if (bg == null || bg == '' || bg == mxConstants.NONE)
  4381. {
  4382. bg = '#ffffff';
  4383. }
  4384. container.style.backgroundColor = bg;
  4385. var codec = new mxCodec(dataNode.ownerDocument);
  4386. codec.decode(dataNode, graph.getModel());
  4387. graph.maxFitScale = 1;
  4388. graph.fit(8);
  4389. graph.center();
  4390. }
  4391. };
  4392. function parseDiagram(diagramNode)
  4393. {
  4394. if (diagramNode != null)
  4395. {
  4396. diagramNode = parseGraphModel(mxUtils.parseXml(editorUi.editor.graph.decompress(
  4397. mxUtils.getTextContent(diagramNode))).documentElement);
  4398. }
  4399. return diagramNode;
  4400. };
  4401. mxEvent.addListener(pageSelect, 'change', function(evt)
  4402. {
  4403. currentPage = parseInt(pageSelect.value);
  4404. parseDiagram(diagrams[currentPage]);
  4405. mxEvent.consume(evt);
  4406. });
  4407. if (node.nodeName == 'mxfile')
  4408. {
  4409. // Workaround for "invalid calling object" error in IE
  4410. var tmp = node.getElementsByTagName('diagram');
  4411. diagrams = [];
  4412. for (var i = 0; i < tmp.length; i++)
  4413. {
  4414. diagrams.push(tmp[i]);
  4415. }
  4416. if (diagrams.length > 0)
  4417. {
  4418. parseDiagram(diagrams[currentPage]);
  4419. }
  4420. if (diagrams.length > 1)
  4421. {
  4422. pageSelect.style.display = '';
  4423. for (var i = 0; i < diagrams.length; i++)
  4424. {
  4425. var pageOption = document.createElement('option');
  4426. mxUtils.write(pageOption, diagrams[i].getAttribute('name') ||
  4427. mxResources.get('pageWithNumber', [i + 1]));
  4428. pageOption.setAttribute('value', i);
  4429. if (i == currentPage)
  4430. {
  4431. pageOption.setAttribute('selected', 'selected');
  4432. }
  4433. pageSelect.appendChild(pageOption);
  4434. }
  4435. }
  4436. }
  4437. else
  4438. {
  4439. parseGraphModel(node);
  4440. }
  4441. };
  4442. tb.appendChild(pageSelect);
  4443. tb.appendChild(zoomInBtn);
  4444. tb.appendChild(zoomOutBtn);
  4445. tb.appendChild(zoomActualBtn);
  4446. tb.appendChild(zoomFitBtn);
  4447. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  4448. {
  4449. editorUi.hideDialog(true);
  4450. });
  4451. cancelBtn.className = 'geBtn';
  4452. if (editorUi.editor.cancelFirst)
  4453. {
  4454. buttons.appendChild(cancelBtn);
  4455. buttons.appendChild(restoreBtn);
  4456. buttons.appendChild(showBtn);
  4457. }
  4458. else
  4459. {
  4460. buttons.appendChild(showBtn);
  4461. buttons.appendChild(restoreBtn);
  4462. buttons.appendChild(cancelBtn);
  4463. }
  4464. div.appendChild(buttons);
  4465. div.appendChild(tb);
  4466. this.container = div;
  4467. };
  4468. /**
  4469. *
  4470. */
  4471. var FindWindow = function(ui, x, y, w, h)
  4472. {
  4473. var action = ui.actions.get('find');
  4474. var graph = ui.editor.graph;
  4475. var lastSearch = null;
  4476. var lastFound = null;
  4477. var div = document.createElement('div');
  4478. div.style.userSelect = 'none';
  4479. div.style.overflow = 'hidden';
  4480. div.style.padding = '10px';
  4481. div.style.height = '100%';
  4482. var searchInput = document.createElement('input');
  4483. searchInput.setAttribute('placeholder', mxResources.get('find'));
  4484. searchInput.setAttribute('type', 'text');
  4485. searchInput.style.marginTop = '4px';
  4486. searchInput.style.marginBottom = '6px';
  4487. searchInput.style.width = '170px';
  4488. searchInput.style.fontSize = '12px';
  4489. searchInput.style.borderRadius = '4px';
  4490. searchInput.style.padding = '6px';
  4491. div.appendChild(searchInput);
  4492. var regexInput = document.createElement('input');
  4493. regexInput.setAttribute('type', 'checkbox');
  4494. div.appendChild(regexInput);
  4495. mxUtils.write(div, mxResources.get('regularExpression'));
  4496. var tmp = document.createElement('div');
  4497. function testMeta(re, cell)
  4498. {
  4499. if (typeof cell.value === 'object' && cell.value.attributes != null)
  4500. {
  4501. var attrs = cell.value.attributes;
  4502. for (var i = 0; i < attrs.length; i++)
  4503. {
  4504. if (attrs[i].nodeName != 'label' && re.test(attrs[i].nodeValue.toLowerCase()))
  4505. {
  4506. return true;
  4507. }
  4508. }
  4509. }
  4510. return false;
  4511. };
  4512. function search()
  4513. {
  4514. var cells = graph.model.getDescendants(graph.model.getRoot());
  4515. var search = searchInput.value.toLowerCase();
  4516. var re = (regexInput.checked) ? new RegExp(search) : null;
  4517. var firstMatch = null;
  4518. if (lastSearch != search)
  4519. {
  4520. lastSearch = search;
  4521. lastFound = null;
  4522. }
  4523. var active = lastFound == null;
  4524. if (graph.isEnabled() && search.length > 0)
  4525. {
  4526. for (var i = 0; i < cells.length; i++)
  4527. {
  4528. var state = graph.view.getState(cells[i]);
  4529. if (state != null && state.cell.value != null && (active || firstMatch == null) &&
  4530. (graph.model.isVertex(state.cell) || graph.model.isEdge(state.cell)))
  4531. {
  4532. if (graph.isHtmlLabel(state.cell))
  4533. {
  4534. tmp.innerHTML = graph.getLabel(state.cell);
  4535. label = mxUtils.extractTextWithWhitespace([tmp]);
  4536. }
  4537. else
  4538. {
  4539. label = graph.getLabel(state.cell);
  4540. }
  4541. label = mxUtils.trim(label.replace(/[\x00-\x1F\x7F-\x9F]|\s+/g, ' ')).toLowerCase();
  4542. if ((re == null && label.substring(0, search.length) === search) ||
  4543. (re != null && (re.test(label) || testMeta(re, state.cell))))
  4544. {
  4545. if (active)
  4546. {
  4547. firstMatch = state;
  4548. break;
  4549. }
  4550. else if (firstMatch == null)
  4551. {
  4552. firstMatch = state;
  4553. }
  4554. }
  4555. }
  4556. active = active || state == lastFound;
  4557. }
  4558. }
  4559. if (firstMatch != null)
  4560. {
  4561. lastFound = firstMatch;
  4562. graph.setSelectionCell(lastFound.cell);
  4563. graph.scrollCellToVisible(lastFound.cell);
  4564. }
  4565. else
  4566. {
  4567. graph.clearSelection();
  4568. }
  4569. return !graph.isEnabled() || search.length == 0 || firstMatch != null;
  4570. };
  4571. mxUtils.br(div);
  4572. var resetBtn = mxUtils.button(mxResources.get('reset'), function()
  4573. {
  4574. searchInput.value = '';
  4575. searchInput.style.backgroundColor = '';
  4576. lastFound = null;
  4577. lastSearch = null;
  4578. searchInput.focus();
  4579. });
  4580. resetBtn.setAttribute('title', mxResources.get('reset'));
  4581. resetBtn.style.marginTop = '6px';
  4582. resetBtn.style.marginRight = '4px';
  4583. resetBtn.style.backgroundColor = '#f5f5f5';
  4584. resetBtn.style.backgroundImage = 'none';
  4585. resetBtn.className = 'geBtn';
  4586. div.appendChild(resetBtn);
  4587. var btn = mxUtils.button(mxResources.get('find'), function()
  4588. {
  4589. try
  4590. {
  4591. searchInput.style.backgroundColor = search() ? '' : '#ffcfcf';
  4592. }
  4593. catch (e)
  4594. {
  4595. ui.handleError(e);
  4596. }
  4597. });
  4598. btn.setAttribute('title', mxResources.get('find') + ' (Enter)');
  4599. btn.style.marginTop = '6px';
  4600. btn.style.backgroundColor = '#4d90fe';
  4601. btn.style.backgroundImage = 'none';
  4602. btn.className = 'geBtn gePrimaryBtn';
  4603. div.appendChild(btn);
  4604. mxEvent.addListener(searchInput, 'keyup', function(evt)
  4605. {
  4606. // Ctrl or Cmd keys
  4607. if (evt.keyCode == 91 || evt.keyCode == 17)
  4608. {
  4609. // Workaround for lost focus on show
  4610. mxEvent.consume(evt);
  4611. }
  4612. else if (evt.keyCode == 27)
  4613. {
  4614. action.funct();
  4615. }
  4616. else if (lastSearch != searchInput.value.toLowerCase() || evt.keyCode == 13)
  4617. {
  4618. try
  4619. {
  4620. searchInput.style.backgroundColor = search() ? '' : '#ffcfcf';
  4621. }
  4622. catch (e)
  4623. {
  4624. searchInput.style.backgroundColor = '#ffcfcf';
  4625. }
  4626. }
  4627. });
  4628. mxEvent.addListener(div, 'keydown', function(evt)
  4629. {
  4630. if (evt.keyCode == 70 && ui.keyHandler.isControlDown(evt) && !mxEvent.isShiftDown(evt))
  4631. {
  4632. action.funct();
  4633. mxEvent.consume(evt);
  4634. }
  4635. });
  4636. this.window = new mxWindow(mxResources.get('find'), div, x, y, w, h, true, true);
  4637. this.window.destroyOnClose = false;
  4638. this.window.setMaximizable(false);
  4639. this.window.setResizable(false);
  4640. this.window.setClosable(true);
  4641. this.window.addListener('show', mxUtils.bind(this, function()
  4642. {
  4643. if (this.window.isVisible())
  4644. {
  4645. searchInput.focus();
  4646. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  4647. {
  4648. searchInput.select();
  4649. }
  4650. else
  4651. {
  4652. document.execCommand('selectAll', false, null);
  4653. }
  4654. }
  4655. else
  4656. {
  4657. graph.container.focus();
  4658. }
  4659. }));
  4660. };
  4661. /**
  4662. *
  4663. */
  4664. var TagsWindow = function(editorUi, x, y, w, h)
  4665. {
  4666. var graph = editorUi.editor.graph;
  4667. var propertyName = 'tags';
  4668. var div = document.createElement('div');
  4669. div.style.userSelect = 'none';
  4670. div.style.overflow = 'hidden';
  4671. div.style.padding = '10px';
  4672. div.style.height = '100%';
  4673. var searchInput = document.createElement('input');
  4674. searchInput.setAttribute('placeholder', mxResources.get('allTags'));
  4675. searchInput.setAttribute('type', 'text');
  4676. searchInput.style.marginTop = '4px';
  4677. searchInput.style.width = '240px';
  4678. searchInput.style.fontSize = '12px';
  4679. searchInput.style.borderRadius = '4px';
  4680. searchInput.style.padding = '6px';
  4681. div.appendChild(searchInput);
  4682. mxEvent.addListener(searchInput, 'dblclick', function()
  4683. {
  4684. var dlg = new FilenameDialog(editorUi, propertyName, mxResources.get('ok'), mxUtils.bind(this, function(name)
  4685. {
  4686. if (name != null && name.length > 0)
  4687. {
  4688. propertyName = name;
  4689. }
  4690. }), mxResources.get('enterPropertyName'));
  4691. editorUi.showDialog(dlg.container, 300, 80, true, true);
  4692. dlg.init();
  4693. });
  4694. searchInput.setAttribute('title', mxResources.get('doubleClickChangeProperty'));
  4695. function searchCells(cells)
  4696. {
  4697. cells = (cells != null) ? cells : graph.model.getDescendants(graph.model.getRoot());
  4698. var tagList = searchInput.value.split(' ');
  4699. var result = [];
  4700. for (var i = 0; i < cells.length; i++)
  4701. {
  4702. if (graph.model.isVertex(cells[i]) || graph.model.isEdge(cells[i]))
  4703. {
  4704. var tags = (cells[i].value != null && typeof(cells[i].value) == 'object') ?
  4705. mxUtils.trim(cells[i].value.getAttribute(propertyName) || '') : '';
  4706. var match = true;
  4707. if (tags.length > 0)
  4708. {
  4709. var tmp = tags.toLowerCase().split(' ');
  4710. for (var j = 0; j < tagList.length && match; j++)
  4711. {
  4712. var tag = mxUtils.trim(tagList[j]).toLowerCase();
  4713. match = match && (tag.length == 0 || mxUtils.indexOf(tmp, tag) >= 0);
  4714. }
  4715. }
  4716. else
  4717. {
  4718. match = mxUtils.trim(searchInput.value).length == 0;
  4719. }
  4720. if (match)
  4721. {
  4722. result.push(cells[i]);
  4723. }
  4724. }
  4725. }
  4726. return result;
  4727. };
  4728. function setCellsVisible(cells, visible)
  4729. {
  4730. graph.model.beginUpdate();
  4731. try
  4732. {
  4733. for (var i = 0; i < cells.length; i++)
  4734. {
  4735. graph.model.setVisible(cells[i], visible);
  4736. }
  4737. }
  4738. finally
  4739. {
  4740. graph.model.endUpdate();
  4741. }
  4742. };
  4743. mxUtils.br(div);
  4744. var hideBtn = mxUtils.button(mxResources.get('hide'), function()
  4745. {
  4746. setCellsVisible(searchCells(), false);
  4747. });
  4748. hideBtn.setAttribute('title', mxResources.get('hide'));
  4749. hideBtn.style.marginTop = '8px';
  4750. hideBtn.style.marginRight = '4px';
  4751. hideBtn.style.backgroundColor = '#f5f5f5';
  4752. hideBtn.style.backgroundImage = 'none';
  4753. hideBtn.className = 'geBtn';
  4754. div.appendChild(hideBtn);
  4755. var showBtn = mxUtils.button(mxResources.get('show'), function()
  4756. {
  4757. var cells = searchCells();
  4758. setCellsVisible(cells, true);
  4759. graph.setSelectionCells(cells);
  4760. });
  4761. showBtn.setAttribute('title', mxResources.get('show'));
  4762. showBtn.style.marginTop = '8px';
  4763. showBtn.style.marginRight = '4px';
  4764. showBtn.style.backgroundColor = '#f5f5f5';
  4765. showBtn.style.backgroundImage = 'none';
  4766. showBtn.className = 'geBtn';
  4767. div.appendChild(showBtn);
  4768. var action = editorUi.actions.get('tags');
  4769. var btn = mxUtils.button(mxResources.get('close'), function()
  4770. {
  4771. action.funct();
  4772. });
  4773. btn.setAttribute('title', mxResources.get('close') + ' (Enter/Esc)');
  4774. btn.style.marginTop = '8px';
  4775. btn.style.backgroundColor = '#4d90fe';
  4776. btn.style.backgroundImage = 'none';
  4777. btn.className = 'geBtn gePrimaryBtn';
  4778. div.appendChild(btn);
  4779. mxEvent.addListener(searchInput, 'keyup', function(evt)
  4780. {
  4781. // Ctrl or Cmd keys
  4782. if (evt.keyCode == 13 || evt.keyCode == 27)
  4783. {
  4784. action.funct();
  4785. }
  4786. });
  4787. this.window = new mxWindow(mxResources.get('tags'), div, x, y, w, h, true, true);
  4788. this.window.destroyOnClose = false;
  4789. this.window.setMaximizable(false);
  4790. this.window.setResizable(false);
  4791. this.window.setClosable(true);
  4792. this.window.addListener('show', mxUtils.bind(this, function()
  4793. {
  4794. if (this.window.isVisible())
  4795. {
  4796. searchInput.focus();
  4797. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  4798. {
  4799. searchInput.select();
  4800. }
  4801. else
  4802. {
  4803. document.execCommand('selectAll', false, null);
  4804. }
  4805. }
  4806. else
  4807. {
  4808. graph.container.focus();
  4809. }
  4810. }));
  4811. };
  4812. /**
  4813. * Constructs a new auth dialog.
  4814. */
  4815. var AuthDialog = function(editorUi, peer, showRememberOption, fn)
  4816. {
  4817. var div = document.createElement('div');
  4818. div.style.textAlign = 'center';
  4819. var hd = document.createElement('p');
  4820. hd.style.fontSize = '16pt';
  4821. hd.style.padding = '0px';
  4822. hd.style.margin = '0px';
  4823. hd.style.color = 'gray';
  4824. mxUtils.write(hd, mxResources.get('authorizationRequired'));
  4825. var service = 'Unknown';
  4826. var img = document.createElement('img');
  4827. img.setAttribute('border', '0');
  4828. img.setAttribute('align', 'absmiddle');
  4829. img.style.marginRight = '10px';
  4830. if (peer == editorUi.drive)
  4831. {
  4832. service = mxResources.get('googleDrive');
  4833. img.src = IMAGE_PATH + '/google-drive-logo-white.svg';
  4834. }
  4835. else if (peer == editorUi.dropbox)
  4836. {
  4837. service = mxResources.get('dropbox');
  4838. img.src = IMAGE_PATH + '/dropbox-logo-white.svg';
  4839. }
  4840. else if (peer == editorUi.oneDrive)
  4841. {
  4842. service = mxResources.get('oneDrive');
  4843. img.src = IMAGE_PATH + '/onedrive-logo-white.svg';
  4844. }
  4845. else if (peer == editorUi.gitHub)
  4846. {
  4847. service = mxResources.get('github');
  4848. img.src = IMAGE_PATH + '/github-logo-white.svg';
  4849. }
  4850. var p = document.createElement('p');
  4851. mxUtils.write(p, mxResources.get('authorizeThisAppIn', [service]));
  4852. var cb = document.createElement('input');
  4853. cb.setAttribute('type', 'checkbox');
  4854. var button = mxUtils.button(mxResources.get('authorize'), function()
  4855. {
  4856. fn(cb.checked);
  4857. });
  4858. button.insertBefore(img, button.firstChild);
  4859. button.style.marginTop = '6px';
  4860. button.className = 'geBigButton';
  4861. div.appendChild(hd);
  4862. div.appendChild(p);
  4863. div.appendChild(button);
  4864. if (showRememberOption)
  4865. {
  4866. var p2 = document.createElement('p');
  4867. p2.style.marginTop = '20px';
  4868. p2.appendChild(cb);
  4869. var span = document.createElement('span');
  4870. mxUtils.write(span, ' ' + mxResources.get('rememberMe'));
  4871. p2.appendChild(span);
  4872. div.appendChild(p2);
  4873. cb.checked = true;
  4874. cb.defaultChecked = true;
  4875. mxEvent.addListener(span, 'click', function(evt)
  4876. {
  4877. cb.checked = !cb.checked;
  4878. mxEvent.consume(evt);
  4879. });
  4880. }
  4881. this.container = div;
  4882. };
  4883. var MoreShapesDialog = function(editorUi, expanded, entries)
  4884. {
  4885. entries = (entries != null) ? entries : editorUi.sidebar.entries;
  4886. var div = document.createElement('div');
  4887. if (expanded)
  4888. {
  4889. var hd = document.createElement('div');
  4890. hd.className = 'geDialogTitle';
  4891. mxUtils.write(hd, mxResources.get('shapes'));
  4892. hd.style.position = 'absolute';
  4893. hd.style.top = '0px';
  4894. hd.style.left = '0px';
  4895. hd.style.lineHeight = '40px';
  4896. hd.style.height = '40px';
  4897. hd.style.right = '0px';
  4898. if (mxClient.IS_QUIRKS)
  4899. {
  4900. hd.style.width = '718px';
  4901. }
  4902. var list = document.createElement('div');
  4903. var preview = document.createElement('div');
  4904. list.style.position = 'absolute';
  4905. list.style.top = '40px';
  4906. list.style.left = '0px';
  4907. list.style.width = '202px';
  4908. list.style.bottom = '60px';
  4909. list.style.overflow = 'auto';
  4910. if (mxClient.IS_QUIRKS)
  4911. {
  4912. list.style.height = '437px';
  4913. list.style.marginTop = '1px';
  4914. }
  4915. preview.style.position = 'absolute';
  4916. preview.style.left = '202px';
  4917. preview.style.right = '0px';
  4918. preview.style.top = '40px';
  4919. preview.style.bottom = '60px';
  4920. preview.style.overflow = 'auto';
  4921. preview.style.borderLeft = '1px solid rgb(211, 211, 211)';
  4922. preview.style.textAlign = 'center';
  4923. if (mxClient.IS_QUIRKS)
  4924. {
  4925. preview.style.width = parseInt(hd.style.width) - 202 + 'px';
  4926. preview.style.height = list.style.height;
  4927. preview.style.marginTop = list.style.marginTop;
  4928. }
  4929. var currentListItem = null;
  4930. var applyFunctions = [];
  4931. var listEntry = document.createElement('div');
  4932. listEntry.style.position = 'relative';
  4933. listEntry.style.left = '0px';
  4934. listEntry.style.right = '0px';
  4935. for (var i = 0; i < entries.length; i++)
  4936. {
  4937. (function(section)
  4938. {
  4939. var title = listEntry.cloneNode(false);
  4940. title.style.fontWeight = 'bold';
  4941. title.style.backgroundColor = '#e5e5e5';
  4942. title.style.padding = '6px 0px 6px 20px';
  4943. mxUtils.write(title, section.title);
  4944. list.appendChild(title);
  4945. for (var j = 0; j < section.entries.length; j++)
  4946. {
  4947. (function(entry)
  4948. {
  4949. var option = listEntry.cloneNode(false);
  4950. option.style.cursor = 'pointer';
  4951. option.style.padding = '4px 0px 4px 20px';
  4952. var checkbox = document.createElement('input');
  4953. checkbox.setAttribute('type', 'checkbox');
  4954. checkbox.checked = editorUi.sidebar.isEntryVisible(entry.id);
  4955. checkbox.defaultChecked = checkbox.checked;
  4956. option.appendChild(checkbox);
  4957. mxUtils.write(option, ' ' + entry.title);
  4958. list.appendChild(option);
  4959. var itemClicked = function(evt)
  4960. {
  4961. if (evt == null || mxEvent.getSource(evt).nodeName != 'INPUT')
  4962. {
  4963. if (entry.imageCallback != null)
  4964. {
  4965. entry.imageCallback(preview);
  4966. }
  4967. else if (entry.image != null)
  4968. {
  4969. preview.innerHTML = '<img border="0" src="' + entry.image + '"/>';
  4970. }
  4971. else
  4972. {
  4973. preview.innerHTML = '<br>';
  4974. mxUtils.write(preview, mxResources.get('noPreview'));
  4975. }
  4976. if (currentListItem != null)
  4977. {
  4978. currentListItem.style.backgroundColor = '';
  4979. }
  4980. currentListItem = option;
  4981. currentListItem.style.backgroundColor = '#ebf2f9';
  4982. if (evt != null)
  4983. {
  4984. mxEvent.consume(evt);
  4985. }
  4986. }
  4987. };
  4988. mxEvent.addListener(option, 'click', itemClicked);
  4989. mxEvent.addListener(option, 'dblclick', function(evt)
  4990. {
  4991. checkbox.checked = !checkbox.checked;
  4992. mxEvent.consume(evt);
  4993. });
  4994. applyFunctions.push(function()
  4995. {
  4996. return (checkbox.checked) ? entry.id : null;
  4997. });
  4998. // Selects first entry
  4999. if (i == 0 && j == 0)
  5000. {
  5001. itemClicked();
  5002. }
  5003. })(section.entries[j]);
  5004. }
  5005. })(entries[i]);
  5006. }
  5007. div.style.padding = '30px';
  5008. div.appendChild(hd);
  5009. div.appendChild(list);
  5010. div.appendChild(preview);
  5011. var buttons = document.createElement('div');
  5012. buttons.className = 'geDialogFooter';
  5013. buttons.style.position = 'absolute';
  5014. buttons.style.paddingRight = '16px';
  5015. buttons.style.color = 'gray';
  5016. buttons.style.left = '0px';
  5017. buttons.style.right = '0px';
  5018. buttons.style.bottom = '0px';
  5019. buttons.style.height = '60px';
  5020. buttons.style.lineHeight = '52px';
  5021. if (mxClient.IS_QUIRKS)
  5022. {
  5023. buttons.style.width = hd.style.width;
  5024. buttons.style.paddingTop = '12px';
  5025. }
  5026. var cb = document.createElement('input');
  5027. cb.setAttribute('type', 'checkbox');
  5028. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  5029. {
  5030. var span = document.createElement('span');
  5031. span.style.paddingRight = '20px';
  5032. span.appendChild(cb);
  5033. mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
  5034. cb.checked = true;
  5035. cb.defaultChecked = true;
  5036. mxEvent.addListener(span, 'click', function(evt)
  5037. {
  5038. if (mxEvent.getSource(evt) != cb)
  5039. {
  5040. cb.checked = !cb.checked;
  5041. mxEvent.consume(evt);
  5042. }
  5043. });
  5044. if (mxClient.IS_QUIRKS)
  5045. {
  5046. span.style.position = 'relative';
  5047. span.style.top = '-6px';
  5048. }
  5049. buttons.appendChild(span);
  5050. }
  5051. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  5052. {
  5053. editorUi.hideDialog();
  5054. });
  5055. cancelBtn.className = 'geBtn';
  5056. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  5057. {
  5058. editorUi.hideDialog();
  5059. var libs = [];
  5060. for (var i = 0; i < applyFunctions.length; i++)
  5061. {
  5062. var lib = applyFunctions[i].apply(this, arguments);
  5063. if (lib != null)
  5064. {
  5065. libs.push(lib);
  5066. }
  5067. }
  5068. editorUi.sidebar.showEntries(libs.join(';'), cb.checked, true);
  5069. });
  5070. applyBtn.className = 'geBtn gePrimaryBtn';
  5071. if (editorUi.editor.cancelFirst)
  5072. {
  5073. buttons.appendChild(cancelBtn);
  5074. buttons.appendChild(applyBtn);
  5075. }
  5076. else
  5077. {
  5078. buttons.appendChild(applyBtn);
  5079. buttons.appendChild(cancelBtn);
  5080. }
  5081. div.appendChild(buttons);
  5082. }
  5083. else
  5084. {
  5085. var libFS = document.createElement('table');
  5086. var tbody = document.createElement('tbody');
  5087. div.style.height = '100%';
  5088. div.style.overflow = 'auto';
  5089. var row = document.createElement('tr');
  5090. libFS.style.width = '100%';
  5091. var leftDiv = document.createElement('td');
  5092. var midDiv = document.createElement('td');
  5093. var rightDiv = document.createElement('td');
  5094. var addLibCB = mxUtils.bind(this, function(wrapperDiv, title, key)
  5095. {
  5096. var libCB = document.createElement('input');
  5097. libCB.type = 'checkbox';
  5098. libFS.appendChild(libCB);
  5099. libCB.checked = editorUi.sidebar.isEntryVisible(key);
  5100. var libSpan = document.createElement('span');
  5101. mxUtils.write(libSpan, title);
  5102. var label = document.createElement('div');
  5103. label.style.display = 'block';
  5104. label.appendChild(libCB);
  5105. label.appendChild(libSpan);
  5106. mxEvent.addListener(libSpan, 'click', function(evt)
  5107. {
  5108. libCB.checked = !libCB.checked;
  5109. mxEvent.consume(evt);
  5110. });
  5111. wrapperDiv.appendChild(label);
  5112. return function()
  5113. {
  5114. return (libCB.checked) ? key : null;
  5115. };
  5116. });
  5117. row.appendChild(leftDiv);
  5118. row.appendChild(midDiv);
  5119. row.appendChild(rightDiv);
  5120. tbody.appendChild(row);
  5121. libFS.appendChild(tbody);
  5122. var applyFunctions = [];
  5123. var count = 0;
  5124. // Counts total number of entries
  5125. for (var i = 0; i < entries.length; i++)
  5126. {
  5127. for (var j = 0; j < entries[i].entries.length; j++)
  5128. {
  5129. count++;
  5130. }
  5131. }
  5132. // Distributes entries on columns
  5133. var cols = [leftDiv, midDiv, rightDiv];
  5134. var counter = 0;
  5135. for (var i = 0; i < entries.length; i++)
  5136. {
  5137. (function(section)
  5138. {
  5139. for (var j = 0; j < section.entries.length; j++)
  5140. {
  5141. (function(entry)
  5142. {
  5143. var index = Math.floor(counter / (count / 3));
  5144. applyFunctions.push(addLibCB(cols[index], entry.title, entry.id));
  5145. counter++;
  5146. })(section.entries[j]);
  5147. }
  5148. })(entries[i]);
  5149. }
  5150. div.appendChild(libFS);
  5151. var remember = document.createElement('div');
  5152. remember.style.marginTop = '18px';
  5153. remember.style.textAlign = 'center';
  5154. var cb = document.createElement('input');
  5155. if (isLocalStorage)
  5156. {
  5157. cb.setAttribute('type', 'checkbox');
  5158. cb.checked = true;
  5159. cb.defaultChecked = true;
  5160. remember.appendChild(cb);
  5161. var span = document.createElement('span');
  5162. mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
  5163. remember.appendChild(span);
  5164. mxEvent.addListener(span, 'click', function(evt)
  5165. {
  5166. cb.checked = !cb.checked;
  5167. mxEvent.consume(evt);
  5168. });
  5169. }
  5170. div.appendChild(remember);
  5171. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  5172. {
  5173. editorUi.hideDialog();
  5174. });
  5175. cancelBtn.className = 'geBtn';
  5176. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  5177. {
  5178. var libs = ['search'];
  5179. for (var i = 0; i < applyFunctions.length; i++)
  5180. {
  5181. var lib = applyFunctions[i].apply(this, arguments);
  5182. if (lib != null)
  5183. {
  5184. libs.push(lib);
  5185. }
  5186. }
  5187. editorUi.sidebar.showEntries((libs.length > 0) ? libs.join(';') : '', cb.checked);
  5188. editorUi.hideDialog();
  5189. });
  5190. applyBtn.className = 'geBtn gePrimaryBtn';
  5191. var buttons = document.createElement('div');
  5192. buttons.style.marginTop = '26px';
  5193. buttons.style.textAlign = 'right';
  5194. if (editorUi.editor.cancelFirst)
  5195. {
  5196. buttons.appendChild(cancelBtn);
  5197. buttons.appendChild(applyBtn);
  5198. }
  5199. else
  5200. {
  5201. buttons.appendChild(applyBtn);
  5202. buttons.appendChild(cancelBtn);
  5203. }
  5204. div.appendChild(buttons);
  5205. }
  5206. this.container = div;
  5207. };
  5208. var PluginsDialog = function(editorUi)
  5209. {
  5210. var div = document.createElement('div');
  5211. var inner = document.createElement('div');
  5212. inner.style.height = '120px';
  5213. inner.style.overflow = 'auto';
  5214. var plugins = mxSettings.getPlugins().slice();
  5215. function refresh()
  5216. {
  5217. if (plugins.length == 0)
  5218. {
  5219. inner.innerHTML = mxResources.get('noPlugins');
  5220. }
  5221. else
  5222. {
  5223. inner.innerHTML = '';
  5224. for (var i = 0; i < plugins.length; i++)
  5225. {
  5226. var span = document.createElement('span');
  5227. span.style.whiteSpace = 'nowrap';
  5228. var img = document.createElement('span');
  5229. img.className = 'geSprite geSprite-delete';
  5230. img.style.position = 'relative';
  5231. img.style.cursor = 'pointer';
  5232. img.style.top = '5px';
  5233. img.style.marginRight = '4px';
  5234. img.style.display = 'inline-block';
  5235. span.appendChild(img);
  5236. mxUtils.write(span, plugins[i]);
  5237. inner.appendChild(span);
  5238. mxUtils.br(inner);
  5239. mxEvent.addListener(img, 'click', (function(index)
  5240. {
  5241. return function()
  5242. {
  5243. editorUi.confirm(window.parent.mxResources.get('delete') + ' "' + plugins[index] + '"?', function()
  5244. {
  5245. plugins.splice(index, 1);
  5246. refresh();
  5247. });
  5248. };
  5249. })(i));
  5250. }
  5251. }
  5252. }
  5253. div.appendChild(inner);
  5254. refresh();
  5255. var addBtn = mxUtils.button(mxResources.get('add'), function()
  5256. {
  5257. var tmp = '';
  5258. var param = urlParams['p'];
  5259. if (param != null && param.length > 0)
  5260. {
  5261. var tokens = param.split(';');
  5262. for (var i = 0; i < tokens.length; i++)
  5263. {
  5264. var url = App.pluginRegistry[tokens[i]];
  5265. if (url != null)
  5266. {
  5267. tmp += url + ';';
  5268. }
  5269. }
  5270. if (tmp.charAt(tmp.length - 1) == ';')
  5271. {
  5272. tmp = tmp.substring(0, tmp.length - 1);
  5273. }
  5274. }
  5275. var dlg = new FilenameDialog(editorUi, tmp, mxResources.get('add'), function(newValue)
  5276. {
  5277. if (newValue != null && newValue.length > 0)
  5278. {
  5279. tokens = newValue.split(';');
  5280. for (var i = 0; i < tokens.length; i++)
  5281. {
  5282. if (tokens[i].length > 0 && mxUtils.indexOf(plugins, tokens[i]) < 0)
  5283. {
  5284. plugins.push(tokens[i]);
  5285. }
  5286. }
  5287. refresh();
  5288. }
  5289. }, mxResources.get('enterValue') + ' (' + mxResources.get('url') + ')');
  5290. editorUi.showDialog(dlg.container, 300, 80, true, true);
  5291. dlg.init();
  5292. });
  5293. addBtn.className = 'geBtn';
  5294. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  5295. {
  5296. editorUi.hideDialog();
  5297. });
  5298. cancelBtn.className = 'geBtn';
  5299. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  5300. {
  5301. mxSettings.setPlugins(plugins);
  5302. mxSettings.save();
  5303. editorUi.hideDialog();
  5304. editorUi.alert(mxResources.get('restartForChangeRequired'));
  5305. });
  5306. applyBtn.className = 'geBtn gePrimaryBtn';
  5307. var buttons = document.createElement('div');
  5308. buttons.style.marginTop = '14px';
  5309. buttons.style.textAlign = 'right';
  5310. if (editorUi.editor.cancelFirst)
  5311. {
  5312. buttons.appendChild(cancelBtn);
  5313. buttons.appendChild(addBtn);
  5314. buttons.appendChild(applyBtn);
  5315. }
  5316. else
  5317. {
  5318. buttons.appendChild(addBtn);
  5319. buttons.appendChild(applyBtn);
  5320. buttons.appendChild(cancelBtn);
  5321. }
  5322. div.appendChild(buttons);
  5323. this.container = div;
  5324. };
  5325. var EditGeometryDialog = function(editorUi, vertices)
  5326. {
  5327. var graph = editorUi.editor.graph;
  5328. var geo = (vertices.length == 1) ? graph.getCellGeometry(vertices[0]) : null;
  5329. var div = document.createElement('div');
  5330. var table = document.createElement('table');
  5331. var tbody = document.createElement('tbody');
  5332. var row = document.createElement('tr');
  5333. var left = document.createElement('td');
  5334. var right = document.createElement('td');
  5335. table.style.paddingLeft = '6px';
  5336. mxUtils.write(left, mxResources.get('left') + ':');
  5337. var xInput = document.createElement('input');
  5338. xInput.setAttribute('type', 'text');
  5339. xInput.style.width = '100px';
  5340. xInput.value = (geo != null) ? geo.x : '';
  5341. this.init = function()
  5342. {
  5343. xInput.focus();
  5344. xInput.select();
  5345. };
  5346. right.appendChild(xInput);
  5347. row.appendChild(left);
  5348. row.appendChild(right);
  5349. tbody.appendChild(row);
  5350. row = document.createElement('tr');
  5351. left = document.createElement('td');
  5352. right = document.createElement('td');
  5353. mxUtils.write(left, mxResources.get('top') + ':');
  5354. var yInput = document.createElement('input');
  5355. yInput.setAttribute('type', 'text');
  5356. yInput.style.width = '100px';
  5357. yInput.value = (geo != null) ? geo.y : '';
  5358. right.appendChild(yInput);
  5359. row.appendChild(left);
  5360. row.appendChild(right);
  5361. tbody.appendChild(row);
  5362. row = document.createElement('tr');
  5363. left = document.createElement('td');
  5364. right = document.createElement('td');
  5365. mxUtils.write(left, mxResources.get('width') + ':');
  5366. var wInput = document.createElement('input');
  5367. wInput.setAttribute('type', 'text');
  5368. wInput.style.width = '100px';
  5369. wInput.value = (geo != null) ? geo.width : '';
  5370. right.appendChild(wInput);
  5371. row.appendChild(left);
  5372. row.appendChild(right);
  5373. tbody.appendChild(row);
  5374. row = document.createElement('tr');
  5375. left = document.createElement('td');
  5376. right = document.createElement('td');
  5377. mxUtils.write(left, mxResources.get('height') + ':');
  5378. var hInput = document.createElement('input');
  5379. hInput.setAttribute('type', 'text');
  5380. hInput.style.width = '100px';
  5381. hInput.value = (geo != null) ? geo.height : '';
  5382. right.appendChild(hInput);
  5383. row.appendChild(left);
  5384. row.appendChild(right);
  5385. tbody.appendChild(row);
  5386. row = document.createElement('tr');
  5387. left = document.createElement('td');
  5388. right = document.createElement('td');
  5389. mxUtils.write(left, mxResources.get('rotation') + ':');
  5390. var rotInput = document.createElement('input');
  5391. rotInput.setAttribute('type', 'text');
  5392. rotInput.style.width = '100px';
  5393. rotInput.value = (vertices.length == 1) ? mxUtils.getValue(graph.getCellStyle(vertices[0]),
  5394. mxConstants.STYLE_ROTATION, 0) : '';
  5395. right.appendChild(rotInput);
  5396. row.appendChild(left);
  5397. row.appendChild(right);
  5398. tbody.appendChild(row);
  5399. table.appendChild(tbody);
  5400. div.appendChild(table);
  5401. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  5402. {
  5403. editorUi.hideDialog();
  5404. });
  5405. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  5406. {
  5407. editorUi.hideDialog();
  5408. graph.getModel().beginUpdate();
  5409. try
  5410. {
  5411. for (var i = 0; i < vertices.length; i++)
  5412. {
  5413. var g = graph.getCellGeometry(vertices[i]);
  5414. if (g != null)
  5415. {
  5416. g = g.clone();
  5417. if (graph.isCellMovable(vertices[i]))
  5418. {
  5419. if (mxUtils.trim(xInput.value).length > 0)
  5420. {
  5421. g.x = Number(xInput.value);
  5422. }
  5423. if (mxUtils.trim(yInput.value).length > 0)
  5424. {
  5425. g.y = Number(yInput.value);
  5426. }
  5427. }
  5428. if (graph.isCellResizable(vertices[i]))
  5429. {
  5430. if (mxUtils.trim(wInput.value).length > 0)
  5431. {
  5432. g.width = Number(wInput.value);
  5433. }
  5434. if (mxUtils.trim(hInput.value).length > 0)
  5435. {
  5436. g.height = Number(hInput.value);
  5437. }
  5438. }
  5439. graph.getModel().setGeometry(vertices[i], g);
  5440. }
  5441. if (mxUtils.trim(rotInput.value).length > 0)
  5442. {
  5443. graph.setCellStyles(mxConstants.STYLE_ROTATION, Number(rotInput.value), [vertices[i]]);
  5444. }
  5445. }
  5446. }
  5447. finally
  5448. {
  5449. graph.getModel().endUpdate();
  5450. }
  5451. });
  5452. mxEvent.addListener(div, 'keypress', function(e)
  5453. {
  5454. if (e.keyCode == 13)
  5455. {
  5456. applyBtn.click();
  5457. }
  5458. });
  5459. var buttons = document.createElement('div');
  5460. buttons.style.marginTop = '20px';
  5461. buttons.style.textAlign = 'right';
  5462. if (editorUi.editor.cancelFirst)
  5463. {
  5464. buttons.appendChild(cancelBtn);
  5465. buttons.appendChild(applyBtn);
  5466. }
  5467. else
  5468. {
  5469. buttons.appendChild(applyBtn);
  5470. buttons.appendChild(cancelBtn);
  5471. }
  5472. div.appendChild(buttons);
  5473. this.container = div;
  5474. };
  5475. /**
  5476. * Constructs a new dialog for creating files from templates.
  5477. */
  5478. var LibraryDialog = function(editorUi, name, library, initialImages, file, mode)
  5479. {
  5480. var images = [];
  5481. var graph = editorUi.editor.graph;
  5482. var outer = document.createElement('div');
  5483. outer.style.height = '100%';
  5484. var header = document.createElement('div');
  5485. header.style.whiteSpace = 'nowrap';
  5486. header.style.height = '40px';
  5487. outer.appendChild(header);
  5488. mxUtils.write(header, mxResources.get('filename') + ':');
  5489. var nameValue = name;
  5490. if (nameValue == null)
  5491. {
  5492. nameValue = editorUi.defaultLibraryName + '.xml';
  5493. }
  5494. var nameInput = document.createElement('input');
  5495. nameInput.setAttribute('value', nameValue);
  5496. nameInput.style.marginRight = '20px';
  5497. nameInput.style.marginLeft = '10px';
  5498. nameInput.style.width = '500px';
  5499. if (file != null && !file.isRenamable())
  5500. {
  5501. nameInput.setAttribute('disabled', 'true');
  5502. }
  5503. this.init = function()
  5504. {
  5505. if (file == null || file.isRenamable())
  5506. {
  5507. nameInput.focus();
  5508. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  5509. {
  5510. nameInput.select();
  5511. }
  5512. else
  5513. {
  5514. document.execCommand('selectAll', false, null);
  5515. }
  5516. }
  5517. };
  5518. header.appendChild(nameInput);
  5519. var div = document.createElement('div');
  5520. div.style.borderWidth = '1px 0px 1px 0px';
  5521. div.style.borderColor = '#d3d3d3';
  5522. div.style.borderStyle = 'solid';
  5523. div.style.marginTop = '6px';
  5524. div.style.overflow = 'auto';
  5525. div.style.height = '340px';
  5526. div.style.backgroundPosition = 'center center';
  5527. div.style.backgroundRepeat = 'no-repeat';
  5528. if (images.length == 0 && Graph.fileSupport)
  5529. {
  5530. div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
  5531. }
  5532. var bg = document.createElement('div');
  5533. bg.style.position = 'absolute';
  5534. bg.style.width = '640px';
  5535. bg.style.top = '260px';
  5536. bg.style.textAlign = 'center';
  5537. bg.style.fontSize = '22px';
  5538. bg.style.color = '#a0c3ff';
  5539. mxUtils.write(bg, mxResources.get('dragImagesHere'));
  5540. outer.appendChild(bg);
  5541. var entries = {};
  5542. var ew = 100;
  5543. var eh = 100;
  5544. var dragSourceIndex = null;
  5545. var dropTargetIndex = null;
  5546. function getIndexForEvent(evt)
  5547. {
  5548. var dropTarget = document.elementFromPoint(evt.clientX, evt.clientY);
  5549. while (dropTarget != null && dropTarget.parentNode != div)
  5550. {
  5551. dropTarget = dropTarget.parentNode;
  5552. }
  5553. var result = null;
  5554. if (dropTarget != null)
  5555. {
  5556. var tmp = div.firstChild;
  5557. result = 0;
  5558. while (tmp != null && tmp != dropTarget)
  5559. {
  5560. tmp = tmp.nextSibling;
  5561. result++;
  5562. }
  5563. }
  5564. return result;
  5565. };
  5566. var stopEditing = null;
  5567. var stopWrapper = function(evt)
  5568. {
  5569. var source = mxEvent.getSource(evt);
  5570. if (source.getAttribute('contentEditable') != 'true' && stopEditing != null)
  5571. {
  5572. stopEditing();
  5573. stopEditing = null;
  5574. mxEvent.consume(evt);
  5575. }
  5576. };
  5577. mxEvent.addListener(div, 'mousedown', stopWrapper);
  5578. mxEvent.addListener(div, 'pointerdown', stopWrapper);
  5579. mxEvent.addListener(div, 'touchstart', stopWrapper);
  5580. // For converting image URLs
  5581. var converter = new mxUrlConverter();
  5582. var errorShowed = false;
  5583. function addButton(data, mimeType, x, y, w, h, img, aspect, title)
  5584. {
  5585. // Ignores duplicates
  5586. try
  5587. {
  5588. if (mimeType == null || mimeType.substring(0, 6) == 'image/')
  5589. {
  5590. if ((data == null && img != null) || entries[data] == null)
  5591. {
  5592. div.style.backgroundImage = '';
  5593. bg.style.display = 'none';
  5594. var iw = w;
  5595. var ih = h;
  5596. if (w > editorUi.maxImageSize || h > editorUi.maxImageSize)
  5597. {
  5598. var s = Math.min(1, Math.min(editorUi.maxImageSize / Math.max(1, w)),
  5599. editorUi.maxImageSize / Math.max(1, h));
  5600. w *= s;
  5601. h *= s;
  5602. }
  5603. if (iw > ih)
  5604. {
  5605. ih = Math.round(ih * ew / iw);
  5606. iw = ew;
  5607. }
  5608. else
  5609. {
  5610. iw = Math.round(iw * eh / ih);
  5611. ih = eh;
  5612. }
  5613. var wrapper = document.createElement('div');
  5614. wrapper.setAttribute('draggable', 'true');
  5615. wrapper.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  5616. wrapper.style.position = 'relative';
  5617. wrapper.style.cursor = 'move';
  5618. mxUtils.setPrefixedStyle(wrapper.style, 'transition', 'transform .1s ease-in-out');
  5619. if (data != null)
  5620. {
  5621. var elt = document.createElement('img');
  5622. elt.setAttribute('src', converter.convert(data));
  5623. elt.style.width = iw + 'px';
  5624. elt.style.height = ih + 'px';
  5625. elt.style.margin = '10px';
  5626. elt.style.paddingBottom = Math.floor((eh - ih) / 2) + 'px';
  5627. elt.style.paddingLeft = Math.floor((ew - iw) / 2) + 'px';
  5628. wrapper.appendChild(elt);
  5629. }
  5630. else if (img != null)
  5631. {
  5632. var cells = editorUi.stringToCells(editorUi.editor.graph.decompress(img.xml));
  5633. if (cells.length > 0)
  5634. {
  5635. editorUi.sidebar.createThumb(cells, ew, eh, wrapper, null, true, false);
  5636. // Needs inline block on SVG for delete icon to appear on same line
  5637. wrapper.firstChild.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  5638. wrapper.firstChild.style.cursor = '';
  5639. }
  5640. }
  5641. var rem = document.createElement('img');
  5642. rem.setAttribute('src', Editor.closeImage);
  5643. rem.setAttribute('border', '0');
  5644. rem.setAttribute('title', mxResources.get('delete'));
  5645. rem.setAttribute('align', 'top');
  5646. rem.style.paddingTop = '4px';
  5647. rem.style.marginLeft = '-22px';
  5648. rem.style.cursor = 'pointer';
  5649. // Blocks dragging of remove icon
  5650. mxEvent.addListener(rem, 'dragstart', function(evt)
  5651. {
  5652. mxEvent.consume(evt);
  5653. });
  5654. // Seems to bring remove icon on top of graph
  5655. if (data == null && img != null)
  5656. {
  5657. rem.style.position = 'relative';
  5658. }
  5659. (function(wrapperDiv, dataParam, imgParam)
  5660. {
  5661. mxEvent.addListener(rem, 'click', function(evt)
  5662. {
  5663. entries[dataParam] = null;
  5664. for (var i = 0; i < images.length; i++)
  5665. {
  5666. if ((images[i].data != null && images[i].data == dataParam) ||
  5667. (images[i].xml != null && imgParam != null &&
  5668. images[i].xml == imgParam.xml))
  5669. {
  5670. images.splice(i, 1);
  5671. break;
  5672. }
  5673. }
  5674. wrapper.parentNode.removeChild(wrapperDiv);
  5675. if (images.length == 0)
  5676. {
  5677. div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
  5678. bg.style.display = '';
  5679. }
  5680. mxEvent.consume(evt);
  5681. });
  5682. // Workaround for accidental select all
  5683. mxEvent.addListener(rem, 'dblclick', function(evt)
  5684. {
  5685. mxEvent.consume(evt);
  5686. });
  5687. })(wrapper, data, img);
  5688. wrapper.appendChild(rem);
  5689. wrapper.style.marginBottom = '30px';
  5690. var label = document.createElement('div');
  5691. label.style.position = 'absolute';
  5692. label.style.boxSizing = 'border-box';
  5693. label.style.bottom = '-18px';
  5694. label.style.left = '10px';
  5695. label.style.right = '10px';
  5696. label.style.backgroundColor = '#ffffff';
  5697. label.style.overflow = 'hidden';
  5698. label.style.textAlign = 'center';
  5699. var entry = null;
  5700. if (data != null)
  5701. {
  5702. entry = {data: data, w: w, h: h, title: title};
  5703. if (aspect != null)
  5704. {
  5705. entry.aspect = aspect;
  5706. }
  5707. entries[data] = elt;
  5708. images.push(entry);
  5709. }
  5710. else if (img != null)
  5711. {
  5712. img.aspect = 'fixed';
  5713. images.push(img);
  5714. entry = img;
  5715. }
  5716. function updateLabel()
  5717. {
  5718. label.innerHTML = '';
  5719. label.style.cursor = 'pointer';
  5720. label.style.whiteSpace = 'nowrap';
  5721. label.style.textOverflow = 'ellipsis';
  5722. mxUtils.write(label, (entry.title != null && entry.title.length > 0) ?
  5723. entry.title : mxResources.get('untitled'));
  5724. if (entry.title == null || entry.title.length == 0)
  5725. {
  5726. label.style.color = '#d0d0d0';
  5727. }
  5728. else
  5729. {
  5730. label.style.color = '';
  5731. }
  5732. };
  5733. mxEvent.addListener(label, 'keydown', function(evt)
  5734. {
  5735. if (evt.keyCode == 13 && stopEditing != null)
  5736. {
  5737. stopEditing();
  5738. stopEditing = null;
  5739. mxEvent.consume(evt);
  5740. }
  5741. });
  5742. updateLabel();
  5743. wrapper.appendChild(label);
  5744. // Blocks dragging of label
  5745. mxEvent.addListener(label, 'mousedown', function(evt)
  5746. {
  5747. if (label.getAttribute('contentEditable') != 'true')
  5748. {
  5749. mxEvent.consume(evt);
  5750. }
  5751. });
  5752. var startEditing = function(evt)
  5753. {
  5754. // Workaround for various issues in IE
  5755. if (!mxClient.IS_IOS && !mxClient.IS_QUIRKS && !mxClient.IS_FF &&
  5756. (document.documentMode == null || document.documentMode > 9))
  5757. {
  5758. if (label.getAttribute('contentEditable') != 'true')
  5759. {
  5760. if (stopEditing != null)
  5761. {
  5762. stopEditing();
  5763. stopEditing = null;
  5764. }
  5765. if (entry.title == null || entry.title.length == 0)
  5766. {
  5767. label.innerHTML = '';
  5768. }
  5769. label.style.textOverflow = '';
  5770. label.style.whiteSpace = '';
  5771. label.style.cursor = 'text';
  5772. label.style.color = '';
  5773. label.setAttribute('contentEditable', 'true');
  5774. label.focus();
  5775. document.execCommand('selectAll', false, null);
  5776. stopEditing = function()
  5777. {
  5778. label.removeAttribute('contentEditable');
  5779. label.style.cursor = 'pointer';
  5780. entry.title = label.innerHTML;
  5781. updateLabel();
  5782. }
  5783. mxEvent.consume(evt);
  5784. }
  5785. }
  5786. else
  5787. {
  5788. var dlg = new FilenameDialog(editorUi, entry.title || '', mxResources.get('ok'), function(newTitle)
  5789. {
  5790. if (newTitle != null)
  5791. {
  5792. entry.title = newTitle;
  5793. updateLabel();
  5794. }
  5795. }, mxResources.get('enterValue'));
  5796. editorUi.showDialog(dlg.container, 300, 80, true, true);
  5797. dlg.init();
  5798. mxEvent.consume(evt);
  5799. }
  5800. };
  5801. mxEvent.addListener(label, 'click', startEditing);
  5802. mxEvent.addListener(wrapper, 'dblclick', startEditing);
  5803. div.appendChild(wrapper);
  5804. mxEvent.addListener(wrapper, 'dragstart', function(evt)
  5805. {
  5806. if (data == null && img != null)
  5807. {
  5808. rem.style.visibility = 'hidden';
  5809. label.style.visibility = 'hidden';
  5810. }
  5811. // Workaround for no DnD on DIV in FF
  5812. if (mxClient.IS_FF && img.xml != null)
  5813. {
  5814. evt.dataTransfer.setData('Text', img.xml);
  5815. }
  5816. dragSourceIndex = getIndexForEvent(evt);
  5817. // Workaround for missing drag preview in Google Chrome
  5818. if (mxClient.IS_GC)
  5819. {
  5820. wrapper.style.opacity = '0.9';
  5821. }
  5822. window.setTimeout(function()
  5823. {
  5824. mxUtils.setPrefixedStyle(wrapper.style, 'transform', 'scale(0.5,0.5)');
  5825. mxUtils.setOpacity(wrapper, 30);
  5826. rem.style.visibility = '';
  5827. label.style.visibility = '';
  5828. }, 0);
  5829. });
  5830. mxEvent.addListener(wrapper, 'dragend', function(evt)
  5831. {
  5832. if (rem.style.visibility == 'hidden')
  5833. {
  5834. rem.style.visibility = '';
  5835. label.style.visibility = '';
  5836. }
  5837. dragSourceIndex = null;
  5838. mxUtils.setOpacity(wrapper, 100);
  5839. mxUtils.setPrefixedStyle(wrapper.style, 'transform', null);
  5840. });
  5841. }
  5842. else if (!errorShowed)
  5843. {
  5844. errorShowed = true;
  5845. editorUi.handleError({message: mxResources.get('fileExists')})
  5846. }
  5847. }
  5848. else
  5849. {
  5850. var done = false;
  5851. try
  5852. {
  5853. editorUi.spinner.stop();
  5854. var doc = mxUtils.parseXml(data);
  5855. if (doc.documentElement.nodeName == 'mxlibrary')
  5856. {
  5857. var temp = JSON.parse(mxUtils.getTextContent(doc.documentElement));
  5858. if (temp != null && temp.length > 0)
  5859. {
  5860. for (var i = 0; i < temp.length; i++)
  5861. {
  5862. if (temp[i].xml != null)
  5863. {
  5864. addButton(null, null, 0, 0, 0, 0, temp[i]);
  5865. }
  5866. else
  5867. {
  5868. addButton(temp[i].data, null, 0, 0, temp[i].w, temp[i].h, null, 'fixed', temp[i].title);
  5869. }
  5870. }
  5871. }
  5872. done = true;
  5873. }
  5874. else if (doc.documentElement.nodeName == 'mxfile')
  5875. {
  5876. var pages = doc.documentElement.getElementsByTagName('diagram');
  5877. for (var i = 0; i < pages.length; i++)
  5878. {
  5879. var temp = mxUtils.getTextContent(pages[i]);
  5880. var cells = editorUi.stringToCells(editorUi.editor.graph.decompress(temp));
  5881. var size = editorUi.editor.graph.getBoundingBoxFromGeometry(cells);
  5882. addButton(null, null, 0, 0, 0, 0, {xml: temp, w: size.width, h: size.height});
  5883. }
  5884. done = true;
  5885. }
  5886. }
  5887. catch (e)
  5888. {
  5889. // ignore
  5890. }
  5891. if (!done)
  5892. {
  5893. editorUi.spinner.stop();
  5894. editorUi.handleError({message: mxResources.get('errorLoadingFile')})
  5895. }
  5896. }
  5897. }
  5898. catch (e)
  5899. {
  5900. // ignore
  5901. }
  5902. return null;
  5903. };
  5904. if (initialImages != null)
  5905. {
  5906. for (var i = 0; i < initialImages.length; i++)
  5907. {
  5908. var img = initialImages[i];
  5909. addButton(img.data, null, 0, 0, img.w, img.h, img, img.aspect, img.title);
  5910. }
  5911. }
  5912. // Setup the dnd listeners
  5913. mxEvent.addListener(div, 'dragleave', function(evt)
  5914. {
  5915. bg.style.cursor = '';
  5916. var source = mxEvent.getSource(evt);
  5917. while (source != null)
  5918. {
  5919. if (source == div || source == bg)
  5920. {
  5921. evt.stopPropagation();
  5922. evt.preventDefault();
  5923. break;
  5924. }
  5925. source = source.parentNode;
  5926. }
  5927. });
  5928. function dragOver(evt)
  5929. {
  5930. evt.dataTransfer.dropEffect = (dragSourceIndex != null) ? 'move' : 'copy';
  5931. evt.stopPropagation();
  5932. evt.preventDefault();
  5933. };
  5934. var createImportHandler = function(evt)
  5935. {
  5936. return function(data, mimeType, x, y, w, h, img, doneFn, file)
  5937. {
  5938. if (file != null && !editorUi.isOffline() && new XMLHttpRequest().upload && editorUi.isRemoteFileFormat(data, file.name))
  5939. {
  5940. editorUi.parseFile(file, mxUtils.bind(this, function(xhr)
  5941. {
  5942. if (xhr.readyState == 4)
  5943. {
  5944. editorUi.spinner.stop();
  5945. if (xhr.status >= 200 && xhr.status <= 299)
  5946. {
  5947. var xml = xhr.responseText;
  5948. addButton(xml, mimeType, x, y, w, h, img, 'fixed', (mxEvent.isAltDown(evt)) ?
  5949. null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
  5950. div.scrollTop = div.scrollHeight;
  5951. }
  5952. }
  5953. }));
  5954. }
  5955. else
  5956. {
  5957. addButton(data, mimeType, x, y, w, h, img, 'fixed', (mxEvent.isAltDown(evt)) ?
  5958. null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
  5959. div.scrollTop = div.scrollHeight;
  5960. }
  5961. };
  5962. };
  5963. function dropHandler(evt)
  5964. {
  5965. evt.stopPropagation();
  5966. evt.preventDefault();
  5967. errorShowed = false;
  5968. dropTargetIndex = getIndexForEvent(evt);
  5969. if (dragSourceIndex != null)
  5970. {
  5971. if (dropTargetIndex != null && dropTargetIndex < div.children.length)
  5972. {
  5973. images.splice((dropTargetIndex > dragSourceIndex) ? dropTargetIndex - 1 : dropTargetIndex,
  5974. 0, images.splice(dragSourceIndex, 1)[0]);
  5975. div.insertBefore(div.children[dragSourceIndex], div.children[dropTargetIndex]);
  5976. }
  5977. else
  5978. {
  5979. images.push(images.splice(dragSourceIndex, 1)[0]);
  5980. div.appendChild(div.children[dragSourceIndex]);
  5981. }
  5982. }
  5983. else if (evt.dataTransfer.files.length > 0)
  5984. {
  5985. editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxImageSize, createImportHandler(evt));
  5986. }
  5987. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  5988. {
  5989. var uri = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
  5990. if (/(\.jpg)($|\?)/i.test(uri) || /(\.png)($|\?)/i.test(uri) ||
  5991. /(\.gif)($|\?)/i.test(uri) || /(\.svg)($|\?)/i.test(uri))
  5992. {
  5993. editorUi.loadImage(uri, function(img)
  5994. {
  5995. addButton(uri, null, 0, 0, img.width, img.height);
  5996. div.scrollTop = div.scrollHeight;
  5997. });
  5998. }
  5999. }
  6000. evt.stopPropagation();
  6001. evt.preventDefault();
  6002. };
  6003. mxEvent.addListener(div, 'dragover', dragOver);
  6004. mxEvent.addListener(div, 'drop', dropHandler);
  6005. mxEvent.addListener(bg, 'dragover', dragOver);
  6006. mxEvent.addListener(bg, 'drop', dropHandler);
  6007. outer.appendChild(div);
  6008. var btns = document.createElement('div');
  6009. btns.style.textAlign = 'right';
  6010. btns.style.marginTop = '20px';
  6011. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  6012. {
  6013. editorUi.hideDialog(true);
  6014. });
  6015. cancelBtn.setAttribute('id', 'btnCancel');
  6016. cancelBtn.className = 'geBtn';
  6017. if (editorUi.editor.cancelFirst)
  6018. {
  6019. btns.appendChild(cancelBtn);
  6020. }
  6021. // Does not show download button, allow filename editing in Chrome Apps
  6022. if (!window.chrome || !chrome.app || !chrome.app.runtime)
  6023. {
  6024. var btn = mxUtils.button(mxResources.get('export'), function()
  6025. {
  6026. var data = editorUi.createLibraryDataFromImages(images);
  6027. var filename = nameInput.value;
  6028. if (!/(\.xml)$/i.test(filename))
  6029. {
  6030. filename += '.xml';
  6031. }
  6032. if (editorUi.isLocalFileSave())
  6033. {
  6034. editorUi.saveLocalFile(data, filename, 'text/xml', null, null, true);
  6035. }
  6036. else
  6037. {
  6038. new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(filename) +
  6039. '&format=xml&xml=' + encodeURIComponent(data)).simulate(document, '_blank');
  6040. }
  6041. });
  6042. btn.setAttribute('id', 'btnDownload');
  6043. btn.className = 'geBtn';
  6044. btns.appendChild(btn);
  6045. }
  6046. else
  6047. {
  6048. nameInput.setAttribute('disabled', 'disabled');
  6049. }
  6050. var fileInput = document.createElement('input');
  6051. fileInput.setAttribute('multiple', 'multiple');
  6052. fileInput.setAttribute('type', 'file');
  6053. if (document.documentMode == null)
  6054. {
  6055. mxEvent.addListener(fileInput, 'change', function(evt)
  6056. {
  6057. errorShowed = false;
  6058. editorUi.importFiles(fileInput.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h, img, doneFn, file)
  6059. {
  6060. createImportHandler(evt)(data, mimeType, x, y, w, h, img, doneFn, file);
  6061. // Resets input to force change event for same file
  6062. fileInput.value = '';
  6063. });
  6064. div.scrollTop = div.scrollHeight;
  6065. });
  6066. var btn = mxUtils.button(mxResources.get('import'), function()
  6067. {
  6068. if (stopEditing != null)
  6069. {
  6070. stopEditing();
  6071. stopEditing = null;
  6072. }
  6073. fileInput.click();
  6074. });
  6075. btn.setAttribute('id', 'btnAddImage');
  6076. btn.className = 'geBtn';
  6077. btns.appendChild(btn);
  6078. }
  6079. var btn = mxUtils.button(mxResources.get('addImageUrl'), function()
  6080. {
  6081. if (stopEditing != null)
  6082. {
  6083. stopEditing();
  6084. stopEditing = null;
  6085. }
  6086. editorUi.showImageDialog(mxResources.get('addImageUrl'), '', function(url, w, h)
  6087. {
  6088. errorShowed = false;
  6089. if (url != null)
  6090. {
  6091. // Image dialog returns modified data URLs which
  6092. // must be converted back to real data URL
  6093. if (url.substring(0, 11) == 'data:image/')
  6094. {
  6095. var comma = url.indexOf(',');
  6096. if (comma > 0)
  6097. {
  6098. url = url.substring(0, comma) + ';base64,' + url.substring(comma + 1);
  6099. }
  6100. }
  6101. addButton(url, null, 0, 0, w, h);
  6102. div.scrollTop = div.scrollHeight;
  6103. }
  6104. });
  6105. });
  6106. btn.setAttribute('id', 'btnAddImageUrl');
  6107. btn.className = 'geBtn';
  6108. btns.appendChild(btn);
  6109. // Indirection for overriding
  6110. this.saveBtnClickHandler = function(name, images, file, mode)
  6111. {
  6112. editorUi.saveLibrary(name, images, file, mode);
  6113. };
  6114. var btn = mxUtils.button(mxResources.get('save'),mxUtils.bind(this, function()
  6115. {
  6116. if (stopEditing != null)
  6117. {
  6118. stopEditing();
  6119. stopEditing = null;
  6120. }
  6121. this.saveBtnClickHandler(nameInput.value, images, file, mode);
  6122. }));
  6123. btn.setAttribute('id', 'btnSave');
  6124. btn.className = 'geBtn gePrimaryBtn';
  6125. btns.appendChild(btn);
  6126. if (!editorUi.editor.cancelFirst)
  6127. {
  6128. btns.appendChild(cancelBtn);
  6129. }
  6130. outer.appendChild(btns);
  6131. this.container = outer;
  6132. };
  6133. /**
  6134. * Constructs a new textarea dialog.
  6135. */
  6136. var EditShapeDialog = function(editorUi, cell, title, w, h)
  6137. {
  6138. w = (w != null) ? w : 300;
  6139. h = (h != null) ? h : 120;
  6140. var row, td;
  6141. var table = document.createElement('table');
  6142. var tbody = document.createElement('tbody');
  6143. table.style.cellPadding = '4px';
  6144. row = document.createElement('tr');
  6145. td = document.createElement('td');
  6146. td.setAttribute('colspan', '2');
  6147. td.style.fontSize = '10pt';
  6148. mxUtils.write(td, title);
  6149. row.appendChild(td);
  6150. tbody.appendChild(row);
  6151. row = document.createElement('tr');
  6152. td = document.createElement('td');
  6153. var nameInput = document.createElement('textarea');
  6154. nameInput.style.outline = 'none';
  6155. nameInput.style.resize = 'none';
  6156. nameInput.style.width = (w - 200) + 'px';
  6157. nameInput.style.height = h + 'px';
  6158. this.textarea = nameInput;
  6159. this.init = function()
  6160. {
  6161. nameInput.focus();
  6162. nameInput.scrollTop = 0;
  6163. };
  6164. td.appendChild(nameInput);
  6165. row.appendChild(td);
  6166. td = document.createElement('td');
  6167. var container = document.createElement('div');
  6168. container.style.position = 'relative';
  6169. container.style.border = '1px solid gray';
  6170. container.style.top = '6px';
  6171. container.style.width = '200px';
  6172. container.style.height = (h + 4) + 'px';
  6173. container.style.overflow = 'hidden';
  6174. container.style.marginBottom = '16px';
  6175. mxEvent.disableContextMenu(container);
  6176. td.appendChild(container);
  6177. var graph = new Graph(container);
  6178. graph.setEnabled(false);
  6179. var clone = editorUi.editor.graph.cloneCells([cell])[0];
  6180. graph.addCells([clone]);
  6181. var state = graph.view.getState(clone);
  6182. var stencil = '';
  6183. if (state.shape != null && state.shape.stencil != null)
  6184. {
  6185. stencil = mxUtils.getPrettyXml(state.shape.stencil.desc);
  6186. }
  6187. mxUtils.write(nameInput, stencil || '');
  6188. var b = graph.getGraphBounds();
  6189. var ns = Math.min((200 - 40) / b.width, (h - 40) / b.height);
  6190. graph.view.scaleAndTranslate(ns, 20 / ns - b.x, 20 / ns - b.y);
  6191. row.appendChild(td);
  6192. tbody.appendChild(row);
  6193. row = document.createElement('tr');
  6194. td = document.createElement('td');
  6195. td.setAttribute('colspan', '2');
  6196. td.style.paddingTop = '2px';
  6197. td.style.whiteSpace = 'nowrap';
  6198. td.setAttribute('align', 'right');
  6199. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  6200. {
  6201. editorUi.hideDialog();
  6202. });
  6203. cancelBtn.className = 'geBtn';
  6204. if (editorUi.editor.cancelFirst)
  6205. {
  6206. td.appendChild(cancelBtn);
  6207. }
  6208. if (!editorUi.isOffline())
  6209. {
  6210. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  6211. {
  6212. window.open('https://desk.draw.io/support/solutions/articles/16000052874');
  6213. });
  6214. helpBtn.className = 'geBtn';
  6215. td.appendChild(helpBtn);
  6216. }
  6217. var updateShape = function(targetGraph, targetCell, hide)
  6218. {
  6219. var newValue = nameInput.value;
  6220. // Checks if XML has changed (getPrettyXml "normalizes" DOM)
  6221. var doc = mxUtils.parseXml(newValue);
  6222. newValue = mxUtils.getPrettyXml(doc.documentElement);
  6223. // Checks for validation errors
  6224. // LATER: Validate against XSD
  6225. var errors = doc.documentElement.getElementsByTagName('parsererror');
  6226. if (errors != null && errors.length > 0)
  6227. {
  6228. editorUi.showError(mxResources.get('error'), mxResources.get('containsValidationErrors'), mxResources.get('ok'));
  6229. }
  6230. else
  6231. {
  6232. if (hide)
  6233. {
  6234. editorUi.hideDialog();
  6235. }
  6236. var isNew = !targetGraph.model.contains(targetCell);
  6237. if (!hide || isNew || newValue != stencil)
  6238. {
  6239. // Transform XML value to be used in cell style
  6240. newValue = editorUi.editor.graph.compress(newValue);
  6241. targetGraph.getModel().beginUpdate();
  6242. try
  6243. {
  6244. // Inserts cell if required
  6245. if (isNew)
  6246. {
  6247. var pt = editorUi.editor.graph.getInsertPoint();
  6248. targetCell.geometry.x = pt.x;
  6249. targetCell.geometry.y = pt.y;
  6250. targetGraph.addCell(targetCell)
  6251. }
  6252. targetGraph.setCellStyles(mxConstants.STYLE_SHAPE, 'stencil(' + newValue + ')', [targetCell]);
  6253. }
  6254. catch (e)
  6255. {
  6256. throw e;
  6257. }
  6258. finally
  6259. {
  6260. // Updates the display
  6261. targetGraph.getModel().endUpdate();
  6262. }
  6263. // Updates selection after stencil was created for rendering
  6264. if (isNew)
  6265. {
  6266. targetGraph.setSelectionCell(targetCell);
  6267. }
  6268. }
  6269. }
  6270. };
  6271. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  6272. {
  6273. updateShape(graph, clone, false);
  6274. });
  6275. previewBtn.className = 'geBtn';
  6276. td.appendChild(previewBtn);
  6277. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  6278. {
  6279. updateShape(editorUi.editor.graph, cell, true);
  6280. });
  6281. applyBtn.className = 'geBtn gePrimaryBtn';
  6282. td.appendChild(applyBtn);
  6283. if (!editorUi.editor.cancelFirst)
  6284. {
  6285. td.appendChild(cancelBtn);
  6286. }
  6287. row.appendChild(td);
  6288. tbody.appendChild(row);
  6289. table.appendChild(tbody);
  6290. this.container = table;
  6291. };
  6292. var CustomDialog = function(editorUi, content, okFn, cancelFn, okButtonText, helpLink)
  6293. {
  6294. var div = document.createElement('div');
  6295. div.appendChild(content);
  6296. var btns = document.createElement('div');
  6297. btns.style.marginTop = '16px';
  6298. btns.style.textAlign = 'right';
  6299. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  6300. {
  6301. editorUi.hideDialog();
  6302. if (cancelFn != null)
  6303. {
  6304. cancelFn();
  6305. }
  6306. });
  6307. cancelBtn.className = 'geBtn';
  6308. if (editorUi.editor.cancelFirst)
  6309. {
  6310. btns.appendChild(cancelBtn);
  6311. }
  6312. if (!editorUi.isOffline() && helpLink != null)
  6313. {
  6314. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  6315. {
  6316. window.open(helpLink);
  6317. });
  6318. helpBtn.className = 'geBtn';
  6319. btns.appendChild(helpBtn);
  6320. }
  6321. var okBtn = mxUtils.button(okButtonText || mxResources.get('ok'), function()
  6322. {
  6323. editorUi.hideDialog();
  6324. if (okFn != null)
  6325. {
  6326. okFn();
  6327. }
  6328. });
  6329. btns.appendChild(okBtn);
  6330. okBtn.className = 'geBtn gePrimaryBtn';
  6331. if (!editorUi.editor.cancelFirst)
  6332. {
  6333. btns.appendChild(cancelBtn);
  6334. }
  6335. div.appendChild(btns);
  6336. this.cancelBtn = cancelBtn;
  6337. this.okButton = okBtn;
  6338. this.container = div;
  6339. };