Dialogs.js 189 KB

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