Dialogs.js 186 KB

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