Dialogs.js 209 KB

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