Dialogs.js 199 KB

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