Dialogs.js 203 KB

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