Dialogs.js 201 KB

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