Dialogs.js 201 KB

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