Dialogs.js 214 KB

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