Dialogs.js 192 KB

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