Dialogs.js 240 KB

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