Dialogs.js 217 KB

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