Dialogs.js 203 KB

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