Dialogs.js 199 KB

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