Dialogs.js 190 KB

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