Dialogs.js 197 KB

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