Dialogs.js 198 KB

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