Dialogs.js 191 KB

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