Dialogs.js 209 KB

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