Dialogs.js 262 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251
  1. /**
  2. * Copyright (c) 2006-2018, JGraph Ltd
  3. * Copyright (c) 2006-2018, Gaudenz Alder
  4. */
  5. var StorageDialog = function(editorUi, fn, rowLimit)
  6. {
  7. rowLimit = (rowLimit != null) ? rowLimit : 2;
  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, true);
  14. var bottom = '28px';
  15. if (elt != null)
  16. {
  17. elt.style.bottom = parseInt(bottom) - 3 + 'px';
  18. }
  19. if (!editorUi.isOffline() && editorUi.getServiceCount() > 1)
  20. {
  21. var help = document.createElement('a');
  22. help.setAttribute('href', 'https://about.draw.io/support/');
  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. mxUtils.setOpacity(icon, 50);
  34. icon.style.height = '16px';
  35. icon.style.width = '16px';
  36. icon.setAttribute('border', '0');
  37. icon.setAttribute('valign', 'bottom');
  38. icon.setAttribute('src', Editor.helpImage);
  39. icon.style.marginRight = '2px';
  40. help.appendChild(icon);
  41. mxUtils.write(help, mxResources.get('help'));
  42. div.appendChild(help);
  43. }
  44. var demo = document.createElement('div');
  45. demo.style.position = 'absolute';
  46. demo.style.cursor = 'pointer';
  47. demo.style.fontSize = '12px';
  48. demo.style.bottom = bottom;
  49. demo.style.color = 'gray';
  50. mxUtils.write(demo, mxResources.get('decideLater'));
  51. if (editorUi.isOfflineApp())
  52. {
  53. demo.style.right = '20px';
  54. }
  55. else
  56. {
  57. mxUtils.setPrefixedStyle(demo.style, 'transform', 'translate(-50%,0)');
  58. demo.style.left = '50%';
  59. }
  60. this.init = function()
  61. {
  62. if (mxClient.IS_QUIRKS || document.documentMode == 8)
  63. {
  64. demo.style.marginLeft = -Math.round(demo.clientWidth / 2) + 'px';
  65. }
  66. };
  67. div.appendChild(demo);
  68. mxEvent.addListener(demo, 'click', function()
  69. {
  70. editorUi.hideDialog();
  71. var prev = Editor.useLocalStorage;
  72. editorUi.createFile(editorUi.defaultFilename, null, null, null, null, null, null, true);
  73. Editor.useLocalStorage = prev;
  74. });
  75. var buttons = document.createElement('div');
  76. if (mxClient.IS_QUIRKS)
  77. {
  78. buttons.style.whiteSpace = 'nowrap';
  79. buttons.style.cssFloat = 'left';
  80. }
  81. buttons.style.border = '1px solid #d3d3d3';
  82. buttons.style.borderWidth = '1px 0px 1px 0px';
  83. buttons.style.padding = '12px 0px 12px 0px';
  84. var cb = document.createElement('input');
  85. cb.setAttribute('type', 'checkbox');
  86. cb.setAttribute('checked', 'checked');
  87. cb.defaultChecked = true;
  88. var count = 0;
  89. var p3 = document.createElement('p');
  90. function addLogo(img, title, mode, clientName, labels, clientFn)
  91. {
  92. var button = document.createElement('a');
  93. button.style.overflow = 'hidden';
  94. button.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  95. button.className = 'geBaseButton';
  96. button.style.boxSizing = 'border-box';
  97. button.style.fontSize = '11px';
  98. button.style.position = 'relative';
  99. button.style.margin = '4px';
  100. button.style.padding = '8px 10px 12px 10px';
  101. button.style.width = '88px';
  102. button.style.height = '100px';
  103. button.style.whiteSpace = 'nowrap';
  104. button.setAttribute('title', title);
  105. // Workaround for quirks is a vertical list (limited to max 2 items)
  106. if (mxClient.IS_QUIRKS)
  107. {
  108. button.style.cssFloat = 'left';
  109. button.style.zoom = '1';
  110. }
  111. var label = document.createElement('div');
  112. label.style.textOverflow = 'ellipsis';
  113. label.style.overflow = 'hidden';
  114. if (img != null)
  115. {
  116. var logo = document.createElement('img');
  117. logo.setAttribute('src', img);
  118. logo.setAttribute('border', '0');
  119. logo.setAttribute('align', 'absmiddle');
  120. logo.style.width = '60px';
  121. logo.style.height = '60px';
  122. logo.style.paddingBottom = '6px';
  123. button.appendChild(logo);
  124. }
  125. else
  126. {
  127. label.style.paddingTop = '5px';
  128. label.style.whiteSpace = 'normal';
  129. // Handles special case
  130. if (mxClient.IS_IOS)
  131. {
  132. button.style.padding = '0px 10px 20px 10px';
  133. button.style.top = '6px';
  134. }
  135. else if (mxClient.IS_FF)
  136. {
  137. label.style.paddingTop = '0px';
  138. label.style.marginTop = '-2px';
  139. }
  140. }
  141. button.appendChild(label);
  142. mxUtils.write(label, title);
  143. if (labels != null)
  144. {
  145. for (var i = 0; i < labels.length; i++)
  146. {
  147. mxUtils.br(label);
  148. mxUtils.write(label, labels[i]);
  149. }
  150. }
  151. function initButton()
  152. {
  153. mxEvent.addListener(button, 'click', (clientFn != null) ? clientFn : function()
  154. {
  155. // Special case: Redirect all drive users to draw.io pro
  156. if (mode == App.MODE_GOOGLE && !editorUi.isDriveDomain())
  157. {
  158. window.location.hostname = DriveClient.prototype.newAppHostname;
  159. }
  160. else if (mode == App.MODE_GOOGLE && editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  161. {
  162. // Tries immediate authentication
  163. editorUi.drive.checkToken(mxUtils.bind(this, function()
  164. {
  165. editorUi.spinner.stop();
  166. editorUi.setMode(mode, cb.checked);
  167. fn();
  168. }));
  169. }
  170. else if (mode == App.MODE_ONEDRIVE && editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  171. {
  172. // Tries immediate authentication
  173. editorUi.oneDrive.checkToken(mxUtils.bind(this, function()
  174. {
  175. editorUi.spinner.stop();
  176. editorUi.setMode(mode, cb.checked);
  177. fn();
  178. }));
  179. }
  180. else
  181. {
  182. editorUi.setMode(mode, cb.checked);
  183. fn();
  184. }
  185. });
  186. };
  187. // Supports lazy loading
  188. if (clientName != null && editorUi[clientName] == null)
  189. {
  190. logo.style.visibility = 'hidden';
  191. mxUtils.setOpacity(label, 10);
  192. var size = 12;
  193. var spinner = new Spinner({
  194. lines: 12, // The number of lines to draw
  195. length: size, // The length of each line
  196. width: 5, // The line thickness
  197. radius: 10, // The radius of the inner circle
  198. rotate: 0, // The rotation offset
  199. color: (uiTheme == 'dark') ? '#c0c0c0' : '#000', // #rgb or #rrggbb
  200. speed: 1.5, // Rounds per second
  201. trail: 60, // Afterglow percentage
  202. shadow: false, // Whether to render a shadow
  203. hwaccel: false, // Whether to use hardware acceleration
  204. top: '40%',
  205. zIndex: 2e9 // The z-index (defaults to 2000000000)
  206. });
  207. spinner.spin(button);
  208. // Timeout after 30 secs
  209. var timeout = window.setTimeout(function()
  210. {
  211. if (editorUi[clientName] == null)
  212. {
  213. spinner.stop();
  214. button.style.display = 'none';
  215. }
  216. }, 30000);
  217. editorUi.addListener('clientLoaded', mxUtils.bind(this, function(sender, evt)
  218. {
  219. if (editorUi[clientName] != null && evt.getProperty('client') == editorUi[clientName])
  220. {
  221. window.clearTimeout(timeout);
  222. mxUtils.setOpacity(label, 100);
  223. logo.style.visibility = '';
  224. spinner.stop();
  225. initButton();
  226. if (clientName == 'drive' && p3.parentNode != null)
  227. {
  228. p3.parentNode.removeChild(p3);
  229. }
  230. }
  231. }));
  232. }
  233. else
  234. {
  235. initButton();
  236. }
  237. buttons.appendChild(button);
  238. if (++count >= rowLimit)
  239. {
  240. mxUtils.br(buttons);
  241. count = 0;
  242. }
  243. };
  244. var hd = document.createElement('p');
  245. hd.style.fontSize = '16pt';
  246. hd.style.padding = '0px';
  247. hd.style.paddingTop = '4px';
  248. hd.style.paddingBottom = '16px';
  249. hd.style.margin = '0px';
  250. hd.style.color = 'gray';
  251. mxUtils.write(hd, mxResources.get('saveDiagramsTo') + ':');
  252. div.appendChild(hd);
  253. if (typeof window.DriveClient === 'function')
  254. {
  255. addLogo(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googleDrive'), App.MODE_GOOGLE, 'drive');
  256. }
  257. if (typeof window.OneDriveClient === 'function')
  258. {
  259. addLogo(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), App.MODE_ONEDRIVE, 'oneDrive');
  260. }
  261. addLogo(IMAGE_PATH + '/osa_drive-harddisk.png', mxResources.get('device'), App.MODE_DEVICE);
  262. if (isLocalStorage && (urlParams['browser'] == '1' || urlParams['offline'] == '1'))
  263. {
  264. addLogo(IMAGE_PATH + '/osa_database.png', mxResources.get('browser'), App.MODE_BROWSER);
  265. }
  266. div.appendChild(buttons);
  267. var p2 = document.createElement('p');
  268. p2.style.marginTop = '12px';
  269. p2.style.marginBottom = '6px';
  270. p2.appendChild(cb);
  271. var span = document.createElement('span');
  272. span.style.color = 'gray';
  273. span.style.fontSize = '12px';
  274. mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
  275. p2.appendChild(span);
  276. mxUtils.br(p2);
  277. var recent = editorUi.getRecent();
  278. if (recent != null && recent.length > 0)
  279. {
  280. var recentSelect = document.createElement('select');
  281. recentSelect.style.marginTop = '8px';
  282. recentSelect.style.width = '140px';
  283. var titleOption = document.createElement('option');
  284. titleOption.setAttribute('value', '');
  285. titleOption.setAttribute('selected', 'selected');
  286. titleOption.style.textAlign = 'center';
  287. mxUtils.write(titleOption, mxResources.get('openRecent') + '...');
  288. recentSelect.appendChild(titleOption);
  289. for (var i = 0; i < recent.length; i++)
  290. {
  291. (function(entry)
  292. {
  293. var modeKey = entry.mode;
  294. // Google and oneDrive use different keys
  295. if (modeKey == App.MODE_GOOGLE)
  296. {
  297. modeKey = 'googleDrive';
  298. }
  299. else if (modeKey == App.MODE_ONEDRIVE)
  300. {
  301. modeKey = 'oneDrive';
  302. }
  303. var entryOption = document.createElement('option');
  304. entryOption.setAttribute('value', entry.id);
  305. mxUtils.write(entryOption, entry.title + ' (' + mxResources.get(modeKey) + ')');
  306. recentSelect.appendChild(entryOption);
  307. })(recent[i]);
  308. }
  309. p2.appendChild(recentSelect);
  310. mxEvent.addListener(recentSelect, 'change', function(evt)
  311. {
  312. if (recentSelect.value != '')
  313. {
  314. editorUi.loadFile(recentSelect.value);
  315. }
  316. });
  317. }
  318. else
  319. {
  320. p2.style.marginTop = '20px';
  321. buttons.style.padding = '30px 0px 26px 0px';
  322. }
  323. if (Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
  324. {
  325. var link = document.createElement('div');
  326. link.style.cursor = 'pointer';
  327. link.style.padding = '18px 0px 6px 0px';
  328. link.style.fontSize = '12px';
  329. link.style.color = 'gray';
  330. mxUtils.write(link, mxResources.get('import') + ': ' + mxResources.get('gliffy') + ', ' +
  331. mxResources.get('formatVssx') + ', ' + mxResources.get('formatVsdx') + ', ' +
  332. mxResources.get('lucidchart') + '...');
  333. mxEvent.addListener(link, 'click', function()
  334. {
  335. var input = document.createElement('input');
  336. input.setAttribute('type', 'file');
  337. mxEvent.addListener(input, 'change', function()
  338. {
  339. if (input.files != null)
  340. {
  341. // Using null for position will disable crop of input file
  342. editorUi.hideDialog();
  343. editorUi.openFiles(input.files, true);
  344. }
  345. });
  346. input.click();
  347. });
  348. p2.appendChild(link);
  349. buttons.style.paddingBottom = '4px';
  350. }
  351. buttons.appendChild(p2);
  352. mxEvent.addListener(span, 'click', function(evt)
  353. {
  354. cb.checked = !cb.checked;
  355. mxEvent.consume(evt);
  356. });
  357. // Checks if Google Drive is missing after a 5 sec delay
  358. if (mxClient.IS_SVG && isLocalStorage && urlParams['gapi'] != '0' &&
  359. (document.documentMode == null || document.documentMode >= 10))
  360. {
  361. window.setTimeout(function()
  362. {
  363. if (editorUi.drive == null)
  364. {
  365. // To check for Disconnect plugin in chrome use mxClient.IS_GC and check for URL:
  366. // chrome-extension://jeoacafpbcihiomhlakheieifhpjdfeo/scripts/vendor/jquery/jquery-2.0.3.min.map
  367. p3.style.padding = '8px';
  368. p3.style.fontSize = '9pt';
  369. p3.style.marginTop = '-14px';
  370. p3.innerHTML = '<a style="background-color:#dcdcdc;padding:5px;color:black;text-decoration:none;" ' +
  371. 'href="https://plus.google.com/u/0/+DrawIo1/posts/1HTrfsb5wDN" target="_blank">' +
  372. '<img border="0" src="' + mxGraph.prototype.warningImage.src + '" align="top"> ' +
  373. mxResources.get('googleDriveMissingClickHere') + '</a>';
  374. div.appendChild(p3);
  375. }
  376. }, 5000);
  377. }
  378. this.container = div;
  379. };
  380. /**
  381. * Constructs a dialog for creating new files from templates.
  382. */
  383. var SplashDialog = function(editorUi)
  384. {
  385. var div = document.createElement('div');
  386. div.style.textAlign = 'center';
  387. var elt = editorUi.addLanguageMenu(div, true);
  388. if (elt != null)
  389. {
  390. elt.style.bottom = '19px';
  391. }
  392. var help = null;
  393. var serviceCount = editorUi.getServiceCount();
  394. if (!editorUi.isOffline() && serviceCount > 1)
  395. {
  396. help = document.createElement('a');
  397. help.setAttribute('href', 'https://about.draw.io/support/');
  398. help.setAttribute('title', mxResources.get('help'));
  399. help.setAttribute('target', '_blank');
  400. help.style.position = 'absolute';
  401. help.style.fontSize = '12px';
  402. help.style.textDecoration = 'none';
  403. help.style.cursor = 'pointer';
  404. help.style.bottom = '22px';
  405. help.style.left = '26px';
  406. help.style.color = 'gray';
  407. var icon = document.createElement('img');
  408. mxUtils.setOpacity(icon, 50);
  409. icon.style.height = '16px';
  410. icon.style.width = '16px';
  411. icon.setAttribute('border', '0');
  412. icon.setAttribute('valign', 'bottom');
  413. icon.setAttribute('src', Editor.helpImage);
  414. icon.style.marginRight = '2px';
  415. help.appendChild(icon);
  416. mxUtils.write(help, mxResources.get('help'));
  417. div.appendChild(help);
  418. }
  419. var hd = document.createElement('p');
  420. hd.style.fontSize = '16pt';
  421. hd.style.padding = '0px';
  422. hd.style.paddingTop = '2px';
  423. hd.style.margin = '0px';
  424. hd.style.color = 'gray';
  425. var logo = document.createElement('img');
  426. logo.setAttribute('border', '0');
  427. logo.setAttribute('align', 'absmiddle');
  428. logo.style.width = '40px';
  429. logo.style.height = '40px';
  430. logo.style.marginRight = '12px';
  431. logo.style.paddingBottom = '4px';
  432. var service = '';
  433. if (editorUi.mode == App.MODE_GOOGLE)
  434. {
  435. logo.src = IMAGE_PATH + '/google-drive-logo.svg';
  436. service = mxResources.get('googleDrive');
  437. }
  438. else if (editorUi.mode == App.MODE_DROPBOX)
  439. {
  440. logo.src = IMAGE_PATH + '/dropbox-logo.svg';
  441. service = mxResources.get('dropbox');
  442. }
  443. else if (editorUi.mode == App.MODE_ONEDRIVE)
  444. {
  445. logo.src = IMAGE_PATH + '/onedrive-logo.svg';
  446. service = mxResources.get('oneDrive');
  447. }
  448. else if (editorUi.mode == App.MODE_GITHUB)
  449. {
  450. logo.src = IMAGE_PATH + '/github-logo.svg';
  451. service = mxResources.get('github');
  452. }
  453. else if (editorUi.mode == App.MODE_TRELLO)
  454. {
  455. logo.src = IMAGE_PATH + '/trello-logo.svg';
  456. service = mxResources.get('trello');
  457. }
  458. else if (editorUi.mode == App.MODE_BROWSER)
  459. {
  460. logo.src = IMAGE_PATH + '/osa_database.png';
  461. service = mxResources.get('browser');
  462. }
  463. else
  464. {
  465. logo.src = IMAGE_PATH + '/osa_drive-harddisk.png';
  466. service = mxResources.get('device');
  467. }
  468. var buttons = document.createElement('div');
  469. buttons.style.margin = '4px 0px 0px 0px';
  470. var btn = document.createElement('button');
  471. btn.className = 'geBigButton';
  472. btn.style.overflow = 'hidden';
  473. btn.style.width = '340px';
  474. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp)
  475. {
  476. hd.appendChild(logo);
  477. mxUtils.write(hd, service);
  478. div.appendChild(hd);
  479. buttons.style.border = '1px solid #d3d3d3';
  480. buttons.style.borderWidth = '1px 0px 1px 0px';
  481. buttons.style.padding = '18px 0px 24px 0px';
  482. btn.style.marginBottom = '8px';
  483. }
  484. else
  485. {
  486. buttons.style.padding = '42px 0px 56px 0px';
  487. btn.style.marginBottom = '12px';
  488. }
  489. if (mxClient.IS_QUIRKS)
  490. {
  491. buttons.style.whiteSpace = 'nowrap';
  492. buttons.style.cssFloat = 'left';
  493. }
  494. if (mxClient.IS_QUIRKS)
  495. {
  496. btn.style.width = '340px';
  497. }
  498. mxUtils.write(btn, mxResources.get('createNewDiagram'));
  499. mxEvent.addListener(btn, 'click', function()
  500. {
  501. editorUi.hideDialog();
  502. editorUi.actions.get('new').funct();
  503. });
  504. buttons.appendChild(btn);
  505. mxUtils.br(buttons);
  506. var btn = document.createElement('button');
  507. btn.className = 'geBigButton';
  508. btn.style.marginBottom = '22px';
  509. btn.style.overflow = 'hidden';
  510. btn.style.width = '340px';
  511. if (mxClient.IS_QUIRKS)
  512. {
  513. btn.style.width = '340px';
  514. }
  515. mxUtils.write(btn, mxResources.get('openExistingDiagram'));
  516. mxEvent.addListener(btn, 'click', function()
  517. {
  518. editorUi.actions.get('open').funct();
  519. });
  520. buttons.appendChild(btn);
  521. var storage = 'undefined';
  522. if (editorUi.mode == App.MODE_GOOGLE)
  523. {
  524. storage = mxResources.get('googleDrive');
  525. }
  526. else if (editorUi.mode == App.MODE_DROPBOX)
  527. {
  528. storage = mxResources.get('dropbox');
  529. }
  530. else if (editorUi.mode == App.MODE_ONEDRIVE)
  531. {
  532. storage = mxResources.get('oneDrive');
  533. }
  534. else if (editorUi.mode == App.MODE_GITHUB)
  535. {
  536. storage = mxResources.get('github');
  537. }
  538. else if (editorUi.mode == App.MODE_TRELLO)
  539. {
  540. storage = mxResources.get('trello');
  541. }
  542. else if (editorUi.mode == App.MODE_DEVICE)
  543. {
  544. storage = mxResources.get('device');
  545. }
  546. else if (editorUi.mode == App.MODE_BROWSER)
  547. {
  548. storage = mxResources.get('browser');
  549. }
  550. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp)
  551. {
  552. var driveUser = (editorUi.drive != null) ? editorUi.drive.getUser() : null;
  553. function addLogout(logout)
  554. {
  555. btn.style.marginBottom = '24px';
  556. var link = document.createElement('a');
  557. link.setAttribute('href', 'javascript:void(0)');
  558. link.style.display = 'inline-block';
  559. link.style.marginTop = '6px';
  560. mxUtils.write(link, mxResources.get('signOut'));
  561. // Makes room after last big buttons
  562. btn.style.marginBottom = '16px';
  563. buttons.style.paddingBottom = '18px';
  564. mxEvent.addListener(link, 'click', function()
  565. {
  566. editorUi.confirm(mxResources.get('areYouSure'), function()
  567. {
  568. logout();
  569. });
  570. });
  571. buttons.appendChild(link);
  572. };
  573. if (editorUi.mode == App.MODE_GOOGLE && driveUser != null)
  574. {
  575. btn.style.marginBottom = '24px';
  576. var link = document.createElement('a');
  577. link.setAttribute('href', 'javascript:void(0)');
  578. link.style.display = 'inline-block';
  579. link.style.marginTop = '6px';
  580. mxUtils.write(link, mxResources.get('changeUser') + ' (' + driveUser.displayName + ')');
  581. // Makes room after last big buttons
  582. btn.style.marginBottom = '16px';
  583. buttons.style.paddingBottom = '18px';
  584. mxEvent.addListener(link, 'click', function()
  585. {
  586. editorUi.hideDialog();
  587. editorUi.drive.clearUserId();
  588. editorUi.drive.setUser(null);
  589. gapi.auth.signOut();
  590. // Restores current dialog after clearing user
  591. editorUi.setMode(App.MODE_GOOGLE);
  592. editorUi.hideDialog();
  593. editorUi.showSplash();
  594. // FIXME: Does not force showing the auth dialog if only one user is logged in
  595. editorUi.drive.authorize(false, mxUtils.bind(this, mxUtils.bind(this, function()
  596. {
  597. editorUi.hideDialog();
  598. editorUi.showSplash();
  599. })), mxUtils.bind(this, function(resp)
  600. {
  601. editorUi.handleError(resp, null, function()
  602. {
  603. editorUi.hideDialog();
  604. editorUi.showSplash();
  605. });
  606. }));
  607. });
  608. buttons.appendChild(link);
  609. }
  610. else if (editorUi.mode == App.MODE_ONEDRIVE && editorUi.oneDrive != null)
  611. {
  612. addLogout(function()
  613. {
  614. editorUi.oneDrive.logout();
  615. });
  616. }
  617. else if (editorUi.mode == App.MODE_GITHUB && editorUi.gitHub != null)
  618. {
  619. addLogout(function()
  620. {
  621. editorUi.gitHub.logout();
  622. editorUi.openLink('https://www.github.com/logout');
  623. });
  624. }
  625. else if (editorUi.mode == App.MODE_TRELLO && editorUi.trello != null)
  626. {
  627. if (editorUi.trello.isAuthorized())
  628. {
  629. addLogout(function()
  630. {
  631. editorUi.trello.logout();
  632. });
  633. }
  634. }
  635. else if (editorUi.mode == App.MODE_DROPBOX && editorUi.dropbox != null)
  636. {
  637. // NOTE: Dropbox has a logout option in the picker
  638. addLogout(function()
  639. {
  640. editorUi.dropbox.logout();
  641. editorUi.openLink('https://www.dropbox.com/logout');
  642. });
  643. }
  644. mxUtils.br(buttons);
  645. var link = document.createElement('a');
  646. link.setAttribute('href', 'javascript:void(0)');
  647. link.style.display = 'inline-block';
  648. link.style.marginTop = '8px';
  649. mxUtils.write(link, mxResources.get('changeStorage'));
  650. mxEvent.addListener(link, 'click', function()
  651. {
  652. editorUi.hideDialog(false);
  653. editorUi.setMode(null);
  654. editorUi.clearMode();
  655. editorUi.showSplash(true);
  656. });
  657. buttons.appendChild(link);
  658. }
  659. div.appendChild(buttons);
  660. this.container = div;
  661. };
  662. /**
  663. *
  664. */
  665. var ConfirmDialog = function(editorUi, message, okFn, cancelFn, okLabel, cancelLabel, okImg, cancelImg, showRememberOption, imgSrc)
  666. {
  667. var div = document.createElement('div');
  668. div.style.textAlign = 'center';
  669. var p2 = document.createElement('div');
  670. p2.style.padding = '6px';
  671. p2.style.overflow = 'auto';
  672. p2.style.maxHeight = '44px';
  673. p2.style.lineHeight = '1.2em';
  674. if (mxClient.IS_QUIRKS)
  675. {
  676. p2.style.height = '60px';
  677. }
  678. mxUtils.write(p2, message);
  679. div.appendChild(p2);
  680. if (imgSrc != null)
  681. {
  682. var p3 = document.createElement('div');
  683. p3.style.padding = '6px 0 6px 0';
  684. var img = document.createElement('img');
  685. img.setAttribute('src', imgSrc);
  686. p3.appendChild(img);
  687. div.appendChild(p3);
  688. }
  689. var btns = document.createElement('div');
  690. btns.style.textAlign = 'center';
  691. btns.style.whiteSpace = 'nowrap';
  692. var cb = document.createElement('input');
  693. cb.setAttribute('type', 'checkbox');
  694. var cancelBtn = mxUtils.button(cancelLabel || mxResources.get('cancel'), function()
  695. {
  696. editorUi.hideDialog();
  697. if (cancelFn != null)
  698. {
  699. cancelFn(cb.checked);
  700. }
  701. });
  702. cancelBtn.className = 'geBtn';
  703. if (cancelImg != null)
  704. {
  705. cancelBtn.innerHTML = cancelImg + '<br>' + cancelBtn.innerHTML;
  706. cancelBtn.style.paddingBottom = '8px';
  707. cancelBtn.style.paddingTop = '8px';
  708. cancelBtn.style.height = 'auto';
  709. cancelBtn.style.width = '40%';
  710. }
  711. if (editorUi.editor.cancelFirst)
  712. {
  713. btns.appendChild(cancelBtn);
  714. }
  715. var okBtn = mxUtils.button(okLabel || mxResources.get('ok'), function()
  716. {
  717. editorUi.hideDialog();
  718. if (okFn != null)
  719. {
  720. okFn(cb.checked);
  721. }
  722. });
  723. btns.appendChild(okBtn);
  724. if (okImg != null)
  725. {
  726. okBtn.innerHTML = okImg + '<br>' + okBtn.innerHTML + '<br>';
  727. okBtn.style.paddingBottom = '8px';
  728. okBtn.style.paddingTop = '8px';
  729. okBtn.style.height = 'auto';
  730. okBtn.className = 'geBtn';
  731. okBtn.style.width = '40%';
  732. }
  733. else
  734. {
  735. okBtn.className = 'geBtn gePrimaryBtn';
  736. }
  737. if (!editorUi.editor.cancelFirst)
  738. {
  739. btns.appendChild(cancelBtn);
  740. }
  741. div.appendChild(btns);
  742. if (showRememberOption)
  743. {
  744. btns.style.marginTop = '10px';
  745. var p2 = document.createElement('p');
  746. p2.style.marginTop = '20px';
  747. p2.appendChild(cb);
  748. var span = document.createElement('span');
  749. mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
  750. p2.appendChild(span);
  751. div.appendChild(p2);
  752. mxEvent.addListener(span, 'click', function(evt)
  753. {
  754. cb.checked = !cb.checked;
  755. mxEvent.consume(evt);
  756. });
  757. }
  758. else
  759. {
  760. btns.style.marginTop = '12px';
  761. }
  762. this.init = function()
  763. {
  764. okBtn.focus();
  765. };
  766. this.container = div;
  767. };
  768. /**
  769. * Constructs a new embed dialog
  770. */
  771. var EmbedDialog = function(editorUi, result, timeout, ignoreSize, previewFn, title)
  772. {
  773. var div = document.createElement('div');
  774. var maxSize = 500000;
  775. var maxFbSize = 51200;
  776. var maxTwitterSize = 7168;
  777. // Checks if result is a link
  778. var validUrl = /^https?:\/\//.test(result) || /^mailto:\/\//.test(result);
  779. if (title != null)
  780. {
  781. mxUtils.write(div, title);
  782. }
  783. else
  784. {
  785. mxUtils.write(div, mxResources.get((result.length < maxSize) ?
  786. ((validUrl) ? 'link' : 'mainEmbedNotice') : 'preview') + ':');
  787. }
  788. mxUtils.br(div);
  789. var size = document.createElement('div');
  790. size.style.position = 'absolute';
  791. size.style.top = '30px';
  792. size.style.right = '30px';
  793. size.style.color = 'gray';
  794. mxUtils.write(size, editorUi.formatFileSize(result.length));
  795. div.appendChild(size);
  796. // Using DIV for faster rendering
  797. var text = document.createElement('textarea');
  798. text.setAttribute('autocomplete', 'off');
  799. text.setAttribute('autocorrect', 'off');
  800. text.setAttribute('autocapitalize', 'off');
  801. text.setAttribute('spellcheck', 'false');
  802. text.style.marginTop = '10px';
  803. text.style.resize = 'none';
  804. text.style.height = '150px';
  805. text.style.width = '440px';
  806. text.style.border = '1px solid gray';
  807. text.value = mxResources.get('updatingDocument');
  808. div.appendChild(text);
  809. mxUtils.br(div);
  810. this.init = function()
  811. {
  812. window.setTimeout(function()
  813. {
  814. if (result.length < maxSize)
  815. {
  816. text.value = result;
  817. text.focus();
  818. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  819. {
  820. text.select();
  821. }
  822. else
  823. {
  824. document.execCommand('selectAll', false, null);
  825. }
  826. }
  827. else
  828. {
  829. text.setAttribute('readonly', 'true');
  830. text.value = result.substring(0, 340) + '... (' + mxResources.get('drawingTooLarge') + ')';
  831. }
  832. }, 0);
  833. };
  834. var buttons = document.createElement('div');
  835. buttons.style.position = 'absolute';
  836. buttons.style.bottom = '36px';
  837. buttons.style.right = '32px';
  838. var previewBtn = null;
  839. // Loads forever in IE9
  840. if (EmbedDialog.showPreviewOption && (!mxClient.IS_CHROMEAPP || validUrl) && !navigator.standalone && (validUrl ||
  841. (mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9))))
  842. {
  843. previewBtn = mxUtils.button(mxResources.get((result.length < maxSize) ? 'preview' : 'openInNewWindow'), function()
  844. {
  845. var value = (result.length < maxSize) ? text.value : result;
  846. if (previewFn != null)
  847. {
  848. previewFn(value);
  849. }
  850. else
  851. {
  852. if (validUrl)
  853. {
  854. try
  855. {
  856. var win = editorUi.openLink(value);
  857. if (win != null && (timeout == null || timeout > 0))
  858. {
  859. window.setTimeout(mxUtils.bind(this, function()
  860. {
  861. if (win != null && win.location.href != null &&
  862. win.location.href.substring(0, 8) != value.substring(0, 8))
  863. {
  864. win.close();
  865. editorUi.handleError({message: mxResources.get('drawingTooLarge')});
  866. }
  867. }), timeout || 500);
  868. }
  869. }
  870. catch (e)
  871. {
  872. editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
  873. }
  874. }
  875. else
  876. {
  877. var wnd = window.open();
  878. var doc = (wnd != null) ? wnd.document : null;
  879. if (doc != null)
  880. {
  881. doc.writeln('<html><head><title>' + encodeURIComponent(mxResources.get('preview')) +
  882. '</title><meta charset="utf-8"></head>' +
  883. '<body>' + result + '</body></html>');
  884. doc.close();
  885. }
  886. else
  887. {
  888. editorUi.handleError({message: mxResources.get('errorUpdatingPreview')});
  889. }
  890. }
  891. }
  892. });
  893. previewBtn.className = 'geBtn';
  894. buttons.appendChild(previewBtn);
  895. }
  896. if (!validUrl || result.length > 7500)
  897. {
  898. var downloadBtn = mxUtils.button(mxResources.get('download'), function()
  899. {
  900. editorUi.hideDialog();
  901. editorUi.saveData('embed.txt', 'txt', result, 'text/plain');
  902. });
  903. downloadBtn.className = 'geBtn';
  904. buttons.appendChild(downloadBtn);
  905. }
  906. // Twitter-intent does not allow more characters, must be pasted manually
  907. if (validUrl && (!editorUi.isOffline() || mxClient.IS_CHROMEAPP))
  908. {
  909. if (result.length < maxFbSize)
  910. {
  911. var fbBtn = mxUtils.button('', function()
  912. {
  913. try
  914. {
  915. var url = 'https://www.facebook.com/sharer.php?p[url]=' +
  916. encodeURIComponent(text.value);
  917. editorUi.openLink(url);
  918. }
  919. catch (e)
  920. {
  921. editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
  922. }
  923. });
  924. var img = document.createElement('img');
  925. img.setAttribute('src', Editor.facebookImage);
  926. img.setAttribute('width', '18');
  927. img.setAttribute('height', '18');
  928. img.setAttribute('border', '0');
  929. fbBtn.appendChild(img);
  930. fbBtn.setAttribute('title', mxResources.get('facebook') + ' (' +
  931. editorUi.formatFileSize(maxFbSize) + ' max)');
  932. fbBtn.style.verticalAlign = 'bottom';
  933. fbBtn.style.paddingTop = '4px';
  934. fbBtn.style.minWidth = '46px'
  935. fbBtn.className = 'geBtn';
  936. buttons.appendChild(fbBtn);
  937. }
  938. if (result.length < maxTwitterSize)
  939. {
  940. var tweetBtn = mxUtils.button('', function()
  941. {
  942. try
  943. {
  944. var url = 'https://twitter.com/intent/tweet?text=' +
  945. encodeURIComponent('Check out the diagram I made using @drawio') +
  946. '&url=' + encodeURIComponent(text.value);
  947. editorUi.openLink(url);
  948. }
  949. catch (e)
  950. {
  951. editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
  952. }
  953. });
  954. var img = document.createElement('img');
  955. img.setAttribute('src', Editor.tweetImage);
  956. img.setAttribute('width', '18');
  957. img.setAttribute('height', '18');
  958. img.setAttribute('border', '0');
  959. img.style.marginBottom = '5px'
  960. tweetBtn.appendChild(img);
  961. tweetBtn.setAttribute('title', mxResources.get('twitter') + ' (' +
  962. editorUi.formatFileSize(maxTwitterSize) + ' max)');
  963. tweetBtn.style.verticalAlign = 'bottom';
  964. tweetBtn.style.paddingTop = '4px';
  965. tweetBtn.style.minWidth = '46px'
  966. tweetBtn.className = 'geBtn';
  967. buttons.appendChild(tweetBtn);
  968. }
  969. }
  970. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  971. {
  972. editorUi.hideDialog();
  973. });
  974. buttons.appendChild(closeBtn);
  975. var copyBtn = mxUtils.button(mxResources.get('copy'), function()
  976. {
  977. text.focus();
  978. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  979. {
  980. text.select();
  981. }
  982. else
  983. {
  984. document.execCommand('selectAll', false, null);
  985. }
  986. document.execCommand('copy');
  987. editorUi.alert(mxResources.get('copiedToClipboard'));
  988. });
  989. if (result.length < maxSize)
  990. {
  991. // Does not work in Safari and shows annoying dialog for IE11-
  992. if (!mxClient.IS_SF && document.documentMode == null)
  993. {
  994. buttons.appendChild(copyBtn);
  995. copyBtn.className = 'geBtn gePrimaryBtn';
  996. closeBtn.className = 'geBtn';
  997. }
  998. else
  999. {
  1000. closeBtn.className = 'geBtn gePrimaryBtn';
  1001. }
  1002. }
  1003. else
  1004. {
  1005. buttons.appendChild(previewBtn);
  1006. closeBtn.className = 'geBtn';
  1007. previewBtn.className = 'geBtn gePrimaryBtn';
  1008. }
  1009. div.appendChild(buttons);
  1010. this.container = div;
  1011. };
  1012. /**
  1013. * Add embed dialog option.
  1014. */
  1015. EmbedDialog.showPreviewOption = true;
  1016. /**
  1017. * Constructs a dialog for embedding the diagram in Google Sites.
  1018. */
  1019. var GoogleSitesDialog = function(editorUi, publicUrl)
  1020. {
  1021. var div = document.createElement('div');
  1022. var graph = editorUi.editor.graph;
  1023. var bounds = graph.getGraphBounds();
  1024. var scale = graph.view.scale;
  1025. var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
  1026. var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
  1027. mxUtils.write(div, mxResources.get('googleGadget') + ':');
  1028. mxUtils.br(div);
  1029. var gadgetInput = document.createElement('input');
  1030. gadgetInput.setAttribute('type', 'text');
  1031. gadgetInput.style.marginBottom = '8px';
  1032. gadgetInput.style.marginTop = '2px';
  1033. gadgetInput.style.width = '410px';
  1034. div.appendChild(gadgetInput);
  1035. mxUtils.br(div);
  1036. this.init = function()
  1037. {
  1038. gadgetInput.focus();
  1039. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1040. {
  1041. gadgetInput.select();
  1042. }
  1043. else
  1044. {
  1045. document.execCommand('selectAll', false, null);
  1046. }
  1047. };
  1048. mxUtils.write(div, mxResources.get('top') + ':');
  1049. var topInput = document.createElement('input');
  1050. topInput.setAttribute('type', 'text');
  1051. topInput.setAttribute('size', '4');
  1052. topInput.style.marginRight = '16px';
  1053. topInput.style.marginLeft = '4px';
  1054. topInput.value = x0;
  1055. div.appendChild(topInput);
  1056. mxUtils.write(div, mxResources.get('height') + ':');
  1057. var heightInput = document.createElement('input');
  1058. heightInput.setAttribute('type', 'text');
  1059. heightInput.setAttribute('size', '4');
  1060. heightInput.style.marginLeft = '4px';
  1061. heightInput.value = Math.ceil(bounds.height / scale);
  1062. div.appendChild(heightInput);
  1063. mxUtils.br(div);
  1064. var hr = document.createElement('hr');
  1065. hr.setAttribute('size', '1');
  1066. hr.style.marginBottom = '16px';
  1067. hr.style.marginTop = '16px';
  1068. div.appendChild(hr);
  1069. mxUtils.write(div, mxResources.get('publicDiagramUrl') + ':');
  1070. mxUtils.br(div);
  1071. var urlInput = document.createElement('input');
  1072. urlInput.setAttribute('type', 'text');
  1073. urlInput.setAttribute('size', '28');
  1074. urlInput.style.marginBottom = '8px';
  1075. urlInput.style.marginTop = '2px';
  1076. urlInput.style.width = '410px';
  1077. urlInput.value = publicUrl || '';
  1078. div.appendChild(urlInput);
  1079. mxUtils.br(div);
  1080. mxUtils.write(div, mxResources.get('borderWidth') + ':');
  1081. var borderInput = document.createElement('input');
  1082. borderInput.setAttribute('type', 'text');
  1083. borderInput.setAttribute('size', '3');
  1084. borderInput.style.marginBottom = '8px';
  1085. borderInput.style.marginLeft = '4px';
  1086. borderInput.value = '0';
  1087. div.appendChild(borderInput);
  1088. mxUtils.br(div);
  1089. var panCheckBox = document.createElement('input');
  1090. panCheckBox.setAttribute('type', 'checkbox');
  1091. panCheckBox.setAttribute('checked', 'checked');
  1092. panCheckBox.defaultChecked = true;
  1093. panCheckBox.style.marginLeft = '16px';
  1094. div.appendChild(panCheckBox);
  1095. mxUtils.write(div, mxResources.get('pan') + ' ');
  1096. var zoomCheckBox = document.createElement('input');
  1097. zoomCheckBox.setAttribute('type', 'checkbox');
  1098. zoomCheckBox.setAttribute('checked', 'checked');
  1099. zoomCheckBox.defaultChecked = true;
  1100. zoomCheckBox.style.marginLeft = '8px';
  1101. div.appendChild(zoomCheckBox);
  1102. mxUtils.write(div, mxResources.get('zoom') + ' ');
  1103. var editCheckBox = document.createElement('input');
  1104. editCheckBox.setAttribute('type', 'checkbox');
  1105. editCheckBox.style.marginLeft = '8px';
  1106. editCheckBox.setAttribute('title', window.location.href);
  1107. div.appendChild(editCheckBox);
  1108. mxUtils.write(div, mxResources.get('edit') + ' ');
  1109. var editBlankCheckBox = document.createElement('input');
  1110. editBlankCheckBox.setAttribute('type', 'checkbox');
  1111. editBlankCheckBox.style.marginLeft = '8px';
  1112. div.appendChild(editBlankCheckBox);
  1113. mxUtils.write(div, mxResources.get('asNew') + ' ');
  1114. mxUtils.br(div);
  1115. var resizeCheckBox = document.createElement('input');
  1116. resizeCheckBox.setAttribute('type', 'checkbox');
  1117. resizeCheckBox.setAttribute('checked', 'checked');
  1118. resizeCheckBox.defaultChecked = true;
  1119. resizeCheckBox.style.marginLeft = '16px';
  1120. div.appendChild(resizeCheckBox);
  1121. mxUtils.write(div, mxResources.get('resize') + ' ');
  1122. var fitCheckBox = document.createElement('input');
  1123. fitCheckBox.setAttribute('type', 'checkbox');
  1124. fitCheckBox.style.marginLeft = '8px';
  1125. div.appendChild(fitCheckBox);
  1126. mxUtils.write(div, mxResources.get('fit') + ' ');
  1127. var embedCheckBox = document.createElement('input');
  1128. embedCheckBox.setAttribute('type', 'checkbox');
  1129. embedCheckBox.style.marginLeft = '8px';
  1130. div.appendChild(embedCheckBox);
  1131. mxUtils.write(div, mxResources.get('embed') + ' ');
  1132. var node = null;
  1133. var s = editorUi.getBasenames().join(';');
  1134. var file = editorUi.getCurrentFile();
  1135. function update()
  1136. {
  1137. var title = (file != null && file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1138. if (embedCheckBox.checked && urlInput.value != '')
  1139. {
  1140. var encUrl = encodeURIComponent(mxUtils.htmlEntities(urlInput.value));
  1141. var gurl = 'https://www.draw.io/gadget.xml?type=4&diagram=' + encUrl;
  1142. if (title != null)
  1143. {
  1144. gurl += '&title=' + encodeURIComponent(title);
  1145. }
  1146. if (s.length > 0)
  1147. {
  1148. gurl += '&s=' + s;
  1149. }
  1150. if (borderInput.value != '' && borderInput.value != '0')
  1151. {
  1152. gurl += '&border=' + borderInput.value;
  1153. }
  1154. if (heightInput.value != '')
  1155. {
  1156. gurl += '&height=' + heightInput.value;
  1157. }
  1158. gurl += '&pan=' + ((panCheckBox.checked) ? '1': '0');
  1159. gurl += '&zoom=' + ((zoomCheckBox.checked) ? '1': '0');
  1160. gurl += '&fit=' + ((fitCheckBox.checked) ? '1': '0');
  1161. gurl += '&resize=' + ((resizeCheckBox.checked) ? '1': '0');
  1162. gurl += '&x0=' + Number(topInput.value);
  1163. gurl += '&y0=' + y0;
  1164. if (graph.mathEnabled)
  1165. {
  1166. gurl += '&math=1';
  1167. }
  1168. if (editBlankCheckBox.checked)
  1169. {
  1170. gurl += '&edit=_blank';
  1171. }
  1172. else if (editCheckBox.checked)
  1173. {
  1174. gurl += '&edit=' + encodeURIComponent(mxUtils.htmlEntities(window.location.href));
  1175. }
  1176. gadgetInput.value = gurl;
  1177. }
  1178. else if (file.constructor == DriveFile || file.constructor == DropboxFile)
  1179. {
  1180. var gurl = 'https://www.draw.io/gadget.xml?embed=0&diagram=';
  1181. if (urlInput.value != '')
  1182. {
  1183. gurl += encodeURIComponent(mxUtils.htmlEntities(urlInput.value)) + '&type=3';
  1184. }
  1185. else
  1186. {
  1187. gurl += file.getHash().substring(1);
  1188. if (file.constructor == DropboxFile)
  1189. {
  1190. gurl += '&type=2';
  1191. }
  1192. else
  1193. {
  1194. gurl += '&type=1';
  1195. }
  1196. }
  1197. if (title != null)
  1198. {
  1199. gurl += '&title=' + encodeURIComponent(title);
  1200. }
  1201. if (heightInput.value != '')
  1202. {
  1203. var h = parseInt(heightInput.value) + parseInt(topInput.value);
  1204. gurl += '&height=' + h;
  1205. }
  1206. gadgetInput.value = gurl;
  1207. }
  1208. else
  1209. {
  1210. gadgetInput.value = '';
  1211. }
  1212. };
  1213. mxEvent.addListener(panCheckBox, 'change', update);
  1214. mxEvent.addListener(zoomCheckBox, 'change', update);
  1215. mxEvent.addListener(resizeCheckBox, 'change', update);
  1216. mxEvent.addListener(fitCheckBox, 'change', update);
  1217. mxEvent.addListener(editCheckBox, 'change', update);
  1218. mxEvent.addListener(editBlankCheckBox, 'change', update);
  1219. mxEvent.addListener(embedCheckBox, 'change', update);
  1220. mxEvent.addListener(heightInput, 'change', update);
  1221. mxEvent.addListener(topInput, 'change', update);
  1222. mxEvent.addListener(borderInput, 'change', update);
  1223. mxEvent.addListener(urlInput, 'change', update);
  1224. update();
  1225. mxEvent.addListener(gadgetInput, 'click', function()
  1226. {
  1227. gadgetInput.focus();
  1228. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1229. {
  1230. gadgetInput.select();
  1231. }
  1232. else
  1233. {
  1234. document.execCommand('selectAll', false, null);
  1235. }
  1236. });
  1237. var buttons = document.createElement('div');
  1238. buttons.style.paddingTop = '12px';
  1239. buttons.style.textAlign = 'right';
  1240. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  1241. {
  1242. editorUi.hideDialog();
  1243. });
  1244. closeBtn.className = 'geBtn gePrimaryBtn';
  1245. buttons.appendChild(closeBtn);
  1246. div.appendChild(buttons);
  1247. this.container = div;
  1248. };
  1249. /**
  1250. * Constructs a new parse dialog.
  1251. */
  1252. var CreateGraphDialog = function(editorUi, title, type)
  1253. {
  1254. var div = document.createElement('div');
  1255. div.style.textAlign = 'right';
  1256. this.init = function()
  1257. {
  1258. var container = document.createElement('div');
  1259. container.style.position = 'relative';
  1260. container.style.border = '1px solid gray';
  1261. container.style.width = '100%';
  1262. container.style.height = '360px';
  1263. container.style.overflow = 'hidden';
  1264. container.style.marginBottom = '16px';
  1265. mxEvent.disableContextMenu(container);
  1266. div.appendChild(container);
  1267. var graph = new Graph(container);
  1268. graph.setCellsCloneable(true);
  1269. graph.setPanning(true);
  1270. graph.setAllowDanglingEdges(false);
  1271. graph.connectionHandler.select = false;
  1272. graph.view.setTranslate(20, 20);
  1273. graph.border = 20;
  1274. graph.panningHandler.useLeftButtonForPanning = true;
  1275. var vertexStyle = 'rounded=1;';
  1276. var edgeStyle = 'curved=1;';
  1277. var startStyle = 'ellipse';
  1278. // FIXME: Does not work in iPad
  1279. var mxCellRendererInstallCellOverlayListeners = mxCellRenderer.prototype.installCellOverlayListeners;
  1280. graph.cellRenderer.installCellOverlayListeners = function(state, overlay, shape)
  1281. {
  1282. mxCellRenderer.prototype.installCellOverlayListeners.apply(this, arguments);
  1283. mxEvent.addListener(shape.node, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown', function (evt)
  1284. {
  1285. overlay.fireEvent(new mxEventObject('pointerdown', 'event', evt, 'state', state));
  1286. });
  1287. if (!mxClient.IS_POINTER && mxClient.IS_TOUCH)
  1288. {
  1289. mxEvent.addListener(shape.node, 'touchstart', function (evt)
  1290. {
  1291. overlay.fireEvent(new mxEventObject('pointerdown', 'event', evt, 'state', state));
  1292. });
  1293. }
  1294. };
  1295. graph.getAllConnectionConstraints = function()
  1296. {
  1297. return null;
  1298. };
  1299. // Keeps highlight behind overlays
  1300. graph.connectionHandler.marker.highlight.keepOnTop = false;
  1301. graph.connectionHandler.createEdgeState = function(me)
  1302. {
  1303. var edge = graph.createEdge(null, null, null, null, null, edgeStyle);
  1304. return new mxCellState(this.graph.view, edge, this.graph.getCellStyle(edge));
  1305. };
  1306. // Gets the default parent for inserting new cells. This
  1307. // is normally the first child of the root (ie. layer 0).
  1308. var parent = graph.getDefaultParent();
  1309. var addOverlay = mxUtils.bind(this, function(cell)
  1310. {
  1311. // Creates a new overlay with an image and a tooltip
  1312. var overlay = new mxCellOverlay(this.connectImage, 'Add outgoing');
  1313. overlay.cursor = 'hand';
  1314. // Installs a handler for clicks on the overlay
  1315. overlay.addListener(mxEvent.CLICK, function(sender, evt2)
  1316. {
  1317. // TODO: Add menu for picking next shape
  1318. graph.connectionHandler.reset();
  1319. graph.clearSelection();
  1320. var geo = graph.getCellGeometry(cell);
  1321. var v2;
  1322. executeLayout(function()
  1323. {
  1324. v2 = graph.insertVertex(parent, null, 'Entry', geo.x, geo.y, 80, 30, vertexStyle);
  1325. addOverlay(v2);
  1326. graph.view.refresh(v2);
  1327. var e1 = graph.insertEdge(parent, null, '', cell, v2, edgeStyle);
  1328. }, function()
  1329. {
  1330. graph.scrollCellToVisible(v2);
  1331. });
  1332. });
  1333. // FIXME: Does not work in iPad (inserts loop)
  1334. overlay.addListener('pointerdown', function(sender, eo)
  1335. {
  1336. var evt2 = eo.getProperty('event');
  1337. var state = eo.getProperty('state');
  1338. graph.popupMenuHandler.hideMenu();
  1339. graph.stopEditing(false);
  1340. var pt = mxUtils.convertPoint(graph.container,
  1341. mxEvent.getClientX(evt2), mxEvent.getClientY(evt2));
  1342. graph.connectionHandler.start(state, pt.x, pt.y);
  1343. graph.isMouseDown = true;
  1344. graph.isMouseTrigger = mxEvent.isMouseEvent(evt2);
  1345. mxEvent.consume(evt2);
  1346. });
  1347. // Sets the overlay for the cell in the graph
  1348. graph.addCellOverlay(cell, overlay);
  1349. });
  1350. // Adds cells to the model in a single step
  1351. graph.getModel().beginUpdate();
  1352. var v1;
  1353. try
  1354. {
  1355. v1 = graph.insertVertex(parent, null, 'Start', 0, 0, 80, 30, startStyle);
  1356. addOverlay(v1);
  1357. }
  1358. finally
  1359. {
  1360. // Updates the display
  1361. graph.getModel().endUpdate();
  1362. }
  1363. var layout;
  1364. if (type == 'horizontalTree')
  1365. {
  1366. layout = new mxCompactTreeLayout(graph);
  1367. layout.edgeRouting = false;
  1368. layout.levelDistance = 30;
  1369. edgeStyle = 'edgeStyle=elbowEdgeStyle;elbow=horizontal;';
  1370. }
  1371. else if (type == 'verticalTree')
  1372. {
  1373. layout = new mxCompactTreeLayout(graph, false);
  1374. layout.edgeRouting = false;
  1375. layout.levelDistance = 30;
  1376. edgeStyle = 'edgeStyle=elbowEdgeStyle;elbow=vertical;';
  1377. }
  1378. else if (type == 'radialTree')
  1379. {
  1380. layout = new mxRadialTreeLayout(graph, false);
  1381. layout.edgeRouting = false;
  1382. layout.levelDistance = 80;
  1383. }
  1384. else if (type == 'verticalFlow')
  1385. {
  1386. layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_NORTH);
  1387. }
  1388. else if (type == 'horizontalFlow')
  1389. {
  1390. layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_WEST);
  1391. }
  1392. else if (type == 'organic')
  1393. {
  1394. layout = new mxFastOrganicLayout(graph, false);
  1395. layout.forceConstant = 80;
  1396. }
  1397. else if (type == 'circle')
  1398. {
  1399. layout = new mxCircleLayout(graph);
  1400. }
  1401. if (layout != null)
  1402. {
  1403. var executeLayout = function(change, post)
  1404. {
  1405. graph.getModel().beginUpdate();
  1406. try
  1407. {
  1408. if (change != null)
  1409. {
  1410. change();
  1411. }
  1412. layout.execute(graph.getDefaultParent(), v1);
  1413. }
  1414. catch (e)
  1415. {
  1416. throw e;
  1417. }
  1418. finally
  1419. {
  1420. // New API for animating graph layout results asynchronously
  1421. var morph = new mxMorphing(graph);
  1422. morph.addListener(mxEvent.DONE, mxUtils.bind(this, function()
  1423. {
  1424. graph.getModel().endUpdate();
  1425. if (post != null)
  1426. {
  1427. post();
  1428. }
  1429. }));
  1430. morph.startAnimation();
  1431. }
  1432. };
  1433. var edgeHandleConnect = mxEdgeHandler.prototype.connect;
  1434. mxEdgeHandler.prototype.connect = function(edge, terminal, isSource, isClone, me)
  1435. {
  1436. edgeHandleConnect.apply(this, arguments);
  1437. executeLayout();
  1438. };
  1439. graph.resizeCell = function()
  1440. {
  1441. mxGraph.prototype.resizeCell.apply(this, arguments);
  1442. executeLayout();
  1443. };
  1444. graph.connectionHandler.addListener(mxEvent.CONNECT, function()
  1445. {
  1446. executeLayout();
  1447. });
  1448. }
  1449. var cancelBtn = mxUtils.button(mxResources.get('close'), function()
  1450. {
  1451. editorUi.confirm(mxResources.get('areYouSure'), function()
  1452. {
  1453. if (container.parentNode != null)
  1454. {
  1455. graph.destroy();
  1456. container.parentNode.removeChild(container);
  1457. }
  1458. editorUi.hideDialog();
  1459. });
  1460. })
  1461. cancelBtn.className = 'geBtn';
  1462. if (editorUi.editor.cancelFirst)
  1463. {
  1464. div.appendChild(cancelBtn);
  1465. }
  1466. var okBtn = mxUtils.button(mxResources.get('insert'), function()
  1467. {
  1468. graph.clearCellOverlays();
  1469. // Computes unscaled, untranslated graph bounds
  1470. var pt = editorUi.editor.graph.getFreeInsertPoint();
  1471. var cells = editorUi.editor.graph.importCells(
  1472. graph.getModel().getChildren(graph.getDefaultParent()), pt.x, pt.y);
  1473. var view = editorUi.editor.graph.view;
  1474. var temp = view.getBounds(cells);
  1475. temp.x -= view.translate.x;
  1476. temp.y -= view.translate.y;
  1477. editorUi.editor.graph.scrollRectToVisible(temp);
  1478. editorUi.editor.graph.setSelectionCells(cells);
  1479. if (container.parentNode != null)
  1480. {
  1481. graph.destroy();
  1482. container.parentNode.removeChild(container);
  1483. }
  1484. editorUi.hideDialog();
  1485. });
  1486. div.appendChild(okBtn);
  1487. okBtn.className = 'geBtn gePrimaryBtn';
  1488. if (!editorUi.editor.cancelFirst)
  1489. {
  1490. div.appendChild(cancelBtn);
  1491. }
  1492. };
  1493. this.container = div;
  1494. };
  1495. /**
  1496. *
  1497. */
  1498. 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==' :
  1499. IMAGE_PATH + '/handle-connect.png', 26, 26);
  1500. /**
  1501. * Constructs a new parse dialog.
  1502. */
  1503. var BackgroundImageDialog = function(editorUi, applyFn)
  1504. {
  1505. var div = document.createElement('div');
  1506. div.style.whiteSpace = 'nowrap';
  1507. var h3 = document.createElement('h2');
  1508. mxUtils.write(h3, mxResources.get('backgroundImage'));
  1509. h3.style.marginTop = '0px';
  1510. div.appendChild(h3);
  1511. mxUtils.write(div, mxResources.get('image') + ' ' + mxResources.get('url') + ':');
  1512. mxUtils.br(div);
  1513. var img = editorUi.editor.graph.backgroundImage;
  1514. var urlInput = document.createElement('input');
  1515. urlInput.setAttribute('type', 'text');
  1516. urlInput.style.marginTop = '4px';
  1517. urlInput.style.marginBottom = '4px';
  1518. urlInput.style.width = '350px';
  1519. urlInput.value = (img != null) ? img.src : '';
  1520. var resetting = false;
  1521. var urlChanged = function()
  1522. {
  1523. if (!resetting && urlInput.value != '' && !editorUi.isOffline())
  1524. {
  1525. editorUi.loadImage(mxUtils.trim(urlInput.value), function(img)
  1526. {
  1527. widthInput.value = img.width;
  1528. heightInput.value = img.height;
  1529. }, function()
  1530. {
  1531. editorUi.showError(mxResources.get('error'), mxResources.get('fileNotFound'), mxResources.get('ok'));
  1532. urlInput.value = '';
  1533. widthInput.value = '';
  1534. heightInput.value = '';
  1535. });
  1536. }
  1537. else
  1538. {
  1539. widthInput.value = '';
  1540. heightInput.value = '';
  1541. }
  1542. };
  1543. this.init = function()
  1544. {
  1545. urlInput.focus();
  1546. // Installs drag and drop handler for local images and links
  1547. if (Graph.fileSupport)
  1548. {
  1549. urlInput.setAttribute('placeholder', mxResources.get('dragImagesHere'));
  1550. // Setup the dnd listeners
  1551. var dlg = div.parentNode;
  1552. var graph = editorUi.editor.graph;
  1553. var dropElt = null;
  1554. mxEvent.addListener(dlg, 'dragleave', function(evt)
  1555. {
  1556. if (dropElt != null)
  1557. {
  1558. dropElt.parentNode.removeChild(dropElt);
  1559. dropElt = null;
  1560. }
  1561. evt.stopPropagation();
  1562. evt.preventDefault();
  1563. });
  1564. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  1565. {
  1566. // IE 10 does not implement pointer-events so it can't have a drop highlight
  1567. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  1568. {
  1569. dropElt = editorUi.highlightElement(dlg);
  1570. }
  1571. evt.stopPropagation();
  1572. evt.preventDefault();
  1573. }));
  1574. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  1575. {
  1576. if (dropElt != null)
  1577. {
  1578. dropElt.parentNode.removeChild(dropElt);
  1579. dropElt = null;
  1580. }
  1581. if (evt.dataTransfer.files.length > 0)
  1582. {
  1583. editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxBackgroundSize, function(data, mimeType, x, y, w, h)
  1584. {
  1585. urlInput.value = data;
  1586. urlChanged();
  1587. }, function()
  1588. {
  1589. // No post processing
  1590. }, function(file)
  1591. {
  1592. // Handles only images
  1593. return file.type.substring(0, 6) == 'image/';
  1594. }, function(queue)
  1595. {
  1596. // Invokes elements of queue in order
  1597. for (var i = 0; i < queue.length; i++)
  1598. {
  1599. queue[i]();
  1600. }
  1601. }, true, editorUi.maxBackgroundBytes, editorUi.maxBackgroundBytes);
  1602. }
  1603. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  1604. {
  1605. var uri = evt.dataTransfer.getData('text/uri-list');
  1606. if ((/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(uri))
  1607. {
  1608. urlInput.value = decodeURIComponent(uri);
  1609. urlChanged();
  1610. }
  1611. }
  1612. evt.stopPropagation();
  1613. evt.preventDefault();
  1614. }), false);
  1615. }
  1616. };
  1617. div.appendChild(urlInput);
  1618. mxUtils.br(div);
  1619. mxUtils.br(div);
  1620. mxUtils.write(div, mxResources.get('width') + ':');
  1621. var widthInput = document.createElement('input');
  1622. widthInput.setAttribute('type', 'text');
  1623. widthInput.style.width = '60px';
  1624. widthInput.style.marginLeft = '4px';
  1625. widthInput.style.marginRight = '16px';
  1626. widthInput.value = (img != null) ? img.width : '';
  1627. div.appendChild(widthInput);
  1628. mxUtils.write(div, mxResources.get('height') + ':');
  1629. var heightInput = document.createElement('input');
  1630. heightInput.setAttribute('type', 'text');
  1631. heightInput.style.width = '60px';
  1632. heightInput.style.marginLeft = '4px';
  1633. heightInput.style.marginRight = '16px';
  1634. heightInput.value = (img != null) ? img.height : '';
  1635. div.appendChild(heightInput);
  1636. var resetBtn = mxUtils.button(mxResources.get('reset'), function()
  1637. {
  1638. urlInput.value = '';
  1639. widthInput.value = '';
  1640. heightInput.value = '';
  1641. resetting = false;
  1642. });
  1643. mxEvent.addListener(resetBtn, 'mousedown', function()
  1644. {
  1645. // Blocks processing a image URL while clicking reset
  1646. resetting = true;
  1647. });
  1648. mxEvent.addListener(resetBtn, 'touchstart', function()
  1649. {
  1650. // Blocks processing a image URL while clicking reset
  1651. resetting = true;
  1652. });
  1653. resetBtn.className = 'geBtn';
  1654. resetBtn.width = '100';
  1655. div.appendChild(resetBtn);
  1656. mxUtils.br(div);
  1657. mxEvent.addListener(urlInput, 'change', urlChanged);
  1658. ImageDialog.filePicked = function(data)
  1659. {
  1660. if (data.action == google.picker.Action.PICKED)
  1661. {
  1662. if (data.docs[0].thumbnails != null)
  1663. {
  1664. var thumb = data.docs[0].thumbnails[data.docs[0].thumbnails.length - 1];
  1665. if (thumb != null)
  1666. {
  1667. urlInput.value = thumb.url;
  1668. urlChanged();
  1669. }
  1670. }
  1671. }
  1672. urlInput.focus();
  1673. };
  1674. var btns = document.createElement('div');
  1675. btns.style.marginTop = '40px';
  1676. btns.style.textAlign = 'right';
  1677. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1678. {
  1679. editorUi.hideDialog();
  1680. });
  1681. cancelBtn.className = 'geBtn';
  1682. if (editorUi.editor.cancelFirst)
  1683. {
  1684. btns.appendChild(cancelBtn);
  1685. }
  1686. if (!editorUi.isOffline())
  1687. {
  1688. // Dialogs not allowed inside iframes
  1689. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined' && window.self === window.top)
  1690. {
  1691. var searchBtn = mxUtils.button(mxResources.get('search'), function()
  1692. {
  1693. // Creates one picker and reuses it to avoid polluting the DOM
  1694. if (editorUi.imageSearchPicker == null)
  1695. {
  1696. var picker = new google.picker.PickerBuilder()
  1697. .setLocale(mxLanguage)
  1698. .addView(google.picker.ViewId.IMAGE_SEARCH)
  1699. .enableFeature(google.picker.Feature.NAV_HIDDEN);
  1700. editorUi.imageSearchPicker = picker.setCallback(function(data)
  1701. {
  1702. ImageDialog.filePicked(data);
  1703. }).build();
  1704. }
  1705. editorUi.imageSearchPicker.setVisible(true);
  1706. });
  1707. searchBtn.className = 'geBtn';
  1708. btns.appendChild(searchBtn);
  1709. if (editorUi.drive != null && urlParams['photos'] == '1')
  1710. {
  1711. var gpBtn = mxUtils.button(mxResources.get('googlePlus'), function()
  1712. {
  1713. if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  1714. {
  1715. editorUi.drive.checkToken(mxUtils.bind(this, function()
  1716. {
  1717. editorUi.spinner.stop();
  1718. // Creates one picker and reuses it to avoid polluting the DOM
  1719. if (editorUi.photoPicker == null)
  1720. {
  1721. var token = gapi.auth.getToken().access_token;
  1722. var picker = new google.picker.PickerBuilder()
  1723. .setAppId(editorUi.drive.appId)
  1724. .setLocale(mxLanguage)
  1725. .setOAuthToken(token)
  1726. .addView(google.picker.ViewId.PHOTOS)
  1727. .addView(google.picker.ViewId.PHOTO_ALBUMS)
  1728. .addView(google.picker.ViewId.PHOTO_UPLOAD);
  1729. editorUi.photoPicker = picker.setCallback(function(data)
  1730. {
  1731. ImageDialog.filePicked(data);
  1732. }).build();
  1733. }
  1734. editorUi.photoPicker.setVisible(true);
  1735. }));
  1736. }
  1737. });
  1738. gpBtn.className = 'geBtn';
  1739. btns.appendChild(gpBtn);
  1740. }
  1741. }
  1742. }
  1743. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  1744. {
  1745. editorUi.hideDialog();
  1746. applyFn((urlInput.value != '') ? new mxImage(mxUtils.trim(urlInput.value), widthInput.value, heightInput.value) : null);
  1747. });
  1748. applyBtn.className = 'geBtn gePrimaryBtn';
  1749. btns.appendChild(applyBtn);
  1750. if (!editorUi.editor.cancelFirst)
  1751. {
  1752. btns.appendChild(cancelBtn);
  1753. }
  1754. div.appendChild(btns);
  1755. this.container = div;
  1756. };
  1757. /**
  1758. * Constructs a new parse dialog.
  1759. */
  1760. var ParseDialog = function(editorUi, title, defaultType)
  1761. {
  1762. var insertPoint = editorUi.editor.graph.getFreeInsertPoint();
  1763. function parse(text, type)
  1764. {
  1765. var lines = text.split('\n');
  1766. if (type == 'plantUmlPng' || type == 'plantUmlSvg' || type == 'plantUmlTxt')
  1767. {
  1768. var plantUmlServerUrl = (type == 'plantUmlTxt') ? PLANT_URL + '/txt/' :
  1769. ((type == 'plantUmlPng') ? PLANT_URL + '/png/' : PLANT_URL + '/svg/');
  1770. var graph = editorUi.editor.graph;
  1771. // TODO: Change server to return base64 and accept POST request
  1772. if (editorUi.spinner.spin(document.body, mxResources.get('inserting')))
  1773. {
  1774. function encode64(data)
  1775. {
  1776. r = "";
  1777. for (i = 0; i < data.length; i += 3)
  1778. {
  1779. if (i + 2 == data.length)
  1780. {
  1781. r += append3bytes(data.charCodeAt(i), data.charCodeAt(i + 1), 0);
  1782. }
  1783. else if (i + 1 == data.length)
  1784. {
  1785. r += append3bytes(data.charCodeAt(i), 0, 0);
  1786. }
  1787. else
  1788. {
  1789. r += append3bytes(data.charCodeAt(i), data.charCodeAt(i + 1),
  1790. data.charCodeAt(i + 2));
  1791. }
  1792. }
  1793. return r;
  1794. }
  1795. function append3bytes(b1, b2, b3)
  1796. {
  1797. c1 = b1 >> 2;
  1798. c2 = ((b1 & 0x3) << 4) | (b2 >> 4);
  1799. c3 = ((b2 & 0xF) << 2) | (b3 >> 6);
  1800. c4 = b3 & 0x3F;
  1801. r = "";
  1802. r += encode6bit(c1 & 0x3F);
  1803. r += encode6bit(c2 & 0x3F);
  1804. r += encode6bit(c3 & 0x3F);
  1805. r += encode6bit(c4 & 0x3F);
  1806. return r;
  1807. }
  1808. function encode6bit(b)
  1809. {
  1810. if (b < 10)
  1811. {
  1812. return String.fromCharCode(48 + b);
  1813. }
  1814. b -= 10;
  1815. if (b < 26)
  1816. {
  1817. return String.fromCharCode(65 + b);
  1818. }
  1819. b -= 26;
  1820. if (b < 26)
  1821. {
  1822. return String.fromCharCode(97 + b);
  1823. }
  1824. b -= 26;
  1825. if (b == 0)
  1826. {
  1827. return '-';
  1828. }
  1829. if (b == 1)
  1830. {
  1831. return '_';
  1832. }
  1833. return '?';
  1834. }
  1835. // TODO: Remove unescape, use btoa for compatibility with graph.compress
  1836. function compress(s)
  1837. {
  1838. return encode64(Graph.bytesToString(
  1839. pako.deflateRaw(unescape(
  1840. encodeURIComponent(s)))));
  1841. };
  1842. var xhr = new XMLHttpRequest();
  1843. xhr.open('GET', plantUmlServerUrl + compress(text), true);
  1844. if (type != 'plantUmlTxt')
  1845. {
  1846. xhr.responseType = 'blob';
  1847. }
  1848. xhr.onload = function(e)
  1849. {
  1850. if (this.status >= 200 && this.status < 300)
  1851. {
  1852. if (type == 'plantUmlTxt')
  1853. {
  1854. editorUi.spinner.stop();
  1855. graph.setSelectionCell(editorUi.insertAsPreText(
  1856. this.response, insertPoint.x, insertPoint.y));
  1857. graph.scrollCellToVisible(graph.getSelectionCell());
  1858. }
  1859. else
  1860. {
  1861. var reader = new FileReader();
  1862. reader.readAsDataURL(this.response);
  1863. reader.onloadend = function(e)
  1864. {
  1865. var img = new Image();
  1866. img.onload = function()
  1867. {
  1868. editorUi.spinner.stop();
  1869. var w = img.width;
  1870. var h = img.height;
  1871. // Workaround for 0 image size in IE11
  1872. if (w == 0 && h == 0)
  1873. {
  1874. var data = reader.result;
  1875. var comma = data.indexOf(',');
  1876. var svgText = decodeURIComponent(escape(atob(data.substring(comma + 1))));
  1877. var root = mxUtils.parseXml(svgText);
  1878. var svgs = root.getElementsByTagName('svg');
  1879. if (svgs.length > 0)
  1880. {
  1881. w = parseFloat(svgs[0].getAttribute('width'));
  1882. h = parseFloat(svgs[0].getAttribute('height'));
  1883. }
  1884. }
  1885. graph.getModel().beginUpdate();
  1886. try
  1887. {
  1888. cell = graph.insertVertex(null, null, text, insertPoint.x, insertPoint.y,
  1889. w, h, 'shape=image;noLabel=1;verticalAlign=top;aspect=fixed;imageAspect=0;' +
  1890. 'image=' + editorUi.convertDataUri(reader.result) + ';');
  1891. }
  1892. finally
  1893. {
  1894. graph.getModel().endUpdate();
  1895. }
  1896. graph.setSelectionCell(cell);
  1897. graph.scrollCellToVisible(graph.getSelectionCell());
  1898. };
  1899. img.src = reader.result;
  1900. };
  1901. reader.onerror = function(e)
  1902. {
  1903. editorUi.handleError(e);
  1904. };
  1905. }
  1906. }
  1907. else
  1908. {
  1909. editorUi.spinner.stop();
  1910. editorUi.handleError(e);
  1911. }
  1912. };
  1913. xhr.onerror = function(e)
  1914. {
  1915. editorUi.handleError(e);
  1916. };
  1917. xhr.send();
  1918. }
  1919. }
  1920. else if (type == 'table')
  1921. {
  1922. var tableCell = null;
  1923. var rows = null;
  1924. var cells = [];
  1925. var dx = 0;
  1926. for (var i = 0; i < lines.length; i++)
  1927. {
  1928. var tmp = mxUtils.trim(lines[i]);
  1929. if (tmp.substring(0, 12).toLowerCase() == 'create table')
  1930. {
  1931. var name = mxUtils.trim(tmp.substring(12));
  1932. if (name.charAt(name.length - 1) == '(')
  1933. {
  1934. name = name.substring(0, name.lastIndexOf(' '));
  1935. }
  1936. tableCell = new mxCell(name, new mxGeometry(dx, 0, 160, 26),
  1937. 'swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=26;fillColor=#e0e0e0;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;swimlaneFillColor=#ffffff;align=center;');
  1938. tableCell.vertex = true;
  1939. cells.push(tableCell);
  1940. var size = editorUi.editor.graph.getPreferredSizeForCell(rowCell);
  1941. if (size != null)
  1942. {
  1943. tableCell.geometry.width = size.width + 10;
  1944. }
  1945. // For primary key lookups
  1946. rows = {};
  1947. }
  1948. else if (tableCell != null && tmp.charAt(0) == ')')
  1949. {
  1950. dx += tableCell.geometry.width + 40;
  1951. tableCell = null;
  1952. }
  1953. else if (tmp != '(' && tableCell != null)
  1954. {
  1955. var name = tmp.substring(0, (tmp.charAt(tmp.length - 1) == ',') ? tmp.length - 1 : tmp.length);
  1956. if (name.substring(0, 11).toLowerCase() != 'primary key')
  1957. {
  1958. var pk = name.toLowerCase().indexOf('primary key');
  1959. name = name.replace(/primary key/i, '');
  1960. var rowCell = new mxCell(name, new mxGeometry(0, 0, 90, 26),
  1961. 'shape=partialRectangle;top=0;left=0;right=0;bottom=0;align=left;verticalAlign=top;spacingTop=-2;fillColor=none;spacingLeft=34;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;dropTarget=0;');
  1962. rowCell.vertex = true;
  1963. var left = sb.cloneCell(rowCell, (pk > 0) ? 'PK' : '');
  1964. left.connectable = false;
  1965. left.style = 'shape=partialRectangle;top=0;left=0;bottom=0;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[];portConstraint=eastwest;part=1;'
  1966. left.geometry.width = 30;
  1967. left.geometry.height = 26;
  1968. rowCell.insert(left);
  1969. var size = editorUi.editor.graph.getPreferredSizeForCell(rowCell);
  1970. if (size != null && tableCell.geometry.width < size.width + 10)
  1971. {
  1972. tableCell.geometry.width = Math.min(220, size.width + 10);
  1973. }
  1974. tableCell.insert(rowCell);
  1975. tableCell.geometry.height += 26;
  1976. rows[rowCell.value] = rowCell;
  1977. }
  1978. }
  1979. }
  1980. if (cells.length > 0)
  1981. {
  1982. var graph = editorUi.editor.graph;
  1983. var view = graph.view;
  1984. var bds = graph.getGraphBounds();
  1985. // Computes unscaled, untranslated graph bounds
  1986. var x = Math.ceil(Math.max(0, bds.x / view.scale - view.translate.x) + 4 * graph.gridSize);
  1987. var y = Math.ceil(Math.max(0, (bds.y + bds.height) / view.scale - view.translate.y) + 4 * graph.gridSize);
  1988. graph.setSelectionCells(graph.importCells(cells, x, y));
  1989. graph.scrollCellToVisible(graph.getSelectionCell());
  1990. }
  1991. }
  1992. else if (type == 'list')
  1993. {
  1994. if (lines.length > 0)
  1995. {
  1996. var graph = editorUi.editor.graph;
  1997. var listCell = new mxCell(lines[0], new mxGeometry(0, 0, 160, 26 + 4),
  1998. 'swimlane;fontStyle=1;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;swimlaneFillColor=#ffffff;');
  1999. listCell.vertex = true;
  2000. var size = graph.getPreferredSizeForCell(listCell);
  2001. if (size != null && listCell.geometry.width < size.width + 10)
  2002. {
  2003. listCell.geometry.width = size.width + 10;
  2004. }
  2005. var inserted = [listCell];
  2006. if (lines.length > 1)
  2007. {
  2008. for (var i = 1; i < lines.length; i++)
  2009. {
  2010. if (lines[i] == '--')
  2011. {
  2012. 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;');
  2013. divider.vertex = true;
  2014. listCell.geometry.height += divider.geometry.height;
  2015. listCell.insert(divider);
  2016. inserted.push(divider);
  2017. }
  2018. else if (lines[i].length > 0 && lines[i].charAt(0) != ';')
  2019. {
  2020. 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;');
  2021. field.vertex = true;
  2022. var size = graph.getPreferredSizeForCell(field);
  2023. if (size != null && field.geometry.width < size.width)
  2024. {
  2025. field.geometry.width = size.width;
  2026. }
  2027. listCell.geometry.width = Math.max(listCell.geometry.width, field.geometry.width);
  2028. listCell.geometry.height += field.geometry.height;
  2029. listCell.insert(field);
  2030. inserted.push(field);
  2031. }
  2032. }
  2033. }
  2034. graph.getModel().beginUpdate();
  2035. try
  2036. {
  2037. listCell = graph.importCells([listCell], insertPoint.x, insertPoint.y)[0];
  2038. graph.fireEvent(new mxEventObject('cellsInserted', 'cells', [listCell].concat(listCell.children)));
  2039. }
  2040. finally
  2041. {
  2042. graph.getModel().endUpdate();
  2043. }
  2044. graph.setSelectionCell(listCell);
  2045. graph.scrollCellToVisible(graph.getSelectionCell());
  2046. }
  2047. }
  2048. else
  2049. {
  2050. var vertices = new Object();
  2051. var cells = [];
  2052. function getOrCreateVertex(id)
  2053. {
  2054. var vertex = vertices[id];
  2055. if (vertex == null)
  2056. {
  2057. vertex = new mxCell(id, new mxGeometry(0, 0, 80, 30), 'whiteSpace=wrap;html=1;');
  2058. vertex.vertex = true;
  2059. vertices[id] = vertex;
  2060. cells.push(vertex);
  2061. }
  2062. return vertex;
  2063. };
  2064. for (var i = 0; i < lines.length; i++)
  2065. {
  2066. if (lines[i].charAt(0) != ';')
  2067. {
  2068. var values = lines[i].split('->');
  2069. if (values.length >= 2)
  2070. {
  2071. var source = getOrCreateVertex(values[0]);
  2072. var target = getOrCreateVertex(values[values.length - 1]);
  2073. var edge = new mxCell((values.length > 2) ? values[1] : '', new mxGeometry());
  2074. edge.edge = true;
  2075. source.insertEdge(edge, true);
  2076. target.insertEdge(edge, false);
  2077. cells.push(edge);
  2078. }
  2079. }
  2080. }
  2081. if (cells.length > 0)
  2082. {
  2083. var container = document.createElement('div');
  2084. container.style.visibility = 'hidden';
  2085. document.body.appendChild(container);
  2086. // Temporary graph for running the layout
  2087. var graph = new Graph(container);
  2088. graph.getModel().beginUpdate();
  2089. try
  2090. {
  2091. cells = graph.importCells(cells);
  2092. for (var i = 0; i < cells.length; i++)
  2093. {
  2094. if (graph.getModel().isVertex(cells[i]))
  2095. {
  2096. var size = graph.getPreferredSizeForCell(cells[i]);
  2097. cells[i].geometry.width = Math.max(cells[i].geometry.width, size.width);
  2098. cells[i].geometry.height = Math.max(cells[i].geometry.height, size.height);
  2099. }
  2100. }
  2101. var layout = new mxFastOrganicLayout(graph);
  2102. layout.disableEdgeStyle = false;
  2103. layout.forceConstant = 120;
  2104. layout.execute(graph.getDefaultParent());
  2105. var edgeLayout = new mxParallelEdgeLayout(graph);
  2106. edgeLayout.spacing = 20;
  2107. edgeLayout.execute(graph.getDefaultParent());
  2108. }
  2109. finally
  2110. {
  2111. graph.getModel().endUpdate();
  2112. }
  2113. graph.clearCellOverlays();
  2114. // Copy to actual graph
  2115. var inserted = [];
  2116. editorUi.editor.graph.getModel().beginUpdate();
  2117. try
  2118. {
  2119. inserted = editorUi.editor.graph.importCells(graph.getModel().getChildren(
  2120. graph.getDefaultParent()), insertPoint.x, insertPoint.y)
  2121. editorUi.editor.graph.fireEvent(new mxEventObject('cellsInserted', 'cells', inserted));
  2122. }
  2123. finally
  2124. {
  2125. editorUi.editor.graph.getModel().endUpdate();
  2126. }
  2127. editorUi.editor.graph.setSelectionCells(inserted);
  2128. editorUi.editor.graph.scrollCellToVisible(editorUi.editor.graph.getSelectionCell());
  2129. graph.destroy();
  2130. container.parentNode.removeChild(container);
  2131. }
  2132. }
  2133. };
  2134. var div = document.createElement('div');
  2135. div.style.textAlign = 'right';
  2136. var textarea = document.createElement('textarea');
  2137. textarea.style.resize = 'none';
  2138. textarea.style.width = '100%';
  2139. textarea.style.height = '354px';
  2140. textarea.style.marginBottom = '16px';
  2141. var typeSelect = document.createElement('select');
  2142. if (defaultType == 'formatSql')
  2143. {
  2144. typeSelect.style.display = 'none';
  2145. }
  2146. var listOption = document.createElement('option');
  2147. listOption.setAttribute('value', 'list');
  2148. mxUtils.write(listOption, mxResources.get('list'));
  2149. if (defaultType != 'plantUml')
  2150. {
  2151. typeSelect.appendChild(listOption);
  2152. }
  2153. if (defaultType == null || defaultType == 'fromText')
  2154. {
  2155. listOption.setAttribute('selected', 'selected');
  2156. }
  2157. var tableOption = document.createElement('option');
  2158. tableOption.setAttribute('value', 'table');
  2159. mxUtils.write(tableOption, mxResources.get('formatSql'));
  2160. if (defaultType == 'formatSql')
  2161. {
  2162. typeSelect.appendChild(tableOption);
  2163. tableOption.setAttribute('selected', 'selected');
  2164. }
  2165. var diagramOption = document.createElement('option');
  2166. diagramOption.setAttribute('value', 'diagram');
  2167. mxUtils.write(diagramOption, mxResources.get('diagram'));
  2168. if (defaultType != 'plantUml')
  2169. {
  2170. typeSelect.appendChild(diagramOption);
  2171. }
  2172. var plantUmlSvgOption = document.createElement('option');
  2173. plantUmlSvgOption.setAttribute('value', 'plantUmlSvg');
  2174. mxUtils.write(plantUmlSvgOption, mxResources.get('plantUml') + ' (' + mxResources.get('formatSvg') + ')');
  2175. if (defaultType == 'plantUml')
  2176. {
  2177. plantUmlSvgOption.setAttribute('selected', 'selected');
  2178. }
  2179. var plantUmlPngOption = document.createElement('option');
  2180. plantUmlPngOption.setAttribute('value', 'plantUmlPng');
  2181. mxUtils.write(plantUmlPngOption, mxResources.get('plantUml') + ' (' + mxResources.get('formatPng') + ')');
  2182. var plantUmlTxtOption = document.createElement('option');
  2183. plantUmlTxtOption.setAttribute('value', 'plantUmlTxt');
  2184. mxUtils.write(plantUmlTxtOption, mxResources.get('plantUml') + ' (' + mxResources.get('text') + ')');
  2185. // Disabled for invalid hosts via CORS headers
  2186. if (EditorUi.enablePlantUml && Graph.fileSupport &&
  2187. !editorUi.isOffline() && defaultType == 'plantUml')
  2188. {
  2189. typeSelect.appendChild(plantUmlSvgOption);
  2190. typeSelect.appendChild(plantUmlPngOption);
  2191. typeSelect.appendChild(plantUmlTxtOption);
  2192. }
  2193. function getDefaultValue()
  2194. {
  2195. if (typeSelect.value == 'list')
  2196. {
  2197. return 'Person\n-name: String\n-birthDate: Date\n--\n+getName(): String\n+setName(String): void\n+isBirthday(): boolean';
  2198. }
  2199. else if (typeSelect.value == 'table')
  2200. {
  2201. return 'CREATE TABLE Suppliers\n(\nsupplier_id int NOT NULL PRIMARY KEY,\n' +
  2202. 'supplier_name char(50) NOT NULL,\ncontact_name char(50),\n);\n' +
  2203. 'CREATE TABLE Customers\n(\ncustomer_id int NOT NULL PRIMARY KEY,\n' +
  2204. 'customer_name char(50) NOT NULL,\naddress char(50),\n' +
  2205. 'city char(50),\nstate char(25),\nzip_code char(10)\n);\n';
  2206. }
  2207. else if (typeSelect.value == 'plantUmlPng')
  2208. {
  2209. return '@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';
  2210. }
  2211. else if (typeSelect.value == 'plantUmlSvg' || typeSelect.value == 'plantUmlTxt')
  2212. {
  2213. return '@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';
  2214. }
  2215. else
  2216. {
  2217. return ';Example:\na->b\nb->edge label->c\nc->a\n';
  2218. }
  2219. };
  2220. var defaultValue = getDefaultValue();
  2221. textarea.value = defaultValue;
  2222. div.appendChild(textarea);
  2223. this.init = function()
  2224. {
  2225. textarea.focus();
  2226. };
  2227. // Enables dropping files
  2228. if (Graph.fileSupport)
  2229. {
  2230. function handleDrop(evt)
  2231. {
  2232. evt.stopPropagation();
  2233. evt.preventDefault();
  2234. if (evt.dataTransfer.files.length > 0)
  2235. {
  2236. var file = evt.dataTransfer.files[0];
  2237. var reader = new FileReader();
  2238. reader.onload = function(e) { textarea.value = e.target.result; };
  2239. reader.readAsText(file);
  2240. }
  2241. };
  2242. function handleDragOver(evt)
  2243. {
  2244. evt.stopPropagation();
  2245. evt.preventDefault();
  2246. };
  2247. // Setup the dnd listeners.
  2248. textarea.addEventListener('dragover', handleDragOver, false);
  2249. textarea.addEventListener('drop', handleDrop, false);
  2250. }
  2251. div.appendChild(typeSelect);
  2252. mxEvent.addListener(typeSelect, 'change', function()
  2253. {
  2254. var newDefaultValue = getDefaultValue();
  2255. if (textarea.value.length == 0 || textarea.value == defaultValue)
  2256. {
  2257. defaultValue = newDefaultValue;
  2258. textarea.value = defaultValue;
  2259. }
  2260. });
  2261. var cancelBtn = mxUtils.button(mxResources.get('close'), function()
  2262. {
  2263. if (textarea.value == defaultValue)
  2264. {
  2265. editorUi.hideDialog();
  2266. }
  2267. else
  2268. {
  2269. editorUi.confirm(mxResources.get('areYouSure'), function()
  2270. {
  2271. editorUi.hideDialog();
  2272. });
  2273. }
  2274. });
  2275. cancelBtn.className = 'geBtn';
  2276. if (editorUi.editor.cancelFirst)
  2277. {
  2278. div.appendChild(cancelBtn);
  2279. }
  2280. var okBtn = mxUtils.button(mxResources.get('insert'), function()
  2281. {
  2282. editorUi.hideDialog();
  2283. parse(textarea.value, typeSelect.value);
  2284. });
  2285. div.appendChild(okBtn);
  2286. okBtn.className = 'geBtn gePrimaryBtn';
  2287. if (!editorUi.editor.cancelFirst)
  2288. {
  2289. div.appendChild(cancelBtn);
  2290. }
  2291. this.container = div;
  2292. };
  2293. /**
  2294. * Constructs a new dialog for creating files from templates.
  2295. */
  2296. var NewDialog = function(editorUi, compact, showName, callback, createOnly, cancelCallback,
  2297. leftHighlight, rightHighlight, rightHighlightBorder, itemPadding, templateFile,
  2298. recentDocsCallback, searchDocsCallback, openExtDocCallback, showImport, createButtonLabel)
  2299. {
  2300. showName = (showName != null) ? showName : true;
  2301. createOnly = (createOnly != null) ? createOnly : false;
  2302. leftHighlight = (leftHighlight != null) ? leftHighlight : '#ebf2f9';
  2303. rightHighlight = (rightHighlight != null) ? rightHighlight : '#e6eff8';
  2304. rightHighlightBorder = (rightHighlightBorder != null) ? rightHighlightBorder : '1px solid #ccd9ea';
  2305. templateFile = (templateFile != null) ? templateFile : EditorUi.templateFile;
  2306. var outer = document.createElement('div');
  2307. outer.style.height = '100%';
  2308. var header = document.createElement('div');
  2309. header.style.whiteSpace = 'nowrap';
  2310. header.style.height = '46px';
  2311. if (showName)
  2312. {
  2313. outer.appendChild(header);
  2314. }
  2315. var logo = document.createElement('img');
  2316. logo.setAttribute('border', '0');
  2317. logo.setAttribute('align', 'absmiddle');
  2318. logo.style.width = '40px';
  2319. logo.style.height = '40px';
  2320. logo.style.marginRight = '10px';
  2321. logo.style.paddingBottom = '4px';
  2322. if (editorUi.mode == App.MODE_GOOGLE)
  2323. {
  2324. logo.src = IMAGE_PATH + '/google-drive-logo.svg';
  2325. }
  2326. else if (editorUi.mode == App.MODE_DROPBOX)
  2327. {
  2328. logo.src = IMAGE_PATH + '/dropbox-logo.svg';
  2329. }
  2330. else if (editorUi.mode == App.MODE_ONEDRIVE)
  2331. {
  2332. logo.src = IMAGE_PATH + '/onedrive-logo.svg';
  2333. }
  2334. else if (editorUi.mode == App.MODE_GITHUB)
  2335. {
  2336. logo.src = IMAGE_PATH + '/github-logo.svg';
  2337. }
  2338. else if (editorUi.mode == App.MODE_TRELLO)
  2339. {
  2340. logo.src = IMAGE_PATH + '/trello-logo.svg';
  2341. }
  2342. else if (editorUi.mode == App.MODE_BROWSER)
  2343. {
  2344. logo.src = IMAGE_PATH + '/osa_database.png';
  2345. }
  2346. else
  2347. {
  2348. logo.src = IMAGE_PATH + '/osa_drive-harddisk.png';
  2349. }
  2350. if (!compact && showName)
  2351. {
  2352. header.appendChild(logo);
  2353. }
  2354. if (showName)
  2355. {
  2356. mxUtils.write(header, ((editorUi.mode == null || editorUi.mode == App.MODE_GOOGLE ||
  2357. editorUi.mode == App.MODE_BROWSER) ? mxResources.get('diagramName') : mxResources.get('filename')) + ':');
  2358. }
  2359. var ext = '.drawio';
  2360. if (editorUi.mode == App.MODE_GOOGLE && editorUi.drive != null)
  2361. {
  2362. ext = editorUi.drive.extension;
  2363. }
  2364. else if (editorUi.mode == App.MODE_DROPBOX && editorUi.dropbox != null)
  2365. {
  2366. ext = editorUi.dropbox.extension;
  2367. }
  2368. else if (editorUi.mode == App.MODE_ONEDRIVE && editorUi.oneDrive != null)
  2369. {
  2370. ext = editorUi.oneDrive.extension;
  2371. }
  2372. else if (editorUi.mode == App.MODE_GITHUB && editorUi.gitHub != null)
  2373. {
  2374. ext = editorUi.gitHub.extension;
  2375. }
  2376. else if (editorUi.mode == App.MODE_TRELLO && editorUi.trello != null)
  2377. {
  2378. ext = editorUi.trello.extension;
  2379. }
  2380. var nameInput = document.createElement('input');
  2381. nameInput.setAttribute('value', editorUi.defaultFilename + ext);
  2382. nameInput.style.marginLeft = '10px';
  2383. nameInput.style.width = (compact) ? '220px' : '430px';
  2384. this.init = function()
  2385. {
  2386. if (showName)
  2387. {
  2388. nameInput.focus();
  2389. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  2390. {
  2391. nameInput.select();
  2392. }
  2393. else
  2394. {
  2395. document.execCommand('selectAll', false, null);
  2396. }
  2397. }
  2398. };
  2399. if (showName)
  2400. {
  2401. header.appendChild(nameInput);
  2402. if (editorUi.editor.fileExtensions != null)
  2403. {
  2404. var hint = FilenameDialog.createTypeHint(
  2405. editorUi, nameInput, editorUi.editor.fileExtensions);
  2406. hint.style.marginTop = '12px';
  2407. header.appendChild(hint);
  2408. }
  2409. }
  2410. var hasTabs = false;
  2411. var i0 = 0;
  2412. // Dynamic loading
  2413. function addTemplates()
  2414. {
  2415. var first = true;
  2416. //TODO support paging of external templates
  2417. if (templates != null)
  2418. {
  2419. while (i0 < templates.length && (first || mxUtils.mod(i0, 30) != 0))
  2420. {
  2421. var tmp = templates[i0++];
  2422. addButton(tmp.url, tmp.libs, tmp.title, tmp.tooltip? tmp.tooltip : tmp.title,
  2423. tmp.select, tmp.imgUrl, tmp.info, tmp.onClick, tmp.preview);
  2424. first = false;
  2425. }
  2426. }
  2427. };
  2428. var spinner = new Spinner({
  2429. lines: 12, // The number of lines to draw
  2430. length: 10, // The length of each line
  2431. width: 5, // The line thickness
  2432. radius: 10, // The radius of the inner circle
  2433. rotate: 0, // The rotation offset
  2434. color: '#000', // #rgb or #rrggbb
  2435. speed: 1.5, // Rounds per second
  2436. trail: 60, // Afterglow percentage
  2437. shadow: false, // Whether to render a shadow
  2438. hwaccel: false, // Whether to use hardware acceleration
  2439. top: '40%',
  2440. zIndex: 2e9 // The z-index (defaults to 2000000000)
  2441. });
  2442. var createButton = mxUtils.button(createButtonLabel || mxResources.get('create'), function()
  2443. {
  2444. createButton.setAttribute('disabled', 'disabled');
  2445. create();
  2446. createButton.removeAttribute('disabled');
  2447. });
  2448. createButton.className = 'geBtn gePrimaryBtn';
  2449. if (recentDocsCallback || searchDocsCallback)
  2450. {
  2451. var tabsEl = [];
  2452. var oldTemplates = null;
  2453. var setActiveTab = function(index)
  2454. {
  2455. createButton.setAttribute('disabled', 'disabled');
  2456. for (var i = 0; i < tabsEl.length; i++)
  2457. {
  2458. if (i == index)
  2459. tabsEl[i].className = 'geBtn gePrimaryBtn';
  2460. else
  2461. tabsEl[i].className = 'geBtn';
  2462. }
  2463. }
  2464. hasTabs = true;
  2465. var tabs = document.createElement('div');
  2466. tabs.style.whiteSpace = 'nowrap';
  2467. tabs.style.height = '30px';
  2468. outer.appendChild(tabs);
  2469. var templatesTab = mxUtils.button(mxResources.get('Templates', null, 'Templates'), function()
  2470. {
  2471. list.style.display = '';
  2472. div.style.left = '160px';
  2473. setActiveTab(0);
  2474. div.scrollTop = 0;
  2475. div.innerHTML = '';
  2476. i0 = 0;
  2477. if (oldTemplates != templates)
  2478. {
  2479. templates = oldTemplates;
  2480. addTemplates();
  2481. oldTemplates = null;
  2482. }
  2483. });
  2484. tabsEl.push(templatesTab);
  2485. tabs.appendChild(templatesTab);
  2486. var getExtTemplates = function(isSearch)
  2487. {
  2488. list.style.display = 'none';
  2489. div.style.left = '30px';
  2490. setActiveTab(isSearch? -1 : 1); //deselect all of them if isSearch
  2491. if (oldTemplates == null)
  2492. {
  2493. oldTemplates = templates;
  2494. }
  2495. div.scrollTop = 0;
  2496. div.innerHTML = '';
  2497. spinner.spin(div);
  2498. i0 = 0;
  2499. var callback2 = function(list, errorMsg)
  2500. {
  2501. spinner.stop();
  2502. templates = list;
  2503. if (errorMsg)
  2504. {
  2505. div.innerHTML = errorMsg;
  2506. }
  2507. else if (list.length == 0)
  2508. {
  2509. div.innerHTML = mxUtils.htmlEntities(mxResources.get('noDiagrams', null, 'No Diagrams Found'));
  2510. }
  2511. else
  2512. {
  2513. div.innerHTML = '';
  2514. addTemplates();
  2515. }
  2516. }
  2517. if (isSearch)
  2518. {
  2519. searchDocsCallback(searchInput.value, callback2);
  2520. }
  2521. else
  2522. {
  2523. recentDocsCallback(callback2);
  2524. }
  2525. }
  2526. if (recentDocsCallback)
  2527. {
  2528. var recentTab = mxUtils.button(mxResources.get('Recent', null, 'Recent'), function()
  2529. {
  2530. getExtTemplates();
  2531. });
  2532. tabs.appendChild(recentTab);
  2533. tabsEl.push(recentTab);
  2534. }
  2535. if (searchDocsCallback)
  2536. {
  2537. var searchTab = document.createElement('span');
  2538. searchTab.style.marginLeft = '10px';
  2539. searchTab.innerHTML = mxUtils.htmlEntities(mxResources.get('search') + ':');
  2540. tabs.appendChild(searchTab);
  2541. var searchInput = document.createElement('input');
  2542. searchInput.style.marginRight = '10px';
  2543. searchInput.style.marginLeft = '10px';
  2544. searchInput.style.width = '220px';
  2545. mxEvent.addListener(searchInput, 'keypress', function(e)
  2546. {
  2547. if (e.keyCode == 13)
  2548. {
  2549. getExtTemplates(true);
  2550. }
  2551. });
  2552. tabs.appendChild(searchInput);
  2553. var searchBtn = mxUtils.button(mxResources.get('search'), function()
  2554. {
  2555. getExtTemplates(true);
  2556. });
  2557. searchBtn.className = 'geBtn';
  2558. tabs.appendChild(searchBtn);
  2559. }
  2560. setActiveTab(0);
  2561. }
  2562. var templateLibs = null;
  2563. var templateXml = null;
  2564. var selectedElt = null;
  2565. var templateExtUrl = null;
  2566. var templateInfoObj = null;
  2567. function create()
  2568. {
  2569. if (templateExtUrl)
  2570. {
  2571. if (!showName)
  2572. {
  2573. editorUi.hideDialog();
  2574. }
  2575. openExtDocCallback(templateExtUrl, templateInfoObj, nameInput.value);
  2576. }
  2577. else if (callback)
  2578. {
  2579. if (!showName)
  2580. {
  2581. editorUi.hideDialog();
  2582. }
  2583. callback(templateXml, nameInput.value);
  2584. }
  2585. else
  2586. {
  2587. var title = nameInput.value;
  2588. if (title != null && title.length > 0)
  2589. {
  2590. editorUi.pickFolder(editorUi.mode, function(folderId)
  2591. {
  2592. editorUi.createFile(title, templateXml, (templateLibs != null &&
  2593. templateLibs.length > 0) ? templateLibs : null, null, function()
  2594. {
  2595. editorUi.hideDialog();
  2596. }, null, folderId);
  2597. }, editorUi.mode != App.MODE_GOOGLE ||
  2598. editorUi.stateArg == null ||
  2599. editorUi.stateArg.folderId == null);
  2600. }
  2601. }
  2602. };
  2603. var div = document.createElement('div');
  2604. div.style.border = '1px solid #d3d3d3';
  2605. div.style.position = 'absolute';
  2606. div.style.left = '160px';
  2607. div.style.right = '34px';
  2608. var divTop = (showName) ? 72 : 40;
  2609. divTop += hasTabs? 30 : 0;
  2610. div.style.top = divTop + 'px';
  2611. div.style.bottom = '68px';
  2612. div.style.margin = '6px 0 0 -1px';
  2613. div.style.padding = '6px';
  2614. div.style.overflow = 'auto';
  2615. var list = document.createElement('div');
  2616. list.style.cssText = 'position:absolute;left:30px;width:128px;top:' + divTop + 'px;bottom:68px;margin-top:6px;overflow:auto;border:1px solid #d3d3d3;';
  2617. var w = 140;
  2618. var h = 140;
  2619. function selectElement(elt, xml, libs, extUrl, infoObj)
  2620. {
  2621. if (selectedElt != null)
  2622. {
  2623. selectedElt.style.backgroundColor = 'transparent';
  2624. selectedElt.style.border = '1px solid transparent';
  2625. }
  2626. createButton.removeAttribute('disabled');
  2627. templateXml = xml;
  2628. templateLibs = libs;
  2629. selectedElt = elt;
  2630. templateExtUrl = extUrl;
  2631. templateInfoObj = infoObj;
  2632. selectedElt.style.backgroundColor = rightHighlight;
  2633. selectedElt.style.border = rightHighlightBorder;
  2634. };
  2635. function addButton(url, libs, title, tooltip, select, imgUrl, infoObj, onClick, preview)
  2636. {
  2637. var elt = document.createElement('div');
  2638. elt.className = 'geTemplate';
  2639. elt.style.height = w + 'px';
  2640. elt.style.width = h + 'px';
  2641. if (tooltip != null && tooltip.length > 0)
  2642. {
  2643. elt.setAttribute('title', tooltip);
  2644. }
  2645. if (imgUrl != null)
  2646. {
  2647. elt.style.backgroundImage = 'url(' + imgUrl + ')';
  2648. elt.style.backgroundSize = 'contain';
  2649. elt.style.backgroundPosition = 'center center';
  2650. elt.style.backgroundRepeat = 'no-repeat';
  2651. mxEvent.addListener(elt, 'click', function(evt)
  2652. {
  2653. selectElement(elt, null, null, url, infoObj);
  2654. });
  2655. mxEvent.addListener(elt, 'dblclick', function(evt)
  2656. {
  2657. create();
  2658. });
  2659. }
  2660. else if (url != null && url.length > 0)
  2661. {
  2662. var png = preview || (TEMPLATE_PATH + '/' + url.substring(0, url.length - 4) + '.png');
  2663. elt.style.backgroundImage = 'url(' + png + ')';
  2664. elt.style.backgroundPosition = 'center center';
  2665. elt.style.backgroundRepeat = 'no-repeat';
  2666. var createIt = false;
  2667. mxEvent.addListener(elt, 'click', function(evt)
  2668. {
  2669. createButton.setAttribute('disabled', 'disabled');
  2670. elt.style.backgroundColor = 'transparent';
  2671. elt.style.border = '1px solid transparent';
  2672. var realUrl = url;
  2673. if (/^https?:\/\//.test(realUrl) && !editorUi.editor.isCorsEnabledForUrl(realUrl))
  2674. {
  2675. realUrl = PROXY_URL + '?url=' + encodeURIComponent(realUrl);
  2676. }
  2677. else
  2678. {
  2679. realUrl = TEMPLATE_PATH + '/' + realUrl;
  2680. }
  2681. spinner.spin(div);
  2682. mxUtils.get(realUrl, mxUtils.bind(this, function(req)
  2683. {
  2684. spinner.stop();
  2685. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  2686. {
  2687. selectElement(elt, req.getText(), libs);
  2688. if (createIt)
  2689. {
  2690. create();
  2691. }
  2692. }
  2693. }));
  2694. });
  2695. mxEvent.addListener(elt, 'dblclick', function(evt)
  2696. {
  2697. // Asynchronous double click handling after loading template
  2698. createIt = true;
  2699. });
  2700. }
  2701. else
  2702. {
  2703. elt.innerHTML = '<table width="100%" height="100%" style="line-height:1em;"><tr>' +
  2704. '<td align="center" valign="middle">' + mxResources.get(title) + '</td></tr></table>';
  2705. if (select)
  2706. {
  2707. selectElement(elt);
  2708. }
  2709. if (onClick != null)
  2710. {
  2711. mxEvent.addListener(elt, 'click', onClick);
  2712. }
  2713. else
  2714. {
  2715. mxEvent.addListener(elt, 'click', function(evt)
  2716. {
  2717. selectElement(elt);
  2718. });
  2719. mxEvent.addListener(elt, 'dblclick', function(evt)
  2720. {
  2721. create();
  2722. });
  2723. }
  2724. }
  2725. div.appendChild(elt);
  2726. };
  2727. var categories = {};
  2728. var categoryCount = 1;
  2729. // Adds local basic templates
  2730. categories['basic'] = [{title: 'blankDiagram', select: true}];
  2731. var templates = categories['basic'];
  2732. function initUi()
  2733. {
  2734. mxEvent.addListener(div, 'scroll', function(evt)
  2735. {
  2736. if (div.scrollTop + div.clientHeight >= div.scrollHeight)
  2737. {
  2738. addTemplates();
  2739. mxEvent.consume(evt);
  2740. }
  2741. });
  2742. var currentEntry = null;
  2743. for (var cat in categories)
  2744. {
  2745. var entry = document.createElement('div');
  2746. var label = mxResources.get(cat);
  2747. var templateList = categories[cat];
  2748. if (label == null)
  2749. {
  2750. label = cat.substring(0, 1).toUpperCase() + cat.substring(1);
  2751. }
  2752. if (label.length > 18)
  2753. {
  2754. label = label.substring(0, 18) + '&hellip;';
  2755. }
  2756. entry.style.cssText = 'display:block;cursor:pointer;padding:6px;white-space:nowrap;margin-bottom:-1px;overflow:hidden;text-overflow:ellipsis;';
  2757. entry.setAttribute('title', label + ' (' + templateList.length + ')');
  2758. mxUtils.write(entry, entry.getAttribute('title'));
  2759. if (itemPadding != null)
  2760. {
  2761. entry.style.padding = itemPadding;
  2762. }
  2763. list.appendChild(entry);
  2764. if (currentEntry == null)
  2765. {
  2766. currentEntry = entry;
  2767. currentEntry.style.backgroundColor = leftHighlight;
  2768. }
  2769. (function(cat2, entry2)
  2770. {
  2771. mxEvent.addListener(entry, 'click', function()
  2772. {
  2773. if (currentEntry != entry2)
  2774. {
  2775. currentEntry.style.backgroundColor = '';
  2776. currentEntry = entry2;
  2777. currentEntry.style.backgroundColor = leftHighlight;
  2778. div.scrollTop = 0;
  2779. div.innerHTML = '';
  2780. i0 = 0;
  2781. templates = categories[cat2];
  2782. oldTemplates = null;
  2783. addTemplates();
  2784. }
  2785. });
  2786. })(cat, entry);
  2787. }
  2788. addTemplates();
  2789. }
  2790. if (!compact)
  2791. {
  2792. outer.appendChild(list);
  2793. outer.appendChild(div);
  2794. var indexLoaded = false;
  2795. var realUrl = templateFile;
  2796. if (/^https?:\/\//.test(realUrl) && !editorUi.editor.isCorsEnabledForUrl(realUrl))
  2797. {
  2798. realUrl = PROXY_URL + '?url=' + encodeURIComponent(realUrl);
  2799. }
  2800. mxUtils.get(realUrl, function(req)
  2801. {
  2802. // Workaround for index loaded 3 times in iOS offline mode
  2803. if (!indexLoaded)
  2804. {
  2805. indexLoaded = true;
  2806. var tmpDoc = req.getXml();
  2807. var node = tmpDoc.documentElement.firstChild;
  2808. while (node != null)
  2809. {
  2810. if (typeof(node.getAttribute) !== 'undefined')
  2811. {
  2812. var url = node.getAttribute('url');
  2813. if (url != null)
  2814. {
  2815. var category = node.getAttribute('section');
  2816. if (category == null)
  2817. {
  2818. var slash = url.indexOf('/');
  2819. category = url.substring(0, slash);
  2820. }
  2821. var list = categories[category];
  2822. if (list == null)
  2823. {
  2824. categoryCount++;
  2825. list = [];
  2826. categories[category] = list;
  2827. }
  2828. list.push({url: node.getAttribute('url'), libs: node.getAttribute('libs'),
  2829. title: node.getAttribute('title'), tooltip: node.getAttribute('url'),
  2830. preview: node.getAttribute('preview')});
  2831. }
  2832. }
  2833. node = node.nextSibling;
  2834. }
  2835. initUi();
  2836. }
  2837. });
  2838. }
  2839. mxEvent.addListener(nameInput, 'keypress', function(e)
  2840. {
  2841. if (editorUi.dialog.container.firstChild == outer &&
  2842. e.keyCode == 13)
  2843. {
  2844. create();
  2845. }
  2846. });
  2847. var btns = document.createElement('div');
  2848. btns.style.marginTop = (compact) ? '4px' : '16px';
  2849. btns.style.textAlign = 'right';
  2850. btns.style.position = 'absolute';
  2851. btns.style.left = '40px';
  2852. btns.style.bottom = '24px';
  2853. btns.style.right = '40px';
  2854. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  2855. {
  2856. if (cancelCallback != null)
  2857. {
  2858. cancelCallback();
  2859. }
  2860. editorUi.hideDialog(true);
  2861. });
  2862. cancelBtn.className = 'geBtn';
  2863. if (editorUi.editor.cancelFirst && (!createOnly || cancelCallback != null))
  2864. {
  2865. btns.appendChild(cancelBtn);
  2866. }
  2867. if (!compact && !editorUi.isOffline() && showName && callback == null && !createOnly)
  2868. {
  2869. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  2870. {
  2871. editorUi.openLink('https://support.draw.io/display/DO/Creating+and+Opening+Files');
  2872. });
  2873. helpBtn.className = 'geBtn';
  2874. btns.appendChild(helpBtn);
  2875. }
  2876. if (!compact && urlParams['embed'] != '1' && !createOnly)
  2877. {
  2878. var fromTmpBtn = mxUtils.button(mxResources.get('fromTemplateUrl'), function()
  2879. {
  2880. var dlg = new FilenameDialog(editorUi, '', mxResources.get('create'), function(fileUrl)
  2881. {
  2882. if (fileUrl != null && fileUrl.length > 0)
  2883. {
  2884. var url = editorUi.getUrl(window.location.pathname + '?mode=' + editorUi.mode +
  2885. '&title=' + encodeURIComponent(nameInput.value) +
  2886. '&create=' + encodeURIComponent(fileUrl));
  2887. if (editorUi.getCurrentFile() == null)
  2888. {
  2889. window.location.href = url;
  2890. }
  2891. else
  2892. {
  2893. window.openWindow(url);
  2894. }
  2895. }
  2896. }, mxResources.get('url'));
  2897. editorUi.showDialog(dlg.container, 300, 80, true, true);
  2898. dlg.init();
  2899. });
  2900. fromTmpBtn.className = 'geBtn';
  2901. btns.appendChild(fromTmpBtn);
  2902. }
  2903. if (Graph.fileSupport && showImport)
  2904. {
  2905. var importBtn = mxUtils.button(mxResources.get('import'), function()
  2906. {
  2907. var fileInput = document.createElement('input');
  2908. fileInput.setAttribute('multiple', 'multiple');
  2909. fileInput.setAttribute('type', 'file');
  2910. mxEvent.addListener(fileInput, 'change', function(evt)
  2911. {
  2912. editorUi.openFiles(fileInput.files, true);
  2913. });
  2914. fileInput.click();
  2915. });
  2916. importBtn.className = 'geBtn';
  2917. btns.appendChild(importBtn);
  2918. }
  2919. btns.appendChild(createButton);
  2920. if (!editorUi.editor.cancelFirst && callback == null && (!createOnly || cancelCallback != null))
  2921. {
  2922. btns.appendChild(cancelBtn);
  2923. }
  2924. outer.appendChild(btns);
  2925. this.container = outer;
  2926. };
  2927. /**
  2928. * Constructs a dialog for creating new files from a template URL.
  2929. */
  2930. var CreateDialog = function(editorUi, title, createFn, cancelFn, dlgTitle, btnLabel, overrideExtension,
  2931. allowBrowser, allowTab, helpLink, showDeviceButton, rowLimit, data, mimeType, base64Encoded, hints)
  2932. {
  2933. overrideExtension = (overrideExtension != null) ? overrideExtension : true;
  2934. allowBrowser = (allowBrowser != null) ? allowBrowser : true;
  2935. rowLimit = (rowLimit != null) ? rowLimit : 4;
  2936. var div = document.createElement('div');
  2937. var showButtons = true;
  2938. if (cancelFn == null)
  2939. {
  2940. editorUi.addLanguageMenu(div);
  2941. }
  2942. var h3 = document.createElement('h2');
  2943. mxUtils.write(h3, dlgTitle || mxResources.get('create'));
  2944. h3.style.marginTop = '0px';
  2945. h3.style.marginBottom = '24px';
  2946. div.appendChild(h3);
  2947. mxUtils.write(div, mxResources.get('filename') + ':');
  2948. var nameInput = document.createElement('input');
  2949. nameInput.setAttribute('value', title);
  2950. nameInput.style.width = '280px';
  2951. nameInput.style.marginLeft = '10px';
  2952. nameInput.style.marginBottom = '20px';
  2953. this.init = function()
  2954. {
  2955. nameInput.focus();
  2956. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  2957. {
  2958. nameInput.select();
  2959. }
  2960. else
  2961. {
  2962. document.execCommand('selectAll', false, null);
  2963. }
  2964. };
  2965. div.appendChild(nameInput);
  2966. if (hints != null)
  2967. {
  2968. div.appendChild(FilenameDialog.createTypeHint(editorUi, nameInput, hints));
  2969. }
  2970. if (data != null && mimeType != null && mimeType.substring(0, 6) == 'image/')
  2971. {
  2972. nameInput.style.width = '160px';
  2973. var preview = null;
  2974. // Workaround for broken images in SVG preview in Chrome
  2975. if (mimeType == 'image/svg+xml' && mxClient.IS_SVG)
  2976. {
  2977. preview = document.createElement('div');
  2978. preview.innerHTML = mxUtils.trim(data);
  2979. var svg = preview.getElementsByTagName('svg')[0];
  2980. var w = parseInt(svg.getAttribute('width'));
  2981. var h = parseInt(svg.getAttribute('height'));
  2982. svg.setAttribute('viewBox', '0 0 ' + w + ' ' + h);
  2983. svg.setAttribute('width', '120px');
  2984. svg.setAttribute('height', '80px');
  2985. }
  2986. else
  2987. {
  2988. preview = document.createElement('img');
  2989. preview.setAttribute('src', 'data:' + mimeType + ((base64Encoded) ? ';base64,': ';utf8,') + data);
  2990. }
  2991. preview.style.position = 'absolute';
  2992. preview.style.top = '70px';
  2993. preview.style.right = '100px';
  2994. preview.style.maxWidth = '120px';
  2995. preview.style.maxHeight = '80px';
  2996. mxUtils.setPrefixedStyle(preview.style, 'transform', 'translate(50%,-50%)');
  2997. div.appendChild(preview);
  2998. if (allowTab && Editor.popupsAllowed)
  2999. {
  3000. preview.style.cursor = 'pointer';
  3001. mxEvent.addListener(preview, 'click', function()
  3002. {
  3003. create('_blank');
  3004. });
  3005. }
  3006. }
  3007. mxUtils.br(div);
  3008. var buttons = document.createElement('div');
  3009. buttons.style.textAlign = 'center';
  3010. var count = 0;
  3011. function addLogo(img, title, mode, clientName)
  3012. {
  3013. var button = document.createElement('a');
  3014. button.style.overflow = 'hidden';
  3015. var logo = document.createElement('img');
  3016. logo.src = img;
  3017. logo.setAttribute('border', '0');
  3018. logo.setAttribute('align', 'absmiddle');
  3019. logo.style.width = '60px';
  3020. logo.style.height = '60px';
  3021. logo.style.paddingBottom = '6px';
  3022. button.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  3023. button.className = 'geBaseButton';
  3024. button.style.position = 'relative';
  3025. button.style.margin = '4px';
  3026. button.style.padding = '8px 8px 10px 8px';
  3027. button.style.whiteSpace = 'nowrap';
  3028. button.appendChild(logo);
  3029. // Workaround for quirks is a vertical list (limited to max 2 items)
  3030. if (mxClient.IS_QUIRKS)
  3031. {
  3032. button.style.cssFloat = 'left';
  3033. button.style.zoom = '1';
  3034. }
  3035. button.style.color = 'gray';
  3036. button.style.fontSize = '11px';
  3037. var label = document.createElement('div');
  3038. button.appendChild(label);
  3039. mxUtils.write(label, title);
  3040. function initButton()
  3041. {
  3042. mxEvent.addListener(button, 'click', function()
  3043. {
  3044. // Updates extension
  3045. change(mode);
  3046. create(mode);
  3047. });
  3048. };
  3049. // Supports lazy loading
  3050. if (clientName != null && editorUi[clientName] == null)
  3051. {
  3052. logo.style.visibility = 'hidden';
  3053. mxUtils.setOpacity(label, 10);
  3054. var size = 12;
  3055. var spinner = new Spinner({
  3056. lines: 12, // The number of lines to draw
  3057. length: size, // The length of each line
  3058. width: 5, // The line thickness
  3059. radius: 10, // The radius of the inner circle
  3060. rotate: 0, // The rotation offset
  3061. color: '#000', // #rgb or #rrggbb
  3062. speed: 1.5, // Rounds per second
  3063. trail: 60, // Afterglow percentage
  3064. shadow: false, // Whether to render a shadow
  3065. hwaccel: false, // Whether to use hardware acceleration
  3066. top: '40%',
  3067. zIndex: 2e9 // The z-index (defaults to 2000000000)
  3068. });
  3069. spinner.spin(button);
  3070. // Timeout after 30 secs
  3071. var timeout = window.setTimeout(function()
  3072. {
  3073. if (editorUi[clientName] == null)
  3074. {
  3075. spinner.stop();
  3076. button.style.display = 'none';
  3077. }
  3078. }, 30000);
  3079. editorUi.addListener('clientLoaded', mxUtils.bind(this, function()
  3080. {
  3081. if (editorUi[clientName] != null)
  3082. {
  3083. window.clearTimeout(timeout);
  3084. mxUtils.setOpacity(label, 100);
  3085. logo.style.visibility = '';
  3086. spinner.stop();
  3087. initButton();
  3088. }
  3089. }));
  3090. }
  3091. else
  3092. {
  3093. initButton();
  3094. }
  3095. buttons.appendChild(button);
  3096. if (++count == rowLimit)
  3097. {
  3098. mxUtils.br(buttons);
  3099. count = 0;
  3100. }
  3101. };
  3102. if (!showButtons)
  3103. {
  3104. mxUtils.write(div, mxResources.get('chooseAnOption') + ':');
  3105. }
  3106. else
  3107. {
  3108. buttons.style.marginTop = '6px';
  3109. div.appendChild(buttons);
  3110. }
  3111. // Adds all papersize options
  3112. var serviceSelect = document.createElement('select');
  3113. serviceSelect.style.marginLeft = '10px';
  3114. if (!editorUi.isOfflineApp() && !editorUi.isOffline())
  3115. {
  3116. if (typeof window.DriveClient === 'function')
  3117. {
  3118. var googleOption = document.createElement('option');
  3119. googleOption.setAttribute('value', App.MODE_GOOGLE);
  3120. mxUtils.write(googleOption, mxResources.get('googleDrive'));
  3121. serviceSelect.appendChild(googleOption);
  3122. addLogo(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googleDrive'), App.MODE_GOOGLE, 'drive');
  3123. }
  3124. if (typeof window.OneDriveClient === 'function')
  3125. {
  3126. var oneDriveOption = document.createElement('option');
  3127. oneDriveOption.setAttribute('value', App.MODE_ONEDRIVE);
  3128. mxUtils.write(oneDriveOption, mxResources.get('oneDrive'));
  3129. serviceSelect.appendChild(oneDriveOption);
  3130. if (editorUi.mode == App.MODE_ONEDRIVE)
  3131. {
  3132. oneDriveOption.setAttribute('selected', 'selected');
  3133. }
  3134. addLogo(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), App.MODE_ONEDRIVE, 'oneDrive');
  3135. }
  3136. if (typeof window.DropboxClient === 'function')
  3137. {
  3138. var dropboxOption = document.createElement('option');
  3139. dropboxOption.setAttribute('value', App.MODE_DROPBOX);
  3140. mxUtils.write(dropboxOption, mxResources.get('dropbox'));
  3141. serviceSelect.appendChild(dropboxOption);
  3142. if (editorUi.mode == App.MODE_DROPBOX)
  3143. {
  3144. dropboxOption.setAttribute('selected', 'selected');
  3145. }
  3146. addLogo(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), App.MODE_DROPBOX, 'dropbox');
  3147. }
  3148. if (editorUi.gitHub != null)
  3149. {
  3150. var gitHubOption = document.createElement('option');
  3151. gitHubOption.setAttribute('value', App.MODE_GITHUB);
  3152. mxUtils.write(gitHubOption, mxResources.get('github'));
  3153. serviceSelect.appendChild(gitHubOption);
  3154. addLogo(IMAGE_PATH + '/github-logo.svg', mxResources.get('github'), App.MODE_GITHUB, 'gitHub');
  3155. }
  3156. if (typeof window.TrelloClient === 'function')
  3157. {
  3158. var trelloOption = document.createElement('option');
  3159. trelloOption.setAttribute('value', App.MODE_TRELLO);
  3160. mxUtils.write(trelloOption, mxResources.get('trello'));
  3161. serviceSelect.appendChild(trelloOption);
  3162. addLogo(IMAGE_PATH + '/trello-logo.svg', mxResources.get('trello'), App.MODE_TRELLO, 'trello');
  3163. }
  3164. }
  3165. if (!Editor.useLocalStorage || urlParams['storage'] == 'device' ||
  3166. (editorUi.getCurrentFile() != null/* && !mxClient.IS_IOS*/))
  3167. {
  3168. var deviceOption = document.createElement('option');
  3169. deviceOption.setAttribute('value', App.MODE_DEVICE);
  3170. mxUtils.write(deviceOption, mxResources.get('device'));
  3171. serviceSelect.appendChild(deviceOption);
  3172. if (editorUi.mode == App.MODE_DEVICE || !allowBrowser)
  3173. {
  3174. deviceOption.setAttribute('selected', 'selected');
  3175. }
  3176. if (showDeviceButton)
  3177. {
  3178. addLogo(IMAGE_PATH + '/osa_drive-harddisk.png', mxResources.get('device'), App.MODE_DEVICE);
  3179. }
  3180. }
  3181. if (allowBrowser && isLocalStorage && urlParams['browser'] != '0')
  3182. {
  3183. var browserOption = document.createElement('option');
  3184. browserOption.setAttribute('value', App.MODE_BROWSER);
  3185. mxUtils.write(browserOption, mxResources.get('browser'));
  3186. serviceSelect.appendChild(browserOption);
  3187. if (editorUi.mode == App.MODE_BROWSER)
  3188. {
  3189. browserOption.setAttribute('selected', 'selected');
  3190. }
  3191. addLogo(IMAGE_PATH + '/osa_database.png', mxResources.get('browser'), App.MODE_BROWSER);
  3192. }
  3193. function change(newMode)
  3194. {
  3195. if (overrideExtension)
  3196. {
  3197. var fn = nameInput.value;
  3198. var idx = fn.lastIndexOf('.');
  3199. if (title.lastIndexOf('.') < 0 && (!showButtons || idx < 0))
  3200. {
  3201. newMode = (newMode != null) ? newMode : serviceSelect.value;
  3202. var ext = '';
  3203. if (newMode == App.MODE_GOOGLE)
  3204. {
  3205. ext = editorUi.drive.extension;
  3206. }
  3207. else if (newMode == App.MODE_GITHUB)
  3208. {
  3209. ext = editorUi.gitHub.extension;
  3210. }
  3211. else if (newMode == App.MODE_TRELLO)
  3212. {
  3213. ext = editorUi.trello.extension;
  3214. }
  3215. else if (newMode == App.MODE_DROPBOX)
  3216. {
  3217. ext = editorUi.dropbox.extension;
  3218. }
  3219. else if (newMode == App.MODE_ONEDRIVE)
  3220. {
  3221. ext = editorUi.oneDrive.extension;
  3222. }
  3223. else if (newMode == App.MODE_DEVICE)
  3224. {
  3225. ext = '.drawio';
  3226. }
  3227. if (idx >= 0)
  3228. {
  3229. fn = fn.substring(0, idx);
  3230. }
  3231. nameInput.value = fn + ext;
  3232. }
  3233. }
  3234. };
  3235. var btns = document.createElement('div');
  3236. btns.style.marginTop = (showButtons) ? '26px' : '38px';
  3237. btns.style.textAlign = 'center';
  3238. if (!showButtons)
  3239. {
  3240. div.appendChild(serviceSelect);
  3241. mxEvent.addListener(serviceSelect, 'change', change);
  3242. change();
  3243. }
  3244. if (helpLink != null)
  3245. {
  3246. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  3247. {
  3248. editorUi.openLink(helpLink);
  3249. });
  3250. helpBtn.className = 'geBtn';
  3251. btns.appendChild(helpBtn);
  3252. }
  3253. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  3254. {
  3255. if (cancelFn != null)
  3256. {
  3257. cancelFn();
  3258. }
  3259. else
  3260. {
  3261. editorUi.fileLoaded(null);
  3262. editorUi.hideDialog();
  3263. window.close();
  3264. window.location.href = editorUi.getUrl();
  3265. }
  3266. });
  3267. cancelBtn.className = 'geBtn';
  3268. if (editorUi.editor.cancelFirst)
  3269. {
  3270. btns.appendChild(cancelBtn);
  3271. }
  3272. function create(mode)
  3273. {
  3274. var title = nameInput.value;
  3275. if (mode == null || (title != null && title.length > 0))
  3276. {
  3277. editorUi.hideDialog();
  3278. createFn(title, mode);
  3279. };
  3280. }
  3281. if (cancelFn == null)
  3282. {
  3283. var laterBtn = mxUtils.button(mxResources.get('decideLater'), function()
  3284. {
  3285. create(null);
  3286. });
  3287. laterBtn.className = 'geBtn';
  3288. btns.appendChild(laterBtn);
  3289. }
  3290. if (allowTab && Editor.popupsAllowed)
  3291. {
  3292. var openBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
  3293. {
  3294. create('_blank');
  3295. });
  3296. openBtn.className = 'geBtn';
  3297. btns.appendChild(openBtn);
  3298. }
  3299. if (CreateDialog.showDownloadButton)
  3300. {
  3301. var downloadButton = mxUtils.button(mxResources.get('download'), function()
  3302. {
  3303. create('download');
  3304. });
  3305. downloadButton.className = 'geBtn';
  3306. btns.appendChild(downloadButton);
  3307. }
  3308. if (/*!mxClient.IS_IOS || */!showButtons)
  3309. {
  3310. var createBtn = mxUtils.button(btnLabel || mxResources.get('create'), function()
  3311. {
  3312. create((showDeviceButton) ? 'download' : ((showButtons) ? App.MODE_DEVICE : serviceSelect.value));
  3313. });
  3314. createBtn.className = 'geBtn gePrimaryBtn';
  3315. btns.appendChild(createBtn);
  3316. }
  3317. if (!editorUi.editor.cancelFirst)
  3318. {
  3319. btns.appendChild(cancelBtn);
  3320. }
  3321. mxEvent.addListener(nameInput, 'keypress', function(e)
  3322. {
  3323. if (e.keyCode == 13)
  3324. {
  3325. create((showButtons) ? App.MODE_DEVICE : serviceSelect.value);
  3326. }
  3327. else if (e.keyCode == 27)
  3328. {
  3329. editorUi.fileLoaded(null);
  3330. editorUi.hideDialog();
  3331. window.close();
  3332. }
  3333. });
  3334. div.appendChild(btns);
  3335. this.container = div;
  3336. };
  3337. /**
  3338. *
  3339. */
  3340. CreateDialog.showDownloadButton = true;
  3341. /**
  3342. * Constructs a new popup dialog.
  3343. */
  3344. var PopupDialog = function(editorUi, url, pre, fallback, hideDialog)
  3345. {
  3346. hideDialog = (hideDialog != null) ? hideDialog : true;
  3347. var div = document.createElement('div');
  3348. div.style.textAlign = 'left';
  3349. mxUtils.write(div, mxResources.get('fileOpenLocation'));
  3350. mxUtils.br(div);
  3351. mxUtils.br(div);
  3352. var replaceBtn = mxUtils.button(mxResources.get('openInThisWindow'), function()
  3353. {
  3354. if (hideDialog)
  3355. {
  3356. editorUi.hideDialog();
  3357. }
  3358. if (fallback != null)
  3359. {
  3360. fallback();
  3361. }
  3362. });
  3363. replaceBtn.className = 'geBtn';
  3364. replaceBtn.style.marginBottom = '8px';
  3365. replaceBtn.style.width = '280px';
  3366. div.appendChild(replaceBtn);
  3367. mxUtils.br(div);
  3368. var wndBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
  3369. {
  3370. if (hideDialog)
  3371. {
  3372. editorUi.hideDialog();
  3373. }
  3374. if (pre != null)
  3375. {
  3376. pre();
  3377. }
  3378. editorUi.openLink(url, null, true);
  3379. });
  3380. wndBtn.className = 'geBtn gePrimaryBtn';
  3381. wndBtn.style.width = replaceBtn.style.width;
  3382. div.appendChild(wndBtn);
  3383. mxUtils.br(div);
  3384. mxUtils.br(div);
  3385. mxUtils.write(div, mxResources.get('allowPopups'));
  3386. this.container = div;
  3387. };
  3388. /**
  3389. * Constructs a new image dialog.
  3390. */
  3391. var ImageDialog = function(editorUi, title, initialValue, fn, ignoreExisting, convertDataUri)
  3392. {
  3393. convertDataUri = (convertDataUri != null) ? convertDataUri : true;
  3394. var graph = editorUi.editor.graph;
  3395. var div = document.createElement('div');
  3396. mxUtils.write(div, title);
  3397. var inner = document.createElement('div');
  3398. inner.className = 'geTitle';
  3399. inner.style.backgroundColor = 'transparent';
  3400. inner.style.borderColor = 'transparent';
  3401. inner.style.whiteSpace = 'nowrap';
  3402. inner.style.textOverflow = 'clip';
  3403. inner.style.cursor = 'default';
  3404. if (!mxClient.IS_VML)
  3405. {
  3406. inner.style.paddingRight = '20px';
  3407. }
  3408. var linkInput = document.createElement('input');
  3409. linkInput.setAttribute('value', initialValue);
  3410. linkInput.setAttribute('type', 'text');
  3411. linkInput.setAttribute('spellcheck', 'false');
  3412. linkInput.setAttribute('autocorrect', 'off');
  3413. linkInput.setAttribute('autocomplete', 'off');
  3414. linkInput.setAttribute('autocapitalize', 'off');
  3415. linkInput.style.marginTop = '6px';
  3416. var realWidth = (Graph.fileSupport) ? 420 : 340;
  3417. linkInput.style.width = realWidth + ((mxClient.IS_QUIRKS) ? 20 : -20) + 'px';
  3418. linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
  3419. linkInput.style.backgroundRepeat = 'no-repeat';
  3420. linkInput.style.backgroundPosition = '100% 50%';
  3421. linkInput.style.paddingRight = '14px';
  3422. var cross = document.createElement('div');
  3423. cross.setAttribute('title', mxResources.get('reset'));
  3424. cross.style.position = 'relative';
  3425. cross.style.left = '-16px';
  3426. cross.style.width = '12px';
  3427. cross.style.height = '14px';
  3428. cross.style.cursor = 'pointer';
  3429. // Workaround for inline-block not supported in IE
  3430. cross.style.display = (mxClient.IS_VML) ? 'inline' : 'inline-block';
  3431. cross.style.top = ((mxClient.IS_VML) ? 0 : 3) + 'px';
  3432. // Needed to block event transparency in IE
  3433. cross.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
  3434. mxEvent.addListener(cross, 'click', function()
  3435. {
  3436. linkInput.value = '';
  3437. linkInput.focus();
  3438. });
  3439. inner.appendChild(linkInput);
  3440. inner.appendChild(cross);
  3441. div.appendChild(inner);
  3442. var insertImage = function(newValue, w, h, resize)
  3443. {
  3444. var dataUri = newValue.substring(0, 5) == 'data:';
  3445. if (!editorUi.isOffline() || (dataUri && typeof chrome === 'undefined'))
  3446. {
  3447. if (newValue.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('inserting')))
  3448. {
  3449. var maxSize = 520;
  3450. editorUi.loadImage(newValue, function(img)
  3451. {
  3452. editorUi.spinner.stop();
  3453. editorUi.hideDialog();
  3454. var s = (resize === false) ? 1 :
  3455. (w != null && h != null) ? Math.max(w / img.width, h / img.height) :
  3456. Math.min(1, Math.min(maxSize / img.width, maxSize / img.height));
  3457. // Handles special case of data URI which needs to be rewritten
  3458. // to be used in a cell style to remove the semicolon
  3459. if (convertDataUri)
  3460. {
  3461. newValue = editorUi.convertDataUri(newValue);
  3462. }
  3463. fn(newValue, Math.round(Number(img.width) * s), Math.round(Number(img.height) * s));
  3464. }, function()
  3465. {
  3466. editorUi.spinner.stop();
  3467. fn(null);
  3468. editorUi.showError(mxResources.get('error'), mxResources.get('fileNotFound'), mxResources.get('ok'));
  3469. });
  3470. }
  3471. else
  3472. {
  3473. editorUi.hideDialog();
  3474. fn(newValue);
  3475. }
  3476. }
  3477. else
  3478. {
  3479. newValue = editorUi.convertDataUri(newValue);
  3480. w = (w == null) ? 120 : w;
  3481. h = (h == null) ? 100 : h;
  3482. editorUi.hideDialog();
  3483. fn(newValue, w, h);
  3484. }
  3485. };
  3486. var apply = function(newValue, resize)
  3487. {
  3488. if (newValue != null)
  3489. {
  3490. var geo = (ignoreExisting) ? null : graph.getModel().getGeometry(graph.getSelectionCell());
  3491. // Reuses width and height of existing cell
  3492. if (geo != null)
  3493. {
  3494. insertImage(newValue, geo.width, geo.height, resize);
  3495. }
  3496. else
  3497. {
  3498. insertImage(newValue, null, null, resize);
  3499. }
  3500. }
  3501. else
  3502. {
  3503. editorUi.hideDialog();
  3504. fn(null);
  3505. }
  3506. };
  3507. this.init = function()
  3508. {
  3509. linkInput.focus();
  3510. // Installs drag and drop handler for local images and links
  3511. if (Graph.fileSupport)
  3512. {
  3513. linkInput.setAttribute('placeholder', mxResources.get('dragImagesHere'));
  3514. // Setup the dnd listeners
  3515. var dlg = div.parentNode;
  3516. var graph = editorUi.editor.graph;
  3517. var dropElt = null;
  3518. mxEvent.addListener(dlg, 'dragleave', function(evt)
  3519. {
  3520. if (dropElt != null)
  3521. {
  3522. dropElt.parentNode.removeChild(dropElt);
  3523. dropElt = null;
  3524. }
  3525. evt.stopPropagation();
  3526. evt.preventDefault();
  3527. });
  3528. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  3529. {
  3530. // IE 10 does not implement pointer-events so it can't have a drop highlight
  3531. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  3532. {
  3533. dropElt = editorUi.highlightElement(dlg);
  3534. }
  3535. evt.stopPropagation();
  3536. evt.preventDefault();
  3537. }));
  3538. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  3539. {
  3540. if (dropElt != null)
  3541. {
  3542. dropElt.parentNode.removeChild(dropElt);
  3543. dropElt = null;
  3544. }
  3545. if (evt.dataTransfer.files.length > 0)
  3546. {
  3547. editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h, fileName, resize)
  3548. {
  3549. apply(data, resize);
  3550. }, function()
  3551. {
  3552. // No post processing
  3553. }, function(file)
  3554. {
  3555. // Handles only images
  3556. return file.type.substring(0, 6) == 'image/';
  3557. }, function(queue)
  3558. {
  3559. // Invokes elements of queue in order
  3560. for (var i = 0; i < queue.length; i++)
  3561. {
  3562. queue[i]();
  3563. }
  3564. }, !mxEvent.isControlDown(evt));
  3565. }
  3566. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  3567. {
  3568. var uri = evt.dataTransfer.getData('text/uri-list');
  3569. if ((/\.(gif|jpg|jpeg|tiff|png|svg)($|\?)/i).test(uri))
  3570. {
  3571. apply(decodeURIComponent(uri));
  3572. }
  3573. }
  3574. evt.stopPropagation();
  3575. evt.preventDefault();
  3576. }), false);
  3577. }
  3578. };
  3579. var btns = document.createElement('div');
  3580. btns.style.marginTop = (mxClient.IS_QUIRKS) ? '22px' : '14px';
  3581. btns.style.textAlign = 'right';
  3582. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  3583. {
  3584. // Just in case a spinner is spinning, has no effect otherwise
  3585. editorUi.spinner.stop();
  3586. editorUi.hideDialog();
  3587. });
  3588. cancelBtn.className = 'geBtn';
  3589. if (editorUi.editor.cancelFirst)
  3590. {
  3591. btns.appendChild(cancelBtn);
  3592. }
  3593. ImageDialog.filePicked = function(data)
  3594. {
  3595. if (data.action == google.picker.Action.PICKED)
  3596. {
  3597. if (data.docs[0].thumbnails != null)
  3598. {
  3599. var thumb = data.docs[0].thumbnails[data.docs[0].thumbnails.length - 1];
  3600. if (thumb != null)
  3601. {
  3602. linkInput.value = thumb.url;
  3603. }
  3604. }
  3605. }
  3606. linkInput.focus();
  3607. };
  3608. if (Graph.fileSupport)
  3609. {
  3610. var fileInput = document.createElement('input');
  3611. fileInput.setAttribute('multiple', 'multiple');
  3612. fileInput.setAttribute('type', 'file');
  3613. if (document.documentMode == null)
  3614. {
  3615. mxEvent.addListener(fileInput, 'change', function(evt)
  3616. {
  3617. editorUi.importFiles(fileInput.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h)
  3618. {
  3619. apply(data);
  3620. }, function()
  3621. {
  3622. // No post processing
  3623. }, function(file)
  3624. {
  3625. // Handles only images
  3626. return file.type.substring(0, 6) == 'image/';
  3627. }, function(queue)
  3628. {
  3629. // Invokes elements of queue in order
  3630. for (var i = 0; i < queue.length; i++)
  3631. {
  3632. queue[i]();
  3633. }
  3634. }, true);
  3635. });
  3636. var btn = mxUtils.button(mxResources.get('open'), function()
  3637. {
  3638. fileInput.click();
  3639. });
  3640. btn.className = 'geBtn';
  3641. btns.appendChild(btn);
  3642. }
  3643. }
  3644. // Image cropping (experimental)
  3645. if (!!document.createElement('canvas').getContext && linkInput.value.substring(0, 11) == 'data:image/' &&
  3646. linkInput.value.substring(0, 14) != 'data:image/svg')
  3647. {
  3648. var cropBtn = mxUtils.button(mxResources.get('crop'), function()
  3649. {
  3650. var dlg = new CropImageDialog(editorUi, linkInput.value, function(image)
  3651. {
  3652. linkInput.value = image;
  3653. });
  3654. editorUi.showDialog(dlg.container, 200, 185, true, true);
  3655. dlg.init();
  3656. });
  3657. cropBtn.className = 'geBtn';
  3658. btns.appendChild(cropBtn);
  3659. }
  3660. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined' && window.self === window.top)
  3661. {
  3662. var searchBtn = mxUtils.button(mxResources.get('search'), function()
  3663. {
  3664. // Creates one picker and reuses it to avoid polluting the DOM
  3665. if (editorUi.imageSearchPicker == null)
  3666. {
  3667. var picker = new google.picker.PickerBuilder()
  3668. .setLocale(mxLanguage)
  3669. .addView(google.picker.ViewId.IMAGE_SEARCH)
  3670. .enableFeature(google.picker.Feature.NAV_HIDDEN);
  3671. editorUi.imageSearchPicker = picker.setCallback(function(data)
  3672. {
  3673. ImageDialog.filePicked(data);
  3674. }).build();
  3675. }
  3676. editorUi.imageSearchPicker.setVisible(true);
  3677. });
  3678. searchBtn.className = 'geBtn';
  3679. btns.appendChild(searchBtn);
  3680. if (editorUi.drive != null && urlParams['photos'] == '1')
  3681. {
  3682. var gpBtn = mxUtils.button(mxResources.get('googlePlus'), function()
  3683. {
  3684. if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  3685. {
  3686. editorUi.drive.checkToken(mxUtils.bind(this, function()
  3687. {
  3688. editorUi.spinner.stop();
  3689. // Creates one picker and reuses it to avoid polluting the DOM
  3690. if (editorUi.photoPicker == null)
  3691. {
  3692. var token = gapi.auth.getToken().access_token;
  3693. var picker = new google.picker.PickerBuilder()
  3694. .setAppId(editorUi.drive.appId)
  3695. .setLocale(mxLanguage)
  3696. .setOAuthToken(token)
  3697. .addView(google.picker.ViewId.PHOTOS)
  3698. .addView(google.picker.ViewId.PHOTO_ALBUMS)
  3699. .addView(google.picker.ViewId.PHOTO_UPLOAD);
  3700. editorUi.photoPicker = picker.setCallback(function(data)
  3701. {
  3702. ImageDialog.filePicked(data);
  3703. }).build();
  3704. }
  3705. editorUi.photoPicker.setVisible(true);
  3706. }));
  3707. }
  3708. });
  3709. gpBtn.className = 'geBtn';
  3710. btns.appendChild(gpBtn);
  3711. }
  3712. }
  3713. mxEvent.addListener(linkInput, 'keypress', function(e)
  3714. {
  3715. if (e.keyCode == 13)
  3716. {
  3717. apply(linkInput.value);
  3718. }
  3719. });
  3720. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  3721. {
  3722. apply(linkInput.value);
  3723. });
  3724. applyBtn.className = 'geBtn gePrimaryBtn';
  3725. btns.appendChild(applyBtn);
  3726. if (!editorUi.editor.cancelFirst)
  3727. {
  3728. btns.appendChild(cancelBtn);
  3729. }
  3730. // Shows drop icon in dialog background
  3731. if (Graph.fileSupport)
  3732. {
  3733. btns.style.marginTop = '120px';
  3734. div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
  3735. div.style.backgroundPosition = 'center 65%';
  3736. div.style.backgroundRepeat = 'no-repeat';
  3737. var bg = document.createElement('div');
  3738. bg.style.position = 'absolute';
  3739. bg.style.width = '420px';
  3740. bg.style.top = '58%';
  3741. bg.style.textAlign = 'center';
  3742. bg.style.fontSize = '18px';
  3743. bg.style.color = '#a0c3ff';
  3744. mxUtils.write(bg, mxResources.get('dragImagesHere'));
  3745. div.appendChild(bg);
  3746. }
  3747. div.appendChild(btns);
  3748. this.container = div;
  3749. };
  3750. /**
  3751. * Overrides link dialog to add Google Picker.
  3752. */
  3753. var LinkDialog = function(editorUi, initialValue, btnLabel, fn, showPages)
  3754. {
  3755. var div = document.createElement('div');
  3756. mxUtils.write(div, mxResources.get('editLink') + ':');
  3757. var inner = document.createElement('div');
  3758. inner.className = 'geTitle';
  3759. inner.style.backgroundColor = 'transparent';
  3760. inner.style.borderColor = 'transparent';
  3761. inner.style.whiteSpace = 'nowrap';
  3762. inner.style.textOverflow = 'clip';
  3763. inner.style.cursor = 'default';
  3764. if (!mxClient.IS_VML)
  3765. {
  3766. inner.style.paddingRight = '20px';
  3767. }
  3768. var linkInput = document.createElement('input');
  3769. linkInput.setAttribute('placeholder', mxResources.get('dragUrlsHere'));
  3770. linkInput.setAttribute('type', 'text');
  3771. linkInput.style.marginTop = '6px';
  3772. linkInput.style.width = '440px';
  3773. linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
  3774. linkInput.style.backgroundRepeat = 'no-repeat';
  3775. linkInput.style.backgroundPosition = '100% 50%';
  3776. linkInput.style.paddingRight = '14px';
  3777. var cross = document.createElement('div');
  3778. cross.setAttribute('title', mxResources.get('reset'));
  3779. cross.style.position = 'relative';
  3780. cross.style.left = '-16px';
  3781. cross.style.width = '12px';
  3782. cross.style.height = '14px';
  3783. cross.style.cursor = 'pointer';
  3784. // Workaround for inline-block not supported in IE
  3785. cross.style.display = (mxClient.IS_VML) ? 'inline' : 'inline-block';
  3786. cross.style.top = ((mxClient.IS_VML) ? 0 : 3) + 'px';
  3787. // Needed to block event transparency in IE
  3788. cross.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
  3789. mxEvent.addListener(cross, 'click', function()
  3790. {
  3791. linkInput.value = '';
  3792. linkInput.focus();
  3793. });
  3794. var urlRadio = document.createElement('input');
  3795. urlRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  3796. urlRadio.setAttribute('value', 'url');
  3797. urlRadio.setAttribute('type', 'radio');
  3798. urlRadio.setAttribute('name', 'current-linkdialog');
  3799. var pageRadio = document.createElement('input');
  3800. pageRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  3801. pageRadio.setAttribute('value', 'url');
  3802. pageRadio.setAttribute('type', 'radio');
  3803. pageRadio.setAttribute('name', 'current-linkdialog');
  3804. var pageSelect = document.createElement('select');
  3805. pageSelect.style.width = '420px';
  3806. if (showPages && editorUi.pages != null)
  3807. {
  3808. if (initialValue != null && initialValue.substring(0, 13) == 'data:page/id,')
  3809. {
  3810. pageRadio.setAttribute('checked', 'checked');
  3811. pageRadio.defaultChecked = true;
  3812. }
  3813. else
  3814. {
  3815. linkInput.setAttribute('value', initialValue);
  3816. urlRadio.setAttribute('checked', 'checked');
  3817. urlRadio.defaultChecked = true;
  3818. }
  3819. linkInput.style.width = '420px';
  3820. inner.appendChild(urlRadio);
  3821. inner.appendChild(linkInput);
  3822. inner.appendChild(cross);
  3823. mxUtils.br(inner);
  3824. inner.appendChild(pageRadio);
  3825. var pageFound = false;
  3826. for (var i = 0; i < editorUi.pages.length; i++)
  3827. {
  3828. var pageOption = document.createElement('option');
  3829. mxUtils.write(pageOption, editorUi.pages[i].getName() ||
  3830. mxResources.get('pageWithNumber', [i + 1]));
  3831. pageOption.setAttribute('value', 'data:page/id,' +
  3832. editorUi.pages[i].getId());
  3833. if (initialValue == pageOption.getAttribute('value'))
  3834. {
  3835. pageOption.setAttribute('selected', 'selected');
  3836. pageFound = true;
  3837. }
  3838. pageSelect.appendChild(pageOption);
  3839. }
  3840. if (!pageFound && pageRadio.checked)
  3841. {
  3842. var notFoundOption = document.createElement('option');
  3843. mxUtils.write(notFoundOption, mxResources.get('pageNotFound'));
  3844. notFoundOption.setAttribute('disabled', 'disabled');
  3845. notFoundOption.setAttribute('selected', 'selected');
  3846. notFoundOption.setAttribute('value', 'pageNotFound');
  3847. pageSelect.appendChild(notFoundOption);
  3848. mxEvent.addListener(pageSelect, 'change', function()
  3849. {
  3850. if (notFoundOption.parentNode != null && !notFoundOption.selected)
  3851. {
  3852. notFoundOption.parentNode.removeChild(notFoundOption);
  3853. }
  3854. });
  3855. }
  3856. inner.appendChild(pageSelect);
  3857. }
  3858. else
  3859. {
  3860. linkInput.setAttribute('value', initialValue);
  3861. inner.appendChild(linkInput);
  3862. inner.appendChild(cross);
  3863. }
  3864. div.appendChild(inner);
  3865. var mainBtn = mxUtils.button(btnLabel, function()
  3866. {
  3867. editorUi.hideDialog();
  3868. var value = (pageRadio.checked) ? ((pageSelect.value !== 'pageNotFound') ?
  3869. pageSelect.value : initialValue) : linkInput.value;
  3870. fn(value, LinkDialog.selectedDocs);
  3871. });
  3872. mainBtn.style.verticalAlign = 'middle';
  3873. mainBtn.className = 'geBtn gePrimaryBtn';
  3874. this.init = function()
  3875. {
  3876. if (pageRadio.checked)
  3877. {
  3878. pageSelect.focus();
  3879. }
  3880. else
  3881. {
  3882. linkInput.focus();
  3883. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  3884. {
  3885. linkInput.select();
  3886. }
  3887. else
  3888. {
  3889. document.execCommand('selectAll', false, null);
  3890. }
  3891. }
  3892. mxEvent.addListener(pageSelect, 'focus', function()
  3893. {
  3894. urlRadio.removeAttribute('checked');
  3895. pageRadio.setAttribute('checked', 'checked');
  3896. pageRadio.checked = true;
  3897. });
  3898. mxEvent.addListener(linkInput, 'focus', function()
  3899. {
  3900. pageRadio.removeAttribute('checked');
  3901. urlRadio.setAttribute('checked', 'checked');
  3902. urlRadio.checked = true;
  3903. });
  3904. // Installs drag and drop handler for links
  3905. if (Graph.fileSupport)
  3906. {
  3907. // Setup the dnd listeners
  3908. var dlg = div.parentNode;
  3909. var graph = editorUi.editor.graph;
  3910. var dropElt = null;
  3911. mxEvent.addListener(dlg, 'dragleave', function(evt)
  3912. {
  3913. if (dropElt != null)
  3914. {
  3915. dropElt.parentNode.removeChild(dropElt);
  3916. dropElt = null;
  3917. }
  3918. evt.stopPropagation();
  3919. evt.preventDefault();
  3920. });
  3921. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  3922. {
  3923. // IE 10 does not implement pointer-events so it can't have a drop highlight
  3924. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  3925. {
  3926. dropElt = editorUi.highlightElement(dlg);
  3927. }
  3928. evt.stopPropagation();
  3929. evt.preventDefault();
  3930. }));
  3931. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  3932. {
  3933. if (dropElt != null)
  3934. {
  3935. dropElt.parentNode.removeChild(dropElt);
  3936. dropElt = null;
  3937. }
  3938. if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  3939. {
  3940. linkInput.value = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
  3941. urlRadio.setAttribute('checked', 'checked');
  3942. urlRadio.checked = true;
  3943. mainBtn.click();
  3944. }
  3945. evt.stopPropagation();
  3946. evt.preventDefault();
  3947. }), false);
  3948. }
  3949. };
  3950. var btns = document.createElement('div');
  3951. btns.style.marginTop = '20px';
  3952. btns.style.textAlign = 'right';
  3953. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  3954. {
  3955. editorUi.hideDialog();
  3956. });
  3957. cancelBtn.style.verticalAlign = 'middle';
  3958. cancelBtn.className = 'geBtn';
  3959. if (editorUi.editor.cancelFirst)
  3960. {
  3961. btns.appendChild(cancelBtn);
  3962. }
  3963. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  3964. {
  3965. editorUi.openLink('https://desk.draw.io/solution/articles/16000080137');
  3966. });
  3967. helpBtn.style.verticalAlign = 'middle';
  3968. helpBtn.className = 'geBtn';
  3969. btns.appendChild(helpBtn);
  3970. if (editorUi.isOffline() && !mxClient.IS_CHROMEAPP)
  3971. {
  3972. helpBtn.style.display = 'none';
  3973. }
  3974. LinkDialog.selectedDocs = null;
  3975. LinkDialog.filePicked = function(data)
  3976. {
  3977. if (data.action == google.picker.Action.PICKED)
  3978. {
  3979. LinkDialog.selectedDocs = data.docs;
  3980. var href = data.docs[0].url;
  3981. if (data.docs[0].mimeType == 'application/mxe' || (data.docs[0].mimeType != null &&
  3982. data.docs[0].mimeType.substring(0, 23) == 'application/vnd.jgraph.'))
  3983. {
  3984. href = 'https://www.draw.io/#G' + data.docs[0].id;
  3985. }
  3986. else if (data.docs[0].mimeType == 'application/vnd.google-apps.folder')
  3987. {
  3988. // Do not use folderview in data.docs[0].url link to Google Drive instead
  3989. href = 'https://drive.google.com/#folders/' + data.docs[0].id;
  3990. }
  3991. linkInput.value = href;
  3992. linkInput.focus();
  3993. }
  3994. else
  3995. {
  3996. LinkDialog.selectedDocs = null;
  3997. }
  3998. linkInput.focus();
  3999. };
  4000. function addButton(src, tooltip, fn)
  4001. {
  4002. var btn = mxUtils.button('', fn);
  4003. btn.className = 'geBtn';
  4004. btn.setAttribute('title', tooltip);
  4005. var img = document.createElement('img');
  4006. img.style.height = '26px';
  4007. img.style.width = '26px';
  4008. img.setAttribute('src', src);
  4009. btn.style.minWidth = '42px';
  4010. btn.style.verticalAlign = 'middle';
  4011. btn.appendChild(img);
  4012. btns.appendChild(btn);
  4013. };
  4014. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined' && editorUi.drive != null)
  4015. {
  4016. addButton(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googlePlus'), function()
  4017. {
  4018. if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  4019. {
  4020. editorUi.drive.checkToken(mxUtils.bind(this, function()
  4021. {
  4022. editorUi.spinner.stop();
  4023. // Creates one picker and reuses it to avoid polluting the DOM
  4024. if (editorUi.linkPicker == null)
  4025. {
  4026. var token = gapi.auth.getToken().access_token;
  4027. var view = new google.picker.DocsView(google.picker.ViewId.FOLDERS)
  4028. .setParent('root')
  4029. .setIncludeFolders(true)
  4030. .setSelectFolderEnabled(true);
  4031. var view2 = new google.picker.DocsView()
  4032. .setIncludeFolders(true)
  4033. .setSelectFolderEnabled(true);
  4034. var view21 = new google.picker.DocsView()
  4035. .setIncludeFolders(true)
  4036. .setEnableTeamDrives(true)
  4037. .setSelectFolderEnabled(true);
  4038. var picker = new google.picker.PickerBuilder()
  4039. .setAppId(editorUi.drive.appId)
  4040. .setLocale(mxLanguage)
  4041. .setOAuthToken(token)
  4042. .enableFeature(google.picker.Feature.SUPPORT_TEAM_DRIVES)
  4043. .addView(view)
  4044. .addView(view2)
  4045. .addView(view21)
  4046. .addView(google.picker.ViewId.RECENTLY_PICKED)
  4047. .addView(google.picker.ViewId.IMAGE_SEARCH)
  4048. .addView(google.picker.ViewId.VIDEO_SEARCH)
  4049. .addView(google.picker.ViewId.MAPS);
  4050. if (urlParams['photos'] == '1')
  4051. {
  4052. picker.addView(google.picker.ViewId.PHOTOS)
  4053. .addView(google.picker.ViewId.PHOTO_ALBUMS)
  4054. .addView(google.picker.ViewId.PHOTO_UPLOAD)
  4055. }
  4056. editorUi.linkPicker = picker.setCallback(function(data)
  4057. {
  4058. LinkDialog.filePicked(data);
  4059. }).build();
  4060. }
  4061. editorUi.linkPicker.setVisible(true);
  4062. }));
  4063. }
  4064. });
  4065. }
  4066. if (typeof(Dropbox) != 'undefined' && typeof(Dropbox.choose) != 'undefined')
  4067. {
  4068. addButton(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), function()
  4069. {
  4070. // Authentication will be carried out on open to make sure the
  4071. // autosave does not show an auth dialog. Showing it here will
  4072. // block the second dialog (the file picker) so it's too early.
  4073. Dropbox.choose(
  4074. {
  4075. linkType : 'direct',
  4076. cancel: function()
  4077. {
  4078. // do nothing
  4079. },
  4080. success : function(files)
  4081. {
  4082. linkInput.value = files[0].link;
  4083. linkInput.focus();
  4084. }
  4085. });
  4086. });
  4087. }
  4088. if (editorUi.oneDrive != null)
  4089. {
  4090. addButton(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), function()
  4091. {
  4092. editorUi.oneDrive.pickFile(function(id, files)
  4093. {
  4094. linkInput.value = files.value[0].webUrl;
  4095. linkInput.focus();
  4096. });
  4097. });
  4098. }
  4099. if (editorUi.gitHub != null)
  4100. {
  4101. addButton(IMAGE_PATH + '/github-logo.svg', mxResources.get('github'), function()
  4102. {
  4103. editorUi.gitHub.pickFile(function(path)
  4104. {
  4105. if (path != null)
  4106. {
  4107. var tokens = path.split('/');
  4108. var org = tokens[0];
  4109. var repo = tokens[1];
  4110. var ref = tokens[2];
  4111. var path = tokens.slice(3, tokens.length).join('/');
  4112. linkInput.value = 'https://github.com/' + org + '/' +
  4113. repo + '/blob/' + ref + '/' + path;
  4114. linkInput.focus();
  4115. }
  4116. });
  4117. });
  4118. }
  4119. //TODO should Trello support this?
  4120. mxEvent.addListener(linkInput, 'keypress', function(e)
  4121. {
  4122. if (e.keyCode == 13)
  4123. {
  4124. editorUi.hideDialog();
  4125. var value = (pageRadio.checked) ? pageSelect.value : linkInput.value;
  4126. fn(value, LinkDialog.selectedDocs);
  4127. }
  4128. });
  4129. btns.appendChild(mainBtn);
  4130. if (!editorUi.editor.cancelFirst)
  4131. {
  4132. btns.appendChild(cancelBtn);
  4133. }
  4134. div.appendChild(btns);
  4135. this.container = div;
  4136. };
  4137. /**
  4138. * Constructs a new about dialog
  4139. */
  4140. var AboutDialog = function(editorUi)
  4141. {
  4142. var div = document.createElement('div');
  4143. div.style.marginTop = '6px';
  4144. div.setAttribute('align', 'center');
  4145. var img = document.createElement('img');
  4146. img.style.border = '0px';
  4147. if (mxClient.IS_SVG)
  4148. {
  4149. img.setAttribute('width', '164');
  4150. img.setAttribute('height', '221');
  4151. img.style.width = '164px';
  4152. img.style.height = '221px';
  4153. img.setAttribute('src', IMAGE_PATH + '/drawlogo-text-bottom.svg');
  4154. }
  4155. else
  4156. {
  4157. img.setAttribute('width', '176');
  4158. img.setAttribute('height', '219');
  4159. img.style.width = '170px';
  4160. img.style.height = '219px';
  4161. img.setAttribute('src', IMAGE_PATH + '/logo-flat.png');
  4162. }
  4163. if (uiTheme == 'dark')
  4164. {
  4165. img.style.filter = 'grayscale(100%) invert(100%)';
  4166. }
  4167. div.appendChild(img);
  4168. mxUtils.br(div);
  4169. var clr = (uiTheme == 'dark') ? '#cccccc' : '#505050';
  4170. var v = document.createElement('small');
  4171. v.innerHTML = 'v ' + EditorUi.VERSION;
  4172. v.style.color = clr;
  4173. div.appendChild(v);
  4174. mxUtils.br(div);
  4175. mxUtils.br(div);
  4176. var small = document.createElement('small');
  4177. small.style.color = clr;
  4178. small.innerHTML = '&copy; 2005-2019 <a href="https://about.draw.io/" style="color:inherit;" target="_blank">JGraph Ltd</a>.<br>All Rights Reserved.';
  4179. div.appendChild(small);
  4180. mxEvent.addListener(div, 'click', function(e)
  4181. {
  4182. if (mxEvent.getSource(e).nodeName != 'A')
  4183. {
  4184. editorUi.hideDialog();
  4185. }
  4186. });
  4187. this.container = div;
  4188. };
  4189. /**
  4190. * Constructs a new about dialog
  4191. */
  4192. var FeedbackDialog = function(editorUi)
  4193. {
  4194. var div = document.createElement('div');
  4195. var label = document.createElement('div');
  4196. mxUtils.write(label, mxResources.get('sendYourFeedbackToDrawIo'));
  4197. label.style.fontSize = '18px';
  4198. label.style.marginBottom = '18px';
  4199. div.appendChild(label);
  4200. label = document.createElement('div');
  4201. mxUtils.write(label, mxResources.get('yourEmailAddress') + ' (' + mxResources.get('required') + ')');
  4202. div.appendChild(label);
  4203. var email = document.createElement('input');
  4204. email.setAttribute('type', 'text');
  4205. email.style.marginTop = '6px';
  4206. email.style.width = '600px';
  4207. var sendButton = mxUtils.button(mxResources.get('sendMessage'), function()
  4208. {
  4209. var diagram = textarea.value +
  4210. ((cb.checked) ? '\nDiagram:\n' + mxUtils.getXml(editorUi.getXmlFileData()) : '') +
  4211. '\nBrowser:\n' + navigator.userAgent;
  4212. if (diagram.length > FeedbackDialog.maxAttachmentSize)
  4213. {
  4214. editorUi.alert(mxResources.get('drawingTooLarge'));
  4215. }
  4216. else
  4217. {
  4218. editorUi.hideDialog();
  4219. if (editorUi.spinner.spin(document.body))
  4220. {
  4221. var postUrl = (FeedbackDialog.feedbackUrl != null) ? FeedbackDialog.feedbackUrl : '/email';
  4222. mxUtils.post(postUrl, 'email=' + encodeURIComponent(email.value) +
  4223. '&version=' + encodeURIComponent(EditorUi.VERSION) +
  4224. '&url=' + encodeURIComponent(window.location.href) +
  4225. '&body=' + encodeURIComponent('Feedback:\n' + diagram),
  4226. function(req)
  4227. {
  4228. editorUi.spinner.stop();
  4229. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  4230. {
  4231. editorUi.alert(mxResources.get('feedbackSent'));
  4232. }
  4233. else
  4234. {
  4235. editorUi.alert(mxResources.get('errorSendingFeedback'));
  4236. }
  4237. },
  4238. function()
  4239. {
  4240. editorUi.spinner.stop();
  4241. editorUi.alert(mxResources.get('errorSendingFeedback'));
  4242. });
  4243. }
  4244. }
  4245. });
  4246. sendButton.className = 'geBtn gePrimaryBtn';
  4247. sendButton.setAttribute('disabled', 'disabled');
  4248. 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,}))$/;
  4249. mxEvent.addListener(email, 'change', function()
  4250. {
  4251. if (email.value.length > 0 && re.test(email.value) > 0)
  4252. {
  4253. sendButton.removeAttribute('disabled');
  4254. }
  4255. else
  4256. {
  4257. sendButton.setAttribute('disabled', 'disabled');
  4258. }
  4259. });
  4260. mxEvent.addListener(email, 'keyup', function()
  4261. {
  4262. if (email.value.length > 0 && re.test(email.value))
  4263. {
  4264. sendButton.removeAttribute('disabled');
  4265. }
  4266. else
  4267. {
  4268. sendButton.setAttribute('disabled', 'disabled');
  4269. }
  4270. });
  4271. div.appendChild(email);
  4272. this.init = function()
  4273. {
  4274. email.focus();
  4275. };
  4276. var cb = document.createElement('input');
  4277. cb.setAttribute('type', 'checkbox');
  4278. cb.setAttribute('checked', 'checked');
  4279. cb.defaultChecked = true;
  4280. var p2 = document.createElement('p');
  4281. p2.style.marginTop = '14px';
  4282. p2.appendChild(cb);
  4283. var span = document.createElement('span');
  4284. mxUtils.write(span, ' ' + mxResources.get('includeCopyOfMyDiagram'));
  4285. p2.appendChild(span);
  4286. mxEvent.addListener(span, 'click', function(evt)
  4287. {
  4288. cb.checked = !cb.checked;
  4289. mxEvent.consume(evt);
  4290. });
  4291. div.appendChild(p2);
  4292. label = document.createElement('div');
  4293. mxUtils.write(label, mxResources.get('feedback'));
  4294. div.appendChild(label);
  4295. var textarea = document.createElement('textarea');
  4296. textarea.style.resize = 'none';
  4297. textarea.style.width = '600px';
  4298. textarea.style.height = '140px';
  4299. textarea.style.marginTop = '6px';
  4300. textarea.setAttribute('placeholder', mxResources.get('comments'));
  4301. div.appendChild(textarea);
  4302. var buttons = document.createElement('div');
  4303. buttons.style.marginTop = '26px';
  4304. buttons.style.textAlign = 'right';
  4305. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  4306. {
  4307. editorUi.hideDialog();
  4308. });
  4309. cancelBtn.className = 'geBtn';
  4310. if (editorUi.editor.cancelFirst)
  4311. {
  4312. buttons.appendChild(cancelBtn);
  4313. buttons.appendChild(sendButton);
  4314. }
  4315. else
  4316. {
  4317. buttons.appendChild(sendButton);
  4318. buttons.appendChild(cancelBtn);
  4319. }
  4320. div.appendChild(buttons);
  4321. this.container = div;
  4322. };
  4323. /**
  4324. * Maximum size of attachments in bytes. Default is 1000000.
  4325. */
  4326. FeedbackDialog.maxAttachmentSize = 1000000;
  4327. /**
  4328. * Constructs a new revision dialog
  4329. */
  4330. var RevisionDialog = function(editorUi, revs, restoreFn)
  4331. {
  4332. var div = document.createElement('div');
  4333. var title = document.createElement('h3');
  4334. title.style.marginTop = '0px';
  4335. mxUtils.write(title, mxResources.get('revisionHistory'));
  4336. div.appendChild(title);
  4337. var list = document.createElement('div');
  4338. list.style.position = 'absolute';
  4339. list.style.overflow = 'auto';
  4340. list.style.width = '170px';
  4341. list.style.height = '378px';
  4342. div.appendChild(list);
  4343. var container = document.createElement('div');
  4344. container.style.position = 'absolute';
  4345. container.style.border = '1px solid lightGray';
  4346. container.style.left = '199px';
  4347. container.style.width = '470px';
  4348. container.style.height = '376px';
  4349. container.style.overflow = 'hidden';
  4350. mxEvent.disableContextMenu(container);
  4351. div.appendChild(container);
  4352. var graph = new Graph(container);
  4353. graph.setTooltips(false);
  4354. graph.setEnabled(false);
  4355. graph.setPanning(true);
  4356. graph.panningHandler.ignoreCell = true;
  4357. graph.panningHandler.useLeftButtonForPanning = true;
  4358. graph.minFitScale = null;
  4359. graph.maxFitScale = null;
  4360. graph.centerZoom = true;
  4361. // Handles placeholders for pages
  4362. var currentPage = 0;
  4363. var diagrams = null;
  4364. var realPage = 0;
  4365. var graphGetGlobalVariable = graph.getGlobalVariable;
  4366. graph.getGlobalVariable = function(name)
  4367. {
  4368. if (name == 'page' && diagrams != null && diagrams[realPage] != null)
  4369. {
  4370. return diagrams[realPage].getAttribute('name');
  4371. }
  4372. else if (name == 'pagenumber')
  4373. {
  4374. return realPage + 1;
  4375. }
  4376. return graphGetGlobalVariable.apply(this, arguments);
  4377. };
  4378. // Disables hyperlinks
  4379. graph.getLinkForCell = function()
  4380. {
  4381. return null;
  4382. };
  4383. if (Editor.MathJaxRender)
  4384. {
  4385. graph.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
  4386. {
  4387. // LATER: Math support is used if current graph has math enabled
  4388. // should use switch from history instead but requires setting the
  4389. // global mxClient.NO_FO switch
  4390. if (editorUi.editor.graph.mathEnabled)
  4391. {
  4392. Editor.MathJaxRender(graph.container);
  4393. }
  4394. }));
  4395. }
  4396. var opts = {
  4397. lines: 11, // The number of lines to draw
  4398. length: 15, // The length of each line
  4399. width: 6, // The line thickness
  4400. radius: 10, // The radius of the inner circle
  4401. corners: 1, // Corner roundness (0..1)
  4402. rotate: 0, // The rotation offset
  4403. direction: 1, // 1: clockwise, -1: counterclockwise
  4404. color: '#000', // #rgb or #rrggbb or array of colors
  4405. speed: 1.4, // Rounds per second
  4406. trail: 60, // Afterglow percentage
  4407. shadow: false, // Whether to render a shadow
  4408. hwaccel: false, // Whether to use hardware acceleration
  4409. className: 'spinner', // The CSS class to assign to the spinner
  4410. zIndex: 2e9, // The z-index (defaults to 2000000000)
  4411. top: '50%', // Top position relative to parent
  4412. left: '50%' // Left position relative to parent
  4413. };
  4414. var spinner = new Spinner(opts);
  4415. var file = editorUi.getCurrentFile();
  4416. var currentRow = null;
  4417. var currentRev = null;
  4418. var currentDoc = null;
  4419. var currentXml = null;
  4420. var zoomInBtn = mxUtils.button('', function()
  4421. {
  4422. if (currentDoc != null)
  4423. {
  4424. graph.zoomIn();
  4425. }
  4426. });
  4427. zoomInBtn.className = 'geSprite geSprite-zoomin';
  4428. zoomInBtn.setAttribute('title', mxResources.get('zoomIn'));
  4429. zoomInBtn.style.outline = 'none';
  4430. zoomInBtn.style.border = 'none';
  4431. zoomInBtn.style.margin = '2px';
  4432. zoomInBtn.setAttribute('disabled', 'disabled');
  4433. mxUtils.setOpacity(zoomInBtn, 20);
  4434. var zoomOutBtn = mxUtils.button('', function()
  4435. {
  4436. if (currentDoc != null)
  4437. {
  4438. graph.zoomOut();
  4439. }
  4440. });
  4441. zoomOutBtn.className = 'geSprite geSprite-zoomout';
  4442. zoomOutBtn.setAttribute('title', mxResources.get('zoomOut'));
  4443. zoomOutBtn.style.outline = 'none';
  4444. zoomOutBtn.style.border = 'none';
  4445. zoomOutBtn.style.margin = '2px';
  4446. zoomOutBtn.setAttribute('disabled', 'disabled');
  4447. mxUtils.setOpacity(zoomOutBtn, 20);
  4448. var zoomFitBtn = mxUtils.button('', function()
  4449. {
  4450. if (currentDoc != null)
  4451. {
  4452. graph.maxFitScale = 8;
  4453. graph.fit(8);
  4454. graph.center();
  4455. }
  4456. });
  4457. zoomFitBtn.className = 'geSprite geSprite-fit';
  4458. zoomFitBtn.setAttribute('title', mxResources.get('fit'));
  4459. zoomFitBtn.style.outline = 'none';
  4460. zoomFitBtn.style.border = 'none';
  4461. zoomFitBtn.style.margin = '2px';
  4462. zoomFitBtn.setAttribute('disabled', 'disabled');
  4463. mxUtils.setOpacity(zoomFitBtn, 20);
  4464. var zoomActualBtn = mxUtils.button('', function()
  4465. {
  4466. if (currentDoc != null)
  4467. {
  4468. graph.zoomActual();
  4469. graph.center();
  4470. }
  4471. });
  4472. zoomActualBtn.className = 'geSprite geSprite-actualsize';
  4473. zoomActualBtn.setAttribute('title', mxResources.get('actualSize'));
  4474. zoomActualBtn.style.outline = 'none';
  4475. zoomActualBtn.style.border = 'none';
  4476. zoomActualBtn.style.margin = '2px';
  4477. zoomActualBtn.setAttribute('disabled', 'disabled');
  4478. mxUtils.setOpacity(zoomActualBtn, 20);
  4479. var fileInfo = document.createElement('div');
  4480. fileInfo.style.position = 'absolute';
  4481. fileInfo.style.textAlign = 'right';
  4482. fileInfo.style.color = 'gray';
  4483. fileInfo.style.marginTop = '10px';
  4484. fileInfo.style.backgroundColor = 'transparent';
  4485. fileInfo.style.top = '440px';
  4486. fileInfo.style.right = '32px';
  4487. fileInfo.style.maxWidth = '380px';
  4488. fileInfo.style.cursor = 'default';
  4489. var downloadBtn = mxUtils.button(mxResources.get('download'), function()
  4490. {
  4491. if (currentDoc != null)
  4492. {
  4493. var data = mxUtils.getXml(currentDoc.documentElement);
  4494. var filename = editorUi.getBaseFilename() + '.drawio';
  4495. if (editorUi.isLocalFileSave())
  4496. {
  4497. editorUi.saveLocalFile(data, filename, 'text/xml');
  4498. }
  4499. else
  4500. {
  4501. var param = (typeof(pako) === 'undefined') ? '&xml=' + encodeURIComponent(data) :
  4502. '&data=' + encodeURIComponent(Graph.compress(data));
  4503. new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(filename) +
  4504. '&format=xml' + param).simulate(document, '_blank');
  4505. }
  4506. }
  4507. });
  4508. downloadBtn.className = 'geBtn';
  4509. downloadBtn.setAttribute('disabled', 'disabled');
  4510. var restoreBtn = mxUtils.button(mxResources.get('restore'), function()
  4511. {
  4512. if (currentDoc != null && currentXml != null)
  4513. {
  4514. editorUi.confirm(mxResources.get('areYouSure'), function()
  4515. {
  4516. if (restoreFn != null)
  4517. {
  4518. restoreFn(currentXml);
  4519. }
  4520. else
  4521. {
  4522. if (editorUi.spinner.spin(document.body, mxResources.get('restoring')))
  4523. {
  4524. file.save(true, function(resp)
  4525. {
  4526. editorUi.spinner.stop();
  4527. editorUi.replaceFileData(currentXml);
  4528. editorUi.hideDialog();
  4529. }, function(resp)
  4530. {
  4531. editorUi.spinner.stop();
  4532. editorUi.editor.setStatus('');
  4533. editorUi.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
  4534. });
  4535. }
  4536. }
  4537. });
  4538. }
  4539. });
  4540. restoreBtn.className = 'geBtn';
  4541. restoreBtn.setAttribute('disabled', 'disabled');
  4542. var pageSelect = document.createElement('select');
  4543. pageSelect.setAttribute('disabled', 'disabled');
  4544. pageSelect.style.maxWidth = '80px';
  4545. pageSelect.style.position = 'relative';
  4546. pageSelect.style.top = '-2px';
  4547. pageSelect.style.verticalAlign = 'bottom';
  4548. pageSelect.style.marginRight = '6px';
  4549. pageSelect.style.display = 'none';
  4550. var pageSelectFunction = null;
  4551. mxEvent.addListener(pageSelect, 'change', function(evt)
  4552. {
  4553. if (pageSelectFunction != null)
  4554. {
  4555. pageSelectFunction(evt);
  4556. mxEvent.consume(evt);
  4557. }
  4558. });
  4559. var newBtn = mxUtils.button(mxResources.get('edit'), function()
  4560. {
  4561. if (currentDoc != null)
  4562. {
  4563. window.openFile = new OpenFile(function()
  4564. {
  4565. window.openFile = null;
  4566. });
  4567. window.openFile.setData(mxUtils.getXml(currentDoc.documentElement));
  4568. editorUi.openLink(editorUi.getUrl(), null, true);
  4569. }
  4570. });
  4571. newBtn.className = 'geBtn';
  4572. newBtn.setAttribute('disabled', 'disabled');
  4573. if (restoreFn != null)
  4574. {
  4575. newBtn.style.display = 'none';
  4576. }
  4577. var showBtn = mxUtils.button(mxResources.get('show'), function()
  4578. {
  4579. if (currentRev != null)
  4580. {
  4581. editorUi.openLink(currentRev.getUrl(pageSelect.selectedIndex));
  4582. }
  4583. });
  4584. showBtn.className = 'geBtn gePrimaryBtn';
  4585. showBtn.setAttribute('disabled', 'disabled');
  4586. if (restoreFn != null)
  4587. {
  4588. showBtn.style.display = 'none';
  4589. restoreBtn.className = 'geBtn gePrimaryBtn';
  4590. }
  4591. var buttons = document.createElement('div');
  4592. buttons.style.position = 'absolute';
  4593. buttons.style.top = '482px';
  4594. buttons.style.width = '640px';
  4595. buttons.style.textAlign = 'right';
  4596. var tb = document.createElement('div');
  4597. tb.className = 'geToolbarContainer';
  4598. tb.style.backgroundColor = 'transparent';
  4599. tb.style.padding = '2px';
  4600. tb.style.border = 'none';
  4601. tb.style.left = '199px';
  4602. tb.style.top = '442px';
  4603. var currentElt = null;
  4604. if (revs != null && revs.length > 0)
  4605. {
  4606. container.style.cursor = 'move';
  4607. var table = document.createElement('table');
  4608. table.style.border = '1px solid lightGray';
  4609. table.style.borderCollapse = 'collapse';
  4610. table.style.borderSpacing = '0px';
  4611. table.style.width = '100%';
  4612. var tbody = document.createElement('tbody');
  4613. var today = new Date().toDateString();
  4614. if (editorUi.currentPage != null && editorUi.pages != null)
  4615. {
  4616. currentPage = mxUtils.indexOf(editorUi.pages, editorUi.currentPage);
  4617. }
  4618. for (var i = revs.length - 1; i >= 0; i--)
  4619. {
  4620. var elt = (function(item)
  4621. {
  4622. var ts = new Date(item.modifiedDate);
  4623. var row = null;
  4624. var pd = '6px';
  4625. // Workaround for negative timestamps in Dropbox
  4626. if (ts.getTime() >= 0)
  4627. {
  4628. row = document.createElement('tr');
  4629. row.style.borderBottom = '1px solid lightGray';
  4630. row.style.fontSize = '12px';
  4631. row.style.cursor = 'pointer';
  4632. var date = document.createElement('td');
  4633. date.style.padding = pd;
  4634. date.style.whiteSpace = 'nowrap';
  4635. if (item == revs[revs.length - 1])
  4636. {
  4637. mxUtils.write(date, mxResources.get('current'));
  4638. }
  4639. else
  4640. {
  4641. if (ts.toDateString() === today)
  4642. {
  4643. mxUtils.write(date, ts.toLocaleTimeString());
  4644. }
  4645. else
  4646. {
  4647. mxUtils.write(date, ts.toLocaleDateString() + ' ' +
  4648. ts.toLocaleTimeString());
  4649. }
  4650. }
  4651. row.appendChild(date);
  4652. row.setAttribute('title', ts.toLocaleDateString() + ' ' +
  4653. ts.toLocaleTimeString() + ' ' +
  4654. editorUi.formatFileSize(parseInt(item.fileSize)) +
  4655. ((item.lastModifyingUserName != null) ? ' ' +
  4656. item.lastModifyingUserName : ''));
  4657. function updateGraph(xml)
  4658. {
  4659. spinner.stop();
  4660. var doc = mxUtils.parseXml(xml);
  4661. var node = editorUi.editor.extractGraphModel(doc.documentElement, true);
  4662. if (node != null)
  4663. {
  4664. pageSelect.style.display = 'none';
  4665. pageSelect.innerHTML = '';
  4666. currentDoc = doc;
  4667. currentXml = xml;
  4668. parseSelectFunction = null;
  4669. diagrams = null;
  4670. realPage = 0;
  4671. function parseGraphModel(dataNode)
  4672. {
  4673. var bg = dataNode.getAttribute('background');
  4674. if (bg == null || bg == '' || bg == mxConstants.NONE)
  4675. {
  4676. bg = '#ffffff';
  4677. }
  4678. container.style.backgroundColor = bg;
  4679. var codec = new mxCodec(dataNode.ownerDocument);
  4680. codec.decode(dataNode, graph.getModel());
  4681. graph.maxFitScale = 1;
  4682. graph.fit(8);
  4683. graph.center();
  4684. return dataNode;
  4685. }
  4686. function parseDiagram(diagramNode)
  4687. {
  4688. if (diagramNode != null)
  4689. {
  4690. diagramNode = parseGraphModel(mxUtils.parseXml(Graph.decompress(
  4691. mxUtils.getTextContent(diagramNode))).documentElement);
  4692. }
  4693. return diagramNode;
  4694. }
  4695. if (node.nodeName == 'mxfile')
  4696. {
  4697. // Workaround for "invalid calling object" error in IE
  4698. var tmp = node.getElementsByTagName('diagram');
  4699. diagrams = [];
  4700. for (var i = 0; i < tmp.length; i++)
  4701. {
  4702. diagrams.push(tmp[i]);
  4703. }
  4704. realPage = Math.min(currentPage, diagrams.length - 1);
  4705. if (diagrams.length > 0)
  4706. {
  4707. parseDiagram(diagrams[realPage]);
  4708. }
  4709. if (diagrams.length > 1)
  4710. {
  4711. pageSelect.removeAttribute('disabled');
  4712. pageSelect.style.display = '';
  4713. for (var i = 0; i < diagrams.length; i++)
  4714. {
  4715. var pageOption = document.createElement('option');
  4716. mxUtils.write(pageOption, diagrams[i].getAttribute('name') ||
  4717. mxResources.get('pageWithNumber', [i + 1]));
  4718. pageOption.setAttribute('value', i);
  4719. if (i == realPage)
  4720. {
  4721. pageOption.setAttribute('selected', 'selected');
  4722. }
  4723. pageSelect.appendChild(pageOption);
  4724. }
  4725. }
  4726. pageSelectFunction = function()
  4727. {
  4728. try
  4729. {
  4730. var temp = parseInt(pageSelect.value);
  4731. parseDiagram(diagrams[temp]);
  4732. currentPage = temp;
  4733. realPage = currentPage;
  4734. }
  4735. catch (e)
  4736. {
  4737. pageSelect.value = currentPage;
  4738. editorUi.handleError(e);
  4739. }
  4740. };
  4741. }
  4742. else
  4743. {
  4744. parseGraphModel(node);
  4745. }
  4746. var shortUser = item.lastModifyingUserName;
  4747. if (shortUser != null && shortUser.length > 20)
  4748. {
  4749. shortUser = shortUser.substring(0, 20) + '...';
  4750. }
  4751. fileInfo.innerHTML = '';
  4752. mxUtils.write(fileInfo, ((shortUser != null) ?
  4753. (shortUser + ' ') : '') + ts.toLocaleDateString() +
  4754. ' ' + ts.toLocaleTimeString());
  4755. fileInfo.setAttribute('title', row.getAttribute('title'));
  4756. zoomInBtn.removeAttribute('disabled');
  4757. zoomOutBtn.removeAttribute('disabled');
  4758. zoomFitBtn.removeAttribute('disabled');
  4759. zoomActualBtn.removeAttribute('disabled');
  4760. if (file == null || !file.isRestricted())
  4761. {
  4762. if (editorUi.editor.graph.isEnabled())
  4763. {
  4764. restoreBtn.removeAttribute('disabled');
  4765. }
  4766. downloadBtn.removeAttribute('disabled');
  4767. showBtn.removeAttribute('disabled');
  4768. newBtn.removeAttribute('disabled');
  4769. }
  4770. mxUtils.setOpacity(zoomInBtn, 60);
  4771. mxUtils.setOpacity(zoomOutBtn, 60);
  4772. mxUtils.setOpacity(zoomFitBtn, 60);
  4773. mxUtils.setOpacity(zoomActualBtn, 60);
  4774. }
  4775. else
  4776. {
  4777. pageSelect.style.display = 'none';
  4778. pageSelect.innerHTML = '';
  4779. fileInfo.innerHTML = '';
  4780. mxUtils.write(fileInfo, mxResources.get('errorLoadingFile'));
  4781. }
  4782. };
  4783. mxEvent.addListener(row, 'click', function(evt)
  4784. {
  4785. if (currentRev != item)
  4786. {
  4787. spinner.stop();
  4788. if (currentRow != null)
  4789. {
  4790. currentRow.style.backgroundColor = '';
  4791. }
  4792. currentRev = item;
  4793. currentRow = row;
  4794. currentRow.style.backgroundColor = '#ebf2f9';
  4795. currentDoc = null;
  4796. currentXml = null;
  4797. fileInfo.removeAttribute('title');
  4798. fileInfo.innerHTML = mxUtils.htmlEntities(mxResources.get('loading') + '...');
  4799. container.style.backgroundColor = '#ffffff';
  4800. graph.getModel().clear();
  4801. restoreBtn.setAttribute('disabled', 'disabled');
  4802. downloadBtn.setAttribute('disabled', 'disabled');
  4803. zoomInBtn.setAttribute('disabled', 'disabled');
  4804. zoomOutBtn.setAttribute('disabled', 'disabled');
  4805. zoomActualBtn.setAttribute('disabled', 'disabled');
  4806. zoomFitBtn.setAttribute('disabled', 'disabled');
  4807. newBtn.setAttribute('disabled', 'disabled');
  4808. showBtn.setAttribute('disabled', 'disabled');
  4809. pageSelect.setAttribute('disabled', 'disabled');
  4810. mxUtils.setOpacity(zoomInBtn, 20);
  4811. mxUtils.setOpacity(zoomOutBtn, 20);
  4812. mxUtils.setOpacity(zoomFitBtn, 20);
  4813. mxUtils.setOpacity(zoomActualBtn, 20);
  4814. spinner.spin(container);
  4815. item.getXml(function(xml)
  4816. {
  4817. if (currentRev == item)
  4818. {
  4819. try
  4820. {
  4821. updateGraph(xml);
  4822. }
  4823. catch (e)
  4824. {
  4825. fileInfo.innerHTML = mxUtils.htmlEntities(
  4826. mxResources.get('error') + ': ' + e.message);
  4827. }
  4828. }
  4829. }, function(err)
  4830. {
  4831. spinner.stop();
  4832. pageSelect.style.display = 'none';
  4833. pageSelect.innerHTML = '';
  4834. fileInfo.innerHTML = '';
  4835. mxUtils.write(fileInfo, mxResources.get('errorLoadingFile'));
  4836. });
  4837. mxEvent.consume(evt);
  4838. }
  4839. });
  4840. mxEvent.addListener(row, 'dblclick', function(evt)
  4841. {
  4842. showBtn.click();
  4843. if (window.getSelection)
  4844. {
  4845. window.getSelection().removeAllRanges();
  4846. }
  4847. else if (document.selection)
  4848. {
  4849. document.selection.empty();
  4850. }
  4851. mxEvent.consume(evt);
  4852. }, false);
  4853. tbody.appendChild(row);
  4854. }
  4855. return row;
  4856. })(revs[i]);
  4857. // Selects and loads first element in list (ie current version) after
  4858. // graph container was initialized since there is no loading delay
  4859. if (elt != null && i == revs.length - 1)
  4860. {
  4861. currentElt = elt;
  4862. }
  4863. }
  4864. table.appendChild(tbody);
  4865. list.appendChild(table);
  4866. }
  4867. else if (file == null || (editorUi.drive == null && file.constructor == window.DriveFile) ||
  4868. (editorUi.dropbox == null && file.constructor == window.DropboxFile))
  4869. {
  4870. container.style.display = 'none';
  4871. tb.style.display = 'none';
  4872. mxUtils.write(list, mxResources.get('notAvailable'));
  4873. }
  4874. else
  4875. {
  4876. container.style.display = 'none';
  4877. tb.style.display = 'none';
  4878. mxUtils.write(list, mxResources.get('noRevisions'));
  4879. }
  4880. this.init = function()
  4881. {
  4882. if (currentElt != null)
  4883. {
  4884. currentElt.click();
  4885. }
  4886. };
  4887. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  4888. {
  4889. editorUi.hideDialog();
  4890. });
  4891. closeBtn.className = 'geBtn';
  4892. tb.appendChild(pageSelect);
  4893. tb.appendChild(zoomInBtn);
  4894. tb.appendChild(zoomOutBtn);
  4895. tb.appendChild(zoomActualBtn);
  4896. tb.appendChild(zoomFitBtn);
  4897. if (editorUi.editor.cancelFirst)
  4898. {
  4899. buttons.appendChild(closeBtn);
  4900. buttons.appendChild(downloadBtn);
  4901. buttons.appendChild(newBtn);
  4902. buttons.appendChild(restoreBtn);
  4903. buttons.appendChild(showBtn);
  4904. }
  4905. else
  4906. {
  4907. buttons.appendChild(downloadBtn);
  4908. buttons.appendChild(newBtn);
  4909. buttons.appendChild(restoreBtn);
  4910. buttons.appendChild(showBtn);
  4911. buttons.appendChild(closeBtn);
  4912. }
  4913. div.appendChild(buttons);
  4914. div.appendChild(tb);
  4915. div.appendChild(fileInfo);
  4916. this.container = div;
  4917. };
  4918. /**
  4919. * Constructs a new revision dialog
  4920. */
  4921. var DraftDialog = function(editorUi, title, xml, editFn, discardFn, editLabel, discardLabel, ignoreFn)
  4922. {
  4923. var div = document.createElement('div');
  4924. var titleDiv = document.createElement('div');
  4925. titleDiv.style.marginTop = '0px';
  4926. titleDiv.style.whiteSpace = 'nowrap';
  4927. titleDiv.style.overflow = 'auto';
  4928. mxUtils.write(titleDiv, title);
  4929. div.appendChild(titleDiv);
  4930. var container = document.createElement('div');
  4931. container.style.position = 'absolute';
  4932. container.style.border = '1px solid lightGray';
  4933. container.style.marginTop = '10px';
  4934. container.style.width = '640px';
  4935. container.style.top = '46px';
  4936. container.style.bottom = '74px';
  4937. container.style.overflow = 'hidden';
  4938. mxEvent.disableContextMenu(container);
  4939. div.appendChild(container);
  4940. var graph = new Graph(container);
  4941. graph.setEnabled(false);
  4942. graph.setPanning(true);
  4943. graph.panningHandler.ignoreCell = true;
  4944. graph.panningHandler.useLeftButtonForPanning = true;
  4945. graph.minFitScale = null;
  4946. graph.maxFitScale = null;
  4947. graph.centerZoom = true;
  4948. // Handles placeholders for pages
  4949. var doc = mxUtils.parseXml(xml);
  4950. var node = editorUi.editor.extractGraphModel(doc.documentElement, true);
  4951. var currentPage = 0;
  4952. var diagrams = null;
  4953. var graphGetGlobalVariable = graph.getGlobalVariable;
  4954. graph.getGlobalVariable = function(name)
  4955. {
  4956. if (name == 'page' && diagrams != null && diagrams[currentPage] != null)
  4957. {
  4958. return diagrams[currentPage].getAttribute('name');
  4959. }
  4960. else if (name == 'pagenumber')
  4961. {
  4962. return currentPage + 1;
  4963. }
  4964. return graphGetGlobalVariable.apply(this, arguments);
  4965. };
  4966. // Disables hyperlinks
  4967. graph.getLinkForCell = function()
  4968. {
  4969. return null;
  4970. };
  4971. // TODO: Enable per-page math
  4972. // if (Editor.MathJaxRender)
  4973. // {
  4974. // graph.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
  4975. // {
  4976. // // LATER: Math support is used if current graph has math enabled
  4977. // // should use switch from history instead but requires setting the
  4978. // // global mxClient.NO_FO switch
  4979. // if (editorUi.editor.graph.mathEnabled)
  4980. // {
  4981. // Editor.MathJaxRender(graph.container);
  4982. // }
  4983. // }));
  4984. // }
  4985. var zoomInBtn = mxUtils.button('', function()
  4986. {
  4987. graph.zoomIn();
  4988. });
  4989. zoomInBtn.className = 'geSprite geSprite-zoomin';
  4990. zoomInBtn.setAttribute('title', mxResources.get('zoomIn'));
  4991. zoomInBtn.style.outline = 'none';
  4992. zoomInBtn.style.border = 'none';
  4993. zoomInBtn.style.margin = '2px';
  4994. mxUtils.setOpacity(zoomInBtn, 60);
  4995. var zoomOutBtn = mxUtils.button('', function()
  4996. {
  4997. graph.zoomOut();
  4998. });
  4999. zoomOutBtn.className = 'geSprite geSprite-zoomout';
  5000. zoomOutBtn.setAttribute('title', mxResources.get('zoomOut'));
  5001. zoomOutBtn.style.outline = 'none';
  5002. zoomOutBtn.style.border = 'none';
  5003. zoomOutBtn.style.margin = '2px';
  5004. mxUtils.setOpacity(zoomOutBtn, 60);
  5005. var zoomFitBtn = mxUtils.button('', function()
  5006. {
  5007. graph.maxFitScale = 8;
  5008. graph.fit(8);
  5009. graph.center();
  5010. });
  5011. zoomFitBtn.className = 'geSprite geSprite-fit';
  5012. zoomFitBtn.setAttribute('title', mxResources.get('fit'));
  5013. zoomFitBtn.style.outline = 'none';
  5014. zoomFitBtn.style.border = 'none';
  5015. zoomFitBtn.style.margin = '2px';
  5016. mxUtils.setOpacity(zoomFitBtn, 60);
  5017. var zoomActualBtn = mxUtils.button('', function()
  5018. {
  5019. graph.zoomActual();
  5020. graph.center();
  5021. });
  5022. zoomActualBtn.className = 'geSprite geSprite-actualsize';
  5023. zoomActualBtn.setAttribute('title', mxResources.get('actualSize'));
  5024. zoomActualBtn.style.outline = 'none';
  5025. zoomActualBtn.style.border = 'none';
  5026. zoomActualBtn.style.margin = '2px';
  5027. mxUtils.setOpacity(zoomActualBtn, 60);
  5028. var restoreBtn = mxUtils.button(discardLabel || mxResources.get('discard'), discardFn);
  5029. restoreBtn.className = 'geBtn';
  5030. var pageSelect = document.createElement('select');
  5031. pageSelect.style.maxWidth = '80px';
  5032. pageSelect.style.position = 'relative';
  5033. pageSelect.style.top = '-2px';
  5034. pageSelect.style.verticalAlign = 'bottom';
  5035. pageSelect.style.marginRight = '6px';
  5036. pageSelect.style.display = 'none';
  5037. var showBtn = mxUtils.button(editLabel || mxResources.get('edit'), editFn);
  5038. showBtn.className = 'geBtn gePrimaryBtn';
  5039. var buttons = document.createElement('div');
  5040. buttons.style.position = 'absolute';
  5041. buttons.style.bottom = '30px';
  5042. buttons.style.width = '640px';
  5043. buttons.style.textAlign = 'right';
  5044. var tb = document.createElement('div');
  5045. tb.className = 'geToolbarContainer';
  5046. tb.style.cssText = 'box-shadow:none !important;background-color:transparent;' +
  5047. 'padding:2px;border-style:none !important;bottom:30px;';
  5048. this.init = function()
  5049. {
  5050. function parseGraphModel(dataNode)
  5051. {
  5052. if (dataNode != null)
  5053. {
  5054. var bg = dataNode.getAttribute('background');
  5055. if (bg == null || bg == '' || bg == mxConstants.NONE)
  5056. {
  5057. bg = '#ffffff';
  5058. }
  5059. container.style.backgroundColor = bg;
  5060. var codec = new mxCodec(dataNode.ownerDocument);
  5061. codec.decode(dataNode, graph.getModel());
  5062. graph.maxFitScale = 1;
  5063. graph.fit(8);
  5064. graph.center();
  5065. }
  5066. };
  5067. function parseDiagram(diagramNode)
  5068. {
  5069. if (diagramNode != null)
  5070. {
  5071. diagramNode = parseGraphModel(mxUtils.parseXml(Graph.decompress(
  5072. mxUtils.getTextContent(diagramNode))).documentElement);
  5073. }
  5074. return diagramNode;
  5075. };
  5076. mxEvent.addListener(pageSelect, 'change', function(evt)
  5077. {
  5078. currentPage = parseInt(pageSelect.value);
  5079. parseDiagram(diagrams[currentPage]);
  5080. mxEvent.consume(evt);
  5081. });
  5082. if (node.nodeName == 'mxfile')
  5083. {
  5084. // Workaround for "invalid calling object" error in IE
  5085. var tmp = node.getElementsByTagName('diagram');
  5086. diagrams = [];
  5087. for (var i = 0; i < tmp.length; i++)
  5088. {
  5089. diagrams.push(tmp[i]);
  5090. }
  5091. if (diagrams.length > 0)
  5092. {
  5093. parseDiagram(diagrams[currentPage]);
  5094. }
  5095. if (diagrams.length > 1)
  5096. {
  5097. pageSelect.style.display = '';
  5098. for (var i = 0; i < diagrams.length; i++)
  5099. {
  5100. var pageOption = document.createElement('option');
  5101. mxUtils.write(pageOption, diagrams[i].getAttribute('name') ||
  5102. mxResources.get('pageWithNumber', [i + 1]));
  5103. pageOption.setAttribute('value', i);
  5104. if (i == currentPage)
  5105. {
  5106. pageOption.setAttribute('selected', 'selected');
  5107. }
  5108. pageSelect.appendChild(pageOption);
  5109. }
  5110. }
  5111. }
  5112. else
  5113. {
  5114. parseGraphModel(node);
  5115. }
  5116. };
  5117. tb.appendChild(pageSelect);
  5118. tb.appendChild(zoomInBtn);
  5119. tb.appendChild(zoomOutBtn);
  5120. tb.appendChild(zoomActualBtn);
  5121. tb.appendChild(zoomFitBtn);
  5122. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  5123. {
  5124. editorUi.hideDialog(true);
  5125. });
  5126. cancelBtn.className = 'geBtn';
  5127. var ignoreBtn = (ignoreFn != null) ? mxUtils.button(mxResources.get('ignore'), ignoreFn) : null;
  5128. if (ignoreBtn != null)
  5129. {
  5130. ignoreBtn.className = 'geBtn';
  5131. }
  5132. if (editorUi.editor.cancelFirst)
  5133. {
  5134. buttons.appendChild(cancelBtn);
  5135. if (ignoreBtn != null)
  5136. {
  5137. buttons.appendChild(ignoreBtn);
  5138. }
  5139. buttons.appendChild(restoreBtn);
  5140. buttons.appendChild(showBtn);
  5141. }
  5142. else
  5143. {
  5144. buttons.appendChild(showBtn);
  5145. buttons.appendChild(restoreBtn);
  5146. if (ignoreBtn != null)
  5147. {
  5148. buttons.appendChild(ignoreBtn);
  5149. }
  5150. buttons.appendChild(cancelBtn);
  5151. }
  5152. div.appendChild(buttons);
  5153. div.appendChild(tb);
  5154. this.container = div;
  5155. };
  5156. /**
  5157. *
  5158. */
  5159. var FindWindow = function(ui, x, y, w, h)
  5160. {
  5161. var action = ui.actions.get('find');
  5162. var graph = ui.editor.graph;
  5163. var lastSearch = null;
  5164. var lastFound = null;
  5165. var div = document.createElement('div');
  5166. div.style.userSelect = 'none';
  5167. div.style.overflow = 'hidden';
  5168. div.style.padding = '10px';
  5169. div.style.height = '100%';
  5170. var searchInput = document.createElement('input');
  5171. searchInput.setAttribute('placeholder', mxResources.get('find'));
  5172. searchInput.setAttribute('type', 'text');
  5173. searchInput.style.marginTop = '4px';
  5174. searchInput.style.marginBottom = '6px';
  5175. searchInput.style.width = '200px';
  5176. searchInput.style.fontSize = '12px';
  5177. searchInput.style.borderRadius = '4px';
  5178. searchInput.style.padding = '6px';
  5179. div.appendChild(searchInput);
  5180. mxUtils.br(div);
  5181. var regexInput = document.createElement('input');
  5182. regexInput.setAttribute('type', 'checkbox');
  5183. regexInput.style.marginRight = '4px';
  5184. div.appendChild(regexInput);
  5185. mxUtils.write(div, mxResources.get('regularExpression'));
  5186. var help = ui.menus.createHelpLink('https://desk.draw.io/support/solutions/articles/16000088250');
  5187. help.style.position = 'relative';
  5188. help.style.marginLeft = '6px';
  5189. help.style.top = '-1px';
  5190. div.appendChild(help);
  5191. var tmp = document.createElement('div');
  5192. function testMeta(re, cell, search)
  5193. {
  5194. if (typeof cell.value === 'object' && cell.value.attributes != null)
  5195. {
  5196. var attrs = cell.value.attributes;
  5197. for (var i = 0; i < attrs.length; i++)
  5198. {
  5199. if (attrs[i].nodeName != 'label')
  5200. {
  5201. var value = mxUtils.trim(attrs[i].nodeValue.replace(/[\x00-\x1F\x7F-\x9F]|\s+/g, ' ')).toLowerCase();
  5202. if ((re == null && value.substring(0, search.length) === search) ||
  5203. (re != null && re.test(value)))
  5204. {
  5205. return true;
  5206. }
  5207. }
  5208. }
  5209. }
  5210. return false;
  5211. };
  5212. function search()
  5213. {
  5214. var cells = graph.model.getDescendants(graph.model.getRoot());
  5215. var search = searchInput.value.toLowerCase();
  5216. var re = (regexInput.checked) ? new RegExp(search) : null;
  5217. var firstMatch = null;
  5218. if (lastSearch != search)
  5219. {
  5220. lastSearch = search;
  5221. lastFound = null;
  5222. }
  5223. var active = lastFound == null;
  5224. if (search.length > 0)
  5225. {
  5226. for (var i = 0; i < cells.length; i++)
  5227. {
  5228. var state = graph.view.getState(cells[i]);
  5229. if (state != null && state.cell.value != null && (active || firstMatch == null) &&
  5230. (graph.model.isVertex(state.cell) || graph.model.isEdge(state.cell)))
  5231. {
  5232. if (graph.isHtmlLabel(state.cell))
  5233. {
  5234. tmp.innerHTML = graph.getLabel(state.cell);
  5235. label = mxUtils.extractTextWithWhitespace([tmp]);
  5236. }
  5237. else
  5238. {
  5239. label = graph.getLabel(state.cell);
  5240. }
  5241. label = mxUtils.trim(label.replace(/[\x00-\x1F\x7F-\x9F]|\s+/g, ' ')).toLowerCase();
  5242. if ((re == null && (label.substring(0, search.length) === search || testMeta(re, state.cell, search))) ||
  5243. (re != null && (re.test(label) || testMeta(re, state.cell, search))))
  5244. {
  5245. if (active)
  5246. {
  5247. firstMatch = state;
  5248. break;
  5249. }
  5250. else if (firstMatch == null)
  5251. {
  5252. firstMatch = state;
  5253. }
  5254. }
  5255. }
  5256. active = active || state == lastFound;
  5257. }
  5258. }
  5259. if (firstMatch != null)
  5260. {
  5261. lastFound = firstMatch;
  5262. graph.scrollCellToVisible(lastFound.cell);
  5263. if (graph.isEnabled())
  5264. {
  5265. graph.setSelectionCell(lastFound.cell);
  5266. }
  5267. else
  5268. {
  5269. graph.highlightCell(lastFound.cell);
  5270. }
  5271. }
  5272. else if (graph.isEnabled())
  5273. {
  5274. graph.clearSelection();
  5275. }
  5276. return search.length == 0 || firstMatch != null;
  5277. };
  5278. mxUtils.br(div);
  5279. var resetBtn = mxUtils.button(mxResources.get('reset'), function()
  5280. {
  5281. searchInput.value = '';
  5282. searchInput.style.backgroundColor = '';
  5283. lastFound = null;
  5284. lastSearch = null;
  5285. searchInput.focus();
  5286. });
  5287. resetBtn.setAttribute('title', mxResources.get('reset'));
  5288. resetBtn.style.marginTop = '6px';
  5289. resetBtn.style.marginRight = '4px';
  5290. resetBtn.className = 'geBtn';
  5291. div.appendChild(resetBtn);
  5292. var btn = mxUtils.button(mxResources.get('find'), function()
  5293. {
  5294. try
  5295. {
  5296. searchInput.style.backgroundColor = search() ? '' : '#ffcfcf';
  5297. }
  5298. catch (e)
  5299. {
  5300. ui.handleError(e);
  5301. }
  5302. });
  5303. btn.setAttribute('title', mxResources.get('find') + ' (Enter)');
  5304. btn.style.marginTop = '6px';
  5305. btn.className = 'geBtn gePrimaryBtn';
  5306. div.appendChild(btn);
  5307. mxEvent.addListener(searchInput, 'keyup', function(evt)
  5308. {
  5309. // Ctrl or Cmd keys
  5310. if (evt.keyCode == 91 || evt.keyCode == 17)
  5311. {
  5312. // Workaround for lost focus on show
  5313. mxEvent.consume(evt);
  5314. }
  5315. else if (evt.keyCode == 27)
  5316. {
  5317. action.funct();
  5318. }
  5319. else if (lastSearch != searchInput.value.toLowerCase() || evt.keyCode == 13)
  5320. {
  5321. try
  5322. {
  5323. searchInput.style.backgroundColor = search() ? '' : '#ffcfcf';
  5324. }
  5325. catch (e)
  5326. {
  5327. searchInput.style.backgroundColor = '#ffcfcf';
  5328. }
  5329. }
  5330. });
  5331. mxEvent.addListener(div, 'keydown', function(evt)
  5332. {
  5333. if (evt.keyCode == 70 && ui.keyHandler.isControlDown(evt) && !mxEvent.isShiftDown(evt))
  5334. {
  5335. action.funct();
  5336. mxEvent.consume(evt);
  5337. }
  5338. });
  5339. this.window = new mxWindow(mxResources.get('find'), div, x, y, w, h, true, true);
  5340. this.window.destroyOnClose = false;
  5341. this.window.setMaximizable(false);
  5342. this.window.setResizable(false);
  5343. this.window.setClosable(true);
  5344. this.window.addListener('show', mxUtils.bind(this, function()
  5345. {
  5346. if (this.window.isVisible())
  5347. {
  5348. searchInput.focus();
  5349. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  5350. {
  5351. searchInput.select();
  5352. }
  5353. else
  5354. {
  5355. document.execCommand('selectAll', false, null);
  5356. }
  5357. }
  5358. else
  5359. {
  5360. graph.container.focus();
  5361. }
  5362. }));
  5363. };
  5364. /**
  5365. *
  5366. */
  5367. var TagsWindow = function(editorUi, x, y, w, h)
  5368. {
  5369. var graph = editorUi.editor.graph;
  5370. var propertyName = 'tags';
  5371. var div = document.createElement('div');
  5372. div.style.userSelect = 'none';
  5373. div.style.overflow = 'hidden';
  5374. div.style.padding = '10px';
  5375. div.style.height = '100%';
  5376. var searchInput = document.createElement('input');
  5377. searchInput.setAttribute('placeholder', mxResources.get('allTags'));
  5378. searchInput.setAttribute('type', 'text');
  5379. searchInput.style.marginTop = '4px';
  5380. searchInput.style.width = '260px';
  5381. searchInput.style.fontSize = '12px';
  5382. searchInput.style.borderRadius = '4px';
  5383. searchInput.style.padding = '6px';
  5384. div.appendChild(searchInput);
  5385. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
  5386. {
  5387. searchInput.style.width = '240px';
  5388. var elt = editorUi.menus.createHelpLink('https://desk.draw.io/support/solutions/articles/16000046966');
  5389. elt.firstChild.style.marginBottom = '6px';
  5390. elt.style.marginLeft = '6px';
  5391. div.appendChild(elt);
  5392. }
  5393. mxEvent.addListener(searchInput, 'dblclick', function()
  5394. {
  5395. var dlg = new FilenameDialog(editorUi, propertyName, mxResources.get('ok'), mxUtils.bind(this, function(name)
  5396. {
  5397. if (name != null && name.length > 0)
  5398. {
  5399. propertyName = name;
  5400. }
  5401. }), mxResources.get('enterPropertyName'));
  5402. editorUi.showDialog(dlg.container, 300, 80, true, true);
  5403. dlg.init();
  5404. });
  5405. searchInput.setAttribute('title', mxResources.get('doubleClickChangeProperty'));
  5406. function searchCells(cells)
  5407. {
  5408. return graph.getCellsForTags(searchInput.value.split(' '), cells, propertyName);
  5409. };
  5410. function setCellsVisible(cells, visible)
  5411. {
  5412. graph.setCellsVisible(cells, visible);
  5413. };
  5414. mxUtils.br(div);
  5415. var hideBtn = mxUtils.button(mxResources.get('hide'), function()
  5416. {
  5417. setCellsVisible(searchCells(), false);
  5418. });
  5419. hideBtn.setAttribute('title', mxResources.get('hide'));
  5420. hideBtn.style.marginTop = '8px';
  5421. hideBtn.style.marginRight = '4px';
  5422. hideBtn.className = 'geBtn';
  5423. div.appendChild(hideBtn);
  5424. var showBtn = mxUtils.button(mxResources.get('show'), function()
  5425. {
  5426. var cells = searchCells();
  5427. setCellsVisible(cells, true);
  5428. if (graph.isEnabled())
  5429. {
  5430. graph.setSelectionCells(cells);
  5431. }
  5432. else
  5433. {
  5434. for (var i = 0; i < cells.length; i++)
  5435. {
  5436. graph.highlightCell(cells[i]);
  5437. }
  5438. }
  5439. });
  5440. showBtn.setAttribute('title', mxResources.get('show'));
  5441. showBtn.style.marginTop = '8px';
  5442. showBtn.style.marginRight = '4px';
  5443. showBtn.className = 'geBtn';
  5444. div.appendChild(showBtn);
  5445. var action = editorUi.actions.get('tags');
  5446. var btn = mxUtils.button(mxResources.get('close'), function()
  5447. {
  5448. action.funct();
  5449. });
  5450. btn.setAttribute('title', mxResources.get('close') + ' (Enter/Esc)');
  5451. btn.style.marginTop = '8px';
  5452. btn.className = 'geBtn gePrimaryBtn';
  5453. div.appendChild(btn);
  5454. mxEvent.addListener(searchInput, 'keyup', function(evt)
  5455. {
  5456. // Ctrl or Cmd keys
  5457. if (evt.keyCode == 13 || evt.keyCode == 27)
  5458. {
  5459. action.funct();
  5460. }
  5461. });
  5462. this.window = new mxWindow(mxResources.get('tags'), div, x, y, w, h, true, true);
  5463. this.window.destroyOnClose = false;
  5464. this.window.setMaximizable(false);
  5465. this.window.setResizable(false);
  5466. this.window.setClosable(true);
  5467. this.window.addListener('show', mxUtils.bind(this, function()
  5468. {
  5469. if (this.window.isVisible())
  5470. {
  5471. searchInput.focus();
  5472. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  5473. {
  5474. searchInput.select();
  5475. }
  5476. else
  5477. {
  5478. document.execCommand('selectAll', false, null);
  5479. }
  5480. }
  5481. else
  5482. {
  5483. graph.container.focus();
  5484. }
  5485. }));
  5486. };
  5487. /**
  5488. * Constructs a new auth dialog.
  5489. */
  5490. var AuthDialog = function(editorUi, peer, showRememberOption, fn)
  5491. {
  5492. var div = document.createElement('div');
  5493. div.style.textAlign = 'center';
  5494. var hd = document.createElement('p');
  5495. hd.style.fontSize = '16pt';
  5496. hd.style.padding = '0px';
  5497. hd.style.margin = '0px';
  5498. hd.style.color = 'gray';
  5499. mxUtils.write(hd, mxResources.get('authorizationRequired'));
  5500. var service = 'Unknown';
  5501. var img = document.createElement('img');
  5502. img.setAttribute('border', '0');
  5503. img.setAttribute('align', 'absmiddle');
  5504. img.style.marginRight = '10px';
  5505. if (peer == editorUi.drive)
  5506. {
  5507. service = mxResources.get('googleDrive');
  5508. img.src = IMAGE_PATH + '/google-drive-logo-white.svg';
  5509. }
  5510. else if (peer == editorUi.dropbox)
  5511. {
  5512. service = mxResources.get('dropbox');
  5513. img.src = IMAGE_PATH + '/dropbox-logo-white.svg';
  5514. }
  5515. else if (peer == editorUi.oneDrive)
  5516. {
  5517. service = mxResources.get('oneDrive');
  5518. img.src = IMAGE_PATH + '/onedrive-logo-white.svg';
  5519. }
  5520. else if (peer == editorUi.gitHub)
  5521. {
  5522. service = mxResources.get('github');
  5523. img.src = IMAGE_PATH + '/github-logo-white.svg';
  5524. }
  5525. else if (peer == editorUi.trello)
  5526. {
  5527. service = mxResources.get('trello');
  5528. img.src = IMAGE_PATH + '/trello-logo-white.svg';
  5529. }
  5530. var p = document.createElement('p');
  5531. mxUtils.write(p, mxResources.get('authorizeThisAppIn', [service]));
  5532. var cb = document.createElement('input');
  5533. cb.setAttribute('type', 'checkbox');
  5534. var button = mxUtils.button(mxResources.get('authorize'), function()
  5535. {
  5536. fn(cb.checked);
  5537. });
  5538. button.insertBefore(img, button.firstChild);
  5539. button.style.marginTop = '6px';
  5540. button.className = 'geBigButton';
  5541. div.appendChild(hd);
  5542. div.appendChild(p);
  5543. div.appendChild(button);
  5544. if (showRememberOption)
  5545. {
  5546. var p2 = document.createElement('p');
  5547. p2.style.marginTop = '20px';
  5548. p2.appendChild(cb);
  5549. var span = document.createElement('span');
  5550. mxUtils.write(span, ' ' + mxResources.get('rememberMe'));
  5551. p2.appendChild(span);
  5552. div.appendChild(p2);
  5553. cb.checked = true;
  5554. cb.defaultChecked = true;
  5555. mxEvent.addListener(span, 'click', function(evt)
  5556. {
  5557. cb.checked = !cb.checked;
  5558. mxEvent.consume(evt);
  5559. });
  5560. }
  5561. this.container = div;
  5562. };
  5563. var MoreShapesDialog = function(editorUi, expanded, entries)
  5564. {
  5565. entries = (entries != null) ? entries : editorUi.sidebar.entries;
  5566. var div = document.createElement('div');
  5567. var newEntries = [];
  5568. // Adds custom sections first
  5569. if (editorUi.sidebar.customEntries != null)
  5570. {
  5571. for (var i = 0; i < editorUi.sidebar.customEntries.length; i++)
  5572. {
  5573. var section = editorUi.sidebar.customEntries[i];
  5574. var tmp = {title: editorUi.getResource(section.title), entries: []};
  5575. for (var j = 0; j < section.entries.length; j++)
  5576. {
  5577. var entry = section.entries[j];
  5578. tmp.entries.push({id: entry.id, title:
  5579. editorUi.getResource(entry.title),
  5580. desc: editorUi.getResource(entry.desc),
  5581. image: entry.preview});
  5582. }
  5583. newEntries.push(tmp);
  5584. }
  5585. }
  5586. // Adds built-in sections and filter entries
  5587. for (var i = 0; i < entries.length; i++)
  5588. {
  5589. if (editorUi.sidebar.enabledLibraries == null)
  5590. {
  5591. newEntries.push(entries[i]);
  5592. }
  5593. else
  5594. {
  5595. var tmp = {title: entries[i].title, entries: []};
  5596. for (var j = 0; j < entries[i].entries.length; j++)
  5597. {
  5598. if (mxUtils.indexOf(editorUi.sidebar.enabledLibraries,
  5599. entries[i].entries[j].id) >= 0)
  5600. {
  5601. tmp.entries.push(entries[i].entries[j]);
  5602. }
  5603. }
  5604. if (tmp.entries.length > 0)
  5605. {
  5606. newEntries.push(tmp);
  5607. }
  5608. }
  5609. }
  5610. entries = newEntries;
  5611. if (expanded)
  5612. {
  5613. var hd = document.createElement('div');
  5614. hd.className = 'geDialogTitle';
  5615. mxUtils.write(hd, mxResources.get('shapes'));
  5616. hd.style.position = 'absolute';
  5617. hd.style.top = '0px';
  5618. hd.style.left = '0px';
  5619. hd.style.lineHeight = '40px';
  5620. hd.style.height = '40px';
  5621. hd.style.right = '0px';
  5622. if (mxClient.IS_QUIRKS)
  5623. {
  5624. hd.style.width = '718px';
  5625. }
  5626. var list = document.createElement('div');
  5627. var preview = document.createElement('div');
  5628. list.style.position = 'absolute';
  5629. list.style.top = '40px';
  5630. list.style.left = '0px';
  5631. list.style.width = '202px';
  5632. list.style.bottom = '60px';
  5633. list.style.overflow = 'auto';
  5634. if (mxClient.IS_QUIRKS)
  5635. {
  5636. list.style.height = '437px';
  5637. list.style.marginTop = '1px';
  5638. }
  5639. preview.style.position = 'absolute';
  5640. preview.style.left = '202px';
  5641. preview.style.right = '0px';
  5642. preview.style.top = '40px';
  5643. preview.style.bottom = '60px';
  5644. preview.style.overflow = 'auto';
  5645. preview.style.borderLeft = '1px solid rgb(211, 211, 211)';
  5646. preview.style.textAlign = 'center';
  5647. if (mxClient.IS_QUIRKS)
  5648. {
  5649. preview.style.width = parseInt(hd.style.width) - 202 + 'px';
  5650. preview.style.height = list.style.height;
  5651. preview.style.marginTop = list.style.marginTop;
  5652. }
  5653. var currentListItem = null;
  5654. var applyFunctions = [];
  5655. var listEntry = document.createElement('div');
  5656. listEntry.style.position = 'relative';
  5657. listEntry.style.left = '0px';
  5658. listEntry.style.right = '0px';
  5659. for (var i = 0; i < entries.length; i++)
  5660. {
  5661. (function(section)
  5662. {
  5663. var title = listEntry.cloneNode(false);
  5664. title.style.fontWeight = 'bold';
  5665. title.style.backgroundColor = (uiTheme == 'dark') ? '#505759' : '#e5e5e5';
  5666. title.style.padding = '6px 0px 6px 20px';
  5667. mxUtils.write(title, section.title);
  5668. list.appendChild(title);
  5669. for (var j = 0; j < section.entries.length; j++)
  5670. {
  5671. (function(entry)
  5672. {
  5673. var option = listEntry.cloneNode(false);
  5674. option.style.cursor = 'pointer';
  5675. option.style.padding = '4px 0px 4px 20px';
  5676. option.setAttribute('title', entry.title + ' (' + entry.id + ')');
  5677. var checkbox = document.createElement('input');
  5678. checkbox.setAttribute('type', 'checkbox');
  5679. checkbox.checked = editorUi.sidebar.isEntryVisible(entry.id);
  5680. checkbox.defaultChecked = checkbox.checked;
  5681. option.appendChild(checkbox);
  5682. mxUtils.write(option, ' ' + entry.title);
  5683. list.appendChild(option);
  5684. var itemClicked = function(evt)
  5685. {
  5686. if (evt == null || mxEvent.getSource(evt).nodeName != 'INPUT')
  5687. {
  5688. preview.style.textAlign = 'center';
  5689. preview.style.padding = '0px';
  5690. preview.style.color = '';
  5691. preview.innerHTML = '';
  5692. if (entry.desc != null)
  5693. {
  5694. var pre = document.createElement('pre');
  5695. pre.style.boxSizing = 'border-box';
  5696. pre.style.fontFamily = 'inherit';
  5697. pre.style.margin = '20px';
  5698. pre.style.right = '0px';
  5699. pre.style.textAlign = 'left';
  5700. mxUtils.write(pre, entry.desc);
  5701. preview.appendChild(pre);
  5702. }
  5703. if (entry.imageCallback != null)
  5704. {
  5705. entry.imageCallback(preview);
  5706. }
  5707. else if (entry.image != null)
  5708. {
  5709. preview.innerHTML += '<img border="0" src="' + entry.image + '"/>';
  5710. }
  5711. else if (entry.desc == null)
  5712. {
  5713. preview.style.padding = '20px';
  5714. preview.style.color = 'rgb(179, 179, 179)';
  5715. mxUtils.write(preview, mxResources.get('noPreview'));
  5716. }
  5717. if (currentListItem != null)
  5718. {
  5719. currentListItem.style.backgroundColor = '';
  5720. }
  5721. currentListItem = option;
  5722. currentListItem.style.backgroundColor = (uiTheme == 'dark') ? '#505759' : '#ebf2f9';
  5723. if (evt != null)
  5724. {
  5725. mxEvent.consume(evt);
  5726. }
  5727. }
  5728. };
  5729. mxEvent.addListener(option, 'click', itemClicked);
  5730. mxEvent.addListener(option, 'dblclick', function(evt)
  5731. {
  5732. checkbox.checked = !checkbox.checked;
  5733. mxEvent.consume(evt);
  5734. });
  5735. applyFunctions.push(function()
  5736. {
  5737. return (checkbox.checked) ? entry.id : null;
  5738. });
  5739. // Selects first entry
  5740. if (i == 0 && j == 0)
  5741. {
  5742. itemClicked();
  5743. }
  5744. })(section.entries[j]);
  5745. }
  5746. })(entries[i]);
  5747. }
  5748. div.style.padding = '30px';
  5749. div.appendChild(hd);
  5750. div.appendChild(list);
  5751. div.appendChild(preview);
  5752. var buttons = document.createElement('div');
  5753. buttons.className = 'geDialogFooter';
  5754. buttons.style.position = 'absolute';
  5755. buttons.style.paddingRight = '16px';
  5756. buttons.style.color = 'gray';
  5757. buttons.style.left = '0px';
  5758. buttons.style.right = '0px';
  5759. buttons.style.bottom = '0px';
  5760. buttons.style.height = '60px';
  5761. buttons.style.lineHeight = '52px';
  5762. if (mxClient.IS_QUIRKS)
  5763. {
  5764. buttons.style.width = hd.style.width;
  5765. buttons.style.paddingTop = '12px';
  5766. }
  5767. var cb = document.createElement('input');
  5768. cb.setAttribute('type', 'checkbox');
  5769. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  5770. {
  5771. var span = document.createElement('span');
  5772. span.style.paddingRight = '20px';
  5773. span.appendChild(cb);
  5774. mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
  5775. cb.checked = true;
  5776. cb.defaultChecked = true;
  5777. mxEvent.addListener(span, 'click', function(evt)
  5778. {
  5779. if (mxEvent.getSource(evt) != cb)
  5780. {
  5781. cb.checked = !cb.checked;
  5782. mxEvent.consume(evt);
  5783. }
  5784. });
  5785. if (mxClient.IS_QUIRKS)
  5786. {
  5787. span.style.position = 'relative';
  5788. span.style.top = '-6px';
  5789. }
  5790. buttons.appendChild(span);
  5791. }
  5792. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  5793. {
  5794. editorUi.hideDialog();
  5795. });
  5796. cancelBtn.className = 'geBtn';
  5797. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  5798. {
  5799. editorUi.hideDialog();
  5800. var libs = [];
  5801. for (var i = 0; i < applyFunctions.length; i++)
  5802. {
  5803. var lib = applyFunctions[i].apply(this, arguments);
  5804. if (lib != null)
  5805. {
  5806. libs.push(lib);
  5807. }
  5808. }
  5809. editorUi.sidebar.showEntries(libs.join(';'), cb.checked, true);
  5810. });
  5811. applyBtn.className = 'geBtn gePrimaryBtn';
  5812. if (editorUi.editor.cancelFirst)
  5813. {
  5814. buttons.appendChild(cancelBtn);
  5815. buttons.appendChild(applyBtn);
  5816. }
  5817. else
  5818. {
  5819. buttons.appendChild(applyBtn);
  5820. buttons.appendChild(cancelBtn);
  5821. }
  5822. div.appendChild(buttons);
  5823. }
  5824. else
  5825. {
  5826. var libFS = document.createElement('table');
  5827. var tbody = document.createElement('tbody');
  5828. div.style.height = '100%';
  5829. div.style.overflow = 'auto';
  5830. var row = document.createElement('tr');
  5831. libFS.style.width = '100%';
  5832. var leftDiv = document.createElement('td');
  5833. var midDiv = document.createElement('td');
  5834. var rightDiv = document.createElement('td');
  5835. var addLibCB = mxUtils.bind(this, function(wrapperDiv, title, key)
  5836. {
  5837. var libCB = document.createElement('input');
  5838. libCB.type = 'checkbox';
  5839. libFS.appendChild(libCB);
  5840. libCB.checked = editorUi.sidebar.isEntryVisible(key);
  5841. var libSpan = document.createElement('span');
  5842. mxUtils.write(libSpan, title);
  5843. var label = document.createElement('div');
  5844. label.style.display = 'block';
  5845. label.appendChild(libCB);
  5846. label.appendChild(libSpan);
  5847. mxEvent.addListener(libSpan, 'click', function(evt)
  5848. {
  5849. libCB.checked = !libCB.checked;
  5850. mxEvent.consume(evt);
  5851. });
  5852. wrapperDiv.appendChild(label);
  5853. return function()
  5854. {
  5855. return (libCB.checked) ? key : null;
  5856. };
  5857. });
  5858. row.appendChild(leftDiv);
  5859. row.appendChild(midDiv);
  5860. row.appendChild(rightDiv);
  5861. tbody.appendChild(row);
  5862. libFS.appendChild(tbody);
  5863. var applyFunctions = [];
  5864. var count = 0;
  5865. // Counts total number of entries
  5866. for (var i = 0; i < entries.length; i++)
  5867. {
  5868. for (var j = 0; j < entries[i].entries.length; j++)
  5869. {
  5870. count++;
  5871. }
  5872. }
  5873. // Distributes entries on columns
  5874. var cols = [leftDiv, midDiv, rightDiv];
  5875. var counter = 0;
  5876. for (var i = 0; i < entries.length; i++)
  5877. {
  5878. (function(section)
  5879. {
  5880. for (var j = 0; j < section.entries.length; j++)
  5881. {
  5882. (function(entry)
  5883. {
  5884. var index = Math.floor(counter / (count / 3));
  5885. applyFunctions.push(addLibCB(cols[index], entry.title, entry.id));
  5886. counter++;
  5887. })(section.entries[j]);
  5888. }
  5889. })(entries[i]);
  5890. }
  5891. div.appendChild(libFS);
  5892. var remember = document.createElement('div');
  5893. remember.style.marginTop = '18px';
  5894. remember.style.textAlign = 'center';
  5895. var cb = document.createElement('input');
  5896. if (isLocalStorage)
  5897. {
  5898. cb.setAttribute('type', 'checkbox');
  5899. cb.checked = true;
  5900. cb.defaultChecked = true;
  5901. remember.appendChild(cb);
  5902. var span = document.createElement('span');
  5903. mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
  5904. remember.appendChild(span);
  5905. mxEvent.addListener(span, 'click', function(evt)
  5906. {
  5907. cb.checked = !cb.checked;
  5908. mxEvent.consume(evt);
  5909. });
  5910. }
  5911. div.appendChild(remember);
  5912. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  5913. {
  5914. editorUi.hideDialog();
  5915. });
  5916. cancelBtn.className = 'geBtn';
  5917. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  5918. {
  5919. var libs = ['search'];
  5920. for (var i = 0; i < applyFunctions.length; i++)
  5921. {
  5922. var lib = applyFunctions[i].apply(this, arguments);
  5923. if (lib != null)
  5924. {
  5925. libs.push(lib);
  5926. }
  5927. }
  5928. editorUi.sidebar.showEntries((libs.length > 0) ? libs.join(';') : '', cb.checked);
  5929. editorUi.hideDialog();
  5930. });
  5931. applyBtn.className = 'geBtn gePrimaryBtn';
  5932. var buttons = document.createElement('div');
  5933. buttons.style.marginTop = '26px';
  5934. buttons.style.textAlign = 'right';
  5935. if (editorUi.editor.cancelFirst)
  5936. {
  5937. buttons.appendChild(cancelBtn);
  5938. buttons.appendChild(applyBtn);
  5939. }
  5940. else
  5941. {
  5942. buttons.appendChild(applyBtn);
  5943. buttons.appendChild(cancelBtn);
  5944. }
  5945. div.appendChild(buttons);
  5946. }
  5947. this.container = div;
  5948. };
  5949. var PluginsDialog = function(editorUi)
  5950. {
  5951. var div = document.createElement('div');
  5952. var inner = document.createElement('div');
  5953. inner.style.height = '120px';
  5954. inner.style.overflow = 'auto';
  5955. var plugins = mxSettings.getPlugins().slice();
  5956. function refresh()
  5957. {
  5958. if (plugins.length == 0)
  5959. {
  5960. inner.innerHTML = mxUtils.htmlEntities(mxResources.get('noPlugins'));
  5961. }
  5962. else
  5963. {
  5964. inner.innerHTML = '';
  5965. for (var i = 0; i < plugins.length; i++)
  5966. {
  5967. var span = document.createElement('span');
  5968. span.style.whiteSpace = 'nowrap';
  5969. var img = document.createElement('span');
  5970. img.className = 'geSprite geSprite-delete';
  5971. img.style.position = 'relative';
  5972. img.style.cursor = 'pointer';
  5973. img.style.top = '5px';
  5974. img.style.marginRight = '4px';
  5975. img.style.display = 'inline-block';
  5976. span.appendChild(img);
  5977. mxUtils.write(span, plugins[i]);
  5978. inner.appendChild(span);
  5979. mxUtils.br(inner);
  5980. mxEvent.addListener(img, 'click', (function(index)
  5981. {
  5982. return function()
  5983. {
  5984. editorUi.confirm(window.parent.mxResources.get('delete') + ' "' + plugins[index] + '"?', function()
  5985. {
  5986. plugins.splice(index, 1);
  5987. refresh();
  5988. });
  5989. };
  5990. })(i));
  5991. }
  5992. }
  5993. }
  5994. div.appendChild(inner);
  5995. refresh();
  5996. var addBtn = mxUtils.button(mxResources.get('add'), function()
  5997. {
  5998. var tmp = '';
  5999. var param = urlParams['p'];
  6000. if (param != null && param.length > 0)
  6001. {
  6002. var tokens = param.split(';');
  6003. for (var i = 0; i < tokens.length; i++)
  6004. {
  6005. var url = App.pluginRegistry[tokens[i]];
  6006. if (url != null)
  6007. {
  6008. tmp += url + ';';
  6009. }
  6010. }
  6011. if (tmp.charAt(tmp.length - 1) == ';')
  6012. {
  6013. tmp = tmp.substring(0, tmp.length - 1);
  6014. }
  6015. }
  6016. var dlg = new FilenameDialog(editorUi, tmp, mxResources.get('add'), function(newValue)
  6017. {
  6018. if (newValue != null && newValue.length > 0)
  6019. {
  6020. tokens = newValue.split(';');
  6021. for (var i = 0; i < tokens.length; i++)
  6022. {
  6023. var token = tokens[i];
  6024. var url = App.pluginRegistry[token];
  6025. if (url != null)
  6026. {
  6027. token = url;
  6028. }
  6029. if (token.length > 0 && mxUtils.indexOf(plugins, token) < 0)
  6030. {
  6031. plugins.push(token);
  6032. }
  6033. }
  6034. refresh();
  6035. }
  6036. }, mxResources.get('enterValue') + ' (' + mxResources.get('url') + ')');
  6037. editorUi.showDialog(dlg.container, 300, 80, true, true);
  6038. dlg.init();
  6039. });
  6040. addBtn.className = 'geBtn';
  6041. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  6042. {
  6043. editorUi.hideDialog();
  6044. });
  6045. cancelBtn.className = 'geBtn';
  6046. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  6047. {
  6048. mxSettings.setPlugins(plugins);
  6049. mxSettings.save();
  6050. editorUi.hideDialog();
  6051. editorUi.alert(mxResources.get('restartForChangeRequired'));
  6052. });
  6053. applyBtn.className = 'geBtn gePrimaryBtn';
  6054. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  6055. {
  6056. editorUi.openLink('https://desk.draw.io/support/solutions/articles/16000056430');
  6057. });
  6058. helpBtn.className = 'geBtn';
  6059. if (editorUi.isOffline() && !mxClient.IS_CHROMEAPP)
  6060. {
  6061. helpBtn.style.display = 'none';
  6062. }
  6063. var buttons = document.createElement('div');
  6064. buttons.style.marginTop = '14px';
  6065. buttons.style.textAlign = 'right';
  6066. if (editorUi.editor.cancelFirst)
  6067. {
  6068. buttons.appendChild(cancelBtn);
  6069. buttons.appendChild(helpBtn);
  6070. buttons.appendChild(addBtn);
  6071. buttons.appendChild(applyBtn);
  6072. }
  6073. else
  6074. {
  6075. buttons.appendChild(helpBtn);
  6076. buttons.appendChild(addBtn);
  6077. buttons.appendChild(applyBtn);
  6078. buttons.appendChild(cancelBtn);
  6079. }
  6080. div.appendChild(buttons);
  6081. this.container = div;
  6082. };
  6083. var CropImageDialog = function(editorUi, image, fn)
  6084. {
  6085. var div = document.createElement('div');
  6086. var table = document.createElement('table');
  6087. var tbody = document.createElement('tbody');
  6088. var row = document.createElement('tr');
  6089. var size = document.createElement('td');
  6090. size.style.whiteSpace = 'nowrap';
  6091. size.setAttribute('colspan', '2');
  6092. mxUtils.write(size, mxResources.get('loading') + '...');
  6093. row.appendChild(size);
  6094. tbody.appendChild(row);
  6095. var row = document.createElement('tr');
  6096. var left = document.createElement('td');
  6097. var right = document.createElement('td');
  6098. table.style.paddingLeft = '6px';
  6099. mxUtils.write(left, mxResources.get('left') + ':');
  6100. var xInput = document.createElement('input');
  6101. xInput.setAttribute('type', 'text');
  6102. xInput.style.width = '100px';
  6103. xInput.value = '0';
  6104. this.init = function()
  6105. {
  6106. xInput.focus();
  6107. xInput.select();
  6108. };
  6109. right.appendChild(xInput);
  6110. row.appendChild(left);
  6111. row.appendChild(right);
  6112. tbody.appendChild(row);
  6113. row = document.createElement('tr');
  6114. left = document.createElement('td');
  6115. right = document.createElement('td');
  6116. mxUtils.write(left, mxResources.get('top') + ':');
  6117. var yInput = document.createElement('input');
  6118. yInput.setAttribute('type', 'text');
  6119. yInput.style.width = '100px';
  6120. yInput.value = '0';
  6121. right.appendChild(yInput);
  6122. row.appendChild(left);
  6123. row.appendChild(right);
  6124. tbody.appendChild(row);
  6125. row = document.createElement('tr');
  6126. left = document.createElement('td');
  6127. right = document.createElement('td');
  6128. mxUtils.write(left, mxResources.get('right') + ':');
  6129. var wInput = document.createElement('input');
  6130. wInput.setAttribute('type', 'text');
  6131. wInput.style.width = '100px';
  6132. wInput.value = '0';
  6133. right.appendChild(wInput);
  6134. row.appendChild(left);
  6135. row.appendChild(right);
  6136. tbody.appendChild(row);
  6137. row = document.createElement('tr');
  6138. left = document.createElement('td');
  6139. right = document.createElement('td');
  6140. mxUtils.write(left, mxResources.get('bottom') + ':');
  6141. var hInput = document.createElement('input');
  6142. hInput.setAttribute('type', 'text');
  6143. hInput.style.width = '100px';
  6144. hInput.value = '0';
  6145. right.appendChild(hInput);
  6146. row.appendChild(left);
  6147. row.appendChild(right);
  6148. tbody.appendChild(row);
  6149. row = document.createElement('tr');
  6150. left = document.createElement('td');
  6151. right = document.createElement('td');
  6152. mxUtils.write(left, mxResources.get('circle') + ':');
  6153. row.appendChild(left);
  6154. var circleInput = document.createElement('input');
  6155. circleInput.setAttribute('type', 'checkbox');
  6156. right.appendChild(circleInput);
  6157. row.appendChild(right);
  6158. tbody.appendChild(row);
  6159. table.appendChild(tbody);
  6160. div.appendChild(table);
  6161. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  6162. {
  6163. editorUi.hideDialog();
  6164. });
  6165. cancelBtn.className = 'geBtn';
  6166. var imageObj = new Image();
  6167. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  6168. {
  6169. editorUi.hideDialog();
  6170. var canvas = document.createElement('canvas');
  6171. var context = canvas.getContext('2d');
  6172. var w = imageObj.width;
  6173. var h = imageObj.height;
  6174. // draw cropped image
  6175. var sourceX = parseInt(xInput.value);
  6176. var sourceY = parseInt(yInput.value);
  6177. var sourceWidth = Math.max(1, w - sourceX - parseInt(wInput.value));
  6178. var sourceHeight = Math.max(1, h - sourceY - parseInt(hInput.value));
  6179. canvas.width = sourceWidth;
  6180. canvas.height = sourceHeight;
  6181. if (circleInput.checked)
  6182. {
  6183. context.fillStyle = '#000000';
  6184. context.arc(sourceWidth / 2, sourceHeight / 2, Math.min(sourceWidth / 2,
  6185. sourceHeight / 2), 0, 2 * Math.PI);
  6186. context.fill();
  6187. context.globalCompositeOperation = 'source-in';
  6188. }
  6189. context.drawImage(imageObj, sourceX, sourceY, sourceWidth, sourceHeight, 0, 0, sourceWidth, sourceHeight);
  6190. fn(canvas.toDataURL());
  6191. });
  6192. applyBtn.className = 'geBtn gePrimaryBtn';
  6193. applyBtn.setAttribute('disabled', 'disabled');
  6194. imageObj.onload = function()
  6195. {
  6196. applyBtn.removeAttribute('disabled');
  6197. size.innerHTML = '';
  6198. mxUtils.write(size, mxResources.get('width') + ': ' + imageObj.width + ' ' +
  6199. mxResources.get('height') + ': ' + imageObj.height);
  6200. };
  6201. imageObj.src = image;
  6202. mxEvent.addListener(div, 'keypress', function(e)
  6203. {
  6204. if (e.keyCode == 13)
  6205. {
  6206. applyBtn.click();
  6207. }
  6208. });
  6209. var buttons = document.createElement('div');
  6210. buttons.style.marginTop = '20px';
  6211. buttons.style.textAlign = 'right';
  6212. if (editorUi.editor.cancelFirst)
  6213. {
  6214. buttons.appendChild(cancelBtn);
  6215. buttons.appendChild(applyBtn);
  6216. }
  6217. else
  6218. {
  6219. buttons.appendChild(applyBtn);
  6220. buttons.appendChild(cancelBtn);
  6221. }
  6222. div.appendChild(buttons);
  6223. this.container = div;
  6224. };
  6225. var EditGeometryDialog = function(editorUi, vertices)
  6226. {
  6227. var graph = editorUi.editor.graph;
  6228. var geo = (vertices.length == 1) ? graph.getCellGeometry(vertices[0]) : null;
  6229. var div = document.createElement('div');
  6230. var table = document.createElement('table');
  6231. var tbody = document.createElement('tbody');
  6232. var row = document.createElement('tr');
  6233. var left = document.createElement('td');
  6234. var right = document.createElement('td');
  6235. table.style.paddingLeft = '6px';
  6236. mxUtils.write(left, mxResources.get('relative') + ':');
  6237. var relInput = document.createElement('input');
  6238. relInput.setAttribute('type', 'checkbox');
  6239. if (geo != null && geo.relative)
  6240. {
  6241. relInput.setAttribute('checked', 'checked');
  6242. relInput.defaultChecked = true;
  6243. }
  6244. this.init = function()
  6245. {
  6246. relInput.focus();
  6247. };
  6248. right.appendChild(relInput);
  6249. row.appendChild(left);
  6250. row.appendChild(right);
  6251. tbody.appendChild(row);
  6252. row = document.createElement('tr');
  6253. left = document.createElement('td');
  6254. right = document.createElement('td');
  6255. mxUtils.write(left, mxResources.get('left') + ':');
  6256. var xInput = document.createElement('input');
  6257. xInput.setAttribute('type', 'text');
  6258. xInput.style.width = '100px';
  6259. xInput.value = (geo != null) ? geo.x : '';
  6260. right.appendChild(xInput);
  6261. row.appendChild(left);
  6262. row.appendChild(right);
  6263. tbody.appendChild(row);
  6264. row = document.createElement('tr');
  6265. left = document.createElement('td');
  6266. right = document.createElement('td');
  6267. mxUtils.write(left, mxResources.get('top') + ':');
  6268. var yInput = document.createElement('input');
  6269. yInput.setAttribute('type', 'text');
  6270. yInput.style.width = '100px';
  6271. yInput.value = (geo != null) ? geo.y : '';
  6272. right.appendChild(yInput);
  6273. row.appendChild(left);
  6274. row.appendChild(right);
  6275. tbody.appendChild(row);
  6276. row = document.createElement('tr');
  6277. left = document.createElement('td');
  6278. right = document.createElement('td');
  6279. mxUtils.write(left, mxResources.get('dx') + ':');
  6280. var dxInput = document.createElement('input');
  6281. dxInput.setAttribute('type', 'text');
  6282. dxInput.style.width = '100px';
  6283. dxInput.value = (geo != null && geo.offset != null) ? geo.offset.x : '';
  6284. right.appendChild(dxInput);
  6285. row.appendChild(left);
  6286. row.appendChild(right);
  6287. tbody.appendChild(row);
  6288. row = document.createElement('tr');
  6289. left = document.createElement('td');
  6290. right = document.createElement('td');
  6291. mxUtils.write(left, mxResources.get('dy') + ':');
  6292. var dyInput = document.createElement('input');
  6293. dyInput.setAttribute('type', 'text');
  6294. dyInput.style.width = '100px';
  6295. dyInput.value = (geo != null && geo.offset != null) ? geo.offset.y : '';
  6296. right.appendChild(dyInput);
  6297. row.appendChild(left);
  6298. row.appendChild(right);
  6299. tbody.appendChild(row);
  6300. row = document.createElement('tr');
  6301. left = document.createElement('td');
  6302. right = document.createElement('td');
  6303. mxUtils.write(left, mxResources.get('width') + ':');
  6304. var wInput = document.createElement('input');
  6305. wInput.setAttribute('type', 'text');
  6306. wInput.style.width = '100px';
  6307. wInput.value = (geo != null) ? geo.width : '';
  6308. right.appendChild(wInput);
  6309. row.appendChild(left);
  6310. row.appendChild(right);
  6311. tbody.appendChild(row);
  6312. row = document.createElement('tr');
  6313. left = document.createElement('td');
  6314. right = document.createElement('td');
  6315. mxUtils.write(left, mxResources.get('height') + ':');
  6316. var hInput = document.createElement('input');
  6317. hInput.setAttribute('type', 'text');
  6318. hInput.style.width = '100px';
  6319. hInput.value = (geo != null) ? geo.height : '';
  6320. right.appendChild(hInput);
  6321. row.appendChild(left);
  6322. row.appendChild(right);
  6323. tbody.appendChild(row);
  6324. row = document.createElement('tr');
  6325. left = document.createElement('td');
  6326. right = document.createElement('td');
  6327. mxUtils.write(left, mxResources.get('rotation') + ':');
  6328. var rotInput = document.createElement('input');
  6329. rotInput.setAttribute('type', 'text');
  6330. rotInput.style.width = '100px';
  6331. rotInput.value = (vertices.length == 1) ? mxUtils.getValue(graph.getCellStyle(vertices[0]),
  6332. mxConstants.STYLE_ROTATION, 0) : '';
  6333. right.appendChild(rotInput);
  6334. row.appendChild(left);
  6335. row.appendChild(right);
  6336. tbody.appendChild(row);
  6337. table.appendChild(tbody);
  6338. div.appendChild(table);
  6339. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  6340. {
  6341. editorUi.hideDialog();
  6342. });
  6343. cancelBtn.className = 'geBtn';
  6344. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  6345. {
  6346. editorUi.hideDialog();
  6347. graph.getModel().beginUpdate();
  6348. try
  6349. {
  6350. for (var i = 0; i < vertices.length; i++)
  6351. {
  6352. var g = graph.getCellGeometry(vertices[i]);
  6353. if (g != null)
  6354. {
  6355. g = g.clone();
  6356. if (graph.isCellMovable(vertices[i]))
  6357. {
  6358. g.relative = relInput.checked;
  6359. if (mxUtils.trim(xInput.value).length > 0)
  6360. {
  6361. g.x = Number(xInput.value);
  6362. }
  6363. if (mxUtils.trim(yInput.value).length > 0)
  6364. {
  6365. g.y = Number(yInput.value);
  6366. }
  6367. if (mxUtils.trim(dxInput.value).length > 0)
  6368. {
  6369. if (g.offset == null)
  6370. {
  6371. g.offset = new mxPoint();
  6372. }
  6373. g.offset.x = Number(dxInput.value);
  6374. }
  6375. if (mxUtils.trim(dyInput.value).length > 0)
  6376. {
  6377. if (g.offset == null)
  6378. {
  6379. g.offset = new mxPoint();
  6380. }
  6381. g.offset.y = Number(dyInput.value);
  6382. }
  6383. }
  6384. if (graph.isCellResizable(vertices[i]))
  6385. {
  6386. if (mxUtils.trim(wInput.value).length > 0)
  6387. {
  6388. g.width = Number(wInput.value);
  6389. }
  6390. if (mxUtils.trim(hInput.value).length > 0)
  6391. {
  6392. g.height = Number(hInput.value);
  6393. }
  6394. }
  6395. graph.getModel().setGeometry(vertices[i], g);
  6396. }
  6397. if (mxUtils.trim(rotInput.value).length > 0)
  6398. {
  6399. graph.setCellStyles(mxConstants.STYLE_ROTATION, Number(rotInput.value), [vertices[i]]);
  6400. }
  6401. }
  6402. }
  6403. finally
  6404. {
  6405. graph.getModel().endUpdate();
  6406. }
  6407. });
  6408. applyBtn.className = 'geBtn gePrimaryBtn';
  6409. mxEvent.addListener(div, 'keypress', function(e)
  6410. {
  6411. if (e.keyCode == 13)
  6412. {
  6413. applyBtn.click();
  6414. }
  6415. });
  6416. var buttons = document.createElement('div');
  6417. buttons.style.marginTop = '20px';
  6418. buttons.style.textAlign = 'right';
  6419. if (editorUi.editor.cancelFirst)
  6420. {
  6421. buttons.appendChild(cancelBtn);
  6422. buttons.appendChild(applyBtn);
  6423. }
  6424. else
  6425. {
  6426. buttons.appendChild(applyBtn);
  6427. buttons.appendChild(cancelBtn);
  6428. }
  6429. div.appendChild(buttons);
  6430. this.container = div;
  6431. };
  6432. /**
  6433. * Constructs a new dialog for creating files from templates.
  6434. */
  6435. var LibraryDialog = function(editorUi, name, library, initialImages, file, mode)
  6436. {
  6437. var images = [];
  6438. var graph = editorUi.editor.graph;
  6439. var outer = document.createElement('div');
  6440. outer.style.height = '100%';
  6441. var header = document.createElement('div');
  6442. header.style.whiteSpace = 'nowrap';
  6443. header.style.height = '40px';
  6444. outer.appendChild(header);
  6445. mxUtils.write(header, mxResources.get('filename') + ':');
  6446. var nameValue = name;
  6447. if (nameValue == null)
  6448. {
  6449. nameValue = editorUi.defaultLibraryName + '.xml';
  6450. }
  6451. var nameInput = document.createElement('input');
  6452. nameInput.setAttribute('value', nameValue);
  6453. nameInput.style.marginRight = '20px';
  6454. nameInput.style.marginLeft = '10px';
  6455. nameInput.style.width = '500px';
  6456. if (file != null && !file.isRenamable())
  6457. {
  6458. nameInput.setAttribute('disabled', 'true');
  6459. }
  6460. this.init = function()
  6461. {
  6462. if (file == null || file.isRenamable())
  6463. {
  6464. nameInput.focus();
  6465. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  6466. {
  6467. nameInput.select();
  6468. }
  6469. else
  6470. {
  6471. document.execCommand('selectAll', false, null);
  6472. }
  6473. }
  6474. };
  6475. header.appendChild(nameInput);
  6476. var div = document.createElement('div');
  6477. div.style.borderWidth = '1px 0px 1px 0px';
  6478. div.style.borderColor = '#d3d3d3';
  6479. div.style.borderStyle = 'solid';
  6480. div.style.marginTop = '6px';
  6481. div.style.overflow = 'auto';
  6482. div.style.height = '340px';
  6483. div.style.backgroundPosition = 'center center';
  6484. div.style.backgroundRepeat = 'no-repeat';
  6485. if (images.length == 0 && Graph.fileSupport)
  6486. {
  6487. div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
  6488. }
  6489. var bg = document.createElement('div');
  6490. bg.style.position = 'absolute';
  6491. bg.style.width = '640px';
  6492. bg.style.top = '260px';
  6493. bg.style.textAlign = 'center';
  6494. bg.style.fontSize = '22px';
  6495. bg.style.color = '#a0c3ff';
  6496. mxUtils.write(bg, mxResources.get('dragImagesHere'));
  6497. outer.appendChild(bg);
  6498. var entries = {};
  6499. var ew = 100;
  6500. var eh = 100;
  6501. var dragSourceIndex = null;
  6502. var dropTargetIndex = null;
  6503. function getIndexForEvent(evt)
  6504. {
  6505. var dropTarget = document.elementFromPoint(evt.clientX, evt.clientY);
  6506. while (dropTarget != null && dropTarget.parentNode != div)
  6507. {
  6508. dropTarget = dropTarget.parentNode;
  6509. }
  6510. var result = null;
  6511. if (dropTarget != null)
  6512. {
  6513. var tmp = div.firstChild;
  6514. result = 0;
  6515. while (tmp != null && tmp != dropTarget)
  6516. {
  6517. tmp = tmp.nextSibling;
  6518. result++;
  6519. }
  6520. }
  6521. return result;
  6522. };
  6523. var stopEditing = null;
  6524. var stopWrapper = function(evt)
  6525. {
  6526. var source = mxEvent.getSource(evt);
  6527. if (source.getAttribute('contentEditable') != 'true' && stopEditing != null)
  6528. {
  6529. stopEditing();
  6530. stopEditing = null;
  6531. mxEvent.consume(evt);
  6532. }
  6533. };
  6534. mxEvent.addListener(div, 'mousedown', stopWrapper);
  6535. mxEvent.addListener(div, 'pointerdown', stopWrapper);
  6536. mxEvent.addListener(div, 'touchstart', stopWrapper);
  6537. // For converting image URLs
  6538. var converter = new mxUrlConverter();
  6539. var errorShowed = false;
  6540. function addButton(data, mimeType, x, y, w, h, img, aspect, title)
  6541. {
  6542. // Ignores duplicates
  6543. try
  6544. {
  6545. if (mimeType == null || mimeType.substring(0, 6) == 'image/')
  6546. {
  6547. if ((data == null && img != null) || entries[data] == null)
  6548. {
  6549. div.style.backgroundImage = '';
  6550. bg.style.display = 'none';
  6551. var iw = w;
  6552. var ih = h;
  6553. if (w > editorUi.maxImageSize || h > editorUi.maxImageSize)
  6554. {
  6555. var s = Math.min(1, Math.min(editorUi.maxImageSize / Math.max(1, w)),
  6556. editorUi.maxImageSize / Math.max(1, h));
  6557. w *= s;
  6558. h *= s;
  6559. }
  6560. if (iw > ih)
  6561. {
  6562. ih = Math.round(ih * ew / iw);
  6563. iw = ew;
  6564. }
  6565. else
  6566. {
  6567. iw = Math.round(iw * eh / ih);
  6568. ih = eh;
  6569. }
  6570. var wrapper = document.createElement('div');
  6571. wrapper.setAttribute('draggable', 'true');
  6572. wrapper.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  6573. wrapper.style.position = 'relative';
  6574. wrapper.style.cursor = 'move';
  6575. mxUtils.setPrefixedStyle(wrapper.style, 'transition', 'transform .1s ease-in-out');
  6576. if (data != null)
  6577. {
  6578. var elt = document.createElement('img');
  6579. elt.setAttribute('src', converter.convert(data));
  6580. elt.style.width = iw + 'px';
  6581. elt.style.height = ih + 'px';
  6582. elt.style.margin = '10px';
  6583. elt.style.paddingBottom = Math.floor((eh - ih) / 2) + 'px';
  6584. elt.style.paddingLeft = Math.floor((ew - iw) / 2) + 'px';
  6585. wrapper.appendChild(elt);
  6586. }
  6587. else if (img != null)
  6588. {
  6589. var cells = editorUi.stringToCells(Graph.decompress(img.xml));
  6590. if (cells.length > 0)
  6591. {
  6592. editorUi.sidebar.createThumb(cells, ew, eh, wrapper, null, true, false);
  6593. // Needs inline block on SVG for delete icon to appear on same line
  6594. wrapper.firstChild.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  6595. wrapper.firstChild.style.cursor = '';
  6596. }
  6597. }
  6598. var rem = document.createElement('img');
  6599. rem.setAttribute('src', Editor.closeImage);
  6600. rem.setAttribute('border', '0');
  6601. rem.setAttribute('title', mxResources.get('delete'));
  6602. rem.setAttribute('align', 'top');
  6603. rem.style.paddingTop = '4px';
  6604. rem.style.position = 'absolute';
  6605. rem.style.marginLeft = '-12px';
  6606. rem.style.zIndex = '1';
  6607. rem.style.cursor = 'pointer';
  6608. // Blocks dragging of remove icon
  6609. mxEvent.addListener(rem, 'dragstart', function(evt)
  6610. {
  6611. mxEvent.consume(evt);
  6612. });
  6613. (function(wrapperDiv, dataParam, imgParam)
  6614. {
  6615. mxEvent.addListener(rem, 'click', function(evt)
  6616. {
  6617. entries[dataParam] = null;
  6618. for (var i = 0; i < images.length; i++)
  6619. {
  6620. if ((images[i].data != null && images[i].data == dataParam) ||
  6621. (images[i].xml != null && imgParam != null &&
  6622. images[i].xml == imgParam.xml))
  6623. {
  6624. images.splice(i, 1);
  6625. break;
  6626. }
  6627. }
  6628. wrapper.parentNode.removeChild(wrapperDiv);
  6629. if (images.length == 0)
  6630. {
  6631. div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
  6632. bg.style.display = '';
  6633. }
  6634. mxEvent.consume(evt);
  6635. });
  6636. // Workaround for accidental select all
  6637. mxEvent.addListener(rem, 'dblclick', function(evt)
  6638. {
  6639. mxEvent.consume(evt);
  6640. });
  6641. })(wrapper, data, img);
  6642. wrapper.appendChild(rem);
  6643. wrapper.style.marginBottom = '30px';
  6644. var label = document.createElement('div');
  6645. label.style.position = 'absolute';
  6646. label.style.boxSizing = 'border-box';
  6647. label.style.bottom = '-18px';
  6648. label.style.left = '10px';
  6649. label.style.right = '10px';
  6650. label.style.backgroundColor = '#ffffff';
  6651. label.style.overflow = 'hidden';
  6652. label.style.textAlign = 'center';
  6653. var entry = null;
  6654. if (data != null)
  6655. {
  6656. entry = {data: data, w: w, h: h, title: title};
  6657. if (aspect != null)
  6658. {
  6659. entry.aspect = aspect;
  6660. }
  6661. entries[data] = elt;
  6662. images.push(entry);
  6663. }
  6664. else if (img != null)
  6665. {
  6666. img.aspect = 'fixed';
  6667. images.push(img);
  6668. entry = img;
  6669. }
  6670. function updateLabel()
  6671. {
  6672. label.innerHTML = '';
  6673. label.style.cursor = 'pointer';
  6674. label.style.whiteSpace = 'nowrap';
  6675. label.style.textOverflow = 'ellipsis';
  6676. mxUtils.write(label, (entry.title != null && entry.title.length > 0) ?
  6677. entry.title : mxResources.get('untitled'));
  6678. if (entry.title == null || entry.title.length == 0)
  6679. {
  6680. label.style.color = '#d0d0d0';
  6681. }
  6682. else
  6683. {
  6684. label.style.color = '';
  6685. }
  6686. };
  6687. mxEvent.addListener(label, 'keydown', function(evt)
  6688. {
  6689. if (evt.keyCode == 13 && stopEditing != null)
  6690. {
  6691. stopEditing();
  6692. stopEditing = null;
  6693. mxEvent.consume(evt);
  6694. }
  6695. });
  6696. updateLabel();
  6697. wrapper.appendChild(label);
  6698. // Blocks dragging of label
  6699. mxEvent.addListener(label, 'mousedown', function(evt)
  6700. {
  6701. if (label.getAttribute('contentEditable') != 'true')
  6702. {
  6703. mxEvent.consume(evt);
  6704. }
  6705. });
  6706. var startEditing = function(evt)
  6707. {
  6708. // Workaround for various issues in IE
  6709. if (!mxClient.IS_IOS && !mxClient.IS_QUIRKS && !mxClient.IS_FF &&
  6710. (document.documentMode == null || document.documentMode > 9))
  6711. {
  6712. if (label.getAttribute('contentEditable') != 'true')
  6713. {
  6714. if (stopEditing != null)
  6715. {
  6716. stopEditing();
  6717. stopEditing = null;
  6718. }
  6719. if (entry.title == null || entry.title.length == 0)
  6720. {
  6721. label.innerHTML = '';
  6722. }
  6723. label.style.textOverflow = '';
  6724. label.style.whiteSpace = '';
  6725. label.style.cursor = 'text';
  6726. label.style.color = '';
  6727. label.setAttribute('contentEditable', 'true');
  6728. label.focus();
  6729. document.execCommand('selectAll', false, null);
  6730. stopEditing = function()
  6731. {
  6732. label.removeAttribute('contentEditable');
  6733. label.style.cursor = 'pointer';
  6734. entry.title = label.innerHTML;
  6735. updateLabel();
  6736. }
  6737. mxEvent.consume(evt);
  6738. }
  6739. }
  6740. else
  6741. {
  6742. var dlg = new FilenameDialog(editorUi, entry.title || '', mxResources.get('ok'), function(newTitle)
  6743. {
  6744. if (newTitle != null)
  6745. {
  6746. entry.title = newTitle;
  6747. updateLabel();
  6748. }
  6749. }, mxResources.get('enterValue'));
  6750. editorUi.showDialog(dlg.container, 300, 80, true, true);
  6751. dlg.init();
  6752. mxEvent.consume(evt);
  6753. }
  6754. };
  6755. mxEvent.addListener(label, 'click', startEditing);
  6756. mxEvent.addListener(wrapper, 'dblclick', startEditing);
  6757. div.appendChild(wrapper);
  6758. mxEvent.addListener(wrapper, 'dragstart', function(evt)
  6759. {
  6760. if (data == null && img != null)
  6761. {
  6762. rem.style.visibility = 'hidden';
  6763. label.style.visibility = 'hidden';
  6764. }
  6765. // Workaround for no DnD on DIV in FF
  6766. if (mxClient.IS_FF && img.xml != null)
  6767. {
  6768. evt.dataTransfer.setData('Text', img.xml);
  6769. }
  6770. dragSourceIndex = getIndexForEvent(evt);
  6771. // Workaround for missing drag preview in Google Chrome
  6772. if (mxClient.IS_GC)
  6773. {
  6774. wrapper.style.opacity = '0.9';
  6775. }
  6776. window.setTimeout(function()
  6777. {
  6778. mxUtils.setPrefixedStyle(wrapper.style, 'transform', 'scale(0.5,0.5)');
  6779. mxUtils.setOpacity(wrapper, 30);
  6780. rem.style.visibility = '';
  6781. label.style.visibility = '';
  6782. }, 0);
  6783. });
  6784. mxEvent.addListener(wrapper, 'dragend', function(evt)
  6785. {
  6786. if (rem.style.visibility == 'hidden')
  6787. {
  6788. rem.style.visibility = '';
  6789. label.style.visibility = '';
  6790. }
  6791. dragSourceIndex = null;
  6792. mxUtils.setOpacity(wrapper, 100);
  6793. mxUtils.setPrefixedStyle(wrapper.style, 'transform', null);
  6794. });
  6795. }
  6796. else if (!errorShowed)
  6797. {
  6798. errorShowed = true;
  6799. editorUi.handleError({message: mxResources.get('fileExists')})
  6800. }
  6801. }
  6802. else
  6803. {
  6804. var done = false;
  6805. try
  6806. {
  6807. editorUi.spinner.stop();
  6808. var doc = mxUtils.parseXml(data);
  6809. if (doc.documentElement.nodeName == 'mxlibrary')
  6810. {
  6811. var temp = JSON.parse(mxUtils.getTextContent(doc.documentElement));
  6812. if (temp != null && temp.length > 0)
  6813. {
  6814. for (var i = 0; i < temp.length; i++)
  6815. {
  6816. if (temp[i].xml != null)
  6817. {
  6818. addButton(null, null, 0, 0, 0, 0, temp[i]);
  6819. }
  6820. else
  6821. {
  6822. addButton(temp[i].data, null, 0, 0, temp[i].w, temp[i].h, null, 'fixed', temp[i].title);
  6823. }
  6824. }
  6825. }
  6826. done = true;
  6827. }
  6828. else if (doc.documentElement.nodeName == 'mxfile')
  6829. {
  6830. var pages = doc.documentElement.getElementsByTagName('diagram');
  6831. for (var i = 0; i < pages.length; i++)
  6832. {
  6833. var temp = mxUtils.getTextContent(pages[i]);
  6834. var cells = editorUi.stringToCells(Graph.decompress(temp));
  6835. var size = editorUi.editor.graph.getBoundingBoxFromGeometry(cells);
  6836. addButton(null, null, 0, 0, 0, 0, {xml: temp, w: size.width, h: size.height});
  6837. }
  6838. done = true;
  6839. }
  6840. }
  6841. catch (e)
  6842. {
  6843. // ignore
  6844. }
  6845. if (!done)
  6846. {
  6847. editorUi.spinner.stop();
  6848. editorUi.handleError({message: mxResources.get('errorLoadingFile')})
  6849. }
  6850. }
  6851. }
  6852. catch (e)
  6853. {
  6854. // ignore
  6855. }
  6856. return null;
  6857. };
  6858. if (initialImages != null)
  6859. {
  6860. for (var i = 0; i < initialImages.length; i++)
  6861. {
  6862. var img = initialImages[i];
  6863. addButton(img.data, null, 0, 0, img.w, img.h, img, img.aspect, img.title);
  6864. }
  6865. }
  6866. // Setup the dnd listeners
  6867. mxEvent.addListener(div, 'dragleave', function(evt)
  6868. {
  6869. bg.style.cursor = '';
  6870. var source = mxEvent.getSource(evt);
  6871. while (source != null)
  6872. {
  6873. if (source == div || source == bg)
  6874. {
  6875. evt.stopPropagation();
  6876. evt.preventDefault();
  6877. break;
  6878. }
  6879. source = source.parentNode;
  6880. }
  6881. });
  6882. function dragOver(evt)
  6883. {
  6884. evt.dataTransfer.dropEffect = (dragSourceIndex != null) ? 'move' : 'copy';
  6885. evt.stopPropagation();
  6886. evt.preventDefault();
  6887. };
  6888. var createImportHandler = function(evt)
  6889. {
  6890. return function(data, mimeType, x, y, w, h, img, doneFn, file)
  6891. {
  6892. if (file != null && (/(\.vsdx)($|\?)/i.test(file.name) || /(\.vssx)($|\?)/i.test(file.name)))
  6893. {
  6894. editorUi.importVisio(file, mxUtils.bind(this, function(xml)
  6895. {
  6896. editorUi.spinner.stop();
  6897. addButton(xml, mimeType, x, y, w, h, img, 'fixed', (mxEvent.isAltDown(evt)) ?
  6898. null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
  6899. }));
  6900. }
  6901. else if (file != null && !editorUi.isOffline() && new XMLHttpRequest().upload && editorUi.isRemoteFileFormat(data, file.name))
  6902. {
  6903. editorUi.parseFile(file, mxUtils.bind(this, function(xhr)
  6904. {
  6905. if (xhr.readyState == 4)
  6906. {
  6907. editorUi.spinner.stop();
  6908. if (xhr.status >= 200 && xhr.status <= 299)
  6909. {
  6910. var xml = xhr.responseText;
  6911. addButton(xml, mimeType, x, y, w, h, img, 'fixed', (mxEvent.isAltDown(evt)) ?
  6912. null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
  6913. div.scrollTop = div.scrollHeight;
  6914. }
  6915. }
  6916. }));
  6917. }
  6918. else
  6919. {
  6920. addButton(data, mimeType, x, y, w, h, img, 'fixed', (mxEvent.isAltDown(evt)) ?
  6921. null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
  6922. div.scrollTop = div.scrollHeight;
  6923. }
  6924. };
  6925. };
  6926. function dropHandler(evt)
  6927. {
  6928. evt.stopPropagation();
  6929. evt.preventDefault();
  6930. errorShowed = false;
  6931. dropTargetIndex = getIndexForEvent(evt);
  6932. if (dragSourceIndex != null)
  6933. {
  6934. if (dropTargetIndex != null && dropTargetIndex < div.children.length)
  6935. {
  6936. images.splice((dropTargetIndex > dragSourceIndex) ? dropTargetIndex - 1 : dropTargetIndex,
  6937. 0, images.splice(dragSourceIndex, 1)[0]);
  6938. div.insertBefore(div.children[dragSourceIndex], div.children[dropTargetIndex]);
  6939. }
  6940. else
  6941. {
  6942. images.push(images.splice(dragSourceIndex, 1)[0]);
  6943. div.appendChild(div.children[dragSourceIndex]);
  6944. }
  6945. }
  6946. else if (evt.dataTransfer.files.length > 0)
  6947. {
  6948. editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxImageSize, createImportHandler(evt));
  6949. }
  6950. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  6951. {
  6952. var uri = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
  6953. if (/(\.jpg)($|\?)/i.test(uri) || /(\.png)($|\?)/i.test(uri) ||
  6954. /(\.gif)($|\?)/i.test(uri) || /(\.svg)($|\?)/i.test(uri))
  6955. {
  6956. editorUi.loadImage(uri, function(img)
  6957. {
  6958. addButton(uri, null, 0, 0, img.width, img.height);
  6959. div.scrollTop = div.scrollHeight;
  6960. });
  6961. }
  6962. }
  6963. evt.stopPropagation();
  6964. evt.preventDefault();
  6965. };
  6966. mxEvent.addListener(div, 'dragover', dragOver);
  6967. mxEvent.addListener(div, 'drop', dropHandler);
  6968. mxEvent.addListener(bg, 'dragover', dragOver);
  6969. mxEvent.addListener(bg, 'drop', dropHandler);
  6970. outer.appendChild(div);
  6971. var btns = document.createElement('div');
  6972. btns.style.textAlign = 'right';
  6973. btns.style.marginTop = '20px';
  6974. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  6975. {
  6976. editorUi.hideDialog(true);
  6977. });
  6978. cancelBtn.setAttribute('id', 'btnCancel');
  6979. cancelBtn.className = 'geBtn';
  6980. if (editorUi.editor.cancelFirst)
  6981. {
  6982. btns.appendChild(cancelBtn);
  6983. }
  6984. var btn = mxUtils.button(mxResources.get('export'), function()
  6985. {
  6986. var data = editorUi.createLibraryDataFromImages(images);
  6987. var filename = nameInput.value;
  6988. if (!/(\.xml)$/i.test(filename))
  6989. {
  6990. filename += '.xml';
  6991. }
  6992. if (editorUi.isLocalFileSave())
  6993. {
  6994. editorUi.saveLocalFile(data, filename, 'text/xml', null, null, true);
  6995. }
  6996. else
  6997. {
  6998. new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(filename) +
  6999. '&format=xml&xml=' + encodeURIComponent(data)).simulate(document, '_blank');
  7000. }
  7001. });
  7002. btn.setAttribute('id', 'btnDownload');
  7003. btn.className = 'geBtn';
  7004. btns.appendChild(btn);
  7005. var fileInput = document.createElement('input');
  7006. fileInput.setAttribute('multiple', 'multiple');
  7007. fileInput.setAttribute('type', 'file');
  7008. if (document.documentMode == null)
  7009. {
  7010. mxEvent.addListener(fileInput, 'change', function(evt)
  7011. {
  7012. errorShowed = false;
  7013. editorUi.importFiles(fileInput.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h, img, doneFn, file)
  7014. {
  7015. createImportHandler(evt)(data, mimeType, x, y, w, h, img, doneFn, file);
  7016. // Resets input to force change event for same file
  7017. fileInput.value = '';
  7018. });
  7019. div.scrollTop = div.scrollHeight;
  7020. });
  7021. var btn = mxUtils.button(mxResources.get('import'), function()
  7022. {
  7023. if (stopEditing != null)
  7024. {
  7025. stopEditing();
  7026. stopEditing = null;
  7027. }
  7028. fileInput.click();
  7029. });
  7030. btn.setAttribute('id', 'btnAddImage');
  7031. btn.className = 'geBtn';
  7032. btns.appendChild(btn);
  7033. }
  7034. var btn = mxUtils.button(mxResources.get('addImageUrl'), function()
  7035. {
  7036. if (stopEditing != null)
  7037. {
  7038. stopEditing();
  7039. stopEditing = null;
  7040. }
  7041. editorUi.showImageDialog(mxResources.get('addImageUrl'), '', function(url, w, h)
  7042. {
  7043. errorShowed = false;
  7044. if (url != null)
  7045. {
  7046. // Image dialog returns modified data URLs which
  7047. // must be converted back to real data URL
  7048. if (url.substring(0, 11) == 'data:image/')
  7049. {
  7050. var comma = url.indexOf(',');
  7051. if (comma > 0)
  7052. {
  7053. url = url.substring(0, comma) + ';base64,' + url.substring(comma + 1);
  7054. }
  7055. }
  7056. addButton(url, null, 0, 0, w, h);
  7057. div.scrollTop = div.scrollHeight;
  7058. }
  7059. });
  7060. });
  7061. btn.setAttribute('id', 'btnAddImageUrl');
  7062. btn.className = 'geBtn';
  7063. btns.appendChild(btn);
  7064. // Indirection for overriding
  7065. this.saveBtnClickHandler = function(name, images, file, mode)
  7066. {
  7067. editorUi.saveLibrary(name, images, file, mode);
  7068. };
  7069. var btn = mxUtils.button(mxResources.get('save'),mxUtils.bind(this, function()
  7070. {
  7071. if (stopEditing != null)
  7072. {
  7073. stopEditing();
  7074. stopEditing = null;
  7075. }
  7076. this.saveBtnClickHandler(nameInput.value, images, file, mode);
  7077. }));
  7078. btn.setAttribute('id', 'btnSave');
  7079. btn.className = 'geBtn gePrimaryBtn';
  7080. btns.appendChild(btn);
  7081. if (!editorUi.editor.cancelFirst)
  7082. {
  7083. btns.appendChild(cancelBtn);
  7084. }
  7085. outer.appendChild(btns);
  7086. this.container = outer;
  7087. };
  7088. /**
  7089. * Constructs a new textarea dialog.
  7090. */
  7091. var EditShapeDialog = function(editorUi, cell, title, w, h)
  7092. {
  7093. w = (w != null) ? w : 300;
  7094. h = (h != null) ? h : 120;
  7095. var row, td;
  7096. var table = document.createElement('table');
  7097. var tbody = document.createElement('tbody');
  7098. table.style.cellPadding = '4px';
  7099. row = document.createElement('tr');
  7100. td = document.createElement('td');
  7101. td.setAttribute('colspan', '2');
  7102. td.style.fontSize = '10pt';
  7103. mxUtils.write(td, title);
  7104. row.appendChild(td);
  7105. tbody.appendChild(row);
  7106. row = document.createElement('tr');
  7107. td = document.createElement('td');
  7108. var nameInput = document.createElement('textarea');
  7109. nameInput.style.outline = 'none';
  7110. nameInput.style.resize = 'none';
  7111. nameInput.style.width = (w - 200) + 'px';
  7112. nameInput.style.height = h + 'px';
  7113. this.textarea = nameInput;
  7114. this.init = function()
  7115. {
  7116. nameInput.focus();
  7117. nameInput.scrollTop = 0;
  7118. };
  7119. td.appendChild(nameInput);
  7120. row.appendChild(td);
  7121. td = document.createElement('td');
  7122. var container = document.createElement('div');
  7123. container.style.position = 'relative';
  7124. container.style.border = '1px solid gray';
  7125. container.style.top = '6px';
  7126. container.style.width = '200px';
  7127. container.style.height = (h + 4) + 'px';
  7128. container.style.overflow = 'hidden';
  7129. container.style.marginBottom = '16px';
  7130. mxEvent.disableContextMenu(container);
  7131. td.appendChild(container);
  7132. var graph = new Graph(container);
  7133. graph.setEnabled(false);
  7134. var clone = editorUi.editor.graph.cloneCell(cell);
  7135. graph.addCells([clone]);
  7136. var state = graph.view.getState(clone);
  7137. var stencil = '';
  7138. if (state.shape != null && state.shape.stencil != null)
  7139. {
  7140. stencil = mxUtils.getPrettyXml(state.shape.stencil.desc);
  7141. }
  7142. mxUtils.write(nameInput, stencil || '');
  7143. var b = graph.getGraphBounds();
  7144. var ns = Math.min((200 - 40) / b.width, (h - 40) / b.height);
  7145. graph.view.scaleAndTranslate(ns, 20 / ns - b.x, 20 / ns - b.y);
  7146. row.appendChild(td);
  7147. tbody.appendChild(row);
  7148. row = document.createElement('tr');
  7149. td = document.createElement('td');
  7150. td.setAttribute('colspan', '2');
  7151. td.style.paddingTop = '2px';
  7152. td.style.whiteSpace = 'nowrap';
  7153. td.setAttribute('align', 'right');
  7154. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  7155. {
  7156. editorUi.hideDialog();
  7157. });
  7158. cancelBtn.className = 'geBtn';
  7159. if (editorUi.editor.cancelFirst)
  7160. {
  7161. td.appendChild(cancelBtn);
  7162. }
  7163. if (!editorUi.isOffline())
  7164. {
  7165. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  7166. {
  7167. editorUi.openLink('https://desk.draw.io/support/solutions/articles/16000052874');
  7168. });
  7169. helpBtn.className = 'geBtn';
  7170. td.appendChild(helpBtn);
  7171. }
  7172. var updateShape = function(targetGraph, targetCell, hide)
  7173. {
  7174. var newValue = nameInput.value;
  7175. // Checks if XML has changed (getPrettyXml "normalizes" DOM)
  7176. var doc = mxUtils.parseXml(newValue);
  7177. newValue = mxUtils.getPrettyXml(doc.documentElement);
  7178. // Checks for validation errors
  7179. // LATER: Validate against XSD
  7180. var errors = doc.documentElement.getElementsByTagName('parsererror');
  7181. if (errors != null && errors.length > 0)
  7182. {
  7183. editorUi.showError(mxResources.get('error'), mxResources.get('containsValidationErrors'), mxResources.get('ok'));
  7184. }
  7185. else
  7186. {
  7187. if (hide)
  7188. {
  7189. editorUi.hideDialog();
  7190. }
  7191. var isNew = !targetGraph.model.contains(targetCell);
  7192. if (!hide || isNew || newValue != stencil)
  7193. {
  7194. // Transform XML value to be used in cell style
  7195. newValue = Graph.compress(newValue);
  7196. targetGraph.getModel().beginUpdate();
  7197. try
  7198. {
  7199. // Inserts cell if required
  7200. if (isNew)
  7201. {
  7202. var pt = editorUi.editor.graph.getInsertPoint();
  7203. targetCell.geometry.x = pt.x;
  7204. targetCell.geometry.y = pt.y;
  7205. targetGraph.addCell(targetCell)
  7206. }
  7207. targetGraph.setCellStyles(mxConstants.STYLE_SHAPE, 'stencil(' + newValue + ')', [targetCell]);
  7208. }
  7209. catch (e)
  7210. {
  7211. throw e;
  7212. }
  7213. finally
  7214. {
  7215. // Updates the display
  7216. targetGraph.getModel().endUpdate();
  7217. }
  7218. // Updates selection after stencil was created for rendering
  7219. if (isNew)
  7220. {
  7221. targetGraph.setSelectionCell(targetCell);
  7222. }
  7223. }
  7224. }
  7225. };
  7226. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  7227. {
  7228. updateShape(graph, clone, false);
  7229. });
  7230. previewBtn.className = 'geBtn';
  7231. td.appendChild(previewBtn);
  7232. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  7233. {
  7234. updateShape(editorUi.editor.graph, cell, true);
  7235. });
  7236. applyBtn.className = 'geBtn gePrimaryBtn';
  7237. td.appendChild(applyBtn);
  7238. if (!editorUi.editor.cancelFirst)
  7239. {
  7240. td.appendChild(cancelBtn);
  7241. }
  7242. row.appendChild(td);
  7243. tbody.appendChild(row);
  7244. table.appendChild(tbody);
  7245. this.container = table;
  7246. };
  7247. var CustomDialog = function(editorUi, content, okFn, cancelFn, okButtonText, helpLink, buttonsContent, hideCancel)
  7248. {
  7249. var div = document.createElement('div');
  7250. div.appendChild(content);
  7251. var btns = document.createElement('div');
  7252. btns.style.marginTop = '16px';
  7253. btns.style.textAlign = 'center';
  7254. if (buttonsContent != null)
  7255. {
  7256. btns.appendChild(buttonsContent);
  7257. }
  7258. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  7259. {
  7260. editorUi.hideDialog();
  7261. if (cancelFn != null)
  7262. {
  7263. cancelFn();
  7264. }
  7265. });
  7266. cancelBtn.className = 'geBtn';
  7267. if (hideCancel)
  7268. {
  7269. cancelBtn.style.display = 'none';
  7270. }
  7271. if (editorUi.editor.cancelFirst)
  7272. {
  7273. btns.appendChild(cancelBtn);
  7274. }
  7275. if (!editorUi.isOffline() && helpLink != null)
  7276. {
  7277. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  7278. {
  7279. editorUi.openLink(helpLink);
  7280. });
  7281. helpBtn.className = 'geBtn';
  7282. btns.appendChild(helpBtn);
  7283. }
  7284. var okBtn = mxUtils.button(okButtonText || mxResources.get('ok'), function()
  7285. {
  7286. editorUi.hideDialog();
  7287. if (okFn != null)
  7288. {
  7289. okFn();
  7290. }
  7291. });
  7292. btns.appendChild(okBtn);
  7293. okBtn.className = 'geBtn gePrimaryBtn';
  7294. if (!editorUi.editor.cancelFirst)
  7295. {
  7296. btns.appendChild(cancelBtn);
  7297. }
  7298. div.appendChild(btns);
  7299. this.cancelBtn = cancelBtn;
  7300. this.okButton = okBtn;
  7301. this.container = div;
  7302. };
  7303. var TemplatesDialog = function()
  7304. {
  7305. var dialogSkeleton =
  7306. '<div class="geTempDlgHeader">' +
  7307. '<img src="/images/draw.io-logo.svg" class="geTempDlgHeaderLogo">' +
  7308. '<input type="search" class="geTempDlgSearchBox" placeholder="'+ mxResources.get('search', null, 'Search') +'">' +
  7309. '</div>' +
  7310. '<div class="geTemplatesList">' +
  7311. '<div class="geTempDlgNewDiagramlbl">'+ mxResources.get('newDiagram', null, 'New Diagram') + '</div>' +
  7312. '<div class="geTempDlgHLine"></div>' +
  7313. '<div class="geTemplatesLbl">'+ mxResources.get('templates', null, 'Templates') + '</div>' +
  7314. '</div>' +
  7315. '<div class="geTempDlgContent">' +
  7316. '<div class="geTempDlgNewDiagramCat">' +
  7317. '<div class="geTempDlgNewDiagramCatLbl">'+ mxResources.get('newDiagram', null, 'New Diagram') +'</div>' +
  7318. '<div class="geTempDlgNewDiagramCatList">' +
  7319. '</div>' +
  7320. '<div class="geTempDlgNewDiagramCatFooter">' +
  7321. '<div class="geTempDlgShowAllBtn">'+ mxResources.get('showAll', null, '+ Show all') +'</div>' +
  7322. '</div>' +
  7323. '</div>' +
  7324. '<div class="geTempDlgDiagramsList">' +
  7325. '<div class="geTempDlgDiagramsListHeader">' +
  7326. '<div class="geTempDlgDiagramsListTitle"></div>' +
  7327. '<div class="geTempDlgDiagramsListBtns">' +
  7328. '<div class="geTempDlgRadioBtn geTempDlgRadioBtnLarge" data-id="myDiagramsBtn">' +
  7329. '<img src="/images/my-diagrams.svg" class="geTempDlgMyDiagramsBtnImg"> <span>'+ mxResources.get('myDiagrams', null, 'My diagrams') + '</span>' +
  7330. '</div><div class="geTempDlgRadioBtn geTempDlgRadioBtnLarge geTempDlgRadioBtnActive" data-id="allDiagramsBtn">' +
  7331. '<img src="/images/all-diagrams-sel.svg" class="geTempDlgAllDiagramsBtnImg"> <span>'+ mxResources.get('allDiagrams', null, 'All diagrams') + '</span>' +
  7332. '</div><div class="geTempDlgSpacer"> </div><div class="geTempDlgRadioBtn geTempDlgRadioBtnSmall geTempDlgRadioBtnActive" data-id="tilesBtn">' +
  7333. '<img src="/images/tiles-sel.svg" class="geTempDlgTilesBtnImg">' +
  7334. '</div><div class="geTempDlgRadioBtn geTempDlgRadioBtnSmall" data-id="listBtn">' +
  7335. '<img src="/images/list.svg" class="geTempDlgListBtnImg">' +
  7336. '</div>' +
  7337. '</div>' +
  7338. '</div>' +
  7339. '<div class="geTempDlgDiagramsTiles">' +
  7340. '</div>'+
  7341. '</div>' +
  7342. '</div>' +
  7343. '<br style="clear:both;"/>' +
  7344. '<div class="geTempDlgFooter">' +
  7345. '<span class="geTempDlgLinkToDiagram geTempDlgLinkToDiagramHint">&#x1F6C8; ' + mxResources.get('linkToDiagramHint', null, 'Add a link to this diagram. The diagram can only be edited from the page that owns it.') + '</span>' +
  7346. '<button class="geTempDlgLinkToDiagram geTempDlgLinkToDiagramBtn">'+ mxResources.get('linkToDiagram', null, 'Link to Diagram') + '</button>' +
  7347. '<div class="geTempDlgCreateBtn">'+ mxResources.get('create', null, 'Create') + '</div>' +
  7348. '<div class="geTempDlgCancelBtn">'+ mxResources.get('cancel', null, 'Cancel') + '</div>' +
  7349. '</div>';
  7350. var div = document.createElement('div');
  7351. div.innerHTML = dialogSkeleton;
  7352. div.className = "geTemplateDlg";
  7353. //override default dialog size based on screen size if needed
  7354. var ww = window.innerWidth;
  7355. var wh = window.innerHeight;
  7356. var dw = 987, dh = 712;
  7357. if (ww * 0.9 < dw)
  7358. {
  7359. dw = Math.max(ww * 0.9, 600);
  7360. div.style.width = dw + "px";
  7361. }
  7362. if (wh * 0.9 < dh)
  7363. {
  7364. dh = Math.max(wh * 0.9, 300);
  7365. div.style.height = dh + "px";
  7366. }
  7367. this.width = dw;
  7368. this.height = dh;
  7369. this.container = div;
  7370. };
  7371. TemplatesDialog.prototype.init = function(editorUi, callback, cancelCallback,
  7372. templateFile, newDiagramCatsFile, username, recentDocsCallback, searchDocsCallback,
  7373. openExtDocCallback, linkToDiagramCallback)
  7374. {
  7375. templateFile = (templateFile != null) ? templateFile : (TEMPLATE_PATH + '/index.xml');
  7376. newDiagramCatsFile = (newDiagramCatsFile != null) ? newDiagramCatsFile : NEW_DIAGRAM_CATS_PATH + '/index.xml';
  7377. var dlgDiv = this.container;
  7378. var callInitiated = false;
  7379. var cancelPendingCall = false;
  7380. var currentEntry = null;
  7381. var currentItem = null;
  7382. var currentItemInfo = null;
  7383. var showingAll = false;
  7384. var isGetAll = true;
  7385. var showAsList = false;
  7386. var curDiagList = [];
  7387. var lastSearchStr;
  7388. var categorySelected = true;
  7389. var showAllBtn = dlgDiv.querySelector(".geTempDlgShowAllBtn");
  7390. var diagramsTiles = dlgDiv.querySelector('.geTempDlgDiagramsTiles');
  7391. var diagramsListTitle = dlgDiv.querySelector('.geTempDlgDiagramsListTitle');
  7392. var diagramsListBtns = dlgDiv.querySelector('.geTempDlgDiagramsListBtns');
  7393. var tempDlgContent = dlgDiv.querySelector('.geTempDlgContent');
  7394. var diagramsList = dlgDiv.querySelector('.geTempDlgDiagramsList');
  7395. var newDiagramCat = dlgDiv.querySelector('.geTempDlgNewDiagramCat');
  7396. var newDiagramCatList = dlgDiv.querySelector(".geTempDlgNewDiagramCatList");
  7397. var createBtn = dlgDiv.querySelector('.geTempDlgCreateBtn');
  7398. var spinner = new Spinner({
  7399. lines: 12, // The number of lines to draw
  7400. length: 10, // The length of each line
  7401. width: 5, // The line thickness
  7402. radius: 10, // The radius of the inner circle
  7403. rotate: 0, // The rotation offset
  7404. color: '#000', // #rgb or #rrggbb
  7405. speed: 1.5, // Rounds per second
  7406. trail: 60, // Afterglow percentage
  7407. shadow: false, // Whether to render a shadow
  7408. hwaccel: false, // Whether to use hardware acceleration
  7409. top: '50px',
  7410. zIndex: 2e9 // The z-index (defaults to 2000000000)
  7411. });
  7412. function deselectTempCat()
  7413. {
  7414. if (currentEntry != null)
  7415. {
  7416. currentEntry.style.fontWeight = 'normal';
  7417. currentEntry.style.textDecoration = 'none';
  7418. currentEntry = null;
  7419. }
  7420. };
  7421. mxEvent.addListener(dlgDiv.querySelector('.geTempDlgNewDiagramlbl'), 'click', function()
  7422. {
  7423. deselectTempCat();
  7424. newDiagramCat.style.display = '';
  7425. diagramsList.style.minHeight = 'calc(100% - 280px)';
  7426. getRecentDocs(isGetAll);
  7427. });
  7428. function radioClick(btn, btnImgId, btnImgFile, otherBtnId, otherBtnImgId, otherBtnImgFile, isLarge)
  7429. {
  7430. if (btn.className.indexOf('geTempDlgRadioBtnActive') > -1)
  7431. {
  7432. return false;
  7433. }
  7434. else
  7435. {
  7436. btn.className += ' geTempDlgRadioBtnActive';
  7437. dlgDiv.querySelector('.geTempDlgRadioBtn[data-id='+ otherBtnId +']').className = "geTempDlgRadioBtn " +
  7438. (isLarge? "geTempDlgRadioBtnLarge" : "geTempDlgRadioBtnSmall");
  7439. dlgDiv.querySelector('.'+ btnImgId).src = "/images/"+ btnImgFile +"-sel.svg";
  7440. dlgDiv.querySelector('.'+ otherBtnImgId).src = "/images/"+ otherBtnImgFile +".svg";
  7441. return true;
  7442. }
  7443. };
  7444. mxEvent.addListener(dlgDiv.querySelector('.geTempDlgRadioBtn[data-id=allDiagramsBtn]'), 'click', function()
  7445. {
  7446. if (radioClick(this, 'geTempDlgAllDiagramsBtnImg', 'all-diagrams', 'myDiagramsBtn', 'geTempDlgMyDiagramsBtnImg', 'my-diagrams', true))
  7447. {
  7448. isGetAll = true;
  7449. lastSearchStr == null? getRecentDocs(isGetAll) : doSearch(lastSearchStr);
  7450. }
  7451. });
  7452. mxEvent.addListener(dlgDiv.querySelector('.geTempDlgRadioBtn[data-id=myDiagramsBtn]'), 'click', function()
  7453. {
  7454. if (radioClick(this, 'geTempDlgMyDiagramsBtnImg', 'my-diagrams', 'allDiagramsBtn', 'geTempDlgAllDiagramsBtnImg', 'all-diagrams', true))
  7455. {
  7456. isGetAll = false;
  7457. lastSearchStr == null? getRecentDocs(isGetAll) : doSearch(lastSearchStr);
  7458. }
  7459. });
  7460. mxEvent.addListener(dlgDiv.querySelector('.geTempDlgRadioBtn[data-id=listBtn]'), 'click', function()
  7461. {
  7462. if (radioClick(this, 'geTempDlgListBtnImg', 'list', 'tilesBtn', 'geTempDlgTilesBtnImg', 'tiles', false))
  7463. {
  7464. showAsList = true;
  7465. fillDiagramsList(curDiagList, false, showAsList);
  7466. }
  7467. });
  7468. mxEvent.addListener(dlgDiv.querySelector('.geTempDlgRadioBtn[data-id=tilesBtn]'), 'click', function()
  7469. {
  7470. if (radioClick(this, 'geTempDlgTilesBtnImg', 'tiles', 'listBtn', 'geTempDlgListBtnImg', 'list', false))
  7471. {
  7472. showAsList = false;
  7473. fillDiagramsList(curDiagList, false, showAsList);
  7474. }
  7475. });
  7476. function createPreview(diagram)
  7477. {
  7478. var imgUrl = diagram.prevImgUrl || diagram.imgUrl || (TEMPLATE_PATH + '/' + diagram.url.substring(0, diagram.url.length - 4) + '.png');
  7479. var mask = document.createElement('div');
  7480. mask.className = "geTempDlgDialogMask";
  7481. dlgDiv.appendChild(mask);
  7482. var prevBox = document.createElement('div');
  7483. prevBox.className = "geTempDlgDiagramPreviewBox";
  7484. var img = document.createElement('img');
  7485. img.src = imgUrl;
  7486. prevBox.appendChild(img);
  7487. var closeBtn = document.createElement('img');
  7488. closeBtn.src = "/images/close.png";
  7489. closeBtn.className = "geTempDlgPreviewCloseBtn";
  7490. closeBtn.setAttribute('title', mxResources.get("close"));
  7491. prevBox.appendChild(closeBtn);
  7492. var scrollTop = tempDlgContent.scrollTop;
  7493. function closeBox(evt)
  7494. {
  7495. tempDlgContent.removeChild(prevBox);
  7496. dlgDiv.removeChild(mask);
  7497. tempDlgContent.scrollTop = scrollTop;
  7498. };
  7499. mxEvent.addListener(closeBtn, 'click', closeBox);
  7500. mxEvent.addListener(mask, 'click', closeBox);
  7501. tempDlgContent.appendChild(prevBox);
  7502. tempDlgContent.scrollTop = 0;
  7503. //for centering the image
  7504. prevBox.style.lineHeight = prevBox.clientHeight + "px";
  7505. };
  7506. function swapActiveItem(newItem, activeCls, itemInfo)
  7507. {
  7508. if (currentItem != null)
  7509. {
  7510. var classes = currentItem.className.split(" ");
  7511. for (var i = 0; i < classes.length; i++)
  7512. {
  7513. if (classes[i].indexOf("Active") > -1)
  7514. {
  7515. classes.splice(i, 1);
  7516. break;
  7517. }
  7518. }
  7519. currentItem.className = classes.join(" ");
  7520. }
  7521. if (newItem != null)
  7522. {
  7523. currentItem = newItem;
  7524. currentItem.className += " " + activeCls;
  7525. currentItemInfo = itemInfo;
  7526. categorySelected = itemInfo.isCategory;
  7527. //activate create button
  7528. createBtn.className = "geTempDlgCreateBtn";
  7529. }
  7530. else
  7531. {
  7532. currentItem = null;
  7533. currentItemInfo = null;
  7534. //disable create button
  7535. createBtn.className = "geTempDlgCreateBtn geTempDlgCreateBtnDisabled";
  7536. }
  7537. };
  7538. function handleDialogOK(linkToDiagram)
  7539. {
  7540. if (currentItemInfo != null)
  7541. {
  7542. var itemInfo = currentItemInfo;
  7543. //disable create button
  7544. currentItemInfo = null;
  7545. createBtn.className = "geTempDlgCreateBtn geTempDlgCreateBtnDisabled geTempDlgCreateBtnBusy";
  7546. if (itemInfo.isExternal)
  7547. {
  7548. if (linkToDiagram == true)
  7549. {
  7550. linkToDiagramCallback(itemInfo.url, itemInfo, "nameInput.value");
  7551. }
  7552. else
  7553. {
  7554. openExtDocCallback(itemInfo.url, itemInfo, "nameInput.value");
  7555. }
  7556. editorUi.hideDialog(true);
  7557. }
  7558. else
  7559. {
  7560. mxUtils.get(TEMPLATE_PATH + '/' + itemInfo.url, mxUtils.bind(this, function(req)
  7561. {
  7562. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  7563. {
  7564. callback(req.getText(), "nameInput.value");
  7565. editorUi.hideDialog(true);
  7566. }
  7567. else
  7568. {
  7569. //TODO Handle errors
  7570. }
  7571. }));
  7572. }
  7573. }
  7574. };
  7575. function showLinkToDiagram(isShown)
  7576. {
  7577. var linkDisplay = isShown? '' : 'none';
  7578. var elems = dlgDiv.querySelectorAll(".geTempDlgLinkToDiagram");
  7579. for(var i = 0; i < elems.length; i++)
  7580. {
  7581. elems[i].style.display = linkDisplay;
  7582. }
  7583. };
  7584. function fillDiagramsList(diagrams, isTemplate, asList)
  7585. {
  7586. function setSubmitBtnLbl()
  7587. {
  7588. if (isTemplate)
  7589. {
  7590. createBtn.innerHTML = mxUtils.htmlEntities(mxResources.get('create'));
  7591. }
  7592. else
  7593. {
  7594. createBtn.innerHTML = mxUtils.htmlEntities(mxResources.get('copy'));
  7595. }
  7596. showLinkToDiagram (!isTemplate);
  7597. };
  7598. diagramsTiles.innerHTML = '';
  7599. swapActiveItem();
  7600. curDiagList = diagrams;
  7601. var grid = null;
  7602. if (asList)
  7603. {
  7604. grid = document.createElement('table');
  7605. grid.className = 'geTempDlgDiagramsListGrid';
  7606. //create header row
  7607. var hrow = document.createElement('tr');
  7608. var th = document.createElement('th');
  7609. th.style.width = "50%";
  7610. th.innerHTML = mxUtils.htmlEntities(mxResources.get('diagram', null, 'Diagram'));
  7611. hrow.appendChild(th);
  7612. th = document.createElement('th');
  7613. th.style.width = "25%";
  7614. th.innerHTML = mxUtils.htmlEntities(mxResources.get('changedBy', null, 'Changed By'));
  7615. hrow.appendChild(th);
  7616. th = document.createElement('th');
  7617. th.style.width = "25%";
  7618. th.innerHTML = mxUtils.htmlEntities(mxResources.get('lastModifiedOn', null, 'Last modified on'));
  7619. hrow.appendChild(th);
  7620. grid.appendChild(hrow);
  7621. diagramsTiles.appendChild(grid);
  7622. }
  7623. //TODO support paging
  7624. for (var i = 0; i < diagrams.length; i++)
  7625. {
  7626. diagrams[i].isExternal = !isTemplate;
  7627. var url = diagrams[i].url;
  7628. var title = mxUtils.htmlEntities(diagrams[i].title);
  7629. var tooltip = diagrams[i].tooltip || diagrams[i].title;
  7630. var imgUrl = diagrams[i].imgUrl;
  7631. var changedBy = mxUtils.htmlEntities(diagrams[i].changedBy || "");
  7632. var lastModifiedOn = mxUtils.htmlEntities(diagrams[i].lastModifiedOn || "");
  7633. if (!imgUrl)
  7634. {
  7635. imgUrl = TEMPLATE_PATH + '/' + url.substring(0, url.length - 4) + '.png';
  7636. }
  7637. var titleLimit = asList? 50 : 15;
  7638. if (title != null && title.length > titleLimit)
  7639. {
  7640. title = title.substring(0, titleLimit) + '&hellip;';
  7641. }
  7642. if (asList)
  7643. {
  7644. var row = document.createElement('tr');
  7645. var td = document.createElement('td');
  7646. var prevImg = document.createElement('img');
  7647. prevImg.src = "/images/icon-search.svg";
  7648. prevImg.className = "geTempDlgDiagramListPreviewBtn";
  7649. prevImg.setAttribute('title', mxResources.get("preview"));
  7650. td.appendChild(prevImg);
  7651. var titleSpan = document.createElement('span');
  7652. titleSpan.className = "geTempDlgDiagramTitle";
  7653. titleSpan.innerHTML = title;
  7654. td.appendChild(titleSpan);
  7655. row.appendChild(td);
  7656. td = document.createElement('td');
  7657. td.innerHTML = changedBy;
  7658. row.appendChild(td);
  7659. td = document.createElement('td');
  7660. td.innerHTML = lastModifiedOn;
  7661. row.appendChild(td);
  7662. grid.appendChild(row);
  7663. if (currentItem == null)
  7664. {
  7665. setSubmitBtnLbl();
  7666. swapActiveItem(row, "geTempDlgDiagramsListGridActive", diagrams[i]);
  7667. }
  7668. (function(diagram2, row2)
  7669. {
  7670. mxEvent.addListener(row, 'click', function()
  7671. {
  7672. if (currentItem != row2)
  7673. {
  7674. setSubmitBtnLbl();
  7675. swapActiveItem(row2, "geTempDlgDiagramsListGridActive", diagram2);
  7676. }
  7677. });
  7678. mxEvent.addListener(row, 'dblclick', handleDialogOK);
  7679. mxEvent.addListener(prevImg, 'click', function()
  7680. {
  7681. createPreview(diagram2);
  7682. });
  7683. })(diagrams[i], row);
  7684. }
  7685. else
  7686. {
  7687. var tile = document.createElement('div');
  7688. tile.className = "geTempDlgDiagramTile";
  7689. tile.setAttribute('title', tooltip);
  7690. if (currentItem == null)
  7691. {
  7692. setSubmitBtnLbl();
  7693. swapActiveItem(tile, "geTempDlgDiagramTileActive", diagrams[i]);
  7694. }
  7695. var imgDiv = document.createElement('div');
  7696. imgDiv.className = "geTempDlgDiagramTileImg geTempDlgDiagramTileImgLoading";
  7697. var img = document.createElement('img');
  7698. img.style.display = "none";
  7699. (function(img2, imgDiv2)
  7700. {
  7701. img.onload = function()
  7702. {
  7703. imgDiv2.className = "geTempDlgDiagramTileImg";
  7704. img2.style.display = "";
  7705. }
  7706. img.onerror = function()
  7707. {
  7708. imgDiv2.className = "geTempDlgDiagramTileImg geTempDlgDiagramTileImgError";
  7709. }
  7710. })(img, imgDiv);
  7711. img.src = imgUrl;
  7712. imgDiv.appendChild(img);
  7713. tile.appendChild(imgDiv);
  7714. var lblDiv = document.createElement('div');
  7715. lblDiv.className = "geTempDlgDiagramTileLbl";
  7716. lblDiv.innerHTML = title != null? title : "";
  7717. tile.appendChild(lblDiv);
  7718. var prevImg = document.createElement('img');
  7719. prevImg.src = "/images/icon-search.svg";
  7720. prevImg.className = "geTempDlgDiagramPreviewBtn";
  7721. prevImg.setAttribute('title', mxResources.get("preview"));
  7722. tile.appendChild(prevImg);
  7723. (function(diagram2, tile2)
  7724. {
  7725. mxEvent.addListener(tile, 'click', function()
  7726. {
  7727. if (currentItem != tile2)
  7728. {
  7729. setSubmitBtnLbl();
  7730. swapActiveItem(tile2, "geTempDlgDiagramTileActive", diagram2);
  7731. }
  7732. });
  7733. mxEvent.addListener(tile, 'dblclick', handleDialogOK);
  7734. mxEvent.addListener(prevImg, 'click', function()
  7735. {
  7736. createPreview(diagram2);
  7737. });
  7738. })(diagrams[i], tile);
  7739. diagramsTiles.appendChild(tile);
  7740. }
  7741. }
  7742. };
  7743. function fillNewDiagramCats(newDiagramCats, showAll)
  7744. {
  7745. newDiagramCatList.innerHTML = "";
  7746. swapActiveItem();
  7747. var catCount = !showAll && newDiagramCats.length > 5 ? 5 : newDiagramCats.length;
  7748. for (var i = 0; i < catCount; i++)
  7749. {
  7750. var cat = newDiagramCats[i];
  7751. cat.isCategory = true;
  7752. var entry = document.createElement('div');
  7753. var label = mxResources.get(cat.title);
  7754. if (label == null)
  7755. {
  7756. label = cat.title.substring(0, 1).toUpperCase() + cat.title.substring(1);
  7757. }
  7758. entry.className = 'geTempDlgNewDiagramCatItem';
  7759. entry.setAttribute('title', label);
  7760. label = mxUtils.htmlEntities(label);
  7761. if (label.length > 15)
  7762. {
  7763. label = label.substring(0, 15) + '&hellip;';
  7764. }
  7765. if (currentItem == null)
  7766. {
  7767. createBtn.innerHTML = mxUtils.htmlEntities(mxResources.get('create'));
  7768. showLinkToDiagram();
  7769. swapActiveItem(entry, "geTempDlgNewDiagramCatItemActive", cat);
  7770. }
  7771. var imgDiv = document.createElement('div');
  7772. imgDiv.className = "geTempDlgNewDiagramCatItemImg";
  7773. var img = document.createElement('img');
  7774. img.src = NEW_DIAGRAM_CATS_PATH + '/' + cat.img;
  7775. imgDiv.appendChild(img);
  7776. entry.appendChild(imgDiv);
  7777. var lblDiv = document.createElement('div');
  7778. lblDiv.className = "geTempDlgNewDiagramCatItemLbl";
  7779. lblDiv.innerHTML = label;
  7780. entry.appendChild(lblDiv);
  7781. newDiagramCatList.appendChild(entry);
  7782. (function(cat2, entry2)
  7783. {
  7784. mxEvent.addListener(entry, 'click', function()
  7785. {
  7786. if (currentItem != entry2)
  7787. {
  7788. createBtn.innerHTML = mxUtils.htmlEntities(mxResources.get('create'));
  7789. showLinkToDiagram();
  7790. swapActiveItem(entry2, "geTempDlgNewDiagramCatItemActive", cat2);
  7791. }
  7792. });
  7793. mxEvent.addListener(entry, 'dblclick', handleDialogOK);
  7794. })(cat, entry);
  7795. }
  7796. showAllBtn.style.display = newDiagramCats.length < 5 ? "none" : "";
  7797. };
  7798. mxEvent.addListener(showAllBtn, 'click', function()
  7799. {
  7800. if (showingAll)
  7801. {
  7802. newDiagramCat.style.height = "280px";
  7803. newDiagramCatList.style.height = "190px";
  7804. showAllBtn.innerHTML = mxUtils.htmlEntities(mxResources.get('showAll', null, '+ Show all'));
  7805. fillNewDiagramCats(newDiagramCats);
  7806. }
  7807. else
  7808. {
  7809. newDiagramCat.style.height = "440px";
  7810. newDiagramCatList.style.height = "355px";
  7811. showAllBtn.innerHTML = mxUtils.htmlEntities(mxResources.get('showLess', null, '- Show less'));
  7812. fillNewDiagramCats(newDiagramCats, true);
  7813. }
  7814. showingAll = !showingAll;
  7815. });
  7816. function fillTemplatesList(categories)
  7817. {
  7818. var list = dlgDiv.querySelector(".geTemplatesList");
  7819. for (var cat in categories)
  7820. {
  7821. var entry = document.createElement('div');
  7822. var label = mxResources.get(cat);
  7823. var templateList = categories[cat];
  7824. if (label == null)
  7825. {
  7826. label = cat.substring(0, 1).toUpperCase() + cat.substring(1);
  7827. }
  7828. entry.className = 'geTemplateCatLink';
  7829. entry.setAttribute('title', label + ' (' + templateList.length + ')');
  7830. label = mxUtils.htmlEntities(label);
  7831. if (label.length > 15)
  7832. {
  7833. label = label.substring(0, 15) + '&hellip;';
  7834. }
  7835. entry.innerHTML = label + ' (' + templateList.length + ')';
  7836. list.appendChild(entry);
  7837. (function(cat2, label2, entry2)
  7838. {
  7839. mxEvent.addListener(entry, 'click', function()
  7840. {
  7841. if (currentEntry != entry2)
  7842. {
  7843. if (currentEntry != null)
  7844. {
  7845. currentEntry.style.fontWeight = 'normal';
  7846. currentEntry.style.textDecoration = 'none';
  7847. }
  7848. else
  7849. {
  7850. newDiagramCat.style.display = 'none';
  7851. diagramsList.style.minHeight = '100%';
  7852. }
  7853. currentEntry = entry2;
  7854. currentEntry.style.fontWeight = 'bold';
  7855. currentEntry.style.textDecoration = 'underline';
  7856. tempDlgContent.scrollTop = 0;
  7857. if (callInitiated)
  7858. {
  7859. cancelPendingCall = true;
  7860. }
  7861. diagramsListTitle.innerHTML = label2;
  7862. diagramsListBtns.style.display = 'none';
  7863. fillDiagramsList(categories[cat2], true);
  7864. }
  7865. });
  7866. })(cat, label, entry);
  7867. }
  7868. };
  7869. var indexLoaded = false, indexLoaded2 = false;
  7870. var categories = {};
  7871. var newDiagramCats = [];
  7872. var categoryCount = 1;
  7873. mxUtils.get(templateFile, function(req)
  7874. {
  7875. // Workaround for index loaded 3 times in iOS offline mode
  7876. if (!indexLoaded)
  7877. {
  7878. indexLoaded = true;
  7879. var tmpDoc = req.getXml();
  7880. var node = tmpDoc.documentElement.firstChild;
  7881. while (node != null)
  7882. {
  7883. if (typeof(node.getAttribute) !== 'undefined')
  7884. {
  7885. var url = node.getAttribute('url');
  7886. if (url != null)
  7887. {
  7888. var slash = url.indexOf('/');
  7889. var category = url.substring(0, slash);
  7890. var list = categories[category];
  7891. if (list == null)
  7892. {
  7893. categoryCount++;
  7894. list = [];
  7895. categories[category] = list;
  7896. }
  7897. list.push({url: node.getAttribute('url'), libs: node.getAttribute('libs'),
  7898. title: node.getAttribute('title'), tooltip: node.getAttribute('url'), imgUrl: node.getAttribute('imgUrl')});
  7899. }
  7900. }
  7901. node = node.nextSibling;
  7902. }
  7903. fillTemplatesList(categories);
  7904. }
  7905. });
  7906. mxUtils.get(newDiagramCatsFile, function(req)
  7907. {
  7908. // Workaround for index loaded 3 times in iOS offline mode
  7909. if (!indexLoaded2)
  7910. {
  7911. indexLoaded2 = true;
  7912. var tmpDoc = req.getXml();
  7913. var node = tmpDoc.documentElement.firstChild;
  7914. while (node != null)
  7915. {
  7916. if (typeof(node.getAttribute) !== 'undefined')
  7917. {
  7918. var title = node.getAttribute('title');
  7919. if (title != null)
  7920. {
  7921. newDiagramCats.push({img: node.getAttribute('img'), libs: node.getAttribute('libs'),
  7922. title: node.getAttribute('title')});
  7923. }
  7924. }
  7925. node = node.nextSibling;
  7926. }
  7927. fillNewDiagramCats(newDiagramCats);
  7928. }
  7929. });
  7930. var extDiagramsCallback = function(list, errorMsg)
  7931. {
  7932. diagramsListBtns.style.display = '';
  7933. spinner.stop();
  7934. callInitiated = false;
  7935. if (cancelPendingCall)
  7936. {
  7937. cancelPendingCall = false;
  7938. return;
  7939. }
  7940. if (errorMsg)
  7941. {
  7942. diagramsTiles.innerHTML = errorMsg;
  7943. }
  7944. else if (list.length == 0)
  7945. {
  7946. diagramsTiles.innerHTML = mxUtils.htmlEntities(mxResources.get('noDiagrams', null, 'No Diagrams Found'));
  7947. }
  7948. else
  7949. {
  7950. fillDiagramsList(list, false, showAsList);
  7951. }
  7952. };
  7953. function getRecentDocs(getAll)
  7954. {
  7955. if (recentDocsCallback)
  7956. {
  7957. tempDlgContent.scrollTop = 0;
  7958. diagramsTiles.innerHTML = '';
  7959. spinner.spin(diagramsTiles);
  7960. cancelPendingCall = false;
  7961. callInitiated = true;
  7962. diagramsListTitle.innerHTML = mxUtils.htmlEntities(mxResources.get('recentDiag', null, 'Recent Diagrams'));
  7963. lastSearchStr = null;
  7964. recentDocsCallback(extDiagramsCallback, getAll? null : username);
  7965. }
  7966. };
  7967. getRecentDocs(isGetAll);
  7968. var delayTimer = null;
  7969. function doSearch(searchStr)
  7970. {
  7971. deselectTempCat();
  7972. tempDlgContent.scrollTop = 0;
  7973. diagramsTiles.innerHTML = '';
  7974. spinner.spin(diagramsTiles);
  7975. cancelPendingCall = false;
  7976. callInitiated = true;
  7977. delayTimer = null;
  7978. diagramsListTitle.innerHTML = mxUtils.htmlEntities(mxResources.get('searchResults', null, 'Search Results')) +
  7979. ' "' + mxUtils.htmlEntities(searchStr) + '"';
  7980. searchDocsCallback(searchStr, extDiagramsCallback, isGetAll? null : username);
  7981. lastSearchStr = searchStr;
  7982. };
  7983. //TODO use request id to allow only last request to show results
  7984. if (searchDocsCallback)
  7985. {
  7986. //Use keyup to detect delete and backspace
  7987. mxEvent.addListener(dlgDiv.querySelector(".geTempDlgSearchBox"), 'keyup', function(evt)
  7988. {
  7989. var searchInout = this;
  7990. if (delayTimer != null)
  7991. {
  7992. clearTimeout(delayTimer);
  7993. }
  7994. if (evt.keyCode == 13)
  7995. {
  7996. doSearch(searchInout.value);
  7997. }
  7998. else
  7999. {
  8000. delayTimer = setTimeout(function()
  8001. {
  8002. doSearch(searchInout.value);
  8003. }, 500);
  8004. }
  8005. });
  8006. }
  8007. mxEvent.addListener(createBtn, 'click', handleDialogOK);
  8008. mxEvent.addListener(dlgDiv.querySelector(".geTempDlgLinkToDiagramBtn"), 'click', function(evt)
  8009. {
  8010. handleDialogOK(true);
  8011. });
  8012. mxEvent.addListener(dlgDiv.querySelector('.geTempDlgCancelBtn'), 'click', function()
  8013. {
  8014. if (cancelCallback != null)
  8015. {
  8016. cancelCallback();
  8017. }
  8018. editorUi.hideDialog(true);
  8019. });
  8020. };
  8021. /**
  8022. * Constructs a new popup opener button dialog.
  8023. */
  8024. var BtnDialog = function(editorUi, peer, btnLbl, fn)
  8025. {
  8026. var div = document.createElement('div');
  8027. div.style.textAlign = 'center';
  8028. var hd = document.createElement('p');
  8029. hd.style.fontSize = '16pt';
  8030. hd.style.padding = '0px';
  8031. hd.style.margin = '0px';
  8032. hd.style.color = 'gray';
  8033. mxUtils.write(hd, mxResources.get('done'));
  8034. var service = 'Unknown';
  8035. var img = document.createElement('img');
  8036. img.setAttribute('border', '0');
  8037. img.setAttribute('align', 'absmiddle');
  8038. img.style.marginRight = '10px';
  8039. if (peer == editorUi.drive)
  8040. {
  8041. service = mxResources.get('googleDrive');
  8042. img.src = IMAGE_PATH + '/google-drive-logo-white.svg';
  8043. }
  8044. else if (peer == editorUi.dropbox)
  8045. {
  8046. service = mxResources.get('dropbox');
  8047. img.src = IMAGE_PATH + '/dropbox-logo-white.svg';
  8048. }
  8049. else if (peer == editorUi.oneDrive)
  8050. {
  8051. service = mxResources.get('oneDrive');
  8052. img.src = IMAGE_PATH + '/onedrive-logo-white.svg';
  8053. }
  8054. else if (peer == editorUi.gitHub)
  8055. {
  8056. service = mxResources.get('github');
  8057. img.src = IMAGE_PATH + '/github-logo-white.svg';
  8058. }
  8059. else if (peer == editorUi.trello)
  8060. {
  8061. service = mxResources.get('trello');
  8062. img.src = IMAGE_PATH + '/trello-logo-white.svg';
  8063. }
  8064. var p = document.createElement('p');
  8065. mxUtils.write(p, mxResources.get('authorizedIn', [service], 'You are now authorized in {1}'));
  8066. var button = mxUtils.button(btnLbl, fn);
  8067. button.insertBefore(img, button.firstChild);
  8068. button.style.marginTop = '6px';
  8069. button.className = 'geBigButton';
  8070. div.appendChild(hd);
  8071. div.appendChild(p);
  8072. div.appendChild(button);
  8073. this.container = div;
  8074. };
  8075. /**
  8076. *
  8077. */
  8078. var CommentsWindow = function(editorUi, x, y, w, h)
  8079. {
  8080. var file = editorUi.getCurrentFile();
  8081. var readOnly = !file.desc.canComment;
  8082. var canReplyToReplies = !readOnly;
  8083. var file = editorUi.getCurrentFile();
  8084. var div = document.createElement('div');
  8085. div.className = 'geCommentsWin';
  8086. div.style.background = (Dialog.backdropColor == 'white') ? 'whiteSmoke' : Dialog.backdropColor;
  8087. var tbarHeight = (!EditorUi.compactUi) ? '30px' : '26px';
  8088. var listDiv = document.createElement('div');
  8089. listDiv.className = 'geCommentsList';
  8090. listDiv.style.backgroundColor = (Dialog.backdropColor == 'white') ? 'whiteSmoke' : Dialog.backdropColor;
  8091. listDiv.style.bottom = (parseInt(tbarHeight) + 7) + 'px';
  8092. div.appendChild(listDiv);
  8093. var noComments = document.createElement('span');
  8094. noComments.style.cssText = 'display:none;padding-top:10px;text-align:center;';
  8095. mxUtils.write(noComments, mxResources.get('noCommentsFound'));
  8096. var selectionComment = null;
  8097. var ldiv = document.createElement('div');
  8098. ldiv.className = 'geToolbarContainer geCommentsToolbar';
  8099. ldiv.style.height = tbarHeight;
  8100. ldiv.style.padding = (!EditorUi.compactUi) ? '1px' : '4px 0px 3px 0px';
  8101. ldiv.style.backgroundColor = (Dialog.backdropColor == 'white') ? 'whiteSmoke' : Dialog.backdropColor;
  8102. if (mxClient.IS_QUIRKS)
  8103. {
  8104. ldiv.style.filter = 'none';
  8105. }
  8106. var link = document.createElement('a');
  8107. link.className = 'geButton';
  8108. if (mxClient.IS_QUIRKS)
  8109. {
  8110. link.style.filter = 'none';
  8111. }
  8112. function editComment(comment, cdiv, saveCallback, deleteOnCancel)
  8113. {
  8114. var commentTxt = cdiv.querySelector('.geCommentTxt');
  8115. var actionsDiv = cdiv.querySelector('.geCommentActionsList');
  8116. var textArea = document.createElement('textarea');
  8117. textArea.className = 'geCommentEditTxtArea';
  8118. textArea.style.minHeight = commentTxt.offsetHeight + 'px';
  8119. textArea.value = commentTxt.innerHTML;
  8120. cdiv.insertBefore(textArea, commentTxt);
  8121. var btnDiv = document.createElement('div');
  8122. btnDiv.className = 'geCommentEditBtns';
  8123. function reset()
  8124. {
  8125. cdiv.removeChild(textArea);
  8126. cdiv.removeChild(btnDiv);
  8127. actionsDiv.style.display = 'block';
  8128. commentTxt.style.display = 'block';
  8129. };
  8130. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  8131. {
  8132. if (deleteOnCancel)
  8133. {
  8134. cdiv.parentNode.removeChild(cdiv);
  8135. }
  8136. else
  8137. {
  8138. reset();
  8139. }
  8140. });
  8141. cancelBtn.className = 'geCommentEditBtn';
  8142. btnDiv.appendChild(cancelBtn);
  8143. var saveBtn = mxUtils.button(mxResources.get('save'), function()
  8144. {
  8145. commentTxt.innerHTML = '';
  8146. comment.content = textArea.value;
  8147. mxUtils.write(commentTxt, comment.content);
  8148. reset();
  8149. saveCallback(comment);
  8150. });
  8151. // Updates modified state and handles placeholder text
  8152. mxEvent.addListener(textArea, 'keydown', mxUtils.bind(this, function(evt)
  8153. {
  8154. if (!mxEvent.isConsumed(evt))
  8155. {
  8156. if ((mxEvent.isControlDown(evt) || (mxClient.IS_MAC &&
  8157. mxEvent.isMetaDown(evt))) && evt.keyCode == 13 /* Ctrl+Enter */)
  8158. {
  8159. saveBtn.click();
  8160. mxEvent.consume(evt);
  8161. }
  8162. else if (evt.keyCode == 27 /* Escape */)
  8163. {
  8164. cancelBtn.click();
  8165. mxEvent.consume(evt);
  8166. }
  8167. }
  8168. }));
  8169. // Focused to include in viewport before focusin textbox
  8170. saveBtn.focus();
  8171. saveBtn.className = 'geCommentEditBtn gePrimaryBtn';
  8172. btnDiv.appendChild(saveBtn);
  8173. cdiv.insertBefore(btnDiv, commentTxt);
  8174. actionsDiv.style.display = 'none';
  8175. commentTxt.style.display = 'none';
  8176. textArea.focus();
  8177. };
  8178. function writeCommentDate(comment, dateDiv)
  8179. {
  8180. dateDiv.innerHTML = '';
  8181. var str = editorUi.timeSince(new Date(comment.modifiedDate));
  8182. if (str == null)
  8183. {
  8184. str = mxResources.get('lessThanAMinute');
  8185. }
  8186. mxUtils.write(dateDiv, mxResources.get('timeAgo', [str], '{1} ago'));
  8187. };
  8188. function showBusy(commentDiv)
  8189. {
  8190. var busyImg = document.createElement('img');
  8191. busyImg.className = 'geCommentBusyImg';
  8192. busyImg.src= '/images/spin.gif';
  8193. commentDiv.appendChild(busyImg);
  8194. commentDiv.busyImg = busyImg;
  8195. };
  8196. function showError(commentDiv)
  8197. {
  8198. commentDiv.style.border = '1px solid red';
  8199. commentDiv.removeChild(commentDiv.busyImg);
  8200. };
  8201. function showDone(commentDiv)
  8202. {
  8203. commentDiv.style.border = '';
  8204. commentDiv.removeChild(commentDiv.busyImg);
  8205. };
  8206. function addComment(comment, parentArr, parent, level, showResolved)
  8207. {
  8208. //Skip resolved comments if showResolved is not set
  8209. if (!showResolved && comment.isResolved)
  8210. {
  8211. return;
  8212. }
  8213. noComments.style.display = 'none';
  8214. var cdiv = document.createElement('div');
  8215. cdiv.className = 'geCommentContainer';
  8216. cdiv.setAttribute('data-commentId', comment.id);
  8217. cdiv.style.marginLeft = (level * 20 + 5) + 'px';
  8218. if (comment.isResolved && uiTheme != 'dark')
  8219. {
  8220. cdiv.style.backgroundColor = 'ghostWhite';
  8221. }
  8222. var headerDiv = document.createElement('div');
  8223. headerDiv.className = 'geCommentHeader';
  8224. var userImg = document.createElement('img');
  8225. userImg.className = 'geCommentUserImg';
  8226. userImg.src = comment.user.pictureUrl || Editor.userImage;
  8227. headerDiv.appendChild(userImg);
  8228. var headerTxt = document.createElement('div');
  8229. headerTxt.className = 'geCommentHeaderTxt';
  8230. headerDiv.appendChild(headerTxt);
  8231. var usernameDiv = document.createElement('div');
  8232. usernameDiv.className = 'geCommentUsername';
  8233. mxUtils.write(usernameDiv, comment.user.displayName || '');
  8234. headerTxt.appendChild(usernameDiv);
  8235. var dateDiv = document.createElement('div');
  8236. dateDiv.className = 'geCommentDate';
  8237. dateDiv.setAttribute('data-commentId', comment.id);
  8238. writeCommentDate(comment, dateDiv);
  8239. headerTxt.appendChild(dateDiv);
  8240. cdiv.appendChild(headerDiv);
  8241. var commentTxtDiv = document.createElement('div');
  8242. commentTxtDiv.className = 'geCommentTxt';
  8243. mxUtils.write(commentTxtDiv, comment.content || '');
  8244. cdiv.appendChild(commentTxtDiv);
  8245. var actionsDiv = document.createElement('div');
  8246. actionsDiv.className = 'geCommentActions';
  8247. var actionsList = document.createElement('ul');
  8248. actionsList.className = 'geCommentActionsList';
  8249. actionsDiv.appendChild(actionsList);
  8250. function addAction(name, evtHandler, hide)
  8251. {
  8252. var action = document.createElement('li');
  8253. action.className = 'geCommentAction';
  8254. var actionLnk = document.createElement('a');
  8255. actionLnk.className = 'geCommentActionLnk';
  8256. mxUtils.write(actionLnk, name);
  8257. action.appendChild(actionLnk);
  8258. mxEvent.addListener(actionLnk, 'click', function(evt)
  8259. {
  8260. evtHandler(evt, comment);
  8261. evt.preventDefault();
  8262. mxEvent.consume(evt);
  8263. });
  8264. actionsList.appendChild(action);
  8265. if (hide) action.style.display = 'none';
  8266. };
  8267. function collectReplies()
  8268. {
  8269. var replies = [];
  8270. var pdiv = cdiv;
  8271. function collectReplies(comment)
  8272. {
  8273. replies.push(pdiv);
  8274. if (comment.replies != null)
  8275. {
  8276. for (var i = 0; i < comment.replies.length; i++)
  8277. {
  8278. pdiv = pdiv.nextSibling;
  8279. collectReplies(comment.replies[i]);
  8280. }
  8281. }
  8282. }
  8283. collectReplies(comment);
  8284. return {pdiv: pdiv, replies: replies};
  8285. };
  8286. function addReply(initContent, editIt, saveCallback, doResolve, doReopen)
  8287. {
  8288. var pdiv = collectReplies().pdiv;
  8289. var newReply = file.newComment(initContent, editorUi.getCurrentUser());
  8290. newReply.pCommentId = comment.id;
  8291. if (comment.replies == null) comment.replies = [];
  8292. var replyComment = addComment(newReply, comment.replies, pdiv, level + 1);
  8293. function doAddReply()
  8294. {
  8295. showBusy(replyComment);
  8296. comment.addReply(newReply, function(id)
  8297. {
  8298. newReply.id = id;
  8299. comment.replies.push(newReply);
  8300. showDone(replyComment);
  8301. if (saveCallback) saveCallback();
  8302. }, function(err)
  8303. {
  8304. doEdit();
  8305. showError(replyComment);
  8306. editorUi.handleError(err, null, null, null,
  8307. mxUtils.htmlEntities(mxResources.get('objectNotFound')));
  8308. }, doResolve, doReopen);
  8309. };
  8310. function doEdit()
  8311. {
  8312. editComment(newReply, replyComment, function(newReply)
  8313. {
  8314. doAddReply();
  8315. }, true);
  8316. };
  8317. if (editIt)
  8318. {
  8319. doEdit();
  8320. }
  8321. else
  8322. {
  8323. doAddReply();
  8324. }
  8325. };
  8326. if (!readOnly && (level == 0 || canReplyToReplies))
  8327. {
  8328. addAction(mxResources.get('reply'), function()
  8329. {
  8330. addReply('', true);
  8331. }, comment.isResolved);
  8332. }
  8333. var user = editorUi.getCurrentUser();
  8334. if (user != null && user.id == comment.user.id && !readOnly)
  8335. {
  8336. addAction(mxResources.get('edit'), function()
  8337. {
  8338. function doEditComment()
  8339. {
  8340. editComment(comment, cdiv, function()
  8341. {
  8342. showBusy(cdiv);
  8343. comment.editComment(comment.content, function()
  8344. {
  8345. showDone(cdiv);
  8346. }, function(err)
  8347. {
  8348. showError(cdiv);
  8349. doEditComment();
  8350. editorUi.handleError(err, null, null, null,
  8351. mxUtils.htmlEntities(mxResources.get('objectNotFound')));
  8352. });
  8353. });
  8354. };
  8355. doEditComment();
  8356. }, comment.isResolved);
  8357. addAction(mxResources.get('delete'), function()
  8358. {
  8359. editorUi.confirm(mxResources.get('areYouSure'), function()
  8360. {
  8361. showBusy(cdiv);
  8362. comment.deleteComment(function()
  8363. {
  8364. var replies = collectReplies(comment).replies;
  8365. for (var i = 0; i < replies.length; i++)
  8366. {
  8367. listDiv.removeChild(replies[i]);
  8368. }
  8369. for (var i = 0; i < parentArr.length; i++)
  8370. {
  8371. if (parentArr[i] == comment)
  8372. {
  8373. parentArr.splice(i, 1);
  8374. break;
  8375. }
  8376. }
  8377. noComments.style.display = (listDiv.getElementsByTagName('div').length == 0) ? 'block' : 'none';
  8378. }, function(err)
  8379. {
  8380. showError(cdiv);
  8381. editorUi.handleError(err, null, null, null,
  8382. mxUtils.htmlEntities(mxResources.get('objectNotFound')));
  8383. });
  8384. });
  8385. }, comment.isResolved);
  8386. }
  8387. if (!readOnly && level == 0) //Resolve is a top-level action only
  8388. {
  8389. function toggleResolve(evt)
  8390. {
  8391. function doToggle()
  8392. {
  8393. var resolveActionLnk = evt.target;
  8394. resolveActionLnk.innerHTML = '';
  8395. comment.isResolved = !comment.isResolved;
  8396. mxUtils.write(resolveActionLnk, comment.isResolved? mxResources.get('reopen') : mxResources.get('resolve'));
  8397. var actionsDisplay = comment.isResolved? 'none' : '';
  8398. var replies = collectReplies(comment).replies;
  8399. var color = (uiTheme == 'dark') ? 'transparent' : (comment.isResolved? 'ghostWhite' : 'white');
  8400. for (var i = 0; i < replies.length; i++)
  8401. {
  8402. replies[i].style.backgroundColor = color;
  8403. var forOpenActions = replies[i].querySelectorAll('.geCommentAction');
  8404. for (var j = 0; j < forOpenActions.length; j ++)
  8405. {
  8406. if (forOpenActions[j] == resolveActionLnk.parentNode) continue;
  8407. forOpenActions[j].style.display = actionsDisplay;
  8408. }
  8409. if (!resolvedChecked)
  8410. {
  8411. replies[i].style.display = 'none';
  8412. }
  8413. }
  8414. var divs = listDiv.getElementsByTagName('div');
  8415. var visibleCount = 0;
  8416. for (var i = 0; i < divs.length; i++)
  8417. {
  8418. if (divs[i].style.display != 'none' && divs[i].parentNode == listDiv)
  8419. {
  8420. visibleCount++;
  8421. }
  8422. }
  8423. noComments.style.display = (visibleCount == 0) ? 'block' : 'none';
  8424. };
  8425. if (comment.isResolved)
  8426. {
  8427. addReply(mxResources.get('reOpened') + ': ', true, doToggle, false, true);
  8428. }
  8429. else
  8430. {
  8431. addReply(mxResources.get('markedAsResolved'), false, doToggle, true);
  8432. }
  8433. };
  8434. addAction(comment.isResolved? mxResources.get('reopen') : mxResources.get('resolve'), toggleResolve);
  8435. }
  8436. cdiv.appendChild(actionsDiv);
  8437. if (parent != null)
  8438. {
  8439. listDiv.insertBefore(cdiv, parent.nextSibling);
  8440. }
  8441. else
  8442. {
  8443. listDiv.appendChild(cdiv);
  8444. }
  8445. for (var i = 0; comment.replies != null && i < comment.replies.length; i++)
  8446. {
  8447. var reply = comment.replies[i];
  8448. reply.isResolved = comment.isResolved; //copy isResolved to child comments (replies)
  8449. addComment(reply, comment.replies, null, level + 1, showResolved);
  8450. }
  8451. return cdiv;
  8452. };
  8453. if (!readOnly)
  8454. {
  8455. var addLink = link.cloneNode();
  8456. addLink.innerHTML = '<div class="geSprite geSprite-plus" style="display:inline-block;"></div>';
  8457. addLink.setAttribute('title', mxResources.get('create') + '...');
  8458. mxEvent.addListener(addLink, 'click', function(evt)
  8459. {
  8460. var newComment = file.newComment('', editorUi.getCurrentUser());
  8461. var newCommentDiv = addComment(newComment, comments, null, 0);
  8462. function doAddComment()
  8463. {
  8464. editComment(newComment, newCommentDiv, function(newComment)
  8465. {
  8466. showBusy(newCommentDiv);
  8467. file.addComment(newComment, function(id)
  8468. {
  8469. newComment.id = id;
  8470. comments.push(newComment);
  8471. showDone(newCommentDiv);
  8472. }, function(err)
  8473. {
  8474. showError(newCommentDiv);
  8475. doAddComment();
  8476. editorUi.handleError(err, null, null, null,
  8477. mxUtils.htmlEntities(mxResources.get('objectNotFound')));
  8478. });
  8479. }, true);
  8480. }
  8481. doAddComment();
  8482. evt.preventDefault();
  8483. mxEvent.consume(evt);
  8484. });
  8485. ldiv.appendChild(addLink);
  8486. }
  8487. var resolvedLink = link.cloneNode();
  8488. resolvedLink.innerHTML = '<img src="/images/check.png" style="width: 16px; padding: 2px;">';
  8489. resolvedLink.setAttribute('title', mxResources.get('showResolved'));
  8490. var resolvedChecked = false;
  8491. if (uiTheme == 'dark')
  8492. {
  8493. resolvedLink.style.filter = 'invert(100%)';
  8494. }
  8495. mxEvent.addListener(resolvedLink, 'click', function(evt)
  8496. {
  8497. resolvedChecked = !resolvedChecked;
  8498. this.className = resolvedChecked? 'geButton geCheckedBtn' : 'geButton';
  8499. refresh();
  8500. evt.preventDefault();
  8501. mxEvent.consume(evt);
  8502. });
  8503. ldiv.appendChild(resolvedLink);
  8504. var refreshLink = link.cloneNode();
  8505. refreshLink.innerHTML = '<img src="/images/update16.png" style="width: 16px; padding: 2px;">';
  8506. refreshLink.setAttribute('title', mxResources.get('refresh'));
  8507. if (uiTheme == 'dark')
  8508. {
  8509. refreshLink.style.filter = 'invert(100%)';
  8510. }
  8511. mxEvent.addListener(refreshLink, 'click', function(evt)
  8512. {
  8513. refresh();
  8514. evt.preventDefault();
  8515. mxEvent.consume(evt);
  8516. });
  8517. ldiv.appendChild(refreshLink);
  8518. div.appendChild(ldiv);
  8519. var comments = [];
  8520. var refresh = mxUtils.bind(this, function()
  8521. {
  8522. listDiv.innerHTML = '<div style="padding-top:10px;text-align:center;"><img src="/images/spin.gif" valign="middle"> ' +
  8523. mxUtils.htmlEntities(mxResources.get('loading')) + '...</div>';
  8524. file = editorUi.getCurrentFile();
  8525. canReplyToReplies = file.canReplyToReplies();
  8526. if (file != null)
  8527. {
  8528. file.getComments(function(list)
  8529. {
  8530. function sortReplies(replies)
  8531. {
  8532. if (replies != null)
  8533. {
  8534. //Sort replies old to new
  8535. replies.sort(function(r1, r2)
  8536. {
  8537. return new Date(r1.modifiedDate) - new Date(r2.modifiedDate);
  8538. });
  8539. for (var i = 0; i < replies.length; i++)
  8540. {
  8541. sortReplies(replies[i].replies);
  8542. }
  8543. }
  8544. };
  8545. //Sort comments old to new
  8546. list.sort(function(c1, c2)
  8547. {
  8548. return new Date(c1.modifiedDate) - new Date(c2.modifiedDate);
  8549. });
  8550. listDiv.innerHTML = '';
  8551. listDiv.appendChild(noComments);
  8552. noComments.style.display = 'block';
  8553. comments = list;
  8554. for (var i = 0; i < comments.length; i++)
  8555. {
  8556. sortReplies(comments[i].replies);
  8557. addComment(comments[i], comments, null, 0, resolvedChecked);
  8558. }
  8559. }, function()
  8560. {
  8561. listDiv.innerHTML = mxUtils.htmlEntities(mxResources.get('error'));
  8562. });
  8563. }
  8564. else
  8565. {
  8566. //TODO if file is null, close the dialog
  8567. listDiv.innerHTML = mxUtils.htmlEntities(mxResources.get('error'));
  8568. }
  8569. });
  8570. refresh();
  8571. this.refreshComments = refresh;
  8572. //Refresh the modified date of each comment if the window is visible
  8573. var refreshCommentsTime = mxUtils.bind(this, function()
  8574. {
  8575. if (!this.window.isVisible()) return; //only update if it is visible
  8576. var modDateDivs = listDiv.querySelectorAll('.geCommentDate');
  8577. var modDateDivsMap = {};
  8578. for (var i = 0; i < modDateDivs.length; i++)
  8579. {
  8580. var div = modDateDivs[i];
  8581. modDateDivsMap[div.getAttribute('data-commentId')] = div;
  8582. }
  8583. function processComment(comment)
  8584. {
  8585. var div = modDateDivsMap[comment.id];
  8586. if (div == null) return; //resolved comments
  8587. writeCommentDate(comment, div);
  8588. for (var i = 0; comment.replies != null && i < comment.replies.length; i++)
  8589. {
  8590. processComment(comment.replies[i]);
  8591. }
  8592. };
  8593. for (var i = 0; i < comments.length; i++)
  8594. {
  8595. processComment(comments[i]);
  8596. }
  8597. });
  8598. //Periodically refresh time every one minute
  8599. setInterval(refreshCommentsTime, 60000);
  8600. this.refreshCommentsTime = refreshCommentsTime;
  8601. this.window = new mxWindow(mxResources.get('comments'), div, x, y, w, h, true, true);
  8602. this.window.minimumSize = new mxRectangle(0, 0, 300, 200);
  8603. this.window.destroyOnClose = false;
  8604. this.window.setMaximizable(false);
  8605. this.window.setResizable(true);
  8606. this.window.setClosable(true);
  8607. this.window.setVisible(true);
  8608. this.window.setLocation = function(x, y)
  8609. {
  8610. var iw = window.innerWidth || document.body.clientWidth || document.documentElement.clientWidth;
  8611. var ih = window.innerHeight || document.body.clientHeight || document.documentElement.clientHeight;
  8612. x = Math.max(0, Math.min(x, iw - this.table.clientWidth));
  8613. y = Math.max(0, Math.min(y, ih - this.table.clientHeight - 48));
  8614. if (this.getX() != x || this.getY() != y)
  8615. {
  8616. mxWindow.prototype.setLocation.apply(this, arguments);
  8617. }
  8618. };
  8619. var resizeListener = mxUtils.bind(this, function()
  8620. {
  8621. var x = this.window.getX();
  8622. var y = this.window.getY();
  8623. this.window.setLocation(x, y);
  8624. });
  8625. mxEvent.addListener(window, 'resize', resizeListener);
  8626. this.destroy = function()
  8627. {
  8628. mxEvent.removeListener(window, 'resize', resizeListener);
  8629. this.window.destroy();
  8630. }
  8631. };