Dialogs.js 199 KB

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