Dialogs.js 199 KB

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