ui-grid.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079
  1. /*!
  2. * ui-grid - v3.1.1 - 2016-02-09
  3. * Copyright (c) 2016 ; License: MIT
  4. */
  5. (function () {
  6. 'use strict';
  7. angular.module('ui.grid.i18n', []);
  8. angular.module('ui.grid', ['ui.grid.i18n']);
  9. })();
  10. (function () {
  11. 'use strict';
  12. angular.module('ui.grid').constant('uiGridConstants', {
  13. LOG_DEBUG_MESSAGES: true,
  14. LOG_WARN_MESSAGES: true,
  15. LOG_ERROR_MESSAGES: true,
  16. CUSTOM_FILTERS: /CUSTOM_FILTERS/g,
  17. COL_FIELD: /COL_FIELD/g,
  18. MODEL_COL_FIELD: /MODEL_COL_FIELD/g,
  19. TOOLTIP: /title=\"TOOLTIP\"/g,
  20. DISPLAY_CELL_TEMPLATE: /DISPLAY_CELL_TEMPLATE/g,
  21. TEMPLATE_REGEXP: /<.+>/,
  22. FUNC_REGEXP: /(\([^)]*\))?$/,
  23. DOT_REGEXP: /\./g,
  24. APOS_REGEXP: /'/g,
  25. BRACKET_REGEXP: /^(.*)((?:\s*\[\s*\d+\s*\]\s*)|(?:\s*\[\s*"(?:[^"\\]|\\.)*"\s*\]\s*)|(?:\s*\[\s*'(?:[^'\\]|\\.)*'\s*\]\s*))(.*)$/,
  26. COL_CLASS_PREFIX: 'ui-grid-col',
  27. events: {
  28. GRID_SCROLL: 'uiGridScroll',
  29. COLUMN_MENU_SHOWN: 'uiGridColMenuShown',
  30. ITEM_DRAGGING: 'uiGridItemDragStart', // For any item being dragged
  31. COLUMN_HEADER_CLICK: 'uiGridColumnHeaderClick'
  32. },
  33. // copied from http://www.lsauer.com/2011/08/javascript-keymap-keycodes-in-json.html
  34. keymap: {
  35. TAB: 9,
  36. STRG: 17,
  37. CAPSLOCK: 20,
  38. CTRL: 17,
  39. CTRLRIGHT: 18,
  40. CTRLR: 18,
  41. SHIFT: 16,
  42. RETURN: 13,
  43. ENTER: 13,
  44. BACKSPACE: 8,
  45. BCKSP: 8,
  46. ALT: 18,
  47. ALTR: 17,
  48. ALTRIGHT: 17,
  49. SPACE: 32,
  50. WIN: 91,
  51. MAC: 91,
  52. FN: null,
  53. PG_UP: 33,
  54. PG_DOWN: 34,
  55. UP: 38,
  56. DOWN: 40,
  57. LEFT: 37,
  58. RIGHT: 39,
  59. ESC: 27,
  60. DEL: 46,
  61. F1: 112,
  62. F2: 113,
  63. F3: 114,
  64. F4: 115,
  65. F5: 116,
  66. F6: 117,
  67. F7: 118,
  68. F8: 119,
  69. F9: 120,
  70. F10: 121,
  71. F11: 122,
  72. F12: 123
  73. },
  74. ASC: 'asc',
  75. DESC: 'desc',
  76. filter: {
  77. STARTS_WITH: 2,
  78. ENDS_WITH: 4,
  79. EXACT: 8,
  80. CONTAINS: 16,
  81. GREATER_THAN: 32,
  82. GREATER_THAN_OR_EQUAL: 64,
  83. LESS_THAN: 128,
  84. LESS_THAN_OR_EQUAL: 256,
  85. NOT_EQUAL: 512,
  86. SELECT: 'select',
  87. INPUT: 'input'
  88. },
  89. aggregationTypes: {
  90. sum: 2,
  91. count: 4,
  92. avg: 8,
  93. min: 16,
  94. max: 32
  95. },
  96. // TODO(c0bra): Create full list of these somehow. NOTE: do any allow a space before or after them?
  97. CURRENCY_SYMBOLS: ['ƒ', '$', '£', '$', '¤', '¥', '៛', '₩', '₱', '฿', '₫'],
  98. scrollDirection: {
  99. UP: 'up',
  100. DOWN: 'down',
  101. LEFT: 'left',
  102. RIGHT: 'right',
  103. NONE: 'none'
  104. },
  105. dataChange: {
  106. ALL: 'all',
  107. EDIT: 'edit',
  108. ROW: 'row',
  109. COLUMN: 'column',
  110. OPTIONS: 'options'
  111. },
  112. scrollbars: {
  113. NEVER: 0,
  114. ALWAYS: 1
  115. //WHEN_NEEDED: 2
  116. }
  117. });
  118. })();
  119. angular.module('ui.grid').directive('uiGridCell', ['$compile', '$parse', 'gridUtil', 'uiGridConstants', function ($compile, $parse, gridUtil, uiGridConstants) {
  120. var uiGridCell = {
  121. priority: 0,
  122. scope: false,
  123. require: '?^uiGrid',
  124. compile: function() {
  125. return {
  126. pre: function($scope, $elm, $attrs, uiGridCtrl) {
  127. function compileTemplate() {
  128. var compiledElementFn = $scope.col.compiledElementFn;
  129. compiledElementFn($scope, function(clonedElement, scope) {
  130. $elm.append(clonedElement);
  131. });
  132. }
  133. // If the grid controller is present, use it to get the compiled cell template function
  134. if (uiGridCtrl && $scope.col.compiledElementFn) {
  135. compileTemplate();
  136. }
  137. // No controller, compile the element manually (for unit tests)
  138. else {
  139. if ( uiGridCtrl && !$scope.col.compiledElementFn ){
  140. // gridUtil.logError('Render has been called before precompile. Please log a ui-grid issue');
  141. $scope.col.getCompiledElementFn()
  142. .then(function (compiledElementFn) {
  143. compiledElementFn($scope, function(clonedElement, scope) {
  144. $elm.append(clonedElement);
  145. });
  146. });
  147. }
  148. else {
  149. var html = $scope.col.cellTemplate
  150. .replace(uiGridConstants.MODEL_COL_FIELD, 'row.entity.' + gridUtil.preEval($scope.col.field))
  151. .replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)');
  152. var cellElement = $compile(html)($scope);
  153. $elm.append(cellElement);
  154. }
  155. }
  156. },
  157. post: function($scope, $elm, $attrs, uiGridCtrl) {
  158. var initColClass = $scope.col.getColClass(false);
  159. $elm.addClass(initColClass);
  160. var classAdded;
  161. var updateClass = function( grid ){
  162. var contents = $elm;
  163. if ( classAdded ){
  164. contents.removeClass( classAdded );
  165. classAdded = null;
  166. }
  167. if (angular.isFunction($scope.col.cellClass)) {
  168. classAdded = $scope.col.cellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex);
  169. }
  170. else {
  171. classAdded = $scope.col.cellClass;
  172. }
  173. contents.addClass(classAdded);
  174. };
  175. if ($scope.col.cellClass) {
  176. updateClass();
  177. }
  178. // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs
  179. var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateClass, [uiGridConstants.dataChange.COLUMN, uiGridConstants.dataChange.EDIT]);
  180. // watch the col and row to see if they change - which would indicate that we've scrolled or sorted or otherwise
  181. // changed the row/col that this cell relates to, and we need to re-evaluate cell classes and maybe other things
  182. var cellChangeFunction = function( n, o ){
  183. if ( n !== o ) {
  184. if ( classAdded || $scope.col.cellClass ){
  185. updateClass();
  186. }
  187. // See if the column's internal class has changed
  188. var newColClass = $scope.col.getColClass(false);
  189. if (newColClass !== initColClass) {
  190. $elm.removeClass(initColClass);
  191. $elm.addClass(newColClass);
  192. initColClass = newColClass;
  193. }
  194. }
  195. };
  196. // TODO(c0bra): Turn this into a deep array watch
  197. /* shouldn't be needed any more given track by col.name
  198. var colWatchDereg = $scope.$watch( 'col', cellChangeFunction );
  199. */
  200. var rowWatchDereg = $scope.$watch( 'row', cellChangeFunction );
  201. var deregisterFunction = function() {
  202. dataChangeDereg();
  203. // colWatchDereg();
  204. rowWatchDereg();
  205. };
  206. $scope.$on( '$destroy', deregisterFunction );
  207. $elm.on( '$destroy', deregisterFunction );
  208. }
  209. };
  210. }
  211. };
  212. return uiGridCell;
  213. }]);
  214. (function(){
  215. angular.module('ui.grid')
  216. .service('uiGridColumnMenuService', [ 'i18nService', 'uiGridConstants', 'gridUtil',
  217. function ( i18nService, uiGridConstants, gridUtil ) {
  218. /**
  219. * @ngdoc service
  220. * @name ui.grid.service:uiGridColumnMenuService
  221. *
  222. * @description Services for working with column menus, factored out
  223. * to make the code easier to understand
  224. */
  225. var service = {
  226. /**
  227. * @ngdoc method
  228. * @methodOf ui.grid.service:uiGridColumnMenuService
  229. * @name initialize
  230. * @description Sets defaults, puts a reference to the $scope on
  231. * the uiGridController
  232. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  233. * @param {controller} uiGridCtrl the uiGridController for the grid
  234. * we're on
  235. *
  236. */
  237. initialize: function( $scope, uiGridCtrl ){
  238. $scope.grid = uiGridCtrl.grid;
  239. // Store a reference to this link/controller in the main uiGrid controller
  240. // to allow showMenu later
  241. uiGridCtrl.columnMenuScope = $scope;
  242. // Save whether we're shown or not so the columns can check
  243. $scope.menuShown = false;
  244. },
  245. /**
  246. * @ngdoc method
  247. * @methodOf ui.grid.service:uiGridColumnMenuService
  248. * @name setColMenuItemWatch
  249. * @description Setup a watch on $scope.col.menuItems, and update
  250. * menuItems based on this. $scope.col needs to be set by the column
  251. * before calling the menu.
  252. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  253. * @param {controller} uiGridCtrl the uiGridController for the grid
  254. * we're on
  255. *
  256. */
  257. setColMenuItemWatch: function ( $scope ){
  258. var deregFunction = $scope.$watch('col.menuItems', function (n) {
  259. if (typeof(n) !== 'undefined' && n && angular.isArray(n)) {
  260. n.forEach(function (item) {
  261. if (typeof(item.context) === 'undefined' || !item.context) {
  262. item.context = {};
  263. }
  264. item.context.col = $scope.col;
  265. });
  266. $scope.menuItems = $scope.defaultMenuItems.concat(n);
  267. }
  268. else {
  269. $scope.menuItems = $scope.defaultMenuItems;
  270. }
  271. });
  272. $scope.$on( '$destroy', deregFunction );
  273. },
  274. /**
  275. * @ngdoc boolean
  276. * @name enableSorting
  277. * @propertyOf ui.grid.class:GridOptions.columnDef
  278. * @description (optional) True by default. When enabled, this setting adds sort
  279. * widgets to the column header, allowing sorting of the data in the individual column.
  280. */
  281. /**
  282. * @ngdoc method
  283. * @methodOf ui.grid.service:uiGridColumnMenuService
  284. * @name sortable
  285. * @description determines whether this column is sortable
  286. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  287. *
  288. */
  289. sortable: function( $scope ) {
  290. if ( $scope.grid.options.enableSorting && typeof($scope.col) !== 'undefined' && $scope.col && $scope.col.enableSorting) {
  291. return true;
  292. }
  293. else {
  294. return false;
  295. }
  296. },
  297. /**
  298. * @ngdoc method
  299. * @methodOf ui.grid.service:uiGridColumnMenuService
  300. * @name isActiveSort
  301. * @description determines whether the requested sort direction is current active, to
  302. * allow highlighting in the menu
  303. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  304. * @param {string} direction the direction that we'd have selected for us to be active
  305. *
  306. */
  307. isActiveSort: function( $scope, direction ){
  308. return (typeof($scope.col) !== 'undefined' && typeof($scope.col.sort) !== 'undefined' &&
  309. typeof($scope.col.sort.direction) !== 'undefined' && $scope.col.sort.direction === direction);
  310. },
  311. /**
  312. * @ngdoc method
  313. * @methodOf ui.grid.service:uiGridColumnMenuService
  314. * @name suppressRemoveSort
  315. * @description determines whether we should suppress the removeSort option
  316. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  317. *
  318. */
  319. suppressRemoveSort: function( $scope ) {
  320. if ($scope.col && $scope.col.suppressRemoveSort) {
  321. return true;
  322. }
  323. else {
  324. return false;
  325. }
  326. },
  327. /**
  328. * @ngdoc boolean
  329. * @name enableHiding
  330. * @propertyOf ui.grid.class:GridOptions.columnDef
  331. * @description (optional) True by default. When set to false, this setting prevents a user from hiding the column
  332. * using the column menu or the grid menu.
  333. */
  334. /**
  335. * @ngdoc method
  336. * @methodOf ui.grid.service:uiGridColumnMenuService
  337. * @name hideable
  338. * @description determines whether a column can be hidden, by checking the enableHiding columnDef option
  339. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  340. *
  341. */
  342. hideable: function( $scope ) {
  343. if (typeof($scope.col) !== 'undefined' && $scope.col && $scope.col.colDef && $scope.col.colDef.enableHiding === false ) {
  344. return false;
  345. }
  346. else {
  347. return true;
  348. }
  349. },
  350. /**
  351. * @ngdoc method
  352. * @methodOf ui.grid.service:uiGridColumnMenuService
  353. * @name getDefaultMenuItems
  354. * @description returns the default menu items for a column menu
  355. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  356. *
  357. */
  358. getDefaultMenuItems: function( $scope ){
  359. return [
  360. {
  361. title: i18nService.getSafeText('sort.ascending'),
  362. icon: 'ui-grid-icon-sort-alt-up',
  363. action: function($event) {
  364. $event.stopPropagation();
  365. $scope.sortColumn($event, uiGridConstants.ASC);
  366. },
  367. shown: function () {
  368. return service.sortable( $scope );
  369. },
  370. active: function() {
  371. return service.isActiveSort( $scope, uiGridConstants.ASC);
  372. }
  373. },
  374. {
  375. title: i18nService.getSafeText('sort.descending'),
  376. icon: 'ui-grid-icon-sort-alt-down',
  377. action: function($event) {
  378. $event.stopPropagation();
  379. $scope.sortColumn($event, uiGridConstants.DESC);
  380. },
  381. shown: function() {
  382. return service.sortable( $scope );
  383. },
  384. active: function() {
  385. return service.isActiveSort( $scope, uiGridConstants.DESC);
  386. }
  387. },
  388. {
  389. title: i18nService.getSafeText('sort.remove'),
  390. icon: 'ui-grid-icon-cancel',
  391. action: function ($event) {
  392. $event.stopPropagation();
  393. $scope.unsortColumn();
  394. },
  395. shown: function() {
  396. return service.sortable( $scope ) &&
  397. typeof($scope.col) !== 'undefined' && (typeof($scope.col.sort) !== 'undefined' &&
  398. typeof($scope.col.sort.direction) !== 'undefined') && $scope.col.sort.direction !== null &&
  399. !service.suppressRemoveSort( $scope );
  400. }
  401. },
  402. {
  403. title: i18nService.getSafeText('column.hide'),
  404. icon: 'ui-grid-icon-cancel',
  405. shown: function() {
  406. return service.hideable( $scope );
  407. },
  408. action: function ($event) {
  409. $event.stopPropagation();
  410. $scope.hideColumn();
  411. }
  412. }
  413. ];
  414. },
  415. /**
  416. * @ngdoc method
  417. * @methodOf ui.grid.service:uiGridColumnMenuService
  418. * @name getColumnElementPosition
  419. * @description gets the position information needed to place the column
  420. * menu below the column header
  421. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  422. * @param {GridCol} column the column we want to position below
  423. * @param {element} $columnElement the column element we want to position below
  424. * @returns {hash} containing left, top, offset, height, width
  425. *
  426. */
  427. getColumnElementPosition: function( $scope, column, $columnElement ){
  428. var positionData = {};
  429. positionData.left = $columnElement[0].offsetLeft;
  430. positionData.top = $columnElement[0].offsetTop;
  431. positionData.parentLeft = $columnElement[0].offsetParent.offsetLeft;
  432. // Get the grid scrollLeft
  433. positionData.offset = 0;
  434. if (column.grid.options.offsetLeft) {
  435. positionData.offset = column.grid.options.offsetLeft;
  436. }
  437. positionData.height = gridUtil.elementHeight($columnElement, true);
  438. positionData.width = gridUtil.elementWidth($columnElement, true);
  439. return positionData;
  440. },
  441. /**
  442. * @ngdoc method
  443. * @methodOf ui.grid.service:uiGridColumnMenuService
  444. * @name repositionMenu
  445. * @description Reposition the menu below the new column. If the menu has no child nodes
  446. * (i.e. it's not currently visible) then we guess it's width at 100, we'll be called again
  447. * later to fix it
  448. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  449. * @param {GridCol} column the column we want to position below
  450. * @param {hash} positionData a hash containing left, top, offset, height, width
  451. * @param {element} $elm the column menu element that we want to reposition
  452. * @param {element} $columnElement the column element that we want to reposition underneath
  453. *
  454. */
  455. repositionMenu: function( $scope, column, positionData, $elm, $columnElement ) {
  456. var menu = $elm[0].querySelectorAll('.ui-grid-menu');
  457. // It's possible that the render container of the column we're attaching to is
  458. // offset from the grid (i.e. pinned containers), we need to get the difference in the offsetLeft
  459. // between the render container and the grid
  460. var renderContainerElm = gridUtil.closestElm($columnElement, '.ui-grid-render-container');
  461. var renderContainerOffset = renderContainerElm.getBoundingClientRect().left - $scope.grid.element[0].getBoundingClientRect().left;
  462. var containerScrollLeft = renderContainerElm.querySelectorAll('.ui-grid-viewport')[0].scrollLeft;
  463. // default value the last width for _this_ column, otherwise last width for _any_ column, otherwise default to 170
  464. var myWidth = column.lastMenuWidth ? column.lastMenuWidth : ( $scope.lastMenuWidth ? $scope.lastMenuWidth : 170);
  465. var paddingRight = column.lastMenuPaddingRight ? column.lastMenuPaddingRight : ( $scope.lastMenuPaddingRight ? $scope.lastMenuPaddingRight : 10);
  466. if ( menu.length !== 0 ){
  467. var mid = menu[0].querySelectorAll('.ui-grid-menu-mid');
  468. if ( mid.length !== 0 && !angular.element(mid).hasClass('ng-hide') ) {
  469. myWidth = gridUtil.elementWidth(menu, true);
  470. $scope.lastMenuWidth = myWidth;
  471. column.lastMenuWidth = myWidth;
  472. // TODO(c0bra): use padding-left/padding-right based on document direction (ltr/rtl), place menu on proper side
  473. // Get the column menu right padding
  474. paddingRight = parseInt(gridUtil.getStyles(angular.element(menu)[0])['paddingRight'], 10);
  475. $scope.lastMenuPaddingRight = paddingRight;
  476. column.lastMenuPaddingRight = paddingRight;
  477. }
  478. }
  479. var left = positionData.left + renderContainerOffset - containerScrollLeft + positionData.parentLeft + positionData.width - myWidth + paddingRight;
  480. if (left < positionData.offset){
  481. left = positionData.offset;
  482. }
  483. $elm.css('left', left + 'px');
  484. $elm.css('top', (positionData.top + positionData.height) + 'px');
  485. }
  486. };
  487. return service;
  488. }])
  489. .directive('uiGridColumnMenu', ['$timeout', 'gridUtil', 'uiGridConstants', 'uiGridColumnMenuService', '$document',
  490. function ($timeout, gridUtil, uiGridConstants, uiGridColumnMenuService, $document) {
  491. /**
  492. * @ngdoc directive
  493. * @name ui.grid.directive:uiGridColumnMenu
  494. * @description Provides the column menu framework, leverages uiGridMenu underneath
  495. *
  496. */
  497. var uiGridColumnMenu = {
  498. priority: 0,
  499. scope: true,
  500. require: '^uiGrid',
  501. templateUrl: 'ui-grid/uiGridColumnMenu',
  502. replace: true,
  503. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  504. uiGridColumnMenuService.initialize( $scope, uiGridCtrl );
  505. $scope.defaultMenuItems = uiGridColumnMenuService.getDefaultMenuItems( $scope );
  506. // Set the menu items for use with the column menu. The user can later add additional items via the watch
  507. $scope.menuItems = $scope.defaultMenuItems;
  508. uiGridColumnMenuService.setColMenuItemWatch( $scope );
  509. /**
  510. * @ngdoc method
  511. * @methodOf ui.grid.directive:uiGridColumnMenu
  512. * @name showMenu
  513. * @description Shows the column menu. If the menu is already displayed it
  514. * calls the menu to ask it to hide (it will animate), then it repositions the menu
  515. * to the right place whilst hidden (it will make an assumption on menu width),
  516. * then it asks the menu to show (it will animate), then it repositions the menu again
  517. * once we can calculate it's size.
  518. * @param {GridCol} column the column we want to position below
  519. * @param {element} $columnElement the column element we want to position below
  520. */
  521. $scope.showMenu = function(column, $columnElement, event) {
  522. // Swap to this column
  523. $scope.col = column;
  524. // Get the position information for the column element
  525. var colElementPosition = uiGridColumnMenuService.getColumnElementPosition( $scope, column, $columnElement );
  526. if ($scope.menuShown) {
  527. // we want to hide, then reposition, then show, but we want to wait for animations
  528. // we set a variable, and then rely on the menu-hidden event to call the reposition and show
  529. $scope.colElement = $columnElement;
  530. $scope.colElementPosition = colElementPosition;
  531. $scope.hideThenShow = true;
  532. $scope.$broadcast('hide-menu', { originalEvent: event });
  533. } else {
  534. $scope.menuShown = true;
  535. uiGridColumnMenuService.repositionMenu( $scope, column, colElementPosition, $elm, $columnElement );
  536. $scope.colElement = $columnElement;
  537. $scope.colElementPosition = colElementPosition;
  538. $scope.$broadcast('show-menu', { originalEvent: event });
  539. }
  540. };
  541. /**
  542. * @ngdoc method
  543. * @methodOf ui.grid.directive:uiGridColumnMenu
  544. * @name hideMenu
  545. * @description Hides the column menu.
  546. * @param {boolean} broadcastTrigger true if we were triggered by a broadcast
  547. * from the menu itself - in which case don't broadcast again as we'll get
  548. * an infinite loop
  549. */
  550. $scope.hideMenu = function( broadcastTrigger ) {
  551. $scope.menuShown = false;
  552. if ( !broadcastTrigger ){
  553. $scope.$broadcast('hide-menu');
  554. }
  555. };
  556. $scope.$on('menu-hidden', function() {
  557. if ( $scope.hideThenShow ){
  558. delete $scope.hideThenShow;
  559. uiGridColumnMenuService.repositionMenu( $scope, $scope.col, $scope.colElementPosition, $elm, $scope.colElement );
  560. $scope.$broadcast('show-menu');
  561. $scope.menuShown = true;
  562. } else {
  563. $scope.hideMenu( true );
  564. if ($scope.col) {
  565. //Focus on the menu button
  566. gridUtil.focus.bySelector($document, '.ui-grid-header-cell.' + $scope.col.getColClass()+ ' .ui-grid-column-menu-button', $scope.col.grid, false);
  567. }
  568. }
  569. });
  570. $scope.$on('menu-shown', function() {
  571. $timeout( function() {
  572. uiGridColumnMenuService.repositionMenu( $scope, $scope.col, $scope.colElementPosition, $elm, $scope.colElement );
  573. //Focus on the first item
  574. gridUtil.focus.bySelector($document, '.ui-grid-menu-items .ui-grid-menu-item', true);
  575. delete $scope.colElementPosition;
  576. delete $scope.columnElement;
  577. }, 200);
  578. });
  579. /* Column methods */
  580. $scope.sortColumn = function (event, dir) {
  581. event.stopPropagation();
  582. $scope.grid.sortColumn($scope.col, dir, true)
  583. .then(function () {
  584. $scope.grid.refresh();
  585. $scope.hideMenu();
  586. });
  587. };
  588. $scope.unsortColumn = function () {
  589. $scope.col.unsort();
  590. $scope.grid.refresh();
  591. $scope.hideMenu();
  592. };
  593. //Since we are hiding this column the default hide action will fail so we need to focus somewhere else.
  594. var setFocusOnHideColumn = function(){
  595. $timeout(function(){
  596. // Get the UID of the first
  597. var focusToGridMenu = function(){
  598. return gridUtil.focus.byId('grid-menu', $scope.grid);
  599. };
  600. var thisIndex;
  601. $scope.grid.columns.some(function(element, index){
  602. if (angular.equals(element, $scope.col)) {
  603. thisIndex = index;
  604. return true;
  605. }
  606. });
  607. var previousVisibleCol;
  608. // Try and find the next lower or nearest column to focus on
  609. $scope.grid.columns.some(function(element, index){
  610. if (!element.visible){
  611. return false;
  612. } // This columns index is below the current column index
  613. else if ( index < thisIndex){
  614. previousVisibleCol = element;
  615. } // This elements index is above this column index and we haven't found one that is lower
  616. else if ( index > thisIndex && !previousVisibleCol) {
  617. // This is the next best thing
  618. previousVisibleCol = element;
  619. // We've found one so use it.
  620. return true;
  621. } // We've reached an element with an index above this column and the previousVisibleCol variable has been set
  622. else if (index > thisIndex && previousVisibleCol) {
  623. // We are done.
  624. return true;
  625. }
  626. });
  627. // If found then focus on it
  628. if (previousVisibleCol){
  629. var colClass = previousVisibleCol.getColClass();
  630. gridUtil.focus.bySelector($document, '.ui-grid-header-cell.' + colClass+ ' .ui-grid-header-cell-primary-focus', true).then(angular.noop, function(reason){
  631. if (reason !== 'canceled'){ // If this is canceled then don't perform the action
  632. //The fallback action is to focus on the grid menu
  633. return focusToGridMenu();
  634. }
  635. });
  636. } else {
  637. // Fallback action to focus on the grid menu
  638. focusToGridMenu();
  639. }
  640. });
  641. };
  642. $scope.hideColumn = function () {
  643. $scope.col.colDef.visible = false;
  644. $scope.col.visible = false;
  645. $scope.grid.queueGridRefresh();
  646. $scope.hideMenu();
  647. $scope.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
  648. $scope.grid.api.core.raise.columnVisibilityChanged( $scope.col );
  649. // We are hiding so the default action of focusing on the button that opened this menu will fail.
  650. setFocusOnHideColumn();
  651. };
  652. },
  653. controller: ['$scope', function ($scope) {
  654. var self = this;
  655. $scope.$watch('menuItems', function (n) {
  656. self.menuItems = n;
  657. });
  658. }]
  659. };
  660. return uiGridColumnMenu;
  661. }]);
  662. })();
  663. (function(){
  664. 'use strict';
  665. angular.module('ui.grid').directive('uiGridFilter', ['$compile', '$templateCache', 'i18nService', 'gridUtil', function ($compile, $templateCache, i18nService, gridUtil) {
  666. return {
  667. compile: function() {
  668. return {
  669. pre: function ($scope, $elm, $attrs, controllers) {
  670. $scope.col.updateFilters = function( filterable ){
  671. $elm.children().remove();
  672. if ( filterable ){
  673. var template = $scope.col.filterHeaderTemplate;
  674. $elm.append($compile(template)($scope));
  675. }
  676. };
  677. $scope.$on( '$destroy', function() {
  678. delete $scope.col.updateFilters;
  679. });
  680. },
  681. post: function ($scope, $elm, $attrs, controllers){
  682. $scope.aria = i18nService.getSafeText('headerCell.aria');
  683. $scope.removeFilter = function(colFilter, index){
  684. colFilter.term = null;
  685. //Set the focus to the filter input after the action disables the button
  686. gridUtil.focus.bySelector($elm, '.ui-grid-filter-input-' + index);
  687. };
  688. }
  689. };
  690. }
  691. };
  692. }]);
  693. })();
  694. (function () {
  695. 'use strict';
  696. angular.module('ui.grid').directive('uiGridFooterCell', ['$timeout', 'gridUtil', 'uiGridConstants', '$compile',
  697. function ($timeout, gridUtil, uiGridConstants, $compile) {
  698. var uiGridFooterCell = {
  699. priority: 0,
  700. scope: {
  701. col: '=',
  702. row: '=',
  703. renderIndex: '='
  704. },
  705. replace: true,
  706. require: '^uiGrid',
  707. compile: function compile(tElement, tAttrs, transclude) {
  708. return {
  709. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  710. var cellFooter = $compile($scope.col.footerCellTemplate)($scope);
  711. $elm.append(cellFooter);
  712. },
  713. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  714. //$elm.addClass($scope.col.getColClass(false));
  715. $scope.grid = uiGridCtrl.grid;
  716. var initColClass = $scope.col.getColClass(false);
  717. $elm.addClass(initColClass);
  718. // apply any footerCellClass
  719. var classAdded;
  720. var updateClass = function( grid ){
  721. var contents = $elm;
  722. if ( classAdded ){
  723. contents.removeClass( classAdded );
  724. classAdded = null;
  725. }
  726. if (angular.isFunction($scope.col.footerCellClass)) {
  727. classAdded = $scope.col.footerCellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex);
  728. }
  729. else {
  730. classAdded = $scope.col.footerCellClass;
  731. }
  732. contents.addClass(classAdded);
  733. };
  734. if ($scope.col.footerCellClass) {
  735. updateClass();
  736. }
  737. $scope.col.updateAggregationValue();
  738. // Watch for column changes so we can alter the col cell class properly
  739. /* shouldn't be needed any more, given track by col.name
  740. $scope.$watch('col', function (n, o) {
  741. if (n !== o) {
  742. // See if the column's internal class has changed
  743. var newColClass = $scope.col.getColClass(false);
  744. if (newColClass !== initColClass) {
  745. $elm.removeClass(initColClass);
  746. $elm.addClass(newColClass);
  747. initColClass = newColClass;
  748. }
  749. }
  750. });
  751. */
  752. // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs
  753. var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateClass, [uiGridConstants.dataChange.COLUMN]);
  754. // listen for visible rows change and update aggregation values
  755. $scope.grid.api.core.on.rowsRendered( $scope, $scope.col.updateAggregationValue );
  756. $scope.grid.api.core.on.rowsRendered( $scope, updateClass );
  757. $scope.$on( '$destroy', dataChangeDereg );
  758. }
  759. };
  760. }
  761. };
  762. return uiGridFooterCell;
  763. }]);
  764. })();
  765. (function () {
  766. 'use strict';
  767. angular.module('ui.grid').directive('uiGridFooter', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', function ($templateCache, $compile, uiGridConstants, gridUtil, $timeout) {
  768. return {
  769. restrict: 'EA',
  770. replace: true,
  771. // priority: 1000,
  772. require: ['^uiGrid', '^uiGridRenderContainer'],
  773. scope: true,
  774. compile: function ($elm, $attrs) {
  775. return {
  776. pre: function ($scope, $elm, $attrs, controllers) {
  777. var uiGridCtrl = controllers[0];
  778. var containerCtrl = controllers[1];
  779. $scope.grid = uiGridCtrl.grid;
  780. $scope.colContainer = containerCtrl.colContainer;
  781. containerCtrl.footer = $elm;
  782. var footerTemplate = $scope.grid.options.footerTemplate;
  783. gridUtil.getTemplate(footerTemplate)
  784. .then(function (contents) {
  785. var template = angular.element(contents);
  786. var newElm = $compile(template)($scope);
  787. $elm.append(newElm);
  788. if (containerCtrl) {
  789. // Inject a reference to the footer viewport (if it exists) into the grid controller for use in the horizontal scroll handler below
  790. var footerViewport = $elm[0].getElementsByClassName('ui-grid-footer-viewport')[0];
  791. if (footerViewport) {
  792. containerCtrl.footerViewport = footerViewport;
  793. }
  794. }
  795. });
  796. },
  797. post: function ($scope, $elm, $attrs, controllers) {
  798. var uiGridCtrl = controllers[0];
  799. var containerCtrl = controllers[1];
  800. // gridUtil.logDebug('ui-grid-footer link');
  801. var grid = uiGridCtrl.grid;
  802. // Don't animate footer cells
  803. gridUtil.disableAnimations($elm);
  804. containerCtrl.footer = $elm;
  805. var footerViewport = $elm[0].getElementsByClassName('ui-grid-footer-viewport')[0];
  806. if (footerViewport) {
  807. containerCtrl.footerViewport = footerViewport;
  808. }
  809. }
  810. };
  811. }
  812. };
  813. }]);
  814. })();
  815. (function () {
  816. 'use strict';
  817. angular.module('ui.grid').directive('uiGridGridFooter', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', function ($templateCache, $compile, uiGridConstants, gridUtil, $timeout) {
  818. return {
  819. restrict: 'EA',
  820. replace: true,
  821. // priority: 1000,
  822. require: '^uiGrid',
  823. scope: true,
  824. compile: function ($elm, $attrs) {
  825. return {
  826. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  827. $scope.grid = uiGridCtrl.grid;
  828. var footerTemplate = $scope.grid.options.gridFooterTemplate;
  829. gridUtil.getTemplate(footerTemplate)
  830. .then(function (contents) {
  831. var template = angular.element(contents);
  832. var newElm = $compile(template)($scope);
  833. $elm.append(newElm);
  834. });
  835. },
  836. post: function ($scope, $elm, $attrs, controllers) {
  837. }
  838. };
  839. }
  840. };
  841. }]);
  842. })();
  843. (function(){
  844. 'use strict';
  845. angular.module('ui.grid').directive('uiGridGroupPanel', ["$compile", "uiGridConstants", "gridUtil", function($compile, uiGridConstants, gridUtil) {
  846. var defaultTemplate = 'ui-grid/ui-grid-group-panel';
  847. return {
  848. restrict: 'EA',
  849. replace: true,
  850. require: '?^uiGrid',
  851. scope: false,
  852. compile: function($elm, $attrs) {
  853. return {
  854. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  855. var groupPanelTemplate = $scope.grid.options.groupPanelTemplate || defaultTemplate;
  856. gridUtil.getTemplate(groupPanelTemplate)
  857. .then(function (contents) {
  858. var template = angular.element(contents);
  859. var newElm = $compile(template)($scope);
  860. $elm.append(newElm);
  861. });
  862. },
  863. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  864. $elm.bind('$destroy', function() {
  865. // scrollUnbinder();
  866. });
  867. }
  868. };
  869. }
  870. };
  871. }]);
  872. })();
  873. (function(){
  874. 'use strict';
  875. angular.module('ui.grid').directive('uiGridHeaderCell', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants', 'ScrollEvent', 'i18nService',
  876. function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, ScrollEvent, i18nService) {
  877. // Do stuff after mouse has been down this many ms on the header cell
  878. var mousedownTimeout = 500;
  879. var changeModeTimeout = 500; // length of time between a touch event and a mouse event being recognised again, and vice versa
  880. var uiGridHeaderCell = {
  881. priority: 0,
  882. scope: {
  883. col: '=',
  884. row: '=',
  885. renderIndex: '='
  886. },
  887. require: ['^uiGrid', '^uiGridRenderContainer'],
  888. replace: true,
  889. compile: function() {
  890. return {
  891. pre: function ($scope, $elm, $attrs) {
  892. var cellHeader = $compile($scope.col.headerCellTemplate)($scope);
  893. $elm.append(cellHeader);
  894. },
  895. post: function ($scope, $elm, $attrs, controllers) {
  896. var uiGridCtrl = controllers[0];
  897. var renderContainerCtrl = controllers[1];
  898. $scope.i18n = {
  899. headerCell: i18nService.getSafeText('headerCell'),
  900. sort: i18nService.getSafeText('sort')
  901. };
  902. $scope.isSortPriorityVisible = function() {
  903. //show sort priority if column is sorted and there is at least one other sorted column
  904. return angular.isNumber($scope.col.sort.priority) && $scope.grid.columns.some(function(element, index){
  905. return angular.isNumber(element.sort.priority) && element !== $scope.col;
  906. });
  907. };
  908. $scope.getSortDirectionAriaLabel = function(){
  909. var col = $scope.col;
  910. //Trying to recreate this sort of thing but it was getting messy having it in the template.
  911. //Sort direction {{col.sort.direction == asc ? 'ascending' : ( col.sort.direction == desc ? 'descending':'none')}}. {{col.sort.priority ? {{columnPriorityText}} {{col.sort.priority}} : ''}
  912. var sortDirectionText = col.sort.direction === uiGridConstants.ASC ? $scope.i18n.sort.ascending : ( col.sort.direction === uiGridConstants.DESC ? $scope.i18n.sort.descending : $scope.i18n.sort.none);
  913. var label = sortDirectionText;
  914. if ($scope.isSortPriorityVisible()) {
  915. label = label + '. ' + $scope.i18n.headerCell.priority + ' ' + col.sort.priority;
  916. }
  917. return label;
  918. };
  919. $scope.grid = uiGridCtrl.grid;
  920. $scope.renderContainer = uiGridCtrl.grid.renderContainers[renderContainerCtrl.containerId];
  921. var initColClass = $scope.col.getColClass(false);
  922. $elm.addClass(initColClass);
  923. // Hide the menu by default
  924. $scope.menuShown = false;
  925. // Put asc and desc sort directions in scope
  926. $scope.asc = uiGridConstants.ASC;
  927. $scope.desc = uiGridConstants.DESC;
  928. // Store a reference to menu element
  929. var $colMenu = angular.element( $elm[0].querySelectorAll('.ui-grid-header-cell-menu') );
  930. var $contentsElm = angular.element( $elm[0].querySelectorAll('.ui-grid-cell-contents') );
  931. // apply any headerCellClass
  932. var classAdded;
  933. var previousMouseX;
  934. // filter watchers
  935. var filterDeregisters = [];
  936. /*
  937. * Our basic approach here for event handlers is that we listen for a down event (mousedown or touchstart).
  938. * Once we have a down event, we need to work out whether we have a click, a drag, or a
  939. * hold. A click would sort the grid (if sortable). A drag would be used by moveable, so
  940. * we ignore it. A hold would open the menu.
  941. *
  942. * So, on down event, we put in place handlers for move and up events, and a timer. If the
  943. * timer expires before we see a move or up, then we have a long press and hence a column menu open.
  944. * If the up happens before the timer, then we have a click, and we sort if the column is sortable.
  945. * If a move happens before the timer, then we are doing column move, so we do nothing, the moveable feature
  946. * will handle it.
  947. *
  948. * To deal with touch enabled devices that also have mice, we only create our handlers when
  949. * we get the down event, and we create the corresponding handlers - if we're touchstart then
  950. * we get touchmove and touchend, if we're mousedown then we get mousemove and mouseup.
  951. *
  952. * We also suppress the click action whilst this is happening - otherwise after the mouseup there
  953. * will be a click event and that can cause the column menu to close
  954. *
  955. */
  956. $scope.downFn = function( event ){
  957. event.stopPropagation();
  958. if (typeof(event.originalEvent) !== 'undefined' && event.originalEvent !== undefined) {
  959. event = event.originalEvent;
  960. }
  961. // Don't show the menu if it's not the left button
  962. if (event.button && event.button !== 0) {
  963. return;
  964. }
  965. previousMouseX = event.pageX;
  966. $scope.mousedownStartTime = (new Date()).getTime();
  967. $scope.mousedownTimeout = $timeout(function() { }, mousedownTimeout);
  968. $scope.mousedownTimeout.then(function () {
  969. if ( $scope.colMenu ) {
  970. uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm, event);
  971. }
  972. });
  973. uiGridCtrl.fireEvent(uiGridConstants.events.COLUMN_HEADER_CLICK, {event: event, columnName: $scope.col.colDef.name});
  974. $scope.offAllEvents();
  975. if ( event.type === 'touchstart'){
  976. $document.on('touchend', $scope.upFn);
  977. $document.on('touchmove', $scope.moveFn);
  978. } else if ( event.type === 'mousedown' ){
  979. $document.on('mouseup', $scope.upFn);
  980. $document.on('mousemove', $scope.moveFn);
  981. }
  982. };
  983. $scope.upFn = function( event ){
  984. event.stopPropagation();
  985. $timeout.cancel($scope.mousedownTimeout);
  986. $scope.offAllEvents();
  987. $scope.onDownEvents(event.type);
  988. var mousedownEndTime = (new Date()).getTime();
  989. var mousedownTime = mousedownEndTime - $scope.mousedownStartTime;
  990. if (mousedownTime > mousedownTimeout) {
  991. // long click, handled above with mousedown
  992. }
  993. else {
  994. // short click
  995. if ( $scope.sortable ){
  996. $scope.handleClick(event);
  997. }
  998. }
  999. };
  1000. $scope.moveFn = function( event ){
  1001. // Chrome is known to fire some bogus move events.
  1002. var changeValue = event.pageX - previousMouseX;
  1003. if ( changeValue === 0 ){ return; }
  1004. // we're a move, so do nothing and leave for column move (if enabled) to take over
  1005. $timeout.cancel($scope.mousedownTimeout);
  1006. $scope.offAllEvents();
  1007. $scope.onDownEvents(event.type);
  1008. };
  1009. $scope.clickFn = function ( event ){
  1010. event.stopPropagation();
  1011. $contentsElm.off('click', $scope.clickFn);
  1012. };
  1013. $scope.offAllEvents = function(){
  1014. $contentsElm.off('touchstart', $scope.downFn);
  1015. $contentsElm.off('mousedown', $scope.downFn);
  1016. $document.off('touchend', $scope.upFn);
  1017. $document.off('mouseup', $scope.upFn);
  1018. $document.off('touchmove', $scope.moveFn);
  1019. $document.off('mousemove', $scope.moveFn);
  1020. $contentsElm.off('click', $scope.clickFn);
  1021. };
  1022. $scope.onDownEvents = function( type ){
  1023. // If there is a previous event, then wait a while before
  1024. // activating the other mode - i.e. if the last event was a touch event then
  1025. // don't enable mouse events for a wee while (500ms or so)
  1026. // Avoids problems with devices that emulate mouse events when you have touch events
  1027. switch (type){
  1028. case 'touchmove':
  1029. case 'touchend':
  1030. $contentsElm.on('click', $scope.clickFn);
  1031. $contentsElm.on('touchstart', $scope.downFn);
  1032. $timeout(function(){
  1033. $contentsElm.on('mousedown', $scope.downFn);
  1034. }, changeModeTimeout);
  1035. break;
  1036. case 'mousemove':
  1037. case 'mouseup':
  1038. $contentsElm.on('click', $scope.clickFn);
  1039. $contentsElm.on('mousedown', $scope.downFn);
  1040. $timeout(function(){
  1041. $contentsElm.on('touchstart', $scope.downFn);
  1042. }, changeModeTimeout);
  1043. break;
  1044. default:
  1045. $contentsElm.on('click', $scope.clickFn);
  1046. $contentsElm.on('touchstart', $scope.downFn);
  1047. $contentsElm.on('mousedown', $scope.downFn);
  1048. }
  1049. };
  1050. var updateHeaderOptions = function( grid ){
  1051. var contents = $elm;
  1052. if ( classAdded ){
  1053. contents.removeClass( classAdded );
  1054. classAdded = null;
  1055. }
  1056. if (angular.isFunction($scope.col.headerCellClass)) {
  1057. classAdded = $scope.col.headerCellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex);
  1058. }
  1059. else {
  1060. classAdded = $scope.col.headerCellClass;
  1061. }
  1062. contents.addClass(classAdded);
  1063. $timeout(function (){
  1064. var rightMostContainer = $scope.grid.renderContainers['right'] ? $scope.grid.renderContainers['right'] : $scope.grid.renderContainers['body'];
  1065. $scope.isLastCol = ( $scope.col === rightMostContainer.visibleColumnCache[ rightMostContainer.visibleColumnCache.length - 1 ] );
  1066. });
  1067. // Figure out whether this column is sortable or not
  1068. if (uiGridCtrl.grid.options.enableSorting && $scope.col.enableSorting) {
  1069. $scope.sortable = true;
  1070. }
  1071. else {
  1072. $scope.sortable = false;
  1073. }
  1074. // Figure out whether this column is filterable or not
  1075. var oldFilterable = $scope.filterable;
  1076. if (uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering) {
  1077. $scope.filterable = true;
  1078. }
  1079. else {
  1080. $scope.filterable = false;
  1081. }
  1082. if ( oldFilterable !== $scope.filterable){
  1083. if ( typeof($scope.col.updateFilters) !== 'undefined' ){
  1084. $scope.col.updateFilters($scope.filterable);
  1085. }
  1086. // if column is filterable add a filter watcher
  1087. if ($scope.filterable) {
  1088. $scope.col.filters.forEach( function(filter, i) {
  1089. filterDeregisters.push($scope.$watch('col.filters[' + i + '].term', function(n, o) {
  1090. if (n !== o) {
  1091. uiGridCtrl.grid.api.core.raise.filterChanged();
  1092. uiGridCtrl.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
  1093. uiGridCtrl.grid.queueGridRefresh();
  1094. }
  1095. }));
  1096. });
  1097. $scope.$on('$destroy', function() {
  1098. filterDeregisters.forEach( function(filterDeregister) {
  1099. filterDeregister();
  1100. });
  1101. });
  1102. } else {
  1103. filterDeregisters.forEach( function(filterDeregister) {
  1104. filterDeregister();
  1105. });
  1106. }
  1107. }
  1108. // figure out whether we support column menus
  1109. if ($scope.col.grid.options && $scope.col.grid.options.enableColumnMenus !== false &&
  1110. $scope.col.colDef && $scope.col.colDef.enableColumnMenu !== false){
  1111. $scope.colMenu = true;
  1112. } else {
  1113. $scope.colMenu = false;
  1114. }
  1115. /**
  1116. * @ngdoc property
  1117. * @name enableColumnMenu
  1118. * @propertyOf ui.grid.class:GridOptions.columnDef
  1119. * @description if column menus are enabled, controls the column menus for this specific
  1120. * column (i.e. if gridOptions.enableColumnMenus, then you can control column menus
  1121. * using this option. If gridOptions.enableColumnMenus === false then you get no column
  1122. * menus irrespective of the value of this option ). Defaults to true.
  1123. *
  1124. */
  1125. /**
  1126. * @ngdoc property
  1127. * @name enableColumnMenus
  1128. * @propertyOf ui.grid.class:GridOptions.columnDef
  1129. * @description Override for column menus everywhere - if set to false then you get no
  1130. * column menus. Defaults to true.
  1131. *
  1132. */
  1133. $scope.offAllEvents();
  1134. if ($scope.sortable || $scope.colMenu) {
  1135. $scope.onDownEvents();
  1136. $scope.$on('$destroy', function () {
  1137. $scope.offAllEvents();
  1138. });
  1139. }
  1140. };
  1141. /*
  1142. $scope.$watch('col', function (n, o) {
  1143. if (n !== o) {
  1144. // See if the column's internal class has changed
  1145. var newColClass = $scope.col.getColClass(false);
  1146. if (newColClass !== initColClass) {
  1147. $elm.removeClass(initColClass);
  1148. $elm.addClass(newColClass);
  1149. initColClass = newColClass;
  1150. }
  1151. }
  1152. });
  1153. */
  1154. updateHeaderOptions();
  1155. // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs
  1156. var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateHeaderOptions, [uiGridConstants.dataChange.COLUMN]);
  1157. $scope.$on( '$destroy', dataChangeDereg );
  1158. $scope.handleClick = function(event) {
  1159. // If the shift key is being held down, add this column to the sort
  1160. var add = false;
  1161. if (event.shiftKey) {
  1162. add = true;
  1163. }
  1164. // Sort this column then rebuild the grid's rows
  1165. uiGridCtrl.grid.sortColumn($scope.col, add)
  1166. .then(function () {
  1167. if (uiGridCtrl.columnMenuScope) { uiGridCtrl.columnMenuScope.hideMenu(); }
  1168. uiGridCtrl.grid.refresh();
  1169. });
  1170. };
  1171. $scope.toggleMenu = function(event) {
  1172. event.stopPropagation();
  1173. // If the menu is already showing...
  1174. if (uiGridCtrl.columnMenuScope.menuShown) {
  1175. // ... and we're the column the menu is on...
  1176. if (uiGridCtrl.columnMenuScope.col === $scope.col) {
  1177. // ... hide it
  1178. uiGridCtrl.columnMenuScope.hideMenu();
  1179. }
  1180. // ... and we're NOT the column the menu is on
  1181. else {
  1182. // ... move the menu to our column
  1183. uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm);
  1184. }
  1185. }
  1186. // If the menu is NOT showing
  1187. else {
  1188. // ... show it on our column
  1189. uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm);
  1190. }
  1191. };
  1192. }
  1193. };
  1194. }
  1195. };
  1196. return uiGridHeaderCell;
  1197. }]);
  1198. })();
  1199. (function(){
  1200. 'use strict';
  1201. angular.module('ui.grid').directive('uiGridHeader', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', 'ScrollEvent',
  1202. function($templateCache, $compile, uiGridConstants, gridUtil, $timeout, ScrollEvent) {
  1203. var defaultTemplate = 'ui-grid/ui-grid-header';
  1204. var emptyTemplate = 'ui-grid/ui-grid-no-header';
  1205. return {
  1206. restrict: 'EA',
  1207. // templateUrl: 'ui-grid/ui-grid-header',
  1208. replace: true,
  1209. // priority: 1000,
  1210. require: ['^uiGrid', '^uiGridRenderContainer'],
  1211. scope: true,
  1212. compile: function($elm, $attrs) {
  1213. return {
  1214. pre: function ($scope, $elm, $attrs, controllers) {
  1215. var uiGridCtrl = controllers[0];
  1216. var containerCtrl = controllers[1];
  1217. $scope.grid = uiGridCtrl.grid;
  1218. $scope.colContainer = containerCtrl.colContainer;
  1219. updateHeaderReferences();
  1220. var headerTemplate;
  1221. if (!$scope.grid.options.showHeader) {
  1222. headerTemplate = emptyTemplate;
  1223. }
  1224. else {
  1225. headerTemplate = ($scope.grid.options.headerTemplate) ? $scope.grid.options.headerTemplate : defaultTemplate;
  1226. }
  1227. gridUtil.getTemplate(headerTemplate)
  1228. .then(function (contents) {
  1229. var template = angular.element(contents);
  1230. var newElm = $compile(template)($scope);
  1231. $elm.replaceWith(newElm);
  1232. // And update $elm to be the new element
  1233. $elm = newElm;
  1234. updateHeaderReferences();
  1235. if (containerCtrl) {
  1236. // Inject a reference to the header viewport (if it exists) into the grid controller for use in the horizontal scroll handler below
  1237. var headerViewport = $elm[0].getElementsByClassName('ui-grid-header-viewport')[0];
  1238. if (headerViewport) {
  1239. containerCtrl.headerViewport = headerViewport;
  1240. angular.element(headerViewport).on('scroll', scrollHandler);
  1241. $scope.$on('$destroy', function () {
  1242. angular.element(headerViewport).off('scroll', scrollHandler);
  1243. });
  1244. }
  1245. }
  1246. $scope.grid.queueRefresh();
  1247. });
  1248. function updateHeaderReferences() {
  1249. containerCtrl.header = containerCtrl.colContainer.header = $elm;
  1250. var headerCanvases = $elm[0].getElementsByClassName('ui-grid-header-canvas');
  1251. if (headerCanvases.length > 0) {
  1252. containerCtrl.headerCanvas = containerCtrl.colContainer.headerCanvas = headerCanvases[0];
  1253. }
  1254. else {
  1255. containerCtrl.headerCanvas = null;
  1256. }
  1257. }
  1258. function scrollHandler(evt) {
  1259. if (uiGridCtrl.grid.isScrollingHorizontally) {
  1260. return;
  1261. }
  1262. var newScrollLeft = gridUtil.normalizeScrollLeft(containerCtrl.headerViewport, uiGridCtrl.grid);
  1263. var horizScrollPercentage = containerCtrl.colContainer.scrollHorizontal(newScrollLeft);
  1264. var scrollEvent = new ScrollEvent(uiGridCtrl.grid, null, containerCtrl.colContainer, ScrollEvent.Sources.ViewPortScroll);
  1265. scrollEvent.newScrollLeft = newScrollLeft;
  1266. if ( horizScrollPercentage > -1 ){
  1267. scrollEvent.x = { percentage: horizScrollPercentage };
  1268. }
  1269. uiGridCtrl.grid.scrollContainers(null, scrollEvent);
  1270. }
  1271. },
  1272. post: function ($scope, $elm, $attrs, controllers) {
  1273. var uiGridCtrl = controllers[0];
  1274. var containerCtrl = controllers[1];
  1275. // gridUtil.logDebug('ui-grid-header link');
  1276. var grid = uiGridCtrl.grid;
  1277. // Don't animate header cells
  1278. gridUtil.disableAnimations($elm);
  1279. function updateColumnWidths() {
  1280. // this styleBuilder always runs after the renderContainer, so we can rely on the column widths
  1281. // already being populated correctly
  1282. var columnCache = containerCtrl.colContainer.visibleColumnCache;
  1283. // Build the CSS
  1284. // uiGridCtrl.grid.columns.forEach(function (column) {
  1285. var ret = '';
  1286. var canvasWidth = 0;
  1287. columnCache.forEach(function (column) {
  1288. ret = ret + column.getColClassDefinition();
  1289. canvasWidth += column.drawnWidth;
  1290. });
  1291. containerCtrl.colContainer.canvasWidth = canvasWidth;
  1292. // Return the styles back to buildStyles which pops them into the `customStyles` scope variable
  1293. return ret;
  1294. }
  1295. containerCtrl.header = $elm;
  1296. var headerViewport = $elm[0].getElementsByClassName('ui-grid-header-viewport')[0];
  1297. if (headerViewport) {
  1298. containerCtrl.headerViewport = headerViewport;
  1299. }
  1300. //todo: remove this if by injecting gridCtrl into unit tests
  1301. if (uiGridCtrl) {
  1302. uiGridCtrl.grid.registerStyleComputation({
  1303. priority: 15,
  1304. func: updateColumnWidths
  1305. });
  1306. }
  1307. }
  1308. };
  1309. }
  1310. };
  1311. }]);
  1312. })();
  1313. (function(){
  1314. angular.module('ui.grid')
  1315. .service('uiGridGridMenuService', [ 'gridUtil', 'i18nService', 'uiGridConstants', function( gridUtil, i18nService, uiGridConstants ) {
  1316. /**
  1317. * @ngdoc service
  1318. * @name ui.grid.gridMenuService
  1319. *
  1320. * @description Methods for working with the grid menu
  1321. */
  1322. var service = {
  1323. /**
  1324. * @ngdoc method
  1325. * @methodOf ui.grid.gridMenuService
  1326. * @name initialize
  1327. * @description Sets up the gridMenu. Most importantly, sets our
  1328. * scope onto the grid object as grid.gridMenuScope, allowing us
  1329. * to operate when passed only the grid. Second most importantly,
  1330. * we register the 'addToGridMenu' and 'removeFromGridMenu' methods
  1331. * on the core api.
  1332. * @param {$scope} $scope the scope of this gridMenu
  1333. * @param {Grid} grid the grid to which this gridMenu is associated
  1334. */
  1335. initialize: function( $scope, grid ){
  1336. grid.gridMenuScope = $scope;
  1337. $scope.grid = grid;
  1338. $scope.registeredMenuItems = [];
  1339. // not certain this is needed, but would be bad to create a memory leak
  1340. $scope.$on('$destroy', function() {
  1341. if ( $scope.grid && $scope.grid.gridMenuScope ){
  1342. $scope.grid.gridMenuScope = null;
  1343. }
  1344. if ( $scope.grid ){
  1345. $scope.grid = null;
  1346. }
  1347. if ( $scope.registeredMenuItems ){
  1348. $scope.registeredMenuItems = null;
  1349. }
  1350. });
  1351. $scope.registeredMenuItems = [];
  1352. /**
  1353. * @ngdoc function
  1354. * @name addToGridMenu
  1355. * @methodOf ui.grid.core.api:PublicApi
  1356. * @description add items to the grid menu. Used by features
  1357. * to add their menu items if they are enabled, can also be used by
  1358. * end users to add menu items. This method has the advantage of allowing
  1359. * remove again, which can simplify management of which items are included
  1360. * in the menu when. (Noting that in most cases the shown and active functions
  1361. * provide a better way to handle visibility of menu items)
  1362. * @param {Grid} grid the grid on which we are acting
  1363. * @param {array} items menu items in the format as described in the tutorial, with
  1364. * the added note that if you want to use remove you must also specify an `id` field,
  1365. * which is provided when you want to remove an item. The id should be unique.
  1366. *
  1367. */
  1368. grid.api.registerMethod( 'core', 'addToGridMenu', service.addToGridMenu );
  1369. /**
  1370. * @ngdoc function
  1371. * @name removeFromGridMenu
  1372. * @methodOf ui.grid.core.api:PublicApi
  1373. * @description Remove an item from the grid menu based on a provided id. Assumes
  1374. * that the id is unique, removes only the last instance of that id. Does nothing if
  1375. * the specified id is not found
  1376. * @param {Grid} grid the grid on which we are acting
  1377. * @param {string} id the id we'd like to remove from the menu
  1378. *
  1379. */
  1380. grid.api.registerMethod( 'core', 'removeFromGridMenu', service.removeFromGridMenu );
  1381. },
  1382. /**
  1383. * @ngdoc function
  1384. * @name addToGridMenu
  1385. * @propertyOf ui.grid.gridMenuService
  1386. * @description add items to the grid menu. Used by features
  1387. * to add their menu items if they are enabled, can also be used by
  1388. * end users to add menu items. This method has the advantage of allowing
  1389. * remove again, which can simplify management of which items are included
  1390. * in the menu when. (Noting that in most cases the shown and active functions
  1391. * provide a better way to handle visibility of menu items)
  1392. * @param {Grid} grid the grid on which we are acting
  1393. * @param {array} items menu items in the format as described in the tutorial, with
  1394. * the added note that if you want to use remove you must also specify an `id` field,
  1395. * which is provided when you want to remove an item. The id should be unique.
  1396. *
  1397. */
  1398. addToGridMenu: function( grid, menuItems ) {
  1399. if ( !angular.isArray( menuItems ) ) {
  1400. gridUtil.logError( 'addToGridMenu: menuItems must be an array, and is not, not adding any items');
  1401. } else {
  1402. if ( grid.gridMenuScope ){
  1403. grid.gridMenuScope.registeredMenuItems = grid.gridMenuScope.registeredMenuItems ? grid.gridMenuScope.registeredMenuItems : [];
  1404. grid.gridMenuScope.registeredMenuItems = grid.gridMenuScope.registeredMenuItems.concat( menuItems );
  1405. } else {
  1406. gridUtil.logError( 'Asked to addToGridMenu, but gridMenuScope not present. Timing issue? Please log issue with ui-grid');
  1407. }
  1408. }
  1409. },
  1410. /**
  1411. * @ngdoc function
  1412. * @name removeFromGridMenu
  1413. * @methodOf ui.grid.gridMenuService
  1414. * @description Remove an item from the grid menu based on a provided id. Assumes
  1415. * that the id is unique, removes only the last instance of that id. Does nothing if
  1416. * the specified id is not found. If there is no gridMenuScope or registeredMenuItems
  1417. * then do nothing silently - the desired result is those menu items not be present and they
  1418. * aren't.
  1419. * @param {Grid} grid the grid on which we are acting
  1420. * @param {string} id the id we'd like to remove from the menu
  1421. *
  1422. */
  1423. removeFromGridMenu: function( grid, id ){
  1424. var foundIndex = -1;
  1425. if ( grid && grid.gridMenuScope ){
  1426. grid.gridMenuScope.registeredMenuItems.forEach( function( value, index ) {
  1427. if ( value.id === id ){
  1428. if (foundIndex > -1) {
  1429. gridUtil.logError( 'removeFromGridMenu: found multiple items with the same id, removing only the last' );
  1430. } else {
  1431. foundIndex = index;
  1432. }
  1433. }
  1434. });
  1435. }
  1436. if ( foundIndex > -1 ){
  1437. grid.gridMenuScope.registeredMenuItems.splice( foundIndex, 1 );
  1438. }
  1439. },
  1440. /**
  1441. * @ngdoc array
  1442. * @name gridMenuCustomItems
  1443. * @propertyOf ui.grid.class:GridOptions
  1444. * @description (optional) An array of menu items that should be added to
  1445. * the gridMenu. Follow the format documented in the tutorial for column
  1446. * menu customisation. The context provided to the action function will
  1447. * include context.grid. An alternative if working with dynamic menus is to use the
  1448. * provided api - core.addToGridMenu and core.removeFromGridMenu, which handles
  1449. * some of the management of items for you.
  1450. *
  1451. */
  1452. /**
  1453. * @ngdoc boolean
  1454. * @name gridMenuShowHideColumns
  1455. * @propertyOf ui.grid.class:GridOptions
  1456. * @description true by default, whether the grid menu should allow hide/show
  1457. * of columns
  1458. *
  1459. */
  1460. /**
  1461. * @ngdoc method
  1462. * @methodOf ui.grid.gridMenuService
  1463. * @name getMenuItems
  1464. * @description Decides the menu items to show in the menu. This is a
  1465. * combination of:
  1466. *
  1467. * - the default menu items that are always included,
  1468. * - any menu items that have been provided through the addMenuItem api. These
  1469. * are typically added by features within the grid
  1470. * - any menu items included in grid.options.gridMenuCustomItems. These can be
  1471. * changed dynamically, as they're always recalculated whenever we show the
  1472. * menu
  1473. * @param {$scope} $scope the scope of this gridMenu, from which we can find all
  1474. * the information that we need
  1475. * @returns {array} an array of menu items that can be shown
  1476. */
  1477. getMenuItems: function( $scope ) {
  1478. var menuItems = [
  1479. // this is where we add any menu items we want to always include
  1480. ];
  1481. if ( $scope.grid.options.gridMenuCustomItems ){
  1482. if ( !angular.isArray( $scope.grid.options.gridMenuCustomItems ) ){
  1483. gridUtil.logError( 'gridOptions.gridMenuCustomItems must be an array, and is not');
  1484. } else {
  1485. menuItems = menuItems.concat( $scope.grid.options.gridMenuCustomItems );
  1486. }
  1487. }
  1488. var clearFilters = [{
  1489. title: i18nService.getSafeText('gridMenu.clearAllFilters'),
  1490. action: function ($event) {
  1491. $scope.grid.clearAllFilters(undefined, true, undefined);
  1492. },
  1493. shown: function() {
  1494. return $scope.grid.options.enableFiltering;
  1495. },
  1496. order: 100
  1497. }];
  1498. menuItems = menuItems.concat( clearFilters );
  1499. menuItems = menuItems.concat( $scope.registeredMenuItems );
  1500. if ( $scope.grid.options.gridMenuShowHideColumns !== false ){
  1501. menuItems = menuItems.concat( service.showHideColumns( $scope ) );
  1502. }
  1503. menuItems.sort(function(a, b){
  1504. return a.order - b.order;
  1505. });
  1506. return menuItems;
  1507. },
  1508. /**
  1509. * @ngdoc array
  1510. * @name gridMenuTitleFilter
  1511. * @propertyOf ui.grid.class:GridOptions
  1512. * @description (optional) A function that takes a title string
  1513. * (usually the col.displayName), and converts it into a display value. The function
  1514. * must return either a string or a promise.
  1515. *
  1516. * Used for internationalization of the grid menu column names - for angular-translate
  1517. * you can pass $translate as the function, for i18nService you can pass getSafeText as the
  1518. * function
  1519. * @example
  1520. * <pre>
  1521. * gridOptions = {
  1522. * gridMenuTitleFilter: $translate
  1523. * }
  1524. * </pre>
  1525. */
  1526. /**
  1527. * @ngdoc method
  1528. * @methodOf ui.grid.gridMenuService
  1529. * @name showHideColumns
  1530. * @description Adds two menu items for each of the columns in columnDefs. One
  1531. * menu item for hide, one menu item for show. Each is visible when appropriate
  1532. * (show when column is not visible, hide when column is visible). Each toggles
  1533. * the visible property on the columnDef using toggleColumnVisibility
  1534. * @param {$scope} $scope of a gridMenu, which contains a reference to the grid
  1535. */
  1536. showHideColumns: function( $scope ){
  1537. var showHideColumns = [];
  1538. if ( !$scope.grid.options.columnDefs || $scope.grid.options.columnDefs.length === 0 || $scope.grid.columns.length === 0 ) {
  1539. return showHideColumns;
  1540. }
  1541. // add header for columns
  1542. showHideColumns.push({
  1543. title: i18nService.getSafeText('gridMenu.columns'),
  1544. order: 300
  1545. });
  1546. $scope.grid.options.gridMenuTitleFilter = $scope.grid.options.gridMenuTitleFilter ? $scope.grid.options.gridMenuTitleFilter : function( title ) { return title; };
  1547. $scope.grid.options.columnDefs.forEach( function( colDef, index ){
  1548. if ( colDef.enableHiding !== false ){
  1549. // add hide menu item - shows an OK icon as we only show when column is already visible
  1550. var menuItem = {
  1551. icon: 'ui-grid-icon-ok',
  1552. action: function($event) {
  1553. $event.stopPropagation();
  1554. service.toggleColumnVisibility( this.context.gridCol );
  1555. },
  1556. shown: function() {
  1557. return this.context.gridCol.colDef.visible === true || this.context.gridCol.colDef.visible === undefined;
  1558. },
  1559. context: { gridCol: $scope.grid.getColumn(colDef.name || colDef.field) },
  1560. leaveOpen: true,
  1561. order: 301 + index * 2
  1562. };
  1563. service.setMenuItemTitle( menuItem, colDef, $scope.grid );
  1564. showHideColumns.push( menuItem );
  1565. // add show menu item - shows no icon as we only show when column is invisible
  1566. menuItem = {
  1567. icon: 'ui-grid-icon-cancel',
  1568. action: function($event) {
  1569. $event.stopPropagation();
  1570. service.toggleColumnVisibility( this.context.gridCol );
  1571. },
  1572. shown: function() {
  1573. return !(this.context.gridCol.colDef.visible === true || this.context.gridCol.colDef.visible === undefined);
  1574. },
  1575. context: { gridCol: $scope.grid.getColumn(colDef.name || colDef.field) },
  1576. leaveOpen: true,
  1577. order: 301 + index * 2 + 1
  1578. };
  1579. service.setMenuItemTitle( menuItem, colDef, $scope.grid );
  1580. showHideColumns.push( menuItem );
  1581. }
  1582. });
  1583. return showHideColumns;
  1584. },
  1585. /**
  1586. * @ngdoc method
  1587. * @methodOf ui.grid.gridMenuService
  1588. * @name setMenuItemTitle
  1589. * @description Handles the response from gridMenuTitleFilter, adding it directly to the menu
  1590. * item if it returns a string, otherwise waiting for the promise to resolve or reject then
  1591. * putting the result into the title
  1592. * @param {object} menuItem the menuItem we want to put the title on
  1593. * @param {object} colDef the colDef from which we can get displayName, name or field
  1594. * @param {Grid} grid the grid, from which we can get the options.gridMenuTitleFilter
  1595. *
  1596. */
  1597. setMenuItemTitle: function( menuItem, colDef, grid ){
  1598. var title = grid.options.gridMenuTitleFilter( colDef.displayName || gridUtil.readableColumnName(colDef.name) || colDef.field );
  1599. if ( typeof(title) === 'string' ){
  1600. menuItem.title = title;
  1601. } else if ( title.then ){
  1602. // must be a promise
  1603. menuItem.title = "";
  1604. title.then( function( successValue ) {
  1605. menuItem.title = successValue;
  1606. }, function( errorValue ) {
  1607. menuItem.title = errorValue;
  1608. });
  1609. } else {
  1610. gridUtil.logError('Expected gridMenuTitleFilter to return a string or a promise, it has returned neither, bad config');
  1611. menuItem.title = 'badconfig';
  1612. }
  1613. },
  1614. /**
  1615. * @ngdoc method
  1616. * @methodOf ui.grid.gridMenuService
  1617. * @name toggleColumnVisibility
  1618. * @description Toggles the visibility of an individual column. Expects to be
  1619. * provided a context that has on it a gridColumn, which is the column that
  1620. * we'll operate upon. We change the visibility, and refresh the grid as appropriate
  1621. * @param {GridCol} gridCol the column that we want to toggle
  1622. *
  1623. */
  1624. toggleColumnVisibility: function( gridCol ) {
  1625. gridCol.colDef.visible = !( gridCol.colDef.visible === true || gridCol.colDef.visible === undefined );
  1626. gridCol.grid.refresh();
  1627. gridCol.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
  1628. gridCol.grid.api.core.raise.columnVisibilityChanged( gridCol );
  1629. }
  1630. };
  1631. return service;
  1632. }])
  1633. .directive('uiGridMenuButton', ['gridUtil', 'uiGridConstants', 'uiGridGridMenuService', 'i18nService',
  1634. function (gridUtil, uiGridConstants, uiGridGridMenuService, i18nService) {
  1635. return {
  1636. priority: 0,
  1637. scope: true,
  1638. require: ['^uiGrid'],
  1639. templateUrl: 'ui-grid/ui-grid-menu-button',
  1640. replace: true,
  1641. link: function ($scope, $elm, $attrs, controllers) {
  1642. var uiGridCtrl = controllers[0];
  1643. // For the aria label
  1644. $scope.i18n = {
  1645. aria: i18nService.getSafeText('gridMenu.aria')
  1646. };
  1647. uiGridGridMenuService.initialize($scope, uiGridCtrl.grid);
  1648. $scope.shown = false;
  1649. $scope.toggleMenu = function () {
  1650. if ( $scope.shown ){
  1651. $scope.$broadcast('hide-menu');
  1652. $scope.shown = false;
  1653. } else {
  1654. $scope.menuItems = uiGridGridMenuService.getMenuItems( $scope );
  1655. $scope.$broadcast('show-menu');
  1656. $scope.shown = true;
  1657. }
  1658. };
  1659. $scope.$on('menu-hidden', function() {
  1660. $scope.shown = false;
  1661. gridUtil.focus.bySelector($elm, '.ui-grid-icon-container');
  1662. });
  1663. }
  1664. };
  1665. }]);
  1666. })();
  1667. (function(){
  1668. /**
  1669. * @ngdoc directive
  1670. * @name ui.grid.directive:uiGridMenu
  1671. * @element style
  1672. * @restrict A
  1673. *
  1674. * @description
  1675. * Allows us to interpolate expressions in `<style>` elements. Angular doesn't do this by default as it can/will/might? break in IE8.
  1676. *
  1677. * @example
  1678. <doc:example module="app">
  1679. <doc:source>
  1680. <script>
  1681. var app = angular.module('app', ['ui.grid']);
  1682. app.controller('MainCtrl', ['$scope', function ($scope) {
  1683. }]);
  1684. </script>
  1685. <div ng-controller="MainCtrl">
  1686. <div ui-grid-menu shown="true" ></div>
  1687. </div>
  1688. </doc:source>
  1689. <doc:scenario>
  1690. </doc:scenario>
  1691. </doc:example>
  1692. */
  1693. angular.module('ui.grid')
  1694. .directive('uiGridMenu', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants', 'i18nService',
  1695. function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18nService) {
  1696. var uiGridMenu = {
  1697. priority: 0,
  1698. scope: {
  1699. // shown: '&',
  1700. menuItems: '=',
  1701. autoHide: '=?'
  1702. },
  1703. require: '?^uiGrid',
  1704. templateUrl: 'ui-grid/uiGridMenu',
  1705. replace: false,
  1706. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  1707. var gridMenuMaxHeight;
  1708. $scope.dynamicStyles = '';
  1709. if (uiGridCtrl) {
  1710. // magic number of 30 because the grid menu displays somewhat below
  1711. // the top of the grid. It is approximately 30px.
  1712. gridMenuMaxHeight = uiGridCtrl.grid.gridHeight - 30;
  1713. $scope.dynamicStyles = [
  1714. '.grid' + uiGridCtrl.grid.id + ' .ui-grid-menu-mid {',
  1715. 'max-height: ' + gridMenuMaxHeight + 'px;',
  1716. '}'
  1717. ].join(' ');
  1718. }
  1719. $scope.i18n = {
  1720. close: i18nService.getSafeText('columnMenu.close')
  1721. };
  1722. // *** Show/Hide functions ******
  1723. $scope.showMenu = function(event, args) {
  1724. if ( !$scope.shown ){
  1725. /*
  1726. * In order to animate cleanly we remove the ng-if, wait a digest cycle, then
  1727. * animate the removal of the ng-hide. We can't successfully (so far as I can tell)
  1728. * animate removal of the ng-if, as the menu items aren't there yet. And we don't want
  1729. * to rely on ng-show only, as that leaves elements in the DOM that are needlessly evaluated
  1730. * on scroll events.
  1731. *
  1732. * Note when testing animation that animations don't run on the tutorials. When debugging it looks
  1733. * like they do, but angular has a default $animate provider that is just a stub, and that's what's
  1734. * being called. ALso don't be fooled by the fact that your browser has actually loaded the
  1735. * angular-translate.js, it's not using it. You need to test animations in an external application.
  1736. */
  1737. $scope.shown = true;
  1738. $timeout( function() {
  1739. $scope.shownMid = true;
  1740. $scope.$emit('menu-shown');
  1741. });
  1742. } else if ( !$scope.shownMid ) {
  1743. // we're probably doing a hide then show, so we don't need to wait for ng-if
  1744. $scope.shownMid = true;
  1745. $scope.$emit('menu-shown');
  1746. }
  1747. var docEventType = 'click';
  1748. if (args && args.originalEvent && args.originalEvent.type && args.originalEvent.type === 'touchstart') {
  1749. docEventType = args.originalEvent.type;
  1750. }
  1751. // Turn off an existing document click handler
  1752. angular.element(document).off('click touchstart', applyHideMenu);
  1753. $elm.off('keyup', checkKeyUp);
  1754. $elm.off('keydown', checkKeyDown);
  1755. // Turn on the document click handler, but in a timeout so it doesn't apply to THIS click if there is one
  1756. $timeout(function() {
  1757. angular.element(document).on(docEventType, applyHideMenu);
  1758. $elm.on('keyup', checkKeyUp);
  1759. $elm.on('keydown', checkKeyDown);
  1760. });
  1761. //automatically set the focus to the first button element in the now open menu.
  1762. gridUtil.focus.bySelector($elm, 'button[type=button]', true);
  1763. };
  1764. $scope.hideMenu = function(event) {
  1765. if ( $scope.shown ){
  1766. /*
  1767. * In order to animate cleanly we animate the addition of ng-hide, then use a $timeout to
  1768. * set the ng-if (shown = false) after the animation runs. In theory we can cascade off the
  1769. * callback on the addClass method, but it is very unreliable with unit tests for no discernable reason.
  1770. *
  1771. * The user may have clicked on the menu again whilst
  1772. * we're waiting, so we check that the mid isn't shown before applying the ng-if.
  1773. */
  1774. $scope.shownMid = false;
  1775. $timeout( function() {
  1776. if ( !$scope.shownMid ){
  1777. $scope.shown = false;
  1778. $scope.$emit('menu-hidden');
  1779. }
  1780. }, 200);
  1781. }
  1782. angular.element(document).off('click touchstart', applyHideMenu);
  1783. $elm.off('keyup', checkKeyUp);
  1784. $elm.off('keydown', checkKeyDown);
  1785. };
  1786. $scope.$on('hide-menu', function (event, args) {
  1787. $scope.hideMenu(event, args);
  1788. });
  1789. $scope.$on('show-menu', function (event, args) {
  1790. $scope.showMenu(event, args);
  1791. });
  1792. // *** Auto hide when click elsewhere ******
  1793. var applyHideMenu = function(){
  1794. if ($scope.shown) {
  1795. $scope.$apply(function () {
  1796. $scope.hideMenu();
  1797. });
  1798. }
  1799. };
  1800. // close menu on ESC and keep tab cyclical
  1801. var checkKeyUp = function(event) {
  1802. if (event.keyCode === 27) {
  1803. $scope.hideMenu();
  1804. }
  1805. };
  1806. var checkKeyDown = function(event) {
  1807. var setFocus = function(elm) {
  1808. elm.focus();
  1809. event.preventDefault();
  1810. return false;
  1811. };
  1812. if (event.keyCode === 9) {
  1813. var firstMenuItem, lastMenuItem;
  1814. var menuItemButtons = $elm[0].querySelectorAll('button:not(.ng-hide)');
  1815. if (menuItemButtons.length > 0) {
  1816. firstMenuItem = menuItemButtons[0];
  1817. lastMenuItem = menuItemButtons[menuItemButtons.length - 1];
  1818. if (event.target === lastMenuItem && !event.shiftKey) {
  1819. setFocus(firstMenuItem);
  1820. } else if (event.target === firstMenuItem && event.shiftKey) {
  1821. setFocus(lastMenuItem);
  1822. }
  1823. }
  1824. }
  1825. };
  1826. if (typeof($scope.autoHide) === 'undefined' || $scope.autoHide === undefined) {
  1827. $scope.autoHide = true;
  1828. }
  1829. if ($scope.autoHide) {
  1830. angular.element($window).on('resize', applyHideMenu);
  1831. }
  1832. $scope.$on('$destroy', function () {
  1833. angular.element(document).off('click touchstart', applyHideMenu);
  1834. });
  1835. $scope.$on('$destroy', function() {
  1836. angular.element($window).off('resize', applyHideMenu);
  1837. });
  1838. if (uiGridCtrl) {
  1839. $scope.$on('$destroy', uiGridCtrl.grid.api.core.on.scrollBegin($scope, applyHideMenu ));
  1840. }
  1841. $scope.$on('$destroy', $scope.$on(uiGridConstants.events.ITEM_DRAGGING, applyHideMenu ));
  1842. }
  1843. };
  1844. return uiGridMenu;
  1845. }])
  1846. .directive('uiGridMenuItem', ['gridUtil', '$compile', 'i18nService', function (gridUtil, $compile, i18nService) {
  1847. var uiGridMenuItem = {
  1848. priority: 0,
  1849. scope: {
  1850. name: '=',
  1851. active: '=',
  1852. action: '=',
  1853. icon: '=',
  1854. shown: '=',
  1855. context: '=',
  1856. templateUrl: '=',
  1857. leaveOpen: '=',
  1858. screenReaderOnly: '='
  1859. },
  1860. require: ['?^uiGrid'],
  1861. templateUrl: 'ui-grid/uiGridMenuItem',
  1862. replace: false,
  1863. compile: function() {
  1864. return {
  1865. pre: function ($scope, $elm) {
  1866. if ($scope.templateUrl) {
  1867. gridUtil.getTemplate($scope.templateUrl)
  1868. .then(function (contents) {
  1869. var template = angular.element(contents);
  1870. var newElm = $compile(template)($scope);
  1871. $elm.replaceWith(newElm);
  1872. });
  1873. }
  1874. },
  1875. post: function ($scope, $elm, $attrs, controllers) {
  1876. var uiGridCtrl = controllers[0];
  1877. // TODO(c0bra): validate that shown and active are functions if they're defined. An exception is already thrown above this though
  1878. // if (typeof($scope.shown) !== 'undefined' && $scope.shown && typeof($scope.shown) !== 'function') {
  1879. // throw new TypeError("$scope.shown is defined but not a function");
  1880. // }
  1881. if (typeof($scope.shown) === 'undefined' || $scope.shown === null) {
  1882. $scope.shown = function() { return true; };
  1883. }
  1884. $scope.itemShown = function () {
  1885. var context = {};
  1886. if ($scope.context) {
  1887. context.context = $scope.context;
  1888. }
  1889. if (typeof(uiGridCtrl) !== 'undefined' && uiGridCtrl) {
  1890. context.grid = uiGridCtrl.grid;
  1891. }
  1892. return $scope.shown.call(context);
  1893. };
  1894. $scope.itemAction = function($event,title) {
  1895. gridUtil.logDebug('itemAction');
  1896. $event.stopPropagation();
  1897. if (typeof($scope.action) === 'function') {
  1898. var context = {};
  1899. if ($scope.context) {
  1900. context.context = $scope.context;
  1901. }
  1902. // Add the grid to the function call context if the uiGrid controller is present
  1903. if (typeof(uiGridCtrl) !== 'undefined' && uiGridCtrl) {
  1904. context.grid = uiGridCtrl.grid;
  1905. }
  1906. $scope.action.call(context, $event, title);
  1907. if ( !$scope.leaveOpen ){
  1908. $scope.$emit('hide-menu');
  1909. } else {
  1910. /*
  1911. * XXX: Fix after column refactor
  1912. * Ideally the focus would remain on the item.
  1913. * However, since there are two menu items that have their 'show' property toggled instead. This is a quick fix.
  1914. */
  1915. gridUtil.focus.bySelector(angular.element(gridUtil.closestElm($elm, ".ui-grid-menu-items")), 'button[type=button]', true);
  1916. }
  1917. }
  1918. };
  1919. $scope.i18n = i18nService.get();
  1920. }
  1921. };
  1922. }
  1923. };
  1924. return uiGridMenuItem;
  1925. }]);
  1926. })();
  1927. (function(){
  1928. 'use strict';
  1929. /**
  1930. * @ngdoc overview
  1931. * @name ui.grid.directive:uiGridOneBind
  1932. * @summary A group of directives that provide a one time bind to a dom element.
  1933. * @description A group of directives that provide a one time bind to a dom element.
  1934. * As one time bindings are not supported in Angular 1.2.* this directive provdes this capability.
  1935. * This is done to reduce the number of watchers on the dom.
  1936. * <br/>
  1937. * <h2>Short Example ({@link ui.grid.directive:uiGridOneBindSrc ui-grid-one-bind-src})</h2>
  1938. * <pre>
  1939. <div ng-init="imageName = 'myImageDir.jpg'">
  1940. <img ui-grid-one-bind-src="imageName"></img>
  1941. </div>
  1942. </pre>
  1943. * Will become:
  1944. * <pre>
  1945. <div ng-init="imageName = 'myImageDir.jpg'">
  1946. <img ui-grid-one-bind-src="imageName" src="myImageDir.jpg"></img>
  1947. </div>
  1948. </pre>
  1949. </br>
  1950. <h2>Short Example ({@link ui.grid.directive:uiGridOneBindText ui-grid-one-bind-text})</h2>
  1951. * <pre>
  1952. <div ng-init="text='Add this text'" ui-grid-one-bind-text="text"></div>
  1953. </pre>
  1954. * Will become:
  1955. * <pre>
  1956. <div ng-init="text='Add this text'" ui-grid-one-bind-text="text">Add this text</div>
  1957. </pre>
  1958. </br>
  1959. * <b>Note:</b> This behavior is slightly different for the {@link ui.grid.directive:uiGridOneBindIdGrid uiGridOneBindIdGrid}
  1960. * and {@link ui.grid.directive:uiGridOneBindAriaLabelledbyGrid uiGridOneBindAriaLabelledbyGrid} directives.
  1961. *
  1962. */
  1963. //https://github.com/joshkurz/Black-Belt-AngularJS-Directives/blob/master/directives/Optimization/oneBind.js
  1964. var oneBinders = angular.module('ui.grid');
  1965. angular.forEach([
  1966. /**
  1967. * @ngdoc directive
  1968. * @name ui.grid.directive:uiGridOneBindSrc
  1969. * @memberof ui.grid.directive:uiGridOneBind
  1970. * @element img
  1971. * @restrict A
  1972. * @param {String} uiGridOneBindSrc The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  1973. * @description One time binding for the src dom tag.
  1974. *
  1975. */
  1976. {tag: 'Src', method: 'attr'},
  1977. /**
  1978. * @ngdoc directive
  1979. * @name ui.grid.directive:uiGridOneBindText
  1980. * @element div
  1981. * @restrict A
  1982. * @param {String} uiGridOneBindText The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  1983. * @description One time binding for the text dom tag.
  1984. */
  1985. {tag: 'Text', method: 'text'},
  1986. /**
  1987. * @ngdoc directive
  1988. * @name ui.grid.directive:uiGridOneBindHref
  1989. * @element div
  1990. * @restrict A
  1991. * @param {String} uiGridOneBindHref The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  1992. * @description One time binding for the href dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  1993. */
  1994. {tag: 'Href', method: 'attr'},
  1995. /**
  1996. * @ngdoc directive
  1997. * @name ui.grid.directive:uiGridOneBindClass
  1998. * @element div
  1999. * @restrict A
  2000. * @param {String} uiGridOneBindClass The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2001. * @param {Object} uiGridOneBindClass The object that you want to bind. At least one of the values in the object must be something other than null or undefined for the watcher to be removed.
  2002. * this is to prevent the watcher from being removed before the scope is initialized.
  2003. * @param {Array} uiGridOneBindClass An array of classes to bind to this element.
  2004. * @description One time binding for the class dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2005. */
  2006. {tag: 'Class', method: 'addClass'},
  2007. /**
  2008. * @ngdoc directive
  2009. * @name ui.grid.directive:uiGridOneBindHtml
  2010. * @element div
  2011. * @restrict A
  2012. * @param {String} uiGridOneBindHtml The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2013. * @description One time binding for the html method on a dom element. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2014. */
  2015. {tag: 'Html', method: 'html'},
  2016. /**
  2017. * @ngdoc directive
  2018. * @name ui.grid.directive:uiGridOneBindAlt
  2019. * @element div
  2020. * @restrict A
  2021. * @param {String} uiGridOneBindAlt The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2022. * @description One time binding for the alt dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2023. */
  2024. {tag: 'Alt', method: 'attr'},
  2025. /**
  2026. * @ngdoc directive
  2027. * @name ui.grid.directive:uiGridOneBindStyle
  2028. * @element div
  2029. * @restrict A
  2030. * @param {String} uiGridOneBindStyle The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2031. * @description One time binding for the style dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2032. */
  2033. {tag: 'Style', method: 'css'},
  2034. /**
  2035. * @ngdoc directive
  2036. * @name ui.grid.directive:uiGridOneBindValue
  2037. * @element div
  2038. * @restrict A
  2039. * @param {String} uiGridOneBindValue The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2040. * @description One time binding for the value dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2041. */
  2042. {tag: 'Value', method: 'attr'},
  2043. /**
  2044. * @ngdoc directive
  2045. * @name ui.grid.directive:uiGridOneBindId
  2046. * @element div
  2047. * @restrict A
  2048. * @param {String} uiGridOneBindId The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2049. * @description One time binding for the value dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2050. */
  2051. {tag: 'Id', method: 'attr'},
  2052. /**
  2053. * @ngdoc directive
  2054. * @name ui.grid.directive:uiGridOneBindIdGrid
  2055. * @element div
  2056. * @restrict A
  2057. * @param {String} uiGridOneBindIdGrid The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2058. * @description One time binding for the id dom tag.
  2059. * <h1>Important Note!</h1>
  2060. * If the id tag passed as a parameter does <b>not</b> contain the grid id as a substring
  2061. * then the directive will search the scope and the parent controller (if it is a uiGridController) for the grid.id value.
  2062. * If this value is found then it is appended to the begining of the id tag. If the grid is not found then the directive throws an error.
  2063. * This is done in order to ensure uniqueness of id tags across the grid.
  2064. * This is to prevent two grids in the same document having duplicate id tags.
  2065. */
  2066. {tag: 'Id', directiveName:'IdGrid', method: 'attr', appendGridId: true},
  2067. /**
  2068. * @ngdoc directive
  2069. * @name ui.grid.directive:uiGridOneBindTitle
  2070. * @element div
  2071. * @restrict A
  2072. * @param {String} uiGridOneBindTitle The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2073. * @description One time binding for the title dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2074. */
  2075. {tag: 'Title', method: 'attr'},
  2076. /**
  2077. * @ngdoc directive
  2078. * @name ui.grid.directive:uiGridOneBindAriaLabel
  2079. * @element div
  2080. * @restrict A
  2081. * @param {String} uiGridOneBindAriaLabel The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2082. * @description One time binding for the aria-label dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2083. *<br/>
  2084. * <pre>
  2085. <div ng-init="text='Add this text'" ui-grid-one-bind-aria-label="text"></div>
  2086. </pre>
  2087. * Will become:
  2088. * <pre>
  2089. <div ng-init="text='Add this text'" ui-grid-one-bind-aria-label="text" aria-label="Add this text"></div>
  2090. </pre>
  2091. */
  2092. {tag: 'Label', method: 'attr', aria:true},
  2093. /**
  2094. * @ngdoc directive
  2095. * @name ui.grid.directive:uiGridOneBindAriaLabelledby
  2096. * @element div
  2097. * @restrict A
  2098. * @param {String} uiGridOneBindAriaLabelledby The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2099. * @description One time binding for the aria-labelledby dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2100. *<br/>
  2101. * <pre>
  2102. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-labelledby="anId"></div>
  2103. </pre>
  2104. * Will become:
  2105. * <pre>
  2106. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-labelledby="anId" aria-labelledby="gridID32"></div>
  2107. </pre>
  2108. */
  2109. {tag: 'Labelledby', method: 'attr', aria:true},
  2110. /**
  2111. * @ngdoc directive
  2112. * @name ui.grid.directive:uiGridOneBindAriaLabelledbyGrid
  2113. * @element div
  2114. * @restrict A
  2115. * @param {String} uiGridOneBindAriaLabelledbyGrid The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2116. * @description One time binding for the aria-labelledby dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2117. * Works somewhat like {@link ui.grid.directive:uiGridOneBindIdGrid} however this one supports a list of ids (seperated by a space) and will dynamically add the
  2118. * grid id to each one.
  2119. *<br/>
  2120. * <pre>
  2121. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-labelledby-grid="anId"></div>
  2122. </pre>
  2123. * Will become ([grid.id] will be replaced by the actual grid id):
  2124. * <pre>
  2125. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-labelledby-grid="anId" aria-labelledby-Grid="[grid.id]-gridID32"></div>
  2126. </pre>
  2127. */
  2128. {tag: 'Labelledby', directiveName:'LabelledbyGrid', appendGridId:true, method: 'attr', aria:true},
  2129. /**
  2130. * @ngdoc directive
  2131. * @name ui.grid.directive:uiGridOneBindAriaDescribedby
  2132. * @element ANY
  2133. * @restrict A
  2134. * @param {String} uiGridOneBindAriaDescribedby The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2135. * @description One time binding for the aria-describedby dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2136. *<br/>
  2137. * <pre>
  2138. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-describedby="anId"></div>
  2139. </pre>
  2140. * Will become:
  2141. * <pre>
  2142. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-describedby="anId" aria-describedby="gridID32"></div>
  2143. </pre>
  2144. */
  2145. {tag: 'Describedby', method: 'attr', aria:true},
  2146. /**
  2147. * @ngdoc directive
  2148. * @name ui.grid.directive:uiGridOneBindAriaDescribedbyGrid
  2149. * @element ANY
  2150. * @restrict A
  2151. * @param {String} uiGridOneBindAriaDescribedbyGrid The angular string you want to bind. Does not support interpolation. Don't use <code>{{scopeElt}}</code> instead use <code>scopeElt</code>.
  2152. * @description One time binding for the aria-labelledby dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2153. * Works somewhat like {@link ui.grid.directive:uiGridOneBindIdGrid} however this one supports a list of ids (seperated by a space) and will dynamically add the
  2154. * grid id to each one.
  2155. *<br/>
  2156. * <pre>
  2157. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-describedby-grid="anId"></div>
  2158. </pre>
  2159. * Will become ([grid.id] will be replaced by the actual grid id):
  2160. * <pre>
  2161. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-describedby-grid="anId" aria-describedby="[grid.id]-gridID32"></div>
  2162. </pre>
  2163. */
  2164. {tag: 'Describedby', directiveName:'DescribedbyGrid', appendGridId:true, method: 'attr', aria:true}],
  2165. function(v){
  2166. var baseDirectiveName = 'uiGridOneBind';
  2167. //If it is an aria tag then append the aria label seperately
  2168. //This is done because the aria tags are formatted aria-* and the directive name can't have a '-' character in it.
  2169. //If the diretiveName has to be overridden then it does so here. This is because the tag being modified and the directive sometimes don't match up.
  2170. var directiveName = (v.aria ? baseDirectiveName + 'Aria' : baseDirectiveName) + (v.directiveName ? v.directiveName : v.tag);
  2171. oneBinders.directive(directiveName, ['gridUtil', function(gridUtil){
  2172. return {
  2173. restrict: 'A',
  2174. require: ['?uiGrid','?^uiGrid'],
  2175. link: function(scope, iElement, iAttrs, controllers){
  2176. /* Appends the grid id to the beginnig of the value. */
  2177. var appendGridId = function(val){
  2178. var grid; //Get an instance of the grid if its available
  2179. //If its available in the scope then we don't need to try to find it elsewhere
  2180. if (scope.grid) {
  2181. grid = scope.grid;
  2182. }
  2183. //Another possible location to try to find the grid
  2184. else if (scope.col && scope.col.grid){
  2185. grid = scope.col.grid;
  2186. }
  2187. //Last ditch effort: Search through the provided controllers.
  2188. else if (!controllers.some( //Go through the controllers till one has the element we need
  2189. function(controller){
  2190. if (controller && controller.grid) {
  2191. grid = controller.grid;
  2192. return true; //We've found the grid
  2193. }
  2194. })){
  2195. //We tried our best to find it for you
  2196. gridUtil.logError("["+directiveName+"] A valid grid could not be found to bind id. Are you using this directive " +
  2197. "within the correct scope? Trying to generate id: [gridID]-" + val);
  2198. throw new Error("No valid grid could be found");
  2199. }
  2200. if (grid){
  2201. var idRegex = new RegExp(grid.id.toString());
  2202. //If the grid id hasn't been appended already in the template declaration
  2203. if (!idRegex.test(val)){
  2204. val = grid.id.toString() + '-' + val;
  2205. }
  2206. }
  2207. return val;
  2208. };
  2209. // The watch returns a function to remove itself.
  2210. var rmWatcher = scope.$watch(iAttrs[directiveName], function(newV){
  2211. if (newV){
  2212. //If we are trying to add an id element then we also apply the grid id if it isn't already there
  2213. if (v.appendGridId) {
  2214. var newIdString = null;
  2215. //Append the id to all of the new ids.
  2216. angular.forEach( newV.split(' '), function(s){
  2217. newIdString = (newIdString ? (newIdString + ' ') : '') + appendGridId(s);
  2218. });
  2219. newV = newIdString;
  2220. }
  2221. // Append this newValue to the dom element.
  2222. switch (v.method) {
  2223. case 'attr': //The attr method takes two paraams the tag and the value
  2224. if (v.aria) {
  2225. //If it is an aria element then append the aria prefix
  2226. iElement[v.method]('aria-' + v.tag.toLowerCase(),newV);
  2227. } else {
  2228. iElement[v.method](v.tag.toLowerCase(),newV);
  2229. }
  2230. break;
  2231. case 'addClass':
  2232. //Pulled from https://github.com/Pasvaz/bindonce/blob/master/bindonce.js
  2233. if (angular.isObject(newV) && !angular.isArray(newV)) {
  2234. var results = [];
  2235. var nonNullFound = false; //We don't want to remove the binding unless the key is actually defined
  2236. angular.forEach(newV, function (value, index) {
  2237. if (value !== null && typeof(value) !== "undefined"){
  2238. nonNullFound = true; //A non null value for a key was found so the object must have been initialized
  2239. if (value) {results.push(index);}
  2240. }
  2241. });
  2242. //A non null value for a key wasn't found so assume that the scope values haven't been fully initialized
  2243. if (!nonNullFound){
  2244. return; // If not initialized then the watcher should not be removed yet.
  2245. }
  2246. newV = results;
  2247. }
  2248. if (newV) {
  2249. iElement.addClass(angular.isArray(newV) ? newV.join(' ') : newV);
  2250. } else {
  2251. return;
  2252. }
  2253. break;
  2254. default:
  2255. iElement[v.method](newV);
  2256. break;
  2257. }
  2258. //Removes the watcher on itself after the bind
  2259. rmWatcher();
  2260. }
  2261. // True ensures that equality is determined using angular.equals instead of ===
  2262. }, true); //End rm watchers
  2263. } //End compile function
  2264. }; //End directive return
  2265. } // End directive function
  2266. ]); //End directive
  2267. }); // End angular foreach
  2268. })();
  2269. (function () {
  2270. 'use strict';
  2271. var module = angular.module('ui.grid');
  2272. module.directive('uiGridRenderContainer', ['$timeout', '$document', 'uiGridConstants', 'gridUtil', 'ScrollEvent',
  2273. function($timeout, $document, uiGridConstants, gridUtil, ScrollEvent) {
  2274. return {
  2275. replace: true,
  2276. transclude: true,
  2277. templateUrl: 'ui-grid/uiGridRenderContainer',
  2278. require: ['^uiGrid', 'uiGridRenderContainer'],
  2279. scope: {
  2280. containerId: '=',
  2281. rowContainerName: '=',
  2282. colContainerName: '=',
  2283. bindScrollHorizontal: '=',
  2284. bindScrollVertical: '=',
  2285. enableVerticalScrollbar: '=',
  2286. enableHorizontalScrollbar: '='
  2287. },
  2288. controller: 'uiGridRenderContainer as RenderContainer',
  2289. compile: function () {
  2290. return {
  2291. pre: function prelink($scope, $elm, $attrs, controllers) {
  2292. var uiGridCtrl = controllers[0];
  2293. var containerCtrl = controllers[1];
  2294. var grid = $scope.grid = uiGridCtrl.grid;
  2295. // Verify that the render container for this element exists
  2296. if (!$scope.rowContainerName) {
  2297. throw "No row render container name specified";
  2298. }
  2299. if (!$scope.colContainerName) {
  2300. throw "No column render container name specified";
  2301. }
  2302. if (!grid.renderContainers[$scope.rowContainerName]) {
  2303. throw "Row render container '" + $scope.rowContainerName + "' is not registered.";
  2304. }
  2305. if (!grid.renderContainers[$scope.colContainerName]) {
  2306. throw "Column render container '" + $scope.colContainerName + "' is not registered.";
  2307. }
  2308. var rowContainer = $scope.rowContainer = grid.renderContainers[$scope.rowContainerName];
  2309. var colContainer = $scope.colContainer = grid.renderContainers[$scope.colContainerName];
  2310. containerCtrl.containerId = $scope.containerId;
  2311. containerCtrl.rowContainer = rowContainer;
  2312. containerCtrl.colContainer = colContainer;
  2313. },
  2314. post: function postlink($scope, $elm, $attrs, controllers) {
  2315. var uiGridCtrl = controllers[0];
  2316. var containerCtrl = controllers[1];
  2317. var grid = uiGridCtrl.grid;
  2318. var rowContainer = containerCtrl.rowContainer;
  2319. var colContainer = containerCtrl.colContainer;
  2320. var scrollTop = null;
  2321. var scrollLeft = null;
  2322. var renderContainer = grid.renderContainers[$scope.containerId];
  2323. // Put the container name on this element as a class
  2324. $elm.addClass('ui-grid-render-container-' + $scope.containerId);
  2325. // Scroll the render container viewport when the mousewheel is used
  2326. gridUtil.on.mousewheel($elm, function (event) {
  2327. var scrollEvent = new ScrollEvent(grid, rowContainer, colContainer, ScrollEvent.Sources.RenderContainerMouseWheel);
  2328. if (event.deltaY !== 0) {
  2329. var scrollYAmount = event.deltaY * -1 * event.deltaFactor;
  2330. scrollTop = containerCtrl.viewport[0].scrollTop;
  2331. // Get the scroll percentage
  2332. scrollEvent.verticalScrollLength = rowContainer.getVerticalScrollLength();
  2333. var scrollYPercentage = (scrollTop + scrollYAmount) / scrollEvent.verticalScrollLength;
  2334. // If we should be scrolled 100%, make sure the scrollTop matches the maximum scroll length
  2335. // Viewports that have "overflow: hidden" don't let the mousewheel scroll all the way to the bottom without this check
  2336. if (scrollYPercentage >= 1 && scrollTop < scrollEvent.verticalScrollLength) {
  2337. containerCtrl.viewport[0].scrollTop = scrollEvent.verticalScrollLength;
  2338. }
  2339. // Keep scrollPercentage within the range 0-1.
  2340. if (scrollYPercentage < 0) { scrollYPercentage = 0; }
  2341. else if (scrollYPercentage > 1) { scrollYPercentage = 1; }
  2342. scrollEvent.y = { percentage: scrollYPercentage, pixels: scrollYAmount };
  2343. }
  2344. if (event.deltaX !== 0) {
  2345. var scrollXAmount = event.deltaX * event.deltaFactor;
  2346. // Get the scroll percentage
  2347. scrollLeft = gridUtil.normalizeScrollLeft(containerCtrl.viewport, grid);
  2348. scrollEvent.horizontalScrollLength = (colContainer.getCanvasWidth() - colContainer.getViewportWidth());
  2349. var scrollXPercentage = (scrollLeft + scrollXAmount) / scrollEvent.horizontalScrollLength;
  2350. // Keep scrollPercentage within the range 0-1.
  2351. if (scrollXPercentage < 0) { scrollXPercentage = 0; }
  2352. else if (scrollXPercentage > 1) { scrollXPercentage = 1; }
  2353. scrollEvent.x = { percentage: scrollXPercentage, pixels: scrollXAmount };
  2354. }
  2355. // Let the parent container scroll if the grid is already at the top/bottom
  2356. if ((event.deltaY !== 0 && (scrollEvent.atTop(scrollTop) || scrollEvent.atBottom(scrollTop))) ||
  2357. (event.deltaX !== 0 && (scrollEvent.atLeft(scrollLeft) || scrollEvent.atRight(scrollLeft)))) {
  2358. //parent controller scrolls
  2359. }
  2360. else {
  2361. event.preventDefault();
  2362. event.stopPropagation();
  2363. scrollEvent.fireThrottledScrollingEvent('', scrollEvent);
  2364. }
  2365. });
  2366. $elm.bind('$destroy', function() {
  2367. $elm.unbind('keydown');
  2368. ['touchstart', 'touchmove', 'touchend','keydown', 'wheel', 'mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'].forEach(function (eventName) {
  2369. $elm.unbind(eventName);
  2370. });
  2371. });
  2372. // TODO(c0bra): Handle resizing the inner canvas based on the number of elements
  2373. function update() {
  2374. var ret = '';
  2375. var canvasWidth = colContainer.canvasWidth;
  2376. var viewportWidth = colContainer.getViewportWidth();
  2377. var canvasHeight = rowContainer.getCanvasHeight();
  2378. //add additional height for scrollbar on left and right container
  2379. //if ($scope.containerId !== 'body') {
  2380. // canvasHeight -= grid.scrollbarHeight;
  2381. //}
  2382. var viewportHeight = rowContainer.getViewportHeight();
  2383. //shorten the height to make room for a scrollbar placeholder
  2384. if (colContainer.needsHScrollbarPlaceholder()) {
  2385. viewportHeight -= grid.scrollbarHeight;
  2386. }
  2387. var headerViewportWidth,
  2388. footerViewportWidth;
  2389. headerViewportWidth = footerViewportWidth = colContainer.getHeaderViewportWidth();
  2390. // Set canvas dimensions
  2391. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId + ' .ui-grid-canvas { width: ' + canvasWidth + 'px; height: ' + canvasHeight + 'px; }';
  2392. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId + ' .ui-grid-header-canvas { width: ' + (canvasWidth + grid.scrollbarWidth) + 'px; }';
  2393. if (renderContainer.explicitHeaderCanvasHeight) {
  2394. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId + ' .ui-grid-header-canvas { height: ' + renderContainer.explicitHeaderCanvasHeight + 'px; }';
  2395. }
  2396. else {
  2397. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId + ' .ui-grid-header-canvas { height: inherit; }';
  2398. }
  2399. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId + ' .ui-grid-viewport { width: ' + viewportWidth + 'px; height: ' + viewportHeight + 'px; }';
  2400. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId + ' .ui-grid-header-viewport { width: ' + headerViewportWidth + 'px; }';
  2401. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId + ' .ui-grid-footer-canvas { width: ' + (canvasWidth + grid.scrollbarWidth) + 'px; }';
  2402. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId + ' .ui-grid-footer-viewport { width: ' + footerViewportWidth + 'px; }';
  2403. return ret;
  2404. }
  2405. uiGridCtrl.grid.registerStyleComputation({
  2406. priority: 6,
  2407. func: update
  2408. });
  2409. }
  2410. };
  2411. }
  2412. };
  2413. }]);
  2414. module.controller('uiGridRenderContainer', ['$scope', 'gridUtil', function ($scope, gridUtil) {
  2415. }]);
  2416. })();
  2417. (function(){
  2418. 'use strict';
  2419. angular.module('ui.grid').directive('uiGridRow', ['gridUtil', function(gridUtil) {
  2420. return {
  2421. replace: true,
  2422. // priority: 2001,
  2423. // templateUrl: 'ui-grid/ui-grid-row',
  2424. require: ['^uiGrid', '^uiGridRenderContainer'],
  2425. scope: {
  2426. row: '=uiGridRow',
  2427. //rowRenderIndex is added to scope to give the true visual index of the row to any directives that need it
  2428. rowRenderIndex: '='
  2429. },
  2430. compile: function() {
  2431. return {
  2432. pre: function($scope, $elm, $attrs, controllers) {
  2433. var uiGridCtrl = controllers[0];
  2434. var containerCtrl = controllers[1];
  2435. var grid = uiGridCtrl.grid;
  2436. $scope.grid = uiGridCtrl.grid;
  2437. $scope.colContainer = containerCtrl.colContainer;
  2438. // Function for attaching the template to this scope
  2439. var clonedElement, cloneScope;
  2440. function compileTemplate() {
  2441. $scope.row.getRowTemplateFn.then(function (compiledElementFn) {
  2442. // var compiledElementFn = $scope.row.compiledElementFn;
  2443. // Create a new scope for the contents of this row, so we can destroy it later if need be
  2444. var newScope = $scope.$new();
  2445. compiledElementFn(newScope, function (newElm, scope) {
  2446. // If we already have a cloned element, we need to remove it and destroy its scope
  2447. if (clonedElement) {
  2448. clonedElement.remove();
  2449. cloneScope.$destroy();
  2450. }
  2451. // Empty the row and append the new element
  2452. $elm.empty().append(newElm);
  2453. // Save the new cloned element and scope
  2454. clonedElement = newElm;
  2455. cloneScope = newScope;
  2456. });
  2457. });
  2458. }
  2459. // Initially attach the compiled template to this scope
  2460. compileTemplate();
  2461. // If the row's compiled element function changes, we need to replace this element's contents with the new compiled template
  2462. $scope.$watch('row.getRowTemplateFn', function (newFunc, oldFunc) {
  2463. if (newFunc !== oldFunc) {
  2464. compileTemplate();
  2465. }
  2466. });
  2467. },
  2468. post: function($scope, $elm, $attrs, controllers) {
  2469. }
  2470. };
  2471. }
  2472. };
  2473. }]);
  2474. })();
  2475. (function(){
  2476. // 'use strict';
  2477. /**
  2478. * @ngdoc directive
  2479. * @name ui.grid.directive:uiGridStyle
  2480. * @element style
  2481. * @restrict A
  2482. *
  2483. * @description
  2484. * Allows us to interpolate expressions in `<style>` elements. Angular doesn't do this by default as it can/will/might? break in IE8.
  2485. *
  2486. * @example
  2487. <doc:example module="app">
  2488. <doc:source>
  2489. <script>
  2490. var app = angular.module('app', ['ui.grid']);
  2491. app.controller('MainCtrl', ['$scope', function ($scope) {
  2492. $scope.myStyle = '.blah { border: 1px solid }';
  2493. }]);
  2494. </script>
  2495. <div ng-controller="MainCtrl">
  2496. <style ui-grid-style>{{ myStyle }}</style>
  2497. <span class="blah">I am in a box.</span>
  2498. </div>
  2499. </doc:source>
  2500. <doc:scenario>
  2501. it('should apply the right class to the element', function () {
  2502. element(by.css('.blah')).getCssValue('border-top-width')
  2503. .then(function(c) {
  2504. expect(c).toContain('1px');
  2505. });
  2506. });
  2507. </doc:scenario>
  2508. </doc:example>
  2509. */
  2510. angular.module('ui.grid').directive('uiGridStyle', ['gridUtil', '$interpolate', function(gridUtil, $interpolate) {
  2511. return {
  2512. // restrict: 'A',
  2513. // priority: 1000,
  2514. // require: '?^uiGrid',
  2515. link: function($scope, $elm, $attrs, uiGridCtrl) {
  2516. // gridUtil.logDebug('ui-grid-style link');
  2517. // if (uiGridCtrl === undefined) {
  2518. // gridUtil.logWarn('[ui-grid-style link] uiGridCtrl is undefined!');
  2519. // }
  2520. var interpolateFn = $interpolate($elm.text(), true);
  2521. if (interpolateFn) {
  2522. $scope.$watch(interpolateFn, function(value) {
  2523. $elm.text(value);
  2524. });
  2525. }
  2526. // uiGridCtrl.recalcRowStyles = function() {
  2527. // var offset = (scope.options.offsetTop || 0) - (scope.options.excessRows * scope.options.rowHeight);
  2528. // var rowHeight = scope.options.rowHeight;
  2529. // var ret = '';
  2530. // var rowStyleCount = uiGridCtrl.minRowsToRender() + (scope.options.excessRows * 2);
  2531. // for (var i = 1; i <= rowStyleCount; i++) {
  2532. // ret = ret + ' .grid' + scope.gridId + ' .ui-grid-row:nth-child(' + i + ') { top: ' + offset + 'px; }';
  2533. // offset = offset + rowHeight;
  2534. // }
  2535. // scope.rowStyles = ret;
  2536. // };
  2537. // uiGridCtrl.styleComputions.push(uiGridCtrl.recalcRowStyles);
  2538. }
  2539. };
  2540. }]);
  2541. })();
  2542. (function(){
  2543. 'use strict';
  2544. angular.module('ui.grid').directive('uiGridViewport', ['gridUtil','ScrollEvent','uiGridConstants', '$log',
  2545. function(gridUtil, ScrollEvent, uiGridConstants, $log) {
  2546. return {
  2547. replace: true,
  2548. scope: {},
  2549. controllerAs: 'Viewport',
  2550. templateUrl: 'ui-grid/uiGridViewport',
  2551. require: ['^uiGrid', '^uiGridRenderContainer'],
  2552. link: function($scope, $elm, $attrs, controllers) {
  2553. // gridUtil.logDebug('viewport post-link');
  2554. var uiGridCtrl = controllers[0];
  2555. var containerCtrl = controllers[1];
  2556. $scope.containerCtrl = containerCtrl;
  2557. var rowContainer = containerCtrl.rowContainer;
  2558. var colContainer = containerCtrl.colContainer;
  2559. var grid = uiGridCtrl.grid;
  2560. $scope.grid = uiGridCtrl.grid;
  2561. // Put the containers in scope so we can get rows and columns from them
  2562. $scope.rowContainer = containerCtrl.rowContainer;
  2563. $scope.colContainer = containerCtrl.colContainer;
  2564. // Register this viewport with its container
  2565. containerCtrl.viewport = $elm;
  2566. $elm.on('scroll', scrollHandler);
  2567. var ignoreScroll = false;
  2568. function scrollHandler(evt) {
  2569. //Leaving in this commented code in case it can someday be used
  2570. //It does improve performance, but because the horizontal scroll is normalized,
  2571. // using this code will lead to the column header getting slightly out of line with columns
  2572. //
  2573. //if (ignoreScroll && (grid.isScrollingHorizontally || grid.isScrollingHorizontally)) {
  2574. // //don't ask for scrollTop if we just set it
  2575. // ignoreScroll = false;
  2576. // return;
  2577. //}
  2578. //ignoreScroll = true;
  2579. var newScrollTop = $elm[0].scrollTop;
  2580. var newScrollLeft = gridUtil.normalizeScrollLeft($elm, grid);
  2581. var vertScrollPercentage = rowContainer.scrollVertical(newScrollTop);
  2582. var horizScrollPercentage = colContainer.scrollHorizontal(newScrollLeft);
  2583. var scrollEvent = new ScrollEvent(grid, rowContainer, colContainer, ScrollEvent.Sources.ViewPortScroll);
  2584. scrollEvent.newScrollLeft = newScrollLeft;
  2585. scrollEvent.newScrollTop = newScrollTop;
  2586. if ( horizScrollPercentage > -1 ){
  2587. scrollEvent.x = { percentage: horizScrollPercentage };
  2588. }
  2589. if ( vertScrollPercentage > -1 ){
  2590. scrollEvent.y = { percentage: vertScrollPercentage };
  2591. }
  2592. grid.scrollContainers($scope.$parent.containerId, scrollEvent);
  2593. }
  2594. if ($scope.$parent.bindScrollVertical) {
  2595. grid.addVerticalScrollSync($scope.$parent.containerId, syncVerticalScroll);
  2596. }
  2597. if ($scope.$parent.bindScrollHorizontal) {
  2598. grid.addHorizontalScrollSync($scope.$parent.containerId, syncHorizontalScroll);
  2599. grid.addHorizontalScrollSync($scope.$parent.containerId + 'header', syncHorizontalHeader);
  2600. grid.addHorizontalScrollSync($scope.$parent.containerId + 'footer', syncHorizontalFooter);
  2601. }
  2602. function syncVerticalScroll(scrollEvent){
  2603. containerCtrl.prevScrollArgs = scrollEvent;
  2604. var newScrollTop = scrollEvent.getNewScrollTop(rowContainer,containerCtrl.viewport);
  2605. $elm[0].scrollTop = newScrollTop;
  2606. }
  2607. function syncHorizontalScroll(scrollEvent){
  2608. containerCtrl.prevScrollArgs = scrollEvent;
  2609. var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport);
  2610. $elm[0].scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid);
  2611. }
  2612. function syncHorizontalHeader(scrollEvent){
  2613. var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport);
  2614. if (containerCtrl.headerViewport) {
  2615. containerCtrl.headerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid);
  2616. }
  2617. }
  2618. function syncHorizontalFooter(scrollEvent){
  2619. var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport);
  2620. if (containerCtrl.footerViewport) {
  2621. containerCtrl.footerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid);
  2622. }
  2623. }
  2624. },
  2625. controller: ['$scope', function ($scope) {
  2626. this.rowStyle = function (index) {
  2627. var rowContainer = $scope.rowContainer;
  2628. var colContainer = $scope.colContainer;
  2629. var styles = {};
  2630. if (index === 0 && rowContainer.currentTopRow !== 0) {
  2631. // The row offset-top is just the height of the rows above the current top-most row, which are no longer rendered
  2632. var hiddenRowWidth = (rowContainer.currentTopRow) * rowContainer.grid.options.rowHeight;
  2633. // return { 'margin-top': hiddenRowWidth + 'px' };
  2634. styles['margin-top'] = hiddenRowWidth + 'px';
  2635. }
  2636. if (colContainer.currentFirstColumn !== 0) {
  2637. if (colContainer.grid.isRTL()) {
  2638. styles['margin-right'] = colContainer.columnOffset + 'px';
  2639. }
  2640. else {
  2641. styles['margin-left'] = colContainer.columnOffset + 'px';
  2642. }
  2643. }
  2644. return styles;
  2645. };
  2646. }]
  2647. };
  2648. }
  2649. ]);
  2650. })();
  2651. (function() {
  2652. angular.module('ui.grid')
  2653. .directive('uiGridVisible', function uiGridVisibleAction() {
  2654. return function ($scope, $elm, $attr) {
  2655. $scope.$watch($attr.uiGridVisible, function (visible) {
  2656. // $elm.css('visibility', visible ? 'visible' : 'hidden');
  2657. $elm[visible ? 'removeClass' : 'addClass']('ui-grid-invisible');
  2658. });
  2659. };
  2660. });
  2661. })();
  2662. (function () {
  2663. 'use strict';
  2664. angular.module('ui.grid').controller('uiGridController', ['$scope', '$element', '$attrs', 'gridUtil', '$q', 'uiGridConstants',
  2665. '$templateCache', 'gridClassFactory', '$timeout', '$parse', '$compile',
  2666. function ($scope, $elm, $attrs, gridUtil, $q, uiGridConstants,
  2667. $templateCache, gridClassFactory, $timeout, $parse, $compile) {
  2668. // gridUtil.logDebug('ui-grid controller');
  2669. var self = this;
  2670. self.grid = gridClassFactory.createGrid($scope.uiGrid);
  2671. //assign $scope.$parent if appScope not already assigned
  2672. self.grid.appScope = self.grid.appScope || $scope.$parent;
  2673. $elm.addClass('grid' + self.grid.id);
  2674. self.grid.rtl = gridUtil.getStyles($elm[0])['direction'] === 'rtl';
  2675. // angular.extend(self.grid.options, );
  2676. //all properties of grid are available on scope
  2677. $scope.grid = self.grid;
  2678. if ($attrs.uiGridColumns) {
  2679. $attrs.$observe('uiGridColumns', function(value) {
  2680. self.grid.options.columnDefs = value;
  2681. self.grid.buildColumns()
  2682. .then(function(){
  2683. self.grid.preCompileCellTemplates();
  2684. self.grid.refreshCanvas(true);
  2685. });
  2686. });
  2687. }
  2688. // if fastWatch is set we watch only the length and the reference, not every individual object
  2689. var deregFunctions = [];
  2690. if (self.grid.options.fastWatch) {
  2691. self.uiGrid = $scope.uiGrid;
  2692. if (angular.isString($scope.uiGrid.data)) {
  2693. deregFunctions.push( $scope.$parent.$watch($scope.uiGrid.data, dataWatchFunction) );
  2694. deregFunctions.push( $scope.$parent.$watch(function() {
  2695. if ( self.grid.appScope[$scope.uiGrid.data] ){
  2696. return self.grid.appScope[$scope.uiGrid.data].length;
  2697. } else {
  2698. return undefined;
  2699. }
  2700. }, dataWatchFunction) );
  2701. } else {
  2702. deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.data; }, dataWatchFunction) );
  2703. deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.data.length; }, function(){ dataWatchFunction($scope.uiGrid.data); }) );
  2704. }
  2705. deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.columnDefs; }, columnDefsWatchFunction) );
  2706. deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.columnDefs.length; }, function(){ columnDefsWatchFunction($scope.uiGrid.columnDefs); }) );
  2707. } else {
  2708. if (angular.isString($scope.uiGrid.data)) {
  2709. deregFunctions.push( $scope.$parent.$watchCollection($scope.uiGrid.data, dataWatchFunction) );
  2710. } else {
  2711. deregFunctions.push( $scope.$parent.$watchCollection(function() { return $scope.uiGrid.data; }, dataWatchFunction) );
  2712. }
  2713. deregFunctions.push( $scope.$parent.$watchCollection(function() { return $scope.uiGrid.columnDefs; }, columnDefsWatchFunction) );
  2714. }
  2715. function columnDefsWatchFunction(n, o) {
  2716. if (n && n !== o) {
  2717. self.grid.options.columnDefs = $scope.uiGrid.columnDefs;
  2718. self.grid.buildColumns({ orderByColumnDefs: true })
  2719. .then(function(){
  2720. self.grid.preCompileCellTemplates();
  2721. self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.COLUMN);
  2722. });
  2723. }
  2724. }
  2725. var mostRecentData;
  2726. function dataWatchFunction(newData) {
  2727. // gridUtil.logDebug('dataWatch fired');
  2728. var promises = [];
  2729. if ( self.grid.options.fastWatch ){
  2730. if (angular.isString($scope.uiGrid.data)) {
  2731. newData = self.grid.appScope[$scope.uiGrid.data];
  2732. } else {
  2733. newData = $scope.uiGrid.data;
  2734. }
  2735. }
  2736. mostRecentData = newData;
  2737. if (newData) {
  2738. // columns length is greater than the number of row header columns, which don't count because they're created automatically
  2739. var hasColumns = self.grid.columns.length > (self.grid.rowHeaderColumns ? self.grid.rowHeaderColumns.length : 0);
  2740. if (
  2741. // If we have no columns
  2742. !hasColumns &&
  2743. // ... and we don't have a ui-grid-columns attribute, which would define columns for us
  2744. !$attrs.uiGridColumns &&
  2745. // ... and we have no pre-defined columns
  2746. self.grid.options.columnDefs.length === 0 &&
  2747. // ... but we DO have data
  2748. newData.length > 0
  2749. ) {
  2750. // ... then build the column definitions from the data that we have
  2751. self.grid.buildColumnDefsFromData(newData);
  2752. }
  2753. // If we haven't built columns before and either have some columns defined or some data defined
  2754. if (!hasColumns && (self.grid.options.columnDefs.length > 0 || newData.length > 0)) {
  2755. // Build the column set, then pre-compile the column cell templates
  2756. promises.push(self.grid.buildColumns()
  2757. .then(function() {
  2758. self.grid.preCompileCellTemplates();
  2759. }));
  2760. }
  2761. $q.all(promises).then(function() {
  2762. // use most recent data, rather than the potentially outdated data passed into watcher handler
  2763. self.grid.modifyRows(mostRecentData)
  2764. .then(function () {
  2765. // if (self.viewport) {
  2766. self.grid.redrawInPlace(true);
  2767. // }
  2768. $scope.$evalAsync(function() {
  2769. self.grid.refreshCanvas(true);
  2770. self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.ROW);
  2771. });
  2772. });
  2773. });
  2774. }
  2775. }
  2776. var styleWatchDereg = $scope.$watch(function () { return self.grid.styleComputations; }, function() {
  2777. self.grid.refreshCanvas(true);
  2778. });
  2779. $scope.$on('$destroy', function() {
  2780. deregFunctions.forEach( function( deregFn ){ deregFn(); });
  2781. styleWatchDereg();
  2782. });
  2783. self.fireEvent = function(eventName, args) {
  2784. // Add the grid to the event arguments if it's not there
  2785. if (typeof(args) === 'undefined' || args === undefined) {
  2786. args = {};
  2787. }
  2788. if (typeof(args.grid) === 'undefined' || args.grid === undefined) {
  2789. args.grid = self.grid;
  2790. }
  2791. $scope.$broadcast(eventName, args);
  2792. };
  2793. self.innerCompile = function innerCompile(elm) {
  2794. $compile(elm)($scope);
  2795. };
  2796. }]);
  2797. /**
  2798. * @ngdoc directive
  2799. * @name ui.grid.directive:uiGrid
  2800. * @element div
  2801. * @restrict EA
  2802. * @param {Object} uiGrid Options for the grid to use
  2803. *
  2804. * @description Create a very basic grid.
  2805. *
  2806. * @example
  2807. <example module="app">
  2808. <file name="app.js">
  2809. var app = angular.module('app', ['ui.grid']);
  2810. app.controller('MainCtrl', ['$scope', function ($scope) {
  2811. $scope.data = [
  2812. { name: 'Bob', title: 'CEO' },
  2813. { name: 'Frank', title: 'Lowly Developer' }
  2814. ];
  2815. }]);
  2816. </file>
  2817. <file name="index.html">
  2818. <div ng-controller="MainCtrl">
  2819. <div ui-grid="{ data: data }"></div>
  2820. </div>
  2821. </file>
  2822. </example>
  2823. */
  2824. angular.module('ui.grid').directive('uiGrid', uiGridDirective);
  2825. uiGridDirective.$inject = ['$compile', '$templateCache', '$timeout', '$window', 'gridUtil', 'uiGridConstants'];
  2826. function uiGridDirective($compile, $templateCache, $timeout, $window, gridUtil, uiGridConstants) {
  2827. return {
  2828. templateUrl: 'ui-grid/ui-grid',
  2829. scope: {
  2830. uiGrid: '='
  2831. },
  2832. replace: true,
  2833. transclude: true,
  2834. controller: 'uiGridController',
  2835. compile: function () {
  2836. return {
  2837. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  2838. var grid = uiGridCtrl.grid;
  2839. // Initialize scrollbars (TODO: move to controller??)
  2840. uiGridCtrl.scrollbars = [];
  2841. grid.element = $elm;
  2842. // See if the grid has a rendered width, if not, wait a bit and try again
  2843. var sizeCheckInterval = 100; // ms
  2844. var maxSizeChecks = 20; // 2 seconds total
  2845. var sizeChecks = 0;
  2846. // Setup (event listeners) the grid
  2847. setup();
  2848. // And initialize it
  2849. init();
  2850. // Mark rendering complete so API events can happen
  2851. grid.renderingComplete();
  2852. // If the grid doesn't have size currently, wait for a bit to see if it gets size
  2853. checkSize();
  2854. /*-- Methods --*/
  2855. function checkSize() {
  2856. // If the grid has no width and we haven't checked more than <maxSizeChecks> times, check again in <sizeCheckInterval> milliseconds
  2857. if ($elm[0].offsetWidth <= 0 && sizeChecks < maxSizeChecks) {
  2858. setTimeout(checkSize, sizeCheckInterval);
  2859. sizeChecks++;
  2860. }
  2861. else {
  2862. $timeout(init);
  2863. }
  2864. }
  2865. // Setup event listeners and watchers
  2866. function setup() {
  2867. // Bind to window resize events
  2868. angular.element($window).on('resize', gridResize);
  2869. // Unbind from window resize events when the grid is destroyed
  2870. $elm.on('$destroy', function () {
  2871. angular.element($window).off('resize', gridResize);
  2872. });
  2873. // If we add a left container after render, we need to watch and react
  2874. $scope.$watch(function () { return grid.hasLeftContainer();}, function (newValue, oldValue) {
  2875. if (newValue === oldValue) {
  2876. return;
  2877. }
  2878. grid.refreshCanvas(true);
  2879. });
  2880. // If we add a right container after render, we need to watch and react
  2881. $scope.$watch(function () { return grid.hasRightContainer();}, function (newValue, oldValue) {
  2882. if (newValue === oldValue) {
  2883. return;
  2884. }
  2885. grid.refreshCanvas(true);
  2886. });
  2887. }
  2888. // Initialize the directive
  2889. function init() {
  2890. grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm);
  2891. // Default canvasWidth to the grid width, in case we don't get any column definitions to calculate it from
  2892. grid.canvasWidth = uiGridCtrl.grid.gridWidth;
  2893. grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm);
  2894. // If the grid isn't tall enough to fit a single row, it's kind of useless. Resize it to fit a minimum number of rows
  2895. if (grid.gridHeight <= grid.options.rowHeight && grid.options.enableMinHeightCheck) {
  2896. autoAdjustHeight();
  2897. }
  2898. // Run initial canvas refresh
  2899. grid.refreshCanvas(true);
  2900. }
  2901. // Set the grid's height ourselves in the case that its height would be unusably small
  2902. function autoAdjustHeight() {
  2903. // Figure out the new height
  2904. var contentHeight = grid.options.minRowsToShow * grid.options.rowHeight;
  2905. var headerHeight = grid.options.showHeader ? grid.options.headerRowHeight : 0;
  2906. var footerHeight = grid.calcFooterHeight();
  2907. var scrollbarHeight = 0;
  2908. if (grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.ALWAYS) {
  2909. scrollbarHeight = gridUtil.getScrollbarWidth();
  2910. }
  2911. var maxNumberOfFilters = 0;
  2912. // Calculates the maximum number of filters in the columns
  2913. angular.forEach(grid.options.columnDefs, function(col) {
  2914. if (col.hasOwnProperty('filter')) {
  2915. if (maxNumberOfFilters < 1) {
  2916. maxNumberOfFilters = 1;
  2917. }
  2918. }
  2919. else if (col.hasOwnProperty('filters')) {
  2920. if (maxNumberOfFilters < col.filters.length) {
  2921. maxNumberOfFilters = col.filters.length;
  2922. }
  2923. }
  2924. });
  2925. if (grid.options.enableFiltering && !maxNumberOfFilters) {
  2926. var allColumnsHaveFilteringTurnedOff = grid.options.columnDefs.length && grid.options.columnDefs.every(function(col) {
  2927. return col.enableFiltering === false;
  2928. });
  2929. if (!allColumnsHaveFilteringTurnedOff) {
  2930. maxNumberOfFilters = 1;
  2931. }
  2932. }
  2933. var filterHeight = maxNumberOfFilters * headerHeight;
  2934. var newHeight = headerHeight + contentHeight + footerHeight + scrollbarHeight + filterHeight;
  2935. $elm.css('height', newHeight + 'px');
  2936. grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm);
  2937. }
  2938. // Resize the grid on window resize events
  2939. function gridResize($event) {
  2940. grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm);
  2941. grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm);
  2942. grid.refreshCanvas(true);
  2943. }
  2944. }
  2945. };
  2946. }
  2947. };
  2948. }
  2949. })();
  2950. (function(){
  2951. 'use strict';
  2952. // TODO: rename this file to ui-grid-pinned-container.js
  2953. angular.module('ui.grid').directive('uiGridPinnedContainer', ['gridUtil', function (gridUtil) {
  2954. return {
  2955. restrict: 'EA',
  2956. replace: true,
  2957. template: '<div class="ui-grid-pinned-container"><div ui-grid-render-container container-id="side" row-container-name="\'body\'" col-container-name="side" bind-scroll-vertical="true" class="{{ side }} ui-grid-render-container-{{ side }}"></div></div>',
  2958. scope: {
  2959. side: '=uiGridPinnedContainer'
  2960. },
  2961. require: '^uiGrid',
  2962. compile: function compile() {
  2963. return {
  2964. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  2965. // gridUtil.logDebug('ui-grid-pinned-container ' + $scope.side + ' link');
  2966. var grid = uiGridCtrl.grid;
  2967. var myWidth = 0;
  2968. $elm.addClass('ui-grid-pinned-container-' + $scope.side);
  2969. // Monkey-patch the viewport width function
  2970. if ($scope.side === 'left' || $scope.side === 'right') {
  2971. grid.renderContainers[$scope.side].getViewportWidth = monkeyPatchedGetViewportWidth;
  2972. }
  2973. function monkeyPatchedGetViewportWidth() {
  2974. /*jshint validthis: true */
  2975. var self = this;
  2976. var viewportWidth = 0;
  2977. self.visibleColumnCache.forEach(function (column) {
  2978. viewportWidth += column.drawnWidth;
  2979. });
  2980. var adjustment = self.getViewportAdjustment();
  2981. viewportWidth = viewportWidth + adjustment.width;
  2982. return viewportWidth;
  2983. }
  2984. function updateContainerWidth() {
  2985. if ($scope.side === 'left' || $scope.side === 'right') {
  2986. var cols = grid.renderContainers[$scope.side].visibleColumnCache;
  2987. var width = 0;
  2988. for (var i = 0; i < cols.length; i++) {
  2989. var col = cols[i];
  2990. width += col.drawnWidth || col.width || 0;
  2991. }
  2992. return width;
  2993. }
  2994. }
  2995. function updateContainerDimensions() {
  2996. var ret = '';
  2997. // Column containers
  2998. if ($scope.side === 'left' || $scope.side === 'right') {
  2999. myWidth = updateContainerWidth();
  3000. // gridUtil.logDebug('myWidth', myWidth);
  3001. // TODO(c0bra): Subtract sum of col widths from grid viewport width and update it
  3002. $elm.attr('style', null);
  3003. // var myHeight = grid.renderContainers.body.getViewportHeight(); // + grid.horizontalScrollbarHeight;
  3004. ret += '.grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ', .grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ' .ui-grid-render-container-' + $scope.side + ' .ui-grid-viewport { width: ' + myWidth + 'px; } ';
  3005. }
  3006. return ret;
  3007. }
  3008. grid.renderContainers.body.registerViewportAdjuster(function (adjustment) {
  3009. myWidth = updateContainerWidth();
  3010. // Subtract our own width
  3011. adjustment.width -= myWidth;
  3012. adjustment.side = $scope.side;
  3013. return adjustment;
  3014. });
  3015. // Register style computation to adjust for columns in `side`'s render container
  3016. grid.registerStyleComputation({
  3017. priority: 15,
  3018. func: updateContainerDimensions
  3019. });
  3020. }
  3021. };
  3022. }
  3023. };
  3024. }]);
  3025. })();
  3026. (function(){
  3027. angular.module('ui.grid')
  3028. .factory('Grid', ['$q', '$compile', '$parse', 'gridUtil', 'uiGridConstants', 'GridOptions', 'GridColumn', 'GridRow', 'GridApi', 'rowSorter', 'rowSearcher', 'GridRenderContainer', '$timeout','ScrollEvent',
  3029. function($q, $compile, $parse, gridUtil, uiGridConstants, GridOptions, GridColumn, GridRow, GridApi, rowSorter, rowSearcher, GridRenderContainer, $timeout, ScrollEvent) {
  3030. /**
  3031. * @ngdoc object
  3032. * @name ui.grid.core.api:PublicApi
  3033. * @description Public Api for the core grid features
  3034. *
  3035. */
  3036. /**
  3037. * @ngdoc function
  3038. * @name ui.grid.class:Grid
  3039. * @description Grid is the main viewModel. Any properties or methods needed to maintain state are defined in
  3040. * this prototype. One instance of Grid is created per Grid directive instance.
  3041. * @param {object} options Object map of options to pass into the grid. An 'id' property is expected.
  3042. */
  3043. var Grid = function Grid(options) {
  3044. var self = this;
  3045. // Get the id out of the options, then remove it
  3046. if (options !== undefined && typeof(options.id) !== 'undefined' && options.id) {
  3047. if (!/^[_a-zA-Z0-9-]+$/.test(options.id)) {
  3048. throw new Error("Grid id '" + options.id + '" is invalid. It must follow CSS selector syntax rules.');
  3049. }
  3050. }
  3051. else {
  3052. throw new Error('No ID provided. An ID must be given when creating a grid.');
  3053. }
  3054. self.id = options.id;
  3055. delete options.id;
  3056. // Get default options
  3057. self.options = GridOptions.initialize( options );
  3058. /**
  3059. * @ngdoc object
  3060. * @name appScope
  3061. * @propertyOf ui.grid.class:Grid
  3062. * @description reference to the application scope (the parent scope of the ui-grid element). Assigned in ui-grid controller
  3063. * <br/>
  3064. * use gridOptions.appScopeProvider to override the default assignment of $scope.$parent with any reference
  3065. */
  3066. self.appScope = self.options.appScopeProvider;
  3067. self.headerHeight = self.options.headerRowHeight;
  3068. /**
  3069. * @ngdoc object
  3070. * @name footerHeight
  3071. * @propertyOf ui.grid.class:Grid
  3072. * @description returns the total footer height gridFooter + columnFooter
  3073. */
  3074. self.footerHeight = self.calcFooterHeight();
  3075. /**
  3076. * @ngdoc object
  3077. * @name columnFooterHeight
  3078. * @propertyOf ui.grid.class:Grid
  3079. * @description returns the total column footer height
  3080. */
  3081. self.columnFooterHeight = self.calcColumnFooterHeight();
  3082. self.rtl = false;
  3083. self.gridHeight = 0;
  3084. self.gridWidth = 0;
  3085. self.columnBuilders = [];
  3086. self.rowBuilders = [];
  3087. self.rowsProcessors = [];
  3088. self.columnsProcessors = [];
  3089. self.styleComputations = [];
  3090. self.viewportAdjusters = [];
  3091. self.rowHeaderColumns = [];
  3092. self.dataChangeCallbacks = {};
  3093. self.verticalScrollSyncCallBackFns = {};
  3094. self.horizontalScrollSyncCallBackFns = {};
  3095. // self.visibleRowCache = [];
  3096. // Set of 'render' containers for self grid, which can render sets of rows
  3097. self.renderContainers = {};
  3098. // Create a
  3099. self.renderContainers.body = new GridRenderContainer('body', self);
  3100. self.cellValueGetterCache = {};
  3101. // Cached function to use with custom row templates
  3102. self.getRowTemplateFn = null;
  3103. //representation of the rows on the grid.
  3104. //these are wrapped references to the actual data rows (options.data)
  3105. self.rows = [];
  3106. //represents the columns on the grid
  3107. self.columns = [];
  3108. /**
  3109. * @ngdoc boolean
  3110. * @name isScrollingVertically
  3111. * @propertyOf ui.grid.class:Grid
  3112. * @description set to true when Grid is scrolling vertically. Set to false via debounced method
  3113. */
  3114. self.isScrollingVertically = false;
  3115. /**
  3116. * @ngdoc boolean
  3117. * @name isScrollingHorizontally
  3118. * @propertyOf ui.grid.class:Grid
  3119. * @description set to true when Grid is scrolling horizontally. Set to false via debounced method
  3120. */
  3121. self.isScrollingHorizontally = false;
  3122. /**
  3123. * @ngdoc property
  3124. * @name scrollDirection
  3125. * @propertyOf ui.grid.class:Grid
  3126. * @description set one of the uiGridConstants.scrollDirection values (UP, DOWN, LEFT, RIGHT, NONE), which tells
  3127. * us which direction we are scrolling. Set to NONE via debounced method
  3128. */
  3129. self.scrollDirection = uiGridConstants.scrollDirection.NONE;
  3130. //if true, grid will not respond to any scroll events
  3131. self.disableScrolling = false;
  3132. function vertical (scrollEvent) {
  3133. self.isScrollingVertically = false;
  3134. self.api.core.raise.scrollEnd(scrollEvent);
  3135. self.scrollDirection = uiGridConstants.scrollDirection.NONE;
  3136. }
  3137. var debouncedVertical = gridUtil.debounce(vertical, self.options.scrollDebounce);
  3138. var debouncedVerticalMinDelay = gridUtil.debounce(vertical, 0);
  3139. function horizontal (scrollEvent) {
  3140. self.isScrollingHorizontally = false;
  3141. self.api.core.raise.scrollEnd(scrollEvent);
  3142. self.scrollDirection = uiGridConstants.scrollDirection.NONE;
  3143. }
  3144. var debouncedHorizontal = gridUtil.debounce(horizontal, self.options.scrollDebounce);
  3145. var debouncedHorizontalMinDelay = gridUtil.debounce(horizontal, 0);
  3146. /**
  3147. * @ngdoc function
  3148. * @name flagScrollingVertically
  3149. * @methodOf ui.grid.class:Grid
  3150. * @description sets isScrollingVertically to true and sets it to false in a debounced function
  3151. */
  3152. self.flagScrollingVertically = function(scrollEvent) {
  3153. if (!self.isScrollingVertically && !self.isScrollingHorizontally) {
  3154. self.api.core.raise.scrollBegin(scrollEvent);
  3155. }
  3156. self.isScrollingVertically = true;
  3157. if (self.options.scrollDebounce === 0 || !scrollEvent.withDelay) {
  3158. debouncedVerticalMinDelay(scrollEvent);
  3159. }
  3160. else {
  3161. debouncedVertical(scrollEvent);
  3162. }
  3163. };
  3164. /**
  3165. * @ngdoc function
  3166. * @name flagScrollingHorizontally
  3167. * @methodOf ui.grid.class:Grid
  3168. * @description sets isScrollingHorizontally to true and sets it to false in a debounced function
  3169. */
  3170. self.flagScrollingHorizontally = function(scrollEvent) {
  3171. if (!self.isScrollingVertically && !self.isScrollingHorizontally) {
  3172. self.api.core.raise.scrollBegin(scrollEvent);
  3173. }
  3174. self.isScrollingHorizontally = true;
  3175. if (self.options.scrollDebounce === 0 || !scrollEvent.withDelay) {
  3176. debouncedHorizontalMinDelay(scrollEvent);
  3177. }
  3178. else {
  3179. debouncedHorizontal(scrollEvent);
  3180. }
  3181. };
  3182. self.scrollbarHeight = 0;
  3183. self.scrollbarWidth = 0;
  3184. if (self.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.ALWAYS) {
  3185. self.scrollbarHeight = gridUtil.getScrollbarWidth();
  3186. }
  3187. if (self.options.enableVerticalScrollbar === uiGridConstants.scrollbars.ALWAYS) {
  3188. self.scrollbarWidth = gridUtil.getScrollbarWidth();
  3189. }
  3190. self.api = new GridApi(self);
  3191. /**
  3192. * @ngdoc function
  3193. * @name refresh
  3194. * @methodOf ui.grid.core.api:PublicApi
  3195. * @description Refresh the rendered grid on screen.
  3196. * The refresh method re-runs both the columnProcessors and the
  3197. * rowProcessors, as well as calling refreshCanvas to update all
  3198. * the grid sizing. In general you should prefer to use queueGridRefresh
  3199. * instead, which is basically a debounced version of refresh.
  3200. *
  3201. * If you only want to resize the grid, not regenerate all the rows
  3202. * and columns, you should consider directly calling refreshCanvas instead.
  3203. *
  3204. */
  3205. self.api.registerMethod( 'core', 'refresh', this.refresh );
  3206. /**
  3207. * @ngdoc function
  3208. * @name queueGridRefresh
  3209. * @methodOf ui.grid.core.api:PublicApi
  3210. * @description Request a refresh of the rendered grid on screen, if multiple
  3211. * calls to queueGridRefresh are made within a digest cycle only one will execute.
  3212. * The refresh method re-runs both the columnProcessors and the
  3213. * rowProcessors, as well as calling refreshCanvas to update all
  3214. * the grid sizing. In general you should prefer to use queueGridRefresh
  3215. * instead, which is basically a debounced version of refresh.
  3216. *
  3217. */
  3218. self.api.registerMethod( 'core', 'queueGridRefresh', this.queueGridRefresh );
  3219. /**
  3220. * @ngdoc function
  3221. * @name refreshRows
  3222. * @methodOf ui.grid.core.api:PublicApi
  3223. * @description Runs only the rowProcessors, columns remain as they were.
  3224. * It then calls redrawInPlace and refreshCanvas, which adjust the grid sizing.
  3225. * @returns {promise} promise that is resolved when render completes?
  3226. *
  3227. */
  3228. self.api.registerMethod( 'core', 'refreshRows', this.refreshRows );
  3229. /**
  3230. * @ngdoc function
  3231. * @name queueRefresh
  3232. * @methodOf ui.grid.core.api:PublicApi
  3233. * @description Requests execution of refreshCanvas, if multiple requests are made
  3234. * during a digest cycle only one will run. RefreshCanvas updates the grid sizing.
  3235. * @returns {promise} promise that is resolved when render completes?
  3236. *
  3237. */
  3238. self.api.registerMethod( 'core', 'queueRefresh', this.queueRefresh );
  3239. /**
  3240. * @ngdoc function
  3241. * @name handleWindowResize
  3242. * @methodOf ui.grid.core.api:PublicApi
  3243. * @description Trigger a grid resize, normally this would be picked
  3244. * up by a watch on window size, but in some circumstances it is necessary
  3245. * to call this manually
  3246. * @returns {promise} promise that is resolved when render completes?
  3247. *
  3248. */
  3249. self.api.registerMethod( 'core', 'handleWindowResize', this.handleWindowResize );
  3250. /**
  3251. * @ngdoc function
  3252. * @name addRowHeaderColumn
  3253. * @methodOf ui.grid.core.api:PublicApi
  3254. * @description adds a row header column to the grid
  3255. * @param {object} column def
  3256. *
  3257. */
  3258. self.api.registerMethod( 'core', 'addRowHeaderColumn', this.addRowHeaderColumn );
  3259. /**
  3260. * @ngdoc function
  3261. * @name scrollToIfNecessary
  3262. * @methodOf ui.grid.core.api:PublicApi
  3263. * @description Scrolls the grid to make a certain row and column combo visible,
  3264. * in the case that it is not completely visible on the screen already.
  3265. * @param {GridRow} gridRow row to make visible
  3266. * @param {GridCol} gridCol column to make visible
  3267. * @returns {promise} a promise that is resolved when scrolling is complete
  3268. *
  3269. */
  3270. self.api.registerMethod( 'core', 'scrollToIfNecessary', function(gridRow, gridCol) { return self.scrollToIfNecessary(gridRow, gridCol);} );
  3271. /**
  3272. * @ngdoc function
  3273. * @name scrollTo
  3274. * @methodOf ui.grid.core.api:PublicApi
  3275. * @description Scroll the grid such that the specified
  3276. * row and column is in view
  3277. * @param {object} rowEntity gridOptions.data[] array instance to make visible
  3278. * @param {object} colDef to make visible
  3279. * @returns {promise} a promise that is resolved after any scrolling is finished
  3280. */
  3281. self.api.registerMethod( 'core', 'scrollTo', function (rowEntity, colDef) { return self.scrollTo(rowEntity, colDef);} );
  3282. /**
  3283. * @ngdoc function
  3284. * @name registerRowsProcessor
  3285. * @methodOf ui.grid.core.api:PublicApi
  3286. * @description
  3287. * Register a "rows processor" function. When the rows are updated,
  3288. * the grid calls each registered "rows processor", which has a chance
  3289. * to alter the set of rows (sorting, etc) as long as the count is not
  3290. * modified.
  3291. *
  3292. * @param {function(renderedRowsToProcess, columns )} processorFunction rows processor function, which
  3293. * is run in the context of the grid (i.e. this for the function will be the grid), and must
  3294. * return the updated rows list, which is passed to the next processor in the chain
  3295. * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room
  3296. * for other people to inject rows processors at intermediate priorities. Lower priority rowsProcessors run earlier.
  3297. *
  3298. * At present allRowsVisible is running at 50, sort manipulations running at 60-65, filter is running at 100,
  3299. * sort is at 200, grouping and treeview at 400-410, selectable rows at 500, pagination at 900 (pagination will generally want to be last)
  3300. */
  3301. self.api.registerMethod( 'core', 'registerRowsProcessor', this.registerRowsProcessor );
  3302. /**
  3303. * @ngdoc function
  3304. * @name registerColumnsProcessor
  3305. * @methodOf ui.grid.core.api:PublicApi
  3306. * @description
  3307. * Register a "columns processor" function. When the columns are updated,
  3308. * the grid calls each registered "columns processor", which has a chance
  3309. * to alter the set of columns as long as the count is not
  3310. * modified.
  3311. *
  3312. * @param {function(renderedColumnsToProcess, rows )} processorFunction columns processor function, which
  3313. * is run in the context of the grid (i.e. this for the function will be the grid), and must
  3314. * return the updated columns list, which is passed to the next processor in the chain
  3315. * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room
  3316. * for other people to inject columns processors at intermediate priorities. Lower priority columnsProcessors run earlier.
  3317. *
  3318. * At present allRowsVisible is running at 50, filter is running at 100, sort is at 200, grouping at 400, selectable rows at 500, pagination at 900 (pagination will generally want to be last)
  3319. */
  3320. self.api.registerMethod( 'core', 'registerColumnsProcessor', this.registerColumnsProcessor );
  3321. /**
  3322. * @ngdoc function
  3323. * @name sortHandleNulls
  3324. * @methodOf ui.grid.core.api:PublicApi
  3325. * @description A null handling method that can be used when building custom sort
  3326. * functions
  3327. * @example
  3328. * <pre>
  3329. * mySortFn = function(a, b) {
  3330. * var nulls = $scope.gridApi.core.sortHandleNulls(a, b);
  3331. * if ( nulls !== null ){
  3332. * return nulls;
  3333. * } else {
  3334. * // your code for sorting here
  3335. * };
  3336. * </pre>
  3337. * @param {object} a sort value a
  3338. * @param {object} b sort value b
  3339. * @returns {number} null if there were no nulls/undefineds, otherwise returns
  3340. * a sort value that should be passed back from the sort function
  3341. *
  3342. */
  3343. self.api.registerMethod( 'core', 'sortHandleNulls', rowSorter.handleNulls );
  3344. /**
  3345. * @ngdoc function
  3346. * @name sortChanged
  3347. * @methodOf ui.grid.core.api:PublicApi
  3348. * @description The sort criteria on one or more columns has
  3349. * changed. Provides as parameters the grid and the output of
  3350. * getColumnSorting, which is an array of gridColumns
  3351. * that have sorting on them, sorted in priority order.
  3352. *
  3353. * @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed.
  3354. * @param {Function} callBack Will be called when the event is emited. The function passes back the grid and an array of
  3355. * columns with sorts on them, in priority order.
  3356. *
  3357. * @example
  3358. * <pre>
  3359. * gridApi.core.on.sortChanged( $scope, function(grid, sortColumns){
  3360. * // do something
  3361. * });
  3362. * </pre>
  3363. */
  3364. self.api.registerEvent( 'core', 'sortChanged' );
  3365. /**
  3366. * @ngdoc function
  3367. * @name columnVisibilityChanged
  3368. * @methodOf ui.grid.core.api:PublicApi
  3369. * @description The visibility of a column has changed,
  3370. * the column itself is passed out as a parameter of the event.
  3371. *
  3372. * @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed.
  3373. * @param {Function} callBack Will be called when the event is emited. The function passes back the GridCol that has changed.
  3374. *
  3375. * @example
  3376. * <pre>
  3377. * gridApi.core.on.columnVisibilityChanged( $scope, function (column) {
  3378. * // do something
  3379. * } );
  3380. * </pre>
  3381. */
  3382. self.api.registerEvent( 'core', 'columnVisibilityChanged' );
  3383. /**
  3384. * @ngdoc method
  3385. * @name notifyDataChange
  3386. * @methodOf ui.grid.core.api:PublicApi
  3387. * @description Notify the grid that a data or config change has occurred,
  3388. * where that change isn't something the grid was otherwise noticing. This
  3389. * might be particularly relevant where you've changed values within the data
  3390. * and you'd like cell classes to be re-evaluated, or changed config within
  3391. * the columnDef and you'd like headerCellClasses to be re-evaluated.
  3392. * @param {string} type one of the
  3393. * uiGridConstants.dataChange values (ALL, ROW, EDIT, COLUMN), which tells
  3394. * us which refreshes to fire.
  3395. *
  3396. */
  3397. self.api.registerMethod( 'core', 'notifyDataChange', this.notifyDataChange );
  3398. /**
  3399. * @ngdoc method
  3400. * @name clearAllFilters
  3401. * @methodOf ui.grid.core.api:PublicApi
  3402. * @description Clears all filters and optionally refreshes the visible rows.
  3403. * @param {object} refreshRows Defaults to true.
  3404. * @param {object} clearConditions Defaults to false.
  3405. * @param {object} clearFlags Defaults to false.
  3406. * @returns {promise} If `refreshRows` is true, returns a promise of the rows refreshing.
  3407. */
  3408. self.api.registerMethod('core', 'clearAllFilters', this.clearAllFilters);
  3409. self.registerDataChangeCallback( self.columnRefreshCallback, [uiGridConstants.dataChange.COLUMN]);
  3410. self.registerDataChangeCallback( self.processRowsCallback, [uiGridConstants.dataChange.EDIT]);
  3411. self.registerDataChangeCallback( self.updateFooterHeightCallback, [uiGridConstants.dataChange.OPTIONS]);
  3412. self.registerStyleComputation({
  3413. priority: 10,
  3414. func: self.getFooterStyles
  3415. });
  3416. };
  3417. Grid.prototype.calcFooterHeight = function () {
  3418. if (!this.hasFooter()) {
  3419. return 0;
  3420. }
  3421. var height = 0;
  3422. if (this.options.showGridFooter) {
  3423. height += this.options.gridFooterHeight;
  3424. }
  3425. height += this.calcColumnFooterHeight();
  3426. return height;
  3427. };
  3428. Grid.prototype.calcColumnFooterHeight = function () {
  3429. var height = 0;
  3430. if (this.options.showColumnFooter) {
  3431. height += this.options.columnFooterHeight;
  3432. }
  3433. return height;
  3434. };
  3435. Grid.prototype.getFooterStyles = function () {
  3436. var style = '.grid' + this.id + ' .ui-grid-footer-aggregates-row { height: ' + this.options.columnFooterHeight + 'px; }';
  3437. style += ' .grid' + this.id + ' .ui-grid-footer-info { height: ' + this.options.gridFooterHeight + 'px; }';
  3438. return style;
  3439. };
  3440. Grid.prototype.hasFooter = function () {
  3441. return this.options.showGridFooter || this.options.showColumnFooter;
  3442. };
  3443. /**
  3444. * @ngdoc function
  3445. * @name isRTL
  3446. * @methodOf ui.grid.class:Grid
  3447. * @description Returns true if grid is RightToLeft
  3448. */
  3449. Grid.prototype.isRTL = function () {
  3450. return this.rtl;
  3451. };
  3452. /**
  3453. * @ngdoc function
  3454. * @name registerColumnBuilder
  3455. * @methodOf ui.grid.class:Grid
  3456. * @description When the build creates columns from column definitions, the columnbuilders will be called to add
  3457. * additional properties to the column.
  3458. * @param {function(colDef, col, gridOptions)} columnBuilder function to be called
  3459. */
  3460. Grid.prototype.registerColumnBuilder = function registerColumnBuilder(columnBuilder) {
  3461. this.columnBuilders.push(columnBuilder);
  3462. };
  3463. /**
  3464. * @ngdoc function
  3465. * @name buildColumnDefsFromData
  3466. * @methodOf ui.grid.class:Grid
  3467. * @description Populates columnDefs from the provided data
  3468. * @param {function(colDef, col, gridOptions)} rowBuilder function to be called
  3469. */
  3470. Grid.prototype.buildColumnDefsFromData = function (dataRows){
  3471. this.options.columnDefs = gridUtil.getColumnsFromData(dataRows, this.options.excludeProperties);
  3472. };
  3473. /**
  3474. * @ngdoc function
  3475. * @name registerRowBuilder
  3476. * @methodOf ui.grid.class:Grid
  3477. * @description When the build creates rows from gridOptions.data, the rowBuilders will be called to add
  3478. * additional properties to the row.
  3479. * @param {function(row, gridOptions)} rowBuilder function to be called
  3480. */
  3481. Grid.prototype.registerRowBuilder = function registerRowBuilder(rowBuilder) {
  3482. this.rowBuilders.push(rowBuilder);
  3483. };
  3484. /**
  3485. * @ngdoc function
  3486. * @name registerDataChangeCallback
  3487. * @methodOf ui.grid.class:Grid
  3488. * @description When a data change occurs, the data change callbacks of the specified type
  3489. * will be called. The rules are:
  3490. *
  3491. * - when the data watch fires, that is considered a ROW change (the data watch only notices
  3492. * added or removed rows)
  3493. * - when the api is called to inform us of a change, the declared type of that change is used
  3494. * - when a cell edit completes, the EDIT callbacks are triggered
  3495. * - when the columnDef watch fires, the COLUMN callbacks are triggered
  3496. * - when the options watch fires, the OPTIONS callbacks are triggered
  3497. *
  3498. * For a given event:
  3499. * - ALL calls ROW, EDIT, COLUMN, OPTIONS and ALL callbacks
  3500. * - ROW calls ROW and ALL callbacks
  3501. * - EDIT calls EDIT and ALL callbacks
  3502. * - COLUMN calls COLUMN and ALL callbacks
  3503. * - OPTIONS calls OPTIONS and ALL callbacks
  3504. *
  3505. * @param {function(grid)} callback function to be called
  3506. * @param {array} types the types of data change you want to be informed of. Values from
  3507. * the uiGridConstants.dataChange values ( ALL, EDIT, ROW, COLUMN, OPTIONS ). Optional and defaults to
  3508. * ALL
  3509. * @returns {function} deregister function - a function that can be called to deregister this callback
  3510. */
  3511. Grid.prototype.registerDataChangeCallback = function registerDataChangeCallback(callback, types, _this) {
  3512. var uid = gridUtil.nextUid();
  3513. if ( !types ){
  3514. types = [uiGridConstants.dataChange.ALL];
  3515. }
  3516. if ( !Array.isArray(types)){
  3517. gridUtil.logError("Expected types to be an array or null in registerDataChangeCallback, value passed was: " + types );
  3518. }
  3519. this.dataChangeCallbacks[uid] = { callback: callback, types: types, _this:_this };
  3520. var self = this;
  3521. var deregisterFunction = function() {
  3522. delete self.dataChangeCallbacks[uid];
  3523. };
  3524. return deregisterFunction;
  3525. };
  3526. /**
  3527. * @ngdoc function
  3528. * @name callDataChangeCallbacks
  3529. * @methodOf ui.grid.class:Grid
  3530. * @description Calls the callbacks based on the type of data change that
  3531. * has occurred. Always calls the ALL callbacks, calls the ROW, EDIT, COLUMN and OPTIONS callbacks if the
  3532. * event type is matching, or if the type is ALL.
  3533. * @param {number} type the type of event that occurred - one of the
  3534. * uiGridConstants.dataChange values (ALL, ROW, EDIT, COLUMN, OPTIONS)
  3535. */
  3536. Grid.prototype.callDataChangeCallbacks = function callDataChangeCallbacks(type, options) {
  3537. angular.forEach( this.dataChangeCallbacks, function( callback, uid ){
  3538. if ( callback.types.indexOf( uiGridConstants.dataChange.ALL ) !== -1 ||
  3539. callback.types.indexOf( type ) !== -1 ||
  3540. type === uiGridConstants.dataChange.ALL ) {
  3541. if (callback._this) {
  3542. callback.callback.apply(callback._this,this);
  3543. }
  3544. else {
  3545. callback.callback( this );
  3546. }
  3547. }
  3548. }, this);
  3549. };
  3550. /**
  3551. * @ngdoc function
  3552. * @name notifyDataChange
  3553. * @methodOf ui.grid.class:Grid
  3554. * @description Notifies us that a data change has occurred, used in the public
  3555. * api for users to tell us when they've changed data or some other event that
  3556. * our watches cannot pick up
  3557. * @param {string} type the type of event that occurred - one of the
  3558. * uiGridConstants.dataChange values (ALL, ROW, EDIT, COLUMN)
  3559. */
  3560. Grid.prototype.notifyDataChange = function notifyDataChange(type) {
  3561. var constants = uiGridConstants.dataChange;
  3562. if ( type === constants.ALL ||
  3563. type === constants.COLUMN ||
  3564. type === constants.EDIT ||
  3565. type === constants.ROW ||
  3566. type === constants.OPTIONS ){
  3567. this.callDataChangeCallbacks( type );
  3568. } else {
  3569. gridUtil.logError("Notified of a data change, but the type was not recognised, so no action taken, type was: " + type);
  3570. }
  3571. };
  3572. /**
  3573. * @ngdoc function
  3574. * @name columnRefreshCallback
  3575. * @methodOf ui.grid.class:Grid
  3576. * @description refreshes the grid when a column refresh
  3577. * is notified, which triggers handling of the visible flag.
  3578. * This is called on uiGridConstants.dataChange.COLUMN, and is
  3579. * registered as a dataChangeCallback in grid.js
  3580. * @param {string} name column name
  3581. */
  3582. Grid.prototype.columnRefreshCallback = function columnRefreshCallback( grid ){
  3583. grid.buildColumns();
  3584. grid.queueGridRefresh();
  3585. };
  3586. /**
  3587. * @ngdoc function
  3588. * @name processRowsCallback
  3589. * @methodOf ui.grid.class:Grid
  3590. * @description calls the row processors, specifically
  3591. * intended to reset the sorting when an edit is called,
  3592. * registered as a dataChangeCallback on uiGridConstants.dataChange.EDIT
  3593. * @param {string} name column name
  3594. */
  3595. Grid.prototype.processRowsCallback = function processRowsCallback( grid ){
  3596. grid.queueGridRefresh();
  3597. };
  3598. /**
  3599. * @ngdoc function
  3600. * @name updateFooterHeightCallback
  3601. * @methodOf ui.grid.class:Grid
  3602. * @description recalculates the footer height,
  3603. * registered as a dataChangeCallback on uiGridConstants.dataChange.OPTIONS
  3604. * @param {string} name column name
  3605. */
  3606. Grid.prototype.updateFooterHeightCallback = function updateFooterHeightCallback( grid ){
  3607. grid.footerHeight = grid.calcFooterHeight();
  3608. grid.columnFooterHeight = grid.calcColumnFooterHeight();
  3609. };
  3610. /**
  3611. * @ngdoc function
  3612. * @name getColumn
  3613. * @methodOf ui.grid.class:Grid
  3614. * @description returns a grid column for the column name
  3615. * @param {string} name column name
  3616. */
  3617. Grid.prototype.getColumn = function getColumn(name) {
  3618. var columns = this.columns.filter(function (column) {
  3619. return column.colDef.name === name;
  3620. });
  3621. return columns.length > 0 ? columns[0] : null;
  3622. };
  3623. /**
  3624. * @ngdoc function
  3625. * @name getColDef
  3626. * @methodOf ui.grid.class:Grid
  3627. * @description returns a grid colDef for the column name
  3628. * @param {string} name column.field
  3629. */
  3630. Grid.prototype.getColDef = function getColDef(name) {
  3631. var colDefs = this.options.columnDefs.filter(function (colDef) {
  3632. return colDef.name === name;
  3633. });
  3634. return colDefs.length > 0 ? colDefs[0] : null;
  3635. };
  3636. /**
  3637. * @ngdoc function
  3638. * @name assignTypes
  3639. * @methodOf ui.grid.class:Grid
  3640. * @description uses the first row of data to assign colDef.type for any types not defined.
  3641. */
  3642. /**
  3643. * @ngdoc property
  3644. * @name type
  3645. * @propertyOf ui.grid.class:GridOptions.columnDef
  3646. * @description the type of the column, used in sorting. If not provided then the
  3647. * grid will guess the type. Add this only if the grid guessing is not to your
  3648. * satisfaction. One of:
  3649. * - 'string'
  3650. * - 'boolean'
  3651. * - 'number'
  3652. * - 'date'
  3653. * - 'object'
  3654. * - 'numberStr'
  3655. * Note that if you choose date, your dates should be in a javascript date type
  3656. *
  3657. */
  3658. Grid.prototype.assignTypes = function(){
  3659. var self = this;
  3660. self.options.columnDefs.forEach(function (colDef, index) {
  3661. //Assign colDef type if not specified
  3662. if (!colDef.type) {
  3663. var col = new GridColumn(colDef, index, self);
  3664. var firstRow = self.rows.length > 0 ? self.rows[0] : null;
  3665. if (firstRow) {
  3666. colDef.type = gridUtil.guessType(self.getCellValue(firstRow, col));
  3667. }
  3668. else {
  3669. colDef.type = 'string';
  3670. }
  3671. }
  3672. });
  3673. };
  3674. /**
  3675. * @ngdoc function
  3676. * @name isRowHeaderColumn
  3677. * @methodOf ui.grid.class:Grid
  3678. * @description returns true if the column is a row Header
  3679. * @param {object} column column
  3680. */
  3681. Grid.prototype.isRowHeaderColumn = function isRowHeaderColumn(column) {
  3682. return this.rowHeaderColumns.indexOf(column) !== -1;
  3683. };
  3684. /**
  3685. * @ngdoc function
  3686. * @name addRowHeaderColumn
  3687. * @methodOf ui.grid.class:Grid
  3688. * @description adds a row header column to the grid
  3689. * @param {object} column def
  3690. */
  3691. Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef) {
  3692. var self = this;
  3693. var rowHeaderCol = new GridColumn(colDef, gridUtil.nextUid(), self);
  3694. rowHeaderCol.isRowHeader = true;
  3695. if (self.isRTL()) {
  3696. self.createRightContainer();
  3697. rowHeaderCol.renderContainer = 'right';
  3698. }
  3699. else {
  3700. self.createLeftContainer();
  3701. rowHeaderCol.renderContainer = 'left';
  3702. }
  3703. // relies on the default column builder being first in array, as it is instantiated
  3704. // as part of grid creation
  3705. self.columnBuilders[0](colDef,rowHeaderCol,self.options)
  3706. .then(function(){
  3707. rowHeaderCol.enableFiltering = false;
  3708. rowHeaderCol.enableSorting = false;
  3709. rowHeaderCol.enableHiding = false;
  3710. self.rowHeaderColumns.push(rowHeaderCol);
  3711. self.buildColumns()
  3712. .then( function() {
  3713. self.preCompileCellTemplates();
  3714. self.queueGridRefresh();
  3715. });
  3716. });
  3717. };
  3718. /**
  3719. * @ngdoc function
  3720. * @name getOnlyDataColumns
  3721. * @methodOf ui.grid.class:Grid
  3722. * @description returns all columns except for rowHeader columns
  3723. */
  3724. Grid.prototype.getOnlyDataColumns = function getOnlyDataColumns() {
  3725. var self = this;
  3726. var cols = [];
  3727. self.columns.forEach(function (col) {
  3728. if (self.rowHeaderColumns.indexOf(col) === -1) {
  3729. cols.push(col);
  3730. }
  3731. });
  3732. return cols;
  3733. };
  3734. /**
  3735. * @ngdoc function
  3736. * @name buildColumns
  3737. * @methodOf ui.grid.class:Grid
  3738. * @description creates GridColumn objects from the columnDefinition. Calls each registered
  3739. * columnBuilder to further process the column
  3740. * @param {object} options An object contains options to use when building columns
  3741. *
  3742. * * **orderByColumnDefs**: defaults to **false**. When true, `buildColumns` will reorder existing columns according to the order within the column definitions.
  3743. *
  3744. * @returns {Promise} a promise to load any needed column resources
  3745. */
  3746. Grid.prototype.buildColumns = function buildColumns(opts) {
  3747. var options = {
  3748. orderByColumnDefs: false
  3749. };
  3750. angular.extend(options, opts);
  3751. // gridUtil.logDebug('buildColumns');
  3752. var self = this;
  3753. var builderPromises = [];
  3754. var headerOffset = self.rowHeaderColumns.length;
  3755. var i;
  3756. // Remove any columns for which a columnDef cannot be found
  3757. // Deliberately don't use forEach, as it doesn't like splice being called in the middle
  3758. // Also don't cache columns.length, as it will change during this operation
  3759. for (i = 0; i < self.columns.length; i++){
  3760. if (!self.getColDef(self.columns[i].name)) {
  3761. self.columns.splice(i, 1);
  3762. i--;
  3763. }
  3764. }
  3765. //add row header columns to the grid columns array _after_ columns without columnDefs have been removed
  3766. self.rowHeaderColumns.forEach(function (rowHeaderColumn) {
  3767. self.columns.unshift(rowHeaderColumn);
  3768. });
  3769. // look at each column def, and update column properties to match. If the column def
  3770. // doesn't have a column, then splice in a new gridCol
  3771. self.options.columnDefs.forEach(function (colDef, index) {
  3772. self.preprocessColDef(colDef);
  3773. var col = self.getColumn(colDef.name);
  3774. if (!col) {
  3775. col = new GridColumn(colDef, gridUtil.nextUid(), self);
  3776. self.columns.splice(index + headerOffset, 0, col);
  3777. }
  3778. else {
  3779. // tell updateColumnDef that the column was pre-existing
  3780. col.updateColumnDef(colDef, false);
  3781. }
  3782. self.columnBuilders.forEach(function (builder) {
  3783. builderPromises.push(builder.call(self, colDef, col, self.options));
  3784. });
  3785. });
  3786. /*** Reorder columns if necessary ***/
  3787. if (!!options.orderByColumnDefs) {
  3788. // Create a shallow copy of the columns as a cache
  3789. var columnCache = self.columns.slice(0);
  3790. // We need to allow for the "row headers" when mapping from the column defs array to the columns array
  3791. // If we have a row header in columns[0] and don't account for it we'll overwrite it with the column in columnDefs[0]
  3792. // Go through all the column defs, use the shorter of columns length and colDefs.length because if a user has given two columns the same name then
  3793. // columns will be shorter than columnDefs. In this situation we'll avoid an error, but the user will still get an unexpected result
  3794. var len = Math.min(self.options.columnDefs.length, self.columns.length);
  3795. for (i = 0; i < len; i++) {
  3796. // If the column at this index has a different name than the column at the same index in the column defs...
  3797. if (self.columns[i + headerOffset].name !== self.options.columnDefs[i].name) {
  3798. // Replace the one in the cache with the appropriate column
  3799. columnCache[i + headerOffset] = self.getColumn(self.options.columnDefs[i].name);
  3800. }
  3801. else {
  3802. // Otherwise just copy over the one from the initial columns
  3803. columnCache[i + headerOffset] = self.columns[i + headerOffset];
  3804. }
  3805. }
  3806. // Empty out the columns array, non-destructively
  3807. self.columns.length = 0;
  3808. // And splice in the updated, ordered columns from the cache
  3809. Array.prototype.splice.apply(self.columns, [0, 0].concat(columnCache));
  3810. }
  3811. return $q.all(builderPromises).then(function(){
  3812. if (self.rows.length > 0){
  3813. self.assignTypes();
  3814. }
  3815. });
  3816. };
  3817. /**
  3818. * @ngdoc function
  3819. * @name preCompileCellTemplates
  3820. * @methodOf ui.grid.class:Grid
  3821. * @description precompiles all cell templates
  3822. */
  3823. Grid.prototype.preCompileCellTemplates = function() {
  3824. var self = this;
  3825. var preCompileTemplate = function( col ) {
  3826. var html = col.cellTemplate.replace(uiGridConstants.MODEL_COL_FIELD, self.getQualifiedColField(col));
  3827. html = html.replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)');
  3828. var compiledElementFn = $compile(html);
  3829. col.compiledElementFn = compiledElementFn;
  3830. if (col.compiledElementFnDefer) {
  3831. col.compiledElementFnDefer.resolve(col.compiledElementFn);
  3832. }
  3833. };
  3834. this.columns.forEach(function (col) {
  3835. if ( col.cellTemplate ){
  3836. preCompileTemplate( col );
  3837. } else if ( col.cellTemplatePromise ){
  3838. col.cellTemplatePromise.then( function() {
  3839. preCompileTemplate( col );
  3840. });
  3841. }
  3842. });
  3843. };
  3844. /**
  3845. * @ngdoc function
  3846. * @name getGridQualifiedColField
  3847. * @methodOf ui.grid.class:Grid
  3848. * @description Returns the $parse-able accessor for a column within its $scope
  3849. * @param {GridColumn} col col object
  3850. */
  3851. Grid.prototype.getQualifiedColField = function (col) {
  3852. return 'row.entity.' + gridUtil.preEval(col.field);
  3853. };
  3854. /**
  3855. * @ngdoc function
  3856. * @name createLeftContainer
  3857. * @methodOf ui.grid.class:Grid
  3858. * @description creates the left render container if it doesn't already exist
  3859. */
  3860. Grid.prototype.createLeftContainer = function() {
  3861. if (!this.hasLeftContainer()) {
  3862. this.renderContainers.left = new GridRenderContainer('left', this, { disableColumnOffset: true });
  3863. }
  3864. };
  3865. /**
  3866. * @ngdoc function
  3867. * @name createRightContainer
  3868. * @methodOf ui.grid.class:Grid
  3869. * @description creates the right render container if it doesn't already exist
  3870. */
  3871. Grid.prototype.createRightContainer = function() {
  3872. if (!this.hasRightContainer()) {
  3873. this.renderContainers.right = new GridRenderContainer('right', this, { disableColumnOffset: true });
  3874. }
  3875. };
  3876. /**
  3877. * @ngdoc function
  3878. * @name hasLeftContainer
  3879. * @methodOf ui.grid.class:Grid
  3880. * @description returns true if leftContainer exists
  3881. */
  3882. Grid.prototype.hasLeftContainer = function() {
  3883. return this.renderContainers.left !== undefined;
  3884. };
  3885. /**
  3886. * @ngdoc function
  3887. * @name hasRightContainer
  3888. * @methodOf ui.grid.class:Grid
  3889. * @description returns true if rightContainer exists
  3890. */
  3891. Grid.prototype.hasRightContainer = function() {
  3892. return this.renderContainers.right !== undefined;
  3893. };
  3894. /**
  3895. * undocumented function
  3896. * @name preprocessColDef
  3897. * @methodOf ui.grid.class:Grid
  3898. * @description defaults the name property from field to maintain backwards compatibility with 2.x
  3899. * validates that name or field is present
  3900. */
  3901. Grid.prototype.preprocessColDef = function preprocessColDef(colDef) {
  3902. var self = this;
  3903. if (!colDef.field && !colDef.name) {
  3904. throw new Error('colDef.name or colDef.field property is required');
  3905. }
  3906. //maintain backwards compatibility with 2.x
  3907. //field was required in 2.x. now name is required
  3908. if (colDef.name === undefined && colDef.field !== undefined) {
  3909. // See if the column name already exists:
  3910. var newName = colDef.field,
  3911. counter = 2;
  3912. while (self.getColumn(newName)) {
  3913. newName = colDef.field + counter.toString();
  3914. counter++;
  3915. }
  3916. colDef.name = newName;
  3917. }
  3918. };
  3919. // Return a list of items that exist in the `n` array but not the `o` array. Uses optional property accessors passed as third & fourth parameters
  3920. Grid.prototype.newInN = function newInN(o, n, oAccessor, nAccessor) {
  3921. var self = this;
  3922. var t = [];
  3923. for (var i = 0; i < n.length; i++) {
  3924. var nV = nAccessor ? n[i][nAccessor] : n[i];
  3925. var found = false;
  3926. for (var j = 0; j < o.length; j++) {
  3927. var oV = oAccessor ? o[j][oAccessor] : o[j];
  3928. if (self.options.rowEquality(nV, oV)) {
  3929. found = true;
  3930. break;
  3931. }
  3932. }
  3933. if (!found) {
  3934. t.push(nV);
  3935. }
  3936. }
  3937. return t;
  3938. };
  3939. /**
  3940. * @ngdoc function
  3941. * @name getRow
  3942. * @methodOf ui.grid.class:Grid
  3943. * @description returns the GridRow that contains the rowEntity
  3944. * @param {object} rowEntity the gridOptions.data array element instance
  3945. * @param {array} rows [optional] the rows to look in - if not provided then
  3946. * looks in grid.rows
  3947. */
  3948. Grid.prototype.getRow = function getRow(rowEntity, lookInRows) {
  3949. var self = this;
  3950. lookInRows = typeof(lookInRows) === 'undefined' ? self.rows : lookInRows;
  3951. var rows = lookInRows.filter(function (row) {
  3952. return self.options.rowEquality(row.entity, rowEntity);
  3953. });
  3954. return rows.length > 0 ? rows[0] : null;
  3955. };
  3956. /**
  3957. * @ngdoc function
  3958. * @name modifyRows
  3959. * @methodOf ui.grid.class:Grid
  3960. * @description creates or removes GridRow objects from the newRawData array. Calls each registered
  3961. * rowBuilder to further process the row
  3962. * @param {array} newRawData Modified set of data
  3963. *
  3964. * This method aims to achieve three things:
  3965. * 1. the resulting rows array is in the same order as the newRawData, we'll call
  3966. * rowsProcessors immediately after to sort the data anyway
  3967. * 2. if we have row hashing available, we try to use the rowHash to find the row
  3968. * 3. no memory leaks - rows that are no longer in newRawData need to be garbage collected
  3969. *
  3970. * The basic logic flow makes use of the newRawData, oldRows and oldHash, and creates
  3971. * the newRows and newHash
  3972. *
  3973. * ```
  3974. * newRawData.forEach newEntity
  3975. * if (hashing enabled)
  3976. * check oldHash for newEntity
  3977. * else
  3978. * look for old row directly in oldRows
  3979. * if !oldRowFound // must be a new row
  3980. * create newRow
  3981. * append to the newRows and add to newHash
  3982. * run the processors
  3983. * ```
  3984. *
  3985. * Rows are identified using the hashKey if configured. If not configured, then rows
  3986. * are identified using the gridOptions.rowEquality function
  3987. *
  3988. * This method is useful when trying to select rows immediately after loading data without
  3989. * using a $timeout/$interval, e.g.:
  3990. *
  3991. * $scope.gridOptions.data = someData;
  3992. * $scope.gridApi.grid.modifyRows($scope.gridOptions.data);
  3993. * $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
  3994. *
  3995. * OR to persist row selection after data update (e.g. rows selected, new data loaded, want
  3996. * originally selected rows to be re-selected))
  3997. */
  3998. Grid.prototype.modifyRows = function modifyRows(newRawData) {
  3999. var self = this;
  4000. var oldRows = self.rows.slice(0);
  4001. var oldRowHash = self.rowHashMap || self.createRowHashMap();
  4002. self.rowHashMap = self.createRowHashMap();
  4003. self.rows.length = 0;
  4004. newRawData.forEach( function( newEntity, i ) {
  4005. var newRow;
  4006. if ( self.options.enableRowHashing ){
  4007. // if hashing is enabled, then this row will be in the hash if we already know about it
  4008. newRow = oldRowHash.get( newEntity );
  4009. } else {
  4010. // otherwise, manually search the oldRows to see if we can find this row
  4011. newRow = self.getRow(newEntity, oldRows);
  4012. }
  4013. // if we didn't find the row, it must be new, so create it
  4014. if ( !newRow ){
  4015. newRow = self.processRowBuilders(new GridRow(newEntity, i, self));
  4016. }
  4017. self.rows.push( newRow );
  4018. self.rowHashMap.put( newEntity, newRow );
  4019. });
  4020. self.assignTypes();
  4021. var p1 = $q.when(self.processRowsProcessors(self.rows))
  4022. .then(function (renderableRows) {
  4023. return self.setVisibleRows(renderableRows);
  4024. });
  4025. var p2 = $q.when(self.processColumnsProcessors(self.columns))
  4026. .then(function (renderableColumns) {
  4027. return self.setVisibleColumns(renderableColumns);
  4028. });
  4029. return $q.all([p1, p2]);
  4030. };
  4031. /**
  4032. * Private Undocumented Method
  4033. * @name addRows
  4034. * @methodOf ui.grid.class:Grid
  4035. * @description adds the newRawData array of rows to the grid and calls all registered
  4036. * rowBuilders. this keyword will reference the grid
  4037. */
  4038. Grid.prototype.addRows = function addRows(newRawData) {
  4039. var self = this;
  4040. var existingRowCount = self.rows.length;
  4041. for (var i = 0; i < newRawData.length; i++) {
  4042. var newRow = self.processRowBuilders(new GridRow(newRawData[i], i + existingRowCount, self));
  4043. if (self.options.enableRowHashing) {
  4044. var found = self.rowHashMap.get(newRow.entity);
  4045. if (found) {
  4046. found.row = newRow;
  4047. }
  4048. }
  4049. self.rows.push(newRow);
  4050. }
  4051. };
  4052. /**
  4053. * @ngdoc function
  4054. * @name processRowBuilders
  4055. * @methodOf ui.grid.class:Grid
  4056. * @description processes all RowBuilders for the gridRow
  4057. * @param {GridRow} gridRow reference to gridRow
  4058. * @returns {GridRow} the gridRow with all additional behavior added
  4059. */
  4060. Grid.prototype.processRowBuilders = function processRowBuilders(gridRow) {
  4061. var self = this;
  4062. self.rowBuilders.forEach(function (builder) {
  4063. builder.call(self, gridRow, self.options);
  4064. });
  4065. return gridRow;
  4066. };
  4067. /**
  4068. * @ngdoc function
  4069. * @name registerStyleComputation
  4070. * @methodOf ui.grid.class:Grid
  4071. * @description registered a styleComputation function
  4072. *
  4073. * If the function returns a value it will be appended into the grid's `<style>` block
  4074. * @param {function($scope)} styleComputation function
  4075. */
  4076. Grid.prototype.registerStyleComputation = function registerStyleComputation(styleComputationInfo) {
  4077. this.styleComputations.push(styleComputationInfo);
  4078. };
  4079. // NOTE (c0bra): We already have rowBuilders. I think these do exactly the same thing...
  4080. // Grid.prototype.registerRowFilter = function(filter) {
  4081. // // TODO(c0bra): validate filter?
  4082. // this.rowFilters.push(filter);
  4083. // };
  4084. // Grid.prototype.removeRowFilter = function(filter) {
  4085. // var idx = this.rowFilters.indexOf(filter);
  4086. // if (typeof(idx) !== 'undefined' && idx !== undefined) {
  4087. // this.rowFilters.slice(idx, 1);
  4088. // }
  4089. // };
  4090. // Grid.prototype.processRowFilters = function(rows) {
  4091. // var self = this;
  4092. // self.rowFilters.forEach(function (filter) {
  4093. // filter.call(self, rows);
  4094. // });
  4095. // };
  4096. /**
  4097. * @ngdoc function
  4098. * @name registerRowsProcessor
  4099. * @methodOf ui.grid.class:Grid
  4100. * @description
  4101. *
  4102. * Register a "rows processor" function. When the rows are updated,
  4103. * the grid calls each registered "rows processor", which has a chance
  4104. * to alter the set of rows (sorting, etc) as long as the count is not
  4105. * modified.
  4106. *
  4107. * @param {function(renderedRowsToProcess, columns )} processorFunction rows processor function, which
  4108. * is run in the context of the grid (i.e. this for the function will be the grid), and must
  4109. * return the updated rows list, which is passed to the next processor in the chain
  4110. * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room
  4111. * for other people to inject rows processors at intermediate priorities. Lower priority rowsProcessors run earlier.
  4112. *
  4113. * At present all rows visible is running at 50, filter is running at 100, sort is at 200, grouping at 400, selectable rows at 500, pagination at 900 (pagination will generally want to be last)
  4114. *
  4115. */
  4116. Grid.prototype.registerRowsProcessor = function registerRowsProcessor(processor, priority) {
  4117. if (!angular.isFunction(processor)) {
  4118. throw 'Attempt to register non-function rows processor: ' + processor;
  4119. }
  4120. this.rowsProcessors.push({processor: processor, priority: priority});
  4121. this.rowsProcessors.sort(function sortByPriority( a, b ){
  4122. return a.priority - b.priority;
  4123. });
  4124. };
  4125. /**
  4126. * @ngdoc function
  4127. * @name removeRowsProcessor
  4128. * @methodOf ui.grid.class:Grid
  4129. * @param {function(renderableRows)} rows processor function
  4130. * @description Remove a registered rows processor
  4131. */
  4132. Grid.prototype.removeRowsProcessor = function removeRowsProcessor(processor) {
  4133. var idx = -1;
  4134. this.rowsProcessors.forEach(function(rowsProcessor, index){
  4135. if ( rowsProcessor.processor === processor ){
  4136. idx = index;
  4137. }
  4138. });
  4139. if ( idx !== -1 ) {
  4140. this.rowsProcessors.splice(idx, 1);
  4141. }
  4142. };
  4143. /**
  4144. * Private Undocumented Method
  4145. * @name processRowsProcessors
  4146. * @methodOf ui.grid.class:Grid
  4147. * @param {Array[GridRow]} The array of "renderable" rows
  4148. * @param {Array[GridColumn]} The array of columns
  4149. * @description Run all the registered rows processors on the array of renderable rows
  4150. */
  4151. Grid.prototype.processRowsProcessors = function processRowsProcessors(renderableRows) {
  4152. var self = this;
  4153. // Create a shallow copy of the rows so that we can safely sort them without altering the original grid.rows sort order
  4154. var myRenderableRows = renderableRows.slice(0);
  4155. // Return myRenderableRows with no processing if we have no rows processors
  4156. if (self.rowsProcessors.length === 0) {
  4157. return $q.when(myRenderableRows);
  4158. }
  4159. // Counter for iterating through rows processors
  4160. var i = 0;
  4161. // Promise for when we're done with all the processors
  4162. var finished = $q.defer();
  4163. // This function will call the processor in self.rowsProcessors at index 'i', and then
  4164. // when done will call the next processor in the list, using the output from the processor
  4165. // at i as the argument for 'renderedRowsToProcess' on the next iteration.
  4166. //
  4167. // If we're at the end of the list of processors, we resolve our 'finished' callback with
  4168. // the result.
  4169. function startProcessor(i, renderedRowsToProcess) {
  4170. // Get the processor at 'i'
  4171. var processor = self.rowsProcessors[i].processor;
  4172. // Call the processor, passing in the rows to process and the current columns
  4173. // (note: it's wrapped in $q.when() in case the processor does not return a promise)
  4174. return $q.when( processor.call(self, renderedRowsToProcess, self.columns) )
  4175. .then(function handleProcessedRows(processedRows) {
  4176. // Check for errors
  4177. if (!processedRows) {
  4178. throw "Processor at index " + i + " did not return a set of renderable rows";
  4179. }
  4180. if (!angular.isArray(processedRows)) {
  4181. throw "Processor at index " + i + " did not return an array";
  4182. }
  4183. // Processor is done, increment the counter
  4184. i++;
  4185. // If we're not done with the processors, call the next one
  4186. if (i <= self.rowsProcessors.length - 1) {
  4187. return startProcessor(i, processedRows);
  4188. }
  4189. // We're done! Resolve the 'finished' promise
  4190. else {
  4191. finished.resolve(processedRows);
  4192. }
  4193. });
  4194. }
  4195. // Start on the first processor
  4196. startProcessor(0, myRenderableRows);
  4197. return finished.promise;
  4198. };
  4199. Grid.prototype.setVisibleRows = function setVisibleRows(rows) {
  4200. var self = this;
  4201. // Reset all the render container row caches
  4202. for (var i in self.renderContainers) {
  4203. var container = self.renderContainers[i];
  4204. container.canvasHeightShouldUpdate = true;
  4205. if ( typeof(container.visibleRowCache) === 'undefined' ){
  4206. container.visibleRowCache = [];
  4207. } else {
  4208. container.visibleRowCache.length = 0;
  4209. }
  4210. }
  4211. // rows.forEach(function (row) {
  4212. for (var ri = 0; ri < rows.length; ri++) {
  4213. var row = rows[ri];
  4214. var targetContainer = (typeof(row.renderContainer) !== 'undefined' && row.renderContainer) ? row.renderContainer : 'body';
  4215. // If the row is visible
  4216. if (row.visible) {
  4217. self.renderContainers[targetContainer].visibleRowCache.push(row);
  4218. }
  4219. }
  4220. self.api.core.raise.rowsRendered(this.api);
  4221. };
  4222. /**
  4223. * @ngdoc function
  4224. * @name registerColumnsProcessor
  4225. * @methodOf ui.grid.class:Grid
  4226. * @param {function(renderedColumnsToProcess, rows)} columnProcessor column processor function, which
  4227. * is run in the context of the grid (i.e. this for the function will be the grid), and
  4228. * which must return an updated renderedColumnsToProcess which can be passed to the next processor
  4229. * in the chain
  4230. * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room
  4231. * for other people to inject columns processors at intermediate priorities. Lower priority columnsProcessors run earlier.
  4232. *
  4233. * At present all rows visible is running at 50, filter is running at 100, sort is at 200, grouping at 400, selectable rows at 500, pagination at 900 (pagination will generally want to be last)
  4234. * @description
  4235. Register a "columns processor" function. When the columns are updated,
  4236. the grid calls each registered "columns processor", which has a chance
  4237. to alter the set of columns, as long as the count is not modified.
  4238. */
  4239. Grid.prototype.registerColumnsProcessor = function registerColumnsProcessor(processor, priority) {
  4240. if (!angular.isFunction(processor)) {
  4241. throw 'Attempt to register non-function rows processor: ' + processor;
  4242. }
  4243. this.columnsProcessors.push({processor: processor, priority: priority});
  4244. this.columnsProcessors.sort(function sortByPriority( a, b ){
  4245. return a.priority - b.priority;
  4246. });
  4247. };
  4248. Grid.prototype.removeColumnsProcessor = function removeColumnsProcessor(processor) {
  4249. var idx = this.columnsProcessors.indexOf(processor);
  4250. if (typeof(idx) !== 'undefined' && idx !== undefined) {
  4251. this.columnsProcessors.splice(idx, 1);
  4252. }
  4253. };
  4254. Grid.prototype.processColumnsProcessors = function processColumnsProcessors(renderableColumns) {
  4255. var self = this;
  4256. // Create a shallow copy of the rows so that we can safely sort them without altering the original grid.rows sort order
  4257. var myRenderableColumns = renderableColumns.slice(0);
  4258. // Return myRenderableRows with no processing if we have no rows processors
  4259. if (self.columnsProcessors.length === 0) {
  4260. return $q.when(myRenderableColumns);
  4261. }
  4262. // Counter for iterating through rows processors
  4263. var i = 0;
  4264. // Promise for when we're done with all the processors
  4265. var finished = $q.defer();
  4266. // This function will call the processor in self.rowsProcessors at index 'i', and then
  4267. // when done will call the next processor in the list, using the output from the processor
  4268. // at i as the argument for 'renderedRowsToProcess' on the next iteration.
  4269. //
  4270. // If we're at the end of the list of processors, we resolve our 'finished' callback with
  4271. // the result.
  4272. function startProcessor(i, renderedColumnsToProcess) {
  4273. // Get the processor at 'i'
  4274. var processor = self.columnsProcessors[i].processor;
  4275. // Call the processor, passing in the rows to process and the current columns
  4276. // (note: it's wrapped in $q.when() in case the processor does not return a promise)
  4277. return $q.when( processor.call(self, renderedColumnsToProcess, self.rows) )
  4278. .then(function handleProcessedRows(processedColumns) {
  4279. // Check for errors
  4280. if (!processedColumns) {
  4281. throw "Processor at index " + i + " did not return a set of renderable rows";
  4282. }
  4283. if (!angular.isArray(processedColumns)) {
  4284. throw "Processor at index " + i + " did not return an array";
  4285. }
  4286. // Processor is done, increment the counter
  4287. i++;
  4288. // If we're not done with the processors, call the next one
  4289. if (i <= self.columnsProcessors.length - 1) {
  4290. return startProcessor(i, myRenderableColumns);
  4291. }
  4292. // We're done! Resolve the 'finished' promise
  4293. else {
  4294. finished.resolve(myRenderableColumns);
  4295. }
  4296. });
  4297. }
  4298. // Start on the first processor
  4299. startProcessor(0, myRenderableColumns);
  4300. return finished.promise;
  4301. };
  4302. Grid.prototype.setVisibleColumns = function setVisibleColumns(columns) {
  4303. // gridUtil.logDebug('setVisibleColumns');
  4304. var self = this;
  4305. // Reset all the render container row caches
  4306. for (var i in self.renderContainers) {
  4307. var container = self.renderContainers[i];
  4308. container.visibleColumnCache.length = 0;
  4309. }
  4310. for (var ci = 0; ci < columns.length; ci++) {
  4311. var column = columns[ci];
  4312. // If the column is visible
  4313. if (column.visible) {
  4314. // If the column has a container specified
  4315. if (typeof(column.renderContainer) !== 'undefined' && column.renderContainer) {
  4316. self.renderContainers[column.renderContainer].visibleColumnCache.push(column);
  4317. }
  4318. // If not, put it into the body container
  4319. else {
  4320. self.renderContainers.body.visibleColumnCache.push(column);
  4321. }
  4322. }
  4323. }
  4324. };
  4325. /**
  4326. * @ngdoc function
  4327. * @name handleWindowResize
  4328. * @methodOf ui.grid.class:Grid
  4329. * @description Triggered when the browser window resizes; automatically resizes the grid
  4330. * @returns {Promise} A resolved promise once the window resize has completed.
  4331. */
  4332. Grid.prototype.handleWindowResize = function handleWindowResize($event) {
  4333. var self = this;
  4334. self.gridWidth = gridUtil.elementWidth(self.element);
  4335. self.gridHeight = gridUtil.elementHeight(self.element);
  4336. return self.queueRefresh();
  4337. };
  4338. /**
  4339. * @ngdoc function
  4340. * @name queueRefresh
  4341. * @methodOf ui.grid.class:Grid
  4342. * @description queues a grid refreshCanvas, a way of debouncing all the refreshes we might otherwise issue
  4343. */
  4344. Grid.prototype.queueRefresh = function queueRefresh() {
  4345. var self = this;
  4346. if (self.refreshCanceller) {
  4347. $timeout.cancel(self.refreshCanceller);
  4348. }
  4349. self.refreshCanceller = $timeout(function () {
  4350. self.refreshCanvas(true);
  4351. });
  4352. self.refreshCanceller.then(function () {
  4353. self.refreshCanceller = null;
  4354. });
  4355. return self.refreshCanceller;
  4356. };
  4357. /**
  4358. * @ngdoc function
  4359. * @name queueGridRefresh
  4360. * @methodOf ui.grid.class:Grid
  4361. * @description queues a grid refresh, a way of debouncing all the refreshes we might otherwise issue
  4362. */
  4363. Grid.prototype.queueGridRefresh = function queueGridRefresh() {
  4364. var self = this;
  4365. if (self.gridRefreshCanceller) {
  4366. $timeout.cancel(self.gridRefreshCanceller);
  4367. }
  4368. self.gridRefreshCanceller = $timeout(function () {
  4369. self.refresh(true);
  4370. });
  4371. self.gridRefreshCanceller.then(function () {
  4372. self.gridRefreshCanceller = null;
  4373. });
  4374. return self.gridRefreshCanceller;
  4375. };
  4376. /**
  4377. * @ngdoc function
  4378. * @name updateCanvasHeight
  4379. * @methodOf ui.grid.class:Grid
  4380. * @description flags all render containers to update their canvas height
  4381. */
  4382. Grid.prototype.updateCanvasHeight = function updateCanvasHeight() {
  4383. var self = this;
  4384. for (var containerId in self.renderContainers) {
  4385. if (self.renderContainers.hasOwnProperty(containerId)) {
  4386. var container = self.renderContainers[containerId];
  4387. container.canvasHeightShouldUpdate = true;
  4388. }
  4389. }
  4390. };
  4391. /**
  4392. * @ngdoc function
  4393. * @name buildStyles
  4394. * @methodOf ui.grid.class:Grid
  4395. * @description calls each styleComputation function
  4396. */
  4397. // TODO: this used to take $scope, but couldn't see that it was used
  4398. Grid.prototype.buildStyles = function buildStyles() {
  4399. // gridUtil.logDebug('buildStyles');
  4400. var self = this;
  4401. self.customStyles = '';
  4402. self.styleComputations
  4403. .sort(function(a, b) {
  4404. if (a.priority === null) { return 1; }
  4405. if (b.priority === null) { return -1; }
  4406. if (a.priority === null && b.priority === null) { return 0; }
  4407. return a.priority - b.priority;
  4408. })
  4409. .forEach(function (compInfo) {
  4410. // this used to provide $scope as a second parameter, but I couldn't find any
  4411. // style builders that used it, so removed it as part of moving to grid from controller
  4412. var ret = compInfo.func.call(self);
  4413. if (angular.isString(ret)) {
  4414. self.customStyles += '\n' + ret;
  4415. }
  4416. });
  4417. };
  4418. Grid.prototype.minColumnsToRender = function minColumnsToRender() {
  4419. var self = this;
  4420. var viewport = this.getViewportWidth();
  4421. var min = 0;
  4422. var totalWidth = 0;
  4423. self.columns.forEach(function(col, i) {
  4424. if (totalWidth < viewport) {
  4425. totalWidth += col.drawnWidth;
  4426. min++;
  4427. }
  4428. else {
  4429. var currWidth = 0;
  4430. for (var j = i; j >= i - min; j--) {
  4431. currWidth += self.columns[j].drawnWidth;
  4432. }
  4433. if (currWidth < viewport) {
  4434. min++;
  4435. }
  4436. }
  4437. });
  4438. return min;
  4439. };
  4440. Grid.prototype.getBodyHeight = function getBodyHeight() {
  4441. // Start with the viewportHeight
  4442. var bodyHeight = this.getViewportHeight();
  4443. // Add the horizontal scrollbar height if there is one
  4444. //if (typeof(this.horizontalScrollbarHeight) !== 'undefined' && this.horizontalScrollbarHeight !== undefined && this.horizontalScrollbarHeight > 0) {
  4445. // bodyHeight = bodyHeight + this.horizontalScrollbarHeight;
  4446. //}
  4447. return bodyHeight;
  4448. };
  4449. // NOTE: viewport drawable height is the height of the grid minus the header row height (including any border)
  4450. // TODO(c0bra): account for footer height
  4451. Grid.prototype.getViewportHeight = function getViewportHeight() {
  4452. var self = this;
  4453. var viewPortHeight = this.gridHeight - this.headerHeight - this.footerHeight;
  4454. // Account for native horizontal scrollbar, if present
  4455. //if (typeof(this.horizontalScrollbarHeight) !== 'undefined' && this.horizontalScrollbarHeight !== undefined && this.horizontalScrollbarHeight > 0) {
  4456. // viewPortHeight = viewPortHeight - this.horizontalScrollbarHeight;
  4457. //}
  4458. var adjustment = self.getViewportAdjustment();
  4459. viewPortHeight = viewPortHeight + adjustment.height;
  4460. //gridUtil.logDebug('viewPortHeight', viewPortHeight);
  4461. return viewPortHeight;
  4462. };
  4463. Grid.prototype.getViewportWidth = function getViewportWidth() {
  4464. var self = this;
  4465. var viewPortWidth = this.gridWidth;
  4466. //if (typeof(this.verticalScrollbarWidth) !== 'undefined' && this.verticalScrollbarWidth !== undefined && this.verticalScrollbarWidth > 0) {
  4467. // viewPortWidth = viewPortWidth - this.verticalScrollbarWidth;
  4468. //}
  4469. var adjustment = self.getViewportAdjustment();
  4470. viewPortWidth = viewPortWidth + adjustment.width;
  4471. //gridUtil.logDebug('getviewPortWidth', viewPortWidth);
  4472. return viewPortWidth;
  4473. };
  4474. Grid.prototype.getHeaderViewportWidth = function getHeaderViewportWidth() {
  4475. var viewPortWidth = this.getViewportWidth();
  4476. //if (typeof(this.verticalScrollbarWidth) !== 'undefined' && this.verticalScrollbarWidth !== undefined && this.verticalScrollbarWidth > 0) {
  4477. // viewPortWidth = viewPortWidth + this.verticalScrollbarWidth;
  4478. //}
  4479. return viewPortWidth;
  4480. };
  4481. Grid.prototype.addVerticalScrollSync = function (containerId, callBackFn) {
  4482. this.verticalScrollSyncCallBackFns[containerId] = callBackFn;
  4483. };
  4484. Grid.prototype.addHorizontalScrollSync = function (containerId, callBackFn) {
  4485. this.horizontalScrollSyncCallBackFns[containerId] = callBackFn;
  4486. };
  4487. /**
  4488. * Scroll needed containers by calling their ScrollSyncs
  4489. * @param sourceContainerId the containerId that has already set it's top/left.
  4490. * can be empty string which means all containers need to set top/left
  4491. * @param scrollEvent
  4492. */
  4493. Grid.prototype.scrollContainers = function (sourceContainerId, scrollEvent) {
  4494. if (scrollEvent.y) {
  4495. //default for no container Id (ex. mousewheel means that all containers must set scrollTop/Left)
  4496. var verts = ['body','left', 'right'];
  4497. this.flagScrollingVertically(scrollEvent);
  4498. if (sourceContainerId === 'body') {
  4499. verts = ['left', 'right'];
  4500. }
  4501. else if (sourceContainerId === 'left') {
  4502. verts = ['body', 'right'];
  4503. }
  4504. else if (sourceContainerId === 'right') {
  4505. verts = ['body', 'left'];
  4506. }
  4507. for (var i = 0; i < verts.length; i++) {
  4508. var id = verts[i];
  4509. if (this.verticalScrollSyncCallBackFns[id]) {
  4510. this.verticalScrollSyncCallBackFns[id](scrollEvent);
  4511. }
  4512. }
  4513. }
  4514. if (scrollEvent.x) {
  4515. //default for no container Id (ex. mousewheel means that all containers must set scrollTop/Left)
  4516. var horizs = ['body','bodyheader', 'bodyfooter'];
  4517. this.flagScrollingHorizontally(scrollEvent);
  4518. if (sourceContainerId === 'body') {
  4519. horizs = ['bodyheader', 'bodyfooter'];
  4520. }
  4521. for (var j = 0; j < horizs.length; j++) {
  4522. var idh = horizs[j];
  4523. if (this.horizontalScrollSyncCallBackFns[idh]) {
  4524. this.horizontalScrollSyncCallBackFns[idh](scrollEvent);
  4525. }
  4526. }
  4527. }
  4528. };
  4529. Grid.prototype.registerViewportAdjuster = function registerViewportAdjuster(func) {
  4530. this.viewportAdjusters.push(func);
  4531. };
  4532. Grid.prototype.removeViewportAdjuster = function registerViewportAdjuster(func) {
  4533. var idx = this.viewportAdjusters.indexOf(func);
  4534. if (typeof(idx) !== 'undefined' && idx !== undefined) {
  4535. this.viewportAdjusters.splice(idx, 1);
  4536. }
  4537. };
  4538. Grid.prototype.getViewportAdjustment = function getViewportAdjustment() {
  4539. var self = this;
  4540. var adjustment = { height: 0, width: 0 };
  4541. self.viewportAdjusters.forEach(function (func) {
  4542. adjustment = func.call(this, adjustment);
  4543. });
  4544. return adjustment;
  4545. };
  4546. Grid.prototype.getVisibleRowCount = function getVisibleRowCount() {
  4547. // var count = 0;
  4548. // this.rows.forEach(function (row) {
  4549. // if (row.visible) {
  4550. // count++;
  4551. // }
  4552. // });
  4553. // return this.visibleRowCache.length;
  4554. return this.renderContainers.body.visibleRowCache.length;
  4555. };
  4556. Grid.prototype.getVisibleRows = function getVisibleRows() {
  4557. return this.renderContainers.body.visibleRowCache;
  4558. };
  4559. Grid.prototype.getVisibleColumnCount = function getVisibleColumnCount() {
  4560. // var count = 0;
  4561. // this.rows.forEach(function (row) {
  4562. // if (row.visible) {
  4563. // count++;
  4564. // }
  4565. // });
  4566. // return this.visibleRowCache.length;
  4567. return this.renderContainers.body.visibleColumnCache.length;
  4568. };
  4569. Grid.prototype.searchRows = function searchRows(renderableRows) {
  4570. return rowSearcher.search(this, renderableRows, this.columns);
  4571. };
  4572. Grid.prototype.sortByColumn = function sortByColumn(renderableRows) {
  4573. return rowSorter.sort(this, renderableRows, this.columns);
  4574. };
  4575. /**
  4576. * @ngdoc function
  4577. * @name getCellValue
  4578. * @methodOf ui.grid.class:Grid
  4579. * @description Gets the value of a cell for a particular row and column
  4580. * @param {GridRow} row Row to access
  4581. * @param {GridColumn} col Column to access
  4582. */
  4583. Grid.prototype.getCellValue = function getCellValue(row, col){
  4584. if ( typeof(row.entity[ '$$' + col.uid ]) !== 'undefined' ) {
  4585. return row.entity[ '$$' + col.uid].rendered;
  4586. } else if (this.options.flatEntityAccess && typeof(col.field) !== 'undefined' ){
  4587. return row.entity[col.field];
  4588. } else {
  4589. if (!col.cellValueGetterCache) {
  4590. col.cellValueGetterCache = $parse(row.getEntityQualifiedColField(col));
  4591. }
  4592. return col.cellValueGetterCache(row);
  4593. }
  4594. };
  4595. /**
  4596. * @ngdoc function
  4597. * @name getCellDisplayValue
  4598. * @methodOf ui.grid.class:Grid
  4599. * @description Gets the displayed value of a cell after applying any the `cellFilter`
  4600. * @param {GridRow} row Row to access
  4601. * @param {GridColumn} col Column to access
  4602. */
  4603. Grid.prototype.getCellDisplayValue = function getCellDisplayValue(row, col) {
  4604. if ( !col.cellDisplayGetterCache ) {
  4605. var custom_filter = col.cellFilter ? " | " + col.cellFilter : "";
  4606. if (typeof(row.entity['$$' + col.uid]) !== 'undefined') {
  4607. col.cellDisplayGetterCache = $parse(row.entity['$$' + col.uid].rendered + custom_filter);
  4608. } else if (this.options.flatEntityAccess && typeof(col.field) !== 'undefined') {
  4609. col.cellDisplayGetterCache = $parse(row.entity[col.field] + custom_filter);
  4610. } else {
  4611. col.cellDisplayGetterCache = $parse(row.getEntityQualifiedColField(col) + custom_filter);
  4612. }
  4613. }
  4614. return col.cellDisplayGetterCache(row);
  4615. };
  4616. Grid.prototype.getNextColumnSortPriority = function getNextColumnSortPriority() {
  4617. var self = this,
  4618. p = 0;
  4619. self.columns.forEach(function (col) {
  4620. if (col.sort && col.sort.priority !== undefined && col.sort.priority >= p) {
  4621. p = col.sort.priority + 1;
  4622. }
  4623. });
  4624. return p;
  4625. };
  4626. /**
  4627. * @ngdoc function
  4628. * @name resetColumnSorting
  4629. * @methodOf ui.grid.class:Grid
  4630. * @description Return the columns that the grid is currently being sorted by
  4631. * @param {GridColumn} [excludedColumn] Optional GridColumn to exclude from having its sorting reset
  4632. */
  4633. Grid.prototype.resetColumnSorting = function resetColumnSorting(excludeCol) {
  4634. var self = this;
  4635. self.columns.forEach(function (col) {
  4636. if (col !== excludeCol && !col.suppressRemoveSort) {
  4637. col.sort = {};
  4638. }
  4639. });
  4640. };
  4641. /**
  4642. * @ngdoc function
  4643. * @name getColumnSorting
  4644. * @methodOf ui.grid.class:Grid
  4645. * @description Return the columns that the grid is currently being sorted by
  4646. * @returns {Array[GridColumn]} An array of GridColumn objects
  4647. */
  4648. Grid.prototype.getColumnSorting = function getColumnSorting() {
  4649. var self = this;
  4650. var sortedCols = [], myCols;
  4651. // Iterate through all the columns, sorted by priority
  4652. // Make local copy of column list, because sorting is in-place and we do not want to
  4653. // change the original sequence of columns
  4654. myCols = self.columns.slice(0);
  4655. myCols.sort(rowSorter.prioritySort).forEach(function (col) {
  4656. if (col.sort && typeof(col.sort.direction) !== 'undefined' && col.sort.direction && (col.sort.direction === uiGridConstants.ASC || col.sort.direction === uiGridConstants.DESC)) {
  4657. sortedCols.push(col);
  4658. }
  4659. });
  4660. return sortedCols;
  4661. };
  4662. /**
  4663. * @ngdoc function
  4664. * @name sortColumn
  4665. * @methodOf ui.grid.class:Grid
  4666. * @description Set the sorting on a given column, optionally resetting any existing sorting on the Grid.
  4667. * Emits the sortChanged event whenever the sort criteria are changed.
  4668. * @param {GridColumn} column Column to set the sorting on
  4669. * @param {uiGridConstants.ASC|uiGridConstants.DESC} [direction] Direction to sort by, either descending or ascending.
  4670. * If not provided, the column will iterate through the sort directions
  4671. * specified in the {@link ui.grid.class:GridOptions.columnDef#sortDirectionCycle sortDirectionCycle} attribute.
  4672. * @param {boolean} [add] Add this column to the sorting. If not provided or set to `false`, the Grid will reset any existing sorting and sort
  4673. * by this column only
  4674. * @returns {Promise} A resolved promise that supplies the column.
  4675. */
  4676. Grid.prototype.sortColumn = function sortColumn(column, directionOrAdd, add) {
  4677. var self = this,
  4678. direction = null;
  4679. if (typeof(column) === 'undefined' || !column) {
  4680. throw new Error('No column parameter provided');
  4681. }
  4682. // Second argument can either be a direction or whether to add this column to the existing sort.
  4683. // If it's a boolean, it's an add, otherwise, it's a direction
  4684. if (typeof(directionOrAdd) === 'boolean') {
  4685. add = directionOrAdd;
  4686. }
  4687. else {
  4688. direction = directionOrAdd;
  4689. }
  4690. if (!add) {
  4691. self.resetColumnSorting(column);
  4692. column.sort.priority = undefined;
  4693. // Get the actual priority since there may be columns which have suppressRemoveSort set
  4694. column.sort.priority = self.getNextColumnSortPriority();
  4695. }
  4696. else if (!column.sort.priority){
  4697. column.sort.priority = self.getNextColumnSortPriority();
  4698. }
  4699. if (!direction) {
  4700. // Find the current position in the cycle (or -1).
  4701. var i = column.sortDirectionCycle.indexOf(column.sort.direction ? column.sort.direction : null);
  4702. // Proceed to the next position in the cycle (or start at the beginning).
  4703. i = (i+1) % column.sortDirectionCycle.length;
  4704. // If suppressRemoveSort is set, and the next position in the cycle would
  4705. // remove the sort, skip it.
  4706. if (column.colDef && column.suppressRemoveSort && !column.sortDirectionCycle[i]) {
  4707. i = (i+1) % column.sortDirectionCycle.length;
  4708. }
  4709. if (column.sortDirectionCycle[i]) {
  4710. column.sort.direction = column.sortDirectionCycle[i];
  4711. } else {
  4712. column.sort = {};
  4713. }
  4714. }
  4715. else {
  4716. column.sort.direction = direction;
  4717. }
  4718. self.api.core.raise.sortChanged( self, self.getColumnSorting() );
  4719. return $q.when(column);
  4720. };
  4721. /**
  4722. * communicate to outside world that we are done with initial rendering
  4723. */
  4724. Grid.prototype.renderingComplete = function(){
  4725. if (angular.isFunction(this.options.onRegisterApi)) {
  4726. this.options.onRegisterApi(this.api);
  4727. }
  4728. this.api.core.raise.renderingComplete( this.api );
  4729. };
  4730. Grid.prototype.createRowHashMap = function createRowHashMap() {
  4731. var self = this;
  4732. var hashMap = new RowHashMap();
  4733. hashMap.grid = self;
  4734. return hashMap;
  4735. };
  4736. /**
  4737. * @ngdoc function
  4738. * @name refresh
  4739. * @methodOf ui.grid.class:Grid
  4740. * @description Refresh the rendered grid on screen.
  4741. * @param {boolean} [rowsAltered] Optional flag for refreshing when the number of rows has changed.
  4742. */
  4743. Grid.prototype.refresh = function refresh(rowsAltered) {
  4744. var self = this;
  4745. var p1 = self.processRowsProcessors(self.rows).then(function (renderableRows) {
  4746. self.setVisibleRows(renderableRows);
  4747. });
  4748. var p2 = self.processColumnsProcessors(self.columns).then(function (renderableColumns) {
  4749. self.setVisibleColumns(renderableColumns);
  4750. });
  4751. return $q.all([p1, p2]).then(function () {
  4752. self.redrawInPlace(rowsAltered);
  4753. self.refreshCanvas(true);
  4754. });
  4755. };
  4756. /**
  4757. * @ngdoc function
  4758. * @name refreshRows
  4759. * @methodOf ui.grid.class:Grid
  4760. * @description Refresh the rendered rows on screen? Note: not functional at present
  4761. * @returns {promise} promise that is resolved when render completes?
  4762. *
  4763. */
  4764. Grid.prototype.refreshRows = function refreshRows() {
  4765. var self = this;
  4766. return self.processRowsProcessors(self.rows)
  4767. .then(function (renderableRows) {
  4768. self.setVisibleRows(renderableRows);
  4769. self.redrawInPlace();
  4770. self.refreshCanvas( true );
  4771. });
  4772. };
  4773. /**
  4774. * @ngdoc function
  4775. * @name refreshCanvas
  4776. * @methodOf ui.grid.class:Grid
  4777. * @description Builds all styles and recalculates much of the grid sizing
  4778. * @param {object} buildStyles optional parameter. Use TBD
  4779. * @returns {promise} promise that is resolved when the canvas
  4780. * has been refreshed
  4781. *
  4782. */
  4783. Grid.prototype.refreshCanvas = function(buildStyles) {
  4784. var self = this;
  4785. if (buildStyles) {
  4786. self.buildStyles();
  4787. }
  4788. var p = $q.defer();
  4789. // Get all the header heights
  4790. var containerHeadersToRecalc = [];
  4791. for (var containerId in self.renderContainers) {
  4792. if (self.renderContainers.hasOwnProperty(containerId)) {
  4793. var container = self.renderContainers[containerId];
  4794. // Skip containers that have no canvasWidth set yet
  4795. if (container.canvasWidth === null || isNaN(container.canvasWidth)) {
  4796. continue;
  4797. }
  4798. if (container.header || container.headerCanvas) {
  4799. container.explicitHeaderHeight = container.explicitHeaderHeight || null;
  4800. container.explicitHeaderCanvasHeight = container.explicitHeaderCanvasHeight || null;
  4801. containerHeadersToRecalc.push(container);
  4802. }
  4803. }
  4804. }
  4805. /*
  4806. *
  4807. * Here we loop through the headers, measuring each element as well as any header "canvas" it has within it.
  4808. *
  4809. * If any header is less than the largest header height, it will be resized to that so that we don't have headers
  4810. * with different heights, which looks like a rendering problem
  4811. *
  4812. * We'll do the same thing with the header canvases, and give the header CELLS an explicit height if their canvas
  4813. * is smaller than the largest canvas height. That was header cells without extra controls like filtering don't
  4814. * appear shorter than other cells.
  4815. *
  4816. */
  4817. if (containerHeadersToRecalc.length > 0) {
  4818. // Build the styles without the explicit header heights
  4819. if (buildStyles) {
  4820. self.buildStyles();
  4821. }
  4822. // Putting in a timeout as it's not calculating after the grid element is rendered and filled out
  4823. $timeout(function() {
  4824. // var oldHeaderHeight = self.grid.headerHeight;
  4825. // self.grid.headerHeight = gridUtil.outerElementHeight(self.header);
  4826. var rebuildStyles = false;
  4827. // Get all the header heights
  4828. var maxHeaderHeight = 0;
  4829. var maxHeaderCanvasHeight = 0;
  4830. var i, container;
  4831. var getHeight = function(oldVal, newVal){
  4832. if ( oldVal !== newVal){
  4833. rebuildStyles = true;
  4834. }
  4835. return newVal;
  4836. };
  4837. for (i = 0; i < containerHeadersToRecalc.length; i++) {
  4838. container = containerHeadersToRecalc[i];
  4839. // Skip containers that have no canvasWidth set yet
  4840. if (container.canvasWidth === null || isNaN(container.canvasWidth)) {
  4841. continue;
  4842. }
  4843. if (container.header) {
  4844. var headerHeight = container.headerHeight = getHeight(container.headerHeight, parseInt(gridUtil.outerElementHeight(container.header), 10));
  4845. // Get the "inner" header height, that is the height minus the top and bottom borders, if present. We'll use it to make sure all the headers have a consistent height
  4846. var topBorder = gridUtil.getBorderSize(container.header, 'top');
  4847. var bottomBorder = gridUtil.getBorderSize(container.header, 'bottom');
  4848. var innerHeaderHeight = parseInt(headerHeight - topBorder - bottomBorder, 10);
  4849. innerHeaderHeight = innerHeaderHeight < 0 ? 0 : innerHeaderHeight;
  4850. container.innerHeaderHeight = innerHeaderHeight;
  4851. // If the header doesn't have an explicit height set, save the largest header height for use later
  4852. // Explicit header heights are based off of the max we are calculating here. We never want to base the max on something we're setting explicitly
  4853. if (!container.explicitHeaderHeight && innerHeaderHeight > maxHeaderHeight) {
  4854. maxHeaderHeight = innerHeaderHeight;
  4855. }
  4856. }
  4857. if (container.headerCanvas) {
  4858. var headerCanvasHeight = container.headerCanvasHeight = getHeight(container.headerCanvasHeight, parseInt(gridUtil.outerElementHeight(container.headerCanvas), 10));
  4859. // If the header doesn't have an explicit canvas height, save the largest header canvas height for use later
  4860. // Explicit header heights are based off of the max we are calculating here. We never want to base the max on something we're setting explicitly
  4861. if (!container.explicitHeaderCanvasHeight && headerCanvasHeight > maxHeaderCanvasHeight) {
  4862. maxHeaderCanvasHeight = headerCanvasHeight;
  4863. }
  4864. }
  4865. }
  4866. // Go through all the headers
  4867. for (i = 0; i < containerHeadersToRecalc.length; i++) {
  4868. container = containerHeadersToRecalc[i];
  4869. /* If:
  4870. 1. We have a max header height
  4871. 2. This container has a header height defined
  4872. 3. And either this container has an explicit header height set, OR its header height is less than the max
  4873. then:
  4874. Give this container's header an explicit height so it will line up with the tallest header
  4875. */
  4876. if (
  4877. maxHeaderHeight > 0 && typeof(container.headerHeight) !== 'undefined' && container.headerHeight !== null &&
  4878. (container.explicitHeaderHeight || container.headerHeight < maxHeaderHeight)
  4879. ) {
  4880. container.explicitHeaderHeight = getHeight(container.explicitHeaderHeight, maxHeaderHeight);
  4881. }
  4882. // Do the same as above except for the header canvas
  4883. if (
  4884. maxHeaderCanvasHeight > 0 && typeof(container.headerCanvasHeight) !== 'undefined' && container.headerCanvasHeight !== null &&
  4885. (container.explicitHeaderCanvasHeight || container.headerCanvasHeight < maxHeaderCanvasHeight)
  4886. ) {
  4887. container.explicitHeaderCanvasHeight = getHeight(container.explicitHeaderCanvasHeight, maxHeaderCanvasHeight);
  4888. }
  4889. }
  4890. // Rebuild styles if the header height has changed
  4891. // The header height is used in body/viewport calculations and those are then used in other styles so we need it to be available
  4892. if (buildStyles && rebuildStyles) {
  4893. self.buildStyles();
  4894. }
  4895. p.resolve();
  4896. });
  4897. }
  4898. else {
  4899. // Timeout still needs to be here to trigger digest after styles have been rebuilt
  4900. $timeout(function() {
  4901. p.resolve();
  4902. });
  4903. }
  4904. return p.promise;
  4905. };
  4906. /**
  4907. * @ngdoc function
  4908. * @name redrawCanvas
  4909. * @methodOf ui.grid.class:Grid
  4910. * @description Redraw the rows and columns based on our current scroll position
  4911. * @param {boolean} [rowsAdded] Optional to indicate rows are added and the scroll percentage must be recalculated
  4912. *
  4913. */
  4914. Grid.prototype.redrawInPlace = function redrawInPlace(rowsAdded) {
  4915. // gridUtil.logDebug('redrawInPlace');
  4916. var self = this;
  4917. for (var i in self.renderContainers) {
  4918. var container = self.renderContainers[i];
  4919. // gridUtil.logDebug('redrawing container', i);
  4920. if (rowsAdded) {
  4921. container.adjustRows(container.prevScrollTop, null);
  4922. container.adjustColumns(container.prevScrollLeft, null);
  4923. }
  4924. else {
  4925. container.adjustRows(null, container.prevScrolltopPercentage);
  4926. container.adjustColumns(null, container.prevScrollleftPercentage);
  4927. }
  4928. }
  4929. };
  4930. /**
  4931. * @ngdoc function
  4932. * @name hasLeftContainerColumns
  4933. * @methodOf ui.grid.class:Grid
  4934. * @description returns true if leftContainer has columns
  4935. */
  4936. Grid.prototype.hasLeftContainerColumns = function () {
  4937. return this.hasLeftContainer() && this.renderContainers.left.renderedColumns.length > 0;
  4938. };
  4939. /**
  4940. * @ngdoc function
  4941. * @name hasRightContainerColumns
  4942. * @methodOf ui.grid.class:Grid
  4943. * @description returns true if rightContainer has columns
  4944. */
  4945. Grid.prototype.hasRightContainerColumns = function () {
  4946. return this.hasRightContainer() && this.renderContainers.right.renderedColumns.length > 0;
  4947. };
  4948. /**
  4949. * @ngdoc method
  4950. * @methodOf ui.grid.class:Grid
  4951. * @name scrollToIfNecessary
  4952. * @description Scrolls the grid to make a certain row and column combo visible,
  4953. * in the case that it is not completely visible on the screen already.
  4954. * @param {GridRow} gridRow row to make visible
  4955. * @param {GridCol} gridCol column to make visible
  4956. * @returns {promise} a promise that is resolved when scrolling is complete
  4957. */
  4958. Grid.prototype.scrollToIfNecessary = function (gridRow, gridCol) {
  4959. var self = this;
  4960. var scrollEvent = new ScrollEvent(self, 'uiGrid.scrollToIfNecessary');
  4961. // Alias the visible row and column caches
  4962. var visRowCache = self.renderContainers.body.visibleRowCache;
  4963. var visColCache = self.renderContainers.body.visibleColumnCache;
  4964. /*-- Get the top, left, right, and bottom "scrolled" edges of the grid --*/
  4965. // The top boundary is the current Y scroll position PLUS the header height, because the header can obscure rows when the grid is scrolled downwards
  4966. var topBound = self.renderContainers.body.prevScrollTop + self.headerHeight;
  4967. // Don't the let top boundary be less than 0
  4968. topBound = (topBound < 0) ? 0 : topBound;
  4969. // The left boundary is the current X scroll position
  4970. var leftBound = self.renderContainers.body.prevScrollLeft;
  4971. // The bottom boundary is the current Y scroll position, plus the height of the grid, but minus the header height.
  4972. // Basically this is the viewport height added on to the scroll position
  4973. var bottomBound = self.renderContainers.body.prevScrollTop + self.gridHeight - self.renderContainers.body.headerHeight - self.footerHeight - self.scrollbarWidth;
  4974. // If there's a horizontal scrollbar, remove its height from the bottom boundary, otherwise we'll be letting it obscure rows
  4975. //if (self.horizontalScrollbarHeight) {
  4976. // bottomBound = bottomBound - self.horizontalScrollbarHeight;
  4977. //}
  4978. // The right position is the current X scroll position minus the grid width
  4979. var rightBound = self.renderContainers.body.prevScrollLeft + Math.ceil(self.renderContainers.body.getViewportWidth());
  4980. // If there's a vertical scrollbar, subtract it from the right boundary or we'll allow it to obscure cells
  4981. //if (self.verticalScrollbarWidth) {
  4982. // rightBound = rightBound - self.verticalScrollbarWidth;
  4983. //}
  4984. // We were given a row to scroll to
  4985. if (gridRow !== null) {
  4986. // This is the index of the row we want to scroll to, within the list of rows that can be visible
  4987. var seekRowIndex = visRowCache.indexOf(gridRow);
  4988. // Total vertical scroll length of the grid
  4989. var scrollLength = (self.renderContainers.body.getCanvasHeight() - self.renderContainers.body.getViewportHeight());
  4990. // Add the height of the native horizontal scrollbar to the scroll length, if it's there. Otherwise it will mask over the final row
  4991. //if (self.horizontalScrollbarHeight && self.horizontalScrollbarHeight > 0) {
  4992. // scrollLength = scrollLength + self.horizontalScrollbarHeight;
  4993. //}
  4994. // This is the minimum amount of pixels we need to scroll vertical in order to see this row.
  4995. var pixelsToSeeRow = (seekRowIndex * self.options.rowHeight + self.headerHeight);
  4996. // Don't let the pixels required to see the row be less than zero
  4997. pixelsToSeeRow = (pixelsToSeeRow < 0) ? 0 : pixelsToSeeRow;
  4998. var scrollPixels, percentage;
  4999. // If the scroll position we need to see the row is LESS than the top boundary, i.e. obscured above the top of the self...
  5000. if (pixelsToSeeRow < topBound) {
  5001. // Get the different between the top boundary and the required scroll position and subtract it from the current scroll position\
  5002. // to get the full position we need
  5003. scrollPixels = self.renderContainers.body.prevScrollTop - (topBound - pixelsToSeeRow);
  5004. // Turn the scroll position into a percentage and make it an argument for a scroll event
  5005. percentage = scrollPixels / scrollLength;
  5006. scrollEvent.y = { percentage: percentage };
  5007. }
  5008. // Otherwise if the scroll position we need to see the row is MORE than the bottom boundary, i.e. obscured below the bottom of the self...
  5009. else if (pixelsToSeeRow > bottomBound) {
  5010. // Get the different between the bottom boundary and the required scroll position and add it to the current scroll position
  5011. // to get the full position we need
  5012. scrollPixels = pixelsToSeeRow - bottomBound + self.renderContainers.body.prevScrollTop;
  5013. // Turn the scroll position into a percentage and make it an argument for a scroll event
  5014. percentage = scrollPixels / scrollLength;
  5015. scrollEvent.y = { percentage: percentage };
  5016. }
  5017. }
  5018. // We were given a column to scroll to
  5019. if (gridCol !== null) {
  5020. // This is the index of the row we want to scroll to, within the list of rows that can be visible
  5021. var seekColumnIndex = visColCache.indexOf(gridCol);
  5022. // Total vertical scroll length of the grid
  5023. var horizScrollLength = (self.renderContainers.body.getCanvasWidth() - self.renderContainers.body.getViewportWidth());
  5024. // Add the height of the native horizontal scrollbar to the scroll length, if it's there. Otherwise it will mask over the final row
  5025. // if (self.verticalScrollbarWidth && self.verticalScrollbarWidth > 0) {
  5026. // horizScrollLength = horizScrollLength + self.verticalScrollbarWidth;
  5027. // }
  5028. // This is the minimum amount of pixels we need to scroll vertical in order to see this column
  5029. var columnLeftEdge = 0;
  5030. for (var i = 0; i < seekColumnIndex; i++) {
  5031. var col = visColCache[i];
  5032. columnLeftEdge += col.drawnWidth;
  5033. }
  5034. columnLeftEdge = (columnLeftEdge < 0) ? 0 : columnLeftEdge;
  5035. var columnRightEdge = columnLeftEdge + gridCol.drawnWidth;
  5036. // Don't let the pixels required to see the column be less than zero
  5037. columnRightEdge = (columnRightEdge < 0) ? 0 : columnRightEdge;
  5038. var horizScrollPixels, horizPercentage;
  5039. // If the scroll position we need to see the row is LESS than the top boundary, i.e. obscured above the top of the self...
  5040. if (columnLeftEdge < leftBound) {
  5041. // Get the different between the top boundary and the required scroll position and subtract it from the current scroll position\
  5042. // to get the full position we need
  5043. horizScrollPixels = self.renderContainers.body.prevScrollLeft - (leftBound - columnLeftEdge);
  5044. // Turn the scroll position into a percentage and make it an argument for a scroll event
  5045. horizPercentage = horizScrollPixels / horizScrollLength;
  5046. horizPercentage = (horizPercentage > 1) ? 1 : horizPercentage;
  5047. scrollEvent.x = { percentage: horizPercentage };
  5048. }
  5049. // Otherwise if the scroll position we need to see the row is MORE than the bottom boundary, i.e. obscured below the bottom of the self...
  5050. else if (columnRightEdge > rightBound) {
  5051. // Get the different between the bottom boundary and the required scroll position and add it to the current scroll position
  5052. // to get the full position we need
  5053. horizScrollPixels = columnRightEdge - rightBound + self.renderContainers.body.prevScrollLeft;
  5054. // Turn the scroll position into a percentage and make it an argument for a scroll event
  5055. horizPercentage = horizScrollPixels / horizScrollLength;
  5056. horizPercentage = (horizPercentage > 1) ? 1 : horizPercentage;
  5057. scrollEvent.x = { percentage: horizPercentage };
  5058. }
  5059. }
  5060. var deferred = $q.defer();
  5061. // If we need to scroll on either the x or y axes, fire a scroll event
  5062. if (scrollEvent.y || scrollEvent.x) {
  5063. scrollEvent.withDelay = false;
  5064. self.scrollContainers('',scrollEvent);
  5065. var dereg = self.api.core.on.scrollEnd(null,function() {
  5066. deferred.resolve(scrollEvent);
  5067. dereg();
  5068. });
  5069. }
  5070. else {
  5071. deferred.resolve();
  5072. }
  5073. return deferred.promise;
  5074. };
  5075. /**
  5076. * @ngdoc method
  5077. * @methodOf ui.grid.class:Grid
  5078. * @name scrollTo
  5079. * @description Scroll the grid such that the specified
  5080. * row and column is in view
  5081. * @param {object} rowEntity gridOptions.data[] array instance to make visible
  5082. * @param {object} colDef to make visible
  5083. * @returns {promise} a promise that is resolved after any scrolling is finished
  5084. */
  5085. Grid.prototype.scrollTo = function (rowEntity, colDef) {
  5086. var gridRow = null, gridCol = null;
  5087. if (rowEntity !== null && typeof(rowEntity) !== 'undefined' ) {
  5088. gridRow = this.getRow(rowEntity);
  5089. }
  5090. if (colDef !== null && typeof(colDef) !== 'undefined' ) {
  5091. gridCol = this.getColumn(colDef.name ? colDef.name : colDef.field);
  5092. }
  5093. return this.scrollToIfNecessary(gridRow, gridCol);
  5094. };
  5095. /**
  5096. * @ngdoc function
  5097. * @name clearAllFilters
  5098. * @methodOf ui.grid.class:Grid
  5099. * @description Clears all filters and optionally refreshes the visible rows.
  5100. * @param {object} refreshRows Defaults to true.
  5101. * @param {object} clearConditions Defaults to false.
  5102. * @param {object} clearFlags Defaults to false.
  5103. * @returns {promise} If `refreshRows` is true, returns a promise of the rows refreshing.
  5104. */
  5105. Grid.prototype.clearAllFilters = function clearAllFilters(refreshRows, clearConditions, clearFlags) {
  5106. // Default `refreshRows` to true because it will be the most commonly desired behaviour.
  5107. if (refreshRows === undefined) {
  5108. refreshRows = true;
  5109. }
  5110. if (clearConditions === undefined) {
  5111. clearConditions = false;
  5112. }
  5113. if (clearFlags === undefined) {
  5114. clearFlags = false;
  5115. }
  5116. this.columns.forEach(function(column) {
  5117. column.filters.forEach(function(filter) {
  5118. filter.term = undefined;
  5119. if (clearConditions) {
  5120. filter.condition = undefined;
  5121. }
  5122. if (clearFlags) {
  5123. filter.flags = undefined;
  5124. }
  5125. });
  5126. });
  5127. if (refreshRows) {
  5128. return this.refreshRows();
  5129. }
  5130. };
  5131. // Blatantly stolen from Angular as it isn't exposed (yet? 2.0?)
  5132. function RowHashMap() {}
  5133. RowHashMap.prototype = {
  5134. /**
  5135. * Store key value pair
  5136. * @param key key to store can be any type
  5137. * @param value value to store can be any type
  5138. */
  5139. put: function(key, value) {
  5140. this[this.grid.options.rowIdentity(key)] = value;
  5141. },
  5142. /**
  5143. * @param key
  5144. * @returns {Object} the value for the key
  5145. */
  5146. get: function(key) {
  5147. return this[this.grid.options.rowIdentity(key)];
  5148. },
  5149. /**
  5150. * Remove the key/value pair
  5151. * @param key
  5152. */
  5153. remove: function(key) {
  5154. var value = this[key = this.grid.options.rowIdentity(key)];
  5155. delete this[key];
  5156. return value;
  5157. }
  5158. };
  5159. return Grid;
  5160. }]);
  5161. })();
  5162. (function () {
  5163. angular.module('ui.grid')
  5164. .factory('GridApi', ['$q', '$rootScope', 'gridUtil', 'uiGridConstants', 'GridRow', 'uiGridGridMenuService',
  5165. function ($q, $rootScope, gridUtil, uiGridConstants, GridRow, uiGridGridMenuService) {
  5166. /**
  5167. * @ngdoc function
  5168. * @name ui.grid.class:GridApi
  5169. * @description GridApi provides the ability to register public methods events inside the grid and allow
  5170. * for other components to use the api via featureName.raise.methodName and featureName.on.eventName(function(args){}.
  5171. * <br/>
  5172. * To listen to events, you must add a callback to gridOptions.onRegisterApi
  5173. * <pre>
  5174. * $scope.gridOptions.onRegisterApi = function(gridApi){
  5175. * gridApi.cellNav.on.navigate($scope,function(newRowCol, oldRowCol){
  5176. * $log.log('navigation event');
  5177. * });
  5178. * };
  5179. * </pre>
  5180. * @param {object} grid grid that owns api
  5181. */
  5182. var GridApi = function GridApi(grid) {
  5183. this.grid = grid;
  5184. this.listeners = [];
  5185. /**
  5186. * @ngdoc function
  5187. * @name renderingComplete
  5188. * @methodOf ui.grid.core.api:PublicApi
  5189. * @description Rendering is complete, called at the same
  5190. * time as `onRegisterApi`, but provides a way to obtain
  5191. * that same event within features without stopping end
  5192. * users from getting at the onRegisterApi method.
  5193. *
  5194. * Included in gridApi so that it's always there - otherwise
  5195. * there is still a timing problem with when a feature can
  5196. * call this.
  5197. *
  5198. * @param {GridApi} gridApi the grid api, as normally
  5199. * returned in the onRegisterApi method
  5200. *
  5201. * @example
  5202. * <pre>
  5203. * gridApi.core.on.renderingComplete( grid );
  5204. * </pre>
  5205. */
  5206. this.registerEvent( 'core', 'renderingComplete' );
  5207. /**
  5208. * @ngdoc event
  5209. * @name filterChanged
  5210. * @eventOf ui.grid.core.api:PublicApi
  5211. * @description is raised after the filter is changed. The nature
  5212. * of the watch expression doesn't allow notification of what changed,
  5213. * so the receiver of this event will need to re-extract the filter
  5214. * conditions from the columns.
  5215. *
  5216. */
  5217. this.registerEvent( 'core', 'filterChanged' );
  5218. /**
  5219. * @ngdoc function
  5220. * @name setRowInvisible
  5221. * @methodOf ui.grid.core.api:PublicApi
  5222. * @description Sets an override on the row to make it always invisible,
  5223. * which will override any filtering or other visibility calculations.
  5224. * If the row is currently visible then sets it to invisible and calls
  5225. * both grid refresh and emits the rowsVisibleChanged event
  5226. * @param {object} rowEntity gridOptions.data[] array instance
  5227. */
  5228. this.registerMethod( 'core', 'setRowInvisible', GridRow.prototype.setRowInvisible );
  5229. /**
  5230. * @ngdoc function
  5231. * @name clearRowInvisible
  5232. * @methodOf ui.grid.core.api:PublicApi
  5233. * @description Clears any override on visibility for the row so that it returns to
  5234. * using normal filtering and other visibility calculations.
  5235. * If the row is currently invisible then sets it to visible and calls
  5236. * both grid refresh and emits the rowsVisibleChanged event
  5237. * TODO: if a filter is active then we can't just set it to visible?
  5238. * @param {object} rowEntity gridOptions.data[] array instance
  5239. */
  5240. this.registerMethod( 'core', 'clearRowInvisible', GridRow.prototype.clearRowInvisible );
  5241. /**
  5242. * @ngdoc function
  5243. * @name getVisibleRows
  5244. * @methodOf ui.grid.core.api:PublicApi
  5245. * @description Returns all visible rows
  5246. * @param {Grid} grid the grid you want to get visible rows from
  5247. * @returns {array} an array of gridRow
  5248. */
  5249. this.registerMethod( 'core', 'getVisibleRows', this.grid.getVisibleRows );
  5250. /**
  5251. * @ngdoc event
  5252. * @name rowsVisibleChanged
  5253. * @eventOf ui.grid.core.api:PublicApi
  5254. * @description is raised after the rows that are visible
  5255. * change. The filtering is zero-based, so it isn't possible
  5256. * to say which rows changed (unlike in the selection feature).
  5257. * We can plausibly know which row was changed when setRowInvisible
  5258. * is called, but in that situation the user already knows which row
  5259. * they changed. When a filter runs we don't know what changed,
  5260. * and that is the one that would have been useful.
  5261. *
  5262. */
  5263. this.registerEvent( 'core', 'rowsVisibleChanged' );
  5264. /**
  5265. * @ngdoc event
  5266. * @name rowsRendered
  5267. * @eventOf ui.grid.core.api:PublicApi
  5268. * @description is raised after the cache of visible rows is changed.
  5269. */
  5270. this.registerEvent( 'core', 'rowsRendered' );
  5271. /**
  5272. * @ngdoc event
  5273. * @name scrollBegin
  5274. * @eventOf ui.grid.core.api:PublicApi
  5275. * @description is raised when scroll begins. Is throttled, so won't be raised too frequently
  5276. */
  5277. this.registerEvent( 'core', 'scrollBegin' );
  5278. /**
  5279. * @ngdoc event
  5280. * @name scrollEnd
  5281. * @eventOf ui.grid.core.api:PublicApi
  5282. * @description is raised when scroll has finished. Is throttled, so won't be raised too frequently
  5283. */
  5284. this.registerEvent( 'core', 'scrollEnd' );
  5285. /**
  5286. * @ngdoc event
  5287. * @name canvasHeightChanged
  5288. * @eventOf ui.grid.core.api:PublicApi
  5289. * @description is raised when the canvas height has changed
  5290. * <br/>
  5291. * arguments: oldHeight, newHeight
  5292. */
  5293. this.registerEvent( 'core', 'canvasHeightChanged');
  5294. };
  5295. /**
  5296. * @ngdoc function
  5297. * @name ui.grid.class:suppressEvents
  5298. * @methodOf ui.grid.class:GridApi
  5299. * @description Used to execute a function while disabling the specified event listeners.
  5300. * Disables the listenerFunctions, executes the callbackFn, and then enables
  5301. * the listenerFunctions again
  5302. * @param {object} listenerFuncs listenerFunc or array of listenerFuncs to suppress. These must be the same
  5303. * functions that were used in the .on.eventName method
  5304. * @param {object} callBackFn function to execute
  5305. * @example
  5306. * <pre>
  5307. * var navigate = function (newRowCol, oldRowCol){
  5308. * //do something on navigate
  5309. * }
  5310. *
  5311. * gridApi.cellNav.on.navigate(scope,navigate);
  5312. *
  5313. *
  5314. * //call the scrollTo event and suppress our navigate listener
  5315. * //scrollTo will still raise the event for other listeners
  5316. * gridApi.suppressEvents(navigate, function(){
  5317. * gridApi.cellNav.scrollTo(aRow, aCol);
  5318. * });
  5319. *
  5320. * </pre>
  5321. */
  5322. GridApi.prototype.suppressEvents = function (listenerFuncs, callBackFn) {
  5323. var self = this;
  5324. var listeners = angular.isArray(listenerFuncs) ? listenerFuncs : [listenerFuncs];
  5325. //find all registered listeners
  5326. var foundListeners = self.listeners.filter(function(listener) {
  5327. return listeners.some(function(l) {
  5328. return listener.handler === l;
  5329. });
  5330. });
  5331. //deregister all the listeners
  5332. foundListeners.forEach(function(l){
  5333. l.dereg();
  5334. });
  5335. callBackFn();
  5336. //reregister all the listeners
  5337. foundListeners.forEach(function(l){
  5338. l.dereg = registerEventWithAngular(l.eventId, l.handler, self.grid, l._this);
  5339. });
  5340. };
  5341. /**
  5342. * @ngdoc function
  5343. * @name registerEvent
  5344. * @methodOf ui.grid.class:GridApi
  5345. * @description Registers a new event for the given feature. The event will get a
  5346. * .raise and .on prepended to it
  5347. * <br>
  5348. * .raise.eventName() - takes no arguments
  5349. * <br/>
  5350. * <br/>
  5351. * .on.eventName(scope, callBackFn, _this)
  5352. * <br/>
  5353. * scope - a scope reference to add a deregister call to the scopes .$on('destroy'). Scope is optional and can be a null value,
  5354. * but in this case you must deregister it yourself via the returned deregister function
  5355. * <br/>
  5356. * callBackFn - The function to call
  5357. * <br/>
  5358. * _this - optional this context variable for callbackFn. If omitted, grid.api will be used for the context
  5359. * <br/>
  5360. * .on.eventName returns a dereg funtion that will remove the listener. It's not necessary to use it as the listener
  5361. * will be removed when the scope is destroyed.
  5362. * @param {string} featureName name of the feature that raises the event
  5363. * @param {string} eventName name of the event
  5364. */
  5365. GridApi.prototype.registerEvent = function (featureName, eventName) {
  5366. var self = this;
  5367. if (!self[featureName]) {
  5368. self[featureName] = {};
  5369. }
  5370. var feature = self[featureName];
  5371. if (!feature.on) {
  5372. feature.on = {};
  5373. feature.raise = {};
  5374. }
  5375. var eventId = self.grid.id + featureName + eventName;
  5376. // gridUtil.logDebug('Creating raise event method ' + featureName + '.raise.' + eventName);
  5377. feature.raise[eventName] = function () {
  5378. $rootScope.$emit.apply($rootScope, [eventId].concat(Array.prototype.slice.call(arguments)));
  5379. };
  5380. // gridUtil.logDebug('Creating on event method ' + featureName + '.on.' + eventName);
  5381. feature.on[eventName] = function (scope, handler, _this) {
  5382. if ( scope !== null && typeof(scope.$on) === 'undefined' ){
  5383. gridUtil.logError('asked to listen on ' + featureName + '.on.' + eventName + ' but scope wasn\'t passed in the input parameters. It is legitimate to pass null, but you\'ve passed something else, so you probably forgot to provide scope rather than did it deliberately, not registering');
  5384. return;
  5385. }
  5386. var deregAngularOn = registerEventWithAngular(eventId, handler, self.grid, _this);
  5387. //track our listener so we can turn off and on
  5388. var listener = {handler: handler, dereg: deregAngularOn, eventId: eventId, scope: scope, _this:_this};
  5389. self.listeners.push(listener);
  5390. var removeListener = function(){
  5391. listener.dereg();
  5392. var index = self.listeners.indexOf(listener);
  5393. self.listeners.splice(index,1);
  5394. };
  5395. //destroy tracking when scope is destroyed
  5396. if (scope) {
  5397. scope.$on('$destroy', function() {
  5398. removeListener();
  5399. });
  5400. }
  5401. return removeListener;
  5402. };
  5403. };
  5404. function registerEventWithAngular(eventId, handler, grid, _this) {
  5405. return $rootScope.$on(eventId, function (event) {
  5406. var args = Array.prototype.slice.call(arguments);
  5407. args.splice(0, 1); //remove evt argument
  5408. handler.apply(_this ? _this : grid.api, args);
  5409. });
  5410. }
  5411. /**
  5412. * @ngdoc function
  5413. * @name registerEventsFromObject
  5414. * @methodOf ui.grid.class:GridApi
  5415. * @description Registers features and events from a simple objectMap.
  5416. * eventObjectMap must be in this format (multiple features allowed)
  5417. * <pre>
  5418. * {featureName:
  5419. * {
  5420. * eventNameOne:function(args){},
  5421. * eventNameTwo:function(args){}
  5422. * }
  5423. * }
  5424. * </pre>
  5425. * @param {object} eventObjectMap map of feature/event names
  5426. */
  5427. GridApi.prototype.registerEventsFromObject = function (eventObjectMap) {
  5428. var self = this;
  5429. var features = [];
  5430. angular.forEach(eventObjectMap, function (featProp, featPropName) {
  5431. var feature = {name: featPropName, events: []};
  5432. angular.forEach(featProp, function (prop, propName) {
  5433. feature.events.push(propName);
  5434. });
  5435. features.push(feature);
  5436. });
  5437. features.forEach(function (feature) {
  5438. feature.events.forEach(function (event) {
  5439. self.registerEvent(feature.name, event);
  5440. });
  5441. });
  5442. };
  5443. /**
  5444. * @ngdoc function
  5445. * @name registerMethod
  5446. * @methodOf ui.grid.class:GridApi
  5447. * @description Registers a new event for the given feature
  5448. * @param {string} featureName name of the feature
  5449. * @param {string} methodName name of the method
  5450. * @param {object} callBackFn function to execute
  5451. * @param {object} _this binds callBackFn 'this' to _this. Defaults to gridApi.grid
  5452. */
  5453. GridApi.prototype.registerMethod = function (featureName, methodName, callBackFn, _this) {
  5454. if (!this[featureName]) {
  5455. this[featureName] = {};
  5456. }
  5457. var feature = this[featureName];
  5458. feature[methodName] = gridUtil.createBoundedWrapper(_this || this.grid, callBackFn);
  5459. };
  5460. /**
  5461. * @ngdoc function
  5462. * @name registerMethodsFromObject
  5463. * @methodOf ui.grid.class:GridApi
  5464. * @description Registers features and methods from a simple objectMap.
  5465. * eventObjectMap must be in this format (multiple features allowed)
  5466. * <br>
  5467. * {featureName:
  5468. * {
  5469. * methodNameOne:function(args){},
  5470. * methodNameTwo:function(args){}
  5471. * }
  5472. * @param {object} eventObjectMap map of feature/event names
  5473. * @param {object} _this binds this to _this for all functions. Defaults to gridApi.grid
  5474. */
  5475. GridApi.prototype.registerMethodsFromObject = function (methodMap, _this) {
  5476. var self = this;
  5477. var features = [];
  5478. angular.forEach(methodMap, function (featProp, featPropName) {
  5479. var feature = {name: featPropName, methods: []};
  5480. angular.forEach(featProp, function (prop, propName) {
  5481. feature.methods.push({name: propName, fn: prop});
  5482. });
  5483. features.push(feature);
  5484. });
  5485. features.forEach(function (feature) {
  5486. feature.methods.forEach(function (method) {
  5487. self.registerMethod(feature.name, method.name, method.fn, _this);
  5488. });
  5489. });
  5490. };
  5491. return GridApi;
  5492. }]);
  5493. })();
  5494. (function(){
  5495. angular.module('ui.grid')
  5496. .factory('GridColumn', ['gridUtil', 'uiGridConstants', 'i18nService', function(gridUtil, uiGridConstants, i18nService) {
  5497. /**
  5498. * ******************************************************************************************
  5499. * PaulL1: Ugly hack here in documentation. These properties are clearly properties of GridColumn,
  5500. * and need to be noted as such for those extending and building ui-grid itself.
  5501. * However, from an end-developer perspective, they interact with all these through columnDefs,
  5502. * and they really need to be documented there. I feel like they're relatively static, and
  5503. * I can't find an elegant way for ngDoc to reference to both....so I've duplicated each
  5504. * comment block. Ugh.
  5505. *
  5506. */
  5507. /**
  5508. * @ngdoc property
  5509. * @name name
  5510. * @propertyOf ui.grid.class:GridColumn
  5511. * @description (mandatory) each column should have a name, although for backward
  5512. * compatibility with 2.x name can be omitted if field is present
  5513. *
  5514. */
  5515. /**
  5516. * @ngdoc property
  5517. * @name name
  5518. * @propertyOf ui.grid.class:GridOptions.columnDef
  5519. * @description (mandatory) each column should have a name, although for backward
  5520. * compatibility with 2.x name can be omitted if field is present
  5521. *
  5522. */
  5523. /**
  5524. * @ngdoc property
  5525. * @name displayName
  5526. * @propertyOf ui.grid.class:GridColumn
  5527. * @description Column name that will be shown in the header. If displayName is not
  5528. * provided then one is generated using the name.
  5529. *
  5530. */
  5531. /**
  5532. * @ngdoc property
  5533. * @name displayName
  5534. * @propertyOf ui.grid.class:GridOptions.columnDef
  5535. * @description Column name that will be shown in the header. If displayName is not
  5536. * provided then one is generated using the name.
  5537. *
  5538. */
  5539. /**
  5540. * @ngdoc property
  5541. * @name field
  5542. * @propertyOf ui.grid.class:GridColumn
  5543. * @description field must be provided if you wish to bind to a
  5544. * property in the data source. Should be an angular expression that evaluates against grid.options.data
  5545. * array element. Can be a complex expression: <code>employee.address.city</code>, or can be a function: <code>employee.getFullAddress()</code>.
  5546. * See the angular docs on binding expressions.
  5547. *
  5548. */
  5549. /**
  5550. * @ngdoc property
  5551. * @name field
  5552. * @propertyOf ui.grid.class:GridOptions.columnDef
  5553. * @description field must be provided if you wish to bind to a
  5554. * property in the data source. Should be an angular expression that evaluates against grid.options.data
  5555. * array element. Can be a complex expression: <code>employee.address.city</code>, or can be a function: <code>employee.getFullAddress()</code>. * See the angular docs on binding expressions. *
  5556. */
  5557. /**
  5558. * @ngdoc property
  5559. * @name filter
  5560. * @propertyOf ui.grid.class:GridColumn
  5561. * @description Filter on this column.
  5562. * @example
  5563. * <pre>{ term: 'text', condition: uiGridConstants.filter.STARTS_WITH, placeholder: 'type to filter...', ariaLabel: 'Filter for text', flags: { caseSensitive: false }, type: uiGridConstants.filter.SELECT, [ { value: 1, label: 'male' }, { value: 2, label: 'female' } ] }</pre>
  5564. *
  5565. */
  5566. /**
  5567. * @ngdoc object
  5568. * @name ui.grid.class:GridColumn
  5569. * @description Represents the viewModel for each column. Any state or methods needed for a Grid Column
  5570. * are defined on this prototype
  5571. * @param {ColumnDef} colDef the column def to associate with this column
  5572. * @param {number} uid the unique and immutable uid we'd like to allocate to this column
  5573. * @param {Grid} grid the grid we'd like to create this column in
  5574. */
  5575. function GridColumn(colDef, uid, grid) {
  5576. var self = this;
  5577. self.grid = grid;
  5578. self.uid = uid;
  5579. self.updateColumnDef(colDef, true);
  5580. self.aggregationValue = undefined;
  5581. // The footer cell registers to listen for the rowsRendered event, and calls this. Needed to be
  5582. // in something with a scope so that the dereg would get called
  5583. self.updateAggregationValue = function() {
  5584. // gridUtil.logDebug('getAggregationValue for Column ' + self.colDef.name);
  5585. /**
  5586. * @ngdoc property
  5587. * @name aggregationType
  5588. * @propertyOf ui.grid.class:GridOptions.columnDef
  5589. * @description The aggregation that you'd like to show in the columnFooter for this
  5590. * column. Valid values are in uiGridConstants, and currently include `uiGridConstants.aggregationTypes.count`,
  5591. * `uiGridConstants.aggregationTypes.sum`, `uiGridConstants.aggregationTypes.avg`, `uiGridConstants.aggregationTypes.min`,
  5592. * `uiGridConstants.aggregationTypes.max`.
  5593. *
  5594. * You can also provide a function as the aggregation type, in this case your function needs to accept the full
  5595. * set of visible rows, and return a value that should be shown
  5596. */
  5597. if (!self.aggregationType) {
  5598. self.aggregationValue = undefined;
  5599. return;
  5600. }
  5601. var result = 0;
  5602. var visibleRows = self.grid.getVisibleRows();
  5603. var cellValues = function(){
  5604. var values = [];
  5605. visibleRows.forEach(function (row) {
  5606. var cellValue = self.grid.getCellValue(row, self);
  5607. var cellNumber = Number(cellValue);
  5608. if (!isNaN(cellNumber)) {
  5609. values.push(cellNumber);
  5610. }
  5611. });
  5612. return values;
  5613. };
  5614. if (angular.isFunction(self.aggregationType)) {
  5615. self.aggregationValue = self.aggregationType(visibleRows, self);
  5616. }
  5617. else if (self.aggregationType === uiGridConstants.aggregationTypes.count) {
  5618. self.aggregationValue = self.grid.getVisibleRowCount();
  5619. }
  5620. else if (self.aggregationType === uiGridConstants.aggregationTypes.sum) {
  5621. cellValues().forEach(function (value) {
  5622. result += value;
  5623. });
  5624. self.aggregationValue = result;
  5625. }
  5626. else if (self.aggregationType === uiGridConstants.aggregationTypes.avg) {
  5627. cellValues().forEach(function (value) {
  5628. result += value;
  5629. });
  5630. result = result / cellValues().length;
  5631. self.aggregationValue = result;
  5632. }
  5633. else if (self.aggregationType === uiGridConstants.aggregationTypes.min) {
  5634. self.aggregationValue = Math.min.apply(null, cellValues());
  5635. }
  5636. else if (self.aggregationType === uiGridConstants.aggregationTypes.max) {
  5637. self.aggregationValue = Math.max.apply(null, cellValues());
  5638. }
  5639. else {
  5640. self.aggregationValue = '\u00A0';
  5641. }
  5642. };
  5643. // var throttledUpdateAggregationValue = gridUtil.throttle(updateAggregationValue, self.grid.options.aggregationCalcThrottle, { trailing: true, context: self.name });
  5644. /**
  5645. * @ngdoc function
  5646. * @name getAggregationValue
  5647. * @methodOf ui.grid.class:GridColumn
  5648. * @description gets the aggregation value based on the aggregation type for this column.
  5649. * Debounced using scrollDebounce option setting
  5650. */
  5651. this.getAggregationValue = function() {
  5652. // if (!self.grid.isScrollingVertically && !self.grid.isScrollingHorizontally) {
  5653. // throttledUpdateAggregationValue();
  5654. // }
  5655. return self.aggregationValue;
  5656. };
  5657. }
  5658. /**
  5659. * @ngdoc function
  5660. * @name hideColumn
  5661. * @methodOf ui.grid.class:GridColumn
  5662. * @description Hides the column by setting colDef.visible = false
  5663. */
  5664. GridColumn.prototype.hideColumn = function() {
  5665. this.colDef.visible = false;
  5666. };
  5667. /**
  5668. * @ngdoc method
  5669. * @methodOf ui.grid.class:GridColumn
  5670. * @name setPropertyOrDefault
  5671. * @description Sets a property on the column using the passed in columnDef, and
  5672. * setting the defaultValue if the value cannot be found on the colDef
  5673. * @param {ColumnDef} colDef the column def to look in for the property value
  5674. * @param {string} propName the property name we'd like to set
  5675. * @param {object} defaultValue the value to use if the colDef doesn't provide the setting
  5676. */
  5677. GridColumn.prototype.setPropertyOrDefault = function (colDef, propName, defaultValue) {
  5678. var self = this;
  5679. // Use the column definition filter if we were passed it
  5680. if (typeof(colDef[propName]) !== 'undefined' && colDef[propName]) {
  5681. self[propName] = colDef[propName];
  5682. }
  5683. // Otherwise use our own if it's set
  5684. else if (typeof(self[propName]) !== 'undefined') {
  5685. self[propName] = self[propName];
  5686. }
  5687. // Default to empty object for the filter
  5688. else {
  5689. self[propName] = defaultValue ? defaultValue : {};
  5690. }
  5691. };
  5692. /**
  5693. * @ngdoc property
  5694. * @name width
  5695. * @propertyOf ui.grid.class:GridOptions.columnDef
  5696. * @description sets the column width. Can be either
  5697. * a number or a percentage, or an * for auto.
  5698. * @example
  5699. * <pre> $scope.gridOptions.columnDefs = [ { field: 'field1', width: 100},
  5700. * { field: 'field2', width: '20%'},
  5701. * { field: 'field3', width: '*' }]; </pre>
  5702. *
  5703. */
  5704. /**
  5705. * @ngdoc property
  5706. * @name minWidth
  5707. * @propertyOf ui.grid.class:GridOptions.columnDef
  5708. * @description sets the minimum column width. Should be a number.
  5709. * @example
  5710. * <pre> $scope.gridOptions.columnDefs = [ { field: 'field1', minWidth: 100}]; </pre>
  5711. *
  5712. */
  5713. /**
  5714. * @ngdoc property
  5715. * @name maxWidth
  5716. * @propertyOf ui.grid.class:GridOptions.columnDef
  5717. * @description sets the maximum column width. Should be a number.
  5718. * @example
  5719. * <pre> $scope.gridOptions.columnDefs = [ { field: 'field1', maxWidth: 100}]; </pre>
  5720. *
  5721. */
  5722. /**
  5723. * @ngdoc property
  5724. * @name visible
  5725. * @propertyOf ui.grid.class:GridOptions.columnDef
  5726. * @description sets whether or not the column is visible
  5727. * </br>Default is true
  5728. * @example
  5729. * <pre> $scope.gridOptions.columnDefs = [
  5730. * { field: 'field1', visible: true},
  5731. * { field: 'field2', visible: false }
  5732. * ]; </pre>
  5733. *
  5734. */
  5735. /**
  5736. * @ngdoc property
  5737. * @name sort
  5738. * @propertyOf ui.grid.class:GridOptions.columnDef
  5739. * @description An object of sort information, attributes are:
  5740. *
  5741. * - direction: values are uiGridConstants.ASC or uiGridConstants.DESC
  5742. * - ignoreSort: if set to true this sort is ignored (used by tree to manipulate the sort functionality)
  5743. * - priority: says what order to sort the columns in (lower priority gets sorted first).
  5744. * @example
  5745. * <pre>
  5746. * $scope.gridOptions.columnDefs = [{
  5747. * field: 'field1',
  5748. * sort: {
  5749. * direction: uiGridConstants.ASC,
  5750. * ignoreSort: true,
  5751. * priority: 0
  5752. * }
  5753. * }];
  5754. * </pre>
  5755. */
  5756. /**
  5757. * @ngdoc property
  5758. * @name sortingAlgorithm
  5759. * @propertyOf ui.grid.class:GridOptions.columnDef
  5760. * @description Algorithm to use for sorting this column. Takes 'a' and 'b' parameters
  5761. * like any normal sorting function with additional 'rowA', 'rowB', and 'direction' parameters
  5762. * that are the row objects and the current direction of the sort respectively.
  5763. *
  5764. */
  5765. /**
  5766. * @ngdoc array
  5767. * @name filters
  5768. * @propertyOf ui.grid.class:GridOptions.columnDef
  5769. * @description Specify multiple filter fields.
  5770. * @example
  5771. * <pre>$scope.gridOptions.columnDefs = [
  5772. * {
  5773. * field: 'field1', filters: [
  5774. * {
  5775. * term: 'aa',
  5776. * condition: uiGridConstants.filter.STARTS_WITH,
  5777. * placeholder: 'starts with...',
  5778. * ariaLabel: 'Filter for field1',
  5779. * flags: { caseSensitive: false },
  5780. * type: uiGridConstants.filter.SELECT,
  5781. * selectOptions: [ { value: 1, label: 'male' }, { value: 2, label: 'female' } ]
  5782. * },
  5783. * {
  5784. * condition: uiGridConstants.filter.ENDS_WITH,
  5785. * placeholder: 'ends with...'
  5786. * }
  5787. * ]
  5788. * }
  5789. * ]; </pre>
  5790. *
  5791. *
  5792. */
  5793. /**
  5794. * @ngdoc array
  5795. * @name filters
  5796. * @propertyOf ui.grid.class:GridColumn
  5797. * @description Filters for this column. Includes 'term' property bound to filter input elements.
  5798. * @example
  5799. * <pre>[
  5800. * {
  5801. * term: 'foo', // ngModel for <input>
  5802. * condition: uiGridConstants.filter.STARTS_WITH,
  5803. * placeholder: 'starts with...',
  5804. * ariaLabel: 'Filter for foo',
  5805. * flags: { caseSensitive: false },
  5806. * type: uiGridConstants.filter.SELECT,
  5807. * selectOptions: [ { value: 1, label: 'male' }, { value: 2, label: 'female' } ]
  5808. * },
  5809. * {
  5810. * term: 'baz',
  5811. * condition: uiGridConstants.filter.ENDS_WITH,
  5812. * placeholder: 'ends with...'
  5813. * }
  5814. * ] </pre>
  5815. *
  5816. *
  5817. */
  5818. /**
  5819. * @ngdoc array
  5820. * @name menuItems
  5821. * @propertyOf ui.grid.class:GridOptions.columnDef
  5822. * @description used to add menu items to a column. Refer to the tutorial on this
  5823. * functionality. A number of settings are supported:
  5824. *
  5825. * - title: controls the title that is displayed in the menu
  5826. * - icon: the icon shown alongside that title
  5827. * - action: the method to call when the menu is clicked
  5828. * - shown: a function to evaluate to determine whether or not to show the item
  5829. * - active: a function to evaluate to determine whether or not the item is currently selected
  5830. * - context: context to pass to the action function, available in this.context in your handler
  5831. * - leaveOpen: if set to true, the menu should stay open after the action, defaults to false
  5832. * @example
  5833. * <pre> $scope.gridOptions.columnDefs = [
  5834. * { field: 'field1', menuItems: [
  5835. * {
  5836. * title: 'Outer Scope Alert',
  5837. * icon: 'ui-grid-icon-info-circled',
  5838. * action: function($event) {
  5839. * this.context.blargh(); // $scope.blargh() would work too, this is just an example
  5840. * },
  5841. * shown: function() { return true; },
  5842. * active: function() { return true; },
  5843. * context: $scope
  5844. * },
  5845. * {
  5846. * title: 'Grid ID',
  5847. * action: function() {
  5848. * alert('Grid ID: ' + this.grid.id);
  5849. * }
  5850. * }
  5851. * ] }]; </pre>
  5852. *
  5853. */
  5854. /**
  5855. * @ngdoc method
  5856. * @methodOf ui.grid.class:GridColumn
  5857. * @name updateColumnDef
  5858. * @description Moves settings from the columnDef down onto the column,
  5859. * and sets properties as appropriate
  5860. * @param {ColumnDef} colDef the column def to look in for the property value
  5861. * @param {boolean} isNew whether the column is being newly created, if not
  5862. * we're updating an existing column, and some items such as the sort shouldn't
  5863. * be copied down
  5864. */
  5865. GridColumn.prototype.updateColumnDef = function(colDef, isNew) {
  5866. var self = this;
  5867. self.colDef = colDef;
  5868. if (colDef.name === undefined) {
  5869. throw new Error('colDef.name is required for column at index ' + self.grid.options.columnDefs.indexOf(colDef));
  5870. }
  5871. self.displayName = (colDef.displayName === undefined) ? gridUtil.readableColumnName(colDef.name) : colDef.displayName;
  5872. if (!angular.isNumber(self.width) || !self.hasCustomWidth || colDef.allowCustomWidthOverride) {
  5873. var colDefWidth = colDef.width;
  5874. var parseErrorMsg = "Cannot parse column width '" + colDefWidth + "' for column named '" + colDef.name + "'";
  5875. self.hasCustomWidth = false;
  5876. if (!angular.isString(colDefWidth) && !angular.isNumber(colDefWidth)) {
  5877. self.width = '*';
  5878. } else if (angular.isString(colDefWidth)) {
  5879. // See if it ends with a percent
  5880. if (gridUtil.endsWith(colDefWidth, '%')) {
  5881. // If so we should be able to parse the non-percent-sign part to a number
  5882. var percentStr = colDefWidth.replace(/%/g, '');
  5883. var percent = parseInt(percentStr, 10);
  5884. if (isNaN(percent)) {
  5885. throw new Error(parseErrorMsg);
  5886. }
  5887. self.width = colDefWidth;
  5888. }
  5889. // And see if it's a number string
  5890. else if (colDefWidth.match(/^(\d+)$/)) {
  5891. self.width = parseInt(colDefWidth.match(/^(\d+)$/)[1], 10);
  5892. }
  5893. // Otherwise it should be a string of asterisks
  5894. else if (colDefWidth.match(/^\*+$/)) {
  5895. self.width = colDefWidth;
  5896. }
  5897. // No idea, throw an Error
  5898. else {
  5899. throw new Error(parseErrorMsg);
  5900. }
  5901. }
  5902. // Is a number, use it as the width
  5903. else {
  5904. self.width = colDefWidth;
  5905. }
  5906. }
  5907. ['minWidth', 'maxWidth'].forEach(function (name) {
  5908. var minOrMaxWidth = colDef[name];
  5909. var parseErrorMsg = "Cannot parse column " + name + " '" + minOrMaxWidth + "' for column named '" + colDef.name + "'";
  5910. if (!angular.isString(minOrMaxWidth) && !angular.isNumber(minOrMaxWidth)) {
  5911. //Sets default minWidth and maxWidth values
  5912. self[name] = ((name === 'minWidth') ? 30 : 9000);
  5913. } else if (angular.isString(minOrMaxWidth)) {
  5914. if (minOrMaxWidth.match(/^(\d+)$/)) {
  5915. self[name] = parseInt(minOrMaxWidth.match(/^(\d+)$/)[1], 10);
  5916. } else {
  5917. throw new Error(parseErrorMsg);
  5918. }
  5919. } else {
  5920. self[name] = minOrMaxWidth;
  5921. }
  5922. });
  5923. //use field if it is defined; name if it is not
  5924. self.field = (colDef.field === undefined) ? colDef.name : colDef.field;
  5925. if ( typeof( self.field ) !== 'string' ){
  5926. gridUtil.logError( 'Field is not a string, this is likely to break the code, Field is: ' + self.field );
  5927. }
  5928. self.name = colDef.name;
  5929. // Use colDef.displayName as long as it's not undefined, otherwise default to the field name
  5930. self.displayName = (colDef.displayName === undefined) ? gridUtil.readableColumnName(colDef.name) : colDef.displayName;
  5931. //self.originalIndex = index;
  5932. self.aggregationType = angular.isDefined(colDef.aggregationType) ? colDef.aggregationType : null;
  5933. self.footerCellTemplate = angular.isDefined(colDef.footerCellTemplate) ? colDef.footerCellTemplate : null;
  5934. /**
  5935. * @ngdoc property
  5936. * @name cellTooltip
  5937. * @propertyOf ui.grid.class:GridOptions.columnDef
  5938. * @description Whether or not to show a tooltip when a user hovers over the cell.
  5939. * If set to false, no tooltip. If true, the cell value is shown in the tooltip (useful
  5940. * if you have long values in your cells), if a function then that function is called
  5941. * passing in the row and the col `cellTooltip( row, col )`, and the return value is shown in the tooltip,
  5942. * if it is a static string then displays that static string.
  5943. *
  5944. * Defaults to false
  5945. *
  5946. */
  5947. if ( typeof(colDef.cellTooltip) === 'undefined' || colDef.cellTooltip === false ) {
  5948. self.cellTooltip = false;
  5949. } else if ( colDef.cellTooltip === true ){
  5950. self.cellTooltip = function(row, col) {
  5951. return self.grid.getCellValue( row, col );
  5952. };
  5953. } else if (typeof(colDef.cellTooltip) === 'function' ){
  5954. self.cellTooltip = colDef.cellTooltip;
  5955. } else {
  5956. self.cellTooltip = function ( row, col ){
  5957. return col.colDef.cellTooltip;
  5958. };
  5959. }
  5960. /**
  5961. * @ngdoc property
  5962. * @name headerTooltip
  5963. * @propertyOf ui.grid.class:GridOptions.columnDef
  5964. * @description Whether or not to show a tooltip when a user hovers over the header cell.
  5965. * If set to false, no tooltip. If true, the displayName is shown in the tooltip (useful
  5966. * if you have long values in your headers), if a function then that function is called
  5967. * passing in the row and the col `headerTooltip( col )`, and the return value is shown in the tooltip,
  5968. * if a static string then shows that static string.
  5969. *
  5970. * Defaults to false
  5971. *
  5972. */
  5973. if ( typeof(colDef.headerTooltip) === 'undefined' || colDef.headerTooltip === false ) {
  5974. self.headerTooltip = false;
  5975. } else if ( colDef.headerTooltip === true ){
  5976. self.headerTooltip = function(col) {
  5977. return col.displayName;
  5978. };
  5979. } else if (typeof(colDef.headerTooltip) === 'function' ){
  5980. self.headerTooltip = colDef.headerTooltip;
  5981. } else {
  5982. self.headerTooltip = function ( col ) {
  5983. return col.colDef.headerTooltip;
  5984. };
  5985. }
  5986. /**
  5987. * @ngdoc property
  5988. * @name footerCellClass
  5989. * @propertyOf ui.grid.class:GridOptions.columnDef
  5990. * @description footerCellClass can be a string specifying the class to append to a cell
  5991. * or it can be a function(grid, row, col, rowRenderIndex, colRenderIndex) that returns a class name
  5992. *
  5993. */
  5994. self.footerCellClass = colDef.footerCellClass;
  5995. /**
  5996. * @ngdoc property
  5997. * @name cellClass
  5998. * @propertyOf ui.grid.class:GridOptions.columnDef
  5999. * @description cellClass can be a string specifying the class to append to a cell
  6000. * or it can be a function(grid, row, col, rowRenderIndex, colRenderIndex) that returns a class name
  6001. *
  6002. */
  6003. self.cellClass = colDef.cellClass;
  6004. /**
  6005. * @ngdoc property
  6006. * @name headerCellClass
  6007. * @propertyOf ui.grid.class:GridOptions.columnDef
  6008. * @description headerCellClass can be a string specifying the class to append to a cell
  6009. * or it can be a function(grid, row, col, rowRenderIndex, colRenderIndex) that returns a class name
  6010. *
  6011. */
  6012. self.headerCellClass = colDef.headerCellClass;
  6013. /**
  6014. * @ngdoc property
  6015. * @name cellFilter
  6016. * @propertyOf ui.grid.class:GridOptions.columnDef
  6017. * @description cellFilter is a filter to apply to the content of each cell
  6018. * @example
  6019. * <pre>
  6020. * gridOptions.columnDefs[0].cellFilter = 'date'
  6021. *
  6022. */
  6023. self.cellFilter = colDef.cellFilter ? colDef.cellFilter : "";
  6024. /**
  6025. * @ngdoc boolean
  6026. * @name sortCellFiltered
  6027. * @propertyOf ui.grid.class:GridOptions.columnDef
  6028. * @description (optional) False by default. When `true` uiGrid will apply the cellFilter before
  6029. * sorting the data. Note that when using this option uiGrid will assume that the displayed value is
  6030. * a string, and use the {@link ui.grid.class:RowSorter#sortAlpha sortAlpha} `sortFn`. It is possible
  6031. * to return a non-string value from an angularjs filter, in which case you should define a {@link ui.grid.class:GridOptions.columnDef#sortingAlgorithm sortingAlgorithm}
  6032. * for the column which hanldes the returned type. You may specify one of the `sortingAlgorithms`
  6033. * found in the {@link ui.grid.RowSorter rowSorter} service.
  6034. */
  6035. self.sortCellFiltered = colDef.sortCellFiltered ? true : false;
  6036. /**
  6037. * @ngdoc boolean
  6038. * @name filterCellFiltered
  6039. * @propertyOf ui.grid.class:GridOptions.columnDef
  6040. * @description (optional) False by default. When `true` uiGrid will apply the cellFilter before
  6041. * applying "search" `filters`.
  6042. */
  6043. self.filterCellFiltered = colDef.filterCellFiltered ? true : false;
  6044. /**
  6045. * @ngdoc property
  6046. * @name headerCellFilter
  6047. * @propertyOf ui.grid.class:GridOptions.columnDef
  6048. * @description headerCellFilter is a filter to apply to the content of the column header
  6049. * @example
  6050. * <pre>
  6051. * gridOptions.columnDefs[0].headerCellFilter = 'translate'
  6052. *
  6053. */
  6054. self.headerCellFilter = colDef.headerCellFilter ? colDef.headerCellFilter : "";
  6055. /**
  6056. * @ngdoc property
  6057. * @name footerCellFilter
  6058. * @propertyOf ui.grid.class:GridOptions.columnDef
  6059. * @description footerCellFilter is a filter to apply to the content of the column footer
  6060. * @example
  6061. * <pre>
  6062. * gridOptions.columnDefs[0].footerCellFilter = 'date'
  6063. *
  6064. */
  6065. self.footerCellFilter = colDef.footerCellFilter ? colDef.footerCellFilter : "";
  6066. self.visible = gridUtil.isNullOrUndefined(colDef.visible) || colDef.visible;
  6067. self.headerClass = colDef.headerClass;
  6068. //self.cursor = self.sortable ? 'pointer' : 'default';
  6069. // Turn on sorting by default
  6070. self.enableSorting = typeof(colDef.enableSorting) !== 'undefined' ? colDef.enableSorting : true;
  6071. self.sortingAlgorithm = colDef.sortingAlgorithm;
  6072. /**
  6073. * @ngdoc property
  6074. * @name sortDirectionCycle
  6075. * @propertyOf ui.grid.class:GridOptions.columnDef
  6076. * @description (optional) An array of sort directions, specifying the order that they
  6077. * should cycle through as the user repeatedly clicks on the column heading.
  6078. * The default is `[null, uiGridConstants.ASC, uiGridConstants.DESC]`. Null
  6079. * refers to the unsorted state. This does not affect the initial sort
  6080. * direction; use the {@link ui.grid.class:GridOptions.columnDef#sort sort}
  6081. * property for that. If
  6082. * {@link ui.grid.class:GridOptions.columnDef#suppressRemoveSort suppressRemoveSort}
  6083. * is also set, the unsorted state will be skipped even if it is listed here.
  6084. * Each direction may not appear in the list more than once (e.g. `[ASC,
  6085. * DESC, DESC]` is not allowed), and the list may not be empty.
  6086. */
  6087. self.sortDirectionCycle = typeof(colDef.sortDirectionCycle) !== 'undefined' ?
  6088. colDef.sortDirectionCycle :
  6089. [null, uiGridConstants.ASC, uiGridConstants.DESC];
  6090. /**
  6091. * @ngdoc boolean
  6092. * @name suppressRemoveSort
  6093. * @propertyOf ui.grid.class:GridOptions.columnDef
  6094. * @description (optional) False by default. When enabled, this setting hides the removeSort option
  6095. * in the menu, and prevents users from manually removing the sort
  6096. */
  6097. if ( typeof(self.suppressRemoveSort) === 'undefined'){
  6098. self.suppressRemoveSort = typeof(colDef.suppressRemoveSort) !== 'undefined' ? colDef.suppressRemoveSort : false;
  6099. }
  6100. /**
  6101. * @ngdoc property
  6102. * @name enableFiltering
  6103. * @propertyOf ui.grid.class:GridOptions.columnDef
  6104. * @description turn off filtering for an individual column, where
  6105. * you've turned on filtering for the overall grid
  6106. * @example
  6107. * <pre>
  6108. * gridOptions.columnDefs[0].enableFiltering = false;
  6109. *
  6110. */
  6111. // Turn on filtering by default (it's disabled by default at the Grid level)
  6112. self.enableFiltering = typeof(colDef.enableFiltering) !== 'undefined' ? colDef.enableFiltering : true;
  6113. // self.menuItems = colDef.menuItems;
  6114. self.setPropertyOrDefault(colDef, 'menuItems', []);
  6115. // Use the column definition sort if we were passed it, but only if this is a newly added column
  6116. if ( isNew ){
  6117. self.setPropertyOrDefault(colDef, 'sort');
  6118. }
  6119. // Set up default filters array for when one is not provided.
  6120. // In other words, this (in column def):
  6121. //
  6122. // filter: { term: 'something', flags: {}, condition: [CONDITION] }
  6123. //
  6124. // is just shorthand for this:
  6125. //
  6126. // filters: [{ term: 'something', flags: {}, condition: [CONDITION] }]
  6127. //
  6128. var defaultFilters = [];
  6129. if (colDef.filter) {
  6130. defaultFilters.push(colDef.filter);
  6131. }
  6132. else if ( colDef.filters ){
  6133. defaultFilters = colDef.filters;
  6134. } else {
  6135. // Add an empty filter definition object, which will
  6136. // translate to a guessed condition and no pre-populated
  6137. // value for the filter <input>.
  6138. defaultFilters.push({});
  6139. }
  6140. /**
  6141. * @ngdoc property
  6142. * @name filter
  6143. * @propertyOf ui.grid.class:GridOptions.columnDef
  6144. * @description Specify a single filter field on this column.
  6145. *
  6146. * A filter consists of a condition, a term, and a placeholder:
  6147. *
  6148. * - condition defines how rows are chosen as matching the filter term. This can be set to
  6149. * one of the constants in uiGridConstants.filter, or you can supply a custom filter function
  6150. * that gets passed the following arguments: [searchTerm, cellValue, row, column].
  6151. * - term: If set, the filter field will be pre-populated
  6152. * with this value.
  6153. * - placeholder: String that will be set to the `<input>.placeholder` attribute.
  6154. * - ariaLabel: String that will be set to the `<input>.ariaLabel` attribute. This is what is read as a label to screen reader users.
  6155. * - noTerm: set this to true if you have defined a custom function in condition, and
  6156. * your custom function doesn't require a term (so it can run even when the term is null)
  6157. * - flags: only flag currently available is `caseSensitive`, set to false if you don't want
  6158. * case sensitive matching
  6159. * - type: defaults to uiGridConstants.filter.INPUT, which gives a text box. If set to uiGridConstants.filter.SELECT
  6160. * then a select box will be shown with options selectOptions
  6161. * - selectOptions: options in the format `[ { value: 1, label: 'male' }]`. No i18n filter is provided, you need
  6162. * to perform the i18n on the values before you provide them
  6163. * - disableCancelFilterButton: defaults to false. If set to true then the 'x' button that cancels/clears the filter
  6164. * will not be shown.
  6165. * @example
  6166. * <pre>$scope.gridOptions.columnDefs = [
  6167. * {
  6168. * field: 'field1',
  6169. * filter: {
  6170. * term: 'xx',
  6171. * condition: uiGridConstants.filter.STARTS_WITH,
  6172. * placeholder: 'starts with...',
  6173. * ariaLabel: 'Starts with filter for field1',
  6174. * flags: { caseSensitive: false },
  6175. * type: uiGridConstants.filter.SELECT,
  6176. * selectOptions: [ { value: 1, label: 'male' }, { value: 2, label: 'female' } ],
  6177. * disableCancelFilterButton: true
  6178. * }
  6179. * }
  6180. * ]; </pre>
  6181. *
  6182. */
  6183. /*
  6184. /*
  6185. self.filters = [
  6186. {
  6187. term: 'search term'
  6188. condition: uiGridConstants.filter.CONTAINS,
  6189. placeholder: 'my placeholder',
  6190. ariaLabel: 'Starts with filter for field1',
  6191. flags: {
  6192. caseSensitive: true
  6193. }
  6194. }
  6195. ]
  6196. */
  6197. // Only set filter if this is a newly added column, if we're updating an existing
  6198. // column then we don't want to put the default filter back if the user may have already
  6199. // removed it.
  6200. // However, we do want to keep the settings if they change, just not the term
  6201. if ( isNew ) {
  6202. self.setPropertyOrDefault(colDef, 'filter');
  6203. self.setPropertyOrDefault(colDef, 'filters', defaultFilters);
  6204. } else if ( self.filters.length === defaultFilters.length ) {
  6205. self.filters.forEach( function( filter, index ){
  6206. if (typeof(defaultFilters[index].placeholder) !== 'undefined') {
  6207. filter.placeholder = defaultFilters[index].placeholder;
  6208. }
  6209. if (typeof(defaultFilters[index].ariaLabel) !== 'undefined') {
  6210. filter.ariaLabel = defaultFilters[index].ariaLabel;
  6211. }
  6212. if (typeof(defaultFilters[index].flags) !== 'undefined') {
  6213. filter.flags = defaultFilters[index].flags;
  6214. }
  6215. if (typeof(defaultFilters[index].type) !== 'undefined') {
  6216. filter.type = defaultFilters[index].type;
  6217. }
  6218. if (typeof(defaultFilters[index].selectOptions) !== 'undefined') {
  6219. filter.selectOptions = defaultFilters[index].selectOptions;
  6220. }
  6221. });
  6222. }
  6223. };
  6224. /**
  6225. * @ngdoc function
  6226. * @name unsort
  6227. * @methodOf ui.grid.class:GridColumn
  6228. * @description Removes column from the grid sorting
  6229. */
  6230. GridColumn.prototype.unsort = function () {
  6231. this.sort = {};
  6232. this.grid.api.core.raise.sortChanged( this.grid, this.grid.getColumnSorting() );
  6233. };
  6234. /**
  6235. * @ngdoc function
  6236. * @name getColClass
  6237. * @methodOf ui.grid.class:GridColumn
  6238. * @description Returns the class name for the column
  6239. * @param {bool} prefixDot if true, will return .className instead of className
  6240. */
  6241. GridColumn.prototype.getColClass = function (prefixDot) {
  6242. var cls = uiGridConstants.COL_CLASS_PREFIX + this.uid;
  6243. return prefixDot ? '.' + cls : cls;
  6244. };
  6245. /**
  6246. * @ngdoc function
  6247. * @name isPinnedLeft
  6248. * @methodOf ui.grid.class:GridColumn
  6249. * @description Returns true if column is in the left render container
  6250. */
  6251. GridColumn.prototype.isPinnedLeft = function () {
  6252. return this.renderContainer === 'left';
  6253. };
  6254. /**
  6255. * @ngdoc function
  6256. * @name isPinnedRight
  6257. * @methodOf ui.grid.class:GridColumn
  6258. * @description Returns true if column is in the right render container
  6259. */
  6260. GridColumn.prototype.isPinnedRight = function () {
  6261. return this.renderContainer === 'right';
  6262. };
  6263. /**
  6264. * @ngdoc function
  6265. * @name getColClassDefinition
  6266. * @methodOf ui.grid.class:GridColumn
  6267. * @description Returns the class definition for th column
  6268. */
  6269. GridColumn.prototype.getColClassDefinition = function () {
  6270. return ' .grid' + this.grid.id + ' ' + this.getColClass(true) + ' { min-width: ' + this.drawnWidth + 'px; max-width: ' + this.drawnWidth + 'px; }';
  6271. };
  6272. /**
  6273. * @ngdoc function
  6274. * @name getRenderContainer
  6275. * @methodOf ui.grid.class:GridColumn
  6276. * @description Returns the render container object that this column belongs to.
  6277. *
  6278. * Columns will be default be in the `body` render container if they aren't allocated to one specifically.
  6279. */
  6280. GridColumn.prototype.getRenderContainer = function getRenderContainer() {
  6281. var self = this;
  6282. var containerId = self.renderContainer;
  6283. if (containerId === null || containerId === '' || containerId === undefined) {
  6284. containerId = 'body';
  6285. }
  6286. return self.grid.renderContainers[containerId];
  6287. };
  6288. /**
  6289. * @ngdoc function
  6290. * @name showColumn
  6291. * @methodOf ui.grid.class:GridColumn
  6292. * @description Makes the column visible by setting colDef.visible = true
  6293. */
  6294. GridColumn.prototype.showColumn = function() {
  6295. this.colDef.visible = true;
  6296. };
  6297. /**
  6298. * @ngdoc property
  6299. * @name aggregationHideLabel
  6300. * @propertyOf ui.grid.class:GridOptions.columnDef
  6301. * @description defaults to false, if set to true hides the label text
  6302. * in the aggregation footer, so only the value is displayed.
  6303. *
  6304. */
  6305. /**
  6306. * @ngdoc function
  6307. * @name getAggregationText
  6308. * @methodOf ui.grid.class:GridColumn
  6309. * @description Gets the aggregation label from colDef.aggregationLabel if
  6310. * specified or by using i18n, including deciding whether or not to display
  6311. * based on colDef.aggregationHideLabel.
  6312. *
  6313. * @param {string} label the i18n lookup value to use for the column label
  6314. *
  6315. */
  6316. GridColumn.prototype.getAggregationText = function () {
  6317. var self = this;
  6318. if ( self.colDef.aggregationHideLabel ){
  6319. return '';
  6320. }
  6321. else if ( self.colDef.aggregationLabel ) {
  6322. return self.colDef.aggregationLabel;
  6323. }
  6324. else {
  6325. switch ( self.colDef.aggregationType ){
  6326. case uiGridConstants.aggregationTypes.count:
  6327. return i18nService.getSafeText('aggregation.count');
  6328. case uiGridConstants.aggregationTypes.sum:
  6329. return i18nService.getSafeText('aggregation.sum');
  6330. case uiGridConstants.aggregationTypes.avg:
  6331. return i18nService.getSafeText('aggregation.avg');
  6332. case uiGridConstants.aggregationTypes.min:
  6333. return i18nService.getSafeText('aggregation.min');
  6334. case uiGridConstants.aggregationTypes.max:
  6335. return i18nService.getSafeText('aggregation.max');
  6336. default:
  6337. return '';
  6338. }
  6339. }
  6340. };
  6341. GridColumn.prototype.getCellTemplate = function () {
  6342. var self = this;
  6343. return self.cellTemplatePromise;
  6344. };
  6345. GridColumn.prototype.getCompiledElementFn = function () {
  6346. var self = this;
  6347. return self.compiledElementFnDefer.promise;
  6348. };
  6349. return GridColumn;
  6350. }]);
  6351. })();
  6352. (function(){
  6353. angular.module('ui.grid')
  6354. .factory('GridOptions', ['gridUtil','uiGridConstants', function(gridUtil,uiGridConstants) {
  6355. /**
  6356. * @ngdoc function
  6357. * @name ui.grid.class:GridOptions
  6358. * @description Default GridOptions class. GridOptions are defined by the application developer and overlaid
  6359. * over this object. Setting gridOptions within your controller is the most common method for an application
  6360. * developer to configure the behaviour of their ui-grid
  6361. *
  6362. * @example To define your gridOptions within your controller:
  6363. * <pre>$scope.gridOptions = {
  6364. * data: $scope.myData,
  6365. * columnDefs: [
  6366. * { name: 'field1', displayName: 'pretty display name' },
  6367. * { name: 'field2', visible: false }
  6368. * ]
  6369. * };</pre>
  6370. *
  6371. * You can then use this within your html template, when you define your grid:
  6372. * <pre>&lt;div ui-grid="gridOptions"&gt;&lt;/div&gt;</pre>
  6373. *
  6374. * To provide default options for all of the grids within your application, use an angular
  6375. * decorator to modify the GridOptions factory.
  6376. * <pre>
  6377. * app.config(function($provide){
  6378. * $provide.decorator('GridOptions',function($delegate){
  6379. * var gridOptions;
  6380. * gridOptions = angular.copy($delegate);
  6381. * gridOptions.initialize = function(options) {
  6382. * var initOptions;
  6383. * initOptions = $delegate.initialize(options);
  6384. * initOptions.enableColumnMenus = false;
  6385. * return initOptions;
  6386. * };
  6387. * return gridOptions;
  6388. * });
  6389. * });
  6390. * </pre>
  6391. */
  6392. return {
  6393. initialize: function( baseOptions ){
  6394. /**
  6395. * @ngdoc function
  6396. * @name onRegisterApi
  6397. * @propertyOf ui.grid.class:GridOptions
  6398. * @description A callback that returns the gridApi once the grid is instantiated, which is
  6399. * then used to interact with the grid programatically.
  6400. *
  6401. * Note that the gridApi.core.renderingComplete event is identical to this
  6402. * callback, but has the advantage that it can be called from multiple places
  6403. * if needed
  6404. *
  6405. * @example
  6406. * <pre>
  6407. * $scope.gridOptions.onRegisterApi = function ( gridApi ) {
  6408. * $scope.gridApi = gridApi;
  6409. * $scope.gridApi.selection.selectAllRows( $scope.gridApi.grid );
  6410. * };
  6411. * </pre>
  6412. *
  6413. */
  6414. baseOptions.onRegisterApi = baseOptions.onRegisterApi || angular.noop();
  6415. /**
  6416. * @ngdoc object
  6417. * @name data
  6418. * @propertyOf ui.grid.class:GridOptions
  6419. * @description (mandatory) Array of data to be rendered into the grid, providing the data source or data binding for
  6420. * the grid.
  6421. *
  6422. * Most commonly the data is an array of objects, where each object has a number of attributes.
  6423. * Each attribute automatically becomes a column in your grid. This array could, for example, be sourced from
  6424. * an angularJS $resource query request. The array can also contain complex objects, refer the binding tutorial
  6425. * for examples of that.
  6426. *
  6427. * The most flexible usage is to set your data on $scope:
  6428. *
  6429. * `$scope.data = data;`
  6430. *
  6431. * And then direct the grid to resolve whatever is in $scope.data:
  6432. *
  6433. * `$scope.gridOptions.data = 'data';`
  6434. *
  6435. * This is the most flexible approach as it allows you to replace $scope.data whenever you feel like it without
  6436. * getting pointer issues.
  6437. *
  6438. * Alternatively you can directly set the data array:
  6439. *
  6440. * `$scope.gridOptions.data = [ ];`
  6441. * or
  6442. *
  6443. * `$http.get('/data/100.json')
  6444. * .success(function(data) {
  6445. * $scope.myData = data;
  6446. * $scope.gridOptions.data = $scope.myData;
  6447. * });`
  6448. *
  6449. * Where you do this, you need to take care in updating the data - you can't just update `$scope.myData` to some other
  6450. * array, you need to update $scope.gridOptions.data to point to that new array as well.
  6451. *
  6452. */
  6453. baseOptions.data = baseOptions.data || [];
  6454. /**
  6455. * @ngdoc array
  6456. * @name columnDefs
  6457. * @propertyOf ui.grid.class:GridOptions
  6458. * @description Array of columnDef objects. Only required property is name.
  6459. * The individual options available in columnDefs are documented in the
  6460. * {@link ui.grid.class:GridOptions.columnDef columnDef} section
  6461. * </br>_field property can be used in place of name for backwards compatibility with 2.x_
  6462. * @example
  6463. *
  6464. * <pre>var columnDefs = [{name:'field1'}, {name:'field2'}];</pre>
  6465. *
  6466. */
  6467. baseOptions.columnDefs = baseOptions.columnDefs || [];
  6468. /**
  6469. * @ngdoc object
  6470. * @name ui.grid.class:GridOptions.columnDef
  6471. * @description Definition / configuration of an individual column, which would typically be
  6472. * one of many column definitions within the gridOptions.columnDefs array
  6473. * @example
  6474. * <pre>{name:'field1', field: 'field1', filter: { term: 'xxx' }}</pre>
  6475. *
  6476. */
  6477. /**
  6478. * @ngdoc array
  6479. * @name excludeProperties
  6480. * @propertyOf ui.grid.class:GridOptions
  6481. * @description Array of property names in data to ignore when auto-generating column names. Provides the
  6482. * inverse of columnDefs - columnDefs is a list of columns to include, excludeProperties is a list of columns
  6483. * to exclude.
  6484. *
  6485. * If columnDefs is defined, this will be ignored.
  6486. *
  6487. * Defaults to ['$$hashKey']
  6488. */
  6489. baseOptions.excludeProperties = baseOptions.excludeProperties || ['$$hashKey'];
  6490. /**
  6491. * @ngdoc boolean
  6492. * @name enableRowHashing
  6493. * @propertyOf ui.grid.class:GridOptions
  6494. * @description True by default. When enabled, this setting allows uiGrid to add
  6495. * `$$hashKey`-type properties (similar to Angular) to elements in the `data` array. This allows
  6496. * the grid to maintain state while vastly speeding up the process of altering `data` by adding/moving/removing rows.
  6497. *
  6498. * Note that this DOES add properties to your data that you may not want, but they are stripped out when using `angular.toJson()`. IF
  6499. * you do not want this at all you can disable this setting but you will take a performance hit if you are using large numbers of rows
  6500. * and are altering the data set often.
  6501. */
  6502. baseOptions.enableRowHashing = baseOptions.enableRowHashing !== false;
  6503. /**
  6504. * @ngdoc function
  6505. * @name rowIdentity
  6506. * @methodOf ui.grid.class:GridOptions
  6507. * @description This function is used to get and, if necessary, set the value uniquely identifying this row (i.e. if an identity is not present it will set one).
  6508. *
  6509. * By default it returns the `$$hashKey` property if it exists. If it doesn't it uses gridUtil.nextUid() to generate one
  6510. */
  6511. baseOptions.rowIdentity = baseOptions.rowIdentity || function rowIdentity(row) {
  6512. return gridUtil.hashKey(row);
  6513. };
  6514. /**
  6515. * @ngdoc function
  6516. * @name getRowIdentity
  6517. * @methodOf ui.grid.class:GridOptions
  6518. * @description This function returns the identity value uniquely identifying this row, if one is not present it does not set it.
  6519. *
  6520. * By default it returns the `$$hashKey` property but can be overridden to use any property or set of properties you want.
  6521. */
  6522. baseOptions.getRowIdentity = baseOptions.getRowIdentity || function getRowIdentity(row) {
  6523. return row.$$hashKey;
  6524. };
  6525. /**
  6526. * @ngdoc property
  6527. * @name flatEntityAccess
  6528. * @propertyOf ui.grid.class:GridOptions
  6529. * @description Set to true if your columns are all related directly to fields in a flat object structure - i.e.
  6530. * each of your columns associate directly with a property on each of the entities in your data array.
  6531. *
  6532. * In that situation we can avoid all the logic associated with complex binding to functions or to properties of sub-objects,
  6533. * which can provide a significant speed improvement with large data sets when filtering or sorting.
  6534. *
  6535. * By default false
  6536. */
  6537. baseOptions.flatEntityAccess = baseOptions.flatEntityAccess === true;
  6538. /**
  6539. * @ngdoc property
  6540. * @name showHeader
  6541. * @propertyOf ui.grid.class:GridOptions
  6542. * @description True by default. When set to false, this setting will replace the
  6543. * standard header template with '<div></div>', resulting in no header being shown.
  6544. */
  6545. baseOptions.showHeader = typeof(baseOptions.showHeader) !== "undefined" ? baseOptions.showHeader : true;
  6546. /* (NOTE): Don't show this in the docs. We only use it internally
  6547. * @ngdoc property
  6548. * @name headerRowHeight
  6549. * @propertyOf ui.grid.class:GridOptions
  6550. * @description The height of the header in pixels, defaults to 30
  6551. *
  6552. */
  6553. if (!baseOptions.showHeader) {
  6554. baseOptions.headerRowHeight = 0;
  6555. }
  6556. else {
  6557. baseOptions.headerRowHeight = typeof(baseOptions.headerRowHeight) !== "undefined" ? baseOptions.headerRowHeight : 30;
  6558. }
  6559. /**
  6560. * @ngdoc property
  6561. * @name rowHeight
  6562. * @propertyOf ui.grid.class:GridOptions
  6563. * @description The height of the row in pixels, defaults to 30
  6564. *
  6565. */
  6566. baseOptions.rowHeight = baseOptions.rowHeight || 30;
  6567. /**
  6568. * @ngdoc integer
  6569. * @name minRowsToShow
  6570. * @propertyOf ui.grid.class:GridOptions
  6571. * @description Minimum number of rows to show when the grid doesn't have a defined height. Defaults to "10".
  6572. */
  6573. baseOptions.minRowsToShow = typeof(baseOptions.minRowsToShow) !== "undefined" ? baseOptions.minRowsToShow : 10;
  6574. /**
  6575. * @ngdoc property
  6576. * @name showGridFooter
  6577. * @propertyOf ui.grid.class:GridOptions
  6578. * @description Whether or not to show the footer, defaults to false
  6579. * The footer display Total Rows and Visible Rows (filtered rows)
  6580. */
  6581. baseOptions.showGridFooter = baseOptions.showGridFooter === true;
  6582. /**
  6583. * @ngdoc property
  6584. * @name showColumnFooter
  6585. * @propertyOf ui.grid.class:GridOptions
  6586. * @description Whether or not to show the column footer, defaults to false
  6587. * The column footer displays column aggregates
  6588. */
  6589. baseOptions.showColumnFooter = baseOptions.showColumnFooter === true;
  6590. /**
  6591. * @ngdoc property
  6592. * @name columnFooterHeight
  6593. * @propertyOf ui.grid.class:GridOptions
  6594. * @description The height of the footer rows (column footer and grid footer) in pixels
  6595. *
  6596. */
  6597. baseOptions.columnFooterHeight = typeof(baseOptions.columnFooterHeight) !== "undefined" ? baseOptions.columnFooterHeight : 30;
  6598. baseOptions.gridFooterHeight = typeof(baseOptions.gridFooterHeight) !== "undefined" ? baseOptions.gridFooterHeight : 30;
  6599. baseOptions.columnWidth = typeof(baseOptions.columnWidth) !== "undefined" ? baseOptions.columnWidth : 50;
  6600. /**
  6601. * @ngdoc property
  6602. * @name maxVisibleColumnCount
  6603. * @propertyOf ui.grid.class:GridOptions
  6604. * @description Defaults to 200
  6605. *
  6606. */
  6607. baseOptions.maxVisibleColumnCount = typeof(baseOptions.maxVisibleColumnCount) !== "undefined" ? baseOptions.maxVisibleColumnCount : 200;
  6608. /**
  6609. * @ngdoc property
  6610. * @name virtualizationThreshold
  6611. * @propertyOf ui.grid.class:GridOptions
  6612. * @description Turn virtualization on when number of data elements goes over this number, defaults to 20
  6613. */
  6614. baseOptions.virtualizationThreshold = typeof(baseOptions.virtualizationThreshold) !== "undefined" ? baseOptions.virtualizationThreshold : 20;
  6615. /**
  6616. * @ngdoc property
  6617. * @name columnVirtualizationThreshold
  6618. * @propertyOf ui.grid.class:GridOptions
  6619. * @description Turn virtualization on when number of columns goes over this number, defaults to 10
  6620. */
  6621. baseOptions.columnVirtualizationThreshold = typeof(baseOptions.columnVirtualizationThreshold) !== "undefined" ? baseOptions.columnVirtualizationThreshold : 10;
  6622. /**
  6623. * @ngdoc property
  6624. * @name excessRows
  6625. * @propertyOf ui.grid.class:GridOptions
  6626. * @description Extra rows to to render outside of the viewport, which helps with smoothness of scrolling.
  6627. * Defaults to 4
  6628. */
  6629. baseOptions.excessRows = typeof(baseOptions.excessRows) !== "undefined" ? baseOptions.excessRows : 4;
  6630. /**
  6631. * @ngdoc property
  6632. * @name scrollThreshold
  6633. * @propertyOf ui.grid.class:GridOptions
  6634. * @description Defaults to 4
  6635. */
  6636. baseOptions.scrollThreshold = typeof(baseOptions.scrollThreshold) !== "undefined" ? baseOptions.scrollThreshold : 4;
  6637. /**
  6638. * @ngdoc property
  6639. * @name excessColumns
  6640. * @propertyOf ui.grid.class:GridOptions
  6641. * @description Extra columns to to render outside of the viewport, which helps with smoothness of scrolling.
  6642. * Defaults to 4
  6643. */
  6644. baseOptions.excessColumns = typeof(baseOptions.excessColumns) !== "undefined" ? baseOptions.excessColumns : 4;
  6645. /**
  6646. * @ngdoc property
  6647. * @name horizontalScrollThreshold
  6648. * @propertyOf ui.grid.class:GridOptions
  6649. * @description Defaults to 4
  6650. */
  6651. baseOptions.horizontalScrollThreshold = typeof(baseOptions.horizontalScrollThreshold) !== "undefined" ? baseOptions.horizontalScrollThreshold : 2;
  6652. /**
  6653. * @ngdoc property
  6654. * @name aggregationCalcThrottle
  6655. * @propertyOf ui.grid.class:GridOptions
  6656. * @description Default time in milliseconds to throttle aggregation calcuations, defaults to 500ms
  6657. */
  6658. baseOptions.aggregationCalcThrottle = typeof(baseOptions.aggregationCalcThrottle) !== "undefined" ? baseOptions.aggregationCalcThrottle : 500;
  6659. /**
  6660. * @ngdoc property
  6661. * @name wheelScrollThrottle
  6662. * @propertyOf ui.grid.class:GridOptions
  6663. * @description Default time in milliseconds to throttle scroll events to, defaults to 70ms
  6664. */
  6665. baseOptions.wheelScrollThrottle = typeof(baseOptions.wheelScrollThrottle) !== "undefined" ? baseOptions.wheelScrollThrottle : 70;
  6666. /**
  6667. * @ngdoc property
  6668. * @name scrollDebounce
  6669. * @propertyOf ui.grid.class:GridOptions
  6670. * @description Default time in milliseconds to debounce scroll events, defaults to 300ms
  6671. */
  6672. baseOptions.scrollDebounce = typeof(baseOptions.scrollDebounce) !== "undefined" ? baseOptions.scrollDebounce : 300;
  6673. /**
  6674. * @ngdoc boolean
  6675. * @name enableSorting
  6676. * @propertyOf ui.grid.class:GridOptions
  6677. * @description True by default. When enabled, this setting adds sort
  6678. * widgets to the column headers, allowing sorting of the data for the entire grid.
  6679. * Sorting can then be disabled on individual columns using the columnDefs.
  6680. */
  6681. baseOptions.enableSorting = baseOptions.enableSorting !== false;
  6682. /**
  6683. * @ngdoc boolean
  6684. * @name enableFiltering
  6685. * @propertyOf ui.grid.class:GridOptions
  6686. * @description False by default. When enabled, this setting adds filter
  6687. * boxes to each column header, allowing filtering within the column for the entire grid.
  6688. * Filtering can then be disabled on individual columns using the columnDefs.
  6689. */
  6690. baseOptions.enableFiltering = baseOptions.enableFiltering === true;
  6691. /**
  6692. * @ngdoc boolean
  6693. * @name enableColumnMenus
  6694. * @propertyOf ui.grid.class:GridOptions
  6695. * @description True by default. When enabled, this setting displays a column
  6696. * menu within each column.
  6697. */
  6698. baseOptions.enableColumnMenus = baseOptions.enableColumnMenus !== false;
  6699. /**
  6700. * @ngdoc boolean
  6701. * @name enableVerticalScrollbar
  6702. * @propertyOf ui.grid.class:GridOptions
  6703. * @description uiGridConstants.scrollbars.ALWAYS by default. This settings controls the vertical scrollbar for the grid.
  6704. * Supported values: uiGridConstants.scrollbars.ALWAYS, uiGridConstants.scrollbars.NEVER
  6705. */
  6706. baseOptions.enableVerticalScrollbar = typeof(baseOptions.enableVerticalScrollbar) !== "undefined" ? baseOptions.enableVerticalScrollbar : uiGridConstants.scrollbars.ALWAYS;
  6707. /**
  6708. * @ngdoc boolean
  6709. * @name enableHorizontalScrollbar
  6710. * @propertyOf ui.grid.class:GridOptions
  6711. * @description uiGridConstants.scrollbars.ALWAYS by default. This settings controls the horizontal scrollbar for the grid.
  6712. * Supported values: uiGridConstants.scrollbars.ALWAYS, uiGridConstants.scrollbars.NEVER
  6713. */
  6714. baseOptions.enableHorizontalScrollbar = typeof(baseOptions.enableHorizontalScrollbar) !== "undefined" ? baseOptions.enableHorizontalScrollbar : uiGridConstants.scrollbars.ALWAYS;
  6715. /**
  6716. * @ngdoc boolean
  6717. * @name enableMinHeightCheck
  6718. * @propertyOf ui.grid.class:GridOptions
  6719. * @description True by default. When enabled, a newly initialized grid will check to see if it is tall enough to display
  6720. * at least one row of data. If the grid is not tall enough, it will resize the DOM element to display minRowsToShow number
  6721. * of rows.
  6722. */
  6723. baseOptions.enableMinHeightCheck = baseOptions.enableMinHeightCheck !== false;
  6724. /**
  6725. * @ngdoc boolean
  6726. * @name minimumColumnSize
  6727. * @propertyOf ui.grid.class:GridOptions
  6728. * @description Columns can't be smaller than this, defaults to 10 pixels
  6729. */
  6730. baseOptions.minimumColumnSize = typeof(baseOptions.minimumColumnSize) !== "undefined" ? baseOptions.minimumColumnSize : 10;
  6731. /**
  6732. * @ngdoc function
  6733. * @name rowEquality
  6734. * @methodOf ui.grid.class:GridOptions
  6735. * @description By default, rows are compared using object equality. This option can be overridden
  6736. * to compare on any data item property or function
  6737. * @param {object} entityA First Data Item to compare
  6738. * @param {object} entityB Second Data Item to compare
  6739. */
  6740. baseOptions.rowEquality = baseOptions.rowEquality || function(entityA, entityB) {
  6741. return entityA === entityB;
  6742. };
  6743. /**
  6744. * @ngdoc string
  6745. * @name headerTemplate
  6746. * @propertyOf ui.grid.class:GridOptions
  6747. * @description Null by default. When provided, this setting uses a custom header
  6748. * template, rather than the default template. Can be set to either the name of a template file:
  6749. * <pre> $scope.gridOptions.headerTemplate = 'header_template.html';</pre>
  6750. * inline html
  6751. * <pre> $scope.gridOptions.headerTemplate = '<div class="ui-grid-top-panel" style="text-align: center">I am a Custom Grid Header</div>'</pre>
  6752. * or the id of a precompiled template (TBD how to use this).
  6753. * </br>Refer to the custom header tutorial for more information.
  6754. * If you want no header at all, you can set to an empty div:
  6755. * <pre> $scope.gridOptions.headerTemplate = '<div></div>';</pre>
  6756. *
  6757. * If you want to only have a static header, then you can set to static content. If
  6758. * you want to tailor the existing column headers, then you should look at the
  6759. * current 'ui-grid-header.html' template in github as your starting point.
  6760. *
  6761. */
  6762. baseOptions.headerTemplate = baseOptions.headerTemplate || null;
  6763. /**
  6764. * @ngdoc string
  6765. * @name footerTemplate
  6766. * @propertyOf ui.grid.class:GridOptions
  6767. * @description (optional) ui-grid/ui-grid-footer by default. This footer shows the per-column
  6768. * aggregation totals.
  6769. * When provided, this setting uses a custom footer template. Can be set to either the name of a template file 'footer_template.html', inline html
  6770. * <pre>'<div class="ui-grid-bottom-panel" style="text-align: center">I am a Custom Grid Footer</div>'</pre>, or the id
  6771. * of a precompiled template (TBD how to use this). Refer to the custom footer tutorial for more information.
  6772. */
  6773. baseOptions.footerTemplate = baseOptions.footerTemplate || 'ui-grid/ui-grid-footer';
  6774. /**
  6775. * @ngdoc string
  6776. * @name gridFooterTemplate
  6777. * @propertyOf ui.grid.class:GridOptions
  6778. * @description (optional) ui-grid/ui-grid-grid-footer by default. This template by default shows the
  6779. * total items at the bottom of the grid, and the selected items if selection is enabled.
  6780. */
  6781. baseOptions.gridFooterTemplate = baseOptions.gridFooterTemplate || 'ui-grid/ui-grid-grid-footer';
  6782. /**
  6783. * @ngdoc string
  6784. * @name rowTemplate
  6785. * @propertyOf ui.grid.class:GridOptions
  6786. * @description 'ui-grid/ui-grid-row' by default. When provided, this setting uses a
  6787. * custom row template. Can be set to either the name of a template file:
  6788. * <pre> $scope.gridOptions.rowTemplate = 'row_template.html';</pre>
  6789. * inline html
  6790. * <pre> $scope.gridOptions.rowTemplate = '<div style="background-color: aquamarine" ng-click="grid.appScope.fnOne(row)" ng-repeat="col in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell" ui-grid-cell></div>';</pre>
  6791. * or the id of a precompiled template (TBD how to use this) can be provided.
  6792. * </br>Refer to the custom row template tutorial for more information.
  6793. */
  6794. baseOptions.rowTemplate = baseOptions.rowTemplate || 'ui-grid/ui-grid-row';
  6795. /**
  6796. * @ngdoc object
  6797. * @name appScopeProvider
  6798. * @propertyOf ui.grid.class:GridOptions
  6799. * @description by default, the parent scope of the ui-grid element will be assigned to grid.appScope
  6800. * this property allows you to assign any reference you want to grid.appScope
  6801. */
  6802. baseOptions.appScopeProvider = baseOptions.appScopeProvider || null;
  6803. return baseOptions;
  6804. }
  6805. };
  6806. }]);
  6807. })();
  6808. (function(){
  6809. angular.module('ui.grid')
  6810. /**
  6811. * @ngdoc function
  6812. * @name ui.grid.class:GridRenderContainer
  6813. * @description The grid has render containers, allowing the ability to have pinned columns. If the grid
  6814. * is right-to-left then there may be a right render container, if left-to-right then there may
  6815. * be a left render container. There is always a body render container.
  6816. * @param {string} name The name of the render container ('body', 'left', or 'right')
  6817. * @param {Grid} grid the grid the render container is in
  6818. * @param {object} options the render container options
  6819. */
  6820. .factory('GridRenderContainer', ['gridUtil', 'uiGridConstants', function(gridUtil, uiGridConstants) {
  6821. function GridRenderContainer(name, grid, options) {
  6822. var self = this;
  6823. // if (gridUtil.type(grid) !== 'Grid') {
  6824. // throw new Error('Grid argument is not a Grid object');
  6825. // }
  6826. self.name = name;
  6827. self.grid = grid;
  6828. // self.rowCache = [];
  6829. // self.columnCache = [];
  6830. self.visibleRowCache = [];
  6831. self.visibleColumnCache = [];
  6832. self.renderedRows = [];
  6833. self.renderedColumns = [];
  6834. self.prevScrollTop = 0;
  6835. self.prevScrolltopPercentage = 0;
  6836. self.prevRowScrollIndex = 0;
  6837. self.prevScrollLeft = 0;
  6838. self.prevScrollleftPercentage = 0;
  6839. self.prevColumnScrollIndex = 0;
  6840. self.columnStyles = "";
  6841. self.viewportAdjusters = [];
  6842. /**
  6843. * @ngdoc boolean
  6844. * @name hasHScrollbar
  6845. * @propertyOf ui.grid.class:GridRenderContainer
  6846. * @description flag to signal that container has a horizontal scrollbar
  6847. */
  6848. self.hasHScrollbar = false;
  6849. /**
  6850. * @ngdoc boolean
  6851. * @name hasVScrollbar
  6852. * @propertyOf ui.grid.class:GridRenderContainer
  6853. * @description flag to signal that container has a vertical scrollbar
  6854. */
  6855. self.hasVScrollbar = false;
  6856. /**
  6857. * @ngdoc boolean
  6858. * @name canvasHeightShouldUpdate
  6859. * @propertyOf ui.grid.class:GridRenderContainer
  6860. * @description flag to signal that container should recalculate the canvas size
  6861. */
  6862. self.canvasHeightShouldUpdate = true;
  6863. /**
  6864. * @ngdoc boolean
  6865. * @name canvasHeight
  6866. * @propertyOf ui.grid.class:GridRenderContainer
  6867. * @description last calculated canvas height value
  6868. */
  6869. self.$$canvasHeight = 0;
  6870. if (options && angular.isObject(options)) {
  6871. angular.extend(self, options);
  6872. }
  6873. grid.registerStyleComputation({
  6874. priority: 5,
  6875. func: function () {
  6876. self.updateColumnWidths();
  6877. return self.columnStyles;
  6878. }
  6879. });
  6880. }
  6881. GridRenderContainer.prototype.reset = function reset() {
  6882. // this.rowCache.length = 0;
  6883. // this.columnCache.length = 0;
  6884. this.visibleColumnCache.length = 0;
  6885. this.visibleRowCache.length = 0;
  6886. this.renderedRows.length = 0;
  6887. this.renderedColumns.length = 0;
  6888. };
  6889. // TODO(c0bra): calculate size?? Should this be in a stackable directive?
  6890. GridRenderContainer.prototype.containsColumn = function (col) {
  6891. return this.visibleColumnCache.indexOf(col) !== -1;
  6892. };
  6893. GridRenderContainer.prototype.minRowsToRender = function minRowsToRender() {
  6894. var self = this;
  6895. var minRows = 0;
  6896. var rowAddedHeight = 0;
  6897. var viewPortHeight = self.getViewportHeight();
  6898. for (var i = self.visibleRowCache.length - 1; rowAddedHeight < viewPortHeight && i >= 0; i--) {
  6899. rowAddedHeight += self.visibleRowCache[i].height;
  6900. minRows++;
  6901. }
  6902. return minRows;
  6903. };
  6904. GridRenderContainer.prototype.minColumnsToRender = function minColumnsToRender() {
  6905. var self = this;
  6906. var viewportWidth = this.getViewportWidth();
  6907. var min = 0;
  6908. var totalWidth = 0;
  6909. // self.columns.forEach(function(col, i) {
  6910. for (var i = 0; i < self.visibleColumnCache.length; i++) {
  6911. var col = self.visibleColumnCache[i];
  6912. if (totalWidth < viewportWidth) {
  6913. totalWidth += col.drawnWidth ? col.drawnWidth : 0;
  6914. min++;
  6915. }
  6916. else {
  6917. var currWidth = 0;
  6918. for (var j = i; j >= i - min; j--) {
  6919. currWidth += self.visibleColumnCache[j].drawnWidth ? self.visibleColumnCache[j].drawnWidth : 0;
  6920. }
  6921. if (currWidth < viewportWidth) {
  6922. min++;
  6923. }
  6924. }
  6925. }
  6926. return min;
  6927. };
  6928. GridRenderContainer.prototype.getVisibleRowCount = function getVisibleRowCount() {
  6929. return this.visibleRowCache.length;
  6930. };
  6931. /**
  6932. * @ngdoc function
  6933. * @name registerViewportAdjuster
  6934. * @methodOf ui.grid.class:GridRenderContainer
  6935. * @description Registers an adjuster to the render container's available width or height. Adjusters are used
  6936. * to tell the render container that there is something else consuming space, and to adjust it's size
  6937. * appropriately.
  6938. * @param {function} func the adjuster function we want to register
  6939. */
  6940. GridRenderContainer.prototype.registerViewportAdjuster = function registerViewportAdjuster(func) {
  6941. this.viewportAdjusters.push(func);
  6942. };
  6943. /**
  6944. * @ngdoc function
  6945. * @name removeViewportAdjuster
  6946. * @methodOf ui.grid.class:GridRenderContainer
  6947. * @description Removes an adjuster, should be used when your element is destroyed
  6948. * @param {function} func the adjuster function we want to remove
  6949. */
  6950. GridRenderContainer.prototype.removeViewportAdjuster = function removeViewportAdjuster(func) {
  6951. var idx = this.viewportAdjusters.indexOf(func);
  6952. if (idx > -1) {
  6953. this.viewportAdjusters.splice(idx, 1);
  6954. }
  6955. };
  6956. /**
  6957. * @ngdoc function
  6958. * @name getViewportAdjustment
  6959. * @methodOf ui.grid.class:GridRenderContainer
  6960. * @description Gets the adjustment based on the viewportAdjusters.
  6961. * @returns {object} a hash of { height: x, width: y }. Usually the values will be negative
  6962. */
  6963. GridRenderContainer.prototype.getViewportAdjustment = function getViewportAdjustment() {
  6964. var self = this;
  6965. var adjustment = { height: 0, width: 0 };
  6966. self.viewportAdjusters.forEach(function (func) {
  6967. adjustment = func.call(this, adjustment);
  6968. });
  6969. return adjustment;
  6970. };
  6971. GridRenderContainer.prototype.getMargin = function getMargin(side) {
  6972. var self = this;
  6973. var amount = 0;
  6974. self.viewportAdjusters.forEach(function (func) {
  6975. var adjustment = func.call(this, { height: 0, width: 0 });
  6976. if (adjustment.side && adjustment.side === side) {
  6977. amount += adjustment.width * -1;
  6978. }
  6979. });
  6980. return amount;
  6981. };
  6982. GridRenderContainer.prototype.getViewportHeight = function getViewportHeight() {
  6983. var self = this;
  6984. var headerHeight = (self.headerHeight) ? self.headerHeight : self.grid.headerHeight;
  6985. var viewPortHeight = self.grid.gridHeight - headerHeight - self.grid.footerHeight;
  6986. var adjustment = self.getViewportAdjustment();
  6987. viewPortHeight = viewPortHeight + adjustment.height;
  6988. return viewPortHeight;
  6989. };
  6990. GridRenderContainer.prototype.getViewportWidth = function getViewportWidth() {
  6991. var self = this;
  6992. var viewportWidth = self.grid.gridWidth;
  6993. //if (typeof(self.grid.verticalScrollbarWidth) !== 'undefined' && self.grid.verticalScrollbarWidth !== undefined && self.grid.verticalScrollbarWidth > 0) {
  6994. // viewPortWidth = viewPortWidth - self.grid.verticalScrollbarWidth;
  6995. //}
  6996. // var viewportWidth = 0;\
  6997. // self.visibleColumnCache.forEach(function (column) {
  6998. // viewportWidth += column.drawnWidth;
  6999. // });
  7000. var adjustment = self.getViewportAdjustment();
  7001. viewportWidth = viewportWidth + adjustment.width;
  7002. return viewportWidth;
  7003. };
  7004. GridRenderContainer.prototype.getHeaderViewportWidth = function getHeaderViewportWidth() {
  7005. var self = this;
  7006. var viewportWidth = this.getViewportWidth();
  7007. //if (typeof(self.grid.verticalScrollbarWidth) !== 'undefined' && self.grid.verticalScrollbarWidth !== undefined && self.grid.verticalScrollbarWidth > 0) {
  7008. // viewPortWidth = viewPortWidth + self.grid.verticalScrollbarWidth;
  7009. //}
  7010. // var adjustment = self.getViewportAdjustment();
  7011. // viewPortWidth = viewPortWidth + adjustment.width;
  7012. return viewportWidth;
  7013. };
  7014. /**
  7015. * @ngdoc function
  7016. * @name getCanvasHeight
  7017. * @methodOf ui.grid.class:GridRenderContainer
  7018. * @description Returns the total canvas height. Only recalculates if canvasHeightShouldUpdate = false
  7019. * @returns {number} total height of all the visible rows in the container
  7020. */
  7021. GridRenderContainer.prototype.getCanvasHeight = function getCanvasHeight() {
  7022. var self = this;
  7023. if (!self.canvasHeightShouldUpdate) {
  7024. return self.$$canvasHeight;
  7025. }
  7026. var oldCanvasHeight = self.$$canvasHeight;
  7027. self.$$canvasHeight = 0;
  7028. self.visibleRowCache.forEach(function(row){
  7029. self.$$canvasHeight += row.height;
  7030. });
  7031. self.canvasHeightShouldUpdate = false;
  7032. self.grid.api.core.raise.canvasHeightChanged(oldCanvasHeight, self.$$canvasHeight);
  7033. return self.$$canvasHeight;
  7034. };
  7035. GridRenderContainer.prototype.getVerticalScrollLength = function getVerticalScrollLength() {
  7036. return this.getCanvasHeight() - this.getViewportHeight() + this.grid.scrollbarHeight;
  7037. };
  7038. GridRenderContainer.prototype.getCanvasWidth = function getCanvasWidth() {
  7039. var self = this;
  7040. var ret = self.canvasWidth;
  7041. return ret;
  7042. };
  7043. GridRenderContainer.prototype.setRenderedRows = function setRenderedRows(newRows) {
  7044. this.renderedRows.length = newRows.length;
  7045. for (var i = 0; i < newRows.length; i++) {
  7046. this.renderedRows[i] = newRows[i];
  7047. }
  7048. };
  7049. GridRenderContainer.prototype.setRenderedColumns = function setRenderedColumns(newColumns) {
  7050. var self = this;
  7051. // OLD:
  7052. this.renderedColumns.length = newColumns.length;
  7053. for (var i = 0; i < newColumns.length; i++) {
  7054. this.renderedColumns[i] = newColumns[i];
  7055. }
  7056. this.updateColumnOffset();
  7057. };
  7058. GridRenderContainer.prototype.updateColumnOffset = function updateColumnOffset() {
  7059. // Calculate the width of the columns on the left side that are no longer rendered.
  7060. // That will be the offset for the columns as we scroll horizontally.
  7061. var hiddenColumnsWidth = 0;
  7062. for (var i = 0; i < this.currentFirstColumn; i++) {
  7063. hiddenColumnsWidth += this.visibleColumnCache[i].drawnWidth;
  7064. }
  7065. this.columnOffset = hiddenColumnsWidth;
  7066. };
  7067. GridRenderContainer.prototype.scrollVertical = function (newScrollTop) {
  7068. var vertScrollPercentage = -1;
  7069. if (newScrollTop !== this.prevScrollTop) {
  7070. var yDiff = newScrollTop - this.prevScrollTop;
  7071. if (yDiff > 0 ) { this.grid.scrollDirection = uiGridConstants.scrollDirection.DOWN; }
  7072. if (yDiff < 0 ) { this.grid.scrollDirection = uiGridConstants.scrollDirection.UP; }
  7073. var vertScrollLength = this.getVerticalScrollLength();
  7074. vertScrollPercentage = newScrollTop / vertScrollLength;
  7075. // console.log('vert', vertScrollPercentage, newScrollTop, vertScrollLength);
  7076. if (vertScrollPercentage > 1) { vertScrollPercentage = 1; }
  7077. if (vertScrollPercentage < 0) { vertScrollPercentage = 0; }
  7078. this.adjustScrollVertical(newScrollTop, vertScrollPercentage);
  7079. return vertScrollPercentage;
  7080. }
  7081. };
  7082. GridRenderContainer.prototype.scrollHorizontal = function(newScrollLeft){
  7083. var horizScrollPercentage = -1;
  7084. // Handle RTL here
  7085. if (newScrollLeft !== this.prevScrollLeft) {
  7086. var xDiff = newScrollLeft - this.prevScrollLeft;
  7087. if (xDiff > 0) { this.grid.scrollDirection = uiGridConstants.scrollDirection.RIGHT; }
  7088. if (xDiff < 0) { this.grid.scrollDirection = uiGridConstants.scrollDirection.LEFT; }
  7089. var horizScrollLength = (this.canvasWidth - this.getViewportWidth());
  7090. if (horizScrollLength !== 0) {
  7091. horizScrollPercentage = newScrollLeft / horizScrollLength;
  7092. }
  7093. else {
  7094. horizScrollPercentage = 0;
  7095. }
  7096. this.adjustScrollHorizontal(newScrollLeft, horizScrollPercentage);
  7097. return horizScrollPercentage;
  7098. }
  7099. };
  7100. GridRenderContainer.prototype.adjustScrollVertical = function adjustScrollVertical(scrollTop, scrollPercentage, force) {
  7101. if (this.prevScrollTop === scrollTop && !force) {
  7102. return;
  7103. }
  7104. if (typeof(scrollTop) === 'undefined' || scrollTop === undefined || scrollTop === null) {
  7105. scrollTop = (this.getCanvasHeight() - this.getViewportHeight()) * scrollPercentage;
  7106. }
  7107. this.adjustRows(scrollTop, scrollPercentage, false);
  7108. this.prevScrollTop = scrollTop;
  7109. this.prevScrolltopPercentage = scrollPercentage;
  7110. this.grid.queueRefresh();
  7111. };
  7112. GridRenderContainer.prototype.adjustScrollHorizontal = function adjustScrollHorizontal(scrollLeft, scrollPercentage, force) {
  7113. if (this.prevScrollLeft === scrollLeft && !force) {
  7114. return;
  7115. }
  7116. if (typeof(scrollLeft) === 'undefined' || scrollLeft === undefined || scrollLeft === null) {
  7117. scrollLeft = (this.getCanvasWidth() - this.getViewportWidth()) * scrollPercentage;
  7118. }
  7119. this.adjustColumns(scrollLeft, scrollPercentage);
  7120. this.prevScrollLeft = scrollLeft;
  7121. this.prevScrollleftPercentage = scrollPercentage;
  7122. this.grid.queueRefresh();
  7123. };
  7124. GridRenderContainer.prototype.adjustRows = function adjustRows(scrollTop, scrollPercentage, postDataLoaded) {
  7125. var self = this;
  7126. var minRows = self.minRowsToRender();
  7127. var rowCache = self.visibleRowCache;
  7128. var maxRowIndex = rowCache.length - minRows;
  7129. // console.log('scroll%1', scrollPercentage);
  7130. // Calculate the scroll percentage according to the scrollTop location, if no percentage was provided
  7131. if ((typeof(scrollPercentage) === 'undefined' || scrollPercentage === null) && scrollTop) {
  7132. scrollPercentage = scrollTop / self.getVerticalScrollLength();
  7133. }
  7134. var rowIndex = Math.ceil(Math.min(maxRowIndex, maxRowIndex * scrollPercentage));
  7135. // console.log('maxRowIndex / scroll%', maxRowIndex, scrollPercentage, rowIndex);
  7136. // Define a max row index that we can't scroll past
  7137. if (rowIndex > maxRowIndex) {
  7138. rowIndex = maxRowIndex;
  7139. }
  7140. var newRange = [];
  7141. if (rowCache.length > self.grid.options.virtualizationThreshold) {
  7142. if (!(typeof(scrollTop) === 'undefined' || scrollTop === null)) {
  7143. // Have we hit the threshold going down?
  7144. if ( !self.grid.suppressParentScrollDown && self.prevScrollTop < scrollTop && rowIndex < self.prevRowScrollIndex + self.grid.options.scrollThreshold && rowIndex < maxRowIndex) {
  7145. return;
  7146. }
  7147. //Have we hit the threshold going up?
  7148. if ( !self.grid.suppressParentScrollUp && self.prevScrollTop > scrollTop && rowIndex > self.prevRowScrollIndex - self.grid.options.scrollThreshold && rowIndex < maxRowIndex) {
  7149. return;
  7150. }
  7151. }
  7152. var rangeStart = {};
  7153. var rangeEnd = {};
  7154. rangeStart = Math.max(0, rowIndex - self.grid.options.excessRows);
  7155. rangeEnd = Math.min(rowCache.length, rowIndex + minRows + self.grid.options.excessRows);
  7156. newRange = [rangeStart, rangeEnd];
  7157. }
  7158. else {
  7159. var maxLen = self.visibleRowCache.length;
  7160. newRange = [0, Math.max(maxLen, minRows + self.grid.options.excessRows)];
  7161. }
  7162. self.updateViewableRowRange(newRange);
  7163. self.prevRowScrollIndex = rowIndex;
  7164. };
  7165. GridRenderContainer.prototype.adjustColumns = function adjustColumns(scrollLeft, scrollPercentage) {
  7166. var self = this;
  7167. var minCols = self.minColumnsToRender();
  7168. var columnCache = self.visibleColumnCache;
  7169. var maxColumnIndex = columnCache.length - minCols;
  7170. // Calculate the scroll percentage according to the scrollLeft location, if no percentage was provided
  7171. if ((typeof(scrollPercentage) === 'undefined' || scrollPercentage === null) && scrollLeft) {
  7172. var horizScrollLength = (self.getCanvasWidth() - self.getViewportWidth());
  7173. scrollPercentage = scrollLeft / horizScrollLength;
  7174. }
  7175. var colIndex = Math.ceil(Math.min(maxColumnIndex, maxColumnIndex * scrollPercentage));
  7176. // Define a max row index that we can't scroll past
  7177. if (colIndex > maxColumnIndex) {
  7178. colIndex = maxColumnIndex;
  7179. }
  7180. var newRange = [];
  7181. if (columnCache.length > self.grid.options.columnVirtualizationThreshold && self.getCanvasWidth() > self.getViewportWidth()) {
  7182. /* Commented the following lines because otherwise the moved column wasn't visible immediately on the new position
  7183. * in the case of many columns with horizontal scroll, one had to scroll left or right and then return in order to see it
  7184. // Have we hit the threshold going down?
  7185. if (self.prevScrollLeft < scrollLeft && colIndex < self.prevColumnScrollIndex + self.grid.options.horizontalScrollThreshold && colIndex < maxColumnIndex) {
  7186. return;
  7187. }
  7188. //Have we hit the threshold going up?
  7189. if (self.prevScrollLeft > scrollLeft && colIndex > self.prevColumnScrollIndex - self.grid.options.horizontalScrollThreshold && colIndex < maxColumnIndex) {
  7190. return;
  7191. }*/
  7192. var rangeStart = Math.max(0, colIndex - self.grid.options.excessColumns);
  7193. var rangeEnd = Math.min(columnCache.length, colIndex + minCols + self.grid.options.excessColumns);
  7194. newRange = [rangeStart, rangeEnd];
  7195. }
  7196. else {
  7197. var maxLen = self.visibleColumnCache.length;
  7198. newRange = [0, Math.max(maxLen, minCols + self.grid.options.excessColumns)];
  7199. }
  7200. self.updateViewableColumnRange(newRange);
  7201. self.prevColumnScrollIndex = colIndex;
  7202. };
  7203. // Method for updating the visible rows
  7204. GridRenderContainer.prototype.updateViewableRowRange = function updateViewableRowRange(renderedRange) {
  7205. // Slice out the range of rows from the data
  7206. // var rowArr = uiGridCtrl.grid.rows.slice(renderedRange[0], renderedRange[1]);
  7207. var rowArr = this.visibleRowCache.slice(renderedRange[0], renderedRange[1]);
  7208. // Define the top-most rendered row
  7209. this.currentTopRow = renderedRange[0];
  7210. this.setRenderedRows(rowArr);
  7211. };
  7212. // Method for updating the visible columns
  7213. GridRenderContainer.prototype.updateViewableColumnRange = function updateViewableColumnRange(renderedRange) {
  7214. // Slice out the range of rows from the data
  7215. // var columnArr = uiGridCtrl.grid.columns.slice(renderedRange[0], renderedRange[1]);
  7216. var columnArr = this.visibleColumnCache.slice(renderedRange[0], renderedRange[1]);
  7217. // Define the left-most rendered columns
  7218. this.currentFirstColumn = renderedRange[0];
  7219. this.setRenderedColumns(columnArr);
  7220. };
  7221. GridRenderContainer.prototype.headerCellWrapperStyle = function () {
  7222. var self = this;
  7223. if (self.currentFirstColumn !== 0) {
  7224. var offset = self.columnOffset;
  7225. if (self.grid.isRTL()) {
  7226. return { 'margin-right': offset + 'px' };
  7227. }
  7228. else {
  7229. return { 'margin-left': offset + 'px' };
  7230. }
  7231. }
  7232. return null;
  7233. };
  7234. /**
  7235. * @ngdoc boolean
  7236. * @name updateColumnWidths
  7237. * @propertyOf ui.grid.class:GridRenderContainer
  7238. * @description Determine the appropriate column width of each column across all render containers.
  7239. *
  7240. * Column width is easy when each column has a specified width. When columns are variable width (i.e.
  7241. * have an * or % of the viewport) then we try to calculate so that things fit in. The problem is that
  7242. * we have multiple render containers, and we don't want one render container to just take the whole viewport
  7243. * when it doesn't need to - we want things to balance out across the render containers.
  7244. *
  7245. * To do this, we use this method to calculate all the renderContainers, recognising that in a given render
  7246. * cycle it'll get called once per render container, so it needs to return the same values each time.
  7247. *
  7248. * The constraints on this method are therefore:
  7249. * - must return the same value when called multiple times, to do this it needs to rely on properties of the
  7250. * columns, but not properties that change when this is called (so it shouldn't rely on drawnWidth)
  7251. *
  7252. * The general logic of this method is:
  7253. * - calculate our total available width
  7254. * - look at all the columns across all render containers, and work out which have widths and which have
  7255. * constraints such as % or * or something else
  7256. * - for those with *, count the total number of * we see and add it onto a running total, add this column to an * array
  7257. * - for those with a %, allocate the % as a percentage of the viewport, having consideration of min and max
  7258. * - for those with manual width (in pixels) we set the drawnWidth to the specified width
  7259. * - we end up with an asterisks array still to process
  7260. * - we look at our remaining width. If it's greater than zero, we divide it up among the asterisk columns, then process
  7261. * them for min and max width constraints
  7262. * - if it's zero or less, we set the asterisk columns to their minimum widths
  7263. * - we use parseInt quite a bit, as we try to make all our column widths integers
  7264. */
  7265. GridRenderContainer.prototype.updateColumnWidths = function () {
  7266. var self = this;
  7267. var asterisksArray = [],
  7268. asteriskNum = 0,
  7269. usedWidthSum = 0,
  7270. ret = '';
  7271. // Get the width of the viewport
  7272. var availableWidth = self.grid.getViewportWidth() - self.grid.scrollbarWidth;
  7273. // get all the columns across all render containers, we have to calculate them all or one render container
  7274. // could consume the whole viewport
  7275. var columnCache = [];
  7276. angular.forEach(self.grid.renderContainers, function( container, name){
  7277. columnCache = columnCache.concat(container.visibleColumnCache);
  7278. });
  7279. // look at each column, process any manual values or %, put the * into an array to look at later
  7280. columnCache.forEach(function(column, i) {
  7281. var width = 0;
  7282. // Skip hidden columns
  7283. if (!column.visible) { return; }
  7284. if (angular.isNumber(column.width)) {
  7285. // pixel width, set to this value
  7286. width = parseInt(column.width, 10);
  7287. usedWidthSum = usedWidthSum + width;
  7288. column.drawnWidth = width;
  7289. } else if (gridUtil.endsWith(column.width, "%")) {
  7290. // percentage width, set to percentage of the viewport
  7291. width = parseInt(parseInt(column.width.replace(/%/g, ''), 10) / 100 * availableWidth);
  7292. if ( width > column.maxWidth ){
  7293. width = column.maxWidth;
  7294. }
  7295. if ( width < column.minWidth ){
  7296. width = column.minWidth;
  7297. }
  7298. usedWidthSum = usedWidthSum + width;
  7299. column.drawnWidth = width;
  7300. } else if (angular.isString(column.width) && column.width.indexOf('*') !== -1) {
  7301. // is an asterisk column, the gridColumn already checked the string consists only of '****'
  7302. asteriskNum = asteriskNum + column.width.length;
  7303. asterisksArray.push(column);
  7304. }
  7305. });
  7306. // Get the remaining width (available width subtracted by the used widths sum)
  7307. var remainingWidth = availableWidth - usedWidthSum;
  7308. var i, column, colWidth;
  7309. if (asterisksArray.length > 0) {
  7310. // the width that each asterisk value would be assigned (this can be negative)
  7311. var asteriskVal = remainingWidth / asteriskNum;
  7312. asterisksArray.forEach(function( column ){
  7313. var width = parseInt(column.width.length * asteriskVal, 10);
  7314. if ( width > column.maxWidth ){
  7315. width = column.maxWidth;
  7316. }
  7317. if ( width < column.minWidth ){
  7318. width = column.minWidth;
  7319. }
  7320. usedWidthSum = usedWidthSum + width;
  7321. column.drawnWidth = width;
  7322. });
  7323. }
  7324. // If the grid width didn't divide evenly into the column widths and we have pixels left over, or our
  7325. // calculated widths would have the grid narrower than the available space,
  7326. // dole the remainder out one by one to make everything fit
  7327. var processColumnUpwards = function(column){
  7328. if ( column.drawnWidth < column.maxWidth && leftoverWidth > 0) {
  7329. column.drawnWidth++;
  7330. usedWidthSum++;
  7331. leftoverWidth--;
  7332. columnsToChange = true;
  7333. }
  7334. };
  7335. var leftoverWidth = availableWidth - usedWidthSum;
  7336. var columnsToChange = true;
  7337. while (leftoverWidth > 0 && columnsToChange) {
  7338. columnsToChange = false;
  7339. asterisksArray.forEach(processColumnUpwards);
  7340. }
  7341. // We can end up with too much width even though some columns aren't at their max width, in this situation
  7342. // we can trim the columns a little
  7343. var processColumnDownwards = function(column){
  7344. if ( column.drawnWidth > column.minWidth && excessWidth > 0) {
  7345. column.drawnWidth--;
  7346. usedWidthSum--;
  7347. excessWidth--;
  7348. columnsToChange = true;
  7349. }
  7350. };
  7351. var excessWidth = usedWidthSum - availableWidth;
  7352. columnsToChange = true;
  7353. while (excessWidth > 0 && columnsToChange) {
  7354. columnsToChange = false;
  7355. asterisksArray.forEach(processColumnDownwards);
  7356. }
  7357. // all that was across all the renderContainers, now we need to work out what that calculation decided for
  7358. // our renderContainer
  7359. var canvasWidth = 0;
  7360. self.visibleColumnCache.forEach(function(column){
  7361. if ( column.visible ){
  7362. canvasWidth = canvasWidth + column.drawnWidth;
  7363. }
  7364. });
  7365. // Build the CSS
  7366. columnCache.forEach(function (column) {
  7367. ret = ret + column.getColClassDefinition();
  7368. });
  7369. self.canvasWidth = canvasWidth;
  7370. // Return the styles back to buildStyles which pops them into the `customStyles` scope variable
  7371. // return ret;
  7372. // Set this render container's column styles so they can be used in style computation
  7373. this.columnStyles = ret;
  7374. };
  7375. GridRenderContainer.prototype.needsHScrollbarPlaceholder = function () {
  7376. return this.grid.options.enableHorizontalScrollbar && !this.hasHScrollbar && !this.grid.disableScrolling;
  7377. };
  7378. GridRenderContainer.prototype.getViewportStyle = function () {
  7379. var self = this;
  7380. var styles = {};
  7381. self.hasHScrollbar = false;
  7382. self.hasVScrollbar = false;
  7383. if (self.grid.disableScrolling) {
  7384. styles['overflow-x'] = 'hidden';
  7385. styles['overflow-y'] = 'hidden';
  7386. return styles;
  7387. }
  7388. if (self.name === 'body') {
  7389. self.hasHScrollbar = self.grid.options.enableHorizontalScrollbar !== uiGridConstants.scrollbars.NEVER;
  7390. if (!self.grid.isRTL()) {
  7391. if (!self.grid.hasRightContainerColumns()) {
  7392. self.hasVScrollbar = self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER;
  7393. }
  7394. }
  7395. else {
  7396. if (!self.grid.hasLeftContainerColumns()) {
  7397. self.hasVScrollbar = self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER;
  7398. }
  7399. }
  7400. }
  7401. else if (self.name === 'left') {
  7402. self.hasVScrollbar = self.grid.isRTL() ? self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER : false;
  7403. }
  7404. else {
  7405. self.hasVScrollbar = !self.grid.isRTL() ? self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER : false;
  7406. }
  7407. styles['overflow-x'] = self.hasHScrollbar ? 'scroll' : 'hidden';
  7408. styles['overflow-y'] = self.hasVScrollbar ? 'scroll' : 'hidden';
  7409. return styles;
  7410. };
  7411. return GridRenderContainer;
  7412. }]);
  7413. })();
  7414. (function(){
  7415. angular.module('ui.grid')
  7416. .factory('GridRow', ['gridUtil', function(gridUtil) {
  7417. /**
  7418. * @ngdoc function
  7419. * @name ui.grid.class:GridRow
  7420. * @description GridRow is the viewModel for one logical row on the grid. A grid Row is not necessarily a one-to-one
  7421. * relation to gridOptions.data.
  7422. * @param {object} entity the array item from GridOptions.data
  7423. * @param {number} index the current position of the row in the array
  7424. * @param {Grid} reference to the parent grid
  7425. */
  7426. function GridRow(entity, index, grid) {
  7427. /**
  7428. * @ngdoc object
  7429. * @name grid
  7430. * @propertyOf ui.grid.class:GridRow
  7431. * @description A reference back to the grid
  7432. */
  7433. this.grid = grid;
  7434. /**
  7435. * @ngdoc object
  7436. * @name entity
  7437. * @propertyOf ui.grid.class:GridRow
  7438. * @description A reference to an item in gridOptions.data[]
  7439. */
  7440. this.entity = entity;
  7441. /**
  7442. * @ngdoc object
  7443. * @name uid
  7444. * @propertyOf ui.grid.class:GridRow
  7445. * @description UniqueId of row
  7446. */
  7447. this.uid = gridUtil.nextUid();
  7448. /**
  7449. * @ngdoc object
  7450. * @name visible
  7451. * @propertyOf ui.grid.class:GridRow
  7452. * @description If true, the row will be rendered
  7453. */
  7454. // Default to true
  7455. this.visible = true;
  7456. this.$$height = grid.options.rowHeight;
  7457. }
  7458. /**
  7459. * @ngdoc object
  7460. * @name height
  7461. * @propertyOf ui.grid.class:GridRow
  7462. * @description height of each individual row. changing the height will flag all
  7463. * row renderContainers to recalculate their canvas height
  7464. */
  7465. Object.defineProperty(GridRow.prototype, 'height', {
  7466. get: function() {
  7467. return this.$$height;
  7468. },
  7469. set: function(height) {
  7470. if (height !== this.$$height) {
  7471. this.grid.updateCanvasHeight();
  7472. this.$$height = height;
  7473. }
  7474. }
  7475. });
  7476. /**
  7477. * @ngdoc function
  7478. * @name getQualifiedColField
  7479. * @methodOf ui.grid.class:GridRow
  7480. * @description returns the qualified field name as it exists on scope
  7481. * ie: row.entity.fieldA
  7482. * @param {GridCol} col column instance
  7483. * @returns {string} resulting name that can be evaluated on scope
  7484. */
  7485. GridRow.prototype.getQualifiedColField = function(col) {
  7486. return 'row.' + this.getEntityQualifiedColField(col);
  7487. };
  7488. /**
  7489. * @ngdoc function
  7490. * @name getEntityQualifiedColField
  7491. * @methodOf ui.grid.class:GridRow
  7492. * @description returns the qualified field name minus the row path
  7493. * ie: entity.fieldA
  7494. * @param {GridCol} col column instance
  7495. * @returns {string} resulting name that can be evaluated against a row
  7496. */
  7497. GridRow.prototype.getEntityQualifiedColField = function(col) {
  7498. return gridUtil.preEval('entity.' + col.field);
  7499. };
  7500. /**
  7501. * @ngdoc function
  7502. * @name setRowInvisible
  7503. * @methodOf ui.grid.class:GridRow
  7504. * @description Sets an override on the row that forces it to always
  7505. * be invisible. Emits the rowsVisibleChanged event if it changed the row visibility.
  7506. *
  7507. * This method can be called from the api, passing in the gridRow we want
  7508. * altered. It should really work by calling gridRow.setRowInvisible, but that's
  7509. * not the way I coded it, and too late to change now. Changed to just call
  7510. * the internal function row.setThisRowInvisible().
  7511. *
  7512. * @param {GridRow} row the row we want to set to invisible
  7513. *
  7514. */
  7515. GridRow.prototype.setRowInvisible = function ( row ) {
  7516. if (row && row.setThisRowInvisible){
  7517. row.setThisRowInvisible( 'user' );
  7518. }
  7519. };
  7520. /**
  7521. * @ngdoc function
  7522. * @name clearRowInvisible
  7523. * @methodOf ui.grid.class:GridRow
  7524. * @description Clears an override on the row that forces it to always
  7525. * be invisible. Emits the rowsVisibleChanged event if it changed the row visibility.
  7526. *
  7527. * This method can be called from the api, passing in the gridRow we want
  7528. * altered. It should really work by calling gridRow.clearRowInvisible, but that's
  7529. * not the way I coded it, and too late to change now. Changed to just call
  7530. * the internal function row.clearThisRowInvisible().
  7531. *
  7532. * @param {GridRow} row the row we want to clear the invisible flag
  7533. *
  7534. */
  7535. GridRow.prototype.clearRowInvisible = function ( row ) {
  7536. if (row && row.clearThisRowInvisible){
  7537. row.clearThisRowInvisible( 'user' );
  7538. }
  7539. };
  7540. /**
  7541. * @ngdoc function
  7542. * @name setThisRowInvisible
  7543. * @methodOf ui.grid.class:GridRow
  7544. * @description Sets an override on the row that forces it to always
  7545. * be invisible. Emits the rowsVisibleChanged event if it changed the row visibility
  7546. *
  7547. * @param {string} reason the reason (usually the module) for the row to be invisible.
  7548. * E.g. grouping, user, filter
  7549. * @param {boolean} fromRowsProcessor whether we were called from a rowsProcessor, passed through to evaluateRowVisibility
  7550. */
  7551. GridRow.prototype.setThisRowInvisible = function ( reason, fromRowsProcessor ) {
  7552. if ( !this.invisibleReason ){
  7553. this.invisibleReason = {};
  7554. }
  7555. this.invisibleReason[reason] = true;
  7556. this.evaluateRowVisibility( fromRowsProcessor);
  7557. };
  7558. /**
  7559. * @ngdoc function
  7560. * @name clearRowInvisible
  7561. * @methodOf ui.grid.class:GridRow
  7562. * @description Clears any override on the row visibility, returning it
  7563. * to normal visibility calculations. Emits the rowsVisibleChanged
  7564. * event
  7565. *
  7566. * @param {string} reason the reason (usually the module) for the row to be invisible.
  7567. * E.g. grouping, user, filter
  7568. * @param {boolean} fromRowsProcessor whether we were called from a rowsProcessor, passed through to evaluateRowVisibility
  7569. */
  7570. GridRow.prototype.clearThisRowInvisible = function ( reason, fromRowsProcessor ) {
  7571. if (typeof(this.invisibleReason) !== 'undefined' ) {
  7572. delete this.invisibleReason[reason];
  7573. }
  7574. this.evaluateRowVisibility( fromRowsProcessor );
  7575. };
  7576. /**
  7577. * @ngdoc function
  7578. * @name evaluateRowVisibility
  7579. * @methodOf ui.grid.class:GridRow
  7580. * @description Determines whether the row should be visible based on invisibleReason,
  7581. * and if it changes the row visibility, then emits the rowsVisibleChanged event.
  7582. *
  7583. * Queues a grid refresh, but doesn't call it directly to avoid hitting lots of grid refreshes.
  7584. * @param {boolean} fromRowProcessor if true, then it won't raise events or queue the refresh, the
  7585. * row processor does that already
  7586. */
  7587. GridRow.prototype.evaluateRowVisibility = function ( fromRowProcessor ) {
  7588. var newVisibility = true;
  7589. if ( typeof(this.invisibleReason) !== 'undefined' ){
  7590. angular.forEach(this.invisibleReason, function( value, key ){
  7591. if ( value ){
  7592. newVisibility = false;
  7593. }
  7594. });
  7595. }
  7596. if ( typeof(this.visible) === 'undefined' || this.visible !== newVisibility ){
  7597. this.visible = newVisibility;
  7598. if ( !fromRowProcessor ){
  7599. this.grid.queueGridRefresh();
  7600. this.grid.api.core.raise.rowsVisibleChanged(this);
  7601. }
  7602. }
  7603. };
  7604. return GridRow;
  7605. }]);
  7606. })();
  7607. (function(){
  7608. 'use strict';
  7609. /**
  7610. * @ngdoc object
  7611. * @name ui.grid.class:GridRowColumn
  7612. * @param {GridRow} row The row for this pair
  7613. * @param {GridColumn} column The column for this pair
  7614. * @description A row and column pair that represents the intersection of these two entities.
  7615. * Must be instantiated as a constructor using the `new` keyword.
  7616. */
  7617. angular.module('ui.grid')
  7618. .factory('GridRowColumn', ['$parse', '$filter',
  7619. function GridRowColumnFactory($parse, $filter){
  7620. var GridRowColumn = function GridRowColumn(row, col) {
  7621. if ( !(this instanceof GridRowColumn)){
  7622. throw "Using GridRowColumn as a function insead of as a constructor. Must be called with `new` keyword";
  7623. }
  7624. /**
  7625. * @ngdoc object
  7626. * @name row
  7627. * @propertyOf ui.grid.class:GridRowColumn
  7628. * @description {@link ui.grid.class:GridRow }
  7629. */
  7630. this.row = row;
  7631. /**
  7632. * @ngdoc object
  7633. * @name col
  7634. * @propertyOf ui.grid.class:GridRowColumn
  7635. * @description {@link ui.grid.class:GridColumn }
  7636. */
  7637. this.col = col;
  7638. };
  7639. /**
  7640. * @ngdoc function
  7641. * @name getIntersectionValueRaw
  7642. * @methodOf ui.grid.class:GridRowColumn
  7643. * @description Gets the intersection of where the row and column meet.
  7644. * @returns {String|Number|Object} The value from the grid data that this GridRowColumn points too.
  7645. * If the column has a cellFilter this will NOT return the filtered value.
  7646. */
  7647. GridRowColumn.prototype.getIntersectionValueRaw = function(){
  7648. var getter = $parse(this.row.getEntityQualifiedColField(this.col));
  7649. var context = this.row;
  7650. return getter(context);
  7651. };
  7652. /**
  7653. * @ngdoc function
  7654. * @name getIntersectionValueFiltered
  7655. * @methodOf ui.grid.class:GridRowColumn
  7656. * @description Gets the intersection of where the row and column meet.
  7657. * @returns {String|Number|Object} The value from the grid data that this GridRowColumn points too.
  7658. * If the column has a cellFilter this will also apply the filter to it and return the value that the filter displays.
  7659. */
  7660. GridRowColumn.prototype.getIntersectionValueFiltered = function(){
  7661. var value = this.getIntersectionValueRaw();
  7662. if (this.col.cellFilter && this.col.cellFilter !== ''){
  7663. var getFilterIfExists = function(filterName){
  7664. try {
  7665. return $filter(filterName);
  7666. } catch (e){
  7667. return null;
  7668. }
  7669. };
  7670. var filter = getFilterIfExists(this.col.cellFilter);
  7671. if (filter) { // Check if this is filter name or a filter string
  7672. value = filter(value);
  7673. } else { // We have the template version of a filter so we need to parse it apart
  7674. // Get the filter params out using a regex
  7675. // Test out this regex here https://regex101.com/r/rC5eR5/2
  7676. var re = /([^:]*):([^:]*):?([\s\S]+)?/;
  7677. var matches;
  7678. if ((matches = re.exec(this.col.cellFilter)) !== null) {
  7679. // View your result using the matches-variable.
  7680. // eg matches[0] etc.
  7681. value = $filter(matches[1])(value, matches[2], matches[3]);
  7682. }
  7683. }
  7684. }
  7685. return value;
  7686. };
  7687. return GridRowColumn;
  7688. }
  7689. ]);
  7690. })();
  7691. (function () {
  7692. angular.module('ui.grid')
  7693. .factory('ScrollEvent', ['gridUtil', function (gridUtil) {
  7694. /**
  7695. * @ngdoc function
  7696. * @name ui.grid.class:ScrollEvent
  7697. * @description Model for all scrollEvents
  7698. * @param {Grid} grid that owns the scroll event
  7699. * @param {GridRenderContainer} sourceRowContainer that owns the scroll event. Can be null
  7700. * @param {GridRenderContainer} sourceColContainer that owns the scroll event. Can be null
  7701. * @param {string} source the source of the event - from uiGridConstants.scrollEventSources or a string value of directive/service/factory.functionName
  7702. */
  7703. function ScrollEvent(grid, sourceRowContainer, sourceColContainer, source) {
  7704. var self = this;
  7705. if (!grid) {
  7706. throw new Error("grid argument is required");
  7707. }
  7708. /**
  7709. * @ngdoc object
  7710. * @name grid
  7711. * @propertyOf ui.grid.class:ScrollEvent
  7712. * @description A reference back to the grid
  7713. */
  7714. self.grid = grid;
  7715. /**
  7716. * @ngdoc object
  7717. * @name source
  7718. * @propertyOf ui.grid.class:ScrollEvent
  7719. * @description the source of the scroll event. limited to values from uiGridConstants.scrollEventSources
  7720. */
  7721. self.source = source;
  7722. /**
  7723. * @ngdoc object
  7724. * @name noDelay
  7725. * @propertyOf ui.grid.class:ScrollEvent
  7726. * @description most scroll events from the mouse or trackpad require delay to operate properly
  7727. * set to false to eliminate delay. Useful for scroll events that the grid causes, such as scrolling to make a row visible.
  7728. */
  7729. self.withDelay = true;
  7730. self.sourceRowContainer = sourceRowContainer;
  7731. self.sourceColContainer = sourceColContainer;
  7732. self.newScrollLeft = null;
  7733. self.newScrollTop = null;
  7734. self.x = null;
  7735. self.y = null;
  7736. self.verticalScrollLength = -9999999;
  7737. self.horizontalScrollLength = -999999;
  7738. /**
  7739. * @ngdoc function
  7740. * @name fireThrottledScrollingEvent
  7741. * @methodOf ui.grid.class:ScrollEvent
  7742. * @description fires a throttled event using grid.api.core.raise.scrollEvent
  7743. */
  7744. self.fireThrottledScrollingEvent = gridUtil.throttle(function(sourceContainerId) {
  7745. self.grid.scrollContainers(sourceContainerId, self);
  7746. }, self.grid.options.wheelScrollThrottle, {trailing: true});
  7747. }
  7748. /**
  7749. * @ngdoc function
  7750. * @name getNewScrollLeft
  7751. * @methodOf ui.grid.class:ScrollEvent
  7752. * @description returns newScrollLeft property if available; calculates a new value if it isn't
  7753. */
  7754. ScrollEvent.prototype.getNewScrollLeft = function(colContainer, viewport){
  7755. var self = this;
  7756. if (!self.newScrollLeft){
  7757. var scrollWidth = (colContainer.getCanvasWidth() - colContainer.getViewportWidth());
  7758. var oldScrollLeft = gridUtil.normalizeScrollLeft(viewport, self.grid);
  7759. var scrollXPercentage;
  7760. if (typeof(self.x.percentage) !== 'undefined' && self.x.percentage !== undefined) {
  7761. scrollXPercentage = self.x.percentage;
  7762. }
  7763. else if (typeof(self.x.pixels) !== 'undefined' && self.x.pixels !== undefined) {
  7764. scrollXPercentage = self.x.percentage = (oldScrollLeft + self.x.pixels) / scrollWidth;
  7765. }
  7766. else {
  7767. throw new Error("No percentage or pixel value provided for scroll event X axis");
  7768. }
  7769. return Math.max(0, scrollXPercentage * scrollWidth);
  7770. }
  7771. return self.newScrollLeft;
  7772. };
  7773. /**
  7774. * @ngdoc function
  7775. * @name getNewScrollTop
  7776. * @methodOf ui.grid.class:ScrollEvent
  7777. * @description returns newScrollTop property if available; calculates a new value if it isn't
  7778. */
  7779. ScrollEvent.prototype.getNewScrollTop = function(rowContainer, viewport){
  7780. var self = this;
  7781. if (!self.newScrollTop){
  7782. var scrollLength = rowContainer.getVerticalScrollLength();
  7783. var oldScrollTop = viewport[0].scrollTop;
  7784. var scrollYPercentage;
  7785. if (typeof(self.y.percentage) !== 'undefined' && self.y.percentage !== undefined) {
  7786. scrollYPercentage = self.y.percentage;
  7787. }
  7788. else if (typeof(self.y.pixels) !== 'undefined' && self.y.pixels !== undefined) {
  7789. scrollYPercentage = self.y.percentage = (oldScrollTop + self.y.pixels) / scrollLength;
  7790. }
  7791. else {
  7792. throw new Error("No percentage or pixel value provided for scroll event Y axis");
  7793. }
  7794. return Math.max(0, scrollYPercentage * scrollLength);
  7795. }
  7796. return self.newScrollTop;
  7797. };
  7798. ScrollEvent.prototype.atTop = function(scrollTop) {
  7799. return (this.y && (this.y.percentage === 0 || this.verticalScrollLength < 0) && scrollTop === 0);
  7800. };
  7801. ScrollEvent.prototype.atBottom = function(scrollTop) {
  7802. return (this.y && (this.y.percentage === 1 || this.verticalScrollLength === 0) && scrollTop > 0);
  7803. };
  7804. ScrollEvent.prototype.atLeft = function(scrollLeft) {
  7805. return (this.x && (this.x.percentage === 0 || this.horizontalScrollLength < 0) && scrollLeft === 0);
  7806. };
  7807. ScrollEvent.prototype.atRight = function(scrollLeft) {
  7808. return (this.x && (this.x.percentage === 1 || this.horizontalScrollLength ===0) && scrollLeft > 0);
  7809. };
  7810. ScrollEvent.Sources = {
  7811. ViewPortScroll: 'ViewPortScroll',
  7812. RenderContainerMouseWheel: 'RenderContainerMouseWheel',
  7813. RenderContainerTouchMove: 'RenderContainerTouchMove',
  7814. Other: 99
  7815. };
  7816. return ScrollEvent;
  7817. }]);
  7818. })();
  7819. (function () {
  7820. 'use strict';
  7821. /**
  7822. * @ngdoc object
  7823. * @name ui.grid.service:gridClassFactory
  7824. *
  7825. * @description factory to return dom specific instances of a grid
  7826. *
  7827. */
  7828. angular.module('ui.grid').service('gridClassFactory', ['gridUtil', '$q', '$compile', '$templateCache', 'uiGridConstants', 'Grid', 'GridColumn', 'GridRow',
  7829. function (gridUtil, $q, $compile, $templateCache, uiGridConstants, Grid, GridColumn, GridRow) {
  7830. var service = {
  7831. /**
  7832. * @ngdoc method
  7833. * @name createGrid
  7834. * @methodOf ui.grid.service:gridClassFactory
  7835. * @description Creates a new grid instance. Each instance will have a unique id
  7836. * @param {object} options An object map of options to pass into the created grid instance.
  7837. * @returns {Grid} grid
  7838. */
  7839. createGrid : function(options) {
  7840. options = (typeof(options) !== 'undefined') ? options : {};
  7841. options.id = gridUtil.newId();
  7842. var grid = new Grid(options);
  7843. // NOTE/TODO: rowTemplate should always be defined...
  7844. if (grid.options.rowTemplate) {
  7845. var rowTemplateFnPromise = $q.defer();
  7846. grid.getRowTemplateFn = rowTemplateFnPromise.promise;
  7847. gridUtil.getTemplate(grid.options.rowTemplate)
  7848. .then(
  7849. function (template) {
  7850. var rowTemplateFn = $compile(template);
  7851. rowTemplateFnPromise.resolve(rowTemplateFn);
  7852. },
  7853. function (res) {
  7854. // Todo handle response error here?
  7855. throw new Error("Couldn't fetch/use row template '" + grid.options.rowTemplate + "'");
  7856. });
  7857. }
  7858. grid.registerColumnBuilder(service.defaultColumnBuilder);
  7859. // Row builder for custom row templates
  7860. grid.registerRowBuilder(service.rowTemplateAssigner);
  7861. // Reset all rows to visible initially
  7862. grid.registerRowsProcessor(function allRowsVisible(rows) {
  7863. rows.forEach(function (row) {
  7864. row.evaluateRowVisibility( true );
  7865. }, 50);
  7866. return rows;
  7867. });
  7868. grid.registerColumnsProcessor(function allColumnsVisible(columns) {
  7869. columns.forEach(function (column) {
  7870. column.visible = true;
  7871. });
  7872. return columns;
  7873. }, 50);
  7874. grid.registerColumnsProcessor(function(renderableColumns) {
  7875. renderableColumns.forEach(function (column) {
  7876. if (column.colDef.visible === false) {
  7877. column.visible = false;
  7878. }
  7879. });
  7880. return renderableColumns;
  7881. }, 50);
  7882. grid.registerRowsProcessor(grid.searchRows, 100);
  7883. // Register the default row processor, it sorts rows by selected columns
  7884. if (grid.options.externalSort && angular.isFunction(grid.options.externalSort)) {
  7885. grid.registerRowsProcessor(grid.options.externalSort, 200);
  7886. }
  7887. else {
  7888. grid.registerRowsProcessor(grid.sortByColumn, 200);
  7889. }
  7890. return grid;
  7891. },
  7892. /**
  7893. * @ngdoc function
  7894. * @name defaultColumnBuilder
  7895. * @methodOf ui.grid.service:gridClassFactory
  7896. * @description Processes designTime column definitions and applies them to col for the
  7897. * core grid features
  7898. * @param {object} colDef reference to column definition
  7899. * @param {GridColumn} col reference to gridCol
  7900. * @param {object} gridOptions reference to grid options
  7901. */
  7902. defaultColumnBuilder: function (colDef, col, gridOptions) {
  7903. var templateGetPromises = [];
  7904. // Abstracts the standard template processing we do for every template type.
  7905. var processTemplate = function( templateType, providedType, defaultTemplate, filterType, tooltipType ) {
  7906. if ( !colDef[templateType] ){
  7907. col[providedType] = defaultTemplate;
  7908. } else {
  7909. col[providedType] = colDef[templateType];
  7910. }
  7911. templateGetPromises.push(gridUtil.getTemplate(col[providedType])
  7912. .then(
  7913. function (template) {
  7914. if ( angular.isFunction(template) ) { template = template(); }
  7915. var tooltipCall = ( tooltipType === 'cellTooltip' ) ? 'col.cellTooltip(row,col)' : 'col.headerTooltip(col)';
  7916. if ( tooltipType && col[tooltipType] === false ){
  7917. template = template.replace(uiGridConstants.TOOLTIP, '');
  7918. } else if ( tooltipType && col[tooltipType] ){
  7919. template = template.replace(uiGridConstants.TOOLTIP, 'title="{{' + tooltipCall + ' CUSTOM_FILTERS }}"');
  7920. }
  7921. if ( filterType ){
  7922. col[templateType] = template.replace(uiGridConstants.CUSTOM_FILTERS, function() {
  7923. return col[filterType] ? "|" + col[filterType] : "";
  7924. });
  7925. } else {
  7926. col[templateType] = template;
  7927. }
  7928. },
  7929. function (res) {
  7930. throw new Error("Couldn't fetch/use colDef." + templateType + " '" + colDef[templateType] + "'");
  7931. })
  7932. );
  7933. };
  7934. /**
  7935. * @ngdoc property
  7936. * @name cellTemplate
  7937. * @propertyOf ui.grid.class:GridOptions.columnDef
  7938. * @description a custom template for each cell in this column. The default
  7939. * is ui-grid/uiGridCell. If you are using the cellNav feature, this template
  7940. * must contain a div that can receive focus.
  7941. *
  7942. */
  7943. processTemplate( 'cellTemplate', 'providedCellTemplate', 'ui-grid/uiGridCell', 'cellFilter', 'cellTooltip' );
  7944. col.cellTemplatePromise = templateGetPromises[0];
  7945. /**
  7946. * @ngdoc property
  7947. * @name headerCellTemplate
  7948. * @propertyOf ui.grid.class:GridOptions.columnDef
  7949. * @description a custom template for the header for this column. The default
  7950. * is ui-grid/uiGridHeaderCell
  7951. *
  7952. */
  7953. processTemplate( 'headerCellTemplate', 'providedHeaderCellTemplate', 'ui-grid/uiGridHeaderCell', 'headerCellFilter', 'headerTooltip' );
  7954. /**
  7955. * @ngdoc property
  7956. * @name footerCellTemplate
  7957. * @propertyOf ui.grid.class:GridOptions.columnDef
  7958. * @description a custom template for the footer for this column. The default
  7959. * is ui-grid/uiGridFooterCell
  7960. *
  7961. */
  7962. processTemplate( 'footerCellTemplate', 'providedFooterCellTemplate', 'ui-grid/uiGridFooterCell', 'footerCellFilter' );
  7963. /**
  7964. * @ngdoc property
  7965. * @name filterHeaderTemplate
  7966. * @propertyOf ui.grid.class:GridOptions.columnDef
  7967. * @description a custom template for the filter input. The default is ui-grid/ui-grid-filter
  7968. *
  7969. */
  7970. processTemplate( 'filterHeaderTemplate', 'providedFilterHeaderTemplate', 'ui-grid/ui-grid-filter' );
  7971. // Create a promise for the compiled element function
  7972. col.compiledElementFnDefer = $q.defer();
  7973. return $q.all(templateGetPromises);
  7974. },
  7975. rowTemplateAssigner: function rowTemplateAssigner(row) {
  7976. var grid = this;
  7977. // Row has no template assigned to it
  7978. if (!row.rowTemplate) {
  7979. // Use the default row template from the grid
  7980. row.rowTemplate = grid.options.rowTemplate;
  7981. // Use the grid's function for fetching the compiled row template function
  7982. row.getRowTemplateFn = grid.getRowTemplateFn;
  7983. }
  7984. // Row has its own template assigned
  7985. else {
  7986. // Create a promise for the compiled row template function
  7987. var perRowTemplateFnPromise = $q.defer();
  7988. row.getRowTemplateFn = perRowTemplateFnPromise.promise;
  7989. // Get the row template
  7990. gridUtil.getTemplate(row.rowTemplate)
  7991. .then(function (template) {
  7992. // Compile the template
  7993. var rowTemplateFn = $compile(template);
  7994. // Resolve the compiled template function promise
  7995. perRowTemplateFnPromise.resolve(rowTemplateFn);
  7996. },
  7997. function (res) {
  7998. // Todo handle response error here?
  7999. throw new Error("Couldn't fetch/use row template '" + row.rowTemplate + "'");
  8000. });
  8001. }
  8002. return row.getRowTemplateFn;
  8003. }
  8004. };
  8005. //class definitions (moved to separate factories)
  8006. return service;
  8007. }]);
  8008. })();
  8009. (function() {
  8010. var module = angular.module('ui.grid');
  8011. function escapeRegExp(str) {
  8012. return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
  8013. }
  8014. /**
  8015. * @ngdoc service
  8016. * @name ui.grid.service:rowSearcher
  8017. *
  8018. * @description Service for searching/filtering rows based on column value conditions.
  8019. */
  8020. module.service('rowSearcher', ['gridUtil', 'uiGridConstants', function (gridUtil, uiGridConstants) {
  8021. var defaultCondition = uiGridConstants.filter.CONTAINS;
  8022. var rowSearcher = {};
  8023. /**
  8024. * @ngdoc function
  8025. * @name getTerm
  8026. * @methodOf ui.grid.service:rowSearcher
  8027. * @description Get the term from a filter
  8028. * Trims leading and trailing whitespace
  8029. * @param {object} filter object to use
  8030. * @returns {object} Parsed term
  8031. */
  8032. rowSearcher.getTerm = function getTerm(filter) {
  8033. if (typeof(filter.term) === 'undefined') { return filter.term; }
  8034. var term = filter.term;
  8035. // Strip leading and trailing whitespace if the term is a string
  8036. if (typeof(term) === 'string') {
  8037. term = term.trim();
  8038. }
  8039. return term;
  8040. };
  8041. /**
  8042. * @ngdoc function
  8043. * @name stripTerm
  8044. * @methodOf ui.grid.service:rowSearcher
  8045. * @description Remove leading and trailing asterisk (*) from the filter's term
  8046. * @param {object} filter object to use
  8047. * @returns {uiGridConstants.filter<int>} Value representing the condition constant value
  8048. */
  8049. rowSearcher.stripTerm = function stripTerm(filter) {
  8050. var term = rowSearcher.getTerm(filter);
  8051. if (typeof(term) === 'string') {
  8052. return escapeRegExp(term.replace(/(^\*|\*$)/g, ''));
  8053. }
  8054. else {
  8055. return term;
  8056. }
  8057. };
  8058. /**
  8059. * @ngdoc function
  8060. * @name guessCondition
  8061. * @methodOf ui.grid.service:rowSearcher
  8062. * @description Guess the condition for a filter based on its term
  8063. * <br>
  8064. * Defaults to STARTS_WITH. Uses CONTAINS for strings beginning and ending with *s (*bob*).
  8065. * Uses STARTS_WITH for strings ending with * (bo*). Uses ENDS_WITH for strings starting with * (*ob).
  8066. * @param {object} filter object to use
  8067. * @returns {uiGridConstants.filter<int>} Value representing the condition constant value
  8068. */
  8069. rowSearcher.guessCondition = function guessCondition(filter) {
  8070. if (typeof(filter.term) === 'undefined' || !filter.term) {
  8071. return defaultCondition;
  8072. }
  8073. var term = rowSearcher.getTerm(filter);
  8074. if (/\*/.test(term)) {
  8075. var regexpFlags = '';
  8076. if (!filter.flags || !filter.flags.caseSensitive) {
  8077. regexpFlags += 'i';
  8078. }
  8079. var reText = term.replace(/(\\)?\*/g, function ($0, $1) { return $1 ? $0 : '[\\s\\S]*?'; });
  8080. return new RegExp('^' + reText + '$', regexpFlags);
  8081. }
  8082. // Otherwise default to default condition
  8083. else {
  8084. return defaultCondition;
  8085. }
  8086. };
  8087. /**
  8088. * @ngdoc function
  8089. * @name setupFilters
  8090. * @methodOf ui.grid.service:rowSearcher
  8091. * @description For a given columns filters (either col.filters, or [col.filter] can be passed in),
  8092. * do all the parsing and pre-processing and store that data into a new filters object. The object
  8093. * has the condition, the flags, the stripped term, and a parsed reg exp if there was one.
  8094. *
  8095. * We could use a forEach in here, since it's much less performance sensitive, but since we're using
  8096. * for loops everywhere else in this module...
  8097. *
  8098. * @param {array} filters the filters from the column (col.filters or [col.filter])
  8099. * @returns {array} An array of parsed/preprocessed filters
  8100. */
  8101. rowSearcher.setupFilters = function setupFilters( filters ){
  8102. var newFilters = [];
  8103. var filtersLength = filters.length;
  8104. for ( var i = 0; i < filtersLength; i++ ){
  8105. var filter = filters[i];
  8106. if ( filter.noTerm || !gridUtil.isNullOrUndefined(filter.term) ){
  8107. var newFilter = {};
  8108. var regexpFlags = '';
  8109. if (!filter.flags || !filter.flags.caseSensitive) {
  8110. regexpFlags += 'i';
  8111. }
  8112. if ( !gridUtil.isNullOrUndefined(filter.term) ){
  8113. // it is possible to have noTerm. We don't need to copy that across, it was just a flag to avoid
  8114. // getting the filter ignored if the filter was a function that didn't use a term
  8115. newFilter.term = rowSearcher.stripTerm(filter);
  8116. }
  8117. if ( filter.condition ){
  8118. newFilter.condition = filter.condition;
  8119. } else {
  8120. newFilter.condition = rowSearcher.guessCondition(filter);
  8121. }
  8122. newFilter.flags = angular.extend( { caseSensitive: false, date: false }, filter.flags );
  8123. if (newFilter.condition === uiGridConstants.filter.STARTS_WITH) {
  8124. newFilter.startswithRE = new RegExp('^' + newFilter.term, regexpFlags);
  8125. }
  8126. if (newFilter.condition === uiGridConstants.filter.ENDS_WITH) {
  8127. newFilter.endswithRE = new RegExp(newFilter.term + '$', regexpFlags);
  8128. }
  8129. if (newFilter.condition === uiGridConstants.filter.CONTAINS) {
  8130. newFilter.containsRE = new RegExp(newFilter.term, regexpFlags);
  8131. }
  8132. if (newFilter.condition === uiGridConstants.filter.EXACT) {
  8133. newFilter.exactRE = new RegExp('^' + newFilter.term + '$', regexpFlags);
  8134. }
  8135. newFilters.push(newFilter);
  8136. }
  8137. }
  8138. return newFilters;
  8139. };
  8140. /**
  8141. * @ngdoc function
  8142. * @name runColumnFilter
  8143. * @methodOf ui.grid.service:rowSearcher
  8144. * @description Runs a single pre-parsed filter against a cell, returning true
  8145. * if the cell matches that one filter.
  8146. *
  8147. * @param {Grid} grid the grid we're working against
  8148. * @param {GridRow} row the row we're matching against
  8149. * @param {GridCol} column the column that we're working against
  8150. * @param {object} filter the specific, preparsed, filter that we want to test
  8151. * @returns {boolean} true if we match (row stays visible)
  8152. */
  8153. rowSearcher.runColumnFilter = function runColumnFilter(grid, row, column, filter) {
  8154. // Cache typeof condition
  8155. var conditionType = typeof(filter.condition);
  8156. // Term to search for.
  8157. var term = filter.term;
  8158. // Get the column value for this row
  8159. var value;
  8160. if ( column.filterCellFiltered ){
  8161. value = grid.getCellDisplayValue(row, column);
  8162. } else {
  8163. value = grid.getCellValue(row, column);
  8164. }
  8165. // If the filter's condition is a RegExp, then use it
  8166. if (filter.condition instanceof RegExp) {
  8167. return filter.condition.test(value);
  8168. }
  8169. // If the filter's condition is a function, run it
  8170. if (conditionType === 'function') {
  8171. return filter.condition(term, value, row, column);
  8172. }
  8173. if (filter.startswithRE) {
  8174. return filter.startswithRE.test(value);
  8175. }
  8176. if (filter.endswithRE) {
  8177. return filter.endswithRE.test(value);
  8178. }
  8179. if (filter.containsRE) {
  8180. return filter.containsRE.test(value);
  8181. }
  8182. if (filter.exactRE) {
  8183. return filter.exactRE.test(value);
  8184. }
  8185. if (filter.condition === uiGridConstants.filter.NOT_EQUAL) {
  8186. var regex = new RegExp('^' + term + '$');
  8187. return !regex.exec(value);
  8188. }
  8189. if (typeof(value) === 'number' && typeof(term) === 'string' ){
  8190. // if the term has a decimal in it, it comes through as '9\.4', we need to take out the \
  8191. // the same for negative numbers
  8192. // TODO: I suspect the right answer is to look at escapeRegExp at the top of this code file, maybe it's not needed?
  8193. var tempFloat = parseFloat(term.replace(/\\\./,'.').replace(/\\\-/,'-'));
  8194. if (!isNaN(tempFloat)) {
  8195. term = tempFloat;
  8196. }
  8197. }
  8198. if (filter.flags.date === true) {
  8199. value = new Date(value);
  8200. // If the term has a dash in it, it comes through as '\-' -- we need to take out the '\'.
  8201. term = new Date(term.replace(/\\/g, ''));
  8202. }
  8203. if (filter.condition === uiGridConstants.filter.GREATER_THAN) {
  8204. return (value > term);
  8205. }
  8206. if (filter.condition === uiGridConstants.filter.GREATER_THAN_OR_EQUAL) {
  8207. return (value >= term);
  8208. }
  8209. if (filter.condition === uiGridConstants.filter.LESS_THAN) {
  8210. return (value < term);
  8211. }
  8212. if (filter.condition === uiGridConstants.filter.LESS_THAN_OR_EQUAL) {
  8213. return (value <= term);
  8214. }
  8215. return true;
  8216. };
  8217. /**
  8218. * @ngdoc boolean
  8219. * @name useExternalFiltering
  8220. * @propertyOf ui.grid.class:GridOptions
  8221. * @description False by default. When enabled, this setting suppresses the internal filtering.
  8222. * All UI logic will still operate, allowing filter conditions to be set and modified.
  8223. *
  8224. * The external filter logic can listen for the `filterChange` event, which fires whenever
  8225. * a filter has been adjusted.
  8226. */
  8227. /**
  8228. * @ngdoc function
  8229. * @name searchColumn
  8230. * @methodOf ui.grid.service:rowSearcher
  8231. * @description Process provided filters on provided column against a given row. If the row meets
  8232. * the conditions on all the filters, return true.
  8233. * @param {Grid} grid Grid to search in
  8234. * @param {GridRow} row Row to search on
  8235. * @param {GridCol} column Column with the filters to use
  8236. * @param {array} filters array of pre-parsed/preprocessed filters to apply
  8237. * @returns {boolean} Whether the column matches or not.
  8238. */
  8239. rowSearcher.searchColumn = function searchColumn(grid, row, column, filters) {
  8240. if (grid.options.useExternalFiltering) {
  8241. return true;
  8242. }
  8243. var filtersLength = filters.length;
  8244. for (var i = 0; i < filtersLength; i++) {
  8245. var filter = filters[i];
  8246. var ret = rowSearcher.runColumnFilter(grid, row, column, filter);
  8247. if (!ret) {
  8248. return false;
  8249. }
  8250. }
  8251. return true;
  8252. };
  8253. /**
  8254. * @ngdoc function
  8255. * @name search
  8256. * @methodOf ui.grid.service:rowSearcher
  8257. * @description Run a search across the given rows and columns, marking any rows that don't
  8258. * match the stored col.filters or col.filter as invisible.
  8259. * @param {Grid} grid Grid instance to search inside
  8260. * @param {Array[GridRow]} rows GridRows to filter
  8261. * @param {Array[GridColumn]} columns GridColumns with filters to process
  8262. */
  8263. rowSearcher.search = function search(grid, rows, columns) {
  8264. /*
  8265. * Added performance optimisations into this code base, as this logic creates deeply nested
  8266. * loops and is therefore very performance sensitive. In particular, avoiding forEach as
  8267. * this impacts some browser optimisers (particularly Chrome), using iterators instead
  8268. */
  8269. // Don't do anything if we weren't passed any rows
  8270. if (!rows) {
  8271. return;
  8272. }
  8273. // don't filter if filtering currently disabled
  8274. if (!grid.options.enableFiltering){
  8275. return rows;
  8276. }
  8277. // Build list of filters to apply
  8278. var filterData = [];
  8279. var colsLength = columns.length;
  8280. var hasTerm = function( filters ) {
  8281. var hasTerm = false;
  8282. filters.forEach( function (filter) {
  8283. if ( !gridUtil.isNullOrUndefined(filter.term) && filter.term !== '' || filter.noTerm ){
  8284. hasTerm = true;
  8285. }
  8286. });
  8287. return hasTerm;
  8288. };
  8289. for (var i = 0; i < colsLength; i++) {
  8290. var col = columns[i];
  8291. if (typeof(col.filters) !== 'undefined' && hasTerm(col.filters) ) {
  8292. filterData.push( { col: col, filters: rowSearcher.setupFilters(col.filters) } );
  8293. }
  8294. }
  8295. if (filterData.length > 0) {
  8296. // define functions outside the loop, performance optimisation
  8297. var foreachRow = function(grid, row, col, filters){
  8298. if ( row.visible && !rowSearcher.searchColumn(grid, row, col, filters) ) {
  8299. row.visible = false;
  8300. }
  8301. };
  8302. var foreachFilterCol = function(grid, filterData){
  8303. var rowsLength = rows.length;
  8304. for ( var i = 0; i < rowsLength; i++){
  8305. foreachRow(grid, rows[i], filterData.col, filterData.filters);
  8306. }
  8307. };
  8308. // nested loop itself - foreachFilterCol, which in turn calls foreachRow
  8309. var filterDataLength = filterData.length;
  8310. for ( var j = 0; j < filterDataLength; j++){
  8311. foreachFilterCol( grid, filterData[j] );
  8312. }
  8313. if (grid.api.core.raise.rowsVisibleChanged) {
  8314. grid.api.core.raise.rowsVisibleChanged();
  8315. }
  8316. // drop any invisible rows
  8317. // keeping these, as needed with filtering for trees - we have to come back and make parent nodes visible if child nodes are selected in the filter
  8318. // rows = rows.filter(function(row){ return row.visible; });
  8319. }
  8320. return rows;
  8321. };
  8322. return rowSearcher;
  8323. }]);
  8324. })();
  8325. (function() {
  8326. var module = angular.module('ui.grid');
  8327. /**
  8328. * @ngdoc object
  8329. * @name ui.grid.class:RowSorter
  8330. * @description RowSorter provides the default sorting mechanisms,
  8331. * including guessing column types and applying appropriate sort
  8332. * algorithms
  8333. *
  8334. */
  8335. module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGridConstants) {
  8336. var currencyRegexStr =
  8337. '(' +
  8338. uiGridConstants.CURRENCY_SYMBOLS
  8339. .map(function (a) { return '\\' + a; }) // Escape all the currency symbols ($ at least will jack up this regex)
  8340. .join('|') + // Join all the symbols together with |s
  8341. ')?';
  8342. // /^[-+]?[£$¤¥]?[\d,.]+%?$/
  8343. var numberStrRegex = new RegExp('^[-+]?' + currencyRegexStr + '[\\d,.]+' + currencyRegexStr + '%?$');
  8344. var rowSorter = {
  8345. // Cache of sorting functions. Once we create them, we don't want to keep re-doing it
  8346. // this takes a piece of data from the cell and tries to determine its type and what sorting
  8347. // function to use for it
  8348. colSortFnCache: {}
  8349. };
  8350. /**
  8351. * @ngdoc method
  8352. * @methodOf ui.grid.class:RowSorter
  8353. * @name guessSortFn
  8354. * @description Assigns a sort function to use based on the itemType in the column
  8355. * @param {string} itemType one of 'number', 'boolean', 'string', 'date', 'object'. And
  8356. * error will be thrown for any other type.
  8357. * @returns {function} a sort function that will sort that type
  8358. */
  8359. rowSorter.guessSortFn = function guessSortFn(itemType) {
  8360. switch (itemType) {
  8361. case "number":
  8362. return rowSorter.sortNumber;
  8363. case "numberStr":
  8364. return rowSorter.sortNumberStr;
  8365. case "boolean":
  8366. return rowSorter.sortBool;
  8367. case "string":
  8368. return rowSorter.sortAlpha;
  8369. case "date":
  8370. return rowSorter.sortDate;
  8371. case "object":
  8372. return rowSorter.basicSort;
  8373. default:
  8374. throw new Error('No sorting function found for type:' + itemType);
  8375. }
  8376. };
  8377. /**
  8378. * @ngdoc method
  8379. * @methodOf ui.grid.class:RowSorter
  8380. * @name handleNulls
  8381. * @description Sorts nulls and undefined to the bottom (top when
  8382. * descending). Called by each of the internal sorters before
  8383. * attempting to sort. Note that this method is available on the core api
  8384. * via gridApi.core.sortHandleNulls
  8385. * @param {object} a sort value a
  8386. * @param {object} b sort value b
  8387. * @returns {number} null if there were no nulls/undefineds, otherwise returns
  8388. * a sort value that should be passed back from the sort function
  8389. */
  8390. rowSorter.handleNulls = function handleNulls(a, b) {
  8391. // We want to allow zero values and false values to be evaluated in the sort function
  8392. if ((!a && a !== 0 && a !== false) || (!b && b !== 0 && b !== false)) {
  8393. // We want to force nulls and such to the bottom when we sort... which effectively is "greater than"
  8394. if ((!a && a !== 0 && a !== false) && (!b && b !== 0 && b !== false)) {
  8395. return 0;
  8396. }
  8397. else if (!a && a !== 0 && a !== false) {
  8398. return 1;
  8399. }
  8400. else if (!b && b !== 0 && b !== false) {
  8401. return -1;
  8402. }
  8403. }
  8404. return null;
  8405. };
  8406. /**
  8407. * @ngdoc method
  8408. * @methodOf ui.grid.class:RowSorter
  8409. * @name basicSort
  8410. * @description Sorts any values that provide the < method, including strings
  8411. * or numbers. Handles nulls and undefined through calling handleNulls
  8412. * @param {object} a sort value a
  8413. * @param {object} b sort value b
  8414. * @returns {number} normal sort function, returns -ve, 0, +ve
  8415. */
  8416. rowSorter.basicSort = function basicSort(a, b) {
  8417. var nulls = rowSorter.handleNulls(a, b);
  8418. if ( nulls !== null ){
  8419. return nulls;
  8420. } else {
  8421. if (a === b) {
  8422. return 0;
  8423. }
  8424. if (a < b) {
  8425. return -1;
  8426. }
  8427. return 1;
  8428. }
  8429. };
  8430. /**
  8431. * @ngdoc method
  8432. * @methodOf ui.grid.class:RowSorter
  8433. * @name sortNumber
  8434. * @description Sorts numerical values. Handles nulls and undefined through calling handleNulls
  8435. * @param {object} a sort value a
  8436. * @param {object} b sort value b
  8437. * @returns {number} normal sort function, returns -ve, 0, +ve
  8438. */
  8439. rowSorter.sortNumber = function sortNumber(a, b) {
  8440. var nulls = rowSorter.handleNulls(a, b);
  8441. if ( nulls !== null ){
  8442. return nulls;
  8443. } else {
  8444. return a - b;
  8445. }
  8446. };
  8447. /**
  8448. * @ngdoc method
  8449. * @methodOf ui.grid.class:RowSorter
  8450. * @name sortNumberStr
  8451. * @description Sorts numerical values that are stored in a string (i.e. parses them to numbers first).
  8452. * Handles nulls and undefined through calling handleNulls
  8453. * @param {object} a sort value a
  8454. * @param {object} b sort value b
  8455. * @returns {number} normal sort function, returns -ve, 0, +ve
  8456. */
  8457. rowSorter.sortNumberStr = function sortNumberStr(a, b) {
  8458. var nulls = rowSorter.handleNulls(a, b);
  8459. if ( nulls !== null ){
  8460. return nulls;
  8461. } else {
  8462. var numA, // The parsed number form of 'a'
  8463. numB, // The parsed number form of 'b'
  8464. badA = false,
  8465. badB = false;
  8466. // Try to parse 'a' to a float
  8467. numA = parseFloat(a.replace(/[^0-9.-]/g, ''));
  8468. // If 'a' couldn't be parsed to float, flag it as bad
  8469. if (isNaN(numA)) {
  8470. badA = true;
  8471. }
  8472. // Try to parse 'b' to a float
  8473. numB = parseFloat(b.replace(/[^0-9.-]/g, ''));
  8474. // If 'b' couldn't be parsed to float, flag it as bad
  8475. if (isNaN(numB)) {
  8476. badB = true;
  8477. }
  8478. // We want bad ones to get pushed to the bottom... which effectively is "greater than"
  8479. if (badA && badB) {
  8480. return 0;
  8481. }
  8482. if (badA) {
  8483. return 1;
  8484. }
  8485. if (badB) {
  8486. return -1;
  8487. }
  8488. return numA - numB;
  8489. }
  8490. };
  8491. /**
  8492. * @ngdoc method
  8493. * @methodOf ui.grid.class:RowSorter
  8494. * @name sortAlpha
  8495. * @description Sorts string values. Handles nulls and undefined through calling handleNulls
  8496. * @param {object} a sort value a
  8497. * @param {object} b sort value b
  8498. * @returns {number} normal sort function, returns -ve, 0, +ve
  8499. */
  8500. rowSorter.sortAlpha = function sortAlpha(a, b) {
  8501. var nulls = rowSorter.handleNulls(a, b);
  8502. if ( nulls !== null ){
  8503. return nulls;
  8504. } else {
  8505. var strA = a.toString().toLowerCase(),
  8506. strB = b.toString().toLowerCase();
  8507. return strA === strB ? 0 : strA.localeCompare(strB);
  8508. }
  8509. };
  8510. /**
  8511. * @ngdoc method
  8512. * @methodOf ui.grid.class:RowSorter
  8513. * @name sortDate
  8514. * @description Sorts date values. Handles nulls and undefined through calling handleNulls.
  8515. * Handles date strings by converting to Date object if not already an instance of Date
  8516. * @param {object} a sort value a
  8517. * @param {object} b sort value b
  8518. * @returns {number} normal sort function, returns -ve, 0, +ve
  8519. */
  8520. rowSorter.sortDate = function sortDate(a, b) {
  8521. var nulls = rowSorter.handleNulls(a, b);
  8522. if ( nulls !== null ){
  8523. return nulls;
  8524. } else {
  8525. if (!(a instanceof Date)) {
  8526. a = new Date(a);
  8527. }
  8528. if (!(b instanceof Date)){
  8529. b = new Date(b);
  8530. }
  8531. var timeA = a.getTime(),
  8532. timeB = b.getTime();
  8533. return timeA === timeB ? 0 : (timeA < timeB ? -1 : 1);
  8534. }
  8535. };
  8536. /**
  8537. * @ngdoc method
  8538. * @methodOf ui.grid.class:RowSorter
  8539. * @name sortBool
  8540. * @description Sorts boolean values, true is considered larger than false.
  8541. * Handles nulls and undefined through calling handleNulls
  8542. * @param {object} a sort value a
  8543. * @param {object} b sort value b
  8544. * @returns {number} normal sort function, returns -ve, 0, +ve
  8545. */
  8546. rowSorter.sortBool = function sortBool(a, b) {
  8547. var nulls = rowSorter.handleNulls(a, b);
  8548. if ( nulls !== null ){
  8549. return nulls;
  8550. } else {
  8551. if (a && b) {
  8552. return 0;
  8553. }
  8554. if (!a && !b) {
  8555. return 0;
  8556. }
  8557. else {
  8558. return a ? 1 : -1;
  8559. }
  8560. }
  8561. };
  8562. /**
  8563. * @ngdoc method
  8564. * @methodOf ui.grid.class:RowSorter
  8565. * @name getSortFn
  8566. * @description Get the sort function for the column. Looks first in
  8567. * rowSorter.colSortFnCache using the column name, failing that it
  8568. * looks at col.sortingAlgorithm (and puts it in the cache), failing that
  8569. * it guesses the sort algorithm based on the data type.
  8570. *
  8571. * The cache currently seems a bit pointless, as none of the work we do is
  8572. * processor intensive enough to need caching. Presumably in future we might
  8573. * inspect the row data itself to guess the sort function, and in that case
  8574. * it would make sense to have a cache, the infrastructure is in place to allow
  8575. * that.
  8576. *
  8577. * @param {Grid} grid the grid to consider
  8578. * @param {GridCol} col the column to find a function for
  8579. * @param {array} rows an array of grid rows. Currently unused, but presumably in future
  8580. * we might inspect the rows themselves to decide what sort of data might be there
  8581. * @returns {function} the sort function chosen for the column
  8582. */
  8583. rowSorter.getSortFn = function getSortFn(grid, col, rows) {
  8584. var sortFn, item;
  8585. // See if we already figured out what to use to sort the column and have it in the cache
  8586. if (rowSorter.colSortFnCache[col.colDef.name]) {
  8587. sortFn = rowSorter.colSortFnCache[col.colDef.name];
  8588. }
  8589. // If the column has its OWN sorting algorithm, use that
  8590. else if (col.sortingAlgorithm !== undefined) {
  8591. sortFn = col.sortingAlgorithm;
  8592. rowSorter.colSortFnCache[col.colDef.name] = col.sortingAlgorithm;
  8593. }
  8594. // Always default to sortAlpha when sorting after a cellFilter
  8595. else if ( col.sortCellFiltered && col.cellFilter ){
  8596. sortFn = rowSorter.sortAlpha;
  8597. rowSorter.colSortFnCache[col.colDef.name] = sortFn;
  8598. }
  8599. // Try and guess what sort function to use
  8600. else {
  8601. // Guess the sort function
  8602. sortFn = rowSorter.guessSortFn(col.colDef.type);
  8603. // If we found a sort function, cache it
  8604. if (sortFn) {
  8605. rowSorter.colSortFnCache[col.colDef.name] = sortFn;
  8606. }
  8607. else {
  8608. // We assign the alpha sort because anything that is null/undefined will never get passed to
  8609. // the actual sorting function. It will get caught in our null check and returned to be sorted
  8610. // down to the bottom
  8611. sortFn = rowSorter.sortAlpha;
  8612. }
  8613. }
  8614. return sortFn;
  8615. };
  8616. /**
  8617. * @ngdoc method
  8618. * @methodOf ui.grid.class:RowSorter
  8619. * @name prioritySort
  8620. * @description Used where multiple columns are present in the sort criteria,
  8621. * we determine which column should take precedence in the sort by sorting
  8622. * the columns based on their sort.priority
  8623. *
  8624. * @param {gridColumn} a column a
  8625. * @param {gridColumn} b column b
  8626. * @returns {number} normal sort function, returns -ve, 0, +ve
  8627. */
  8628. rowSorter.prioritySort = function (a, b) {
  8629. // Both columns have a sort priority
  8630. if (a.sort.priority !== undefined && b.sort.priority !== undefined) {
  8631. // A is higher priority
  8632. if (a.sort.priority < b.sort.priority) {
  8633. return -1;
  8634. }
  8635. // Equal
  8636. else if (a.sort.priority === b.sort.priority) {
  8637. return 0;
  8638. }
  8639. // B is higher
  8640. else {
  8641. return 1;
  8642. }
  8643. }
  8644. // Only A has a priority
  8645. else if (a.sort.priority || a.sort.priority === undefined) {
  8646. return -1;
  8647. }
  8648. // Only B has a priority
  8649. else if (b.sort.priority || b.sort.priority === undefined) {
  8650. return 1;
  8651. }
  8652. // Neither has a priority
  8653. else {
  8654. return 0;
  8655. }
  8656. };
  8657. /**
  8658. * @ngdoc object
  8659. * @name useExternalSorting
  8660. * @propertyOf ui.grid.class:GridOptions
  8661. * @description Prevents the internal sorting from executing. Events will
  8662. * still be fired when the sort changes, and the sort information on
  8663. * the columns will be updated, allowing an external sorter (for example,
  8664. * server sorting) to be implemented. Defaults to false.
  8665. *
  8666. */
  8667. /**
  8668. * @ngdoc method
  8669. * @methodOf ui.grid.class:RowSorter
  8670. * @name sort
  8671. * @description sorts the grid
  8672. * @param {Object} grid the grid itself
  8673. * @param {array} rows the rows to be sorted
  8674. * @param {array} columns the columns in which to look
  8675. * for sort criteria
  8676. * @returns {array} sorted rows
  8677. */
  8678. rowSorter.sort = function rowSorterSort(grid, rows, columns) {
  8679. // first make sure we are even supposed to do work
  8680. if (!rows) {
  8681. return;
  8682. }
  8683. if (grid.options.useExternalSorting){
  8684. return rows;
  8685. }
  8686. // Build the list of columns to sort by
  8687. var sortCols = [];
  8688. columns.forEach(function (col) {
  8689. if (col.sort && !col.sort.ignoreSort && col.sort.direction && (col.sort.direction === uiGridConstants.ASC || col.sort.direction === uiGridConstants.DESC)) {
  8690. sortCols.push(col);
  8691. }
  8692. });
  8693. // Sort the "sort columns" by their sort priority
  8694. sortCols = sortCols.sort(rowSorter.prioritySort);
  8695. // Now rows to sort by, maintain original order
  8696. if (sortCols.length === 0) {
  8697. return rows;
  8698. }
  8699. // Re-usable variables
  8700. var col, direction;
  8701. // put a custom index field on each row, used to make a stable sort out of unstable sorts (e.g. Chrome)
  8702. var setIndex = function( row, idx ){
  8703. row.entity.$$uiGridIndex = idx;
  8704. };
  8705. rows.forEach(setIndex);
  8706. // IE9-11 HACK.... the 'rows' variable would be empty where we call rowSorter.getSortFn(...) below. We have to use a separate reference
  8707. // var d = data.slice(0);
  8708. var r = rows.slice(0);
  8709. // Now actually sort the data
  8710. var rowSortFn = function (rowA, rowB) {
  8711. var tem = 0,
  8712. idx = 0,
  8713. sortFn;
  8714. while (tem === 0 && idx < sortCols.length) {
  8715. // grab the metadata for the rest of the logic
  8716. col = sortCols[idx];
  8717. direction = sortCols[idx].sort.direction;
  8718. sortFn = rowSorter.getSortFn(grid, col, r);
  8719. var propA, propB;
  8720. if ( col.sortCellFiltered ){
  8721. propA = grid.getCellDisplayValue(rowA, col);
  8722. propB = grid.getCellDisplayValue(rowB, col);
  8723. } else {
  8724. propA = grid.getCellValue(rowA, col);
  8725. propB = grid.getCellValue(rowB, col);
  8726. }
  8727. tem = sortFn(propA, propB, rowA, rowB, direction);
  8728. idx++;
  8729. }
  8730. // Chrome doesn't implement a stable sort function. If our sort returns 0
  8731. // (i.e. the items are equal), and we're at the last sort column in the list,
  8732. // then return the previous order using our custom
  8733. // index variable
  8734. if (tem === 0 ) {
  8735. return rowA.entity.$$uiGridIndex - rowB.entity.$$uiGridIndex;
  8736. }
  8737. // Made it this far, we don't have to worry about null & undefined
  8738. if (direction === uiGridConstants.ASC) {
  8739. return tem;
  8740. } else {
  8741. return 0 - tem;
  8742. }
  8743. };
  8744. var newRows = rows.sort(rowSortFn);
  8745. // remove the custom index field on each row, used to make a stable sort out of unstable sorts (e.g. Chrome)
  8746. var clearIndex = function( row, idx ){
  8747. delete row.entity.$$uiGridIndex;
  8748. };
  8749. rows.forEach(clearIndex);
  8750. return newRows;
  8751. };
  8752. return rowSorter;
  8753. }]);
  8754. })();
  8755. (function() {
  8756. var module = angular.module('ui.grid');
  8757. var bindPolyfill;
  8758. if (typeof Function.prototype.bind !== "function") {
  8759. bindPolyfill = function() {
  8760. var slice = Array.prototype.slice;
  8761. return function(context) {
  8762. var fn = this,
  8763. args = slice.call(arguments, 1);
  8764. if (args.length) {
  8765. return function() {
  8766. return arguments.length ? fn.apply(context, args.concat(slice.call(arguments))) : fn.apply(context, args);
  8767. };
  8768. }
  8769. return function() {
  8770. return arguments.length ? fn.apply(context, arguments) : fn.call(context);
  8771. };
  8772. };
  8773. };
  8774. }
  8775. function getStyles (elem) {
  8776. var e = elem;
  8777. if (typeof(e.length) !== 'undefined' && e.length) {
  8778. e = elem[0];
  8779. }
  8780. return e.ownerDocument.defaultView.getComputedStyle(e, null);
  8781. }
  8782. var rnumnonpx = new RegExp( "^(" + (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source + ")(?!px)[a-z%]+$", "i" ),
  8783. // swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
  8784. // see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
  8785. rdisplayswap = /^(block|none|table(?!-c[ea]).+)/,
  8786. cssShow = { position: "absolute", visibility: "hidden", display: "block" };
  8787. function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
  8788. var i = extra === ( isBorderBox ? 'border' : 'content' ) ?
  8789. // If we already have the right measurement, avoid augmentation
  8790. 4 :
  8791. // Otherwise initialize for horizontal or vertical properties
  8792. name === 'width' ? 1 : 0,
  8793. val = 0;
  8794. var sides = ['Top', 'Right', 'Bottom', 'Left'];
  8795. for ( ; i < 4; i += 2 ) {
  8796. var side = sides[i];
  8797. // dump('side', side);
  8798. // both box models exclude margin, so add it if we want it
  8799. if ( extra === 'margin' ) {
  8800. var marg = parseFloat(styles[extra + side]);
  8801. if (!isNaN(marg)) {
  8802. val += marg;
  8803. }
  8804. }
  8805. // dump('val1', val);
  8806. if ( isBorderBox ) {
  8807. // border-box includes padding, so remove it if we want content
  8808. if ( extra === 'content' ) {
  8809. var padd = parseFloat(styles['padding' + side]);
  8810. if (!isNaN(padd)) {
  8811. val -= padd;
  8812. // dump('val2', val);
  8813. }
  8814. }
  8815. // at this point, extra isn't border nor margin, so remove border
  8816. if ( extra !== 'margin' ) {
  8817. var bordermarg = parseFloat(styles['border' + side + 'Width']);
  8818. if (!isNaN(bordermarg)) {
  8819. val -= bordermarg;
  8820. // dump('val3', val);
  8821. }
  8822. }
  8823. }
  8824. else {
  8825. // at this point, extra isn't content, so add padding
  8826. var nocontentPad = parseFloat(styles['padding' + side]);
  8827. if (!isNaN(nocontentPad)) {
  8828. val += nocontentPad;
  8829. // dump('val4', val);
  8830. }
  8831. // at this point, extra isn't content nor padding, so add border
  8832. if ( extra !== 'padding') {
  8833. var nocontentnopad = parseFloat(styles['border' + side + 'Width']);
  8834. if (!isNaN(nocontentnopad)) {
  8835. val += nocontentnopad;
  8836. // dump('val5', val);
  8837. }
  8838. }
  8839. }
  8840. }
  8841. // dump('augVal', val);
  8842. return val;
  8843. }
  8844. function getWidthOrHeight( elem, name, extra ) {
  8845. // Start with offset property, which is equivalent to the border-box value
  8846. var valueIsBorderBox = true,
  8847. val, // = name === 'width' ? elem.offsetWidth : elem.offsetHeight,
  8848. styles = getStyles(elem),
  8849. isBorderBox = styles['boxSizing'] === 'border-box';
  8850. // some non-html elements return undefined for offsetWidth, so check for null/undefined
  8851. // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
  8852. // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
  8853. if ( val <= 0 || val == null ) {
  8854. // Fall back to computed then uncomputed css if necessary
  8855. val = styles[name];
  8856. if ( val < 0 || val == null ) {
  8857. val = elem.style[ name ];
  8858. }
  8859. // Computed unit is not pixels. Stop here and return.
  8860. if ( rnumnonpx.test(val) ) {
  8861. return val;
  8862. }
  8863. // we need the check for style in case a browser which returns unreliable values
  8864. // for getComputedStyle silently falls back to the reliable elem.style
  8865. valueIsBorderBox = isBorderBox &&
  8866. ( true || val === elem.style[ name ] ); // use 'true' instead of 'support.boxSizingReliable()'
  8867. // Normalize "", auto, and prepare for extra
  8868. val = parseFloat( val ) || 0;
  8869. }
  8870. // use the active box-sizing model to add/subtract irrelevant styles
  8871. var ret = ( val +
  8872. augmentWidthOrHeight(
  8873. elem,
  8874. name,
  8875. extra || ( isBorderBox ? "border" : "content" ),
  8876. valueIsBorderBox,
  8877. styles
  8878. )
  8879. );
  8880. // dump('ret', ret, val);
  8881. return ret;
  8882. }
  8883. function getLineHeight(elm) {
  8884. elm = angular.element(elm)[0];
  8885. var parent = elm.parentElement;
  8886. if (!parent) {
  8887. parent = document.getElementsByTagName('body')[0];
  8888. }
  8889. return parseInt( getStyles(parent).fontSize ) || parseInt( getStyles(elm).fontSize ) || 16;
  8890. }
  8891. var uid = ['0', '0', '0', '0'];
  8892. var uidPrefix = 'uiGrid-';
  8893. /**
  8894. * @ngdoc service
  8895. * @name ui.grid.service:GridUtil
  8896. *
  8897. * @description Grid utility functions
  8898. */
  8899. module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateCache', '$timeout', '$interval', '$injector', '$q', '$interpolate', 'uiGridConstants',
  8900. function ($log, $window, $document, $http, $templateCache, $timeout, $interval, $injector, $q, $interpolate, uiGridConstants) {
  8901. var s = {
  8902. augmentWidthOrHeight: augmentWidthOrHeight,
  8903. getStyles: getStyles,
  8904. /**
  8905. * @ngdoc method
  8906. * @name createBoundedWrapper
  8907. * @methodOf ui.grid.service:GridUtil
  8908. *
  8909. * @param {object} Object to bind 'this' to
  8910. * @param {method} Method to bind
  8911. * @returns {Function} The wrapper that performs the binding
  8912. *
  8913. * @description
  8914. * Binds given method to given object.
  8915. *
  8916. * By means of a wrapper, ensures that ``method`` is always bound to
  8917. * ``object`` regardless of its calling environment.
  8918. * Iow, inside ``method``, ``this`` always points to ``object``.
  8919. *
  8920. * See http://alistapart.com/article/getoutbindingsituations
  8921. *
  8922. */
  8923. createBoundedWrapper: function(object, method) {
  8924. return function() {
  8925. return method.apply(object, arguments);
  8926. };
  8927. },
  8928. /**
  8929. * @ngdoc method
  8930. * @name readableColumnName
  8931. * @methodOf ui.grid.service:GridUtil
  8932. *
  8933. * @param {string} columnName Column name as a string
  8934. * @returns {string} Column name appropriately capitalized and split apart
  8935. *
  8936. @example
  8937. <example module="app">
  8938. <file name="app.js">
  8939. var app = angular.module('app', ['ui.grid']);
  8940. app.controller('MainCtrl', ['$scope', 'gridUtil', function ($scope, gridUtil) {
  8941. $scope.name = 'firstName';
  8942. $scope.columnName = function(name) {
  8943. return gridUtil.readableColumnName(name);
  8944. };
  8945. }]);
  8946. </file>
  8947. <file name="index.html">
  8948. <div ng-controller="MainCtrl">
  8949. <strong>Column name:</strong> <input ng-model="name" />
  8950. <br>
  8951. <strong>Output:</strong> <span ng-bind="columnName(name)"></span>
  8952. </div>
  8953. </file>
  8954. </example>
  8955. */
  8956. readableColumnName: function (columnName) {
  8957. // Convert underscores to spaces
  8958. if (typeof(columnName) === 'undefined' || columnName === undefined || columnName === null) { return columnName; }
  8959. if (typeof(columnName) !== 'string') {
  8960. columnName = String(columnName);
  8961. }
  8962. return columnName.replace(/_+/g, ' ')
  8963. // Replace a completely all-capsed word with a first-letter-capitalized version
  8964. .replace(/^[A-Z]+$/, function (match) {
  8965. return angular.lowercase(angular.uppercase(match.charAt(0)) + match.slice(1));
  8966. })
  8967. // Capitalize the first letter of words
  8968. .replace(/([\w\u00C0-\u017F]+)/g, function (match) {
  8969. return angular.uppercase(match.charAt(0)) + match.slice(1);
  8970. })
  8971. // Put a space in between words that have partial capilizations (i.e. 'firstName' becomes 'First Name')
  8972. // .replace(/([A-Z]|[A-Z]\w+)([A-Z])/g, "$1 $2");
  8973. // .replace(/(\w+?|\w)([A-Z])/g, "$1 $2");
  8974. .replace(/(\w+?(?=[A-Z]))/g, '$1 ');
  8975. },
  8976. /**
  8977. * @ngdoc method
  8978. * @name getColumnsFromData
  8979. * @methodOf ui.grid.service:GridUtil
  8980. * @description Return a list of column names, given a data set
  8981. *
  8982. * @param {string} data Data array for grid
  8983. * @returns {Object} Column definitions with field accessor and column name
  8984. *
  8985. * @example
  8986. <pre>
  8987. var data = [
  8988. { firstName: 'Bob', lastName: 'Jones' },
  8989. { firstName: 'Frank', lastName: 'Smith' }
  8990. ];
  8991. var columnDefs = GridUtil.getColumnsFromData(data, excludeProperties);
  8992. columnDefs == [
  8993. {
  8994. field: 'firstName',
  8995. name: 'First Name'
  8996. },
  8997. {
  8998. field: 'lastName',
  8999. name: 'Last Name'
  9000. }
  9001. ];
  9002. </pre>
  9003. */
  9004. getColumnsFromData: function (data, excludeProperties) {
  9005. var columnDefs = [];
  9006. if (!data || typeof(data[0]) === 'undefined' || data[0] === undefined) { return []; }
  9007. if (angular.isUndefined(excludeProperties)) { excludeProperties = []; }
  9008. var item = data[0];
  9009. angular.forEach(item,function (prop, propName) {
  9010. if ( excludeProperties.indexOf(propName) === -1){
  9011. columnDefs.push({
  9012. name: propName
  9013. });
  9014. }
  9015. });
  9016. return columnDefs;
  9017. },
  9018. /**
  9019. * @ngdoc method
  9020. * @name newId
  9021. * @methodOf ui.grid.service:GridUtil
  9022. * @description Return a unique ID string
  9023. *
  9024. * @returns {string} Unique string
  9025. *
  9026. * @example
  9027. <pre>
  9028. var id = GridUtil.newId();
  9029. # 1387305700482;
  9030. </pre>
  9031. */
  9032. newId: (function() {
  9033. var seedId = new Date().getTime();
  9034. return function() {
  9035. return seedId += 1;
  9036. };
  9037. })(),
  9038. /**
  9039. * @ngdoc method
  9040. * @name getTemplate
  9041. * @methodOf ui.grid.service:GridUtil
  9042. * @description Get's template from cache / element / url
  9043. *
  9044. * @param {string|element|promise} Either a string representing the template id, a string representing the template url,
  9045. * an jQuery/Angualr element, or a promise that returns the template contents to use.
  9046. * @returns {object} a promise resolving to template contents
  9047. *
  9048. * @example
  9049. <pre>
  9050. GridUtil.getTemplate(url).then(function (contents) {
  9051. alert(contents);
  9052. })
  9053. </pre>
  9054. */
  9055. getTemplate: function (template) {
  9056. // Try to fetch the template out of the templateCache
  9057. if ($templateCache.get(template)) {
  9058. return s.postProcessTemplate($templateCache.get(template));
  9059. }
  9060. // See if the template is itself a promise
  9061. if (template.hasOwnProperty('then')) {
  9062. return template.then(s.postProcessTemplate);
  9063. }
  9064. // If the template is an element, return the element
  9065. try {
  9066. if (angular.element(template).length > 0) {
  9067. return $q.when(template).then(s.postProcessTemplate);
  9068. }
  9069. }
  9070. catch (err){
  9071. //do nothing; not valid html
  9072. }
  9073. s.logDebug('fetching url', template);
  9074. // Default to trying to fetch the template as a url with $http
  9075. return $http({ method: 'GET', url: template})
  9076. .then(
  9077. function (result) {
  9078. var templateHtml = result.data.trim();
  9079. //put in templateCache for next call
  9080. $templateCache.put(template, templateHtml);
  9081. return templateHtml;
  9082. },
  9083. function (err) {
  9084. throw new Error("Could not get template " + template + ": " + err);
  9085. }
  9086. )
  9087. .then(s.postProcessTemplate);
  9088. },
  9089. //
  9090. postProcessTemplate: function (template) {
  9091. var startSym = $interpolate.startSymbol(),
  9092. endSym = $interpolate.endSymbol();
  9093. // If either of the interpolation symbols have been changed, we need to alter this template
  9094. if (startSym !== '{{' || endSym !== '}}') {
  9095. template = template.replace(/\{\{/g, startSym);
  9096. template = template.replace(/\}\}/g, endSym);
  9097. }
  9098. return $q.when(template);
  9099. },
  9100. /**
  9101. * @ngdoc method
  9102. * @name guessType
  9103. * @methodOf ui.grid.service:GridUtil
  9104. * @description guesses the type of an argument
  9105. *
  9106. * @param {string/number/bool/object} item variable to examine
  9107. * @returns {string} one of the following
  9108. * - 'string'
  9109. * - 'boolean'
  9110. * - 'number'
  9111. * - 'date'
  9112. * - 'object'
  9113. */
  9114. guessType : function (item) {
  9115. var itemType = typeof(item);
  9116. // Check for numbers and booleans
  9117. switch (itemType) {
  9118. case "number":
  9119. case "boolean":
  9120. case "string":
  9121. return itemType;
  9122. default:
  9123. if (angular.isDate(item)) {
  9124. return "date";
  9125. }
  9126. return "object";
  9127. }
  9128. },
  9129. /**
  9130. * @ngdoc method
  9131. * @name elementWidth
  9132. * @methodOf ui.grid.service:GridUtil
  9133. *
  9134. * @param {element} element DOM element
  9135. * @param {string} [extra] Optional modifier for calculation. Use 'margin' to account for margins on element
  9136. *
  9137. * @returns {number} Element width in pixels, accounting for any borders, etc.
  9138. */
  9139. elementWidth: function (elem) {
  9140. },
  9141. /**
  9142. * @ngdoc method
  9143. * @name elementHeight
  9144. * @methodOf ui.grid.service:GridUtil
  9145. *
  9146. * @param {element} element DOM element
  9147. * @param {string} [extra] Optional modifier for calculation. Use 'margin' to account for margins on element
  9148. *
  9149. * @returns {number} Element height in pixels, accounting for any borders, etc.
  9150. */
  9151. elementHeight: function (elem) {
  9152. },
  9153. // Thanks to http://stackoverflow.com/a/13382873/888165
  9154. getScrollbarWidth: function() {
  9155. var outer = document.createElement("div");
  9156. outer.style.visibility = "hidden";
  9157. outer.style.width = "100px";
  9158. outer.style.msOverflowStyle = "scrollbar"; // needed for WinJS apps
  9159. document.body.appendChild(outer);
  9160. var widthNoScroll = outer.offsetWidth;
  9161. // force scrollbars
  9162. outer.style.overflow = "scroll";
  9163. // add innerdiv
  9164. var inner = document.createElement("div");
  9165. inner.style.width = "100%";
  9166. outer.appendChild(inner);
  9167. var widthWithScroll = inner.offsetWidth;
  9168. // remove divs
  9169. outer.parentNode.removeChild(outer);
  9170. return widthNoScroll - widthWithScroll;
  9171. },
  9172. swap: function( elem, options, callback, args ) {
  9173. var ret, name,
  9174. old = {};
  9175. // Remember the old values, and insert the new ones
  9176. for ( name in options ) {
  9177. old[ name ] = elem.style[ name ];
  9178. elem.style[ name ] = options[ name ];
  9179. }
  9180. ret = callback.apply( elem, args || [] );
  9181. // Revert the old values
  9182. for ( name in options ) {
  9183. elem.style[ name ] = old[ name ];
  9184. }
  9185. return ret;
  9186. },
  9187. fakeElement: function( elem, options, callback, args ) {
  9188. var ret, name,
  9189. newElement = angular.element(elem).clone()[0];
  9190. for ( name in options ) {
  9191. newElement.style[ name ] = options[ name ];
  9192. }
  9193. angular.element(document.body).append(newElement);
  9194. ret = callback.call( newElement, newElement );
  9195. angular.element(newElement).remove();
  9196. return ret;
  9197. },
  9198. /**
  9199. * @ngdoc method
  9200. * @name normalizeWheelEvent
  9201. * @methodOf ui.grid.service:GridUtil
  9202. *
  9203. * @param {event} event A mouse wheel event
  9204. *
  9205. * @returns {event} A normalized event
  9206. *
  9207. * @description
  9208. * Given an event from this list:
  9209. *
  9210. * `wheel, mousewheel, DomMouseScroll, MozMousePixelScroll`
  9211. *
  9212. * "normalize" it
  9213. * so that it stays consistent no matter what browser it comes from (i.e. scale it correctly and make sure the direction is right.)
  9214. */
  9215. normalizeWheelEvent: function (event) {
  9216. // var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'];
  9217. // var toBind = 'onwheel' in document || document.documentMode >= 9 ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'];
  9218. var lowestDelta, lowestDeltaXY;
  9219. var orgEvent = event || window.event,
  9220. args = [].slice.call(arguments, 1),
  9221. delta = 0,
  9222. deltaX = 0,
  9223. deltaY = 0,
  9224. absDelta = 0,
  9225. absDeltaXY = 0,
  9226. fn;
  9227. // event = $.event.fix(orgEvent);
  9228. // event.type = 'mousewheel';
  9229. // NOTE: jQuery masks the event and stores it in the event as originalEvent
  9230. if (orgEvent.originalEvent) {
  9231. orgEvent = orgEvent.originalEvent;
  9232. }
  9233. // Old school scrollwheel delta
  9234. if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta; }
  9235. if ( orgEvent.detail ) { delta = orgEvent.detail * -1; }
  9236. // At a minimum, setup the deltaY to be delta
  9237. deltaY = delta;
  9238. // Firefox < 17 related to DOMMouseScroll event
  9239. if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
  9240. deltaY = 0;
  9241. deltaX = delta * -1;
  9242. }
  9243. // New school wheel delta (wheel event)
  9244. if ( orgEvent.deltaY ) {
  9245. deltaY = orgEvent.deltaY * -1;
  9246. delta = deltaY;
  9247. }
  9248. if ( orgEvent.deltaX ) {
  9249. deltaX = orgEvent.deltaX;
  9250. delta = deltaX * -1;
  9251. }
  9252. // Webkit
  9253. if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY; }
  9254. if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = orgEvent.wheelDeltaX; }
  9255. // Look for lowest delta to normalize the delta values
  9256. absDelta = Math.abs(delta);
  9257. if ( !lowestDelta || absDelta < lowestDelta ) { lowestDelta = absDelta; }
  9258. absDeltaXY = Math.max(Math.abs(deltaY), Math.abs(deltaX));
  9259. if ( !lowestDeltaXY || absDeltaXY < lowestDeltaXY ) { lowestDeltaXY = absDeltaXY; }
  9260. // Get a whole value for the deltas
  9261. fn = delta > 0 ? 'floor' : 'ceil';
  9262. delta = Math[fn](delta / lowestDelta);
  9263. deltaX = Math[fn](deltaX / lowestDeltaXY);
  9264. deltaY = Math[fn](deltaY / lowestDeltaXY);
  9265. return {
  9266. delta: delta,
  9267. deltaX: deltaX,
  9268. deltaY: deltaY
  9269. };
  9270. },
  9271. // Stolen from Modernizr
  9272. // TODO: make this, and everythign that flows from it, robust
  9273. //http://www.stucox.com/blog/you-cant-detect-a-touchscreen/
  9274. isTouchEnabled: function() {
  9275. var bool;
  9276. if (('ontouchstart' in $window) || $window.DocumentTouch && $document instanceof DocumentTouch) {
  9277. bool = true;
  9278. }
  9279. return bool;
  9280. },
  9281. isNullOrUndefined: function(obj) {
  9282. if (obj === undefined || obj === null) {
  9283. return true;
  9284. }
  9285. return false;
  9286. },
  9287. endsWith: function(str, suffix) {
  9288. if (!str || !suffix || typeof str !== "string") {
  9289. return false;
  9290. }
  9291. return str.indexOf(suffix, str.length - suffix.length) !== -1;
  9292. },
  9293. arrayContainsObjectWithProperty: function(array, propertyName, propertyValue) {
  9294. var found = false;
  9295. angular.forEach(array, function (object) {
  9296. if (object[propertyName] === propertyValue) {
  9297. found = true;
  9298. }
  9299. });
  9300. return found;
  9301. },
  9302. //// Shim requestAnimationFrame
  9303. //requestAnimationFrame: $window.requestAnimationFrame && $window.requestAnimationFrame.bind($window) ||
  9304. // $window.webkitRequestAnimationFrame && $window.webkitRequestAnimationFrame.bind($window) ||
  9305. // function(fn) {
  9306. // return $timeout(fn, 10, false);
  9307. // },
  9308. numericAndNullSort: function (a, b) {
  9309. if (a === null) { return 1; }
  9310. if (b === null) { return -1; }
  9311. if (a === null && b === null) { return 0; }
  9312. return a - b;
  9313. },
  9314. // Disable ngAnimate animations on an element
  9315. disableAnimations: function (element) {
  9316. var $animate;
  9317. try {
  9318. $animate = $injector.get('$animate');
  9319. // See: http://brianhann.com/angular-1-4-breaking-changes-to-be-aware-of/#animate
  9320. if (angular.version.major > 1 || (angular.version.major === 1 && angular.version.minor >= 4)) {
  9321. $animate.enabled(element, false);
  9322. } else {
  9323. $animate.enabled(false, element);
  9324. }
  9325. }
  9326. catch (e) {}
  9327. },
  9328. enableAnimations: function (element) {
  9329. var $animate;
  9330. try {
  9331. $animate = $injector.get('$animate');
  9332. // See: http://brianhann.com/angular-1-4-breaking-changes-to-be-aware-of/#animate
  9333. if (angular.version.major > 1 || (angular.version.major === 1 && angular.version.minor >= 4)) {
  9334. $animate.enabled(element, true);
  9335. } else {
  9336. $animate.enabled(true, element);
  9337. }
  9338. return $animate;
  9339. }
  9340. catch (e) {}
  9341. },
  9342. // Blatantly stolen from Angular as it isn't exposed (yet. 2.0 maybe?)
  9343. nextUid: function nextUid() {
  9344. var index = uid.length;
  9345. var digit;
  9346. while (index) {
  9347. index--;
  9348. digit = uid[index].charCodeAt(0);
  9349. if (digit === 57 /*'9'*/) {
  9350. uid[index] = 'A';
  9351. return uidPrefix + uid.join('');
  9352. }
  9353. if (digit === 90 /*'Z'*/) {
  9354. uid[index] = '0';
  9355. } else {
  9356. uid[index] = String.fromCharCode(digit + 1);
  9357. return uidPrefix + uid.join('');
  9358. }
  9359. }
  9360. uid.unshift('0');
  9361. return uidPrefix + uid.join('');
  9362. },
  9363. // Blatantly stolen from Angular as it isn't exposed (yet. 2.0 maybe?)
  9364. hashKey: function hashKey(obj) {
  9365. var objType = typeof obj,
  9366. key;
  9367. if (objType === 'object' && obj !== null) {
  9368. if (typeof (key = obj.$$hashKey) === 'function') {
  9369. // must invoke on object to keep the right this
  9370. key = obj.$$hashKey();
  9371. }
  9372. else if (typeof(obj.$$hashKey) !== 'undefined' && obj.$$hashKey) {
  9373. key = obj.$$hashKey;
  9374. }
  9375. else if (key === undefined) {
  9376. key = obj.$$hashKey = s.nextUid();
  9377. }
  9378. }
  9379. else {
  9380. key = obj;
  9381. }
  9382. return objType + ':' + key;
  9383. },
  9384. resetUids: function () {
  9385. uid = ['0', '0', '0'];
  9386. },
  9387. /**
  9388. * @ngdoc method
  9389. * @methodOf ui.grid.service:GridUtil
  9390. * @name logError
  9391. * @description wraps the $log method, allowing us to choose different
  9392. * treatment within ui-grid if we so desired. At present we only log
  9393. * error messages if uiGridConstants.LOG_ERROR_MESSAGES is set to true
  9394. * @param {string} logMessage message to be logged to the console
  9395. *
  9396. */
  9397. logError: function( logMessage ){
  9398. if ( uiGridConstants.LOG_ERROR_MESSAGES ){
  9399. $log.error( logMessage );
  9400. }
  9401. },
  9402. /**
  9403. * @ngdoc method
  9404. * @methodOf ui.grid.service:GridUtil
  9405. * @name logWarn
  9406. * @description wraps the $log method, allowing us to choose different
  9407. * treatment within ui-grid if we so desired. At present we only log
  9408. * warning messages if uiGridConstants.LOG_WARN_MESSAGES is set to true
  9409. * @param {string} logMessage message to be logged to the console
  9410. *
  9411. */
  9412. logWarn: function( logMessage ){
  9413. if ( uiGridConstants.LOG_WARN_MESSAGES ){
  9414. $log.warn( logMessage );
  9415. }
  9416. },
  9417. /**
  9418. * @ngdoc method
  9419. * @methodOf ui.grid.service:GridUtil
  9420. * @name logDebug
  9421. * @description wraps the $log method, allowing us to choose different
  9422. * treatment within ui-grid if we so desired. At present we only log
  9423. * debug messages if uiGridConstants.LOG_DEBUG_MESSAGES is set to true
  9424. *
  9425. */
  9426. logDebug: function() {
  9427. if ( uiGridConstants.LOG_DEBUG_MESSAGES ){
  9428. $log.debug.apply($log, arguments);
  9429. }
  9430. }
  9431. };
  9432. /**
  9433. * @ngdoc object
  9434. * @name focus
  9435. * @propertyOf ui.grid.service:GridUtil
  9436. * @description Provies a set of methods to set the document focus inside the grid.
  9437. * See {@link ui.grid.service:GridUtil.focus} for more information.
  9438. */
  9439. /**
  9440. * @ngdoc object
  9441. * @name ui.grid.service:GridUtil.focus
  9442. * @description Provies a set of methods to set the document focus inside the grid.
  9443. * Timeouts are utilized to ensure that the focus is invoked after any other event has been triggered.
  9444. * e.g. click events that need to run before the focus or
  9445. * inputs elements that are in a disabled state but are enabled when those events
  9446. * are triggered.
  9447. */
  9448. s.focus = {
  9449. queue: [],
  9450. //http://stackoverflow.com/questions/25596399/set-element-focus-in-angular-way
  9451. /**
  9452. * @ngdoc method
  9453. * @methodOf ui.grid.service:GridUtil.focus
  9454. * @name byId
  9455. * @description Sets the focus of the document to the given id value.
  9456. * If provided with the grid object it will automatically append the grid id.
  9457. * This is done to encourage unique dom id's as it allows for multiple grids on a
  9458. * page.
  9459. * @param {String} id the id of the dom element to set the focus on
  9460. * @param {Object=} Grid the grid object for this grid instance. See: {@link ui.grid.class:Grid}
  9461. * @param {Number} Grid.id the unique id for this grid. Already set on an initialized grid object.
  9462. * @returns {Promise} The `$timeout` promise that will be resolved once focus is set. If another focus is requested before this request is evaluated.
  9463. * then the promise will fail with the `'canceled'` reason.
  9464. */
  9465. byId: function (id, Grid) {
  9466. this._purgeQueue();
  9467. var promise = $timeout(function() {
  9468. var elementID = (Grid && Grid.id ? Grid.id + '-' : '') + id;
  9469. var element = $window.document.getElementById(elementID);
  9470. if (element) {
  9471. element.focus();
  9472. } else {
  9473. s.logWarn('[focus.byId] Element id ' + elementID + ' was not found.');
  9474. }
  9475. });
  9476. this.queue.push(promise);
  9477. return promise;
  9478. },
  9479. /**
  9480. * @ngdoc method
  9481. * @methodOf ui.grid.service:GridUtil.focus
  9482. * @name byElement
  9483. * @description Sets the focus of the document to the given dom element.
  9484. * @param {(element|angular.element)} element the DOM element to set the focus on
  9485. * @returns {Promise} The `$timeout` promise that will be resolved once focus is set. If another focus is requested before this request is evaluated.
  9486. * then the promise will fail with the `'canceled'` reason.
  9487. */
  9488. byElement: function(element){
  9489. if (!angular.isElement(element)){
  9490. s.logWarn("Trying to focus on an element that isn\'t an element.");
  9491. return $q.reject('not-element');
  9492. }
  9493. element = angular.element(element);
  9494. this._purgeQueue();
  9495. var promise = $timeout(function(){
  9496. if (element){
  9497. element[0].focus();
  9498. }
  9499. });
  9500. this.queue.push(promise);
  9501. return promise;
  9502. },
  9503. /**
  9504. * @ngdoc method
  9505. * @methodOf ui.grid.service:GridUtil.focus
  9506. * @name bySelector
  9507. * @description Sets the focus of the document to the given dom element.
  9508. * @param {(element|angular.element)} parentElement the parent/ancestor of the dom element that you are selecting using the query selector
  9509. * @param {String} querySelector finds the dom element using the {@link http://www.w3schools.com/jsref/met_document_queryselector.asp querySelector}
  9510. * @param {boolean} [aSync=false] If true then the selector will be querried inside of a timeout. Otherwise the selector will be querried imidately
  9511. * then the focus will be called.
  9512. * @returns {Promise} The `$timeout` promise that will be resolved once focus is set. If another focus is requested before this request is evaluated.
  9513. * then the promise will fail with the `'canceled'` reason.
  9514. */
  9515. bySelector: function(parentElement, querySelector, aSync){
  9516. var self = this;
  9517. if (!angular.isElement(parentElement)){
  9518. throw new Error("The parent element is not an element.");
  9519. }
  9520. // Ensure that this is an angular element.
  9521. // It is fine if this is already an angular element.
  9522. parentElement = angular.element(parentElement);
  9523. var focusBySelector = function(){
  9524. var element = parentElement[0].querySelector(querySelector);
  9525. return self.byElement(element);
  9526. };
  9527. this._purgeQueue();
  9528. if (aSync){ //Do this asynchronysly
  9529. var promise = $timeout(focusBySelector);
  9530. this.queue.push($timeout(focusBySelector));
  9531. return promise;
  9532. } else {
  9533. return focusBySelector();
  9534. }
  9535. },
  9536. _purgeQueue: function(){
  9537. this.queue.forEach(function(element){
  9538. $timeout.cancel(element);
  9539. });
  9540. this.queue = [];
  9541. }
  9542. };
  9543. ['width', 'height'].forEach(function (name) {
  9544. var capsName = angular.uppercase(name.charAt(0)) + name.substr(1);
  9545. s['element' + capsName] = function (elem, extra) {
  9546. var e = elem;
  9547. if (e && typeof(e.length) !== 'undefined' && e.length) {
  9548. e = elem[0];
  9549. }
  9550. if (e) {
  9551. var styles = getStyles(e);
  9552. return e.offsetWidth === 0 && rdisplayswap.test(styles.display) ?
  9553. s.swap(e, cssShow, function() {
  9554. return getWidthOrHeight(e, name, extra );
  9555. }) :
  9556. getWidthOrHeight( e, name, extra );
  9557. }
  9558. else {
  9559. return null;
  9560. }
  9561. };
  9562. s['outerElement' + capsName] = function (elem, margin) {
  9563. return elem ? s['element' + capsName].call(this, elem, margin ? 'margin' : 'border') : null;
  9564. };
  9565. });
  9566. // http://stackoverflow.com/a/24107550/888165
  9567. s.closestElm = function closestElm(el, selector) {
  9568. if (typeof(el.length) !== 'undefined' && el.length) {
  9569. el = el[0];
  9570. }
  9571. var matchesFn;
  9572. // find vendor prefix
  9573. ['matches','webkitMatchesSelector','mozMatchesSelector','msMatchesSelector','oMatchesSelector'].some(function(fn) {
  9574. if (typeof document.body[fn] === 'function') {
  9575. matchesFn = fn;
  9576. return true;
  9577. }
  9578. return false;
  9579. });
  9580. // traverse parents
  9581. var parent;
  9582. while (el !== null) {
  9583. parent = el.parentElement;
  9584. if (parent !== null && parent[matchesFn](selector)) {
  9585. return parent;
  9586. }
  9587. el = parent;
  9588. }
  9589. return null;
  9590. };
  9591. s.type = function (obj) {
  9592. var text = Function.prototype.toString.call(obj.constructor);
  9593. return text.match(/function (.*?)\(/)[1];
  9594. };
  9595. s.getBorderSize = function getBorderSize(elem, borderType) {
  9596. if (typeof(elem.length) !== 'undefined' && elem.length) {
  9597. elem = elem[0];
  9598. }
  9599. var styles = getStyles(elem);
  9600. // If a specific border is supplied, like 'top', read the 'borderTop' style property
  9601. if (borderType) {
  9602. borderType = 'border' + borderType.charAt(0).toUpperCase() + borderType.slice(1);
  9603. }
  9604. else {
  9605. borderType = 'border';
  9606. }
  9607. borderType += 'Width';
  9608. var val = parseInt(styles[borderType], 10);
  9609. if (isNaN(val)) {
  9610. return 0;
  9611. }
  9612. else {
  9613. return val;
  9614. }
  9615. };
  9616. // http://stackoverflow.com/a/22948274/888165
  9617. // TODO: Opera? Mobile?
  9618. s.detectBrowser = function detectBrowser() {
  9619. var userAgent = $window.navigator.userAgent;
  9620. var browsers = {chrome: /chrome/i, safari: /safari/i, firefox: /firefox/i, ie: /internet explorer|trident\//i};
  9621. for (var key in browsers) {
  9622. if (browsers[key].test(userAgent)) {
  9623. return key;
  9624. }
  9625. }
  9626. return 'unknown';
  9627. };
  9628. // Borrowed from https://github.com/othree/jquery.rtl-scroll-type
  9629. // Determine the scroll "type" this browser is using for RTL
  9630. s.rtlScrollType = function rtlScrollType() {
  9631. if (rtlScrollType.type) {
  9632. return rtlScrollType.type;
  9633. }
  9634. var definer = angular.element('<div dir="rtl" style="font-size: 14px; width: 1px; height: 1px; position: absolute; top: -1000px; overflow: scroll">A</div>')[0],
  9635. type = 'reverse';
  9636. document.body.appendChild(definer);
  9637. if (definer.scrollLeft > 0) {
  9638. type = 'default';
  9639. }
  9640. else {
  9641. definer.scrollLeft = 1;
  9642. if (definer.scrollLeft === 0) {
  9643. type = 'negative';
  9644. }
  9645. }
  9646. angular.element(definer).remove();
  9647. rtlScrollType.type = type;
  9648. return type;
  9649. };
  9650. /**
  9651. * @ngdoc method
  9652. * @name normalizeScrollLeft
  9653. * @methodOf ui.grid.service:GridUtil
  9654. *
  9655. * @param {element} element The element to get the `scrollLeft` from.
  9656. * @param {grid} grid - grid used to normalize (uses the rtl property)
  9657. *
  9658. * @returns {number} A normalized scrollLeft value for the current browser.
  9659. *
  9660. * @description
  9661. * Browsers currently handle RTL in different ways, resulting in inconsistent scrollLeft values. This method normalizes them
  9662. */
  9663. s.normalizeScrollLeft = function normalizeScrollLeft(element, grid) {
  9664. if (typeof(element.length) !== 'undefined' && element.length) {
  9665. element = element[0];
  9666. }
  9667. var scrollLeft = element.scrollLeft;
  9668. if (grid.isRTL()) {
  9669. switch (s.rtlScrollType()) {
  9670. case 'default':
  9671. return element.scrollWidth - scrollLeft - element.clientWidth;
  9672. case 'negative':
  9673. return Math.abs(scrollLeft);
  9674. case 'reverse':
  9675. return scrollLeft;
  9676. }
  9677. }
  9678. return scrollLeft;
  9679. };
  9680. /**
  9681. * @ngdoc method
  9682. * @name denormalizeScrollLeft
  9683. * @methodOf ui.grid.service:GridUtil
  9684. *
  9685. * @param {element} element The element to normalize the `scrollLeft` value for
  9686. * @param {number} scrollLeft The `scrollLeft` value to denormalize.
  9687. * @param {grid} grid The grid that owns the scroll event.
  9688. *
  9689. * @returns {number} A normalized scrollLeft value for the current browser.
  9690. *
  9691. * @description
  9692. * Browsers currently handle RTL in different ways, resulting in inconsistent scrollLeft values. This method denormalizes a value for the current browser.
  9693. */
  9694. s.denormalizeScrollLeft = function denormalizeScrollLeft(element, scrollLeft, grid) {
  9695. if (typeof(element.length) !== 'undefined' && element.length) {
  9696. element = element[0];
  9697. }
  9698. if (grid.isRTL()) {
  9699. switch (s.rtlScrollType()) {
  9700. case 'default':
  9701. // Get the max scroll for the element
  9702. var maxScrollLeft = element.scrollWidth - element.clientWidth;
  9703. // Subtract the current scroll amount from the max scroll
  9704. return maxScrollLeft - scrollLeft;
  9705. case 'negative':
  9706. return scrollLeft * -1;
  9707. case 'reverse':
  9708. return scrollLeft;
  9709. }
  9710. }
  9711. return scrollLeft;
  9712. };
  9713. /**
  9714. * @ngdoc method
  9715. * @name preEval
  9716. * @methodOf ui.grid.service:GridUtil
  9717. *
  9718. * @param {string} path Path to evaluate
  9719. *
  9720. * @returns {string} A path that is normalized.
  9721. *
  9722. * @description
  9723. * Takes a field path and converts it to bracket notation to allow for special characters in path
  9724. * @example
  9725. * <pre>
  9726. * gridUtil.preEval('property') == 'property'
  9727. * gridUtil.preEval('nested.deep.prop-erty') = "nested['deep']['prop-erty']"
  9728. * </pre>
  9729. */
  9730. s.preEval = function (path) {
  9731. var m = uiGridConstants.BRACKET_REGEXP.exec(path);
  9732. if (m) {
  9733. return (m[1] ? s.preEval(m[1]) : m[1]) + m[2] + (m[3] ? s.preEval(m[3]) : m[3]);
  9734. } else {
  9735. path = path.replace(uiGridConstants.APOS_REGEXP, '\\\'');
  9736. var parts = path.split(uiGridConstants.DOT_REGEXP);
  9737. var preparsed = [parts.shift()]; // first item must be var notation, thus skip
  9738. angular.forEach(parts, function (part) {
  9739. preparsed.push(part.replace(uiGridConstants.FUNC_REGEXP, '\']$1'));
  9740. });
  9741. return preparsed.join('[\'');
  9742. }
  9743. };
  9744. /**
  9745. * @ngdoc method
  9746. * @name debounce
  9747. * @methodOf ui.grid.service:GridUtil
  9748. *
  9749. * @param {function} func function to debounce
  9750. * @param {number} wait milliseconds to delay
  9751. * @param {boolean} immediate execute before delay
  9752. *
  9753. * @returns {function} A function that can be executed as debounced function
  9754. *
  9755. * @description
  9756. * Copied from https://github.com/shahata/angular-debounce
  9757. * Takes a function, decorates it to execute only 1 time after multiple calls, and returns the decorated function
  9758. * @example
  9759. * <pre>
  9760. * var debouncedFunc = gridUtil.debounce(function(){alert('debounced');}, 500);
  9761. * debouncedFunc();
  9762. * debouncedFunc();
  9763. * debouncedFunc();
  9764. * </pre>
  9765. */
  9766. s.debounce = function (func, wait, immediate) {
  9767. var timeout, args, context, result;
  9768. function debounce() {
  9769. /* jshint validthis:true */
  9770. context = this;
  9771. args = arguments;
  9772. var later = function () {
  9773. timeout = null;
  9774. if (!immediate) {
  9775. result = func.apply(context, args);
  9776. }
  9777. };
  9778. var callNow = immediate && !timeout;
  9779. if (timeout) {
  9780. $timeout.cancel(timeout);
  9781. }
  9782. timeout = $timeout(later, wait, false);
  9783. if (callNow) {
  9784. result = func.apply(context, args);
  9785. }
  9786. return result;
  9787. }
  9788. debounce.cancel = function () {
  9789. $timeout.cancel(timeout);
  9790. timeout = null;
  9791. };
  9792. return debounce;
  9793. };
  9794. /**
  9795. * @ngdoc method
  9796. * @name throttle
  9797. * @methodOf ui.grid.service:GridUtil
  9798. *
  9799. * @param {function} func function to throttle
  9800. * @param {number} wait milliseconds to delay after first trigger
  9801. * @param {Object} params to use in throttle.
  9802. *
  9803. * @returns {function} A function that can be executed as throttled function
  9804. *
  9805. * @description
  9806. * Adapted from debounce function (above)
  9807. * Potential keys for Params Object are:
  9808. * trailing (bool) - whether to trigger after throttle time ends if called multiple times
  9809. * Updated to use $interval rather than $timeout, as protractor (e2e tests) is able to work with $interval,
  9810. * but not with $timeout
  9811. *
  9812. * Note that when using throttle, you need to use throttle to create a new function upfront, then use the function
  9813. * return from that call each time you need to call throttle. If you call throttle itself repeatedly, the lastCall
  9814. * variable will get overwritten and the throttling won't work
  9815. *
  9816. * @example
  9817. * <pre>
  9818. * var throttledFunc = gridUtil.throttle(function(){console.log('throttled');}, 500, {trailing: true});
  9819. * throttledFunc(); //=> logs throttled
  9820. * throttledFunc(); //=> queues attempt to log throttled for ~500ms (since trailing param is truthy)
  9821. * throttledFunc(); //=> updates arguments to keep most-recent request, but does not do anything else.
  9822. * </pre>
  9823. */
  9824. s.throttle = function(func, wait, options){
  9825. options = options || {};
  9826. var lastCall = 0, queued = null, context, args;
  9827. function runFunc(endDate){
  9828. lastCall = +new Date();
  9829. func.apply(context, args);
  9830. $interval(function(){ queued = null; }, 0, 1, false);
  9831. }
  9832. return function(){
  9833. /* jshint validthis:true */
  9834. context = this;
  9835. args = arguments;
  9836. if (queued === null){
  9837. var sinceLast = +new Date() - lastCall;
  9838. if (sinceLast > wait){
  9839. runFunc();
  9840. }
  9841. else if (options.trailing){
  9842. queued = $interval(runFunc, wait - sinceLast, 1, false);
  9843. }
  9844. }
  9845. };
  9846. };
  9847. s.on = {};
  9848. s.off = {};
  9849. s._events = {};
  9850. s.addOff = function (eventName) {
  9851. s.off[eventName] = function (elm, fn) {
  9852. var idx = s._events[eventName].indexOf(fn);
  9853. if (idx > 0) {
  9854. s._events[eventName].removeAt(idx);
  9855. }
  9856. };
  9857. };
  9858. var mouseWheeltoBind = ( 'onwheel' in document || document.documentMode >= 9 ) ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
  9859. nullLowestDeltaTimeout,
  9860. lowestDelta;
  9861. s.on.mousewheel = function (elm, fn) {
  9862. if (!elm || !fn) { return; }
  9863. var $elm = angular.element(elm);
  9864. // Store the line height and page height for this particular element
  9865. $elm.data('mousewheel-line-height', getLineHeight($elm));
  9866. $elm.data('mousewheel-page-height', s.elementHeight($elm));
  9867. if (!$elm.data('mousewheel-callbacks')) { $elm.data('mousewheel-callbacks', {}); }
  9868. var cbs = $elm.data('mousewheel-callbacks');
  9869. cbs[fn] = (Function.prototype.bind || bindPolyfill).call(mousewheelHandler, $elm[0], fn);
  9870. // Bind all the mousew heel events
  9871. for ( var i = mouseWheeltoBind.length; i; ) {
  9872. $elm.on(mouseWheeltoBind[--i], cbs[fn]);
  9873. }
  9874. };
  9875. s.off.mousewheel = function (elm, fn) {
  9876. var $elm = angular.element(elm);
  9877. var cbs = $elm.data('mousewheel-callbacks');
  9878. var handler = cbs[fn];
  9879. if (handler) {
  9880. for ( var i = mouseWheeltoBind.length; i; ) {
  9881. $elm.off(mouseWheeltoBind[--i], handler);
  9882. }
  9883. }
  9884. delete cbs[fn];
  9885. if (Object.keys(cbs).length === 0) {
  9886. $elm.removeData('mousewheel-line-height');
  9887. $elm.removeData('mousewheel-page-height');
  9888. $elm.removeData('mousewheel-callbacks');
  9889. }
  9890. };
  9891. function mousewheelHandler(fn, event) {
  9892. var $elm = angular.element(this);
  9893. var delta = 0,
  9894. deltaX = 0,
  9895. deltaY = 0,
  9896. absDelta = 0,
  9897. offsetX = 0,
  9898. offsetY = 0;
  9899. // jQuery masks events
  9900. if (event.originalEvent) { event = event.originalEvent; }
  9901. if ( 'detail' in event ) { deltaY = event.detail * -1; }
  9902. if ( 'wheelDelta' in event ) { deltaY = event.wheelDelta; }
  9903. if ( 'wheelDeltaY' in event ) { deltaY = event.wheelDeltaY; }
  9904. if ( 'wheelDeltaX' in event ) { deltaX = event.wheelDeltaX * -1; }
  9905. // Firefox < 17 horizontal scrolling related to DOMMouseScroll event
  9906. if ( 'axis' in event && event.axis === event.HORIZONTAL_AXIS ) {
  9907. deltaX = deltaY * -1;
  9908. deltaY = 0;
  9909. }
  9910. // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy
  9911. delta = deltaY === 0 ? deltaX : deltaY;
  9912. // New school wheel delta (wheel event)
  9913. if ( 'deltaY' in event ) {
  9914. deltaY = event.deltaY * -1;
  9915. delta = deltaY;
  9916. }
  9917. if ( 'deltaX' in event ) {
  9918. deltaX = event.deltaX;
  9919. if ( deltaY === 0 ) { delta = deltaX * -1; }
  9920. }
  9921. // No change actually happened, no reason to go any further
  9922. if ( deltaY === 0 && deltaX === 0 ) { return; }
  9923. // Need to convert lines and pages to pixels if we aren't already in pixels
  9924. // There are three delta modes:
  9925. // * deltaMode 0 is by pixels, nothing to do
  9926. // * deltaMode 1 is by lines
  9927. // * deltaMode 2 is by pages
  9928. if ( event.deltaMode === 1 ) {
  9929. var lineHeight = $elm.data('mousewheel-line-height');
  9930. delta *= lineHeight;
  9931. deltaY *= lineHeight;
  9932. deltaX *= lineHeight;
  9933. }
  9934. else if ( event.deltaMode === 2 ) {
  9935. var pageHeight = $elm.data('mousewheel-page-height');
  9936. delta *= pageHeight;
  9937. deltaY *= pageHeight;
  9938. deltaX *= pageHeight;
  9939. }
  9940. // Store lowest absolute delta to normalize the delta values
  9941. absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
  9942. if ( !lowestDelta || absDelta < lowestDelta ) {
  9943. lowestDelta = absDelta;
  9944. // Adjust older deltas if necessary
  9945. if ( shouldAdjustOldDeltas(event, absDelta) ) {
  9946. lowestDelta /= 40;
  9947. }
  9948. }
  9949. // Get a whole, normalized value for the deltas
  9950. delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
  9951. deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
  9952. deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
  9953. event.deltaMode = 0;
  9954. // Normalise offsetX and offsetY properties
  9955. // if ($elm[0].getBoundingClientRect ) {
  9956. // var boundingRect = $(elm)[0].getBoundingClientRect();
  9957. // offsetX = event.clientX - boundingRect.left;
  9958. // offsetY = event.clientY - boundingRect.top;
  9959. // }
  9960. // event.deltaX = deltaX;
  9961. // event.deltaY = deltaY;
  9962. // event.deltaFactor = lowestDelta;
  9963. var newEvent = {
  9964. originalEvent: event,
  9965. deltaX: deltaX,
  9966. deltaY: deltaY,
  9967. deltaFactor: lowestDelta,
  9968. preventDefault: function () { event.preventDefault(); },
  9969. stopPropagation: function () { event.stopPropagation(); }
  9970. };
  9971. // Clearout lowestDelta after sometime to better
  9972. // handle multiple device types that give
  9973. // a different lowestDelta
  9974. // Ex: trackpad = 3 and mouse wheel = 120
  9975. if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
  9976. nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
  9977. fn.call($elm[0], newEvent);
  9978. }
  9979. function nullLowestDelta() {
  9980. lowestDelta = null;
  9981. }
  9982. function shouldAdjustOldDeltas(orgEvent, absDelta) {
  9983. // If this is an older event and the delta is divisable by 120,
  9984. // then we are assuming that the browser is treating this as an
  9985. // older mouse wheel event and that we should divide the deltas
  9986. // by 40 to try and get a more usable deltaFactor.
  9987. // Side note, this actually impacts the reported scroll distance
  9988. // in older browsers and can cause scrolling to be slower than native.
  9989. // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.
  9990. return orgEvent.type === 'mousewheel' && absDelta % 120 === 0;
  9991. }
  9992. return s;
  9993. }]);
  9994. // Add 'px' to the end of a number string if it doesn't have it already
  9995. module.filter('px', function() {
  9996. return function(str) {
  9997. if (str.match(/^[\d\.]+$/)) {
  9998. return str + 'px';
  9999. }
  10000. else {
  10001. return str;
  10002. }
  10003. };
  10004. });
  10005. })();
  10006. (function () {
  10007. angular.module('ui.grid').config(['$provide', function($provide) {
  10008. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10009. var lang = {
  10010. aggregate: {
  10011. label: 'položky'
  10012. },
  10013. groupPanel: {
  10014. description: 'Přesuňte záhlaví zde pro vytvoření skupiny dle sloupce.'
  10015. },
  10016. search: {
  10017. placeholder: 'Hledat...',
  10018. showingItems: 'Zobrazuji položky:',
  10019. selectedItems: 'Vybrané položky:',
  10020. totalItems: 'Celkem položek:',
  10021. size: 'Velikost strany:',
  10022. first: 'První strana',
  10023. next: 'Další strana',
  10024. previous: 'Předchozí strana',
  10025. last: 'Poslední strana'
  10026. },
  10027. menu: {
  10028. text: 'Vyberte sloupec:'
  10029. },
  10030. sort: {
  10031. ascending: 'Seřadit od A-Z',
  10032. descending: 'Seřadit od Z-A',
  10033. remove: 'Odebrat seřazení'
  10034. },
  10035. column: {
  10036. hide: 'Schovat sloupec'
  10037. },
  10038. aggregation: {
  10039. count: 'celkem řádků: ',
  10040. sum: 'celkem: ',
  10041. avg: 'avg: ',
  10042. min: 'min.: ',
  10043. max: 'max.: '
  10044. },
  10045. pinning: {
  10046. pinLeft: 'Zamknout vlevo',
  10047. pinRight: 'Zamknout vpravo',
  10048. unpin: 'Odemknout'
  10049. },
  10050. gridMenu: {
  10051. columns: 'Sloupce:',
  10052. importerTitle: 'Importovat soubor',
  10053. exporterAllAsCsv: 'Exportovat všechna data do csv',
  10054. exporterVisibleAsCsv: 'Exportovat viditelná data do csv',
  10055. exporterSelectedAsCsv: 'Exportovat vybraná data do csv',
  10056. exporterAllAsPdf: 'Exportovat všechna data do pdf',
  10057. exporterVisibleAsPdf: 'Exportovat viditelná data do pdf',
  10058. exporterSelectedAsPdf: 'Exportovat vybraná data do pdf',
  10059. clearAllFilters: 'Odstranit všechny filtry'
  10060. },
  10061. importer: {
  10062. noHeaders: 'Názvy sloupců se nepodařilo získat, obsahuje soubor záhlaví?',
  10063. noObjects: 'Data se nepodařilo zpracovat, obsahuje soubor řádky mimo záhlaví?',
  10064. invalidCsv: 'Soubor nelze zpracovat, jedná se o CSV?',
  10065. invalidJson: 'Soubor nelze zpracovat, je to JSON?',
  10066. jsonNotArray: 'Soubor musí obsahovat json. Ukončuji..'
  10067. },
  10068. pagination: {
  10069. sizes: 'položek na stránku',
  10070. totalItems: 'položek'
  10071. },
  10072. grouping: {
  10073. group: 'Seskupit',
  10074. ungroup: 'Odebrat seskupení',
  10075. aggregate_count: 'Agregace: Count',
  10076. aggregate_sum: 'Agregace: Sum',
  10077. aggregate_max: 'Agregace: Max',
  10078. aggregate_min: 'Agregace: Min',
  10079. aggregate_avg: 'Agregace: Avg',
  10080. aggregate_remove: 'Agregace: Odebrat'
  10081. }
  10082. };
  10083. // support varianty of different czech keys.
  10084. $delegate.add('cs', lang);
  10085. $delegate.add('cz', lang);
  10086. $delegate.add('cs-cz', lang);
  10087. $delegate.add('cs-CZ', lang);
  10088. return $delegate;
  10089. }]);
  10090. }]);
  10091. })();
  10092. (function(){
  10093. angular.module('ui.grid').config(['$provide', function($provide) {
  10094. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10095. $delegate.add('da', {
  10096. aggregate:{
  10097. label: 'artikler'
  10098. },
  10099. groupPanel:{
  10100. description: 'Grupér rækker udfra en kolonne ved at trække dens overskift hertil.'
  10101. },
  10102. search:{
  10103. placeholder: 'Søg...',
  10104. showingItems: 'Viste rækker:',
  10105. selectedItems: 'Valgte rækker:',
  10106. totalItems: 'Rækker totalt:',
  10107. size: 'Side størrelse:',
  10108. first: 'Første side',
  10109. next: 'Næste side',
  10110. previous: 'Forrige side',
  10111. last: 'Sidste side'
  10112. },
  10113. menu:{
  10114. text: 'Vælg kolonner:'
  10115. },
  10116. sort: {
  10117. ascending: 'Sorter stigende',
  10118. descending: 'Sorter faldende',
  10119. none: 'Sorter ingen',
  10120. remove: 'Fjern sortering'
  10121. },
  10122. column: {
  10123. hide: 'Skjul kolonne'
  10124. },
  10125. aggregation: {
  10126. count: 'antal rækker: ',
  10127. sum: 'sum: ',
  10128. avg: 'gns: ',
  10129. min: 'min: ',
  10130. max: 'max: '
  10131. },
  10132. gridMenu: {
  10133. columns: 'Columns:',
  10134. importerTitle: 'Import file',
  10135. exporterAllAsCsv: 'Export all data as csv',
  10136. exporterVisibleAsCsv: 'Export visible data as csv',
  10137. exporterSelectedAsCsv: 'Export selected data as csv',
  10138. exporterAllAsPdf: 'Export all data as pdf',
  10139. exporterVisibleAsPdf: 'Export visible data as pdf',
  10140. exporterSelectedAsPdf: 'Export selected data as pdf',
  10141. clearAllFilters: 'Clear all filters'
  10142. },
  10143. importer: {
  10144. noHeaders: 'Column names were unable to be derived, does the file have a header?',
  10145. noObjects: 'Objects were not able to be derived, was there data in the file other than headers?',
  10146. invalidCsv: 'File was unable to be processed, is it valid CSV?',
  10147. invalidJson: 'File was unable to be processed, is it valid Json?',
  10148. jsonNotArray: 'Imported json file must contain an array, aborting.'
  10149. }
  10150. });
  10151. return $delegate;
  10152. }]);
  10153. }]);
  10154. })();
  10155. (function () {
  10156. angular.module('ui.grid').config(['$provide', function ($provide) {
  10157. $provide.decorator('i18nService', ['$delegate', function ($delegate) {
  10158. $delegate.add('de', {
  10159. headerCell: {
  10160. aria: {
  10161. defaultFilterLabel: 'Filter für Spalte',
  10162. removeFilter: 'Filter löschen',
  10163. columnMenuButtonLabel: 'Spaltenmenü'
  10164. },
  10165. priority: 'Priorität:',
  10166. filterLabel: "Filter für Spalte: "
  10167. },
  10168. aggregate: {
  10169. label: 'Eintrag'
  10170. },
  10171. groupPanel: {
  10172. description: 'Ziehen Sie eine Spaltenüberschrift hierhin, um nach dieser Spalte zu gruppieren.'
  10173. },
  10174. search: {
  10175. placeholder: 'Suche...',
  10176. showingItems: 'Zeige Einträge:',
  10177. selectedItems: 'Ausgewählte Einträge:',
  10178. totalItems: 'Einträge gesamt:',
  10179. size: 'Einträge pro Seite:',
  10180. first: 'Erste Seite',
  10181. next: 'Nächste Seite',
  10182. previous: 'Vorherige Seite',
  10183. last: 'Letzte Seite'
  10184. },
  10185. menu: {
  10186. text: 'Spalten auswählen:'
  10187. },
  10188. sort: {
  10189. ascending: 'aufsteigend sortieren',
  10190. descending: 'absteigend sortieren',
  10191. none: 'keine Sortierung',
  10192. remove: 'Sortierung zurücksetzen'
  10193. },
  10194. column: {
  10195. hide: 'Spalte ausblenden'
  10196. },
  10197. aggregation: {
  10198. count: 'Zeilen insgesamt: ',
  10199. sum: 'gesamt: ',
  10200. avg: 'Durchschnitt: ',
  10201. min: 'min: ',
  10202. max: 'max: '
  10203. },
  10204. pinning: {
  10205. pinLeft: 'Links anheften',
  10206. pinRight: 'Rechts anheften',
  10207. unpin: 'Lösen'
  10208. },
  10209. columnMenu: {
  10210. close: 'Schließen'
  10211. },
  10212. gridMenu: {
  10213. aria: {
  10214. buttonLabel: 'Tabellenmenü'
  10215. },
  10216. columns: 'Spalten:',
  10217. importerTitle: 'Datei importieren',
  10218. exporterAllAsCsv: 'Alle Daten als CSV exportieren',
  10219. exporterVisibleAsCsv: 'sichtbare Daten als CSV exportieren',
  10220. exporterSelectedAsCsv: 'markierte Daten als CSV exportieren',
  10221. exporterAllAsPdf: 'Alle Daten als PDF exportieren',
  10222. exporterVisibleAsPdf: 'sichtbare Daten als PDF exportieren',
  10223. exporterSelectedAsPdf: 'markierte Daten als CSV exportieren',
  10224. clearAllFilters: 'Alle Filter zurücksetzen'
  10225. },
  10226. importer: {
  10227. noHeaders: 'Es konnten keine Spaltennamen ermittelt werden. Sind in der Datei Spaltendefinitionen enthalten?',
  10228. noObjects: 'Es konnten keine Zeileninformationen gelesen werden, Sind in der Datei außer den Spaltendefinitionen auch Daten enthalten?',
  10229. invalidCsv: 'Die Datei konnte nicht eingelesen werden, ist es eine gültige CSV-Datei?',
  10230. invalidJson: 'Die Datei konnte nicht eingelesen werden. Enthält sie gültiges JSON?',
  10231. jsonNotArray: 'Die importierte JSON-Datei muß ein Array enthalten. Breche Import ab.'
  10232. },
  10233. pagination: {
  10234. aria: {
  10235. pageToFirst: 'Zum Anfang',
  10236. pageBack: 'Seite zurück',
  10237. pageSelected: 'Ausgwählte Seite',
  10238. pageForward: 'Seite vor',
  10239. pageToLast: 'Zum Ende'
  10240. },
  10241. sizes: 'Einträge pro Seite',
  10242. totalItems: 'Einträge',
  10243. through: 'bis',
  10244. of: 'von'
  10245. },
  10246. grouping: {
  10247. group: 'Gruppieren',
  10248. ungroup: 'Gruppierung aufheben',
  10249. aggregate_count: 'Agg: Anzahl',
  10250. aggregate_sum: 'Agg: Summe',
  10251. aggregate_max: 'Agg: Maximum',
  10252. aggregate_min: 'Agg: Minimum',
  10253. aggregate_avg: 'Agg: Mittelwert',
  10254. aggregate_remove: 'Aggregation entfernen'
  10255. }
  10256. });
  10257. return $delegate;
  10258. }]);
  10259. }]);
  10260. })();
  10261. (function () {
  10262. angular.module('ui.grid').config(['$provide', function($provide) {
  10263. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10264. $delegate.add('en', {
  10265. headerCell: {
  10266. aria: {
  10267. defaultFilterLabel: 'Filter for column',
  10268. removeFilter: 'Remove Filter',
  10269. columnMenuButtonLabel: 'Column Menu'
  10270. },
  10271. priority: 'Priority:',
  10272. filterLabel: "Filter for column: "
  10273. },
  10274. aggregate: {
  10275. label: 'items'
  10276. },
  10277. groupPanel: {
  10278. description: 'Drag a column header here and drop it to group by that column.'
  10279. },
  10280. search: {
  10281. placeholder: 'Search...',
  10282. showingItems: 'Showing Items:',
  10283. selectedItems: 'Selected Items:',
  10284. totalItems: 'Total Items:',
  10285. size: 'Page Size:',
  10286. first: 'First Page',
  10287. next: 'Next Page',
  10288. previous: 'Previous Page',
  10289. last: 'Last Page'
  10290. },
  10291. menu: {
  10292. text: 'Choose Columns:'
  10293. },
  10294. sort: {
  10295. ascending: 'Sort Ascending',
  10296. descending: 'Sort Descending',
  10297. none: 'Sort None',
  10298. remove: 'Remove Sort'
  10299. },
  10300. column: {
  10301. hide: 'Hide Column'
  10302. },
  10303. aggregation: {
  10304. count: 'total rows: ',
  10305. sum: 'total: ',
  10306. avg: 'avg: ',
  10307. min: 'min: ',
  10308. max: 'max: '
  10309. },
  10310. pinning: {
  10311. pinLeft: 'Pin Left',
  10312. pinRight: 'Pin Right',
  10313. unpin: 'Unpin'
  10314. },
  10315. columnMenu: {
  10316. close: 'Close'
  10317. },
  10318. gridMenu: {
  10319. aria: {
  10320. buttonLabel: 'Grid Menu'
  10321. },
  10322. columns: 'Columns:',
  10323. importerTitle: 'Import file',
  10324. exporterAllAsCsv: 'Export all data as csv',
  10325. exporterVisibleAsCsv: 'Export visible data as csv',
  10326. exporterSelectedAsCsv: 'Export selected data as csv',
  10327. exporterAllAsPdf: 'Export all data as pdf',
  10328. exporterVisibleAsPdf: 'Export visible data as pdf',
  10329. exporterSelectedAsPdf: 'Export selected data as pdf',
  10330. clearAllFilters: 'Clear all filters'
  10331. },
  10332. importer: {
  10333. noHeaders: 'Column names were unable to be derived, does the file have a header?',
  10334. noObjects: 'Objects were not able to be derived, was there data in the file other than headers?',
  10335. invalidCsv: 'File was unable to be processed, is it valid CSV?',
  10336. invalidJson: 'File was unable to be processed, is it valid Json?',
  10337. jsonNotArray: 'Imported json file must contain an array, aborting.'
  10338. },
  10339. pagination: {
  10340. aria: {
  10341. pageToFirst: 'Page to first',
  10342. pageBack: 'Page back',
  10343. pageSelected: 'Selected page',
  10344. pageForward: 'Page forward',
  10345. pageToLast: 'Page to last'
  10346. },
  10347. sizes: 'items per page',
  10348. totalItems: 'items',
  10349. through: 'through',
  10350. of: 'of'
  10351. },
  10352. grouping: {
  10353. group: 'Group',
  10354. ungroup: 'Ungroup',
  10355. aggregate_count: 'Agg: Count',
  10356. aggregate_sum: 'Agg: Sum',
  10357. aggregate_max: 'Agg: Max',
  10358. aggregate_min: 'Agg: Min',
  10359. aggregate_avg: 'Agg: Avg',
  10360. aggregate_remove: 'Agg: Remove'
  10361. },
  10362. validate: {
  10363. error: 'Error:',
  10364. minLength: 'Value should be at least THRESHOLD characters long.',
  10365. maxLength: 'Value should be at most THRESHOLD characters long.',
  10366. required: 'A value is needed.'
  10367. }
  10368. });
  10369. return $delegate;
  10370. }]);
  10371. }]);
  10372. })();
  10373. (function () {
  10374. angular.module('ui.grid').config(['$provide', function($provide) {
  10375. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10376. $delegate.add('es', {
  10377. aggregate: {
  10378. label: 'Artículos'
  10379. },
  10380. groupPanel: {
  10381. description: 'Arrastre un encabezado de columna aquí y suéltelo para agrupar por esa columna.'
  10382. },
  10383. search: {
  10384. placeholder: 'Buscar...',
  10385. showingItems: 'Artículos Mostrados:',
  10386. selectedItems: 'Artículos Seleccionados:',
  10387. totalItems: 'Artículos Totales:',
  10388. size: 'Tamaño de Página:',
  10389. first: 'Primera Página',
  10390. next: 'Página Siguiente',
  10391. previous: 'Página Anterior',
  10392. last: 'Última Página'
  10393. },
  10394. menu: {
  10395. text: 'Elegir columnas:'
  10396. },
  10397. sort: {
  10398. ascending: 'Orden Ascendente',
  10399. descending: 'Orden Descendente',
  10400. remove: 'Sin Ordenar'
  10401. },
  10402. column: {
  10403. hide: 'Ocultar la columna'
  10404. },
  10405. aggregation: {
  10406. count: 'filas totales: ',
  10407. sum: 'total: ',
  10408. avg: 'media: ',
  10409. min: 'min: ',
  10410. max: 'max: '
  10411. },
  10412. pinning: {
  10413. pinLeft: 'Fijar a la Izquierda',
  10414. pinRight: 'Fijar a la Derecha',
  10415. unpin: 'Quitar Fijación'
  10416. },
  10417. gridMenu: {
  10418. columns: 'Columnas:',
  10419. importerTitle: 'Importar archivo',
  10420. exporterAllAsCsv: 'Exportar todo como csv',
  10421. exporterVisibleAsCsv: 'Exportar vista como csv',
  10422. exporterSelectedAsCsv: 'Exportar selección como csv',
  10423. exporterAllAsPdf: 'Exportar todo como pdf',
  10424. exporterVisibleAsPdf: 'Exportar vista como pdf',
  10425. exporterSelectedAsPdf: 'Exportar selección como pdf',
  10426. clearAllFilters: 'Limpiar todos los filtros'
  10427. },
  10428. importer: {
  10429. noHeaders: 'No fue posible derivar los nombres de las columnas, ¿tiene encabezados el archivo?',
  10430. noObjects: 'No fue posible obtener registros, ¿contiene datos el archivo, aparte de los encabezados?',
  10431. invalidCsv: 'No fue posible procesar el archivo, ¿es un CSV válido?',
  10432. invalidJson: 'No fue posible procesar el archivo, ¿es un Json válido?',
  10433. jsonNotArray: 'El archivo json importado debe contener un array, abortando.'
  10434. },
  10435. pagination: {
  10436. sizes: 'registros por página',
  10437. totalItems: 'registros',
  10438. of: 'de'
  10439. },
  10440. grouping: {
  10441. group: 'Agrupar',
  10442. ungroup: 'Desagrupar',
  10443. aggregate_count: 'Agr: Cont',
  10444. aggregate_sum: 'Agr: Sum',
  10445. aggregate_max: 'Agr: Máx',
  10446. aggregate_min: 'Agr: Min',
  10447. aggregate_avg: 'Agr: Prom',
  10448. aggregate_remove: 'Agr: Quitar'
  10449. }
  10450. });
  10451. return $delegate;
  10452. }]);
  10453. }]);
  10454. })();
  10455. /**
  10456. * Translated by: R. Salarmehr
  10457. * M. Hosseynzade
  10458. * Using Vajje.com online dictionary.
  10459. */
  10460. (function () {
  10461. angular.module('ui.grid').config(['$provide', function ($provide) {
  10462. $provide.decorator('i18nService', ['$delegate', function ($delegate) {
  10463. $delegate.add('fa', {
  10464. aggregate: {
  10465. label: 'قلم'
  10466. },
  10467. groupPanel: {
  10468. description: 'عنوان یک ستون را بگیر و به گروهی از آن ستون رها کن.'
  10469. },
  10470. search: {
  10471. placeholder: 'جستجو...',
  10472. showingItems: 'نمایش اقلام:',
  10473. selectedItems: 'قلم\u200cهای انتخاب شده:',
  10474. totalItems: 'مجموع اقلام:',
  10475. size: 'اندازه\u200cی صفحه:',
  10476. first: 'اولین صفحه',
  10477. next: 'صفحه\u200cی\u200cبعدی',
  10478. previous: 'صفحه\u200cی\u200c قبلی',
  10479. last: 'آخرین صفحه'
  10480. },
  10481. menu: {
  10482. text: 'ستون\u200cهای انتخابی:'
  10483. },
  10484. sort: {
  10485. ascending: 'ترتیب صعودی',
  10486. descending: 'ترتیب نزولی',
  10487. remove: 'حذف مرتب کردن'
  10488. },
  10489. column: {
  10490. hide: 'پنهان\u200cکردن ستون'
  10491. },
  10492. aggregation: {
  10493. count: 'تعداد: ',
  10494. sum: 'مجموع: ',
  10495. avg: 'میانگین: ',
  10496. min: 'کمترین: ',
  10497. max: 'بیشترین: '
  10498. },
  10499. pinning: {
  10500. pinLeft: 'پین کردن سمت چپ',
  10501. pinRight: 'پین کردن سمت راست',
  10502. unpin: 'حذف پین'
  10503. },
  10504. gridMenu: {
  10505. columns: 'ستون\u200cها:',
  10506. importerTitle: 'وارد کردن فایل',
  10507. exporterAllAsCsv: 'خروجی تمام داده\u200cها در فایل csv',
  10508. exporterVisibleAsCsv: 'خروجی داده\u200cهای قابل مشاهده در فایل csv',
  10509. exporterSelectedAsCsv: 'خروجی داده\u200cهای انتخاب\u200cشده در فایل csv',
  10510. exporterAllAsPdf: 'خروجی تمام داده\u200cها در فایل pdf',
  10511. exporterVisibleAsPdf: 'خروجی داده\u200cهای قابل مشاهده در فایل pdf',
  10512. exporterSelectedAsPdf: 'خروجی داده\u200cهای انتخاب\u200cشده در فایل pdf',
  10513. clearAllFilters: 'پاک کردن تمام فیلتر'
  10514. },
  10515. importer: {
  10516. noHeaders: 'نام ستون قابل استخراج نیست. آیا فایل عنوان دارد؟',
  10517. noObjects: 'اشیا قابل استخراج نیستند. آیا به جز عنوان\u200cها در فایل داده وجود دارد؟',
  10518. invalidCsv: 'فایل قابل پردازش نیست. آیا فرمت csv معتبر است؟',
  10519. invalidJson: 'فایل قابل پردازش نیست. آیا فرمت json معتبر است؟',
  10520. jsonNotArray: 'فایل json وارد شده باید حاوی آرایه باشد. عملیات ساقط شد.'
  10521. },
  10522. pagination: {
  10523. sizes: 'اقلام در هر صفحه',
  10524. totalItems: 'اقلام',
  10525. of: 'از'
  10526. },
  10527. grouping: {
  10528. group: 'گروه\u200cبندی',
  10529. ungroup: 'حذف گروه\u200cبندی',
  10530. aggregate_count: 'Agg: تعداد',
  10531. aggregate_sum: 'Agg: جمع',
  10532. aggregate_max: 'Agg: بیشینه',
  10533. aggregate_min: 'Agg: کمینه',
  10534. aggregate_avg: 'Agg: میانگین',
  10535. aggregate_remove: 'Agg: حذف'
  10536. }
  10537. });
  10538. return $delegate;
  10539. }]);
  10540. }]);
  10541. })();
  10542. (function () {
  10543. angular.module('ui.grid').config(['$provide', function($provide) {
  10544. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10545. $delegate.add('fi', {
  10546. aggregate: {
  10547. label: 'rivit'
  10548. },
  10549. groupPanel: {
  10550. description: 'Raahaa ja pudota otsikko tähän ryhmittääksesi sarakkeen mukaan.'
  10551. },
  10552. search: {
  10553. placeholder: 'Hae...',
  10554. showingItems: 'Näytetään rivejä:',
  10555. selectedItems: 'Valitut rivit:',
  10556. totalItems: 'Rivejä yht.:',
  10557. size: 'Näytä:',
  10558. first: 'Ensimmäinen sivu',
  10559. next: 'Seuraava sivu',
  10560. previous: 'Edellinen sivu',
  10561. last: 'Viimeinen sivu'
  10562. },
  10563. menu: {
  10564. text: 'Valitse sarakkeet:'
  10565. },
  10566. sort: {
  10567. ascending: 'Järjestä nouseva',
  10568. descending: 'Järjestä laskeva',
  10569. remove: 'Poista järjestys'
  10570. },
  10571. column: {
  10572. hide: 'Piilota sarake'
  10573. },
  10574. aggregation: {
  10575. count: 'Rivejä yht.: ',
  10576. sum: 'Summa: ',
  10577. avg: 'K.a.: ',
  10578. min: 'Min: ',
  10579. max: 'Max: '
  10580. },
  10581. pinning: {
  10582. pinLeft: 'Lukitse vasemmalle',
  10583. pinRight: 'Lukitse oikealle',
  10584. unpin: 'Poista lukitus'
  10585. },
  10586. gridMenu: {
  10587. columns: 'Sarakkeet:',
  10588. importerTitle: 'Tuo tiedosto',
  10589. exporterAllAsCsv: 'Vie tiedot csv-muodossa',
  10590. exporterVisibleAsCsv: 'Vie näkyvä tieto csv-muodossa',
  10591. exporterSelectedAsCsv: 'Vie valittu tieto csv-muodossa',
  10592. exporterAllAsPdf: 'Vie tiedot pdf-muodossa',
  10593. exporterVisibleAsPdf: 'Vie näkyvä tieto pdf-muodossa',
  10594. exporterSelectedAsPdf: 'Vie valittu tieto pdf-muodossa',
  10595. clearAllFilters: 'Puhdista kaikki suodattimet'
  10596. },
  10597. importer: {
  10598. noHeaders: 'Sarakkeen nimiä ei voitu päätellä, onko tiedostossa otsikkoriviä?',
  10599. noObjects: 'Tietoja ei voitu lukea, onko tiedostossa muuta kuin otsikkot?',
  10600. invalidCsv: 'Tiedostoa ei voitu käsitellä, oliko se CSV-muodossa?',
  10601. invalidJson: 'Tiedostoa ei voitu käsitellä, oliko se JSON-muodossa?',
  10602. jsonNotArray: 'Tiedosto ei sisältänyt taulukkoa, lopetetaan.'
  10603. }
  10604. });
  10605. return $delegate;
  10606. }]);
  10607. }]);
  10608. })();
  10609. (function () {
  10610. angular.module('ui.grid').config(['$provide', function($provide) {
  10611. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10612. $delegate.add('fr', {
  10613. aggregate: {
  10614. label: 'éléments'
  10615. },
  10616. groupPanel: {
  10617. description: 'Faites glisser une en-tête de colonne ici pour créer un groupe de colonnes.'
  10618. },
  10619. search: {
  10620. placeholder: 'Recherche...',
  10621. showingItems: 'Affichage des éléments :',
  10622. selectedItems: 'Éléments sélectionnés :',
  10623. totalItems: 'Nombre total d\'éléments:',
  10624. size: 'Taille de page:',
  10625. first: 'Première page',
  10626. next: 'Page Suivante',
  10627. previous: 'Page précédente',
  10628. last: 'Dernière page'
  10629. },
  10630. menu: {
  10631. text: 'Choisir des colonnes :'
  10632. },
  10633. sort: {
  10634. ascending: 'Trier par ordre croissant',
  10635. descending: 'Trier par ordre décroissant',
  10636. remove: 'Enlever le tri'
  10637. },
  10638. column: {
  10639. hide: 'Cacher la colonne'
  10640. },
  10641. aggregation: {
  10642. count: 'lignes totales: ',
  10643. sum: 'total: ',
  10644. avg: 'moy: ',
  10645. min: 'min: ',
  10646. max: 'max: '
  10647. },
  10648. pinning: {
  10649. pinLeft: 'Épingler à gauche',
  10650. pinRight: 'Épingler à droite',
  10651. unpin: 'Détacher'
  10652. },
  10653. gridMenu: {
  10654. columns: 'Colonnes:',
  10655. importerTitle: 'Importer un fichier',
  10656. exporterAllAsCsv: 'Exporter toutes les données en CSV',
  10657. exporterVisibleAsCsv: 'Exporter les données visibles en CSV',
  10658. exporterSelectedAsCsv: 'Exporter les données sélectionnées en CSV',
  10659. exporterAllAsPdf: 'Exporter toutes les données en PDF',
  10660. exporterVisibleAsPdf: 'Exporter les données visibles en PDF',
  10661. exporterSelectedAsPdf: 'Exporter les données sélectionnées en PDF',
  10662. clearAllFilters: 'Nettoyez tous les filtres'
  10663. },
  10664. importer: {
  10665. noHeaders: 'Impossible de déterminer le nom des colonnes, le fichier possède-t-il une en-tête ?',
  10666. noObjects: 'Aucun objet trouvé, le fichier possède-t-il des données autres que l\'en-tête ?',
  10667. invalidCsv: 'Le fichier n\'a pas pu être traité, le CSV est-il valide ?',
  10668. invalidJson: 'Le fichier n\'a pas pu être traité, le JSON est-il valide ?',
  10669. jsonNotArray: 'Le fichier JSON importé doit contenir un tableau, abandon.'
  10670. },
  10671. pagination: {
  10672. sizes: 'éléments par page',
  10673. totalItems: 'éléments',
  10674. of: 'sur'
  10675. },
  10676. grouping: {
  10677. group: 'Grouper',
  10678. ungroup: 'Dégrouper',
  10679. aggregate_count: 'Agg: Compte',
  10680. aggregate_sum: 'Agg: Somme',
  10681. aggregate_max: 'Agg: Max',
  10682. aggregate_min: 'Agg: Min',
  10683. aggregate_avg: 'Agg: Moy',
  10684. aggregate_remove: 'Agg: Retirer'
  10685. }
  10686. });
  10687. return $delegate;
  10688. }]);
  10689. }]);
  10690. })();
  10691. (function () {
  10692. angular.module('ui.grid').config(['$provide', function ($provide) {
  10693. $provide.decorator('i18nService', ['$delegate', function ($delegate) {
  10694. $delegate.add('he', {
  10695. aggregate: {
  10696. label: 'items'
  10697. },
  10698. groupPanel: {
  10699. description: 'גרור עמודה לכאן ושחרר בכדי לקבץ עמודה זו.'
  10700. },
  10701. search: {
  10702. placeholder: 'חפש...',
  10703. showingItems: 'מציג:',
  10704. selectedItems: 'סה"כ נבחרו:',
  10705. totalItems: 'סה"כ רשומות:',
  10706. size: 'תוצאות בדף:',
  10707. first: 'דף ראשון',
  10708. next: 'דף הבא',
  10709. previous: 'דף קודם',
  10710. last: 'דף אחרון'
  10711. },
  10712. menu: {
  10713. text: 'בחר עמודות:'
  10714. },
  10715. sort: {
  10716. ascending: 'סדר עולה',
  10717. descending: 'סדר יורד',
  10718. remove: 'בטל'
  10719. },
  10720. column: {
  10721. hide: 'טור הסתר'
  10722. },
  10723. aggregation: {
  10724. count: 'total rows: ',
  10725. sum: 'total: ',
  10726. avg: 'avg: ',
  10727. min: 'min: ',
  10728. max: 'max: '
  10729. },
  10730. gridMenu: {
  10731. columns: 'Columns:',
  10732. importerTitle: 'Import file',
  10733. exporterAllAsCsv: 'Export all data as csv',
  10734. exporterVisibleAsCsv: 'Export visible data as csv',
  10735. exporterSelectedAsCsv: 'Export selected data as csv',
  10736. exporterAllAsPdf: 'Export all data as pdf',
  10737. exporterVisibleAsPdf: 'Export visible data as pdf',
  10738. exporterSelectedAsPdf: 'Export selected data as pdf',
  10739. clearAllFilters: 'Clean all filters'
  10740. },
  10741. importer: {
  10742. noHeaders: 'Column names were unable to be derived, does the file have a header?',
  10743. noObjects: 'Objects were not able to be derived, was there data in the file other than headers?',
  10744. invalidCsv: 'File was unable to be processed, is it valid CSV?',
  10745. invalidJson: 'File was unable to be processed, is it valid Json?',
  10746. jsonNotArray: 'Imported json file must contain an array, aborting.'
  10747. }
  10748. });
  10749. return $delegate;
  10750. }]);
  10751. }]);
  10752. })();
  10753. (function () {
  10754. angular.module('ui.grid').config(['$provide', function($provide) {
  10755. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10756. $delegate.add('hy', {
  10757. aggregate: {
  10758. label: 'տվյալներ'
  10759. },
  10760. groupPanel: {
  10761. description: 'Ըստ սյան խմբավորելու համար քաշեք և գցեք վերնագիրն այստեղ։'
  10762. },
  10763. search: {
  10764. placeholder: 'Փնտրում...',
  10765. showingItems: 'Ցուցադրված տվյալներ՝',
  10766. selectedItems: 'Ընտրված:',
  10767. totalItems: 'Ընդամենը՝',
  10768. size: 'Տողերի քանակը էջում՝',
  10769. first: 'Առաջին էջ',
  10770. next: 'Հաջորդ էջ',
  10771. previous: 'Նախորդ էջ',
  10772. last: 'Վերջին էջ'
  10773. },
  10774. menu: {
  10775. text: 'Ընտրել սյուները:'
  10776. },
  10777. sort: {
  10778. ascending: 'Աճման կարգով',
  10779. descending: 'Նվազման կարգով',
  10780. remove: 'Հանել '
  10781. },
  10782. column: {
  10783. hide: 'Թաքցնել սյունը'
  10784. },
  10785. aggregation: {
  10786. count: 'ընդամենը տող՝ ',
  10787. sum: 'ընդամենը՝ ',
  10788. avg: 'միջին՝ ',
  10789. min: 'մին՝ ',
  10790. max: 'մաքս՝ '
  10791. },
  10792. pinning: {
  10793. pinLeft: 'Կպցնել ձախ կողմում',
  10794. pinRight: 'Կպցնել աջ կողմում',
  10795. unpin: 'Արձակել'
  10796. },
  10797. gridMenu: {
  10798. columns: 'Սյուներ:',
  10799. importerTitle: 'Ներմուծել ֆայլ',
  10800. exporterAllAsCsv: 'Արտահանել ամբողջը CSV',
  10801. exporterVisibleAsCsv: 'Արտահանել երևացող տվյալները CSV',
  10802. exporterSelectedAsCsv: 'Արտահանել ընտրված տվյալները CSV',
  10803. exporterAllAsPdf: 'Արտահանել PDF',
  10804. exporterVisibleAsPdf: 'Արտահանել երևացող տվյալները PDF',
  10805. exporterSelectedAsPdf: 'Արտահանել ընտրված տվյալները PDF',
  10806. clearAllFilters: 'Մաքրել բոլոր ֆիլտրերը'
  10807. },
  10808. importer: {
  10809. noHeaders: 'Հնարավոր չեղավ որոշել սյան վերնագրերը։ Արդյո՞ք ֆայլը ունի վերնագրեր։',
  10810. noObjects: 'Հնարավոր չեղավ կարդալ տվյալները։ Արդյո՞ք ֆայլում կան տվյալներ։',
  10811. invalidCsv: 'Հնարավոր չեղավ մշակել ֆայլը։ Արդյո՞ք այն վավեր CSV է։',
  10812. invalidJson: 'Հնարավոր չեղավ մշակել ֆայլը։ Արդյո՞ք այն վավեր Json է։',
  10813. jsonNotArray: 'Ներմուծված json ֆայլը պետք է պարունակի զանգված, կասեցվում է։'
  10814. }
  10815. });
  10816. return $delegate;
  10817. }]);
  10818. }]);
  10819. })();
  10820. (function () {
  10821. angular.module('ui.grid').config(['$provide', function($provide) {
  10822. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10823. $delegate.add('it', {
  10824. aggregate: {
  10825. label: 'elementi'
  10826. },
  10827. groupPanel: {
  10828. description: 'Trascina un\'intestazione all\'interno del gruppo della colonna.'
  10829. },
  10830. search: {
  10831. placeholder: 'Ricerca...',
  10832. showingItems: 'Mostra:',
  10833. selectedItems: 'Selezionati:',
  10834. totalItems: 'Totali:',
  10835. size: 'Tot Pagine:',
  10836. first: 'Prima',
  10837. next: 'Prossima',
  10838. previous: 'Precedente',
  10839. last: 'Ultima'
  10840. },
  10841. menu: {
  10842. text: 'Scegli le colonne:'
  10843. },
  10844. sort: {
  10845. ascending: 'Asc.',
  10846. descending: 'Desc.',
  10847. remove: 'Annulla ordinamento'
  10848. },
  10849. column: {
  10850. hide: 'Nascondi'
  10851. },
  10852. aggregation: {
  10853. count: 'righe totali: ',
  10854. sum: 'tot: ',
  10855. avg: 'media: ',
  10856. min: 'minimo: ',
  10857. max: 'massimo: '
  10858. },
  10859. pinning: {
  10860. pinLeft: 'Blocca a sx',
  10861. pinRight: 'Blocca a dx',
  10862. unpin: 'Blocca in alto'
  10863. },
  10864. gridMenu: {
  10865. columns: 'Colonne:',
  10866. importerTitle: 'Importa',
  10867. exporterAllAsCsv: 'Esporta tutti i dati in CSV',
  10868. exporterVisibleAsCsv: 'Esporta i dati visibili in CSV',
  10869. exporterSelectedAsCsv: 'Esporta i dati selezionati in CSV',
  10870. exporterAllAsPdf: 'Esporta tutti i dati in PDF',
  10871. exporterVisibleAsPdf: 'Esporta i dati visibili in PDF',
  10872. exporterSelectedAsPdf: 'Esporta i dati selezionati in PDF',
  10873. clearAllFilters: 'Pulire tutti i filtri'
  10874. },
  10875. importer: {
  10876. noHeaders: 'Impossibile reperire i nomi delle colonne, sicuro che siano indicati all\'interno del file?',
  10877. noObjects: 'Impossibile reperire gli oggetti, sicuro che siano indicati all\'interno del file?',
  10878. invalidCsv: 'Impossibile elaborare il file, sicuro che sia un CSV?',
  10879. invalidJson: 'Impossibile elaborare il file, sicuro che sia un JSON valido?',
  10880. jsonNotArray: 'Errore! Il file JSON da importare deve contenere un array.'
  10881. },
  10882. grouping: {
  10883. group: 'Raggruppa',
  10884. ungroup: 'Separa',
  10885. aggregate_count: 'Agg: N. Elem.',
  10886. aggregate_sum: 'Agg: Somma',
  10887. aggregate_max: 'Agg: Massimo',
  10888. aggregate_min: 'Agg: Minimo',
  10889. aggregate_avg: 'Agg: Media',
  10890. aggregate_remove: 'Agg: Rimuovi'
  10891. },
  10892. validate: {
  10893. error: 'Errore:',
  10894. minLength: 'Lunghezza minima pari a THRESHOLD caratteri.',
  10895. maxLength: 'Lunghezza massima pari a THRESHOLD caratteri.',
  10896. required: 'Necessario inserire un valore.'
  10897. }
  10898. });
  10899. return $delegate;
  10900. }]);
  10901. }]);
  10902. })();
  10903. (function() {
  10904. angular.module('ui.grid').config(['$provide', function($provide) {
  10905. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10906. $delegate.add('ja', {
  10907. aggregate: {
  10908. label: '項目'
  10909. },
  10910. groupPanel: {
  10911. description: 'ここに列ヘッダをドラッグアンドドロップして、その列でグループ化します。'
  10912. },
  10913. search: {
  10914. placeholder: '検索...',
  10915. showingItems: '表示中の項目:',
  10916. selectedItems: '選択した項目:',
  10917. totalItems: '項目の総数:',
  10918. size: 'ページサイズ:',
  10919. first: '最初のページ',
  10920. next: '次のページ',
  10921. previous: '前のページ',
  10922. last: '前のページ'
  10923. },
  10924. menu: {
  10925. text: '列の選択:'
  10926. },
  10927. sort: {
  10928. ascending: '昇順に並べ替え',
  10929. descending: '降順に並べ替え',
  10930. remove: '並べ替えの解除'
  10931. },
  10932. column: {
  10933. hide: '列の非表示'
  10934. },
  10935. aggregation: {
  10936. count: '合計行数: ',
  10937. sum: '合計: ',
  10938. avg: '平均: ',
  10939. min: '最小: ',
  10940. max: '最大: '
  10941. },
  10942. pinning: {
  10943. pinLeft: '左に固定',
  10944. pinRight: '右に固定',
  10945. unpin: '固定解除'
  10946. },
  10947. gridMenu: {
  10948. columns: '列:',
  10949. importerTitle: 'ファイルのインポート',
  10950. exporterAllAsCsv: 'すべてのデータをCSV形式でエクスポート',
  10951. exporterVisibleAsCsv: '表示中のデータをCSV形式でエクスポート',
  10952. exporterSelectedAsCsv: '選択したデータをCSV形式でエクスポート',
  10953. exporterAllAsPdf: 'すべてのデータをPDF形式でエクスポート',
  10954. exporterVisibleAsPdf: '表示中のデータをPDF形式でエクスポート',
  10955. exporterSelectedAsPdf: '選択したデータをPDF形式でエクスポート',
  10956. clearAllFilters: 'すべてのフィルタを清掃してください'
  10957. },
  10958. importer: {
  10959. noHeaders: '列名を取得できません。ファイルにヘッダが含まれていることを確認してください。',
  10960. noObjects: 'オブジェクトを取得できません。ファイルにヘッダ以外のデータが含まれていることを確認してください。',
  10961. invalidCsv: 'ファイルを処理できません。ファイルが有効なCSV形式であることを確認してください。',
  10962. invalidJson: 'ファイルを処理できません。ファイルが有効なJSON形式であることを確認してください。',
  10963. jsonNotArray: 'インポートしたJSONファイルには配列が含まれている必要があります。処理を中止します。'
  10964. },
  10965. pagination: {
  10966. aria: {
  10967. pageToFirst: '最初のページ',
  10968. pageBack: '前のページ',
  10969. pageSelected: '現在のページ',
  10970. pageForward: '次のページ',
  10971. pageToLast: '最後のページ'
  10972. },
  10973. sizes: '項目/ページ',
  10974. totalItems: '項目',
  10975. through: 'から',
  10976. of: '項目/全'
  10977. }
  10978. });
  10979. return $delegate;
  10980. }]);
  10981. }]);
  10982. })();
  10983. (function () {
  10984. angular.module('ui.grid').config(['$provide', function($provide) {
  10985. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10986. $delegate.add('ko', {
  10987. aggregate: {
  10988. label: '아이템'
  10989. },
  10990. groupPanel: {
  10991. description: '컬럼으로 그룹핑하기 위해서는 컬럼 헤더를 끌어 떨어뜨려 주세요.'
  10992. },
  10993. search: {
  10994. placeholder: '검색...',
  10995. showingItems: '항목 보여주기:',
  10996. selectedItems: '선택 항목:',
  10997. totalItems: '전체 항목:',
  10998. size: '페이지 크기:',
  10999. first: '첫번째 페이지',
  11000. next: '다음 페이지',
  11001. previous: '이전 페이지',
  11002. last: '마지막 페이지'
  11003. },
  11004. menu: {
  11005. text: '컬럼을 선택하세요:'
  11006. },
  11007. sort: {
  11008. ascending: '오름차순 정렬',
  11009. descending: '내림차순 정렬',
  11010. remove: '소팅 제거'
  11011. },
  11012. column: {
  11013. hide: '컬럼 제거'
  11014. },
  11015. aggregation: {
  11016. count: '전체 갯수: ',
  11017. sum: '전체: ',
  11018. avg: '평균: ',
  11019. min: '최소: ',
  11020. max: '최대: '
  11021. },
  11022. pinning: {
  11023. pinLeft: '왼쪽 핀',
  11024. pinRight: '오른쪽 핀',
  11025. unpin: '핀 제거'
  11026. },
  11027. gridMenu: {
  11028. columns: '컬럼:',
  11029. importerTitle: '파일 가져오기',
  11030. exporterAllAsCsv: 'csv로 모든 데이터 내보내기',
  11031. exporterVisibleAsCsv: 'csv로 보이는 데이터 내보내기',
  11032. exporterSelectedAsCsv: 'csv로 선택된 데이터 내보내기',
  11033. exporterAllAsPdf: 'pdf로 모든 데이터 내보내기',
  11034. exporterVisibleAsPdf: 'pdf로 보이는 데이터 내보내기',
  11035. exporterSelectedAsPdf: 'pdf로 선택 데이터 내보내기',
  11036. clearAllFilters: '모든 필터를 청소'
  11037. },
  11038. importer: {
  11039. noHeaders: '컬럼명이 지정되어 있지 않습니다. 파일에 헤더가 명시되어 있는지 확인해 주세요.',
  11040. noObjects: '데이터가 지정되어 있지 않습니다. 데이터가 파일에 있는지 확인해 주세요.',
  11041. invalidCsv: '파일을 처리할 수 없습니다. 올바른 csv인지 확인해 주세요.',
  11042. invalidJson: '파일을 처리할 수 없습니다. 올바른 json인지 확인해 주세요.',
  11043. jsonNotArray: 'json 파일은 배열을 포함해야 합니다.'
  11044. },
  11045. pagination: {
  11046. sizes: '페이지당 항목',
  11047. totalItems: '전체 항목'
  11048. }
  11049. });
  11050. return $delegate;
  11051. }]);
  11052. }]);
  11053. })();
  11054. (function () {
  11055. angular.module('ui.grid').config(['$provide', function($provide) {
  11056. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11057. $delegate.add('nl', {
  11058. aggregate: {
  11059. label: 'items'
  11060. },
  11061. groupPanel: {
  11062. description: 'Sleep hier een kolomnaam heen om op te groeperen.'
  11063. },
  11064. search: {
  11065. placeholder: 'Zoeken...',
  11066. showingItems: 'Getoonde items:',
  11067. selectedItems: 'Geselecteerde items:',
  11068. totalItems: 'Totaal aantal items:',
  11069. size: 'Items per pagina:',
  11070. first: 'Eerste pagina',
  11071. next: 'Volgende pagina',
  11072. previous: 'Vorige pagina',
  11073. last: 'Laatste pagina'
  11074. },
  11075. menu: {
  11076. text: 'Kies kolommen:'
  11077. },
  11078. sort: {
  11079. ascending: 'Sorteer oplopend',
  11080. descending: 'Sorteer aflopend',
  11081. remove: 'Verwijder sortering'
  11082. },
  11083. column: {
  11084. hide: 'Verberg kolom'
  11085. },
  11086. aggregation: {
  11087. count: 'Aantal rijen: ',
  11088. sum: 'Som: ',
  11089. avg: 'Gemiddelde: ',
  11090. min: 'Min: ',
  11091. max: 'Max: '
  11092. },
  11093. pinning: {
  11094. pinLeft: 'Zet links vast',
  11095. pinRight: 'Zet rechts vast',
  11096. unpin: 'Maak los'
  11097. },
  11098. gridMenu: {
  11099. columns: 'Kolommen:',
  11100. importerTitle: 'Importeer bestand',
  11101. exporterAllAsCsv: 'Exporteer alle data als csv',
  11102. exporterVisibleAsCsv: 'Exporteer zichtbare data als csv',
  11103. exporterSelectedAsCsv: 'Exporteer geselecteerde data als csv',
  11104. exporterAllAsPdf: 'Exporteer alle data als pdf',
  11105. exporterVisibleAsPdf: 'Exporteer zichtbare data als pdf',
  11106. exporterSelectedAsPdf: 'Exporteer geselecteerde data als pdf',
  11107. clearAllFilters: 'Reinig alle filters'
  11108. },
  11109. importer: {
  11110. noHeaders: 'Kolomnamen kunnen niet worden afgeleid. Heeft het bestand een header?',
  11111. noObjects: 'Objecten kunnen niet worden afgeleid. Bevat het bestand data naast de headers?',
  11112. invalidCsv: 'Het bestand kan niet verwerkt worden. Is het een valide csv bestand?',
  11113. invalidJson: 'Het bestand kan niet verwerkt worden. Is het valide json?',
  11114. jsonNotArray: 'Het json bestand moet een array bevatten. De actie wordt geannuleerd.'
  11115. },
  11116. pagination: {
  11117. sizes: 'items per pagina',
  11118. totalItems: 'items',
  11119. of: 'van de'
  11120. },
  11121. grouping: {
  11122. group: 'Groepeer',
  11123. ungroup: 'Groepering opheffen',
  11124. aggregate_count: 'Agg: Aantal',
  11125. aggregate_sum: 'Agg: Som',
  11126. aggregate_max: 'Agg: Max',
  11127. aggregate_min: 'Agg: Min',
  11128. aggregate_avg: 'Agg: Gem',
  11129. aggregate_remove: 'Agg: Verwijder'
  11130. }
  11131. });
  11132. return $delegate;
  11133. }]);
  11134. }]);
  11135. })();
  11136. (function () {
  11137. angular.module('ui.grid').config(['$provide', function($provide) {
  11138. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11139. $delegate.add('pl', {
  11140. headerCell: {
  11141. aria: {
  11142. defaultFilterLabel: 'Filter dla kolumny',
  11143. removeFilter: 'Usuń filter',
  11144. columnMenuButtonLabel: 'Menu kolumny'
  11145. },
  11146. priority: 'Prioritet:',
  11147. filterLabel: "Filtr dla kolumny: "
  11148. },
  11149. aggregate: {
  11150. label: 'pozycji'
  11151. },
  11152. groupPanel: {
  11153. description: 'Przeciągnij nagłówek kolumny tutaj, aby pogrupować według niej.'
  11154. },
  11155. search: {
  11156. placeholder: 'Szukaj...',
  11157. showingItems: 'Widoczne pozycje:',
  11158. selectedItems: 'Zaznaczone pozycje:',
  11159. totalItems: 'Wszystkich pozycji:',
  11160. size: 'Rozmiar strony:',
  11161. first: 'Pierwsza strona',
  11162. next: 'Następna strona',
  11163. previous: 'Poprzednia strona',
  11164. last: 'Ostatnia strona'
  11165. },
  11166. menu: {
  11167. text: 'Wybierz kolumny:'
  11168. },
  11169. sort: {
  11170. ascending: 'Sortuj rosnąco',
  11171. descending: 'Sortuj malejąco',
  11172. none: 'Brak sortowania',
  11173. remove: 'Wyłącz sortowanie'
  11174. },
  11175. column: {
  11176. hide: 'Ukryj kolumne'
  11177. },
  11178. aggregation: {
  11179. count: 'Razem pozycji: ',
  11180. sum: 'Razem: ',
  11181. avg: 'Średnia: ',
  11182. min: 'Min: ',
  11183. max: 'Max: '
  11184. },
  11185. pinning: {
  11186. pinLeft: 'Przypnij do lewej',
  11187. pinRight: 'Przypnij do prawej',
  11188. unpin: 'Odepnij'
  11189. },
  11190. columnMenu: {
  11191. close: 'Zamknij'
  11192. },
  11193. gridMenu: {
  11194. aria: {
  11195. buttonLabel: 'Menu Grida'
  11196. },
  11197. columns: 'Kolumny:',
  11198. importerTitle: 'Importuj plik',
  11199. exporterAllAsCsv: 'Eksportuj wszystkie dane do csv',
  11200. exporterVisibleAsCsv: 'Eksportuj widoczne dane do csv',
  11201. exporterSelectedAsCsv: 'Eksportuj zaznaczone dane do csv',
  11202. exporterAllAsPdf: 'Eksportuj wszystkie dane do pdf',
  11203. exporterVisibleAsPdf: 'Eksportuj widoczne dane do pdf',
  11204. exporterSelectedAsPdf: 'Eksportuj zaznaczone dane do pdf',
  11205. clearAllFilters: 'Wyczyść filtry'
  11206. },
  11207. importer: {
  11208. noHeaders: 'Nie udało się wczytać nazw kolumn. Czy plik posiada nagłówek?',
  11209. noObjects: 'Nie udalo się wczytać pozycji. Czy plik zawiera dane??',
  11210. invalidCsv: 'Nie udało się przetworzyć pliku, jest to prawidlowy plik CSV??',
  11211. invalidJson: 'Nie udało się przetworzyć pliku, jest to prawidlowy plik Json?',
  11212. jsonNotArray: 'Importowany plik json musi zawierać tablicę, importowanie przerwane.'
  11213. },
  11214. pagination: {
  11215. aria: {
  11216. pageToFirst: 'Pierwsza strona',
  11217. pageBack: 'Poprzednia strona',
  11218. pageSelected: 'Wybrana strona',
  11219. pageForward: 'Następna strona',
  11220. pageToLast: 'Ostatnia strona'
  11221. },
  11222. sizes: 'pozycji na stronę',
  11223. totalItems: 'pozycji',
  11224. through: 'do',
  11225. of: 'z'
  11226. },
  11227. grouping: {
  11228. group: 'Grupuj',
  11229. ungroup: 'Rozgrupuj',
  11230. aggregate_count: 'Zbiorczo: Razem',
  11231. aggregate_sum: 'Zbiorczo: Suma',
  11232. aggregate_max: 'Zbiorczo: Max',
  11233. aggregate_min: 'Zbiorczo: Min',
  11234. aggregate_avg: 'Zbiorczo: Średnia',
  11235. aggregate_remove: 'Zbiorczo: Usuń'
  11236. }
  11237. });
  11238. return $delegate;
  11239. }]);
  11240. }]);
  11241. })();
  11242. (function () {
  11243. angular.module('ui.grid').config(['$provide', function($provide) {
  11244. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11245. $delegate.add('pt-br', {
  11246. headerCell: {
  11247. aria: {
  11248. defaultFilterLabel: 'Filtro por coluna',
  11249. removeFilter: 'Remover filtro',
  11250. columnMenuButtonLabel: 'Menu coluna'
  11251. },
  11252. priority: 'Prioridade:',
  11253. filterLabel: "Filtro por coluna: "
  11254. },
  11255. aggregate: {
  11256. label: 'itens'
  11257. },
  11258. groupPanel: {
  11259. description: 'Arraste e solte uma coluna aqui para agrupar por essa coluna'
  11260. },
  11261. search: {
  11262. placeholder: 'Procurar...',
  11263. showingItems: 'Mostrando os Itens:',
  11264. selectedItems: 'Items Selecionados:',
  11265. totalItems: 'Total de Itens:',
  11266. size: 'Tamanho da Página:',
  11267. first: 'Primeira Página',
  11268. next: 'Próxima Página',
  11269. previous: 'Página Anterior',
  11270. last: 'Última Página'
  11271. },
  11272. menu: {
  11273. text: 'Selecione as colunas:'
  11274. },
  11275. sort: {
  11276. ascending: 'Ordenar Ascendente',
  11277. descending: 'Ordenar Descendente',
  11278. none: 'Nenhuma Ordem',
  11279. remove: 'Remover Ordenação'
  11280. },
  11281. column: {
  11282. hide: 'Esconder coluna'
  11283. },
  11284. aggregation: {
  11285. count: 'total de linhas: ',
  11286. sum: 'total: ',
  11287. avg: 'med: ',
  11288. min: 'min: ',
  11289. max: 'max: '
  11290. },
  11291. pinning: {
  11292. pinLeft: 'Fixar Esquerda',
  11293. pinRight: 'Fixar Direita',
  11294. unpin: 'Desprender'
  11295. },
  11296. columnMenu: {
  11297. close: 'Fechar'
  11298. },
  11299. gridMenu: {
  11300. aria: {
  11301. buttonLabel: 'Menu Grid'
  11302. },
  11303. columns: 'Colunas:',
  11304. importerTitle: 'Importar arquivo',
  11305. exporterAllAsCsv: 'Exportar todos os dados como csv',
  11306. exporterVisibleAsCsv: 'Exportar dados visíveis como csv',
  11307. exporterSelectedAsCsv: 'Exportar dados selecionados como csv',
  11308. exporterAllAsPdf: 'Exportar todos os dados como pdf',
  11309. exporterVisibleAsPdf: 'Exportar dados visíveis como pdf',
  11310. exporterSelectedAsPdf: 'Exportar dados selecionados como pdf',
  11311. clearAllFilters: 'Limpar todos os filtros'
  11312. },
  11313. importer: {
  11314. noHeaders: 'Nomes de colunas não puderam ser derivados. O arquivo tem um cabeçalho?',
  11315. noObjects: 'Objetos não puderam ser derivados. Havia dados no arquivo, além dos cabeçalhos?',
  11316. invalidCsv: 'Arquivo não pode ser processado. É um CSV válido?',
  11317. invalidJson: 'Arquivo não pode ser processado. É um Json válido?',
  11318. jsonNotArray: 'Arquivo json importado tem que conter um array. Abortando.'
  11319. },
  11320. pagination: {
  11321. aria: {
  11322. pageToFirst: 'Primeira página',
  11323. pageBack: 'Página anterior',
  11324. pageSelected: 'Página Selecionada',
  11325. pageForward: 'Proxima',
  11326. pageToLast: 'Anterior'
  11327. },
  11328. sizes: 'itens por página',
  11329. totalItems: 'itens',
  11330. through: 'através dos',
  11331. of: 'de'
  11332. },
  11333. grouping: {
  11334. group: 'Agrupar',
  11335. ungroup: 'Desagrupar',
  11336. aggregate_count: 'Agr: Contar',
  11337. aggregate_sum: 'Agr: Soma',
  11338. aggregate_max: 'Agr: Max',
  11339. aggregate_min: 'Agr: Min',
  11340. aggregate_avg: 'Agr: Med',
  11341. aggregate_remove: 'Agr: Remover'
  11342. }
  11343. });
  11344. return $delegate;
  11345. }]);
  11346. }]);
  11347. })();
  11348. (function () {
  11349. angular.module('ui.grid').config(['$provide', function($provide) {
  11350. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11351. $delegate.add('pt', {
  11352. headerCell: {
  11353. aria: {
  11354. defaultFilterLabel: 'Filtro por coluna',
  11355. removeFilter: 'Remover filtro',
  11356. columnMenuButtonLabel: 'Menu coluna'
  11357. },
  11358. priority: 'Prioridade:',
  11359. filterLabel: "Filtro por coluna: "
  11360. },
  11361. aggregate: {
  11362. label: 'itens'
  11363. },
  11364. groupPanel: {
  11365. description: 'Arraste e solte uma coluna aqui para agrupar por essa coluna'
  11366. },
  11367. search: {
  11368. placeholder: 'Procurar...',
  11369. showingItems: 'Mostrando os Itens:',
  11370. selectedItems: 'Itens Selecionados:',
  11371. totalItems: 'Total de Itens:',
  11372. size: 'Tamanho da Página:',
  11373. first: 'Primeira Página',
  11374. next: 'Próxima Página',
  11375. previous: 'Página Anterior',
  11376. last: 'Última Página'
  11377. },
  11378. menu: {
  11379. text: 'Selecione as colunas:'
  11380. },
  11381. sort: {
  11382. ascending: 'Ordenar Ascendente',
  11383. descending: 'Ordenar Descendente',
  11384. none: 'Nenhuma Ordem',
  11385. remove: 'Remover Ordenação'
  11386. },
  11387. column: {
  11388. hide: 'Esconder coluna'
  11389. },
  11390. aggregation: {
  11391. count: 'total de linhas: ',
  11392. sum: 'total: ',
  11393. avg: 'med: ',
  11394. min: 'min: ',
  11395. max: 'max: '
  11396. },
  11397. pinning: {
  11398. pinLeft: 'Fixar Esquerda',
  11399. pinRight: 'Fixar Direita',
  11400. unpin: 'Desprender'
  11401. },
  11402. columnMenu: {
  11403. close: 'Fechar'
  11404. },
  11405. gridMenu: {
  11406. aria: {
  11407. buttonLabel: 'Menu Grid'
  11408. },
  11409. columns: 'Colunas:',
  11410. importerTitle: 'Importar ficheiro',
  11411. exporterAllAsCsv: 'Exportar todos os dados como csv',
  11412. exporterVisibleAsCsv: 'Exportar dados visíveis como csv',
  11413. exporterSelectedAsCsv: 'Exportar dados selecionados como csv',
  11414. exporterAllAsPdf: 'Exportar todos os dados como pdf',
  11415. exporterVisibleAsPdf: 'Exportar dados visíveis como pdf',
  11416. exporterSelectedAsPdf: 'Exportar dados selecionados como pdf',
  11417. clearAllFilters: 'Limpar todos os filtros'
  11418. },
  11419. importer: {
  11420. noHeaders: 'Nomes de colunas não puderam ser derivados. O ficheiro tem um cabeçalho?',
  11421. noObjects: 'Objetos não puderam ser derivados. Havia dados no ficheiro, além dos cabeçalhos?',
  11422. invalidCsv: 'Ficheiro não pode ser processado. É um CSV válido?',
  11423. invalidJson: 'Ficheiro não pode ser processado. É um Json válido?',
  11424. jsonNotArray: 'Ficheiro json importado tem que conter um array. Interrompendo.'
  11425. },
  11426. pagination: {
  11427. aria: {
  11428. pageToFirst: 'Primeira página',
  11429. pageBack: 'Página anterior',
  11430. pageSelected: 'Página Selecionada',
  11431. pageForward: 'Próxima',
  11432. pageToLast: 'Anterior'
  11433. },
  11434. sizes: 'itens por página',
  11435. totalItems: 'itens',
  11436. through: 'através dos',
  11437. of: 'de'
  11438. },
  11439. grouping: {
  11440. group: 'Agrupar',
  11441. ungroup: 'Desagrupar',
  11442. aggregate_count: 'Agr: Contar',
  11443. aggregate_sum: 'Agr: Soma',
  11444. aggregate_max: 'Agr: Max',
  11445. aggregate_min: 'Agr: Min',
  11446. aggregate_avg: 'Agr: Med',
  11447. aggregate_remove: 'Agr: Remover'
  11448. }
  11449. });
  11450. return $delegate;
  11451. }]);
  11452. }]);
  11453. })();
  11454. (function () {
  11455. angular.module('ui.grid').config(['$provide', function($provide) {
  11456. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11457. $delegate.add('ro', {
  11458. headerCell: {
  11459. aria: {
  11460. defaultFilterLabel: 'Filtru pentru coloana',
  11461. removeFilter: 'Sterge filtru',
  11462. columnMenuButtonLabel: 'Column Menu'
  11463. },
  11464. priority: 'Prioritate:',
  11465. filterLabel: "Filtru pentru coloana:"
  11466. },
  11467. aggregate: {
  11468. label: 'Elemente'
  11469. },
  11470. groupPanel: {
  11471. description: 'Trage un cap de coloana aici pentru a grupa elementele dupa coloana respectiva'
  11472. },
  11473. search: {
  11474. placeholder: 'Cauta...',
  11475. showingItems: 'Arata elementele:',
  11476. selectedItems: 'Elementele selectate:',
  11477. totalItems: 'Total elemente:',
  11478. size: 'Marime pagina:',
  11479. first: 'Prima pagina',
  11480. next: 'Pagina urmatoare',
  11481. previous: 'Pagina anterioara',
  11482. last: 'Ultima pagina'
  11483. },
  11484. menu: {
  11485. text: 'Alege coloane:'
  11486. },
  11487. sort: {
  11488. ascending: 'Ordoneaza crescator',
  11489. descending: 'Ordoneaza descrescator',
  11490. none: 'Fara ordonare',
  11491. remove: 'Sterge ordonarea'
  11492. },
  11493. column: {
  11494. hide: 'Ascunde coloana'
  11495. },
  11496. aggregation: {
  11497. count: 'total linii: ',
  11498. sum: 'total: ',
  11499. avg: 'medie: ',
  11500. min: 'min: ',
  11501. max: 'max: '
  11502. },
  11503. pinning: {
  11504. pinLeft: 'Pin la stanga',
  11505. pinRight: 'Pin la dreapta',
  11506. unpin: 'Sterge pinul'
  11507. },
  11508. columnMenu: {
  11509. close: 'Inchide'
  11510. },
  11511. gridMenu: {
  11512. aria: {
  11513. buttonLabel: 'Grid Menu'
  11514. },
  11515. columns: 'Coloane:',
  11516. importerTitle: 'Incarca fisier',
  11517. exporterAllAsCsv: 'Exporta toate datele ca csv',
  11518. exporterVisibleAsCsv: 'Exporta datele vizibile ca csv',
  11519. exporterSelectedAsCsv: 'Exporta datele selectate ca csv',
  11520. exporterAllAsPdf: 'Exporta toate datele ca pdf',
  11521. exporterVisibleAsPdf: 'Exporta datele vizibile ca pdf',
  11522. exporterSelectedAsPdf: 'Exporta datele selectate ca csv pdf',
  11523. clearAllFilters: 'Sterge toate filtrele'
  11524. },
  11525. importer: {
  11526. noHeaders: 'Numele coloanelor nu a putut fi incarcat, acest fisier are un header?',
  11527. noObjects: 'Datele nu au putut fi incarcate, exista date in fisier in afara numelor de coloane?',
  11528. invalidCsv: 'Fisierul nu a putut fi procesat, ati incarcat un CSV valid ?',
  11529. invalidJson: 'Fisierul nu a putut fi procesat, ati incarcat un Json valid?',
  11530. jsonNotArray: 'Json-ul incarcat trebuie sa contina un array, inchidere.'
  11531. },
  11532. pagination: {
  11533. aria: {
  11534. pageToFirst: 'Prima pagina',
  11535. pageBack: 'O pagina inapoi',
  11536. pageSelected: 'Pagina selectata',
  11537. pageForward: 'O pagina inainte',
  11538. pageToLast: 'Ultima pagina'
  11539. },
  11540. sizes: 'Elemente per pagina',
  11541. totalItems: 'elemente',
  11542. through: 'prin',
  11543. of: 'of'
  11544. },
  11545. grouping: {
  11546. group: 'Grupeaza',
  11547. ungroup: 'Opreste gruparea',
  11548. aggregate_count: 'Agg: Count',
  11549. aggregate_sum: 'Agg: Sum',
  11550. aggregate_max: 'Agg: Max',
  11551. aggregate_min: 'Agg: Min',
  11552. aggregate_avg: 'Agg: Avg',
  11553. aggregate_remove: 'Agg: Remove'
  11554. }
  11555. });
  11556. return $delegate;
  11557. }]);
  11558. }]);
  11559. })();
  11560. (function () {
  11561. angular.module('ui.grid').config(['$provide', function($provide) {
  11562. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11563. $delegate.add('ru', {
  11564. headerCell: {
  11565. aria: {
  11566. defaultFilterLabel: 'Фильтр столбца',
  11567. removeFilter: 'Удалить фильтр',
  11568. columnMenuButtonLabel: 'Меню столбца'
  11569. },
  11570. priority: 'Приоритет:',
  11571. filterLabel: "Фильтр столбца: "
  11572. },
  11573. aggregate: {
  11574. label: 'элементы'
  11575. },
  11576. groupPanel: {
  11577. description: 'Для группировки по столбцу перетащите сюда его название.'
  11578. },
  11579. search: {
  11580. placeholder: 'Поиск...',
  11581. showingItems: 'Показать элементы:',
  11582. selectedItems: 'Выбранные элементы:',
  11583. totalItems: 'Всего элементов:',
  11584. size: 'Размер страницы:',
  11585. first: 'Первая страница',
  11586. next: 'Следующая страница',
  11587. previous: 'Предыдущая страница',
  11588. last: 'Последняя страница'
  11589. },
  11590. menu: {
  11591. text: 'Выбрать столбцы:'
  11592. },
  11593. sort: {
  11594. ascending: 'По возрастанию',
  11595. descending: 'По убыванию',
  11596. none: 'Без сортировки',
  11597. remove: 'Убрать сортировку'
  11598. },
  11599. column: {
  11600. hide: 'Спрятать столбец'
  11601. },
  11602. aggregation: {
  11603. count: 'всего строк: ',
  11604. sum: 'итого: ',
  11605. avg: 'среднее: ',
  11606. min: 'мин: ',
  11607. max: 'макс: '
  11608. },
  11609. pinning: {
  11610. pinLeft: 'Закрепить слева',
  11611. pinRight: 'Закрепить справа',
  11612. unpin: 'Открепить'
  11613. },
  11614. columnMenu: {
  11615. close: 'Закрыть'
  11616. },
  11617. gridMenu: {
  11618. aria: {
  11619. buttonLabel: 'Меню'
  11620. },
  11621. columns: 'Столбцы:',
  11622. importerTitle: 'Импортировать файл',
  11623. exporterAllAsCsv: 'Экспортировать всё в CSV',
  11624. exporterVisibleAsCsv: 'Экспортировать видимые данные в CSV',
  11625. exporterSelectedAsCsv: 'Экспортировать выбранные данные в CSV',
  11626. exporterAllAsPdf: 'Экспортировать всё в PDF',
  11627. exporterVisibleAsPdf: 'Экспортировать видимые данные в PDF',
  11628. exporterSelectedAsPdf: 'Экспортировать выбранные данные в PDF',
  11629. clearAllFilters: 'Очистите все фильтры'
  11630. },
  11631. importer: {
  11632. noHeaders: 'Не удалось получить названия столбцов, есть ли в файле заголовок?',
  11633. noObjects: 'Не удалось получить данные, есть ли в файле строки кроме заголовка?',
  11634. invalidCsv: 'Не удалось обработать файл, это правильный CSV-файл?',
  11635. invalidJson: 'Не удалось обработать файл, это правильный JSON?',
  11636. jsonNotArray: 'Импортируемый JSON-файл должен содержать массив, операция отменена.'
  11637. },
  11638. pagination: {
  11639. aria: {
  11640. pageToFirst: 'Первая страница',
  11641. pageBack: 'Предыдущая страница',
  11642. pageSelected: 'Выбранная страница',
  11643. pageForward: 'Следующая страница',
  11644. pageToLast: 'Последняя страница'
  11645. },
  11646. sizes: 'строк на страницу',
  11647. totalItems: 'строк',
  11648. through: 'по',
  11649. of: 'из'
  11650. },
  11651. grouping: {
  11652. group: 'Группировать',
  11653. ungroup: 'Разгруппировать',
  11654. aggregate_count: 'Группировать: Count',
  11655. aggregate_sum: 'Для группы: Сумма',
  11656. aggregate_max: 'Для группы: Максимум',
  11657. aggregate_min: 'Для группы: Минимум',
  11658. aggregate_avg: 'Для группы: Среднее',
  11659. aggregate_remove: 'Для группы: Пусто'
  11660. }
  11661. });
  11662. return $delegate;
  11663. }]);
  11664. }]);
  11665. })();
  11666. (function () {
  11667. angular.module('ui.grid').config(['$provide', function($provide) {
  11668. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11669. $delegate.add('sk', {
  11670. aggregate: {
  11671. label: 'items'
  11672. },
  11673. groupPanel: {
  11674. description: 'Pretiahni sem názov stĺpca pre zoskupenie podľa toho stĺpca.'
  11675. },
  11676. search: {
  11677. placeholder: 'Hľadaj...',
  11678. showingItems: 'Zobrazujem položky:',
  11679. selectedItems: 'Vybraté položky:',
  11680. totalItems: 'Počet položiek:',
  11681. size: 'Počet:',
  11682. first: 'Prvá strana',
  11683. next: 'Ďalšia strana',
  11684. previous: 'Predchádzajúca strana',
  11685. last: 'Posledná strana'
  11686. },
  11687. menu: {
  11688. text: 'Vyberte stĺpce:'
  11689. },
  11690. sort: {
  11691. ascending: 'Zotriediť vzostupne',
  11692. descending: 'Zotriediť zostupne',
  11693. remove: 'Vymazať triedenie'
  11694. },
  11695. aggregation: {
  11696. count: 'total rows: ',
  11697. sum: 'total: ',
  11698. avg: 'avg: ',
  11699. min: 'min: ',
  11700. max: 'max: '
  11701. },
  11702. gridMenu: {
  11703. columns: 'Columns:',
  11704. importerTitle: 'Import file',
  11705. exporterAllAsCsv: 'Export all data as csv',
  11706. exporterVisibleAsCsv: 'Export visible data as csv',
  11707. exporterSelectedAsCsv: 'Export selected data as csv',
  11708. exporterAllAsPdf: 'Export all data as pdf',
  11709. exporterVisibleAsPdf: 'Export visible data as pdf',
  11710. exporterSelectedAsPdf: 'Export selected data as pdf',
  11711. clearAllFilters: 'Clear all filters'
  11712. },
  11713. importer: {
  11714. noHeaders: 'Column names were unable to be derived, does the file have a header?',
  11715. noObjects: 'Objects were not able to be derived, was there data in the file other than headers?',
  11716. invalidCsv: 'File was unable to be processed, is it valid CSV?',
  11717. invalidJson: 'File was unable to be processed, is it valid Json?',
  11718. jsonNotArray: 'Imported json file must contain an array, aborting.'
  11719. }
  11720. });
  11721. return $delegate;
  11722. }]);
  11723. }]);
  11724. })();
  11725. (function () {
  11726. angular.module('ui.grid').config(['$provide', function($provide) {
  11727. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11728. $delegate.add('sv', {
  11729. aggregate: {
  11730. label: 'Artiklar'
  11731. },
  11732. groupPanel: {
  11733. description: 'Dra en kolumnrubrik hit och släpp den för att gruppera efter den kolumnen.'
  11734. },
  11735. search: {
  11736. placeholder: 'Sök...',
  11737. showingItems: 'Visar artiklar:',
  11738. selectedItems: 'Valda artiklar:',
  11739. totalItems: 'Antal artiklar:',
  11740. size: 'Sidstorlek:',
  11741. first: 'Första sidan',
  11742. next: 'Nästa sida',
  11743. previous: 'Föregående sida',
  11744. last: 'Sista sidan'
  11745. },
  11746. menu: {
  11747. text: 'Välj kolumner:'
  11748. },
  11749. sort: {
  11750. ascending: 'Sortera stigande',
  11751. descending: 'Sortera fallande',
  11752. remove: 'Inaktivera sortering'
  11753. },
  11754. column: {
  11755. hide: 'Göm kolumn'
  11756. },
  11757. aggregation: {
  11758. count: 'Antal rader: ',
  11759. sum: 'Summa: ',
  11760. avg: 'Genomsnitt: ',
  11761. min: 'Min: ',
  11762. max: 'Max: '
  11763. },
  11764. pinning: {
  11765. pinLeft: 'Fäst vänster',
  11766. pinRight: 'Fäst höger',
  11767. unpin: 'Lösgör'
  11768. },
  11769. gridMenu: {
  11770. columns: 'Kolumner:',
  11771. importerTitle: 'Importera fil',
  11772. exporterAllAsCsv: 'Exportera all data som CSV',
  11773. exporterVisibleAsCsv: 'Exportera synlig data som CSV',
  11774. exporterSelectedAsCsv: 'Exportera markerad data som CSV',
  11775. exporterAllAsPdf: 'Exportera all data som PDF',
  11776. exporterVisibleAsPdf: 'Exportera synlig data som PDF',
  11777. exporterSelectedAsPdf: 'Exportera markerad data som PDF',
  11778. clearAllFilters: 'Rengör alla filter'
  11779. },
  11780. importer: {
  11781. noHeaders: 'Kolumnnamn kunde inte härledas. Har filen ett sidhuvud?',
  11782. noObjects: 'Objekt kunde inte härledas. Har filen data undantaget sidhuvud?',
  11783. invalidCsv: 'Filen kunde inte behandlas, är den en giltig CSV?',
  11784. invalidJson: 'Filen kunde inte behandlas, är den en giltig JSON?',
  11785. jsonNotArray: 'Importerad JSON-fil måste innehålla ett fält. Import avbruten.'
  11786. },
  11787. pagination: {
  11788. sizes: 'Artiklar per sida',
  11789. totalItems: 'Artiklar'
  11790. }
  11791. });
  11792. return $delegate;
  11793. }]);
  11794. }]);
  11795. })();
  11796. (function () {
  11797. angular.module('ui.grid').config(['$provide', function($provide) {
  11798. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11799. $delegate.add('ta', {
  11800. aggregate: {
  11801. label: 'உருப்படிகள்'
  11802. },
  11803. groupPanel: {
  11804. description: 'ஒரு பத்தியை குழுவாக அமைக்க அப்பத்தியின் தலைப்பை இங்கே இழுத்து வரவும் '
  11805. },
  11806. search: {
  11807. placeholder: 'தேடல் ...',
  11808. showingItems: 'உருப்படிகளை காண்பித்தல்:',
  11809. selectedItems: 'தேர்ந்தெடுக்கப்பட்ட உருப்படிகள்:',
  11810. totalItems: 'மொத்த உருப்படிகள்:',
  11811. size: 'பக்க அளவு: ',
  11812. first: 'முதல் பக்கம்',
  11813. next: 'அடுத்த பக்கம்',
  11814. previous: 'முந்தைய பக்கம் ',
  11815. last: 'இறுதி பக்கம்'
  11816. },
  11817. menu: {
  11818. text: 'பத்திகளை தேர்ந்தெடு:'
  11819. },
  11820. sort: {
  11821. ascending: 'மேலிருந்து கீழாக',
  11822. descending: 'கீழிருந்து மேலாக',
  11823. remove: 'வரிசையை நீக்கு'
  11824. },
  11825. column: {
  11826. hide: 'பத்தியை மறைத்து வை '
  11827. },
  11828. aggregation: {
  11829. count: 'மொத்த வரிகள்:',
  11830. sum: 'மொத்தம்: ',
  11831. avg: 'சராசரி: ',
  11832. min: 'குறைந்தபட்ச: ',
  11833. max: 'அதிகபட்ச: '
  11834. },
  11835. pinning: {
  11836. pinLeft: 'இடதுபுறமாக தைக்க ',
  11837. pinRight: 'வலதுபுறமாக தைக்க',
  11838. unpin: 'பிரி'
  11839. },
  11840. gridMenu: {
  11841. columns: 'பத்திகள்:',
  11842. importerTitle: 'கோப்பு : படித்தல்',
  11843. exporterAllAsCsv: 'எல்லா தரவுகளையும் கோப்பாக்கு: csv',
  11844. exporterVisibleAsCsv: 'இருக்கும் தரவுகளை கோப்பாக்கு: csv',
  11845. exporterSelectedAsCsv: 'தேர்ந்தெடுத்த தரவுகளை கோப்பாக்கு: csv',
  11846. exporterAllAsPdf: 'எல்லா தரவுகளையும் கோப்பாக்கு: pdf',
  11847. exporterVisibleAsPdf: 'இருக்கும் தரவுகளை கோப்பாக்கு: pdf',
  11848. exporterSelectedAsPdf: 'தேர்ந்தெடுத்த தரவுகளை கோப்பாக்கு: pdf',
  11849. clearAllFilters: 'Clear all filters'
  11850. },
  11851. importer: {
  11852. noHeaders: 'பத்தியின் தலைப்புகளை பெற இயலவில்லை, கோப்பிற்கு தலைப்பு உள்ளதா?',
  11853. noObjects: 'இலக்குகளை உருவாக்க முடியவில்லை, கோப்பில் தலைப்புகளை தவிர தரவு ஏதேனும் உள்ளதா? ',
  11854. invalidCsv: 'சரிவர நடைமுறை படுத்த இயலவில்லை, கோப்பு சரிதானா? - csv',
  11855. invalidJson: 'சரிவர நடைமுறை படுத்த இயலவில்லை, கோப்பு சரிதானா? - json',
  11856. jsonNotArray: 'படித்த கோப்பில் வரிசைகள் உள்ளது, நடைமுறை ரத்து செய் : json'
  11857. },
  11858. pagination: {
  11859. sizes : 'உருப்படிகள் / பக்கம்',
  11860. totalItems : 'உருப்படிகள் '
  11861. },
  11862. grouping: {
  11863. group : 'குழு',
  11864. ungroup : 'பிரி',
  11865. aggregate_count : 'மதிப்பீட்டு : எண்ணு',
  11866. aggregate_sum : 'மதிப்பீட்டு : கூட்டல்',
  11867. aggregate_max : 'மதிப்பீட்டு : அதிகபட்சம்',
  11868. aggregate_min : 'மதிப்பீட்டு : குறைந்தபட்சம்',
  11869. aggregate_avg : 'மதிப்பீட்டு : சராசரி',
  11870. aggregate_remove : 'மதிப்பீட்டு : நீக்கு'
  11871. }
  11872. });
  11873. return $delegate;
  11874. }]);
  11875. }]);
  11876. })();
  11877. (function () {
  11878. angular.module('ui.grid').config(['$provide', function($provide) {
  11879. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11880. $delegate.add('tr', {
  11881. headerCell: {
  11882. aria: {
  11883. defaultFilterLabel: 'Sütun için filtre',
  11884. removeFilter: 'Filtreyi Kaldır',
  11885. columnMenuButtonLabel: 'Sütun Menüsü'
  11886. },
  11887. priority: 'Öncelik:',
  11888. filterLabel: "Sütun için filtre: "
  11889. },
  11890. aggregate: {
  11891. label: 'kayıtlar'
  11892. },
  11893. groupPanel: {
  11894. description: 'Sütuna göre gruplamak için sütun başlığını buraya sürükleyin ve bırakın.'
  11895. },
  11896. search: {
  11897. placeholder: 'Arama...',
  11898. showingItems: 'Gösterilen Kayıt:',
  11899. selectedItems: 'Seçili Kayıt:',
  11900. totalItems: 'Toplam Kayıt:',
  11901. size: 'Sayfa Boyutu:',
  11902. first: 'İlk Sayfa',
  11903. next: 'Sonraki Sayfa',
  11904. previous: 'Önceki Sayfa',
  11905. last: 'Son Sayfa'
  11906. },
  11907. menu: {
  11908. text: 'Sütunları Seç:'
  11909. },
  11910. sort: {
  11911. ascending: 'Artan Sırada Sırala',
  11912. descending: 'Azalan Sırada Sırala',
  11913. none: 'Sıralama Yapma',
  11914. remove: 'Sıralamayı Kaldır'
  11915. },
  11916. column: {
  11917. hide: 'Sütunu Gizle'
  11918. },
  11919. aggregation: {
  11920. count: 'toplam satır: ',
  11921. sum: 'toplam: ',
  11922. avg: 'ort: ',
  11923. min: 'min: ',
  11924. max: 'maks: '
  11925. },
  11926. pinning: {
  11927. pinLeft: 'Sola Sabitle',
  11928. pinRight: 'Sağa Sabitle',
  11929. unpin: 'Sabitlemeyi Kaldır'
  11930. },
  11931. columnMenu: {
  11932. close: 'Kapat'
  11933. },
  11934. gridMenu: {
  11935. aria: {
  11936. buttonLabel: 'Tablo Menü'
  11937. },
  11938. columns: 'Sütunlar:',
  11939. importerTitle: 'Dosya içeri aktar',
  11940. exporterAllAsCsv: 'Bütün veriyi CSV olarak dışarı aktar',
  11941. exporterVisibleAsCsv: 'Görünen veriyi CSV olarak dışarı aktar',
  11942. exporterSelectedAsCsv: 'Seçili veriyi CSV olarak dışarı aktar',
  11943. exporterAllAsPdf: 'Bütün veriyi PDF olarak dışarı aktar',
  11944. exporterVisibleAsPdf: 'Görünen veriyi PDF olarak dışarı aktar',
  11945. exporterSelectedAsPdf: 'Seçili veriyi PDF olarak dışarı aktar',
  11946. clearAllFilters: 'Bütün filtreleri kaldır'
  11947. },
  11948. importer: {
  11949. noHeaders: 'Sütun isimleri üretilemiyor, dosyanın bir başlığı var mı?',
  11950. noObjects: 'Nesneler üretilemiyor, dosyada başlıktan başka bir veri var mı?',
  11951. invalidCsv: 'Dosya işlenemedi, geçerli bir CSV dosyası mı?',
  11952. invalidJson: 'Dosya işlenemedi, geçerli bir Json dosyası mı?',
  11953. jsonNotArray: 'Alınan Json dosyasında bir dizi bulunmalıdır, işlem iptal ediliyor.'
  11954. },
  11955. pagination: {
  11956. aria: {
  11957. pageToFirst: 'İlk sayfaya',
  11958. pageBack: 'Geri git',
  11959. pageSelected: 'Seçili sayfa',
  11960. pageForward: 'İleri git',
  11961. pageToLast: 'Sona git'
  11962. },
  11963. sizes: 'Sayfadaki nesne sayısı',
  11964. totalItems: 'kayıtlar',
  11965. through: '', //note(fsw) : turkish dont have this preposition
  11966. of: '' //note(fsw) : turkish dont have this preposition
  11967. },
  11968. grouping: {
  11969. group: 'Grupla',
  11970. ungroup: 'Gruplama',
  11971. aggregate_count: 'Yekun: Sayı',
  11972. aggregate_sum: 'Yekun: Toplam',
  11973. aggregate_max: 'Yekun: Maks',
  11974. aggregate_min: 'Yekun: Min',
  11975. aggregate_avg: 'Yekun: Ort',
  11976. aggregate_remove: 'Yekun: Sil'
  11977. }
  11978. });
  11979. return $delegate;
  11980. }]);
  11981. }]);
  11982. })();
  11983. /**
  11984. * @ngdoc overview
  11985. * @name ui.grid.i18n
  11986. * @description
  11987. *
  11988. * # ui.grid.i18n
  11989. * This module provides i18n functions to ui.grid and any application that wants to use it
  11990. *
  11991. * <div doc-module-components="ui.grid.i18n"></div>
  11992. */
  11993. (function () {
  11994. var DIRECTIVE_ALIASES = ['uiT', 'uiTranslate'];
  11995. var FILTER_ALIASES = ['t', 'uiTranslate'];
  11996. var module = angular.module('ui.grid.i18n');
  11997. /**
  11998. * @ngdoc object
  11999. * @name ui.grid.i18n.constant:i18nConstants
  12000. *
  12001. * @description constants available in i18n module
  12002. */
  12003. module.constant('i18nConstants', {
  12004. MISSING: '[MISSING]',
  12005. UPDATE_EVENT: '$uiI18n',
  12006. LOCALE_DIRECTIVE_ALIAS: 'uiI18n',
  12007. // default to english
  12008. DEFAULT_LANG: 'en'
  12009. });
  12010. // module.config(['$provide', function($provide) {
  12011. // $provide.decorator('i18nService', ['$delegate', function($delegate) {}])}]);
  12012. /**
  12013. * @ngdoc service
  12014. * @name ui.grid.i18n.service:i18nService
  12015. *
  12016. * @description Services for i18n
  12017. */
  12018. module.service('i18nService', ['$log', 'i18nConstants', '$rootScope',
  12019. function ($log, i18nConstants, $rootScope) {
  12020. var langCache = {
  12021. _langs: {},
  12022. current: null,
  12023. get: function (lang) {
  12024. return this._langs[lang.toLowerCase()];
  12025. },
  12026. add: function (lang, strings) {
  12027. var lower = lang.toLowerCase();
  12028. if (!this._langs[lower]) {
  12029. this._langs[lower] = {};
  12030. }
  12031. angular.extend(this._langs[lower], strings);
  12032. },
  12033. getAllLangs: function () {
  12034. var langs = [];
  12035. if (!this._langs) {
  12036. return langs;
  12037. }
  12038. for (var key in this._langs) {
  12039. langs.push(key);
  12040. }
  12041. return langs;
  12042. },
  12043. setCurrent: function (lang) {
  12044. this.current = lang.toLowerCase();
  12045. },
  12046. getCurrentLang: function () {
  12047. return this.current;
  12048. }
  12049. };
  12050. var service = {
  12051. /**
  12052. * @ngdoc service
  12053. * @name add
  12054. * @methodOf ui.grid.i18n.service:i18nService
  12055. * @description Adds the languages and strings to the cache. Decorate this service to
  12056. * add more translation strings
  12057. * @param {string} lang language to add
  12058. * @param {object} stringMaps of strings to add grouped by property names
  12059. * @example
  12060. * <pre>
  12061. * i18nService.add('en', {
  12062. * aggregate: {
  12063. * label1: 'items',
  12064. * label2: 'some more items'
  12065. * }
  12066. * },
  12067. * groupPanel: {
  12068. * description: 'Drag a column header here and drop it to group by that column.'
  12069. * }
  12070. * }
  12071. * </pre>
  12072. */
  12073. add: function (langs, stringMaps) {
  12074. if (typeof(langs) === 'object') {
  12075. angular.forEach(langs, function (lang) {
  12076. if (lang) {
  12077. langCache.add(lang, stringMaps);
  12078. }
  12079. });
  12080. } else {
  12081. langCache.add(langs, stringMaps);
  12082. }
  12083. },
  12084. /**
  12085. * @ngdoc service
  12086. * @name getAllLangs
  12087. * @methodOf ui.grid.i18n.service:i18nService
  12088. * @description return all currently loaded languages
  12089. * @returns {array} string
  12090. */
  12091. getAllLangs: function () {
  12092. return langCache.getAllLangs();
  12093. },
  12094. /**
  12095. * @ngdoc service
  12096. * @name get
  12097. * @methodOf ui.grid.i18n.service:i18nService
  12098. * @description return all currently loaded languages
  12099. * @param {string} lang to return. If not specified, returns current language
  12100. * @returns {object} the translation string maps for the language
  12101. */
  12102. get: function (lang) {
  12103. var language = lang ? lang : service.getCurrentLang();
  12104. return langCache.get(language);
  12105. },
  12106. /**
  12107. * @ngdoc service
  12108. * @name getSafeText
  12109. * @methodOf ui.grid.i18n.service:i18nService
  12110. * @description returns the text specified in the path or a Missing text if text is not found
  12111. * @param {string} path property path to use for retrieving text from string map
  12112. * @param {string} lang to return. If not specified, returns current language
  12113. * @returns {object} the translation for the path
  12114. * @example
  12115. * <pre>
  12116. * i18nService.getSafeText('sort.ascending')
  12117. * </pre>
  12118. */
  12119. getSafeText: function (path, lang) {
  12120. var language = lang ? lang : service.getCurrentLang();
  12121. var trans = langCache.get(language);
  12122. if (!trans) {
  12123. return i18nConstants.MISSING;
  12124. }
  12125. var paths = path.split('.');
  12126. var current = trans;
  12127. for (var i = 0; i < paths.length; ++i) {
  12128. if (current[paths[i]] === undefined || current[paths[i]] === null) {
  12129. return i18nConstants.MISSING;
  12130. } else {
  12131. current = current[paths[i]];
  12132. }
  12133. }
  12134. return current;
  12135. },
  12136. /**
  12137. * @ngdoc service
  12138. * @name setCurrentLang
  12139. * @methodOf ui.grid.i18n.service:i18nService
  12140. * @description sets the current language to use in the application
  12141. * $broadcasts the Update_Event on the $rootScope
  12142. * @param {string} lang to set
  12143. * @example
  12144. * <pre>
  12145. * i18nService.setCurrentLang('fr');
  12146. * </pre>
  12147. */
  12148. setCurrentLang: function (lang) {
  12149. if (lang) {
  12150. langCache.setCurrent(lang);
  12151. $rootScope.$broadcast(i18nConstants.UPDATE_EVENT);
  12152. }
  12153. },
  12154. /**
  12155. * @ngdoc service
  12156. * @name getCurrentLang
  12157. * @methodOf ui.grid.i18n.service:i18nService
  12158. * @description returns the current language used in the application
  12159. */
  12160. getCurrentLang: function () {
  12161. var lang = langCache.getCurrentLang();
  12162. if (!lang) {
  12163. lang = i18nConstants.DEFAULT_LANG;
  12164. langCache.setCurrent(lang);
  12165. }
  12166. return lang;
  12167. }
  12168. };
  12169. return service;
  12170. }]);
  12171. var localeDirective = function (i18nService, i18nConstants) {
  12172. return {
  12173. compile: function () {
  12174. return {
  12175. pre: function ($scope, $elm, $attrs) {
  12176. var alias = i18nConstants.LOCALE_DIRECTIVE_ALIAS;
  12177. // check for watchable property
  12178. var lang = $scope.$eval($attrs[alias]);
  12179. if (lang) {
  12180. $scope.$watch($attrs[alias], function () {
  12181. i18nService.setCurrentLang(lang);
  12182. });
  12183. } else if ($attrs.$$observers) {
  12184. $attrs.$observe(alias, function () {
  12185. i18nService.setCurrentLang($attrs[alias] || i18nConstants.DEFAULT_LANG);
  12186. });
  12187. }
  12188. }
  12189. };
  12190. }
  12191. };
  12192. };
  12193. module.directive('uiI18n', ['i18nService', 'i18nConstants', localeDirective]);
  12194. // directive syntax
  12195. var uitDirective = function ($parse, i18nService, i18nConstants) {
  12196. return {
  12197. restrict: 'EA',
  12198. compile: function () {
  12199. return {
  12200. pre: function ($scope, $elm, $attrs) {
  12201. var alias1 = DIRECTIVE_ALIASES[0],
  12202. alias2 = DIRECTIVE_ALIASES[1];
  12203. var token = $attrs[alias1] || $attrs[alias2] || $elm.html();
  12204. var missing = i18nConstants.MISSING + token;
  12205. var observer;
  12206. if ($attrs.$$observers) {
  12207. var prop = $attrs[alias1] ? alias1 : alias2;
  12208. observer = $attrs.$observe(prop, function (result) {
  12209. if (result) {
  12210. $elm.html($parse(result)(i18nService.getCurrentLang()) || missing);
  12211. }
  12212. });
  12213. }
  12214. var getter = $parse(token);
  12215. var listener = $scope.$on(i18nConstants.UPDATE_EVENT, function (evt) {
  12216. if (observer) {
  12217. observer($attrs[alias1] || $attrs[alias2]);
  12218. } else {
  12219. // set text based on i18n current language
  12220. $elm.html(getter(i18nService.get()) || missing);
  12221. }
  12222. });
  12223. $scope.$on('$destroy', listener);
  12224. $elm.html(getter(i18nService.get()) || missing);
  12225. }
  12226. };
  12227. }
  12228. };
  12229. };
  12230. angular.forEach( DIRECTIVE_ALIASES, function ( alias ) {
  12231. module.directive( alias, ['$parse', 'i18nService', 'i18nConstants', uitDirective] );
  12232. } );
  12233. // optional filter syntax
  12234. var uitFilter = function ($parse, i18nService, i18nConstants) {
  12235. return function (data) {
  12236. var getter = $parse(data);
  12237. // set text based on i18n current language
  12238. return getter(i18nService.get()) || i18nConstants.MISSING + data;
  12239. };
  12240. };
  12241. angular.forEach( FILTER_ALIASES, function ( alias ) {
  12242. module.filter( alias, ['$parse', 'i18nService', 'i18nConstants', uitFilter] );
  12243. } );
  12244. })();
  12245. (function() {
  12246. angular.module('ui.grid').config(['$provide', function($provide) {
  12247. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  12248. $delegate.add('zh-cn', {
  12249. headerCell: {
  12250. aria: {
  12251. defaultFilterLabel: '列过滤器',
  12252. removeFilter: '移除过滤器',
  12253. columnMenuButtonLabel: '列菜单'
  12254. },
  12255. priority: '优先级:',
  12256. filterLabel: "列过滤器: "
  12257. },
  12258. aggregate: {
  12259. label: '行'
  12260. },
  12261. groupPanel: {
  12262. description: '拖曳表头到此处进行分组'
  12263. },
  12264. search: {
  12265. placeholder: '查找',
  12266. showingItems: '已显示行数:',
  12267. selectedItems: '已选择行数:',
  12268. totalItems: '总行数:',
  12269. size: '每页显示行数:',
  12270. first: '首页',
  12271. next: '下一页',
  12272. previous: '上一页',
  12273. last: '末页'
  12274. },
  12275. menu: {
  12276. text: '选择列:'
  12277. },
  12278. sort: {
  12279. ascending: '升序',
  12280. descending: '降序',
  12281. none: '无序',
  12282. remove: '取消排序'
  12283. },
  12284. column: {
  12285. hide: '隐藏列'
  12286. },
  12287. aggregation: {
  12288. count: '计数:',
  12289. sum: '求和:',
  12290. avg: '均值:',
  12291. min: '最小值:',
  12292. max: '最大值:'
  12293. },
  12294. pinning: {
  12295. pinLeft: '左侧固定',
  12296. pinRight: '右侧固定',
  12297. unpin: '取消固定'
  12298. },
  12299. columnMenu: {
  12300. close: '关闭'
  12301. },
  12302. gridMenu: {
  12303. aria: {
  12304. buttonLabel: '表格菜单'
  12305. },
  12306. columns: '列:',
  12307. importerTitle: '导入文件',
  12308. exporterAllAsCsv: '导出全部数据到CSV',
  12309. exporterVisibleAsCsv: '导出可见数据到CSV',
  12310. exporterSelectedAsCsv: '导出已选数据到CSV',
  12311. exporterAllAsPdf: '导出全部数据到PDF',
  12312. exporterVisibleAsPdf: '导出可见数据到PDF',
  12313. exporterSelectedAsPdf: '导出已选数据到PDF',
  12314. clearAllFilters: '清除所有过滤器'
  12315. },
  12316. importer: {
  12317. noHeaders: '无法获取列名,确定文件包含表头?',
  12318. noObjects: '无法获取数据,确定文件包含数据?',
  12319. invalidCsv: '无法处理文件,确定是合法的CSV文件?',
  12320. invalidJson: '无法处理文件,确定是合法的JSON文件?',
  12321. jsonNotArray: '导入的文件不是JSON数组!'
  12322. },
  12323. pagination: {
  12324. aria: {
  12325. pageToFirst: '第一页',
  12326. pageBack: '上一页',
  12327. pageSelected: '当前页',
  12328. pageForward: '下一页',
  12329. pageToLast: '最后一页'
  12330. },
  12331. sizes: '行每页',
  12332. totalItems: '行',
  12333. through: '至',
  12334. of: '共'
  12335. },
  12336. grouping: {
  12337. group: '分组',
  12338. ungroup: '取消分组',
  12339. aggregate_count: '合计: 计数',
  12340. aggregate_sum: '合计: 求和',
  12341. aggregate_max: '合计: 最大',
  12342. aggregate_min: '合计: 最小',
  12343. aggregate_avg: '合计: 平均',
  12344. aggregate_remove: '合计: 移除'
  12345. }
  12346. });
  12347. return $delegate;
  12348. }]);
  12349. }]);
  12350. })();
  12351. (function() {
  12352. angular.module('ui.grid').config(['$provide', function($provide) {
  12353. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  12354. $delegate.add('zh-tw', {
  12355. aggregate: {
  12356. label: '行'
  12357. },
  12358. groupPanel: {
  12359. description: '拖曳表頭到此處進行分組'
  12360. },
  12361. search: {
  12362. placeholder: '查找',
  12363. showingItems: '已顯示行數:',
  12364. selectedItems: '已選擇行數:',
  12365. totalItems: '總行數:',
  12366. size: '每頁顯示行數:',
  12367. first: '首頁',
  12368. next: '下壹頁',
  12369. previous: '上壹頁',
  12370. last: '末頁'
  12371. },
  12372. menu: {
  12373. text: '選擇列:'
  12374. },
  12375. sort: {
  12376. ascending: '升序',
  12377. descending: '降序',
  12378. remove: '取消排序'
  12379. },
  12380. column: {
  12381. hide: '隱藏列'
  12382. },
  12383. aggregation: {
  12384. count: '計數:',
  12385. sum: '求和:',
  12386. avg: '均值:',
  12387. min: '最小值:',
  12388. max: '最大值:'
  12389. },
  12390. pinning: {
  12391. pinLeft: '左側固定',
  12392. pinRight: '右側固定',
  12393. unpin: '取消固定'
  12394. },
  12395. gridMenu: {
  12396. columns: '列:',
  12397. importerTitle: '導入文件',
  12398. exporterAllAsCsv: '導出全部數據到CSV',
  12399. exporterVisibleAsCsv: '導出可見數據到CSV',
  12400. exporterSelectedAsCsv: '導出已選數據到CSV',
  12401. exporterAllAsPdf: '導出全部數據到PDF',
  12402. exporterVisibleAsPdf: '導出可見數據到PDF',
  12403. exporterSelectedAsPdf: '導出已選數據到PDF',
  12404. clearAllFilters: '清除所有过滤器'
  12405. },
  12406. importer: {
  12407. noHeaders: '無法獲取列名,確定文件包含表頭?',
  12408. noObjects: '無法獲取數據,確定文件包含數據?',
  12409. invalidCsv: '無法處理文件,確定是合法的CSV文件?',
  12410. invalidJson: '無法處理文件,確定是合法的JSON文件?',
  12411. jsonNotArray: '導入的文件不是JSON數組!'
  12412. },
  12413. pagination: {
  12414. sizes: '行每頁',
  12415. totalItems: '行'
  12416. }
  12417. });
  12418. return $delegate;
  12419. }]);
  12420. }]);
  12421. })();
  12422. (function() {
  12423. 'use strict';
  12424. /**
  12425. * @ngdoc overview
  12426. * @name ui.grid.autoResize
  12427. *
  12428. * @description
  12429. *
  12430. * #ui.grid.autoResize
  12431. *
  12432. * <div class="alert alert-warning" role="alert"><strong>Beta</strong> This feature is ready for testing, but it either hasn't seen a lot of use or has some known bugs.</div>
  12433. *
  12434. * This module provides auto-resizing functionality to UI-Grid.
  12435. */
  12436. var module = angular.module('ui.grid.autoResize', ['ui.grid']);
  12437. module.directive('uiGridAutoResize', ['$timeout', 'gridUtil', function ($timeout, gridUtil) {
  12438. return {
  12439. require: 'uiGrid',
  12440. scope: false,
  12441. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  12442. var prevGridWidth, prevGridHeight;
  12443. function getDimensions() {
  12444. prevGridHeight = gridUtil.elementHeight($elm);
  12445. prevGridWidth = gridUtil.elementWidth($elm);
  12446. }
  12447. // Initialize the dimensions
  12448. getDimensions();
  12449. var resizeTimeoutId;
  12450. function startTimeout() {
  12451. clearTimeout(resizeTimeoutId);
  12452. resizeTimeoutId = setTimeout(function () {
  12453. var newGridHeight = gridUtil.elementHeight($elm);
  12454. var newGridWidth = gridUtil.elementWidth($elm);
  12455. if (newGridHeight !== prevGridHeight || newGridWidth !== prevGridWidth) {
  12456. uiGridCtrl.grid.gridHeight = newGridHeight;
  12457. uiGridCtrl.grid.gridWidth = newGridWidth;
  12458. $scope.$apply(function () {
  12459. uiGridCtrl.grid.refresh()
  12460. .then(function () {
  12461. getDimensions();
  12462. startTimeout();
  12463. });
  12464. });
  12465. }
  12466. else {
  12467. startTimeout();
  12468. }
  12469. }, 250);
  12470. }
  12471. startTimeout();
  12472. $scope.$on('$destroy', function() {
  12473. clearTimeout(resizeTimeoutId);
  12474. });
  12475. }
  12476. };
  12477. }]);
  12478. })();
  12479. (function () {
  12480. 'use strict';
  12481. /**
  12482. * @ngdoc overview
  12483. * @name ui.grid.cellNav
  12484. *
  12485. * @description
  12486. #ui.grid.cellNav
  12487. <div class="alert alert-success" role="alert"><strong>Stable</strong> This feature is stable. There should no longer be breaking api changes without a deprecation warning.</div>
  12488. This module provides auto-resizing functionality to UI-Grid.
  12489. */
  12490. var module = angular.module('ui.grid.cellNav', ['ui.grid']);
  12491. /**
  12492. * @ngdoc object
  12493. * @name ui.grid.cellNav.constant:uiGridCellNavConstants
  12494. *
  12495. * @description constants available in cellNav
  12496. */
  12497. module.constant('uiGridCellNavConstants', {
  12498. FEATURE_NAME: 'gridCellNav',
  12499. CELL_NAV_EVENT: 'cellNav',
  12500. direction: {LEFT: 0, RIGHT: 1, UP: 2, DOWN: 3, PG_UP: 4, PG_DOWN: 5},
  12501. EVENT_TYPE: {
  12502. KEYDOWN: 0,
  12503. CLICK: 1,
  12504. CLEAR: 2
  12505. }
  12506. });
  12507. module.factory('uiGridCellNavFactory', ['gridUtil', 'uiGridConstants', 'uiGridCellNavConstants', 'GridRowColumn', '$q',
  12508. function (gridUtil, uiGridConstants, uiGridCellNavConstants, GridRowColumn, $q) {
  12509. /**
  12510. * @ngdoc object
  12511. * @name ui.grid.cellNav.object:CellNav
  12512. * @description returns a CellNav prototype function
  12513. * @param {object} rowContainer container for rows
  12514. * @param {object} colContainer parent column container
  12515. * @param {object} leftColContainer column container to the left of parent
  12516. * @param {object} rightColContainer column container to the right of parent
  12517. */
  12518. var UiGridCellNav = function UiGridCellNav(rowContainer, colContainer, leftColContainer, rightColContainer) {
  12519. this.rows = rowContainer.visibleRowCache;
  12520. this.columns = colContainer.visibleColumnCache;
  12521. this.leftColumns = leftColContainer ? leftColContainer.visibleColumnCache : [];
  12522. this.rightColumns = rightColContainer ? rightColContainer.visibleColumnCache : [];
  12523. this.bodyContainer = rowContainer;
  12524. };
  12525. /** returns focusable columns of all containers */
  12526. UiGridCellNav.prototype.getFocusableCols = function () {
  12527. var allColumns = this.leftColumns.concat(this.columns, this.rightColumns);
  12528. return allColumns.filter(function (col) {
  12529. return col.colDef.allowCellFocus;
  12530. });
  12531. };
  12532. /**
  12533. * @ngdoc object
  12534. * @name ui.grid.cellNav.api:GridRow
  12535. *
  12536. * @description GridRow settings for cellNav feature, these are available to be
  12537. * set only internally (for example, by other features)
  12538. */
  12539. /**
  12540. * @ngdoc object
  12541. * @name allowCellFocus
  12542. * @propertyOf ui.grid.cellNav.api:GridRow
  12543. * @description Enable focus on a cell within this row. If set to false then no cells
  12544. * in this row can be focused - group header rows as an example would set this to false.
  12545. * <br/>Defaults to true
  12546. */
  12547. /** returns focusable rows */
  12548. UiGridCellNav.prototype.getFocusableRows = function () {
  12549. return this.rows.filter(function(row) {
  12550. return row.allowCellFocus !== false;
  12551. });
  12552. };
  12553. UiGridCellNav.prototype.getNextRowCol = function (direction, curRow, curCol) {
  12554. switch (direction) {
  12555. case uiGridCellNavConstants.direction.LEFT:
  12556. return this.getRowColLeft(curRow, curCol);
  12557. case uiGridCellNavConstants.direction.RIGHT:
  12558. return this.getRowColRight(curRow, curCol);
  12559. case uiGridCellNavConstants.direction.UP:
  12560. return this.getRowColUp(curRow, curCol);
  12561. case uiGridCellNavConstants.direction.DOWN:
  12562. return this.getRowColDown(curRow, curCol);
  12563. case uiGridCellNavConstants.direction.PG_UP:
  12564. return this.getRowColPageUp(curRow, curCol);
  12565. case uiGridCellNavConstants.direction.PG_DOWN:
  12566. return this.getRowColPageDown(curRow, curCol);
  12567. }
  12568. };
  12569. UiGridCellNav.prototype.initializeSelection = function () {
  12570. var focusableCols = this.getFocusableCols();
  12571. var focusableRows = this.getFocusableRows();
  12572. if (focusableCols.length === 0 || focusableRows.length === 0) {
  12573. return null;
  12574. }
  12575. var curRowIndex = 0;
  12576. var curColIndex = 0;
  12577. return new GridRowColumn(focusableRows[0], focusableCols[0]); //return same row
  12578. };
  12579. UiGridCellNav.prototype.getRowColLeft = function (curRow, curCol) {
  12580. var focusableCols = this.getFocusableCols();
  12581. var focusableRows = this.getFocusableRows();
  12582. var curColIndex = focusableCols.indexOf(curCol);
  12583. var curRowIndex = focusableRows.indexOf(curRow);
  12584. //could not find column in focusable Columns so set it to 1
  12585. if (curColIndex === -1) {
  12586. curColIndex = 1;
  12587. }
  12588. var nextColIndex = curColIndex === 0 ? focusableCols.length - 1 : curColIndex - 1;
  12589. //get column to left
  12590. if (nextColIndex > curColIndex) {
  12591. // On the first row
  12592. // if (curRowIndex === 0 && curColIndex === 0) {
  12593. // return null;
  12594. // }
  12595. if (curRowIndex === 0) {
  12596. return new GridRowColumn(curRow, focusableCols[nextColIndex]); //return same row
  12597. }
  12598. else {
  12599. //up one row and far right column
  12600. return new GridRowColumn(focusableRows[curRowIndex - 1], focusableCols[nextColIndex]);
  12601. }
  12602. }
  12603. else {
  12604. return new GridRowColumn(curRow, focusableCols[nextColIndex]);
  12605. }
  12606. };
  12607. UiGridCellNav.prototype.getRowColRight = function (curRow, curCol) {
  12608. var focusableCols = this.getFocusableCols();
  12609. var focusableRows = this.getFocusableRows();
  12610. var curColIndex = focusableCols.indexOf(curCol);
  12611. var curRowIndex = focusableRows.indexOf(curRow);
  12612. //could not find column in focusable Columns so set it to 0
  12613. if (curColIndex === -1) {
  12614. curColIndex = 0;
  12615. }
  12616. var nextColIndex = curColIndex === focusableCols.length - 1 ? 0 : curColIndex + 1;
  12617. if (nextColIndex < curColIndex) {
  12618. if (curRowIndex === focusableRows.length - 1) {
  12619. return new GridRowColumn(curRow, focusableCols[nextColIndex]); //return same row
  12620. }
  12621. else {
  12622. //down one row and far left column
  12623. return new GridRowColumn(focusableRows[curRowIndex + 1], focusableCols[nextColIndex]);
  12624. }
  12625. }
  12626. else {
  12627. return new GridRowColumn(curRow, focusableCols[nextColIndex]);
  12628. }
  12629. };
  12630. UiGridCellNav.prototype.getRowColDown = function (curRow, curCol) {
  12631. var focusableCols = this.getFocusableCols();
  12632. var focusableRows = this.getFocusableRows();
  12633. var curColIndex = focusableCols.indexOf(curCol);
  12634. var curRowIndex = focusableRows.indexOf(curRow);
  12635. //could not find column in focusable Columns so set it to 0
  12636. if (curColIndex === -1) {
  12637. curColIndex = 0;
  12638. }
  12639. if (curRowIndex === focusableRows.length - 1) {
  12640. return new GridRowColumn(curRow, focusableCols[curColIndex]); //return same row
  12641. }
  12642. else {
  12643. //down one row
  12644. return new GridRowColumn(focusableRows[curRowIndex + 1], focusableCols[curColIndex]);
  12645. }
  12646. };
  12647. UiGridCellNav.prototype.getRowColPageDown = function (curRow, curCol) {
  12648. var focusableCols = this.getFocusableCols();
  12649. var focusableRows = this.getFocusableRows();
  12650. var curColIndex = focusableCols.indexOf(curCol);
  12651. var curRowIndex = focusableRows.indexOf(curRow);
  12652. //could not find column in focusable Columns so set it to 0
  12653. if (curColIndex === -1) {
  12654. curColIndex = 0;
  12655. }
  12656. var pageSize = this.bodyContainer.minRowsToRender();
  12657. if (curRowIndex >= focusableRows.length - pageSize) {
  12658. return new GridRowColumn(focusableRows[focusableRows.length - 1], focusableCols[curColIndex]); //return last row
  12659. }
  12660. else {
  12661. //down one page
  12662. return new GridRowColumn(focusableRows[curRowIndex + pageSize], focusableCols[curColIndex]);
  12663. }
  12664. };
  12665. UiGridCellNav.prototype.getRowColUp = function (curRow, curCol) {
  12666. var focusableCols = this.getFocusableCols();
  12667. var focusableRows = this.getFocusableRows();
  12668. var curColIndex = focusableCols.indexOf(curCol);
  12669. var curRowIndex = focusableRows.indexOf(curRow);
  12670. //could not find column in focusable Columns so set it to 0
  12671. if (curColIndex === -1) {
  12672. curColIndex = 0;
  12673. }
  12674. if (curRowIndex === 0) {
  12675. return new GridRowColumn(curRow, focusableCols[curColIndex]); //return same row
  12676. }
  12677. else {
  12678. //up one row
  12679. return new GridRowColumn(focusableRows[curRowIndex - 1], focusableCols[curColIndex]);
  12680. }
  12681. };
  12682. UiGridCellNav.prototype.getRowColPageUp = function (curRow, curCol) {
  12683. var focusableCols = this.getFocusableCols();
  12684. var focusableRows = this.getFocusableRows();
  12685. var curColIndex = focusableCols.indexOf(curCol);
  12686. var curRowIndex = focusableRows.indexOf(curRow);
  12687. //could not find column in focusable Columns so set it to 0
  12688. if (curColIndex === -1) {
  12689. curColIndex = 0;
  12690. }
  12691. var pageSize = this.bodyContainer.minRowsToRender();
  12692. if (curRowIndex - pageSize < 0) {
  12693. return new GridRowColumn(focusableRows[0], focusableCols[curColIndex]); //return first row
  12694. }
  12695. else {
  12696. //up one page
  12697. return new GridRowColumn(focusableRows[curRowIndex - pageSize], focusableCols[curColIndex]);
  12698. }
  12699. };
  12700. return UiGridCellNav;
  12701. }]);
  12702. /**
  12703. * @ngdoc service
  12704. * @name ui.grid.cellNav.service:uiGridCellNavService
  12705. *
  12706. * @description Services for cell navigation features. If you don't like the key maps we use,
  12707. * or the direction cells navigation, override with a service decorator (see angular docs)
  12708. */
  12709. module.service('uiGridCellNavService', ['gridUtil', 'uiGridConstants', 'uiGridCellNavConstants', '$q', 'uiGridCellNavFactory', 'GridRowColumn', 'ScrollEvent',
  12710. function (gridUtil, uiGridConstants, uiGridCellNavConstants, $q, UiGridCellNav, GridRowColumn, ScrollEvent) {
  12711. var service = {
  12712. initializeGrid: function (grid) {
  12713. grid.registerColumnBuilder(service.cellNavColumnBuilder);
  12714. /**
  12715. * @ngdoc object
  12716. * @name ui.grid.cellNav:Grid.cellNav
  12717. * @description cellNav properties added to grid class
  12718. */
  12719. grid.cellNav = {};
  12720. grid.cellNav.lastRowCol = null;
  12721. grid.cellNav.focusedCells = [];
  12722. service.defaultGridOptions(grid.options);
  12723. /**
  12724. * @ngdoc object
  12725. * @name ui.grid.cellNav.api:PublicApi
  12726. *
  12727. * @description Public Api for cellNav feature
  12728. */
  12729. var publicApi = {
  12730. events: {
  12731. cellNav: {
  12732. /**
  12733. * @ngdoc event
  12734. * @name navigate
  12735. * @eventOf ui.grid.cellNav.api:PublicApi
  12736. * @description raised when the active cell is changed
  12737. * <pre>
  12738. * gridApi.cellNav.on.navigate(scope,function(newRowcol, oldRowCol){})
  12739. * </pre>
  12740. * @param {object} newRowCol new position
  12741. * @param {object} oldRowCol old position
  12742. */
  12743. navigate: function (newRowCol, oldRowCol) {},
  12744. /**
  12745. * @ngdoc event
  12746. * @name viewPortKeyDown
  12747. * @eventOf ui.grid.cellNav.api:PublicApi
  12748. * @description is raised when the viewPort receives a keyDown event. Cells never get focus in uiGrid
  12749. * due to the difficulties of setting focus on a cell that is not visible in the viewport. Use this
  12750. * event whenever you need a keydown event on a cell
  12751. * <br/>
  12752. * @param {object} event keydown event
  12753. * @param {object} rowCol current rowCol position
  12754. */
  12755. viewPortKeyDown: function (event, rowCol) {},
  12756. /**
  12757. * @ngdoc event
  12758. * @name viewPortKeyPress
  12759. * @eventOf ui.grid.cellNav.api:PublicApi
  12760. * @description is raised when the viewPort receives a keyPress event. Cells never get focus in uiGrid
  12761. * due to the difficulties of setting focus on a cell that is not visible in the viewport. Use this
  12762. * event whenever you need a keypress event on a cell
  12763. * <br/>
  12764. * @param {object} event keypress event
  12765. * @param {object} rowCol current rowCol position
  12766. */
  12767. viewPortKeyPress: function (event, rowCol) {}
  12768. }
  12769. },
  12770. methods: {
  12771. cellNav: {
  12772. /**
  12773. * @ngdoc function
  12774. * @name scrollToFocus
  12775. * @methodOf ui.grid.cellNav.api:PublicApi
  12776. * @description brings the specified row and column into view, and sets focus
  12777. * to that cell
  12778. * @param {object} rowEntity gridOptions.data[] array instance to make visible and set focus
  12779. * @param {object} colDef to make visible and set focus
  12780. * @returns {promise} a promise that is resolved after any scrolling is finished
  12781. */
  12782. scrollToFocus: function (rowEntity, colDef) {
  12783. return service.scrollToFocus(grid, rowEntity, colDef);
  12784. },
  12785. /**
  12786. * @ngdoc function
  12787. * @name getFocusedCell
  12788. * @methodOf ui.grid.cellNav.api:PublicApi
  12789. * @description returns the current (or last if Grid does not have focus) focused row and column
  12790. * <br> value is null if no selection has occurred
  12791. */
  12792. getFocusedCell: function () {
  12793. return grid.cellNav.lastRowCol;
  12794. },
  12795. /**
  12796. * @ngdoc function
  12797. * @name getCurrentSelection
  12798. * @methodOf ui.grid.cellNav.api:PublicApi
  12799. * @description returns an array containing the current selection
  12800. * <br> array is empty if no selection has occurred
  12801. */
  12802. getCurrentSelection: function () {
  12803. return grid.cellNav.focusedCells;
  12804. },
  12805. /**
  12806. * @ngdoc function
  12807. * @name rowColSelectIndex
  12808. * @methodOf ui.grid.cellNav.api:PublicApi
  12809. * @description returns the index in the order in which the GridRowColumn was selected, returns -1 if the GridRowColumn
  12810. * isn't selected
  12811. * @param {object} rowCol the rowCol to evaluate
  12812. */
  12813. rowColSelectIndex: function (rowCol) {
  12814. //return gridUtil.arrayContainsObjectWithProperty(grid.cellNav.focusedCells, 'col.uid', rowCol.col.uid) &&
  12815. var index = -1;
  12816. for (var i = 0; i < grid.cellNav.focusedCells.length; i++) {
  12817. if (grid.cellNav.focusedCells[i].col.uid === rowCol.col.uid &&
  12818. grid.cellNav.focusedCells[i].row.uid === rowCol.row.uid) {
  12819. index = i;
  12820. break;
  12821. }
  12822. }
  12823. return index;
  12824. }
  12825. }
  12826. }
  12827. };
  12828. grid.api.registerEventsFromObject(publicApi.events);
  12829. grid.api.registerMethodsFromObject(publicApi.methods);
  12830. },
  12831. defaultGridOptions: function (gridOptions) {
  12832. /**
  12833. * @ngdoc object
  12834. * @name ui.grid.cellNav.api:GridOptions
  12835. *
  12836. * @description GridOptions for cellNav feature, these are available to be
  12837. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  12838. */
  12839. /**
  12840. * @ngdoc object
  12841. * @name modifierKeysToMultiSelectCells
  12842. * @propertyOf ui.grid.cellNav.api:GridOptions
  12843. * @description Enable multiple cell selection only when using the ctrlKey or shiftKey.
  12844. * <br/>Defaults to false
  12845. */
  12846. gridOptions.modifierKeysToMultiSelectCells = gridOptions.modifierKeysToMultiSelectCells === true;
  12847. },
  12848. /**
  12849. * @ngdoc service
  12850. * @name decorateRenderContainers
  12851. * @methodOf ui.grid.cellNav.service:uiGridCellNavService
  12852. * @description decorates grid renderContainers with cellNav functions
  12853. */
  12854. decorateRenderContainers: function (grid) {
  12855. var rightContainer = grid.hasRightContainer() ? grid.renderContainers.right : null;
  12856. var leftContainer = grid.hasLeftContainer() ? grid.renderContainers.left : null;
  12857. if (leftContainer !== null) {
  12858. grid.renderContainers.left.cellNav = new UiGridCellNav(grid.renderContainers.body, leftContainer, rightContainer, grid.renderContainers.body);
  12859. }
  12860. if (rightContainer !== null) {
  12861. grid.renderContainers.right.cellNav = new UiGridCellNav(grid.renderContainers.body, rightContainer, grid.renderContainers.body, leftContainer);
  12862. }
  12863. grid.renderContainers.body.cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, leftContainer, rightContainer);
  12864. },
  12865. /**
  12866. * @ngdoc service
  12867. * @name getDirection
  12868. * @methodOf ui.grid.cellNav.service:uiGridCellNavService
  12869. * @description determines which direction to for a given keyDown event
  12870. * @returns {uiGridCellNavConstants.direction} direction
  12871. */
  12872. getDirection: function (evt) {
  12873. if (evt.keyCode === uiGridConstants.keymap.LEFT ||
  12874. (evt.keyCode === uiGridConstants.keymap.TAB && evt.shiftKey)) {
  12875. return uiGridCellNavConstants.direction.LEFT;
  12876. }
  12877. if (evt.keyCode === uiGridConstants.keymap.RIGHT ||
  12878. evt.keyCode === uiGridConstants.keymap.TAB) {
  12879. return uiGridCellNavConstants.direction.RIGHT;
  12880. }
  12881. if (evt.keyCode === uiGridConstants.keymap.UP ||
  12882. (evt.keyCode === uiGridConstants.keymap.ENTER && evt.shiftKey) ) {
  12883. return uiGridCellNavConstants.direction.UP;
  12884. }
  12885. if (evt.keyCode === uiGridConstants.keymap.PG_UP){
  12886. return uiGridCellNavConstants.direction.PG_UP;
  12887. }
  12888. if (evt.keyCode === uiGridConstants.keymap.DOWN ||
  12889. evt.keyCode === uiGridConstants.keymap.ENTER && !(evt.ctrlKey || evt.altKey)) {
  12890. return uiGridCellNavConstants.direction.DOWN;
  12891. }
  12892. if (evt.keyCode === uiGridConstants.keymap.PG_DOWN){
  12893. return uiGridCellNavConstants.direction.PG_DOWN;
  12894. }
  12895. return null;
  12896. },
  12897. /**
  12898. * @ngdoc service
  12899. * @name cellNavColumnBuilder
  12900. * @methodOf ui.grid.cellNav.service:uiGridCellNavService
  12901. * @description columnBuilder function that adds cell navigation properties to grid column
  12902. * @returns {promise} promise that will load any needed templates when resolved
  12903. */
  12904. cellNavColumnBuilder: function (colDef, col, gridOptions) {
  12905. var promises = [];
  12906. /**
  12907. * @ngdoc object
  12908. * @name ui.grid.cellNav.api:ColumnDef
  12909. *
  12910. * @description Column Definitions for cellNav feature, these are available to be
  12911. * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs}
  12912. */
  12913. /**
  12914. * @ngdoc object
  12915. * @name allowCellFocus
  12916. * @propertyOf ui.grid.cellNav.api:ColumnDef
  12917. * @description Enable focus on a cell within this column.
  12918. * <br/>Defaults to true
  12919. */
  12920. colDef.allowCellFocus = colDef.allowCellFocus === undefined ? true : colDef.allowCellFocus;
  12921. return $q.all(promises);
  12922. },
  12923. /**
  12924. * @ngdoc method
  12925. * @methodOf ui.grid.cellNav.service:uiGridCellNavService
  12926. * @name scrollToFocus
  12927. * @description Scroll the grid such that the specified
  12928. * row and column is in view, and set focus to the cell in that row and column
  12929. * @param {Grid} grid the grid you'd like to act upon, usually available
  12930. * from gridApi.grid
  12931. * @param {object} rowEntity gridOptions.data[] array instance to make visible and set focus to
  12932. * @param {object} colDef to make visible and set focus to
  12933. * @returns {promise} a promise that is resolved after any scrolling is finished
  12934. */
  12935. scrollToFocus: function (grid, rowEntity, colDef) {
  12936. var gridRow = null, gridCol = null;
  12937. if (typeof(rowEntity) !== 'undefined' && rowEntity !== null) {
  12938. gridRow = grid.getRow(rowEntity);
  12939. }
  12940. if (typeof(colDef) !== 'undefined' && colDef !== null) {
  12941. gridCol = grid.getColumn(colDef.name ? colDef.name : colDef.field);
  12942. }
  12943. return grid.api.core.scrollToIfNecessary(gridRow, gridCol).then(function () {
  12944. var rowCol = { row: gridRow, col: gridCol };
  12945. // Broadcast the navigation
  12946. if (gridRow !== null && gridCol !== null) {
  12947. grid.cellNav.broadcastCellNav(rowCol);
  12948. }
  12949. });
  12950. },
  12951. /**
  12952. * @ngdoc method
  12953. * @methodOf ui.grid.cellNav.service:uiGridCellNavService
  12954. * @name getLeftWidth
  12955. * @description Get the current drawn width of the columns in the
  12956. * grid up to the numbered column, and add an apportionment for the
  12957. * column that we're on. So if we are on column 0, we want to scroll
  12958. * 0% (i.e. exclude this column from calc). If we're on the last column
  12959. * we want to scroll to 100% (i.e. include this column in the calc). So
  12960. * we include (thisColIndex / totalNumberCols) % of this column width
  12961. * @param {Grid} grid the grid you'd like to act upon, usually available
  12962. * from gridApi.grid
  12963. * @param {gridCol} upToCol the column to total up to and including
  12964. */
  12965. getLeftWidth: function (grid, upToCol) {
  12966. var width = 0;
  12967. if (!upToCol) {
  12968. return width;
  12969. }
  12970. var lastIndex = grid.renderContainers.body.visibleColumnCache.indexOf( upToCol );
  12971. // total column widths up-to but not including the passed in column
  12972. grid.renderContainers.body.visibleColumnCache.forEach( function( col, index ) {
  12973. if ( index < lastIndex ){
  12974. width += col.drawnWidth;
  12975. }
  12976. });
  12977. // pro-rata the final column based on % of total columns.
  12978. var percentage = lastIndex === 0 ? 0 : (lastIndex + 1) / grid.renderContainers.body.visibleColumnCache.length;
  12979. width += upToCol.drawnWidth * percentage;
  12980. return width;
  12981. }
  12982. };
  12983. return service;
  12984. }]);
  12985. /**
  12986. * @ngdoc directive
  12987. * @name ui.grid.cellNav.directive:uiCellNav
  12988. * @element div
  12989. * @restrict EA
  12990. *
  12991. * @description Adds cell navigation features to the grid columns
  12992. *
  12993. * @example
  12994. <example module="app">
  12995. <file name="app.js">
  12996. var app = angular.module('app', ['ui.grid', 'ui.grid.cellNav']);
  12997. app.controller('MainCtrl', ['$scope', function ($scope) {
  12998. $scope.data = [
  12999. { name: 'Bob', title: 'CEO' },
  13000. { name: 'Frank', title: 'Lowly Developer' }
  13001. ];
  13002. $scope.columnDefs = [
  13003. {name: 'name'},
  13004. {name: 'title'}
  13005. ];
  13006. }]);
  13007. </file>
  13008. <file name="index.html">
  13009. <div ng-controller="MainCtrl">
  13010. <div ui-grid="{ data: data, columnDefs: columnDefs }" ui-grid-cellnav></div>
  13011. </div>
  13012. </file>
  13013. </example>
  13014. */
  13015. module.directive('uiGridCellnav', ['gridUtil', 'uiGridCellNavService', 'uiGridCellNavConstants', 'uiGridConstants', 'GridRowColumn', '$timeout', '$compile',
  13016. function (gridUtil, uiGridCellNavService, uiGridCellNavConstants, uiGridConstants, GridRowColumn, $timeout, $compile) {
  13017. return {
  13018. replace: true,
  13019. priority: -150,
  13020. require: '^uiGrid',
  13021. scope: false,
  13022. controller: function () {},
  13023. compile: function () {
  13024. return {
  13025. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  13026. var _scope = $scope;
  13027. var grid = uiGridCtrl.grid;
  13028. uiGridCellNavService.initializeGrid(grid);
  13029. uiGridCtrl.cellNav = {};
  13030. //Ensure that the object has all of the methods we expect it to
  13031. uiGridCtrl.cellNav.makeRowCol = function (obj) {
  13032. if (!(obj instanceof GridRowColumn)) {
  13033. obj = new GridRowColumn(obj.row, obj.col);
  13034. }
  13035. return obj;
  13036. };
  13037. uiGridCtrl.cellNav.getActiveCell = function () {
  13038. var elms = $elm[0].getElementsByClassName('ui-grid-cell-focus');
  13039. if (elms.length > 0){
  13040. return elms[0];
  13041. }
  13042. return undefined;
  13043. };
  13044. uiGridCtrl.cellNav.broadcastCellNav = grid.cellNav.broadcastCellNav = function (newRowCol, modifierDown, originEvt) {
  13045. modifierDown = !(modifierDown === undefined || !modifierDown);
  13046. newRowCol = uiGridCtrl.cellNav.makeRowCol(newRowCol);
  13047. uiGridCtrl.cellNav.broadcastFocus(newRowCol, modifierDown, originEvt);
  13048. _scope.$broadcast(uiGridCellNavConstants.CELL_NAV_EVENT, newRowCol, modifierDown, originEvt);
  13049. };
  13050. uiGridCtrl.cellNav.clearFocus = grid.cellNav.clearFocus = function () {
  13051. grid.cellNav.focusedCells = [];
  13052. _scope.$broadcast(uiGridCellNavConstants.CELL_NAV_EVENT);
  13053. };
  13054. uiGridCtrl.cellNav.broadcastFocus = function (rowCol, modifierDown, originEvt) {
  13055. modifierDown = !(modifierDown === undefined || !modifierDown);
  13056. rowCol = uiGridCtrl.cellNav.makeRowCol(rowCol);
  13057. var row = rowCol.row,
  13058. col = rowCol.col;
  13059. var rowColSelectIndex = uiGridCtrl.grid.api.cellNav.rowColSelectIndex(rowCol);
  13060. if (grid.cellNav.lastRowCol === null || rowColSelectIndex === -1) {
  13061. var newRowCol = new GridRowColumn(row, col);
  13062. if (grid.cellNav.lastRowCol === null || grid.cellNav.lastRowCol.row !== newRowCol.row || grid.cellNav.lastRowCol.col !== newRowCol.col){
  13063. grid.api.cellNav.raise.navigate(newRowCol, grid.cellNav.lastRowCol);
  13064. grid.cellNav.lastRowCol = newRowCol;
  13065. }
  13066. if (uiGridCtrl.grid.options.modifierKeysToMultiSelectCells && modifierDown) {
  13067. grid.cellNav.focusedCells.push(rowCol);
  13068. } else {
  13069. grid.cellNav.focusedCells = [rowCol];
  13070. }
  13071. } else if (grid.options.modifierKeysToMultiSelectCells && modifierDown &&
  13072. rowColSelectIndex >= 0) {
  13073. grid.cellNav.focusedCells.splice(rowColSelectIndex, 1);
  13074. }
  13075. };
  13076. uiGridCtrl.cellNav.handleKeyDown = function (evt) {
  13077. var direction = uiGridCellNavService.getDirection(evt);
  13078. if (direction === null) {
  13079. return null;
  13080. }
  13081. var containerId = 'body';
  13082. if (evt.uiGridTargetRenderContainerId) {
  13083. containerId = evt.uiGridTargetRenderContainerId;
  13084. }
  13085. // Get the last-focused row+col combo
  13086. var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
  13087. if (lastRowCol) {
  13088. // Figure out which new row+combo we're navigating to
  13089. var rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(direction, lastRowCol.row, lastRowCol.col);
  13090. var focusableCols = uiGridCtrl.grid.renderContainers[containerId].cellNav.getFocusableCols();
  13091. var rowColSelectIndex = uiGridCtrl.grid.api.cellNav.rowColSelectIndex(rowCol);
  13092. // Shift+tab on top-left cell should exit cellnav on render container
  13093. if (
  13094. // Navigating left
  13095. direction === uiGridCellNavConstants.direction.LEFT &&
  13096. // New col is last col (i.e. wrap around)
  13097. rowCol.col === focusableCols[focusableCols.length - 1] &&
  13098. // Staying on same row, which means we're at first row
  13099. rowCol.row === lastRowCol.row &&
  13100. evt.keyCode === uiGridConstants.keymap.TAB &&
  13101. evt.shiftKey
  13102. ) {
  13103. grid.cellNav.focusedCells.splice(rowColSelectIndex, 1);
  13104. uiGridCtrl.cellNav.clearFocus();
  13105. return true;
  13106. }
  13107. // Tab on bottom-right cell should exit cellnav on render container
  13108. else if (
  13109. direction === uiGridCellNavConstants.direction.RIGHT &&
  13110. // New col is first col (i.e. wrap around)
  13111. rowCol.col === focusableCols[0] &&
  13112. // Staying on same row, which means we're at first row
  13113. rowCol.row === lastRowCol.row &&
  13114. evt.keyCode === uiGridConstants.keymap.TAB &&
  13115. !evt.shiftKey
  13116. ) {
  13117. grid.cellNav.focusedCells.splice(rowColSelectIndex, 1);
  13118. uiGridCtrl.cellNav.clearFocus();
  13119. return true;
  13120. }
  13121. // Scroll to the new cell, if it's not completely visible within the render container's viewport
  13122. grid.scrollToIfNecessary(rowCol.row, rowCol.col).then(function () {
  13123. uiGridCtrl.cellNav.broadcastCellNav(rowCol);
  13124. });
  13125. evt.stopPropagation();
  13126. evt.preventDefault();
  13127. return false;
  13128. }
  13129. };
  13130. },
  13131. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  13132. var _scope = $scope;
  13133. var grid = uiGridCtrl.grid;
  13134. function addAriaLiveRegion(){
  13135. // Thanks to google docs for the inspiration behind how to do this
  13136. // XXX: Why is this entire mess nessasary?
  13137. // Because browsers take a lot of coercing to get them to read out live regions
  13138. //http://www.paciellogroup.com/blog/2012/06/html5-accessibility-chops-aria-rolealert-browser-support/
  13139. var ariaNotifierDomElt = '<div ' +
  13140. 'id="' + grid.id +'-aria-speakable" ' +
  13141. 'class="ui-grid-a11y-ariascreenreader-speakable ui-grid-offscreen" ' +
  13142. 'aria-live="assertive" ' +
  13143. 'role="region" ' +
  13144. 'aria-atomic="true" ' +
  13145. 'aria-hidden="false" ' +
  13146. 'aria-relevant="additions" ' +
  13147. '>' +
  13148. '&nbsp;' +
  13149. '</div>';
  13150. var ariaNotifier = $compile(ariaNotifierDomElt)($scope);
  13151. $elm.prepend(ariaNotifier);
  13152. $scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, function (evt, rowCol, modifierDown, originEvt) {
  13153. /*
  13154. * If the cell nav event was because of a focus event then we don't want to
  13155. * change the notifier text.
  13156. * Reasoning: Voice Over fires a focus events when moving arround the grid.
  13157. * If the screen reader is handing the grid nav properly then we don't need to
  13158. * use the alert to notify the user of the movement.
  13159. * In all other cases we do want a notification event.
  13160. */
  13161. if (originEvt && originEvt.type === 'focus'){return;}
  13162. function setNotifyText(text){
  13163. if (text === ariaNotifier.text()){return;}
  13164. ariaNotifier[0].style.clip = 'rect(0px,0px,0px,0px)';
  13165. /*
  13166. * This is how google docs handles clearing the div. Seems to work better than setting the text of the div to ''
  13167. */
  13168. ariaNotifier[0].innerHTML = "";
  13169. ariaNotifier[0].style.visibility = 'hidden';
  13170. ariaNotifier[0].style.visibility = 'visible';
  13171. if (text !== ''){
  13172. ariaNotifier[0].style.clip = 'auto';
  13173. /*
  13174. * The space after the text is something that google docs does.
  13175. */
  13176. ariaNotifier[0].appendChild(document.createTextNode(text + " "));
  13177. ariaNotifier[0].style.visibility = 'hidden';
  13178. ariaNotifier[0].style.visibility = 'visible';
  13179. }
  13180. }
  13181. var values = [];
  13182. var currentSelection = grid.api.cellNav.getCurrentSelection();
  13183. for (var i = 0; i < currentSelection.length; i++) {
  13184. values.push(currentSelection[i].getIntersectionValueFiltered());
  13185. }
  13186. var cellText = values.toString();
  13187. setNotifyText(cellText);
  13188. });
  13189. }
  13190. addAriaLiveRegion();
  13191. }
  13192. };
  13193. }
  13194. };
  13195. }]);
  13196. module.directive('uiGridRenderContainer', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', '$compile','uiGridCellNavConstants',
  13197. function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, $compile, uiGridCellNavConstants) {
  13198. return {
  13199. replace: true,
  13200. priority: -99999, //this needs to run very last
  13201. require: ['^uiGrid', 'uiGridRenderContainer', '?^uiGridCellnav'],
  13202. scope: false,
  13203. compile: function () {
  13204. return {
  13205. post: function ($scope, $elm, $attrs, controllers) {
  13206. var uiGridCtrl = controllers[0],
  13207. renderContainerCtrl = controllers[1],
  13208. uiGridCellnavCtrl = controllers[2];
  13209. // Skip attaching cell-nav specific logic if the directive is not attached above us
  13210. if (!uiGridCtrl.grid.api.cellNav) { return; }
  13211. var containerId = renderContainerCtrl.containerId;
  13212. var grid = uiGridCtrl.grid;
  13213. //run each time a render container is created
  13214. uiGridCellNavService.decorateRenderContainers(grid);
  13215. // focusser only created for body
  13216. if (containerId !== 'body') {
  13217. return;
  13218. }
  13219. if (uiGridCtrl.grid.options.modifierKeysToMultiSelectCells){
  13220. $elm.attr('aria-multiselectable', true);
  13221. } else {
  13222. $elm.attr('aria-multiselectable', false);
  13223. }
  13224. //add an element with no dimensions that can be used to set focus and capture keystrokes
  13225. var focuser = $compile('<div class="ui-grid-focuser" role="region" aria-live="assertive" aria-atomic="false" tabindex="0" aria-controls="' + grid.id +'-aria-speakable '+ grid.id + '-grid-container' +'" aria-owns="' + grid.id + '-grid-container' + '"></div>')($scope);
  13226. $elm.append(focuser);
  13227. focuser.on('focus', function (evt) {
  13228. evt.uiGridTargetRenderContainerId = containerId;
  13229. var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
  13230. if (rowCol === null) {
  13231. rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(uiGridCellNavConstants.direction.DOWN, null, null);
  13232. if (rowCol.row && rowCol.col) {
  13233. uiGridCtrl.cellNav.broadcastCellNav(rowCol);
  13234. }
  13235. }
  13236. });
  13237. uiGridCellnavCtrl.setAriaActivedescendant = function(id){
  13238. $elm.attr('aria-activedescendant', id);
  13239. };
  13240. uiGridCellnavCtrl.removeAriaActivedescendant = function(id){
  13241. if ($elm.attr('aria-activedescendant') === id){
  13242. $elm.attr('aria-activedescendant', '');
  13243. }
  13244. };
  13245. uiGridCtrl.focus = function () {
  13246. gridUtil.focus.byElement(focuser[0]);
  13247. //allow for first time grid focus
  13248. };
  13249. var viewPortKeyDownWasRaisedForRowCol = null;
  13250. // Bind to keydown events in the render container
  13251. focuser.on('keydown', function (evt) {
  13252. evt.uiGridTargetRenderContainerId = containerId;
  13253. var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
  13254. var result = uiGridCtrl.cellNav.handleKeyDown(evt);
  13255. if (result === null) {
  13256. uiGridCtrl.grid.api.cellNav.raise.viewPortKeyDown(evt, rowCol);
  13257. viewPortKeyDownWasRaisedForRowCol = rowCol;
  13258. }
  13259. });
  13260. //Bind to keypress events in the render container
  13261. //keypress events are needed by edit function so the key press
  13262. //that initiated an edit is not lost
  13263. //must fire the event in a timeout so the editor can
  13264. //initialize and subscribe to the event on another event loop
  13265. focuser.on('keypress', function (evt) {
  13266. if (viewPortKeyDownWasRaisedForRowCol) {
  13267. $timeout(function () {
  13268. uiGridCtrl.grid.api.cellNav.raise.viewPortKeyPress(evt, viewPortKeyDownWasRaisedForRowCol);
  13269. },4);
  13270. viewPortKeyDownWasRaisedForRowCol = null;
  13271. }
  13272. });
  13273. $scope.$on('$destroy', function(){
  13274. //Remove all event handlers associated with this focuser.
  13275. focuser.off();
  13276. });
  13277. }
  13278. };
  13279. }
  13280. };
  13281. }]);
  13282. module.directive('uiGridViewport', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', 'uiGridCellNavConstants','$log','$compile',
  13283. function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, uiGridCellNavConstants, $log, $compile) {
  13284. return {
  13285. replace: true,
  13286. priority: -99999, //this needs to run very last
  13287. require: ['^uiGrid', '^uiGridRenderContainer', '?^uiGridCellnav'],
  13288. scope: false,
  13289. compile: function () {
  13290. return {
  13291. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  13292. },
  13293. post: function ($scope, $elm, $attrs, controllers) {
  13294. var uiGridCtrl = controllers[0],
  13295. renderContainerCtrl = controllers[1];
  13296. // Skip attaching cell-nav specific logic if the directive is not attached above us
  13297. if (!uiGridCtrl.grid.api.cellNav) { return; }
  13298. var containerId = renderContainerCtrl.containerId;
  13299. //no need to process for other containers
  13300. if (containerId !== 'body') {
  13301. return;
  13302. }
  13303. var grid = uiGridCtrl.grid;
  13304. grid.api.core.on.scrollBegin($scope, function (args) {
  13305. // Skip if there's no currently-focused cell
  13306. var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
  13307. if (lastRowCol === null) {
  13308. return;
  13309. }
  13310. //if not in my container, move on
  13311. //todo: worry about horiz scroll
  13312. if (!renderContainerCtrl.colContainer.containsColumn(lastRowCol.col)) {
  13313. return;
  13314. }
  13315. uiGridCtrl.cellNav.clearFocus();
  13316. });
  13317. grid.api.core.on.scrollEnd($scope, function (args) {
  13318. // Skip if there's no currently-focused cell
  13319. var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
  13320. if (lastRowCol === null) {
  13321. return;
  13322. }
  13323. //if not in my container, move on
  13324. //todo: worry about horiz scroll
  13325. if (!renderContainerCtrl.colContainer.containsColumn(lastRowCol.col)) {
  13326. return;
  13327. }
  13328. uiGridCtrl.cellNav.broadcastCellNav(lastRowCol);
  13329. });
  13330. grid.api.cellNav.on.navigate($scope, function () {
  13331. //focus again because it can be lost
  13332. uiGridCtrl.focus();
  13333. });
  13334. }
  13335. };
  13336. }
  13337. };
  13338. }]);
  13339. /**
  13340. * @ngdoc directive
  13341. * @name ui.grid.cellNav.directive:uiGridCell
  13342. * @element div
  13343. * @restrict A
  13344. * @description Stacks on top of ui.grid.uiGridCell to provide cell navigation
  13345. */
  13346. module.directive('uiGridCell', ['$timeout', '$document', 'uiGridCellNavService', 'gridUtil', 'uiGridCellNavConstants', 'uiGridConstants', 'GridRowColumn',
  13347. function ($timeout, $document, uiGridCellNavService, gridUtil, uiGridCellNavConstants, uiGridConstants, GridRowColumn) {
  13348. return {
  13349. priority: -150, // run after default uiGridCell directive and ui.grid.edit uiGridCell
  13350. restrict: 'A',
  13351. require: ['^uiGrid', '?^uiGridCellnav'],
  13352. scope: false,
  13353. link: function ($scope, $elm, $attrs, controllers) {
  13354. var uiGridCtrl = controllers[0],
  13355. uiGridCellnavCtrl = controllers[1];
  13356. // Skip attaching cell-nav specific logic if the directive is not attached above us
  13357. if (!uiGridCtrl.grid.api.cellNav) { return; }
  13358. if (!$scope.col.colDef.allowCellFocus) {
  13359. return;
  13360. }
  13361. //Convinience local variables
  13362. var grid = uiGridCtrl.grid;
  13363. $scope.focused = false;
  13364. // Make this cell focusable but only with javascript/a mouse click
  13365. $elm.attr('tabindex', -1);
  13366. // When a cell is clicked, broadcast a cellNav event saying that this row+col combo is now focused
  13367. $elm.find('div').on('click', function (evt) {
  13368. uiGridCtrl.cellNav.broadcastCellNav(new GridRowColumn($scope.row, $scope.col), evt.ctrlKey || evt.metaKey, evt);
  13369. evt.stopPropagation();
  13370. $scope.$apply();
  13371. });
  13372. /*
  13373. * XXX Hack for screen readers.
  13374. * This allows the grid to focus using only the screen reader cursor.
  13375. * Since the focus event doesn't include key press information we can't use it
  13376. * as our primary source of the event.
  13377. */
  13378. $elm.on('mousedown', preventMouseDown);
  13379. //turn on and off for edit events
  13380. if (uiGridCtrl.grid.api.edit) {
  13381. uiGridCtrl.grid.api.edit.on.beginCellEdit($scope, function () {
  13382. $elm.off('mousedown', preventMouseDown);
  13383. });
  13384. uiGridCtrl.grid.api.edit.on.afterCellEdit($scope, function () {
  13385. $elm.on('mousedown', preventMouseDown);
  13386. });
  13387. uiGridCtrl.grid.api.edit.on.cancelCellEdit($scope, function () {
  13388. $elm.on('mousedown', preventMouseDown);
  13389. });
  13390. }
  13391. function preventMouseDown(evt) {
  13392. //Prevents the foucus event from firing if the click event is already going to fire.
  13393. //If both events fire it will cause bouncing behavior.
  13394. evt.preventDefault();
  13395. }
  13396. //You can only focus on elements with a tabindex value
  13397. $elm.on('focus', function (evt) {
  13398. uiGridCtrl.cellNav.broadcastCellNav(new GridRowColumn($scope.row, $scope.col), false, evt);
  13399. evt.stopPropagation();
  13400. $scope.$apply();
  13401. });
  13402. // This event is fired for all cells. If the cell matches, then focus is set
  13403. $scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, function (evt, rowCol, modifierDown) {
  13404. var isFocused = grid.cellNav.focusedCells.some(function(focusedRowCol, index){
  13405. return (focusedRowCol.row === $scope.row && focusedRowCol.col === $scope.col);
  13406. });
  13407. if (isFocused){
  13408. setFocused();
  13409. } else {
  13410. clearFocus();
  13411. }
  13412. });
  13413. function setFocused() {
  13414. if (!$scope.focused){
  13415. var div = $elm.find('div');
  13416. div.addClass('ui-grid-cell-focus');
  13417. $elm.attr('aria-selected', true);
  13418. uiGridCellnavCtrl.setAriaActivedescendant($elm.attr('id'));
  13419. $scope.focused = true;
  13420. }
  13421. }
  13422. function clearFocus() {
  13423. if ($scope.focused){
  13424. var div = $elm.find('div');
  13425. div.removeClass('ui-grid-cell-focus');
  13426. $elm.attr('aria-selected', false);
  13427. uiGridCellnavCtrl.removeAriaActivedescendant($elm.attr('id'));
  13428. $scope.focused = false;
  13429. }
  13430. }
  13431. $scope.$on('$destroy', function () {
  13432. //.off withouth paramaters removes all handlers
  13433. $elm.find('div').off();
  13434. $elm.off();
  13435. });
  13436. }
  13437. };
  13438. }]);
  13439. })();
  13440. (function () {
  13441. 'use strict';
  13442. /**
  13443. * @ngdoc overview
  13444. * @name ui.grid.edit
  13445. * @description
  13446. *
  13447. * # ui.grid.edit
  13448. *
  13449. * <div class="alert alert-success" role="alert"><strong>Stable</strong> This feature is stable. There should no longer be breaking api changes without a deprecation warning.</div>
  13450. *
  13451. * This module provides cell editing capability to ui.grid. The goal was to emulate keying data in a spreadsheet via
  13452. * a keyboard.
  13453. * <br/>
  13454. * <br/>
  13455. * To really get the full spreadsheet-like data entry, the ui.grid.cellNav module should be used. This will allow the
  13456. * user to key data and then tab, arrow, or enter to the cells beside or below.
  13457. *
  13458. * <div doc-module-components="ui.grid.edit"></div>
  13459. */
  13460. var module = angular.module('ui.grid.edit', ['ui.grid']);
  13461. /**
  13462. * @ngdoc object
  13463. * @name ui.grid.edit.constant:uiGridEditConstants
  13464. *
  13465. * @description constants available in edit module
  13466. */
  13467. module.constant('uiGridEditConstants', {
  13468. EDITABLE_CELL_TEMPLATE: /EDITABLE_CELL_TEMPLATE/g,
  13469. //must be lowercase because template bulder converts to lower
  13470. EDITABLE_CELL_DIRECTIVE: /editable_cell_directive/g,
  13471. events: {
  13472. BEGIN_CELL_EDIT: 'uiGridEventBeginCellEdit',
  13473. END_CELL_EDIT: 'uiGridEventEndCellEdit',
  13474. CANCEL_CELL_EDIT: 'uiGridEventCancelCellEdit'
  13475. }
  13476. });
  13477. /**
  13478. * @ngdoc service
  13479. * @name ui.grid.edit.service:uiGridEditService
  13480. *
  13481. * @description Services for editing features
  13482. */
  13483. module.service('uiGridEditService', ['$q', 'uiGridConstants', 'gridUtil',
  13484. function ($q, uiGridConstants, gridUtil) {
  13485. var service = {
  13486. initializeGrid: function (grid) {
  13487. service.defaultGridOptions(grid.options);
  13488. grid.registerColumnBuilder(service.editColumnBuilder);
  13489. grid.edit = {};
  13490. /**
  13491. * @ngdoc object
  13492. * @name ui.grid.edit.api:PublicApi
  13493. *
  13494. * @description Public Api for edit feature
  13495. */
  13496. var publicApi = {
  13497. events: {
  13498. edit: {
  13499. /**
  13500. * @ngdoc event
  13501. * @name afterCellEdit
  13502. * @eventOf ui.grid.edit.api:PublicApi
  13503. * @description raised when cell editing is complete
  13504. * <pre>
  13505. * gridApi.edit.on.afterCellEdit(scope,function(rowEntity, colDef){})
  13506. * </pre>
  13507. * @param {object} rowEntity the options.data element that was edited
  13508. * @param {object} colDef the column that was edited
  13509. * @param {object} newValue new value
  13510. * @param {object} oldValue old value
  13511. */
  13512. afterCellEdit: function (rowEntity, colDef, newValue, oldValue) {
  13513. },
  13514. /**
  13515. * @ngdoc event
  13516. * @name beginCellEdit
  13517. * @eventOf ui.grid.edit.api:PublicApi
  13518. * @description raised when cell editing starts on a cell
  13519. * <pre>
  13520. * gridApi.edit.on.beginCellEdit(scope,function(rowEntity, colDef){})
  13521. * </pre>
  13522. * @param {object} rowEntity the options.data element that was edited
  13523. * @param {object} colDef the column that was edited
  13524. * @param {object} triggerEvent the event that triggered the edit. Useful to prevent losing keystrokes on some
  13525. * complex editors
  13526. */
  13527. beginCellEdit: function (rowEntity, colDef, triggerEvent) {
  13528. },
  13529. /**
  13530. * @ngdoc event
  13531. * @name cancelCellEdit
  13532. * @eventOf ui.grid.edit.api:PublicApi
  13533. * @description raised when cell editing is cancelled on a cell
  13534. * <pre>
  13535. * gridApi.edit.on.cancelCellEdit(scope,function(rowEntity, colDef){})
  13536. * </pre>
  13537. * @param {object} rowEntity the options.data element that was edited
  13538. * @param {object} colDef the column that was edited
  13539. */
  13540. cancelCellEdit: function (rowEntity, colDef) {
  13541. }
  13542. }
  13543. },
  13544. methods: {
  13545. edit: { }
  13546. }
  13547. };
  13548. grid.api.registerEventsFromObject(publicApi.events);
  13549. //grid.api.registerMethodsFromObject(publicApi.methods);
  13550. },
  13551. defaultGridOptions: function (gridOptions) {
  13552. /**
  13553. * @ngdoc object
  13554. * @name ui.grid.edit.api:GridOptions
  13555. *
  13556. * @description Options for configuring the edit feature, these are available to be
  13557. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  13558. */
  13559. /**
  13560. * @ngdoc object
  13561. * @name enableCellEdit
  13562. * @propertyOf ui.grid.edit.api:GridOptions
  13563. * @description If defined, sets the default value for the editable flag on each individual colDefs
  13564. * if their individual enableCellEdit configuration is not defined. Defaults to undefined.
  13565. */
  13566. /**
  13567. * @ngdoc object
  13568. * @name cellEditableCondition
  13569. * @propertyOf ui.grid.edit.api:GridOptions
  13570. * @description If specified, either a value or function to be used by all columns before editing.
  13571. * If falsy, then editing of cell is not allowed.
  13572. * @example
  13573. * <pre>
  13574. * function($scope){
  13575. * //use $scope.row.entity and $scope.col.colDef to determine if editing is allowed
  13576. * return true;
  13577. * }
  13578. * </pre>
  13579. */
  13580. gridOptions.cellEditableCondition = gridOptions.cellEditableCondition === undefined ? true : gridOptions.cellEditableCondition;
  13581. /**
  13582. * @ngdoc object
  13583. * @name editableCellTemplate
  13584. * @propertyOf ui.grid.edit.api:GridOptions
  13585. * @description If specified, cellTemplate to use as the editor for all columns.
  13586. * <br/> defaults to 'ui-grid/cellTextEditor'
  13587. */
  13588. /**
  13589. * @ngdoc object
  13590. * @name enableCellEditOnFocus
  13591. * @propertyOf ui.grid.edit.api:GridOptions
  13592. * @description If true, then editor is invoked as soon as cell receives focus. Default false.
  13593. * <br/>_requires cellNav feature and the edit feature to be enabled_
  13594. */
  13595. //enableCellEditOnFocus can only be used if cellnav module is used
  13596. gridOptions.enableCellEditOnFocus = gridOptions.enableCellEditOnFocus === undefined ? false : gridOptions.enableCellEditOnFocus;
  13597. },
  13598. /**
  13599. * @ngdoc service
  13600. * @name editColumnBuilder
  13601. * @methodOf ui.grid.edit.service:uiGridEditService
  13602. * @description columnBuilder function that adds edit properties to grid column
  13603. * @returns {promise} promise that will load any needed templates when resolved
  13604. */
  13605. editColumnBuilder: function (colDef, col, gridOptions) {
  13606. var promises = [];
  13607. /**
  13608. * @ngdoc object
  13609. * @name ui.grid.edit.api:ColumnDef
  13610. *
  13611. * @description Column Definition for edit feature, these are available to be
  13612. * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs}
  13613. */
  13614. /**
  13615. * @ngdoc object
  13616. * @name enableCellEdit
  13617. * @propertyOf ui.grid.edit.api:ColumnDef
  13618. * @description enable editing on column
  13619. */
  13620. colDef.enableCellEdit = colDef.enableCellEdit === undefined ? (gridOptions.enableCellEdit === undefined ?
  13621. (colDef.type !== 'object') : gridOptions.enableCellEdit) : colDef.enableCellEdit;
  13622. /**
  13623. * @ngdoc object
  13624. * @name cellEditableCondition
  13625. * @propertyOf ui.grid.edit.api:ColumnDef
  13626. * @description If specified, either a value or function evaluated before editing cell. If falsy, then editing of cell is not allowed.
  13627. * @example
  13628. * <pre>
  13629. * function($scope){
  13630. * //use $scope.row.entity and $scope.col.colDef to determine if editing is allowed
  13631. * return true;
  13632. * }
  13633. * </pre>
  13634. */
  13635. colDef.cellEditableCondition = colDef.cellEditableCondition === undefined ? gridOptions.cellEditableCondition : colDef.cellEditableCondition;
  13636. /**
  13637. * @ngdoc object
  13638. * @name editableCellTemplate
  13639. * @propertyOf ui.grid.edit.api:ColumnDef
  13640. * @description cell template to be used when editing this column. Can be Url or text template
  13641. * <br/>Defaults to gridOptions.editableCellTemplate
  13642. */
  13643. if (colDef.enableCellEdit) {
  13644. colDef.editableCellTemplate = colDef.editableCellTemplate || gridOptions.editableCellTemplate || 'ui-grid/cellEditor';
  13645. promises.push(gridUtil.getTemplate(colDef.editableCellTemplate)
  13646. .then(
  13647. function (template) {
  13648. col.editableCellTemplate = template;
  13649. },
  13650. function (res) {
  13651. // Todo handle response error here?
  13652. throw new Error("Couldn't fetch/use colDef.editableCellTemplate '" + colDef.editableCellTemplate + "'");
  13653. }));
  13654. }
  13655. /**
  13656. * @ngdoc object
  13657. * @name enableCellEditOnFocus
  13658. * @propertyOf ui.grid.edit.api:ColumnDef
  13659. * @requires ui.grid.cellNav
  13660. * @description If true, then editor is invoked as soon as cell receives focus. Default false.
  13661. * <br>_requires both the cellNav feature and the edit feature to be enabled_
  13662. */
  13663. //enableCellEditOnFocus can only be used if cellnav module is used
  13664. colDef.enableCellEditOnFocus = colDef.enableCellEditOnFocus === undefined ? gridOptions.enableCellEditOnFocus : colDef.enableCellEditOnFocus;
  13665. /**
  13666. * @ngdoc string
  13667. * @name editModelField
  13668. * @propertyOf ui.grid.edit.api:ColumnDef
  13669. * @description a bindable string value that is used when binding to edit controls instead of colDef.field
  13670. * <br/> example: You have a complex property on and object like state:{abbrev:'MS',name:'Mississippi'}. The
  13671. * grid should display state.name in the cell and sort/filter based on the state.name property but the editor
  13672. * requires the full state object.
  13673. * <br/>colDef.field = 'state.name'
  13674. * <br/>colDef.editModelField = 'state'
  13675. */
  13676. //colDef.editModelField
  13677. return $q.all(promises);
  13678. },
  13679. /**
  13680. * @ngdoc service
  13681. * @name isStartEditKey
  13682. * @methodOf ui.grid.edit.service:uiGridEditService
  13683. * @description Determines if a keypress should start editing. Decorate this service to override with your
  13684. * own key events. See service decorator in angular docs.
  13685. * @param {Event} evt keydown event
  13686. * @returns {boolean} true if an edit should start
  13687. */
  13688. isStartEditKey: function (evt) {
  13689. if (evt.metaKey ||
  13690. evt.keyCode === uiGridConstants.keymap.ESC ||
  13691. evt.keyCode === uiGridConstants.keymap.SHIFT ||
  13692. evt.keyCode === uiGridConstants.keymap.CTRL ||
  13693. evt.keyCode === uiGridConstants.keymap.ALT ||
  13694. evt.keyCode === uiGridConstants.keymap.WIN ||
  13695. evt.keyCode === uiGridConstants.keymap.CAPSLOCK ||
  13696. evt.keyCode === uiGridConstants.keymap.LEFT ||
  13697. (evt.keyCode === uiGridConstants.keymap.TAB && evt.shiftKey) ||
  13698. evt.keyCode === uiGridConstants.keymap.RIGHT ||
  13699. evt.keyCode === uiGridConstants.keymap.TAB ||
  13700. evt.keyCode === uiGridConstants.keymap.UP ||
  13701. (evt.keyCode === uiGridConstants.keymap.ENTER && evt.shiftKey) ||
  13702. evt.keyCode === uiGridConstants.keymap.DOWN ||
  13703. evt.keyCode === uiGridConstants.keymap.ENTER) {
  13704. return false;
  13705. }
  13706. return true;
  13707. }
  13708. };
  13709. return service;
  13710. }]);
  13711. /**
  13712. * @ngdoc directive
  13713. * @name ui.grid.edit.directive:uiGridEdit
  13714. * @element div
  13715. * @restrict A
  13716. *
  13717. * @description Adds editing features to the ui-grid directive.
  13718. *
  13719. * @example
  13720. <example module="app">
  13721. <file name="app.js">
  13722. var app = angular.module('app', ['ui.grid', 'ui.grid.edit']);
  13723. app.controller('MainCtrl', ['$scope', function ($scope) {
  13724. $scope.data = [
  13725. { name: 'Bob', title: 'CEO' },
  13726. { name: 'Frank', title: 'Lowly Developer' }
  13727. ];
  13728. $scope.columnDefs = [
  13729. {name: 'name', enableCellEdit: true},
  13730. {name: 'title', enableCellEdit: true}
  13731. ];
  13732. }]);
  13733. </file>
  13734. <file name="index.html">
  13735. <div ng-controller="MainCtrl">
  13736. <div ui-grid="{ data: data, columnDefs: columnDefs }" ui-grid-edit></div>
  13737. </div>
  13738. </file>
  13739. </example>
  13740. */
  13741. module.directive('uiGridEdit', ['gridUtil', 'uiGridEditService', function (gridUtil, uiGridEditService) {
  13742. return {
  13743. replace: true,
  13744. priority: 0,
  13745. require: '^uiGrid',
  13746. scope: false,
  13747. compile: function () {
  13748. return {
  13749. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  13750. uiGridEditService.initializeGrid(uiGridCtrl.grid);
  13751. },
  13752. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  13753. }
  13754. };
  13755. }
  13756. };
  13757. }]);
  13758. /**
  13759. * @ngdoc directive
  13760. * @name ui.grid.edit.directive:uiGridRenderContainer
  13761. * @element div
  13762. * @restrict A
  13763. *
  13764. * @description Adds keydown listeners to renderContainer element so we can capture when to begin edits
  13765. *
  13766. */
  13767. module.directive('uiGridViewport', [ 'uiGridEditConstants',
  13768. function ( uiGridEditConstants) {
  13769. return {
  13770. replace: true,
  13771. priority: -99998, //run before cellNav
  13772. require: ['^uiGrid', '^uiGridRenderContainer'],
  13773. scope: false,
  13774. compile: function () {
  13775. return {
  13776. post: function ($scope, $elm, $attrs, controllers) {
  13777. var uiGridCtrl = controllers[0];
  13778. // Skip attaching if edit and cellNav is not enabled
  13779. if (!uiGridCtrl.grid.api.edit || !uiGridCtrl.grid.api.cellNav) { return; }
  13780. var containerId = controllers[1].containerId;
  13781. //no need to process for other containers
  13782. if (containerId !== 'body') {
  13783. return;
  13784. }
  13785. //refocus on the grid
  13786. $scope.$on(uiGridEditConstants.events.CANCEL_CELL_EDIT, function () {
  13787. uiGridCtrl.focus();
  13788. });
  13789. $scope.$on(uiGridEditConstants.events.END_CELL_EDIT, function () {
  13790. uiGridCtrl.focus();
  13791. });
  13792. }
  13793. };
  13794. }
  13795. };
  13796. }]);
  13797. /**
  13798. * @ngdoc directive
  13799. * @name ui.grid.edit.directive:uiGridCell
  13800. * @element div
  13801. * @restrict A
  13802. *
  13803. * @description Stacks on top of ui.grid.uiGridCell to provide in-line editing capabilities to the cell
  13804. * Editing Actions.
  13805. *
  13806. * Binds edit start events to the uiGridCell element. When the events fire, the gridCell element is appended
  13807. * with the columnDef.editableCellTemplate element ('cellEditor.html' by default).
  13808. *
  13809. * The editableCellTemplate should respond to uiGridEditConstants.events.BEGIN\_CELL\_EDIT angular event
  13810. * and do the initial steps needed to edit the cell (setfocus on input element, etc).
  13811. *
  13812. * When the editableCellTemplate recognizes that the editing is ended (blur event, Enter key, etc.)
  13813. * it should emit the uiGridEditConstants.events.END\_CELL\_EDIT event.
  13814. *
  13815. * If editableCellTemplate recognizes that the editing has been cancelled (esc key)
  13816. * it should emit the uiGridEditConstants.events.CANCEL\_CELL\_EDIT event. The original value
  13817. * will be set back on the model by the uiGridCell directive.
  13818. *
  13819. * Events that invoke editing:
  13820. * - dblclick
  13821. * - F2 keydown (when using cell selection)
  13822. *
  13823. * Events that end editing:
  13824. * - Dependent on the specific editableCellTemplate
  13825. * - Standards should be blur and enter keydown
  13826. *
  13827. * Events that cancel editing:
  13828. * - Dependent on the specific editableCellTemplate
  13829. * - Standards should be Esc keydown
  13830. *
  13831. * Grid Events that end editing:
  13832. * - uiGridConstants.events.GRID_SCROLL
  13833. *
  13834. */
  13835. /**
  13836. * @ngdoc object
  13837. * @name ui.grid.edit.api:GridRow
  13838. *
  13839. * @description GridRow options for edit feature, these are available to be
  13840. * set internally only, by other features
  13841. */
  13842. /**
  13843. * @ngdoc object
  13844. * @name enableCellEdit
  13845. * @propertyOf ui.grid.edit.api:GridRow
  13846. * @description enable editing on row, grouping for example might disable editing on group header rows
  13847. */
  13848. module.directive('uiGridCell',
  13849. ['$compile', '$injector', '$timeout', 'uiGridConstants', 'uiGridEditConstants', 'gridUtil', '$parse', 'uiGridEditService', '$rootScope', '$q',
  13850. function ($compile, $injector, $timeout, uiGridConstants, uiGridEditConstants, gridUtil, $parse, uiGridEditService, $rootScope, $q) {
  13851. var touchstartTimeout = 500;
  13852. if ($injector.has('uiGridCellNavService')) {
  13853. var uiGridCellNavService = $injector.get('uiGridCellNavService');
  13854. }
  13855. return {
  13856. priority: -100, // run after default uiGridCell directive
  13857. restrict: 'A',
  13858. scope: false,
  13859. require: '?^uiGrid',
  13860. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  13861. var html;
  13862. var origCellValue;
  13863. var inEdit = false;
  13864. var cellModel;
  13865. var cancelTouchstartTimeout;
  13866. var editCellScope;
  13867. if (!$scope.col.colDef.enableCellEdit) {
  13868. return;
  13869. }
  13870. var cellNavNavigateDereg = function() {};
  13871. var viewPortKeyDownDereg = function() {};
  13872. var setEditable = function() {
  13873. if ($scope.col.colDef.enableCellEdit && $scope.row.enableCellEdit !== false) {
  13874. if (!$scope.beginEditEventsWired) { //prevent multiple attachments
  13875. registerBeginEditEvents();
  13876. }
  13877. } else {
  13878. if ($scope.beginEditEventsWired) {
  13879. cancelBeginEditEvents();
  13880. }
  13881. }
  13882. };
  13883. setEditable();
  13884. var rowWatchDereg = $scope.$watch('row', function (n, o) {
  13885. if (n !== o) {
  13886. setEditable();
  13887. }
  13888. });
  13889. $scope.$on( '$destroy', rowWatchDereg );
  13890. function registerBeginEditEvents() {
  13891. $elm.on('dblclick', beginEdit);
  13892. // Add touchstart handling. If the users starts a touch and it doesn't end after X milliseconds, then start the edit
  13893. $elm.on('touchstart', touchStart);
  13894. if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) {
  13895. viewPortKeyDownDereg = uiGridCtrl.grid.api.cellNav.on.viewPortKeyDown($scope, function (evt, rowCol) {
  13896. if (rowCol === null) {
  13897. return;
  13898. }
  13899. if (rowCol.row === $scope.row && rowCol.col === $scope.col && !$scope.col.colDef.enableCellEditOnFocus) {
  13900. //important to do this before scrollToIfNecessary
  13901. beginEditKeyDown(evt);
  13902. }
  13903. });
  13904. cellNavNavigateDereg = uiGridCtrl.grid.api.cellNav.on.navigate($scope, function (newRowCol, oldRowCol) {
  13905. if ($scope.col.colDef.enableCellEditOnFocus) {
  13906. // Don't begin edit if the cell hasn't changed
  13907. if ((!oldRowCol || newRowCol.row !== oldRowCol.row || newRowCol.col !== oldRowCol.col) &&
  13908. newRowCol.row === $scope.row && newRowCol.col === $scope.col) {
  13909. $timeout(function () {
  13910. beginEdit();
  13911. });
  13912. }
  13913. }
  13914. });
  13915. }
  13916. $scope.beginEditEventsWired = true;
  13917. }
  13918. function touchStart(event) {
  13919. // jQuery masks events
  13920. if (typeof(event.originalEvent) !== 'undefined' && event.originalEvent !== undefined) {
  13921. event = event.originalEvent;
  13922. }
  13923. // Bind touchend handler
  13924. $elm.on('touchend', touchEnd);
  13925. // Start a timeout
  13926. cancelTouchstartTimeout = $timeout(function() { }, touchstartTimeout);
  13927. // Timeout's done! Start the edit
  13928. cancelTouchstartTimeout.then(function () {
  13929. // Use setTimeout to start the edit because beginEdit expects to be outside of $digest
  13930. setTimeout(beginEdit, 0);
  13931. // Undbind the touchend handler, we don't need it anymore
  13932. $elm.off('touchend', touchEnd);
  13933. });
  13934. }
  13935. // Cancel any touchstart timeout
  13936. function touchEnd(event) {
  13937. $timeout.cancel(cancelTouchstartTimeout);
  13938. $elm.off('touchend', touchEnd);
  13939. }
  13940. function cancelBeginEditEvents() {
  13941. $elm.off('dblclick', beginEdit);
  13942. $elm.off('keydown', beginEditKeyDown);
  13943. $elm.off('touchstart', touchStart);
  13944. cellNavNavigateDereg();
  13945. viewPortKeyDownDereg();
  13946. $scope.beginEditEventsWired = false;
  13947. }
  13948. function beginEditKeyDown(evt) {
  13949. if (uiGridEditService.isStartEditKey(evt)) {
  13950. beginEdit(evt);
  13951. }
  13952. }
  13953. function shouldEdit(col, row) {
  13954. return !row.isSaving &&
  13955. ( angular.isFunction(col.colDef.cellEditableCondition) ?
  13956. col.colDef.cellEditableCondition($scope) :
  13957. col.colDef.cellEditableCondition );
  13958. }
  13959. function beginEdit(triggerEvent) {
  13960. //we need to scroll the cell into focus before invoking the editor
  13961. $scope.grid.api.core.scrollToIfNecessary($scope.row, $scope.col)
  13962. .then(function () {
  13963. beginEditAfterScroll(triggerEvent);
  13964. });
  13965. }
  13966. /**
  13967. * @ngdoc property
  13968. * @name editDropdownOptionsArray
  13969. * @propertyOf ui.grid.edit.api:ColumnDef
  13970. * @description an array of values in the format
  13971. * [ {id: xxx, value: xxx} ], which is populated
  13972. * into the edit dropdown
  13973. *
  13974. */
  13975. /**
  13976. * @ngdoc property
  13977. * @name editDropdownIdLabel
  13978. * @propertyOf ui.grid.edit.api:ColumnDef
  13979. * @description the label for the "id" field
  13980. * in the editDropdownOptionsArray. Defaults
  13981. * to 'id'
  13982. * @example
  13983. * <pre>
  13984. * $scope.gridOptions = {
  13985. * columnDefs: [
  13986. * {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
  13987. * editDropdownOptionsArray: [{code: 1, status: 'active'}, {code: 2, status: 'inactive'}],
  13988. * editDropdownIdLabel: 'code', editDropdownValueLabel: 'status' }
  13989. * ],
  13990. * </pre>
  13991. *
  13992. */
  13993. /**
  13994. * @ngdoc property
  13995. * @name editDropdownRowEntityOptionsArrayPath
  13996. * @propertyOf ui.grid.edit.api:ColumnDef
  13997. * @description a path to a property on row.entity containing an
  13998. * array of values in the format
  13999. * [ {id: xxx, value: xxx} ], which will be used to populate
  14000. * the edit dropdown. This can be used when the dropdown values are dependent on
  14001. * the backing row entity.
  14002. * If this property is set then editDropdownOptionsArray will be ignored.
  14003. * @example
  14004. * <pre>
  14005. * $scope.gridOptions = {
  14006. * columnDefs: [
  14007. * {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
  14008. * editDropdownRowEntityOptionsArrayPath: 'foo.bars[0].baz',
  14009. * editDropdownIdLabel: 'code', editDropdownValueLabel: 'status' }
  14010. * ],
  14011. * </pre>
  14012. *
  14013. */
  14014. /**
  14015. * @ngdoc service
  14016. * @name editDropdownOptionsFunction
  14017. * @methodOf ui.grid.edit.api:ColumnDef
  14018. * @description a function returning an array of values in the format
  14019. * [ {id: xxx, value: xxx} ], which will be used to populate
  14020. * the edit dropdown. This can be used when the dropdown values are dependent on
  14021. * the backing row entity with some kind of algorithm.
  14022. * If this property is set then both editDropdownOptionsArray and
  14023. * editDropdownRowEntityOptionsArrayPath will be ignored.
  14024. * @param {object} rowEntity the options.data element that the returned array refers to
  14025. * @param {object} colDef the column that implements this dropdown
  14026. * @returns {object} an array of values in the format
  14027. * [ {id: xxx, value: xxx} ] used to populate the edit dropdown
  14028. * @example
  14029. * <pre>
  14030. * $scope.gridOptions = {
  14031. * columnDefs: [
  14032. * {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
  14033. * editDropdownOptionsFunction: function(rowEntity, colDef) {
  14034. * if (rowEntity.foo === 'bar') {
  14035. * return [{id: 'bar1', value: 'BAR 1'},
  14036. * {id: 'bar2', value: 'BAR 2'},
  14037. * {id: 'bar3', value: 'BAR 3'}];
  14038. * } else {
  14039. * return [{id: 'foo1', value: 'FOO 1'},
  14040. * {id: 'foo2', value: 'FOO 2'}];
  14041. * }
  14042. * },
  14043. * editDropdownIdLabel: 'code', editDropdownValueLabel: 'status' }
  14044. * ],
  14045. * </pre>
  14046. *
  14047. */
  14048. /**
  14049. * @ngdoc property
  14050. * @name editDropdownValueLabel
  14051. * @propertyOf ui.grid.edit.api:ColumnDef
  14052. * @description the label for the "value" field
  14053. * in the editDropdownOptionsArray. Defaults
  14054. * to 'value'
  14055. * @example
  14056. * <pre>
  14057. * $scope.gridOptions = {
  14058. * columnDefs: [
  14059. * {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
  14060. * editDropdownOptionsArray: [{code: 1, status: 'active'}, {code: 2, status: 'inactive'}],
  14061. * editDropdownIdLabel: 'code', editDropdownValueLabel: 'status' }
  14062. * ],
  14063. * </pre>
  14064. *
  14065. */
  14066. /**
  14067. * @ngdoc property
  14068. * @name editDropdownFilter
  14069. * @propertyOf ui.grid.edit.api:ColumnDef
  14070. * @description A filter that you would like to apply to the values in the options list
  14071. * of the dropdown. For example if you were using angular-translate you might set this
  14072. * to `'translate'`
  14073. * @example
  14074. * <pre>
  14075. * $scope.gridOptions = {
  14076. * columnDefs: [
  14077. * {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
  14078. * editDropdownOptionsArray: [{code: 1, status: 'active'}, {code: 2, status: 'inactive'}],
  14079. * editDropdownIdLabel: 'code', editDropdownValueLabel: 'status', editDropdownFilter: 'translate' }
  14080. * ],
  14081. * </pre>
  14082. *
  14083. */
  14084. function beginEditAfterScroll(triggerEvent) {
  14085. // If we are already editing, then just skip this so we don't try editing twice...
  14086. if (inEdit) {
  14087. return;
  14088. }
  14089. if (!shouldEdit($scope.col, $scope.row)) {
  14090. return;
  14091. }
  14092. cellModel = $parse($scope.row.getQualifiedColField($scope.col));
  14093. //get original value from the cell
  14094. origCellValue = cellModel($scope);
  14095. html = $scope.col.editableCellTemplate;
  14096. if ($scope.col.colDef.editModelField) {
  14097. html = html.replace(uiGridConstants.MODEL_COL_FIELD, gridUtil.preEval('row.entity.' + $scope.col.colDef.editModelField));
  14098. }
  14099. else {
  14100. html = html.replace(uiGridConstants.MODEL_COL_FIELD, $scope.row.getQualifiedColField($scope.col));
  14101. }
  14102. html = html.replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)');
  14103. var optionFilter = $scope.col.colDef.editDropdownFilter ? '|' + $scope.col.colDef.editDropdownFilter : '';
  14104. html = html.replace(uiGridConstants.CUSTOM_FILTERS, optionFilter);
  14105. var inputType = 'text';
  14106. switch ($scope.col.colDef.type){
  14107. case 'boolean':
  14108. inputType = 'checkbox';
  14109. break;
  14110. case 'number':
  14111. inputType = 'number';
  14112. break;
  14113. case 'date':
  14114. inputType = 'date';
  14115. break;
  14116. }
  14117. html = html.replace('INPUT_TYPE', inputType);
  14118. // In order to fill dropdown options we use:
  14119. // - A function/promise or
  14120. // - An array inside of row entity if no function exists or
  14121. // - A single array for the whole column if none of the previous exists.
  14122. var editDropdownOptionsFunction = $scope.col.colDef.editDropdownOptionsFunction;
  14123. if (editDropdownOptionsFunction) {
  14124. $q.when(editDropdownOptionsFunction($scope.row.entity, $scope.col.colDef))
  14125. .then(function(result) {
  14126. $scope.editDropdownOptionsArray = result;
  14127. });
  14128. } else {
  14129. var editDropdownRowEntityOptionsArrayPath = $scope.col.colDef.editDropdownRowEntityOptionsArrayPath;
  14130. if (editDropdownRowEntityOptionsArrayPath) {
  14131. $scope.editDropdownOptionsArray = resolveObjectFromPath($scope.row.entity, editDropdownRowEntityOptionsArrayPath);
  14132. }
  14133. else {
  14134. $scope.editDropdownOptionsArray = $scope.col.colDef.editDropdownOptionsArray;
  14135. }
  14136. }
  14137. $scope.editDropdownIdLabel = $scope.col.colDef.editDropdownIdLabel ? $scope.col.colDef.editDropdownIdLabel : 'id';
  14138. $scope.editDropdownValueLabel = $scope.col.colDef.editDropdownValueLabel ? $scope.col.colDef.editDropdownValueLabel : 'value';
  14139. var cellElement;
  14140. var createEditor = function(){
  14141. inEdit = true;
  14142. cancelBeginEditEvents();
  14143. var cellElement = angular.element(html);
  14144. $elm.append(cellElement);
  14145. editCellScope = $scope.$new();
  14146. $compile(cellElement)(editCellScope);
  14147. var gridCellContentsEl = angular.element($elm.children()[0]);
  14148. gridCellContentsEl.addClass('ui-grid-cell-contents-hidden');
  14149. };
  14150. if (!$rootScope.$$phase) {
  14151. $scope.$apply(createEditor);
  14152. } else {
  14153. createEditor();
  14154. }
  14155. //stop editing when grid is scrolled
  14156. var deregOnGridScroll = $scope.col.grid.api.core.on.scrollBegin($scope, function () {
  14157. if ($scope.grid.disableScrolling) {
  14158. return;
  14159. }
  14160. endEdit();
  14161. $scope.grid.api.edit.raise.afterCellEdit($scope.row.entity, $scope.col.colDef, cellModel($scope), origCellValue);
  14162. deregOnGridScroll();
  14163. deregOnEndCellEdit();
  14164. deregOnCancelCellEdit();
  14165. });
  14166. //end editing
  14167. var deregOnEndCellEdit = $scope.$on(uiGridEditConstants.events.END_CELL_EDIT, function () {
  14168. endEdit();
  14169. $scope.grid.api.edit.raise.afterCellEdit($scope.row.entity, $scope.col.colDef, cellModel($scope), origCellValue);
  14170. deregOnEndCellEdit();
  14171. deregOnGridScroll();
  14172. deregOnCancelCellEdit();
  14173. });
  14174. //cancel editing
  14175. var deregOnCancelCellEdit = $scope.$on(uiGridEditConstants.events.CANCEL_CELL_EDIT, function () {
  14176. cancelEdit();
  14177. deregOnCancelCellEdit();
  14178. deregOnGridScroll();
  14179. deregOnEndCellEdit();
  14180. });
  14181. $scope.$broadcast(uiGridEditConstants.events.BEGIN_CELL_EDIT, triggerEvent);
  14182. $timeout(function () {
  14183. //execute in a timeout to give any complex editor templates a cycle to completely render
  14184. $scope.grid.api.edit.raise.beginCellEdit($scope.row.entity, $scope.col.colDef, triggerEvent);
  14185. });
  14186. }
  14187. function endEdit() {
  14188. $scope.grid.disableScrolling = false;
  14189. if (!inEdit) {
  14190. return;
  14191. }
  14192. //sometimes the events can't keep up with the keyboard and grid focus is lost, so always focus
  14193. //back to grid here. The focus call needs to be before the $destroy and removal of the control,
  14194. //otherwise ng-model-options of UpdateOn: 'blur' will not work.
  14195. if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) {
  14196. uiGridCtrl.focus();
  14197. }
  14198. var gridCellContentsEl = angular.element($elm.children()[0]);
  14199. //remove edit element
  14200. editCellScope.$destroy();
  14201. angular.element($elm.children()[1]).remove();
  14202. gridCellContentsEl.removeClass('ui-grid-cell-contents-hidden');
  14203. inEdit = false;
  14204. registerBeginEditEvents();
  14205. $scope.grid.api.core.notifyDataChange( uiGridConstants.dataChange.EDIT );
  14206. }
  14207. function cancelEdit() {
  14208. $scope.grid.disableScrolling = false;
  14209. if (!inEdit) {
  14210. return;
  14211. }
  14212. cellModel.assign($scope, origCellValue);
  14213. $scope.$apply();
  14214. $scope.grid.api.edit.raise.cancelCellEdit($scope.row.entity, $scope.col.colDef);
  14215. endEdit();
  14216. }
  14217. // resolves a string path against the given object
  14218. // shamelessly borrowed from
  14219. // http://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key
  14220. function resolveObjectFromPath(object, path) {
  14221. path = path.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
  14222. path = path.replace(/^\./, ''); // strip a leading dot
  14223. var a = path.split('.');
  14224. while (a.length) {
  14225. var n = a.shift();
  14226. if (n in object) {
  14227. object = object[n];
  14228. } else {
  14229. return;
  14230. }
  14231. }
  14232. return object;
  14233. }
  14234. }
  14235. };
  14236. }]);
  14237. /**
  14238. * @ngdoc directive
  14239. * @name ui.grid.edit.directive:uiGridEditor
  14240. * @element div
  14241. * @restrict A
  14242. *
  14243. * @description input editor directive for editable fields.
  14244. * Provides EndEdit and CancelEdit events
  14245. *
  14246. * Events that end editing:
  14247. * blur and enter keydown
  14248. *
  14249. * Events that cancel editing:
  14250. * - Esc keydown
  14251. *
  14252. */
  14253. module.directive('uiGridEditor',
  14254. ['gridUtil', 'uiGridConstants', 'uiGridEditConstants','$timeout', 'uiGridEditService',
  14255. function (gridUtil, uiGridConstants, uiGridEditConstants, $timeout, uiGridEditService) {
  14256. return {
  14257. scope: true,
  14258. require: ['?^uiGrid', '?^uiGridRenderContainer', 'ngModel'],
  14259. compile: function () {
  14260. return {
  14261. pre: function ($scope, $elm, $attrs) {
  14262. },
  14263. post: function ($scope, $elm, $attrs, controllers) {
  14264. var uiGridCtrl, renderContainerCtrl, ngModel;
  14265. if (controllers[0]) { uiGridCtrl = controllers[0]; }
  14266. if (controllers[1]) { renderContainerCtrl = controllers[1]; }
  14267. if (controllers[2]) { ngModel = controllers[2]; }
  14268. //set focus at start of edit
  14269. $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function (evt,triggerEvent) {
  14270. $timeout(function () {
  14271. $elm[0].focus();
  14272. //only select text if it is not being replaced below in the cellNav viewPortKeyPress
  14273. if ($elm[0].select && $scope.col.colDef.enableCellEditOnFocus || !(uiGridCtrl && uiGridCtrl.grid.api.cellNav)) {
  14274. $elm[0].select();
  14275. }
  14276. else {
  14277. //some browsers (Chrome) stupidly, imo, support the w3 standard that number, email, ...
  14278. //fields should not allow setSelectionRange. We ignore the error for those browsers
  14279. //https://www.w3.org/Bugs/Public/show_bug.cgi?id=24796
  14280. try {
  14281. $elm[0].setSelectionRange($elm[0].value.length, $elm[0].value.length);
  14282. }
  14283. catch (ex) {
  14284. //ignore
  14285. }
  14286. }
  14287. });
  14288. //set the keystroke that started the edit event
  14289. //we must do this because the BeginEdit is done in a different event loop than the intitial
  14290. //keydown event
  14291. //fire this event for the keypress that is received
  14292. if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) {
  14293. var viewPortKeyDownUnregister = uiGridCtrl.grid.api.cellNav.on.viewPortKeyPress($scope, function (evt, rowCol) {
  14294. if (uiGridEditService.isStartEditKey(evt)) {
  14295. ngModel.$setViewValue(String.fromCharCode( typeof evt.which === 'number' ? evt.which : evt.keyCode), evt);
  14296. ngModel.$render();
  14297. }
  14298. viewPortKeyDownUnregister();
  14299. });
  14300. }
  14301. $elm.on('blur', function (evt) {
  14302. $scope.stopEdit(evt);
  14303. });
  14304. });
  14305. $scope.deepEdit = false;
  14306. $scope.stopEdit = function (evt) {
  14307. if ($scope.inputForm && !$scope.inputForm.$valid) {
  14308. evt.stopPropagation();
  14309. $scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
  14310. }
  14311. else {
  14312. $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
  14313. }
  14314. $scope.deepEdit = false;
  14315. };
  14316. $elm.on('click', function (evt) {
  14317. if ($elm[0].type !== 'checkbox') {
  14318. $scope.deepEdit = true;
  14319. $timeout(function () {
  14320. $scope.grid.disableScrolling = true;
  14321. });
  14322. }
  14323. });
  14324. $elm.on('keydown', function (evt) {
  14325. switch (evt.keyCode) {
  14326. case uiGridConstants.keymap.ESC:
  14327. evt.stopPropagation();
  14328. $scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
  14329. break;
  14330. }
  14331. if ($scope.deepEdit &&
  14332. (evt.keyCode === uiGridConstants.keymap.LEFT ||
  14333. evt.keyCode === uiGridConstants.keymap.RIGHT ||
  14334. evt.keyCode === uiGridConstants.keymap.UP ||
  14335. evt.keyCode === uiGridConstants.keymap.DOWN)) {
  14336. evt.stopPropagation();
  14337. }
  14338. // Pass the keydown event off to the cellNav service, if it exists
  14339. else if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) {
  14340. evt.uiGridTargetRenderContainerId = renderContainerCtrl.containerId;
  14341. if (uiGridCtrl.cellNav.handleKeyDown(evt) !== null) {
  14342. $scope.stopEdit(evt);
  14343. }
  14344. }
  14345. else {
  14346. //handle enter and tab for editing not using cellNav
  14347. switch (evt.keyCode) {
  14348. case uiGridConstants.keymap.ENTER: // Enter (Leave Field)
  14349. case uiGridConstants.keymap.TAB:
  14350. evt.stopPropagation();
  14351. evt.preventDefault();
  14352. $scope.stopEdit(evt);
  14353. break;
  14354. }
  14355. }
  14356. return true;
  14357. });
  14358. }
  14359. };
  14360. }
  14361. };
  14362. }]);
  14363. /**
  14364. * @ngdoc directive
  14365. * @name ui.grid.edit.directive:input
  14366. * @element input
  14367. * @restrict E
  14368. *
  14369. * @description directive to provide binding between input[date] value and ng-model for angular 1.2
  14370. * It is similar to input[date] directive of angular 1.3
  14371. *
  14372. * Supported date format for input is 'yyyy-MM-dd'
  14373. * The directive will set the $valid property of input element and the enclosing form to false if
  14374. * model is invalid date or value of input is entered wrong.
  14375. *
  14376. */
  14377. module.directive('uiGridEditor', ['$filter', function ($filter) {
  14378. function parseDateString(dateString) {
  14379. if (typeof(dateString) === 'undefined' || dateString === '') {
  14380. return null;
  14381. }
  14382. var parts = dateString.split('-');
  14383. if (parts.length !== 3) {
  14384. return null;
  14385. }
  14386. var year = parseInt(parts[0], 10);
  14387. var month = parseInt(parts[1], 10);
  14388. var day = parseInt(parts[2], 10);
  14389. if (month < 1 || year < 1 || day < 1) {
  14390. return null;
  14391. }
  14392. return new Date(year, (month - 1), day);
  14393. }
  14394. return {
  14395. priority: -100, // run after default uiGridEditor directive
  14396. require: '?ngModel',
  14397. link: function (scope, element, attrs, ngModel) {
  14398. if (angular.version.minor === 2 && attrs.type && attrs.type === 'date' && ngModel) {
  14399. ngModel.$formatters.push(function (modelValue) {
  14400. ngModel.$setValidity(null,(!modelValue || !isNaN(modelValue.getTime())));
  14401. return $filter('date')(modelValue, 'yyyy-MM-dd');
  14402. });
  14403. ngModel.$parsers.push(function (viewValue) {
  14404. if (viewValue && viewValue.length > 0) {
  14405. var dateValue = parseDateString(viewValue);
  14406. ngModel.$setValidity(null, (dateValue && !isNaN(dateValue.getTime())));
  14407. return dateValue;
  14408. }
  14409. else {
  14410. ngModel.$setValidity(null, true);
  14411. return null;
  14412. }
  14413. });
  14414. }
  14415. }
  14416. };
  14417. }]);
  14418. /**
  14419. * @ngdoc directive
  14420. * @name ui.grid.edit.directive:uiGridEditDropdown
  14421. * @element div
  14422. * @restrict A
  14423. *
  14424. * @description dropdown editor for editable fields.
  14425. * Provides EndEdit and CancelEdit events
  14426. *
  14427. * Events that end editing:
  14428. * blur and enter keydown, and any left/right nav
  14429. *
  14430. * Events that cancel editing:
  14431. * - Esc keydown
  14432. *
  14433. */
  14434. module.directive('uiGridEditDropdown',
  14435. ['uiGridConstants', 'uiGridEditConstants',
  14436. function (uiGridConstants, uiGridEditConstants) {
  14437. return {
  14438. require: ['?^uiGrid', '?^uiGridRenderContainer'],
  14439. scope: true,
  14440. compile: function () {
  14441. return {
  14442. pre: function ($scope, $elm, $attrs) {
  14443. },
  14444. post: function ($scope, $elm, $attrs, controllers) {
  14445. var uiGridCtrl = controllers[0];
  14446. var renderContainerCtrl = controllers[1];
  14447. //set focus at start of edit
  14448. $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () {
  14449. $elm[0].focus();
  14450. $elm[0].style.width = ($elm[0].parentElement.offsetWidth - 1) + 'px';
  14451. $elm.on('blur', function (evt) {
  14452. $scope.stopEdit(evt);
  14453. });
  14454. });
  14455. $scope.stopEdit = function (evt) {
  14456. // no need to validate a dropdown - invalid values shouldn't be
  14457. // available in the list
  14458. $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
  14459. };
  14460. $elm.on('keydown', function (evt) {
  14461. switch (evt.keyCode) {
  14462. case uiGridConstants.keymap.ESC:
  14463. evt.stopPropagation();
  14464. $scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
  14465. break;
  14466. }
  14467. if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) {
  14468. evt.uiGridTargetRenderContainerId = renderContainerCtrl.containerId;
  14469. if (uiGridCtrl.cellNav.handleKeyDown(evt) !== null) {
  14470. $scope.stopEdit(evt);
  14471. }
  14472. }
  14473. else {
  14474. //handle enter and tab for editing not using cellNav
  14475. switch (evt.keyCode) {
  14476. case uiGridConstants.keymap.ENTER: // Enter (Leave Field)
  14477. case uiGridConstants.keymap.TAB:
  14478. evt.stopPropagation();
  14479. evt.preventDefault();
  14480. $scope.stopEdit(evt);
  14481. break;
  14482. }
  14483. }
  14484. return true;
  14485. });
  14486. }
  14487. };
  14488. }
  14489. };
  14490. }]);
  14491. /**
  14492. * @ngdoc directive
  14493. * @name ui.grid.edit.directive:uiGridEditFileChooser
  14494. * @element div
  14495. * @restrict A
  14496. *
  14497. * @description input editor directive for editable fields.
  14498. * Provides EndEdit and CancelEdit events
  14499. *
  14500. * Events that end editing:
  14501. * blur and enter keydown
  14502. *
  14503. * Events that cancel editing:
  14504. * - Esc keydown
  14505. *
  14506. */
  14507. module.directive('uiGridEditFileChooser',
  14508. ['gridUtil', 'uiGridConstants', 'uiGridEditConstants','$timeout',
  14509. function (gridUtil, uiGridConstants, uiGridEditConstants, $timeout) {
  14510. return {
  14511. scope: true,
  14512. require: ['?^uiGrid', '?^uiGridRenderContainer'],
  14513. compile: function () {
  14514. return {
  14515. pre: function ($scope, $elm, $attrs) {
  14516. },
  14517. post: function ($scope, $elm, $attrs, controllers) {
  14518. var uiGridCtrl, renderContainerCtrl;
  14519. if (controllers[0]) { uiGridCtrl = controllers[0]; }
  14520. if (controllers[1]) { renderContainerCtrl = controllers[1]; }
  14521. var grid = uiGridCtrl.grid;
  14522. var handleFileSelect = function( event ){
  14523. var target = event.srcElement || event.target;
  14524. if (target && target.files && target.files.length > 0) {
  14525. /**
  14526. * @ngdoc property
  14527. * @name editFileChooserCallback
  14528. * @propertyOf ui.grid.edit.api:ColumnDef
  14529. * @description A function that should be called when any files have been chosen
  14530. * by the user. You should use this to process the files appropriately for your
  14531. * application.
  14532. *
  14533. * It passes the gridCol, the gridRow (from which you can get gridRow.entity),
  14534. * and the files. The files are in the format as returned from the file chooser,
  14535. * an array of files, with each having useful information such as:
  14536. * - `files[0].lastModifiedDate`
  14537. * - `files[0].name`
  14538. * - `files[0].size` (appears to be in bytes)
  14539. * - `files[0].type` (MIME type by the looks)
  14540. *
  14541. * Typically you would do something with these files - most commonly you would
  14542. * use the filename or read the file itself in. The example function does both.
  14543. *
  14544. * @example
  14545. * <pre>
  14546. * editFileChooserCallBack: function(gridRow, gridCol, files ){
  14547. * // ignore all but the first file, it can only choose one anyway
  14548. * // set the filename into this column
  14549. * gridRow.entity.filename = file[0].name;
  14550. *
  14551. * // read the file and set it into a hidden column, which we may do stuff with later
  14552. * var setFile = function(fileContent){
  14553. * gridRow.entity.file = fileContent.currentTarget.result;
  14554. * };
  14555. * var reader = new FileReader();
  14556. * reader.onload = setFile;
  14557. * reader.readAsText( files[0] );
  14558. * }
  14559. * </pre>
  14560. */
  14561. if ( typeof($scope.col.colDef.editFileChooserCallback) === 'function' ) {
  14562. $scope.col.colDef.editFileChooserCallback($scope.row, $scope.col, target.files);
  14563. } else {
  14564. gridUtil.logError('You need to set colDef.editFileChooserCallback to use the file chooser');
  14565. }
  14566. target.form.reset();
  14567. $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
  14568. } else {
  14569. $scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
  14570. }
  14571. };
  14572. $elm[0].addEventListener('change', handleFileSelect, false); // TODO: why the false on the end? Google
  14573. $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () {
  14574. $elm[0].focus();
  14575. $elm[0].select();
  14576. $elm.on('blur', function (evt) {
  14577. $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
  14578. });
  14579. });
  14580. }
  14581. };
  14582. }
  14583. };
  14584. }]);
  14585. })();
  14586. (function () {
  14587. 'use strict';
  14588. /**
  14589. * @ngdoc overview
  14590. * @name ui.grid.expandable
  14591. * @description
  14592. *
  14593. * # ui.grid.expandable
  14594. *
  14595. * <div class="alert alert-warning" role="alert"><strong>Alpha</strong> This feature is in development. There will almost certainly be breaking api changes, or there are major outstanding bugs.</div>
  14596. *
  14597. * This module provides the ability to create subgrids with the ability to expand a row
  14598. * to show the subgrid.
  14599. *
  14600. * <div doc-module-components="ui.grid.expandable"></div>
  14601. */
  14602. var module = angular.module('ui.grid.expandable', ['ui.grid']);
  14603. /**
  14604. * @ngdoc service
  14605. * @name ui.grid.expandable.service:uiGridExpandableService
  14606. *
  14607. * @description Services for the expandable grid
  14608. */
  14609. module.service('uiGridExpandableService', ['gridUtil', '$compile', function (gridUtil, $compile) {
  14610. var service = {
  14611. initializeGrid: function (grid) {
  14612. grid.expandable = {};
  14613. grid.expandable.expandedAll = false;
  14614. /**
  14615. * @ngdoc object
  14616. * @name enableExpandable
  14617. * @propertyOf ui.grid.expandable.api:GridOptions
  14618. * @description Whether or not to use expandable feature, allows you to turn off expandable on specific grids
  14619. * within your application, or in specific modes on _this_ grid. Defaults to true.
  14620. * @example
  14621. * <pre>
  14622. * $scope.gridOptions = {
  14623. * enableExpandable: false
  14624. * }
  14625. * </pre>
  14626. */
  14627. grid.options.enableExpandable = grid.options.enableExpandable !== false;
  14628. /**
  14629. * @ngdoc object
  14630. * @name expandableRowHeight
  14631. * @propertyOf ui.grid.expandable.api:GridOptions
  14632. * @description Height in pixels of the expanded subgrid. Defaults to
  14633. * 150
  14634. * @example
  14635. * <pre>
  14636. * $scope.gridOptions = {
  14637. * expandableRowHeight: 150
  14638. * }
  14639. * </pre>
  14640. */
  14641. grid.options.expandableRowHeight = grid.options.expandableRowHeight || 150;
  14642. /**
  14643. * @ngdoc object
  14644. * @name
  14645. * @propertyOf ui.grid.expandable.api:GridOptions
  14646. * @description Width in pixels of the expandable column. Defaults to 40
  14647. * @example
  14648. * <pre>
  14649. * $scope.gridOptions = {
  14650. * expandableRowHeaderWidth: 40
  14651. * }
  14652. * </pre>
  14653. */
  14654. grid.options.expandableRowHeaderWidth = grid.options.expandableRowHeaderWidth || 40;
  14655. /**
  14656. * @ngdoc object
  14657. * @name expandableRowTemplate
  14658. * @propertyOf ui.grid.expandable.api:GridOptions
  14659. * @description Mandatory. The template for your expanded row
  14660. * @example
  14661. * <pre>
  14662. * $scope.gridOptions = {
  14663. * expandableRowTemplate: 'expandableRowTemplate.html'
  14664. * }
  14665. * </pre>
  14666. */
  14667. if ( grid.options.enableExpandable && !grid.options.expandableRowTemplate ){
  14668. gridUtil.logError( 'You have not set the expandableRowTemplate, disabling expandable module' );
  14669. grid.options.enableExpandable = false;
  14670. }
  14671. /**
  14672. * @ngdoc object
  14673. * @name ui.grid.expandable.api:PublicApi
  14674. *
  14675. * @description Public Api for expandable feature
  14676. */
  14677. /**
  14678. * @ngdoc object
  14679. * @name ui.grid.expandable.api:GridRow
  14680. *
  14681. * @description Additional properties added to GridRow when using the expandable module
  14682. */
  14683. /**
  14684. * @ngdoc object
  14685. * @name ui.grid.expandable.api:GridOptions
  14686. *
  14687. * @description Options for configuring the expandable feature, these are available to be
  14688. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  14689. */
  14690. var publicApi = {
  14691. events: {
  14692. expandable: {
  14693. /**
  14694. * @ngdoc event
  14695. * @name rowExpandedStateChanged
  14696. * @eventOf ui.grid.expandable.api:PublicApi
  14697. * @description raised when cell editing is complete
  14698. * <pre>
  14699. * gridApi.expandable.on.rowExpandedStateChanged(scope,function(row){})
  14700. * </pre>
  14701. * @param {GridRow} row the row that was expanded
  14702. */
  14703. rowExpandedBeforeStateChanged: function(scope,row){
  14704. },
  14705. rowExpandedStateChanged: function (scope, row) {
  14706. }
  14707. }
  14708. },
  14709. methods: {
  14710. expandable: {
  14711. /**
  14712. * @ngdoc method
  14713. * @name toggleRowExpansion
  14714. * @methodOf ui.grid.expandable.api:PublicApi
  14715. * @description Toggle a specific row
  14716. * <pre>
  14717. * gridApi.expandable.toggleRowExpansion(rowEntity);
  14718. * </pre>
  14719. * @param {object} rowEntity the data entity for the row you want to expand
  14720. */
  14721. toggleRowExpansion: function (rowEntity) {
  14722. var row = grid.getRow(rowEntity);
  14723. if (row !== null) {
  14724. service.toggleRowExpansion(grid, row);
  14725. }
  14726. },
  14727. /**
  14728. * @ngdoc method
  14729. * @name expandAllRows
  14730. * @methodOf ui.grid.expandable.api:PublicApi
  14731. * @description Expand all subgrids.
  14732. * <pre>
  14733. * gridApi.expandable.expandAllRows();
  14734. * </pre>
  14735. */
  14736. expandAllRows: function() {
  14737. service.expandAllRows(grid);
  14738. },
  14739. /**
  14740. * @ngdoc method
  14741. * @name collapseAllRows
  14742. * @methodOf ui.grid.expandable.api:PublicApi
  14743. * @description Collapse all subgrids.
  14744. * <pre>
  14745. * gridApi.expandable.collapseAllRows();
  14746. * </pre>
  14747. */
  14748. collapseAllRows: function() {
  14749. service.collapseAllRows(grid);
  14750. },
  14751. /**
  14752. * @ngdoc method
  14753. * @name toggleAllRows
  14754. * @methodOf ui.grid.expandable.api:PublicApi
  14755. * @description Toggle all subgrids.
  14756. * <pre>
  14757. * gridApi.expandable.toggleAllRows();
  14758. * </pre>
  14759. */
  14760. toggleAllRows: function() {
  14761. service.toggleAllRows(grid);
  14762. },
  14763. /**
  14764. * @ngdoc function
  14765. * @name expandRow
  14766. * @methodOf ui.grid.expandable.api:PublicApi
  14767. * @description Expand the data row
  14768. * @param {object} rowEntity gridOptions.data[] array instance
  14769. */
  14770. expandRow: function (rowEntity) {
  14771. var row = grid.getRow(rowEntity);
  14772. if (row !== null && !row.isExpanded) {
  14773. service.toggleRowExpansion(grid, row);
  14774. }
  14775. },
  14776. /**
  14777. * @ngdoc function
  14778. * @name collapseRow
  14779. * @methodOf ui.grid.expandable.api:PublicApi
  14780. * @description Collapse the data row
  14781. * @param {object} rowEntity gridOptions.data[] array instance
  14782. */
  14783. collapseRow: function (rowEntity) {
  14784. var row = grid.getRow(rowEntity);
  14785. if (row !== null && row.isExpanded) {
  14786. service.toggleRowExpansion(grid, row);
  14787. }
  14788. },
  14789. /**
  14790. * @ngdoc function
  14791. * @name getExpandedRows
  14792. * @methodOf ui.grid.expandable.api:PublicApi
  14793. * @description returns all expandedRow's entity references
  14794. */
  14795. getExpandedRows: function () {
  14796. return service.getExpandedRows(grid).map(function (gridRow) {
  14797. return gridRow.entity;
  14798. });
  14799. }
  14800. }
  14801. }
  14802. };
  14803. grid.api.registerEventsFromObject(publicApi.events);
  14804. grid.api.registerMethodsFromObject(publicApi.methods);
  14805. },
  14806. toggleRowExpansion: function (grid, row) {
  14807. // trigger the "before change" event. Can change row height dynamically this way.
  14808. grid.api.expandable.raise.rowExpandedBeforeStateChanged(row);
  14809. /**
  14810. * @ngdoc object
  14811. * @name isExpanded
  14812. * @propertyOf ui.grid.expandable.api:GridRow
  14813. * @description Whether or not the row is currently expanded.
  14814. * @example
  14815. * <pre>
  14816. * $scope.api.expandable.on.rowExpandedStateChanged($scope, function (row) {
  14817. * if (row.isExpanded) {
  14818. * //...
  14819. * }
  14820. * });
  14821. * </pre>
  14822. */
  14823. row.isExpanded = !row.isExpanded;
  14824. if (angular.isUndefined(row.expandedRowHeight)){
  14825. row.expandedRowHeight = grid.options.expandableRowHeight;
  14826. }
  14827. if (row.isExpanded) {
  14828. row.height = row.grid.options.rowHeight + row.expandedRowHeight;
  14829. }
  14830. else {
  14831. row.height = row.grid.options.rowHeight;
  14832. grid.expandable.expandedAll = false;
  14833. }
  14834. grid.api.expandable.raise.rowExpandedStateChanged(row);
  14835. },
  14836. expandAllRows: function(grid, $scope) {
  14837. grid.renderContainers.body.visibleRowCache.forEach( function(row) {
  14838. if (!row.isExpanded) {
  14839. service.toggleRowExpansion(grid, row);
  14840. }
  14841. });
  14842. grid.expandable.expandedAll = true;
  14843. grid.queueGridRefresh();
  14844. },
  14845. collapseAllRows: function(grid) {
  14846. grid.renderContainers.body.visibleRowCache.forEach( function(row) {
  14847. if (row.isExpanded) {
  14848. service.toggleRowExpansion(grid, row);
  14849. }
  14850. });
  14851. grid.expandable.expandedAll = false;
  14852. grid.queueGridRefresh();
  14853. },
  14854. toggleAllRows: function(grid) {
  14855. if (grid.expandable.expandedAll) {
  14856. service.collapseAllRows(grid);
  14857. }
  14858. else {
  14859. service.expandAllRows(grid);
  14860. }
  14861. },
  14862. getExpandedRows: function (grid) {
  14863. return grid.rows.filter(function (row) {
  14864. return row.isExpanded;
  14865. });
  14866. }
  14867. };
  14868. return service;
  14869. }]);
  14870. /**
  14871. * @ngdoc object
  14872. * @name enableExpandableRowHeader
  14873. * @propertyOf ui.grid.expandable.api:GridOptions
  14874. * @description Show a rowHeader to provide the expandable buttons. If set to false then implies
  14875. * you're going to use a custom method for expanding and collapsing the subgrids. Defaults to true.
  14876. * @example
  14877. * <pre>
  14878. * $scope.gridOptions = {
  14879. * enableExpandableRowHeader: false
  14880. * }
  14881. * </pre>
  14882. */
  14883. module.directive('uiGridExpandable', ['uiGridExpandableService', '$templateCache',
  14884. function (uiGridExpandableService, $templateCache) {
  14885. return {
  14886. replace: true,
  14887. priority: 0,
  14888. require: '^uiGrid',
  14889. scope: false,
  14890. compile: function () {
  14891. return {
  14892. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  14893. if ( uiGridCtrl.grid.options.enableExpandableRowHeader !== false ) {
  14894. var expandableRowHeaderColDef = {
  14895. name: 'expandableButtons',
  14896. displayName: '',
  14897. exporterSuppressExport: true,
  14898. enableColumnResizing: false,
  14899. enableColumnMenu: false,
  14900. width: uiGridCtrl.grid.options.expandableRowHeaderWidth || 40
  14901. };
  14902. expandableRowHeaderColDef.cellTemplate = $templateCache.get('ui-grid/expandableRowHeader');
  14903. expandableRowHeaderColDef.headerCellTemplate = $templateCache.get('ui-grid/expandableTopRowHeader');
  14904. uiGridCtrl.grid.addRowHeaderColumn(expandableRowHeaderColDef);
  14905. }
  14906. uiGridExpandableService.initializeGrid(uiGridCtrl.grid);
  14907. },
  14908. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  14909. }
  14910. };
  14911. }
  14912. };
  14913. }]);
  14914. /**
  14915. * @ngdoc directive
  14916. * @name ui.grid.expandable.directive:uiGrid
  14917. * @description stacks on the uiGrid directive to register child grid with parent row when child is created
  14918. */
  14919. module.directive('uiGrid', ['uiGridExpandableService', '$templateCache',
  14920. function (uiGridExpandableService, $templateCache) {
  14921. return {
  14922. replace: true,
  14923. priority: 599,
  14924. require: '^uiGrid',
  14925. scope: false,
  14926. compile: function () {
  14927. return {
  14928. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  14929. uiGridCtrl.grid.api.core.on.renderingComplete($scope, function() {
  14930. //if a parent grid row is on the scope, then add the parentRow property to this childGrid
  14931. if ($scope.row && $scope.row.grid && $scope.row.grid.options && $scope.row.grid.options.enableExpandable) {
  14932. /**
  14933. * @ngdoc directive
  14934. * @name ui.grid.expandable.class:Grid
  14935. * @description Additional Grid properties added by expandable module
  14936. */
  14937. /**
  14938. * @ngdoc object
  14939. * @name parentRow
  14940. * @propertyOf ui.grid.expandable.class:Grid
  14941. * @description reference to the expanded parent row that owns this grid
  14942. */
  14943. uiGridCtrl.grid.parentRow = $scope.row;
  14944. //todo: adjust height on parent row when child grid height changes. we need some sort of gridHeightChanged event
  14945. // uiGridCtrl.grid.core.on.canvasHeightChanged($scope, function(oldHeight, newHeight) {
  14946. // uiGridCtrl.grid.parentRow = newHeight;
  14947. // });
  14948. }
  14949. });
  14950. },
  14951. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  14952. }
  14953. };
  14954. }
  14955. };
  14956. }]);
  14957. /**
  14958. * @ngdoc directive
  14959. * @name ui.grid.expandable.directive:uiGridExpandableRow
  14960. * @description directive to render the expandable row template
  14961. */
  14962. module.directive('uiGridExpandableRow',
  14963. ['uiGridExpandableService', '$timeout', '$compile', 'uiGridConstants','gridUtil','$interval', '$log',
  14964. function (uiGridExpandableService, $timeout, $compile, uiGridConstants, gridUtil, $interval, $log) {
  14965. return {
  14966. replace: false,
  14967. priority: 0,
  14968. scope: false,
  14969. compile: function () {
  14970. return {
  14971. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  14972. gridUtil.getTemplate($scope.grid.options.expandableRowTemplate).then(
  14973. function (template) {
  14974. if ($scope.grid.options.expandableRowScope) {
  14975. var expandableRowScope = $scope.grid.options.expandableRowScope;
  14976. for (var property in expandableRowScope) {
  14977. if (expandableRowScope.hasOwnProperty(property)) {
  14978. $scope[property] = expandableRowScope[property];
  14979. }
  14980. }
  14981. }
  14982. var expandedRowElement = $compile(template)($scope);
  14983. $elm.append(expandedRowElement);
  14984. $scope.row.expandedRendered = true;
  14985. });
  14986. },
  14987. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  14988. $scope.$on('$destroy', function() {
  14989. $scope.row.expandedRendered = false;
  14990. });
  14991. }
  14992. };
  14993. }
  14994. };
  14995. }]);
  14996. /**
  14997. * @ngdoc directive
  14998. * @name ui.grid.expandable.directive:uiGridRow
  14999. * @description stacks on the uiGridRow directive to add support for expandable rows
  15000. */
  15001. module.directive('uiGridRow',
  15002. ['$compile', 'gridUtil', '$templateCache',
  15003. function ($compile, gridUtil, $templateCache) {
  15004. return {
  15005. priority: -200,
  15006. scope: false,
  15007. compile: function ($elm, $attrs) {
  15008. return {
  15009. pre: function ($scope, $elm, $attrs, controllers) {
  15010. $scope.expandableRow = {};
  15011. $scope.expandableRow.shouldRenderExpand = function () {
  15012. var ret = $scope.colContainer.name === 'body' && $scope.grid.options.enableExpandable !== false && $scope.row.isExpanded && (!$scope.grid.isScrollingVertically || $scope.row.expandedRendered);
  15013. return ret;
  15014. };
  15015. $scope.expandableRow.shouldRenderFiller = function () {
  15016. var ret = $scope.row.isExpanded && ( $scope.colContainer.name !== 'body' || ($scope.grid.isScrollingVertically && !$scope.row.expandedRendered));
  15017. return ret;
  15018. };
  15019. /*
  15020. * Commented out @PaulL1. This has no purpose that I can see, and causes #2964. If this code needs to be reinstated for some
  15021. * reason it needs to use drawnWidth, not width, and needs to check column visibility. It should really use render container
  15022. * visible column cache also instead of checking column.renderContainer.
  15023. function updateRowContainerWidth() {
  15024. var grid = $scope.grid;
  15025. var colWidth = 0;
  15026. grid.columns.forEach( function (column) {
  15027. if (column.renderContainer === 'left') {
  15028. colWidth += column.width;
  15029. }
  15030. });
  15031. colWidth = Math.floor(colWidth);
  15032. return '.grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.colContainer.name + ', .grid' + grid.id +
  15033. ' .ui-grid-pinned-container-' + $scope.colContainer.name + ' .ui-grid-render-container-' + $scope.colContainer.name +
  15034. ' .ui-grid-viewport .ui-grid-canvas .ui-grid-row { width: ' + colWidth + 'px; }';
  15035. }
  15036. if ($scope.colContainer.name === 'left') {
  15037. $scope.grid.registerStyleComputation({
  15038. priority: 15,
  15039. func: updateRowContainerWidth
  15040. });
  15041. }*/
  15042. },
  15043. post: function ($scope, $elm, $attrs, controllers) {
  15044. }
  15045. };
  15046. }
  15047. };
  15048. }]);
  15049. /**
  15050. * @ngdoc directive
  15051. * @name ui.grid.expandable.directive:uiGridViewport
  15052. * @description stacks on the uiGridViewport directive to append the expandable row html elements to the
  15053. * default gridRow template
  15054. */
  15055. module.directive('uiGridViewport',
  15056. ['$compile', 'gridUtil', '$templateCache',
  15057. function ($compile, gridUtil, $templateCache) {
  15058. return {
  15059. priority: -200,
  15060. scope: false,
  15061. compile: function ($elm, $attrs) {
  15062. var rowRepeatDiv = angular.element($elm.children().children()[0]);
  15063. var expandedRowFillerElement = $templateCache.get('ui-grid/expandableScrollFiller');
  15064. var expandedRowElement = $templateCache.get('ui-grid/expandableRow');
  15065. rowRepeatDiv.append(expandedRowElement);
  15066. rowRepeatDiv.append(expandedRowFillerElement);
  15067. return {
  15068. pre: function ($scope, $elm, $attrs, controllers) {
  15069. },
  15070. post: function ($scope, $elm, $attrs, controllers) {
  15071. }
  15072. };
  15073. }
  15074. };
  15075. }]);
  15076. })();
  15077. /* global console */
  15078. (function () {
  15079. 'use strict';
  15080. /**
  15081. * @ngdoc overview
  15082. * @name ui.grid.exporter
  15083. * @description
  15084. *
  15085. * # ui.grid.exporter
  15086. *
  15087. * <div class="alert alert-success" role="alert"><strong>Stable</strong> This feature is stable. There should no longer be breaking api changes without a deprecation warning.</div>
  15088. *
  15089. * This module provides the ability to export data from the grid.
  15090. *
  15091. * Data can be exported in a range of formats, and all data, visible
  15092. * data, or selected rows can be exported, with all columns or visible
  15093. * columns.
  15094. *
  15095. * No UI is provided, the caller should provide their own UI/buttons
  15096. * as appropriate, or enable the gridMenu
  15097. *
  15098. * <br/>
  15099. * <br/>
  15100. *
  15101. * <div doc-module-components="ui.grid.exporter"></div>
  15102. */
  15103. var module = angular.module('ui.grid.exporter', ['ui.grid']);
  15104. /**
  15105. * @ngdoc object
  15106. * @name ui.grid.exporter.constant:uiGridExporterConstants
  15107. *
  15108. * @description constants available in exporter module
  15109. */
  15110. /**
  15111. * @ngdoc property
  15112. * @propertyOf ui.grid.exporter.constant:uiGridExporterConstants
  15113. * @name ALL
  15114. * @description export all data, including data not visible. Can
  15115. * be set for either rowTypes or colTypes
  15116. */
  15117. /**
  15118. * @ngdoc property
  15119. * @propertyOf ui.grid.exporter.constant:uiGridExporterConstants
  15120. * @name VISIBLE
  15121. * @description export only visible data, including data not visible. Can
  15122. * be set for either rowTypes or colTypes
  15123. */
  15124. /**
  15125. * @ngdoc property
  15126. * @propertyOf ui.grid.exporter.constant:uiGridExporterConstants
  15127. * @name SELECTED
  15128. * @description export all data, including data not visible. Can
  15129. * be set only for rowTypes, selection of only some columns is
  15130. * not supported
  15131. */
  15132. module.constant('uiGridExporterConstants', {
  15133. featureName: 'exporter',
  15134. ALL: 'all',
  15135. VISIBLE: 'visible',
  15136. SELECTED: 'selected',
  15137. CSV_CONTENT: 'CSV_CONTENT',
  15138. BUTTON_LABEL: 'BUTTON_LABEL',
  15139. FILE_NAME: 'FILE_NAME'
  15140. });
  15141. /**
  15142. * @ngdoc service
  15143. * @name ui.grid.exporter.service:uiGridExporterService
  15144. *
  15145. * @description Services for exporter feature
  15146. */
  15147. module.service('uiGridExporterService', ['$q', 'uiGridExporterConstants', 'gridUtil', '$compile', '$interval', 'i18nService',
  15148. function ($q, uiGridExporterConstants, gridUtil, $compile, $interval, i18nService) {
  15149. var service = {
  15150. delay: 100,
  15151. initializeGrid: function (grid) {
  15152. //add feature namespace and any properties to grid for needed state
  15153. grid.exporter = {};
  15154. this.defaultGridOptions(grid.options);
  15155. /**
  15156. * @ngdoc object
  15157. * @name ui.grid.exporter.api:PublicApi
  15158. *
  15159. * @description Public Api for exporter feature
  15160. */
  15161. var publicApi = {
  15162. events: {
  15163. exporter: {
  15164. }
  15165. },
  15166. methods: {
  15167. exporter: {
  15168. /**
  15169. * @ngdoc function
  15170. * @name csvExport
  15171. * @methodOf ui.grid.exporter.api:PublicApi
  15172. * @description Exports rows from the grid in csv format,
  15173. * the data exported is selected based on the provided options
  15174. * @param {string} rowTypes which rows to export, valid values are
  15175. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  15176. * uiGridExporterConstants.SELECTED
  15177. * @param {string} colTypes which columns to export, valid values are
  15178. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE
  15179. */
  15180. csvExport: function (rowTypes, colTypes) {
  15181. service.csvExport(grid, rowTypes, colTypes);
  15182. },
  15183. /**
  15184. * @ngdoc function
  15185. * @name pdfExport
  15186. * @methodOf ui.grid.exporter.api:PublicApi
  15187. * @description Exports rows from the grid in pdf format,
  15188. * the data exported is selected based on the provided options
  15189. * Note that this function has a dependency on pdfMake, all
  15190. * going well this has been installed for you.
  15191. * The resulting pdf opens in a new browser window.
  15192. * @param {string} rowTypes which rows to export, valid values are
  15193. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  15194. * uiGridExporterConstants.SELECTED
  15195. * @param {string} colTypes which columns to export, valid values are
  15196. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE
  15197. */
  15198. pdfExport: function (rowTypes, colTypes) {
  15199. service.pdfExport(grid, rowTypes, colTypes);
  15200. }
  15201. }
  15202. }
  15203. };
  15204. grid.api.registerEventsFromObject(publicApi.events);
  15205. grid.api.registerMethodsFromObject(publicApi.methods);
  15206. if (grid.api.core.addToGridMenu){
  15207. service.addToMenu( grid );
  15208. } else {
  15209. // order of registration is not guaranteed, register in a little while
  15210. $interval( function() {
  15211. if (grid.api.core.addToGridMenu){
  15212. service.addToMenu( grid );
  15213. }
  15214. }, this.delay, 1);
  15215. }
  15216. },
  15217. defaultGridOptions: function (gridOptions) {
  15218. //default option to true unless it was explicitly set to false
  15219. /**
  15220. * @ngdoc object
  15221. * @name ui.grid.exporter.api:GridOptions
  15222. *
  15223. * @description GridOptions for exporter feature, these are available to be
  15224. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  15225. */
  15226. /**
  15227. * @ngdoc object
  15228. * @name ui.grid.exporter.api:ColumnDef
  15229. * @description ColumnDef settings for exporter
  15230. */
  15231. /**
  15232. * @ngdoc object
  15233. * @name exporterSuppressMenu
  15234. * @propertyOf ui.grid.exporter.api:GridOptions
  15235. * @description Don't show the export menu button, implying the user
  15236. * will roll their own UI for calling the exporter
  15237. * <br/>Defaults to false
  15238. */
  15239. gridOptions.exporterSuppressMenu = gridOptions.exporterSuppressMenu === true;
  15240. /**
  15241. * @ngdoc object
  15242. * @name exporterMenuLabel
  15243. * @propertyOf ui.grid.exporter.api:GridOptions
  15244. * @description The text to show on the exporter menu button
  15245. * link
  15246. * <br/>Defaults to 'Export'
  15247. */
  15248. gridOptions.exporterMenuLabel = gridOptions.exporterMenuLabel ? gridOptions.exporterMenuLabel : 'Export';
  15249. /**
  15250. * @ngdoc object
  15251. * @name exporterSuppressColumns
  15252. * @propertyOf ui.grid.exporter.api:GridOptions
  15253. * @description Columns that should not be exported. The selectionRowHeader is already automatically
  15254. * suppressed, but if you had a button column or some other "system" column that shouldn't be shown in the
  15255. * output then add it in this list. You should provide an array of column names.
  15256. * <br/>Defaults to: []
  15257. * <pre>
  15258. * gridOptions.exporterSuppressColumns = [ 'buttons' ];
  15259. * </pre>
  15260. */
  15261. gridOptions.exporterSuppressColumns = gridOptions.exporterSuppressColumns ? gridOptions.exporterSuppressColumns : [];
  15262. /**
  15263. * @ngdoc object
  15264. * @name exporterCsvColumnSeparator
  15265. * @propertyOf ui.grid.exporter.api:GridOptions
  15266. * @description The character to use as column separator
  15267. * link
  15268. * <br/>Defaults to ','
  15269. */
  15270. gridOptions.exporterCsvColumnSeparator = gridOptions.exporterCsvColumnSeparator ? gridOptions.exporterCsvColumnSeparator : ',';
  15271. /**
  15272. * @ngdoc object
  15273. * @name exporterCsvFilename
  15274. * @propertyOf ui.grid.exporter.api:GridOptions
  15275. * @description The default filename to use when saving the downloaded csv.
  15276. * This will only work in some browsers.
  15277. * <br/>Defaults to 'download.csv'
  15278. */
  15279. gridOptions.exporterCsvFilename = gridOptions.exporterCsvFilename ? gridOptions.exporterCsvFilename : 'download.csv';
  15280. /**
  15281. * @ngdoc object
  15282. * @name exporterPdfFilename
  15283. * @propertyOf ui.grid.exporter.api:GridOptions
  15284. * @description The default filename to use when saving the downloaded pdf, only used in IE (other browsers open pdfs in a new window)
  15285. * <br/>Defaults to 'download.pdf'
  15286. */
  15287. gridOptions.exporterPdfFilename = gridOptions.exporterPdfFilename ? gridOptions.exporterPdfFilename : 'download.pdf';
  15288. /**
  15289. * @ngdoc object
  15290. * @name exporterOlderExcelCompatibility
  15291. * @propertyOf ui.grid.exporter.api:GridOptions
  15292. * @description Some versions of excel don't like the utf-16 BOM on the front, and it comes
  15293. * through as  in the first column header. Setting this option to false will suppress this, at the
  15294. * expense of proper utf-16 handling in applications that do recognise the BOM
  15295. * <br/>Defaults to false
  15296. */
  15297. gridOptions.exporterOlderExcelCompatibility = gridOptions.exporterOlderExcelCompatibility === true;
  15298. /**
  15299. * @ngdoc object
  15300. * @name exporterPdfDefaultStyle
  15301. * @propertyOf ui.grid.exporter.api:GridOptions
  15302. * @description The default style in pdfMake format
  15303. * <br/>Defaults to:
  15304. * <pre>
  15305. * {
  15306. * fontSize: 11
  15307. * }
  15308. * </pre>
  15309. */
  15310. gridOptions.exporterPdfDefaultStyle = gridOptions.exporterPdfDefaultStyle ? gridOptions.exporterPdfDefaultStyle : { fontSize: 11 };
  15311. /**
  15312. * @ngdoc object
  15313. * @name exporterPdfTableStyle
  15314. * @propertyOf ui.grid.exporter.api:GridOptions
  15315. * @description The table style in pdfMake format
  15316. * <br/>Defaults to:
  15317. * <pre>
  15318. * {
  15319. * margin: [0, 5, 0, 15]
  15320. * }
  15321. * </pre>
  15322. */
  15323. gridOptions.exporterPdfTableStyle = gridOptions.exporterPdfTableStyle ? gridOptions.exporterPdfTableStyle : { margin: [0, 5, 0, 15] };
  15324. /**
  15325. * @ngdoc object
  15326. * @name exporterPdfTableHeaderStyle
  15327. * @propertyOf ui.grid.exporter.api:GridOptions
  15328. * @description The tableHeader style in pdfMake format
  15329. * <br/>Defaults to:
  15330. * <pre>
  15331. * {
  15332. * bold: true,
  15333. * fontSize: 12,
  15334. * color: 'black'
  15335. * }
  15336. * </pre>
  15337. */
  15338. gridOptions.exporterPdfTableHeaderStyle = gridOptions.exporterPdfTableHeaderStyle ? gridOptions.exporterPdfTableHeaderStyle : { bold: true, fontSize: 12, color: 'black' };
  15339. /**
  15340. * @ngdoc object
  15341. * @name exporterPdfHeader
  15342. * @propertyOf ui.grid.exporter.api:GridOptions
  15343. * @description The header section for pdf exports. Can be
  15344. * simple text:
  15345. * <pre>
  15346. * gridOptions.exporterPdfHeader = 'My Header';
  15347. * </pre>
  15348. * Can be a more complex object in pdfMake format:
  15349. * <pre>
  15350. * gridOptions.exporterPdfHeader = {
  15351. * columns: [
  15352. * 'Left part',
  15353. * { text: 'Right part', alignment: 'right' }
  15354. * ]
  15355. * };
  15356. * </pre>
  15357. * Or can be a function, allowing page numbers and the like
  15358. * <pre>
  15359. * gridOptions.exporterPdfHeader: function(currentPage, pageCount) { return currentPage.toString() + ' of ' + pageCount; };
  15360. * </pre>
  15361. */
  15362. gridOptions.exporterPdfHeader = gridOptions.exporterPdfHeader ? gridOptions.exporterPdfHeader : null;
  15363. /**
  15364. * @ngdoc object
  15365. * @name exporterPdfFooter
  15366. * @propertyOf ui.grid.exporter.api:GridOptions
  15367. * @description The header section for pdf exports. Can be
  15368. * simple text:
  15369. * <pre>
  15370. * gridOptions.exporterPdfFooter = 'My Footer';
  15371. * </pre>
  15372. * Can be a more complex object in pdfMake format:
  15373. * <pre>
  15374. * gridOptions.exporterPdfFooter = {
  15375. * columns: [
  15376. * 'Left part',
  15377. * { text: 'Right part', alignment: 'right' }
  15378. * ]
  15379. * };
  15380. * </pre>
  15381. * Or can be a function, allowing page numbers and the like
  15382. * <pre>
  15383. * gridOptions.exporterPdfFooter: function(currentPage, pageCount) { return currentPage.toString() + ' of ' + pageCount; };
  15384. * </pre>
  15385. */
  15386. gridOptions.exporterPdfFooter = gridOptions.exporterPdfFooter ? gridOptions.exporterPdfFooter : null;
  15387. /**
  15388. * @ngdoc object
  15389. * @name exporterPdfOrientation
  15390. * @propertyOf ui.grid.exporter.api:GridOptions
  15391. * @description The orientation, should be a valid pdfMake value,
  15392. * 'landscape' or 'portrait'
  15393. * <br/>Defaults to landscape
  15394. */
  15395. gridOptions.exporterPdfOrientation = gridOptions.exporterPdfOrientation ? gridOptions.exporterPdfOrientation : 'landscape';
  15396. /**
  15397. * @ngdoc object
  15398. * @name exporterPdfPageSize
  15399. * @propertyOf ui.grid.exporter.api:GridOptions
  15400. * @description The orientation, should be a valid pdfMake
  15401. * paper size, usually 'A4' or 'LETTER'
  15402. * {@link https://github.com/bpampuch/pdfmake/blob/master/src/standardPageSizes.js pdfMake page sizes}
  15403. * <br/>Defaults to A4
  15404. */
  15405. gridOptions.exporterPdfPageSize = gridOptions.exporterPdfPageSize ? gridOptions.exporterPdfPageSize : 'A4';
  15406. /**
  15407. * @ngdoc object
  15408. * @name exporterPdfMaxGridWidth
  15409. * @propertyOf ui.grid.exporter.api:GridOptions
  15410. * @description The maxium grid width - the current grid width
  15411. * will be scaled to match this, with any fixed width columns
  15412. * being adjusted accordingly.
  15413. * <br/>Defaults to 720 (for A4 landscape), use 670 for LETTER
  15414. */
  15415. gridOptions.exporterPdfMaxGridWidth = gridOptions.exporterPdfMaxGridWidth ? gridOptions.exporterPdfMaxGridWidth : 720;
  15416. /**
  15417. * @ngdoc object
  15418. * @name exporterPdfTableLayout
  15419. * @propertyOf ui.grid.exporter.api:GridOptions
  15420. * @description A tableLayout in pdfMake format,
  15421. * controls gridlines and the like. We use the default
  15422. * layout usually.
  15423. * <br/>Defaults to null, which means no layout
  15424. */
  15425. /**
  15426. * @ngdoc object
  15427. * @name exporterMenuAllData
  15428. * @porpertyOf ui.grid.exporter.api:GridOptions
  15429. * @description Add export all data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true.
  15430. */
  15431. gridOptions.exporterMenuAllData = gridOptions.exporterMenuAllData !== undefined ? gridOptions.exporterMenuAllData : true;
  15432. /**
  15433. * @ngdoc object
  15434. * @name exporterMenuVisibleData
  15435. * @porpertyOf ui.grid.exporter.api:GridOptions
  15436. * @description Add export visible data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true.
  15437. */
  15438. gridOptions.exporterMenuVisibleData = gridOptions.exporterMenuVisibleData !== undefined ? gridOptions.exporterMenuVisibleData : true;
  15439. /**
  15440. * @ngdoc object
  15441. * @name exporterMenuSelectedData
  15442. * @porpertyOf ui.grid.exporter.api:GridOptions
  15443. * @description Add export selected data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true.
  15444. */
  15445. gridOptions.exporterMenuSelectedData = gridOptions.exporterMenuSelectedData !== undefined ? gridOptions.exporterMenuSelectedData : true;
  15446. /**
  15447. * @ngdoc object
  15448. * @name exporterMenuCsv
  15449. * @propertyOf ui.grid.exporter.api:GridOptions
  15450. * @description Add csv export menu items to the ui-grid grid menu, if it's present. Defaults to true.
  15451. */
  15452. gridOptions.exporterMenuCsv = gridOptions.exporterMenuCsv !== undefined ? gridOptions.exporterMenuCsv : true;
  15453. /**
  15454. * @ngdoc object
  15455. * @name exporterMenuPdf
  15456. * @propertyOf ui.grid.exporter.api:GridOptions
  15457. * @description Add pdf export menu items to the ui-grid grid menu, if it's present. Defaults to true.
  15458. */
  15459. gridOptions.exporterMenuPdf = gridOptions.exporterMenuPdf !== undefined ? gridOptions.exporterMenuPdf : true;
  15460. /**
  15461. * @ngdoc object
  15462. * @name exporterPdfCustomFormatter
  15463. * @propertyOf ui.grid.exporter.api:GridOptions
  15464. * @description A custom callback routine that changes the pdf document, adding any
  15465. * custom styling or content that is supported by pdfMake. Takes in the complete docDefinition, and
  15466. * must return an updated docDefinition ready for pdfMake.
  15467. * @example
  15468. * In this example we add a style to the style array, so that we can use it in our
  15469. * footer definition.
  15470. * <pre>
  15471. * gridOptions.exporterPdfCustomFormatter = function ( docDefinition ) {
  15472. * docDefinition.styles.footerStyle = { bold: true, fontSize: 10 };
  15473. * return docDefinition;
  15474. * }
  15475. *
  15476. * gridOptions.exporterPdfFooter = { text: 'My footer', style: 'footerStyle' }
  15477. * </pre>
  15478. */
  15479. gridOptions.exporterPdfCustomFormatter = ( gridOptions.exporterPdfCustomFormatter && typeof( gridOptions.exporterPdfCustomFormatter ) === 'function' ) ? gridOptions.exporterPdfCustomFormatter : function ( docDef ) { return docDef; };
  15480. /**
  15481. * @ngdoc object
  15482. * @name exporterHeaderFilterUseName
  15483. * @propertyOf ui.grid.exporter.api:GridOptions
  15484. * @description Defaults to false, which leads to `displayName` being passed into the headerFilter.
  15485. * If set to true, then will pass `name` instead.
  15486. *
  15487. *
  15488. * @example
  15489. * <pre>
  15490. * gridOptions.exporterHeaderFilterUseName = true;
  15491. * </pre>
  15492. */
  15493. gridOptions.exporterHeaderFilterUseName = gridOptions.exporterHeaderFilterUseName === true;
  15494. /**
  15495. * @ngdoc object
  15496. * @name exporterHeaderFilter
  15497. * @propertyOf ui.grid.exporter.api:GridOptions
  15498. * @description A function to apply to the header displayNames before exporting. Useful for internationalisation,
  15499. * for example if you were using angular-translate you'd set this to `$translate.instant`. Note that this
  15500. * call must be synchronous, it cannot be a call that returns a promise.
  15501. *
  15502. * Behaviour can be changed to pass in `name` instead of `displayName` through use of `exporterHeaderFilterUseName: true`.
  15503. *
  15504. * @example
  15505. * <pre>
  15506. * gridOptions.exporterHeaderFilter = function( displayName ){ return 'col: ' + name; };
  15507. * </pre>
  15508. * OR
  15509. * <pre>
  15510. * gridOptions.exporterHeaderFilter = $translate.instant;
  15511. * </pre>
  15512. */
  15513. /**
  15514. * @ngdoc function
  15515. * @name exporterFieldCallback
  15516. * @propertyOf ui.grid.exporter.api:GridOptions
  15517. * @description A function to call for each field before exporting it. Allows
  15518. * massaging of raw data into a display format, for example if you have applied
  15519. * filters to convert codes into decodes, or you require
  15520. * a specific date format in the exported content.
  15521. *
  15522. * The method is called once for each field exported, and provides the grid, the
  15523. * gridCol and the GridRow for you to use as context in massaging the data.
  15524. *
  15525. * @param {Grid} grid provides the grid in case you have need of it
  15526. * @param {GridRow} row the row from which the data comes
  15527. * @param {GridCol} col the column from which the data comes
  15528. * @param {object} value the value for your massaging
  15529. * @returns {object} you must return the massaged value ready for exporting
  15530. *
  15531. * @example
  15532. * <pre>
  15533. * gridOptions.exporterFieldCallback = function ( grid, row, col, value ){
  15534. * if ( col.name === 'status' ){
  15535. * value = decodeStatus( value );
  15536. * }
  15537. * return value;
  15538. * }
  15539. * </pre>
  15540. */
  15541. gridOptions.exporterFieldCallback = gridOptions.exporterFieldCallback ? gridOptions.exporterFieldCallback : function( grid, row, col, value ) { return value; };
  15542. /**
  15543. * @ngdoc function
  15544. * @name exporterAllDataFn
  15545. * @propertyOf ui.grid.exporter.api:GridOptions
  15546. * @description This promise is needed when exporting all rows,
  15547. * and the data need to be provided by server side. Default is null.
  15548. * @returns {Promise} a promise to load all data from server
  15549. *
  15550. * @example
  15551. * <pre>
  15552. * gridOptions.exporterAllDataFn = function () {
  15553. * return $http.get('/data/100.json')
  15554. * }
  15555. * </pre>
  15556. */
  15557. gridOptions.exporterAllDataFn = gridOptions.exporterAllDataFn ? gridOptions.exporterAllDataFn : null;
  15558. /**
  15559. * @ngdoc function
  15560. * @name exporterAllDataPromise
  15561. * @propertyOf ui.grid.exporter.api:GridOptions
  15562. * @description DEPRECATED - exporterAllDataFn used to be
  15563. * called this, but it wasn't a promise, it was a function that returned
  15564. * a promise. Deprecated, but supported for backward compatibility, use
  15565. * exporterAllDataFn instead.
  15566. * @returns {Promise} a promise to load all data from server
  15567. *
  15568. * @example
  15569. * <pre>
  15570. * gridOptions.exporterAllDataFn = function () {
  15571. * return $http.get('/data/100.json')
  15572. * }
  15573. * </pre>
  15574. */
  15575. if ( gridOptions.exporterAllDataFn == null && gridOptions.exporterAllDataPromise ) {
  15576. gridOptions.exporterAllDataFn = gridOptions.exporterAllDataPromise;
  15577. }
  15578. },
  15579. /**
  15580. * @ngdoc function
  15581. * @name addToMenu
  15582. * @methodOf ui.grid.exporter.service:uiGridExporterService
  15583. * @description Adds export items to the grid menu,
  15584. * allowing the user to select export options
  15585. * @param {Grid} grid the grid from which data should be exported
  15586. */
  15587. addToMenu: function ( grid ) {
  15588. grid.api.core.addToGridMenu( grid, [
  15589. {
  15590. title: i18nService.getSafeText('gridMenu.exporterAllAsCsv'),
  15591. action: function ($event) {
  15592. this.grid.api.exporter.csvExport( uiGridExporterConstants.ALL, uiGridExporterConstants.ALL );
  15593. },
  15594. shown: function() {
  15595. return this.grid.options.exporterMenuCsv && this.grid.options.exporterMenuAllData;
  15596. },
  15597. order: 200
  15598. },
  15599. {
  15600. title: i18nService.getSafeText('gridMenu.exporterVisibleAsCsv'),
  15601. action: function ($event) {
  15602. this.grid.api.exporter.csvExport( uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE );
  15603. },
  15604. shown: function() {
  15605. return this.grid.options.exporterMenuCsv && this.grid.options.exporterMenuVisibleData;
  15606. },
  15607. order: 201
  15608. },
  15609. {
  15610. title: i18nService.getSafeText('gridMenu.exporterSelectedAsCsv'),
  15611. action: function ($event) {
  15612. this.grid.api.exporter.csvExport( uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE );
  15613. },
  15614. shown: function() {
  15615. return this.grid.options.exporterMenuCsv && this.grid.options.exporterMenuSelectedData &&
  15616. ( this.grid.api.selection && this.grid.api.selection.getSelectedRows().length > 0 );
  15617. },
  15618. order: 202
  15619. },
  15620. {
  15621. title: i18nService.getSafeText('gridMenu.exporterAllAsPdf'),
  15622. action: function ($event) {
  15623. this.grid.api.exporter.pdfExport( uiGridExporterConstants.ALL, uiGridExporterConstants.ALL );
  15624. },
  15625. shown: function() {
  15626. return this.grid.options.exporterMenuPdf && this.grid.options.exporterMenuAllData;
  15627. },
  15628. order: 203
  15629. },
  15630. {
  15631. title: i18nService.getSafeText('gridMenu.exporterVisibleAsPdf'),
  15632. action: function ($event) {
  15633. this.grid.api.exporter.pdfExport( uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE );
  15634. },
  15635. shown: function() {
  15636. return this.grid.options.exporterMenuPdf && this.grid.options.exporterMenuVisibleData;
  15637. },
  15638. order: 204
  15639. },
  15640. {
  15641. title: i18nService.getSafeText('gridMenu.exporterSelectedAsPdf'),
  15642. action: function ($event) {
  15643. this.grid.api.exporter.pdfExport( uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE );
  15644. },
  15645. shown: function() {
  15646. return this.grid.options.exporterMenuPdf && this.grid.options.exporterMenuSelectedData &&
  15647. ( this.grid.api.selection && this.grid.api.selection.getSelectedRows().length > 0 );
  15648. },
  15649. order: 205
  15650. }
  15651. ]);
  15652. },
  15653. /**
  15654. * @ngdoc function
  15655. * @name csvExport
  15656. * @methodOf ui.grid.exporter.service:uiGridExporterService
  15657. * @description Exports rows from the grid in csv format,
  15658. * the data exported is selected based on the provided options
  15659. * @param {Grid} grid the grid from which data should be exported
  15660. * @param {string} rowTypes which rows to export, valid values are
  15661. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  15662. * uiGridExporterConstants.SELECTED
  15663. * @param {string} colTypes which columns to export, valid values are
  15664. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  15665. * uiGridExporterConstants.SELECTED
  15666. */
  15667. csvExport: function (grid, rowTypes, colTypes) {
  15668. var self = this;
  15669. this.loadAllDataIfNeeded(grid, rowTypes, colTypes).then(function() {
  15670. var exportColumnHeaders = grid.options.showHeader ? self.getColumnHeaders(grid, colTypes) : [];
  15671. var exportData = self.getData(grid, rowTypes, colTypes);
  15672. var csvContent = self.formatAsCsv(exportColumnHeaders, exportData, grid.options.exporterCsvColumnSeparator);
  15673. self.downloadFile (grid.options.exporterCsvFilename, csvContent, grid.options.exporterOlderExcelCompatibility);
  15674. });
  15675. },
  15676. /**
  15677. * @ngdoc function
  15678. * @name loadAllDataIfNeeded
  15679. * @methodOf ui.grid.exporter.service:uiGridExporterService
  15680. * @description When using server side pagination, use exporterAllDataFn to
  15681. * load all data before continuing processing.
  15682. * When using client side pagination, return a resolved promise so processing
  15683. * continues immediately
  15684. * @param {Grid} grid the grid from which data should be exported
  15685. * @param {string} rowTypes which rows to export, valid values are
  15686. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  15687. * uiGridExporterConstants.SELECTED
  15688. * @param {string} colTypes which columns to export, valid values are
  15689. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  15690. * uiGridExporterConstants.SELECTED
  15691. */
  15692. loadAllDataIfNeeded: function (grid, rowTypes, colTypes) {
  15693. if ( rowTypes === uiGridExporterConstants.ALL && grid.rows.length !== grid.options.totalItems && grid.options.exporterAllDataFn) {
  15694. return grid.options.exporterAllDataFn()
  15695. .then(function() {
  15696. grid.modifyRows(grid.options.data);
  15697. });
  15698. } else {
  15699. var deferred = $q.defer();
  15700. deferred.resolve();
  15701. return deferred.promise;
  15702. }
  15703. },
  15704. /**
  15705. * @ngdoc property
  15706. * @propertyOf ui.grid.exporter.api:ColumnDef
  15707. * @name exporterSuppressExport
  15708. * @description Suppresses export for this column. Used by selection and expandable.
  15709. */
  15710. /**
  15711. * @ngdoc function
  15712. * @name getColumnHeaders
  15713. * @methodOf ui.grid.exporter.service:uiGridExporterService
  15714. * @description Gets the column headers from the grid to use
  15715. * as a title row for the exported file, all headers have
  15716. * headerCellFilters applied as appropriate.
  15717. *
  15718. * Column headers are an array of objects, each object has
  15719. * name, displayName, width and align attributes. Only name is
  15720. * used for csv, all attributes are used for pdf.
  15721. *
  15722. * @param {Grid} grid the grid from which data should be exported
  15723. * @param {string} colTypes which columns to export, valid values are
  15724. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  15725. * uiGridExporterConstants.SELECTED
  15726. */
  15727. getColumnHeaders: function (grid, colTypes) {
  15728. var headers = [];
  15729. var columns;
  15730. if ( colTypes === uiGridExporterConstants.ALL ){
  15731. columns = grid.columns;
  15732. } else {
  15733. var leftColumns = grid.renderContainers.left ? grid.renderContainers.left.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
  15734. var bodyColumns = grid.renderContainers.body ? grid.renderContainers.body.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
  15735. var rightColumns = grid.renderContainers.right ? grid.renderContainers.right.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
  15736. columns = leftColumns.concat(bodyColumns,rightColumns);
  15737. }
  15738. columns.forEach( function( gridCol, index ) {
  15739. if ( gridCol.colDef.exporterSuppressExport !== true &&
  15740. grid.options.exporterSuppressColumns.indexOf( gridCol.name ) === -1 ){
  15741. headers.push({
  15742. name: gridCol.field,
  15743. displayName: grid.options.exporterHeaderFilter ? ( grid.options.exporterHeaderFilterUseName ? grid.options.exporterHeaderFilter(gridCol.name) : grid.options.exporterHeaderFilter(gridCol.displayName) ) : gridCol.displayName,
  15744. width: gridCol.drawnWidth ? gridCol.drawnWidth : gridCol.width,
  15745. align: gridCol.colDef.type === 'number' ? 'right' : 'left'
  15746. });
  15747. }
  15748. });
  15749. return headers;
  15750. },
  15751. /**
  15752. * @ngdoc property
  15753. * @propertyOf ui.grid.exporter.api:ColumnDef
  15754. * @name exporterPdfAlign
  15755. * @description the alignment you'd like for this specific column when
  15756. * exported into a pdf. Can be 'left', 'right', 'center' or any other
  15757. * valid pdfMake alignment option.
  15758. */
  15759. /**
  15760. * @ngdoc object
  15761. * @name ui.grid.exporter.api:GridRow
  15762. * @description GridRow settings for exporter
  15763. */
  15764. /**
  15765. * @ngdoc object
  15766. * @name exporterEnableExporting
  15767. * @propertyOf ui.grid.exporter.api:GridRow
  15768. * @description If set to false, then don't export this row, notwithstanding visible or
  15769. * other settings
  15770. * <br/>Defaults to true
  15771. */
  15772. /**
  15773. * @ngdoc function
  15774. * @name getData
  15775. * @methodOf ui.grid.exporter.service:uiGridExporterService
  15776. * @description Gets data from the grid based on the provided options,
  15777. * all cells have cellFilters applied as appropriate. Any rows marked
  15778. * `exporterEnableExporting: false` will not be exported
  15779. * @param {Grid} grid the grid from which data should be exported
  15780. * @param {string} rowTypes which rows to export, valid values are
  15781. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  15782. * uiGridExporterConstants.SELECTED
  15783. * @param {string} colTypes which columns to export, valid values are
  15784. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  15785. * uiGridExporterConstants.SELECTED
  15786. * @param {boolean} applyCellFilters whether or not to get the display value or the raw value of the data
  15787. */
  15788. getData: function (grid, rowTypes, colTypes, applyCellFilters) {
  15789. var data = [];
  15790. var rows;
  15791. var columns;
  15792. switch ( rowTypes ) {
  15793. case uiGridExporterConstants.ALL:
  15794. rows = grid.rows;
  15795. break;
  15796. case uiGridExporterConstants.VISIBLE:
  15797. rows = grid.getVisibleRows();
  15798. break;
  15799. case uiGridExporterConstants.SELECTED:
  15800. if ( grid.api.selection ){
  15801. rows = grid.api.selection.getSelectedGridRows();
  15802. } else {
  15803. gridUtil.logError('selection feature must be enabled to allow selected rows to be exported');
  15804. }
  15805. break;
  15806. }
  15807. if ( colTypes === uiGridExporterConstants.ALL ){
  15808. columns = grid.columns;
  15809. } else {
  15810. var leftColumns = grid.renderContainers.left ? grid.renderContainers.left.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
  15811. var bodyColumns = grid.renderContainers.body ? grid.renderContainers.body.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
  15812. var rightColumns = grid.renderContainers.right ? grid.renderContainers.right.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
  15813. columns = leftColumns.concat(bodyColumns,rightColumns);
  15814. }
  15815. rows.forEach( function( row, index ) {
  15816. if (row.exporterEnableExporting !== false) {
  15817. var extractedRow = [];
  15818. columns.forEach( function( gridCol, index ) {
  15819. if ( (gridCol.visible || colTypes === uiGridExporterConstants.ALL ) &&
  15820. gridCol.colDef.exporterSuppressExport !== true &&
  15821. grid.options.exporterSuppressColumns.indexOf( gridCol.name ) === -1 ){
  15822. var cellValue = applyCellFilters ? grid.getCellDisplayValue( row, gridCol ) : grid.getCellValue( row, gridCol );
  15823. var extractedField = { value: grid.options.exporterFieldCallback( grid, row, gridCol, cellValue ) };
  15824. if ( gridCol.colDef.exporterPdfAlign ) {
  15825. extractedField.alignment = gridCol.colDef.exporterPdfAlign;
  15826. }
  15827. extractedRow.push(extractedField);
  15828. }
  15829. });
  15830. data.push(extractedRow);
  15831. }
  15832. });
  15833. return data;
  15834. },
  15835. /**
  15836. * @ngdoc function
  15837. * @name formatAsCSV
  15838. * @methodOf ui.grid.exporter.service:uiGridExporterService
  15839. * @description Formats the column headers and data as a CSV,
  15840. * and sends that data to the user
  15841. * @param {array} exportColumnHeaders an array of column headers,
  15842. * where each header is an object with name, width and maybe alignment
  15843. * @param {array} exportData an array of rows, where each row is
  15844. * an array of column data
  15845. * @returns {string} csv the formatted csv as a string
  15846. */
  15847. formatAsCsv: function (exportColumnHeaders, exportData, separator) {
  15848. var self = this;
  15849. var bareHeaders = exportColumnHeaders.map(function(header){return { value: header.displayName };});
  15850. var csv = bareHeaders.length > 0 ? (self.formatRowAsCsv(this, separator)(bareHeaders) + '\n') : '';
  15851. csv += exportData.map(this.formatRowAsCsv(this, separator)).join('\n');
  15852. return csv;
  15853. },
  15854. /**
  15855. * @ngdoc function
  15856. * @name formatRowAsCsv
  15857. * @methodOf ui.grid.exporter.service:uiGridExporterService
  15858. * @description Renders a single field as a csv field, including
  15859. * quotes around the value
  15860. * @param {exporterService} exporter pass in exporter
  15861. * @param {array} row the row to be turned into a csv string
  15862. * @returns {string} a csv-ified version of the row
  15863. */
  15864. formatRowAsCsv: function (exporter, separator) {
  15865. return function (row) {
  15866. return row.map(exporter.formatFieldAsCsv).join(separator);
  15867. };
  15868. },
  15869. /**
  15870. * @ngdoc function
  15871. * @name formatFieldAsCsv
  15872. * @methodOf ui.grid.exporter.service:uiGridExporterService
  15873. * @description Renders a single field as a csv field, including
  15874. * quotes around the value
  15875. * @param {field} field the field to be turned into a csv string,
  15876. * may be of any type
  15877. * @returns {string} a csv-ified version of the field
  15878. */
  15879. formatFieldAsCsv: function (field) {
  15880. if (field.value == null) { // we want to catch anything null-ish, hence just == not ===
  15881. return '';
  15882. }
  15883. if (typeof(field.value) === 'number') {
  15884. return field.value;
  15885. }
  15886. if (typeof(field.value) === 'boolean') {
  15887. return (field.value ? 'TRUE' : 'FALSE') ;
  15888. }
  15889. if (typeof(field.value) === 'string') {
  15890. return '"' + field.value.replace(/"/g,'""') + '"';
  15891. }
  15892. return JSON.stringify(field.value);
  15893. },
  15894. /**
  15895. * @ngdoc function
  15896. * @name isIE
  15897. * @methodOf ui.grid.exporter.service:uiGridExporterService
  15898. * @description Checks whether current browser is IE and returns it's version if it is
  15899. */
  15900. isIE: function () {
  15901. var match = navigator.userAgent.search(/(?:Edge|MSIE|Trident\/.*; rv:)/);
  15902. var isIE = false;
  15903. if (match !== -1) {
  15904. isIE = true;
  15905. }
  15906. return isIE;
  15907. },
  15908. /**
  15909. * @ngdoc function
  15910. * @name downloadFile
  15911. * @methodOf ui.grid.exporter.service:uiGridExporterService
  15912. * @description Triggers download of a csv file. Logic provided
  15913. * by @cssensei (from his colleagues at https://github.com/ifeelgoods) in issue #2391
  15914. * @param {string} fileName the filename we'd like our file to be
  15915. * given
  15916. * @param {string} csvContent the csv content that we'd like to
  15917. * download as a file
  15918. * @param {boolean} exporterOlderExcelCompatibility whether or not we put a utf-16 BOM on the from (\uFEFF)
  15919. */
  15920. downloadFile: function (fileName, csvContent, exporterOlderExcelCompatibility) {
  15921. var D = document;
  15922. var a = D.createElement('a');
  15923. var strMimeType = 'application/octet-stream;charset=utf-8';
  15924. var rawFile;
  15925. var ieVersion;
  15926. ieVersion = this.isIE();
  15927. if (ieVersion && ieVersion < 10) {
  15928. var frame = D.createElement('iframe');
  15929. document.body.appendChild(frame);
  15930. frame.contentWindow.document.open("text/html", "replace");
  15931. frame.contentWindow.document.write('sep=,\r\n' + csvContent);
  15932. frame.contentWindow.document.close();
  15933. frame.contentWindow.focus();
  15934. frame.contentWindow.document.execCommand('SaveAs', true, fileName);
  15935. document.body.removeChild(frame);
  15936. return true;
  15937. }
  15938. // IE10+
  15939. if (navigator.msSaveBlob) {
  15940. return navigator.msSaveOrOpenBlob(
  15941. new Blob(
  15942. [exporterOlderExcelCompatibility ? "\uFEFF" : '', csvContent],
  15943. { type: strMimeType } ),
  15944. fileName
  15945. );
  15946. }
  15947. //html5 A[download]
  15948. if ('download' in a) {
  15949. var blob = new Blob(
  15950. [exporterOlderExcelCompatibility ? "\uFEFF" : '', csvContent],
  15951. { type: strMimeType }
  15952. );
  15953. rawFile = URL.createObjectURL(blob);
  15954. a.setAttribute('download', fileName);
  15955. } else {
  15956. rawFile = 'data:' + strMimeType + ',' + encodeURIComponent(csvContent);
  15957. a.setAttribute('target', '_blank');
  15958. }
  15959. a.href = rawFile;
  15960. a.setAttribute('style', 'display:none;');
  15961. D.body.appendChild(a);
  15962. setTimeout(function() {
  15963. if (a.click) {
  15964. a.click();
  15965. // Workaround for Safari 5
  15966. } else if (document.createEvent) {
  15967. var eventObj = document.createEvent('MouseEvents');
  15968. eventObj.initEvent('click', true, true);
  15969. a.dispatchEvent(eventObj);
  15970. }
  15971. D.body.removeChild(a);
  15972. }, this.delay);
  15973. },
  15974. /**
  15975. * @ngdoc function
  15976. * @name pdfExport
  15977. * @methodOf ui.grid.exporter.service:uiGridExporterService
  15978. * @description Exports rows from the grid in pdf format,
  15979. * the data exported is selected based on the provided options.
  15980. * Note that this function has a dependency on pdfMake, which must
  15981. * be installed. The resulting pdf opens in a new
  15982. * browser window.
  15983. * @param {Grid} grid the grid from which data should be exported
  15984. * @param {string} rowTypes which rows to export, valid values are
  15985. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  15986. * uiGridExporterConstants.SELECTED
  15987. * @param {string} colTypes which columns to export, valid values are
  15988. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  15989. * uiGridExporterConstants.SELECTED
  15990. */
  15991. pdfExport: function (grid, rowTypes, colTypes) {
  15992. var self = this;
  15993. this.loadAllDataIfNeeded(grid, rowTypes, colTypes).then(function () {
  15994. var exportColumnHeaders = self.getColumnHeaders(grid, colTypes);
  15995. var exportData = self.getData(grid, rowTypes, colTypes);
  15996. var docDefinition = self.prepareAsPdf(grid, exportColumnHeaders, exportData);
  15997. if (self.isIE() || navigator.appVersion.indexOf("Edge") !== -1) {
  15998. self.downloadPDF(grid.options.exporterPdfFilename, docDefinition);
  15999. } else {
  16000. pdfMake.createPdf(docDefinition).open();
  16001. }
  16002. });
  16003. },
  16004. /**
  16005. * @ngdoc function
  16006. * @name downloadPdf
  16007. * @methodOf ui.grid.exporter.service:uiGridExporterService
  16008. * @description Generates and retrieves the pdf as a blob, then downloads
  16009. * it as a file. Only used in IE, in all other browsers we use the native
  16010. * pdfMake.open function to just open the PDF
  16011. * @param {string} fileName the filename to give to the pdf, can be set
  16012. * through exporterPdfFilename
  16013. * @param {object} docDefinition a pdf docDefinition that we can generate
  16014. * and get a blob from
  16015. */
  16016. downloadPDF: function (fileName, docDefinition) {
  16017. var D = document;
  16018. var a = D.createElement('a');
  16019. var strMimeType = 'application/octet-stream;charset=utf-8';
  16020. var rawFile;
  16021. var ieVersion;
  16022. ieVersion = this.isIE(); // This is now a boolean value
  16023. var doc = pdfMake.createPdf(docDefinition);
  16024. var blob;
  16025. doc.getBuffer( function (buffer) {
  16026. blob = new Blob([buffer]);
  16027. // IE10+
  16028. if (navigator.msSaveBlob) {
  16029. return navigator.msSaveBlob(
  16030. blob, fileName
  16031. );
  16032. }
  16033. // Previously: && ieVersion < 10
  16034. // ieVersion now returns a boolean for the
  16035. // sake of sanity. We just check `msSaveBlob` first.
  16036. if (ieVersion) {
  16037. var frame = D.createElement('iframe');
  16038. document.body.appendChild(frame);
  16039. frame.contentWindow.document.open("text/html", "replace");
  16040. frame.contentWindow.document.write(blob);
  16041. frame.contentWindow.document.close();
  16042. frame.contentWindow.focus();
  16043. frame.contentWindow.document.execCommand('SaveAs', true, fileName);
  16044. document.body.removeChild(frame);
  16045. return true;
  16046. }
  16047. });
  16048. },
  16049. /**
  16050. * @ngdoc function
  16051. * @name renderAsPdf
  16052. * @methodOf ui.grid.exporter.service:uiGridExporterService
  16053. * @description Renders the data into a pdf, and opens that pdf.
  16054. *
  16055. * @param {Grid} grid the grid from which data should be exported
  16056. * @param {array} exportColumnHeaders an array of column headers,
  16057. * where each header is an object with name, width and maybe alignment
  16058. * @param {array} exportData an array of rows, where each row is
  16059. * an array of column data
  16060. * @returns {object} a pdfMake format document definition, ready
  16061. * for generation
  16062. */
  16063. prepareAsPdf: function(grid, exportColumnHeaders, exportData) {
  16064. var headerWidths = this.calculatePdfHeaderWidths( grid, exportColumnHeaders );
  16065. var headerColumns = exportColumnHeaders.map( function( header ) {
  16066. return { text: header.displayName, style: 'tableHeader' };
  16067. });
  16068. var stringData = exportData.map(this.formatRowAsPdf(this));
  16069. var allData = [headerColumns].concat(stringData);
  16070. var docDefinition = {
  16071. pageOrientation: grid.options.exporterPdfOrientation,
  16072. pageSize: grid.options.exporterPdfPageSize,
  16073. content: [{
  16074. style: 'tableStyle',
  16075. table: {
  16076. headerRows: 1,
  16077. widths: headerWidths,
  16078. body: allData
  16079. }
  16080. }],
  16081. styles: {
  16082. tableStyle: grid.options.exporterPdfTableStyle,
  16083. tableHeader: grid.options.exporterPdfTableHeaderStyle
  16084. },
  16085. defaultStyle: grid.options.exporterPdfDefaultStyle
  16086. };
  16087. if ( grid.options.exporterPdfLayout ){
  16088. docDefinition.layout = grid.options.exporterPdfLayout;
  16089. }
  16090. if ( grid.options.exporterPdfHeader ){
  16091. docDefinition.header = grid.options.exporterPdfHeader;
  16092. }
  16093. if ( grid.options.exporterPdfFooter ){
  16094. docDefinition.footer = grid.options.exporterPdfFooter;
  16095. }
  16096. if ( grid.options.exporterPdfCustomFormatter ){
  16097. docDefinition = grid.options.exporterPdfCustomFormatter( docDefinition );
  16098. }
  16099. return docDefinition;
  16100. },
  16101. /**
  16102. * @ngdoc function
  16103. * @name calculatePdfHeaderWidths
  16104. * @methodOf ui.grid.exporter.service:uiGridExporterService
  16105. * @description Determines the column widths base on the
  16106. * widths we got from the grid. If the column is drawn
  16107. * then we have a drawnWidth. If the column is not visible
  16108. * then we have '*', 'x%' or a width. When columns are
  16109. * not visible they don't contribute to the overall gridWidth,
  16110. * so we need to adjust to allow for extra columns
  16111. *
  16112. * Our basic heuristic is to take the current gridWidth, plus
  16113. * numeric columns and call this the base gridwidth.
  16114. *
  16115. * To that we add 100 for any '*' column, and x% of the base gridWidth
  16116. * for any column that is a %
  16117. *
  16118. * @param {Grid} grid the grid from which data should be exported
  16119. * @param {array} exportHeaders array of header information
  16120. * @returns {object} an array of header widths
  16121. */
  16122. calculatePdfHeaderWidths: function ( grid, exportHeaders ) {
  16123. var baseGridWidth = 0;
  16124. exportHeaders.forEach( function(value){
  16125. if (typeof(value.width) === 'number'){
  16126. baseGridWidth += value.width;
  16127. }
  16128. });
  16129. var extraColumns = 0;
  16130. exportHeaders.forEach( function(value){
  16131. if (value.width === '*'){
  16132. extraColumns += 100;
  16133. }
  16134. if (typeof(value.width) === 'string' && value.width.match(/(\d)*%/)) {
  16135. var percent = parseInt(value.width.match(/(\d)*%/)[0]);
  16136. value.width = baseGridWidth * percent / 100;
  16137. extraColumns += value.width;
  16138. }
  16139. });
  16140. var gridWidth = baseGridWidth + extraColumns;
  16141. return exportHeaders.map(function( header ) {
  16142. return header.width === '*' ? header.width : header.width * grid.options.exporterPdfMaxGridWidth / gridWidth;
  16143. });
  16144. },
  16145. /**
  16146. * @ngdoc function
  16147. * @name formatRowAsPdf
  16148. * @methodOf ui.grid.exporter.service:uiGridExporterService
  16149. * @description Renders a row in a format consumable by PDF,
  16150. * mainly meaning casting everything to a string
  16151. * @param {exporterService} exporter pass in exporter
  16152. * @param {array} row the row to be turned into a csv string
  16153. * @returns {string} a csv-ified version of the row
  16154. */
  16155. formatRowAsPdf: function ( exporter ) {
  16156. return function( row ) {
  16157. return row.map(exporter.formatFieldAsPdfString);
  16158. };
  16159. },
  16160. /**
  16161. * @ngdoc function
  16162. * @name formatFieldAsCsv
  16163. * @methodOf ui.grid.exporter.service:uiGridExporterService
  16164. * @description Renders a single field as a pdf-able field, which
  16165. * is different from a csv field only in that strings don't have quotes
  16166. * around them
  16167. * @param {field} field the field to be turned into a pdf string,
  16168. * may be of any type
  16169. * @returns {string} a string-ified version of the field
  16170. */
  16171. formatFieldAsPdfString: function (field) {
  16172. var returnVal;
  16173. if (field.value == null) { // we want to catch anything null-ish, hence just == not ===
  16174. returnVal = '';
  16175. } else if (typeof(field.value) === 'number') {
  16176. returnVal = field.value.toString();
  16177. } else if (typeof(field.value) === 'boolean') {
  16178. returnVal = (field.value ? 'TRUE' : 'FALSE') ;
  16179. } else if (typeof(field.value) === 'string') {
  16180. returnVal = field.value.replace(/"/g,'""');
  16181. } else {
  16182. returnVal = JSON.stringify(field.value).replace(/^"/,'').replace(/"$/,'');
  16183. }
  16184. if (field.alignment && typeof(field.alignment) === 'string' ){
  16185. returnVal = { text: returnVal, alignment: field.alignment };
  16186. }
  16187. return returnVal;
  16188. }
  16189. };
  16190. return service;
  16191. }
  16192. ]);
  16193. /**
  16194. * @ngdoc directive
  16195. * @name ui.grid.exporter.directive:uiGridExporter
  16196. * @element div
  16197. * @restrict A
  16198. *
  16199. * @description Adds exporter features to grid
  16200. *
  16201. * @example
  16202. <example module="app">
  16203. <file name="app.js">
  16204. var app = angular.module('app', ['ui.grid', 'ui.grid.exporter']);
  16205. app.controller('MainCtrl', ['$scope', function ($scope) {
  16206. $scope.data = [
  16207. { name: 'Bob', title: 'CEO' },
  16208. { name: 'Frank', title: 'Lowly Developer' }
  16209. ];
  16210. $scope.gridOptions = {
  16211. enableGridMenu: true,
  16212. exporterMenuCsv: false,
  16213. columnDefs: [
  16214. {name: 'name', enableCellEdit: true},
  16215. {name: 'title', enableCellEdit: true}
  16216. ],
  16217. data: $scope.data
  16218. };
  16219. }]);
  16220. </file>
  16221. <file name="index.html">
  16222. <div ng-controller="MainCtrl">
  16223. <div ui-grid="gridOptions" ui-grid-exporter></div>
  16224. </div>
  16225. </file>
  16226. </example>
  16227. */
  16228. module.directive('uiGridExporter', ['uiGridExporterConstants', 'uiGridExporterService', 'gridUtil', '$compile',
  16229. function (uiGridExporterConstants, uiGridExporterService, gridUtil, $compile) {
  16230. return {
  16231. replace: true,
  16232. priority: 0,
  16233. require: '^uiGrid',
  16234. scope: false,
  16235. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  16236. uiGridExporterService.initializeGrid(uiGridCtrl.grid);
  16237. uiGridCtrl.grid.exporter.$scope = $scope;
  16238. }
  16239. };
  16240. }
  16241. ]);
  16242. })();
  16243. (function () {
  16244. 'use strict';
  16245. /**
  16246. * @ngdoc overview
  16247. * @name ui.grid.grouping
  16248. * @description
  16249. *
  16250. * # ui.grid.grouping
  16251. *
  16252. * <div class="alert alert-warning" role="alert"><strong>Beta</strong> This feature is ready for testing, but it either hasn't seen a lot of use or has some known bugs.</div>
  16253. *
  16254. * This module provides grouping of rows based on the data in them, similar
  16255. * in concept to excel grouping. You can group multiple columns, resulting in
  16256. * nested grouping.
  16257. *
  16258. * In concept this feature is similar to sorting + grid footer/aggregation, it
  16259. * sorts the data based on the grouped columns, then creates group rows that
  16260. * reflect a break in the data. Each of those group rows can have aggregations for
  16261. * the data within that group.
  16262. *
  16263. * This feature leverages treeBase to provide the tree functionality itself,
  16264. * the key thing this feature does therefore is to set treeLevels on the rows
  16265. * and insert the group headers.
  16266. *
  16267. * Design information:
  16268. * -------------------
  16269. *
  16270. * Each column will get new menu items - group by, and aggregate by. Group by
  16271. * will cause this column to be sorted (if not already), and will move this column
  16272. * to the front of the sorted columns (i.e. grouped columns take precedence over
  16273. * sorted columns). It will respect the sort order already set if there is one,
  16274. * and it will allow the sorting logic to change that sort order, it just forces
  16275. * the column to the front of the sorting. You can group by multiple columns, the
  16276. * logic will add this column to the sorting after any already grouped columns.
  16277. *
  16278. * Once a grouping is defined, grouping logic is added to the rowsProcessors. This
  16279. * will process the rows, identifying a break in the data value, and inserting a grouping row.
  16280. * Grouping rows have specific attributes on them:
  16281. *
  16282. * - internalRow = true: tells us that this isn't a real row, so we can ignore it
  16283. * from any processing that it looking at core data rows. This is used by the core
  16284. * logic (or will be one day), as it's not grouping specific
  16285. * - groupHeader = true: tells us this is a groupHeader. This is used by the grouping logic
  16286. * to know if this is a groupHeader row or not
  16287. *
  16288. * Since the logic is baked into the rowsProcessors, it should get triggered whenever
  16289. * row order or filtering or anything like that is changed. In order to avoid the row instantiation
  16290. * time, and to preserve state across invocations, we hold a cache of the rows that we created
  16291. * last time, and we use them again this time if we can.
  16292. *
  16293. * By default rows are collapsed, which means all data rows have their visible property
  16294. * set to false, and only level 0 group rows are set to visible.
  16295. *
  16296. * <br/>
  16297. * <br/>
  16298. *
  16299. * <div doc-module-components="ui.grid.grouping"></div>
  16300. */
  16301. var module = angular.module('ui.grid.grouping', ['ui.grid', 'ui.grid.treeBase']);
  16302. /**
  16303. * @ngdoc object
  16304. * @name ui.grid.grouping.constant:uiGridGroupingConstants
  16305. *
  16306. * @description constants available in grouping module, this includes
  16307. * all the constants declared in the treeBase module (these are manually copied
  16308. * as there isn't an easy way to include constants in another constants file, and
  16309. * we don't want to make users include treeBase)
  16310. *
  16311. */
  16312. module.constant('uiGridGroupingConstants', {
  16313. featureName: "grouping",
  16314. rowHeaderColName: 'treeBaseRowHeaderCol',
  16315. EXPANDED: 'expanded',
  16316. COLLAPSED: 'collapsed',
  16317. aggregation: {
  16318. COUNT: 'count',
  16319. SUM: 'sum',
  16320. MAX: 'max',
  16321. MIN: 'min',
  16322. AVG: 'avg'
  16323. }
  16324. });
  16325. /**
  16326. * @ngdoc service
  16327. * @name ui.grid.grouping.service:uiGridGroupingService
  16328. *
  16329. * @description Services for grouping features
  16330. */
  16331. module.service('uiGridGroupingService', ['$q', 'uiGridGroupingConstants', 'gridUtil', 'rowSorter', 'GridRow', 'gridClassFactory', 'i18nService', 'uiGridConstants', 'uiGridTreeBaseService',
  16332. function ($q, uiGridGroupingConstants, gridUtil, rowSorter, GridRow, gridClassFactory, i18nService, uiGridConstants, uiGridTreeBaseService) {
  16333. var service = {
  16334. initializeGrid: function (grid, $scope) {
  16335. uiGridTreeBaseService.initializeGrid( grid, $scope );
  16336. //add feature namespace and any properties to grid for needed
  16337. /**
  16338. * @ngdoc object
  16339. * @name ui.grid.grouping.grid:grouping
  16340. *
  16341. * @description Grid properties and functions added for grouping
  16342. */
  16343. grid.grouping = {};
  16344. /**
  16345. * @ngdoc property
  16346. * @propertyOf ui.grid.grouping.grid:grouping
  16347. * @name groupHeaderCache
  16348. *
  16349. * @description Cache that holds the group header rows we created last time, we'll
  16350. * reuse these next time, not least because they hold our expanded states.
  16351. *
  16352. * We need to take care with these that they don't become a memory leak, we
  16353. * create a new cache each time using the values from the old cache. This works
  16354. * so long as we're creating group rows for invisible rows as well.
  16355. *
  16356. * The cache is a nested hash, indexed on the value we grouped by. So if we
  16357. * grouped by gender then age, we'd maybe have something like:
  16358. * ```
  16359. * {
  16360. * male: {
  16361. * row: <pointer to the old row>,
  16362. * children: {
  16363. * 22: { row: <pointer to the old row> },
  16364. * 31: { row: <pointer to the old row> }
  16365. * },
  16366. * female: {
  16367. * row: <pointer to the old row>,
  16368. * children: {
  16369. * 28: { row: <pointer to the old row> },
  16370. * 55: { row: <pointer to the old row> }
  16371. * }
  16372. * }
  16373. * ```
  16374. *
  16375. * We create new rows for any missing rows, this means that they come in as collapsed.
  16376. *
  16377. */
  16378. grid.grouping.groupHeaderCache = {};
  16379. service.defaultGridOptions(grid.options);
  16380. grid.registerRowsProcessor(service.groupRows, 400);
  16381. grid.registerColumnBuilder( service.groupingColumnBuilder);
  16382. grid.registerColumnsProcessor(service.groupingColumnProcessor, 400);
  16383. /**
  16384. * @ngdoc object
  16385. * @name ui.grid.grouping.api:PublicApi
  16386. *
  16387. * @description Public Api for grouping feature
  16388. */
  16389. var publicApi = {
  16390. events: {
  16391. grouping: {
  16392. /**
  16393. * @ngdoc event
  16394. * @eventOf ui.grid.grouping.api:PublicApi
  16395. * @name aggregationChanged
  16396. * @description raised whenever aggregation is changed, added or removed from a column
  16397. *
  16398. * <pre>
  16399. * gridApi.grouping.on.aggregationChanged(scope,function(col){})
  16400. * </pre>
  16401. * @param {gridCol} col the column which on which aggregation changed. The aggregation
  16402. * type is available as `col.treeAggregation.type`
  16403. */
  16404. aggregationChanged: {},
  16405. /**
  16406. * @ngdoc event
  16407. * @eventOf ui.grid.grouping.api:PublicApi
  16408. * @name groupingChanged
  16409. * @description raised whenever the grouped columns changes
  16410. *
  16411. * <pre>
  16412. * gridApi.grouping.on.groupingChanged(scope,function(col){})
  16413. * </pre>
  16414. * @param {gridCol} col the column which on which grouping changed. The new grouping is
  16415. * available as `col.grouping`
  16416. */
  16417. groupingChanged: {}
  16418. }
  16419. },
  16420. methods: {
  16421. grouping: {
  16422. /**
  16423. * @ngdoc function
  16424. * @name getGrouping
  16425. * @methodOf ui.grid.grouping.api:PublicApi
  16426. * @description Get the grouping configuration for this grid,
  16427. * used by the saveState feature. Adds expandedState to the information
  16428. * provided by the internal getGrouping, and removes any aggregations that have a source
  16429. * of grouping (i.e. will be automatically reapplied when we regroup the column)
  16430. * Returned grouping is an object
  16431. * `{ grouping: groupArray, treeAggregations: aggregateArray, expandedState: hash }`
  16432. * where grouping contains an array of objects:
  16433. * `{ field: column.field, colName: column.name, groupPriority: column.grouping.groupPriority }`
  16434. * and aggregations contains an array of objects:
  16435. * `{ field: column.field, colName: column.name, aggregation: column.grouping.aggregation }`
  16436. * and expandedState is a hash of the currently expanded nodes
  16437. *
  16438. * The groupArray will be sorted by groupPriority.
  16439. *
  16440. * @param {boolean} getExpanded whether or not to return the expanded state
  16441. * @returns {object} grouping configuration
  16442. */
  16443. getGrouping: function ( getExpanded ) {
  16444. var grouping = service.getGrouping(grid);
  16445. grouping.grouping.forEach( function( group ) {
  16446. group.colName = group.col.name;
  16447. delete group.col;
  16448. });
  16449. grouping.aggregations.forEach( function( aggregation ) {
  16450. aggregation.colName = aggregation.col.name;
  16451. delete aggregation.col;
  16452. });
  16453. grouping.aggregations = grouping.aggregations.filter( function( aggregation ){
  16454. return !aggregation.aggregation.source || aggregation.aggregation.source !== 'grouping';
  16455. });
  16456. if ( getExpanded ){
  16457. grouping.rowExpandedStates = service.getRowExpandedStates( grid.grouping.groupingHeaderCache );
  16458. }
  16459. return grouping;
  16460. },
  16461. /**
  16462. * @ngdoc function
  16463. * @name setGrouping
  16464. * @methodOf ui.grid.grouping.api:PublicApi
  16465. * @description Set the grouping configuration for this grid,
  16466. * used by the saveState feature, but can also be used by any
  16467. * user to specify a combined grouping and aggregation configuration
  16468. * @param {object} config the config you want to apply, in the format
  16469. * provided out by getGrouping
  16470. */
  16471. setGrouping: function ( config ) {
  16472. service.setGrouping(grid, config);
  16473. },
  16474. /**
  16475. * @ngdoc function
  16476. * @name groupColumn
  16477. * @methodOf ui.grid.grouping.api:PublicApi
  16478. * @description Adds this column to the existing grouping, at the end of the priority order.
  16479. * If the column doesn't have a sort, adds one, by default ASC
  16480. *
  16481. * This column will move to the left of any non-group columns, the
  16482. * move is handled in a columnProcessor, so gets called as part of refresh
  16483. *
  16484. * @param {string} columnName the name of the column we want to group
  16485. */
  16486. groupColumn: function( columnName ) {
  16487. var column = grid.getColumn(columnName);
  16488. service.groupColumn(grid, column);
  16489. },
  16490. /**
  16491. * @ngdoc function
  16492. * @name ungroupColumn
  16493. * @methodOf ui.grid.grouping.api:PublicApi
  16494. * @description Removes the groupPriority from this column. If the
  16495. * column was previously aggregated the aggregation will come back.
  16496. * The sort will remain.
  16497. *
  16498. * This column will move to the right of any other group columns, the
  16499. * move is handled in a columnProcessor, so gets called as part of refresh
  16500. *
  16501. * @param {string} columnName the name of the column we want to ungroup
  16502. */
  16503. ungroupColumn: function( columnName ) {
  16504. var column = grid.getColumn(columnName);
  16505. service.ungroupColumn(grid, column);
  16506. },
  16507. /**
  16508. * @ngdoc function
  16509. * @name clearGrouping
  16510. * @methodOf ui.grid.grouping.api:PublicApi
  16511. * @description Clear any grouped columns and any aggregations. Doesn't remove sorting,
  16512. * as we don't know whether that sorting was added by grouping or was there beforehand
  16513. *
  16514. */
  16515. clearGrouping: function() {
  16516. service.clearGrouping(grid);
  16517. },
  16518. /**
  16519. * @ngdoc function
  16520. * @name aggregateColumn
  16521. * @methodOf ui.grid.grouping.api:PublicApi
  16522. * @description Sets the aggregation type on a column, if the
  16523. * column is currently grouped then it removes the grouping first.
  16524. * If the aggregationDef is null then will result in the aggregation
  16525. * being removed
  16526. *
  16527. * @param {string} columnName the column we want to aggregate
  16528. * @param {string} or {function} aggregationDef one of the recognised types
  16529. * from uiGridGroupingConstants or a custom aggregation function.
  16530. * @param {string} aggregationLabel (optional) The label to use for this aggregation.
  16531. */
  16532. aggregateColumn: function( columnName, aggregationDef, aggregationLabel){
  16533. var column = grid.getColumn(columnName);
  16534. service.aggregateColumn( grid, column, aggregationDef, aggregationLabel);
  16535. }
  16536. }
  16537. }
  16538. };
  16539. grid.api.registerEventsFromObject(publicApi.events);
  16540. grid.api.registerMethodsFromObject(publicApi.methods);
  16541. grid.api.core.on.sortChanged( $scope, service.tidyPriorities);
  16542. },
  16543. defaultGridOptions: function (gridOptions) {
  16544. //default option to true unless it was explicitly set to false
  16545. /**
  16546. * @ngdoc object
  16547. * @name ui.grid.grouping.api:GridOptions
  16548. *
  16549. * @description GridOptions for grouping feature, these are available to be
  16550. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  16551. */
  16552. /**
  16553. * @ngdoc object
  16554. * @name enableGrouping
  16555. * @propertyOf ui.grid.grouping.api:GridOptions
  16556. * @description Enable row grouping for entire grid.
  16557. * <br/>Defaults to true
  16558. */
  16559. gridOptions.enableGrouping = gridOptions.enableGrouping !== false;
  16560. /**
  16561. * @ngdoc object
  16562. * @name groupingShowCounts
  16563. * @propertyOf ui.grid.grouping.api:GridOptions
  16564. * @description shows counts on the groupHeader rows. Not that if you are using a cellFilter or a
  16565. * sortingAlgorithm which relies on a specific format or data type, showing counts may cause that
  16566. * to break, since the group header rows will always be a string with groupingShowCounts enabled.
  16567. * <br/>Defaults to true except on columns of type 'date'
  16568. */
  16569. gridOptions.groupingShowCounts = gridOptions.groupingShowCounts !== false;
  16570. /**
  16571. * @ngdoc object
  16572. * @name groupingNullLabel
  16573. * @propertyOf ui.grid.grouping.api:GridOptions
  16574. * @description The string to use for the grouping header row label on rows which contain a null or undefined value in the grouped column.
  16575. * <br/>Defaults to "Null"
  16576. */
  16577. gridOptions.groupingNullLabel = typeof(gridOptions.groupingNullLabel) === 'undefined' ? 'Null' : gridOptions.groupingNullLabel;
  16578. /**
  16579. * @ngdoc object
  16580. * @name enableGroupHeaderSelection
  16581. * @propertyOf ui.grid.grouping.api:GridOptions
  16582. * @description Allows group header rows to be selected.
  16583. * <br/>Defaults to false
  16584. */
  16585. gridOptions.enableGroupHeaderSelection = gridOptions.enableGroupHeaderSelection === true;
  16586. },
  16587. /**
  16588. * @ngdoc function
  16589. * @name groupingColumnBuilder
  16590. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  16591. * @description Sets the grouping defaults based on the columnDefs
  16592. *
  16593. * @param {object} colDef columnDef we're basing on
  16594. * @param {GridCol} col the column we're to update
  16595. * @param {object} gridOptions the options we should use
  16596. * @returns {promise} promise for the builder - actually we do it all inline so it's immediately resolved
  16597. */
  16598. groupingColumnBuilder: function (colDef, col, gridOptions) {
  16599. /**
  16600. * @ngdoc object
  16601. * @name ui.grid.grouping.api:ColumnDef
  16602. *
  16603. * @description ColumnDef for grouping feature, these are available to be
  16604. * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs}
  16605. */
  16606. /**
  16607. * @ngdoc object
  16608. * @name enableGrouping
  16609. * @propertyOf ui.grid.grouping.api:ColumnDef
  16610. * @description Enable grouping on this column
  16611. * <br/>Defaults to true.
  16612. */
  16613. if (colDef.enableGrouping === false){
  16614. return;
  16615. }
  16616. /**
  16617. * @ngdoc object
  16618. * @name grouping
  16619. * @propertyOf ui.grid.grouping.api:ColumnDef
  16620. * @description Set the grouping for a column. Format is:
  16621. * ```
  16622. * {
  16623. * groupPriority: <number, starts at 0, if less than 0 or undefined then we're aggregating in this column>
  16624. * }
  16625. * ```
  16626. *
  16627. * **Note that aggregation used to be included in grouping, but is now separately set on the column via treeAggregation
  16628. * setting in treeBase**
  16629. *
  16630. * We group in the priority order given, this will also put these columns to the high order of the sort irrespective
  16631. * of the sort priority given them. If there is no sort defined then we sort ascending, if there is a sort defined then
  16632. * we use that sort.
  16633. *
  16634. * If the groupPriority is undefined or less than 0, then we expect to be aggregating, and we look at the
  16635. * aggregation types to determine what sort of aggregation we can do. Values are in the constants file, but
  16636. * include SUM, COUNT, MAX, MIN
  16637. *
  16638. * groupPriorities should generally be sequential, if they're not then the next time getGrouping is called
  16639. * we'll renumber them to be sequential.
  16640. * <br/>Defaults to undefined.
  16641. */
  16642. if ( typeof(col.grouping) === 'undefined' && typeof(colDef.grouping) !== 'undefined') {
  16643. col.grouping = angular.copy(colDef.grouping);
  16644. if ( typeof(col.grouping.groupPriority) !== 'undefined' && col.grouping.groupPriority > -1 ){
  16645. col.treeAggregationFn = uiGridTreeBaseService.nativeAggregations()[uiGridGroupingConstants.aggregation.COUNT].aggregationFn;
  16646. col.treeAggregationFinalizerFn = service.groupedFinalizerFn;
  16647. }
  16648. } else if (typeof(col.grouping) === 'undefined'){
  16649. col.grouping = {};
  16650. }
  16651. if (typeof(col.grouping) !== 'undefined' && typeof(col.grouping.groupPriority) !== 'undefined' && col.grouping.groupPriority >= 0){
  16652. col.suppressRemoveSort = true;
  16653. }
  16654. var groupColumn = {
  16655. name: 'ui.grid.grouping.group',
  16656. title: i18nService.get().grouping.group,
  16657. icon: 'ui-grid-icon-indent-right',
  16658. shown: function () {
  16659. return typeof(this.context.col.grouping) === 'undefined' ||
  16660. typeof(this.context.col.grouping.groupPriority) === 'undefined' ||
  16661. this.context.col.grouping.groupPriority < 0;
  16662. },
  16663. action: function () {
  16664. service.groupColumn( this.context.col.grid, this.context.col );
  16665. }
  16666. };
  16667. var ungroupColumn = {
  16668. name: 'ui.grid.grouping.ungroup',
  16669. title: i18nService.get().grouping.ungroup,
  16670. icon: 'ui-grid-icon-indent-left',
  16671. shown: function () {
  16672. return typeof(this.context.col.grouping) !== 'undefined' &&
  16673. typeof(this.context.col.grouping.groupPriority) !== 'undefined' &&
  16674. this.context.col.grouping.groupPriority >= 0;
  16675. },
  16676. action: function () {
  16677. service.ungroupColumn( this.context.col.grid, this.context.col );
  16678. }
  16679. };
  16680. var aggregateRemove = {
  16681. name: 'ui.grid.grouping.aggregateRemove',
  16682. title: i18nService.get().grouping.aggregate_remove,
  16683. shown: function () {
  16684. return typeof(this.context.col.treeAggregationFn) !== 'undefined';
  16685. },
  16686. action: function () {
  16687. service.aggregateColumn( this.context.col.grid, this.context.col, null);
  16688. }
  16689. };
  16690. // generic adder for the aggregation menus, which follow a pattern
  16691. var addAggregationMenu = function(type, title){
  16692. title = title || i18nService.get().grouping['aggregate_' + type] || type;
  16693. var menuItem = {
  16694. name: 'ui.grid.grouping.aggregate' + type,
  16695. title: title,
  16696. shown: function () {
  16697. return typeof(this.context.col.treeAggregation) === 'undefined' ||
  16698. typeof(this.context.col.treeAggregation.type) === 'undefined' ||
  16699. this.context.col.treeAggregation.type !== type;
  16700. },
  16701. action: function () {
  16702. service.aggregateColumn( this.context.col.grid, this.context.col, type);
  16703. }
  16704. };
  16705. if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.grouping.aggregate' + type)) {
  16706. col.menuItems.push(menuItem);
  16707. }
  16708. };
  16709. /**
  16710. * @ngdoc object
  16711. * @name groupingShowGroupingMenu
  16712. * @propertyOf ui.grid.grouping.api:ColumnDef
  16713. * @description Show the grouping (group and ungroup items) menu on this column
  16714. * <br/>Defaults to true.
  16715. */
  16716. if ( col.colDef.groupingShowGroupingMenu !== false ){
  16717. if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.grouping.group')) {
  16718. col.menuItems.push(groupColumn);
  16719. }
  16720. if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.grouping.ungroup')) {
  16721. col.menuItems.push(ungroupColumn);
  16722. }
  16723. }
  16724. /**
  16725. * @ngdoc object
  16726. * @name groupingShowAggregationMenu
  16727. * @propertyOf ui.grid.grouping.api:ColumnDef
  16728. * @description Show the aggregation menu on this column
  16729. * <br/>Defaults to true.
  16730. */
  16731. if ( col.colDef.groupingShowAggregationMenu !== false ){
  16732. angular.forEach(uiGridTreeBaseService.nativeAggregations(), function(aggregationDef, name){
  16733. addAggregationMenu(name);
  16734. });
  16735. angular.forEach(gridOptions.treeCustomAggregations, function(aggregationDef, name){
  16736. addAggregationMenu(name, aggregationDef.menuTitle);
  16737. });
  16738. if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.grouping.aggregateRemove')) {
  16739. col.menuItems.push(aggregateRemove);
  16740. }
  16741. }
  16742. },
  16743. /**
  16744. * @ngdoc function
  16745. * @name groupingColumnProcessor
  16746. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  16747. * @description Moves the columns around based on which are grouped
  16748. *
  16749. * @param {array} columns the columns to consider rendering
  16750. * @param {array} rows the grid rows, which we don't use but are passed to us
  16751. * @returns {array} updated columns array
  16752. */
  16753. groupingColumnProcessor: function( columns, rows ) {
  16754. var grid = this;
  16755. columns = service.moveGroupColumns(this, columns, rows);
  16756. return columns;
  16757. },
  16758. /**
  16759. * @ngdoc function
  16760. * @name groupedFinalizerFn
  16761. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  16762. * @description Used on group columns to display the rendered value and optionally
  16763. * display the count of rows.
  16764. *
  16765. * @param {aggregation} the aggregation entity for a grouped column
  16766. */
  16767. groupedFinalizerFn: function( aggregation ){
  16768. var col = this;
  16769. if ( typeof(aggregation.groupVal) !== 'undefined') {
  16770. aggregation.rendered = aggregation.groupVal;
  16771. if ( col.grid.options.groupingShowCounts && col.colDef.type !== 'date' ){
  16772. aggregation.rendered += (' (' + aggregation.value + ')');
  16773. }
  16774. } else {
  16775. aggregation.rendered = null;
  16776. }
  16777. },
  16778. /**
  16779. * @ngdoc function
  16780. * @name moveGroupColumns
  16781. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  16782. * @description Moves the column order so that the grouped columns are lined up
  16783. * to the left (well, unless you're RTL, then it's the right). By doing this in
  16784. * the columnsProcessor, we make it transient - when the column is ungrouped it'll
  16785. * go back to where it was.
  16786. *
  16787. * Does nothing if the option `moveGroupColumns` is set to false.
  16788. *
  16789. * @param {Grid} grid grid object
  16790. * @param {array} columns the columns that we should process/move
  16791. * @param {array} rows the grid rows
  16792. * @returns {array} updated columns
  16793. */
  16794. moveGroupColumns: function( grid, columns, rows ){
  16795. if ( grid.options.moveGroupColumns === false){
  16796. return columns;
  16797. }
  16798. columns.forEach( function(column, index){
  16799. // position used to make stable sort in moveGroupColumns
  16800. column.groupingPosition = index;
  16801. });
  16802. columns.sort(function(a, b){
  16803. var a_group, b_group;
  16804. if (a.isRowHeader){
  16805. a_group = -1000;
  16806. }
  16807. else if ( typeof(a.grouping) === 'undefined' || typeof(a.grouping.groupPriority) === 'undefined' || a.grouping.groupPriority < 0){
  16808. a_group = null;
  16809. } else {
  16810. a_group = a.grouping.groupPriority;
  16811. }
  16812. if (b.isRowHeader){
  16813. b_group = -1000;
  16814. }
  16815. else if ( typeof(b.grouping) === 'undefined' || typeof(b.grouping.groupPriority) === 'undefined' || b.grouping.groupPriority < 0){
  16816. b_group = null;
  16817. } else {
  16818. b_group = b.grouping.groupPriority;
  16819. }
  16820. // groups get sorted to the top
  16821. if ( a_group !== null && b_group === null) { return -1; }
  16822. if ( b_group !== null && a_group === null) { return 1; }
  16823. if ( a_group !== null && b_group !== null) {return a_group - b_group; }
  16824. return a.groupingPosition - b.groupingPosition;
  16825. });
  16826. columns.forEach( function(column, index) {
  16827. delete column.groupingPosition;
  16828. });
  16829. return columns;
  16830. },
  16831. /**
  16832. * @ngdoc function
  16833. * @name groupColumn
  16834. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  16835. * @description Adds this column to the existing grouping, at the end of the priority order.
  16836. * If the column doesn't have a sort, adds one, by default ASC
  16837. *
  16838. * This column will move to the left of any non-group columns, the
  16839. * move is handled in a columnProcessor, so gets called as part of refresh
  16840. *
  16841. * @param {Grid} grid grid object
  16842. * @param {GridCol} column the column we want to group
  16843. */
  16844. groupColumn: function( grid, column){
  16845. if ( typeof(column.grouping) === 'undefined' ){
  16846. column.grouping = {};
  16847. }
  16848. // set the group priority to the next number in the hierarchy
  16849. var existingGrouping = service.getGrouping( grid );
  16850. column.grouping.groupPriority = existingGrouping.grouping.length;
  16851. // add sort if not present
  16852. if ( !column.sort ){
  16853. column.sort = { direction: uiGridConstants.ASC };
  16854. } else if ( typeof(column.sort.direction) === 'undefined' || column.sort.direction === null ){
  16855. column.sort.direction = uiGridConstants.ASC;
  16856. }
  16857. column.treeAggregation = { type: uiGridGroupingConstants.aggregation.COUNT, source: 'grouping' };
  16858. column.treeAggregationFn = uiGridTreeBaseService.nativeAggregations()[uiGridGroupingConstants.aggregation.COUNT].aggregationFn;
  16859. column.treeAggregationFinalizerFn = service.groupedFinalizerFn;
  16860. grid.api.grouping.raise.groupingChanged(column);
  16861. // This indirectly calls service.tidyPriorities( grid );
  16862. grid.api.core.raise.sortChanged(grid, grid.getColumnSorting());
  16863. grid.queueGridRefresh();
  16864. },
  16865. /**
  16866. * @ngdoc function
  16867. * @name ungroupColumn
  16868. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  16869. * @description Removes the groupPriority from this column. If the
  16870. * column was previously aggregated the aggregation will come back.
  16871. * The sort will remain.
  16872. *
  16873. * This column will move to the right of any other group columns, the
  16874. * move is handled in a columnProcessor, so gets called as part of refresh
  16875. *
  16876. * @param {Grid} grid grid object
  16877. * @param {GridCol} column the column we want to ungroup
  16878. */
  16879. ungroupColumn: function( grid, column){
  16880. if ( typeof(column.grouping) === 'undefined' ){
  16881. return;
  16882. }
  16883. delete column.grouping.groupPriority;
  16884. delete column.treeAggregation;
  16885. delete column.customTreeAggregationFinalizer;
  16886. service.tidyPriorities( grid );
  16887. grid.api.grouping.raise.groupingChanged(column);
  16888. grid.queueGridRefresh();
  16889. },
  16890. /**
  16891. * @ngdoc function
  16892. * @name aggregateColumn
  16893. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  16894. * @description Sets the aggregation type on a column, if the
  16895. * column is currently grouped then it removes the grouping first.
  16896. *
  16897. * @param {Grid} grid grid object
  16898. * @param {GridCol} column the column we want to aggregate
  16899. * @param {string} one of the recognised types from uiGridGroupingConstants or one of the custom aggregations from gridOptions
  16900. */
  16901. aggregateColumn: function( grid, column, aggregationType){
  16902. if (typeof(column.grouping) !== 'undefined' && typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0){
  16903. service.ungroupColumn( grid, column );
  16904. }
  16905. var aggregationDef = {};
  16906. if ( typeof(grid.options.treeCustomAggregations[aggregationType]) !== 'undefined' ){
  16907. aggregationDef = grid.options.treeCustomAggregations[aggregationType];
  16908. } else if ( typeof(uiGridTreeBaseService.nativeAggregations()[aggregationType]) !== 'undefined' ){
  16909. aggregationDef = uiGridTreeBaseService.nativeAggregations()[aggregationType];
  16910. }
  16911. column.treeAggregation = { type: aggregationType, label: i18nService.get().aggregation[aggregationDef.label] || aggregationDef.label };
  16912. column.treeAggregationFn = aggregationDef.aggregationFn;
  16913. column.treeAggregationFinalizerFn = aggregationDef.finalizerFn;
  16914. grid.api.grouping.raise.aggregationChanged(column);
  16915. grid.queueGridRefresh();
  16916. },
  16917. /**
  16918. * @ngdoc function
  16919. * @name setGrouping
  16920. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  16921. * @description Set the grouping based on a config object, used by the save state feature
  16922. * (more specifically, by the restore function in that feature )
  16923. *
  16924. * @param {Grid} grid grid object
  16925. * @param {object} config the config we want to set, same format as that returned by getGrouping
  16926. */
  16927. setGrouping: function ( grid, config ){
  16928. if ( typeof(config) === 'undefined' ){
  16929. return;
  16930. }
  16931. // first remove any existing grouping
  16932. service.clearGrouping(grid);
  16933. if ( config.grouping && config.grouping.length && config.grouping.length > 0 ){
  16934. config.grouping.forEach( function( group ) {
  16935. var col = grid.getColumn(group.colName);
  16936. if ( col ) {
  16937. service.groupColumn( grid, col );
  16938. }
  16939. });
  16940. }
  16941. if ( config.aggregations && config.aggregations.length ){
  16942. config.aggregations.forEach( function( aggregation ) {
  16943. var col = grid.getColumn(aggregation.colName);
  16944. if ( col ) {
  16945. service.aggregateColumn( grid, col, aggregation.aggregation.type );
  16946. }
  16947. });
  16948. }
  16949. if ( config.rowExpandedStates ){
  16950. service.applyRowExpandedStates( grid.grouping.groupingHeaderCache, config.rowExpandedStates );
  16951. }
  16952. },
  16953. /**
  16954. * @ngdoc function
  16955. * @name clearGrouping
  16956. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  16957. * @description Clear any grouped columns and any aggregations. Doesn't remove sorting,
  16958. * as we don't know whether that sorting was added by grouping or was there beforehand
  16959. *
  16960. * @param {Grid} grid grid object
  16961. */
  16962. clearGrouping: function( grid ) {
  16963. var currentGrouping = service.getGrouping(grid);
  16964. if ( currentGrouping.grouping.length > 0 ){
  16965. currentGrouping.grouping.forEach( function( group ) {
  16966. if (!group.col){
  16967. // should have a group.colName if there's no col
  16968. group.col = grid.getColumn(group.colName);
  16969. }
  16970. service.ungroupColumn(grid, group.col);
  16971. });
  16972. }
  16973. if ( currentGrouping.aggregations.length > 0 ){
  16974. currentGrouping.aggregations.forEach( function( aggregation ){
  16975. if (!aggregation.col){
  16976. // should have a group.colName if there's no col
  16977. aggregation.col = grid.getColumn(aggregation.colName);
  16978. }
  16979. service.aggregateColumn(grid, aggregation.col, null);
  16980. });
  16981. }
  16982. },
  16983. /**
  16984. * @ngdoc function
  16985. * @name tidyPriorities
  16986. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  16987. * @description Renumbers groupPriority and sortPriority such that
  16988. * groupPriority is contiguous, and sortPriority either matches
  16989. * groupPriority (for group columns), and otherwise is contiguous and
  16990. * higher than groupPriority.
  16991. *
  16992. * @param {Grid} grid grid object
  16993. */
  16994. tidyPriorities: function( grid ){
  16995. // if we're called from sortChanged, grid is in this, not passed as param, the param can be a column or undefined
  16996. if ( ( typeof(grid) === 'undefined' || typeof(grid.grid) !== 'undefined' ) && typeof(this.grid) !== 'undefined' ) {
  16997. grid = this.grid;
  16998. }
  16999. var groupArray = [];
  17000. var sortArray = [];
  17001. grid.columns.forEach( function(column, index){
  17002. if ( typeof(column.grouping) !== 'undefined' && typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0){
  17003. groupArray.push(column);
  17004. } else if ( typeof(column.sort) !== 'undefined' && typeof(column.sort.priority) !== 'undefined' && column.sort.priority >= 0){
  17005. sortArray.push(column);
  17006. }
  17007. });
  17008. groupArray.sort(function(a, b){ return a.grouping.groupPriority - b.grouping.groupPriority; });
  17009. groupArray.forEach( function(column, index){
  17010. column.grouping.groupPriority = index;
  17011. column.suppressRemoveSort = true;
  17012. if ( typeof(column.sort) === 'undefined'){
  17013. column.sort = {};
  17014. }
  17015. column.sort.priority = index;
  17016. });
  17017. var i = groupArray.length;
  17018. sortArray.sort(function(a, b){ return a.sort.priority - b.sort.priority; });
  17019. sortArray.forEach( function(column, index){
  17020. column.sort.priority = i;
  17021. column.suppressRemoveSort = column.colDef.suppressRemoveSort;
  17022. i++;
  17023. });
  17024. },
  17025. /**
  17026. * @ngdoc function
  17027. * @name groupRows
  17028. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  17029. * @description The rowProcessor that creates the groupHeaders (i.e. does
  17030. * the actual grouping).
  17031. *
  17032. * Assumes it is always called after the sorting processor, guaranteed by the priority setting
  17033. *
  17034. * Processes all the rows in order, inserting a groupHeader row whenever there is a change
  17035. * in value of a grouped row, based on the sortAlgorithm used for the column. The group header row
  17036. * is looked up in the groupHeaderCache, and used from there if there is one. The entity is reset
  17037. * to {} if one is found.
  17038. *
  17039. * As it processes it maintains a `processingState` array. This records, for each level of grouping we're
  17040. * working with, the following information:
  17041. * ```
  17042. * {
  17043. * fieldName: name,
  17044. * col: col,
  17045. * initialised: boolean,
  17046. * currentValue: value,
  17047. * currentRow: gridRow,
  17048. * }
  17049. * ```
  17050. * We look for changes in the currentValue at any of the levels. Where we find a change we:
  17051. *
  17052. * - create a new groupHeader row in the array
  17053. *
  17054. * @param {array} renderableRows the rows we want to process, usually the output from the previous rowProcessor
  17055. * @returns {array} the updated rows, including our new group rows
  17056. */
  17057. groupRows: function( renderableRows ) {
  17058. if (renderableRows.length === 0){
  17059. return renderableRows;
  17060. }
  17061. var grid = this;
  17062. grid.grouping.oldGroupingHeaderCache = grid.grouping.groupingHeaderCache || {};
  17063. grid.grouping.groupingHeaderCache = {};
  17064. var processingState = service.initialiseProcessingState( grid );
  17065. // processes each of the fields we are grouping by, checks if the value has changed and inserts a groupHeader
  17066. // Broken out as shouldn't create functions in a loop.
  17067. var updateProcessingState = function( groupFieldState, stateIndex ) {
  17068. var fieldValue = grid.getCellValue(row, groupFieldState.col);
  17069. // look for change of value - and insert a header
  17070. if ( !groupFieldState.initialised || rowSorter.getSortFn(grid, groupFieldState.col, renderableRows)(fieldValue, groupFieldState.currentValue) !== 0 ){
  17071. service.insertGroupHeader( grid, renderableRows, i, processingState, stateIndex );
  17072. i++;
  17073. }
  17074. };
  17075. // use a for loop because it's tolerant of the array length changing whilst we go - we can
  17076. // manipulate the iterator when we insert groupHeader rows
  17077. for (var i = 0; i < renderableRows.length; i++ ){
  17078. var row = renderableRows[i];
  17079. if ( row.visible ){
  17080. processingState.forEach( updateProcessingState );
  17081. }
  17082. }
  17083. delete grid.grouping.oldGroupingHeaderCache;
  17084. return renderableRows;
  17085. },
  17086. /**
  17087. * @ngdoc function
  17088. * @name initialiseProcessingState
  17089. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  17090. * @description Creates the processing state array that is used
  17091. * for groupRows.
  17092. *
  17093. * @param {Grid} grid grid object
  17094. * @returns {array} an array in the format described in the groupRows method,
  17095. * initialised with blank values
  17096. */
  17097. initialiseProcessingState: function( grid ){
  17098. var processingState = [];
  17099. var columnSettings = service.getGrouping( grid );
  17100. columnSettings.grouping.forEach( function( groupItem, index){
  17101. processingState.push({
  17102. fieldName: groupItem.field,
  17103. col: groupItem.col,
  17104. initialised: false,
  17105. currentValue: null,
  17106. currentRow: null
  17107. });
  17108. });
  17109. return processingState;
  17110. },
  17111. /**
  17112. * @ngdoc function
  17113. * @name getGrouping
  17114. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  17115. * @description Get the grouping settings from the columns. As a side effect
  17116. * this always renumbers the grouping starting at 0
  17117. * @param {Grid} grid grid object
  17118. * @returns {array} an array of the group fields, in order of priority
  17119. */
  17120. getGrouping: function( grid ){
  17121. var groupArray = [];
  17122. var aggregateArray = [];
  17123. // get all the grouping
  17124. grid.columns.forEach( function(column, columnIndex){
  17125. if ( column.grouping ){
  17126. if ( typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0){
  17127. groupArray.push({ field: column.field, col: column, groupPriority: column.grouping.groupPriority, grouping: column.grouping });
  17128. }
  17129. }
  17130. if ( column.treeAggregation && column.treeAggregation.type ){
  17131. aggregateArray.push({ field: column.field, col: column, aggregation: column.treeAggregation });
  17132. }
  17133. });
  17134. // sort grouping into priority order
  17135. groupArray.sort( function(a, b){
  17136. return a.groupPriority - b.groupPriority;
  17137. });
  17138. // renumber the priority in case it was somewhat messed up, then remove the grouping reference
  17139. groupArray.forEach( function( group, index) {
  17140. group.grouping.groupPriority = index;
  17141. group.groupPriority = index;
  17142. delete group.grouping;
  17143. });
  17144. return { grouping: groupArray, aggregations: aggregateArray };
  17145. },
  17146. /**
  17147. * @ngdoc function
  17148. * @name insertGroupHeader
  17149. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  17150. * @description Create a group header row, and link it to the various configuration
  17151. * items that we use.
  17152. *
  17153. * Look for the row in the oldGroupingHeaderCache, write the row into the new groupingHeaderCache.
  17154. *
  17155. * @param {Grid} grid grid object
  17156. * @param {array} renderableRows the rows that we are processing
  17157. * @param {number} rowIndex the row we were up to processing
  17158. * @param {array} processingState the current processing state
  17159. * @param {number} stateIndex the processing state item that we were on when we triggered a new group header -
  17160. * i.e. the column that we want to create a header for
  17161. */
  17162. insertGroupHeader: function( grid, renderableRows, rowIndex, processingState, stateIndex ) {
  17163. // set the value that caused the end of a group into the header row and the processing state
  17164. var fieldName = processingState[stateIndex].fieldName;
  17165. var col = processingState[stateIndex].col;
  17166. var newValue = grid.getCellValue(renderableRows[rowIndex], col);
  17167. var newDisplayValue = newValue;
  17168. if ( typeof(newValue) === 'undefined' || newValue === null ) {
  17169. newDisplayValue = grid.options.groupingNullLabel;
  17170. }
  17171. var getKeyAsValueForCacheMap = function(key) {
  17172. if (angular.isObject(key)) {
  17173. return JSON.stringify(key);
  17174. } else {
  17175. return key;
  17176. }
  17177. };
  17178. var cacheItem = grid.grouping.oldGroupingHeaderCache;
  17179. for ( var i = 0; i < stateIndex; i++ ){
  17180. if ( cacheItem && cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)] ){
  17181. cacheItem = cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)].children;
  17182. }
  17183. }
  17184. var headerRow;
  17185. if ( cacheItem && cacheItem[getKeyAsValueForCacheMap(newValue)]){
  17186. headerRow = cacheItem[getKeyAsValueForCacheMap(newValue)].row;
  17187. headerRow.entity = {};
  17188. } else {
  17189. headerRow = new GridRow( {}, null, grid );
  17190. gridClassFactory.rowTemplateAssigner.call(grid, headerRow);
  17191. }
  17192. headerRow.entity['$$' + processingState[stateIndex].col.uid] = { groupVal: newDisplayValue };
  17193. headerRow.treeLevel = stateIndex;
  17194. headerRow.groupHeader = true;
  17195. headerRow.internalRow = true;
  17196. headerRow.enableCellEdit = false;
  17197. headerRow.enableSelection = grid.options.enableGroupHeaderSelection;
  17198. processingState[stateIndex].initialised = true;
  17199. processingState[stateIndex].currentValue = newValue;
  17200. processingState[stateIndex].currentRow = headerRow;
  17201. // set all processing states below this one to not be initialised - change of this state
  17202. // means all those need to start again
  17203. service.finaliseProcessingState( processingState, stateIndex + 1);
  17204. // insert our new header row
  17205. renderableRows.splice(rowIndex, 0, headerRow);
  17206. // add our new header row to the cache
  17207. cacheItem = grid.grouping.groupingHeaderCache;
  17208. for ( i = 0; i < stateIndex; i++ ){
  17209. cacheItem = cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)].children;
  17210. }
  17211. cacheItem[getKeyAsValueForCacheMap(newValue)] = { row: headerRow, children: {} };
  17212. },
  17213. /**
  17214. * @ngdoc function
  17215. * @name finaliseProcessingState
  17216. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  17217. * @description Set all processing states lower than the one that had a break in value to
  17218. * no longer be initialised. Render the counts into the entity ready for display.
  17219. *
  17220. * @param {Grid} grid grid object
  17221. * @param {array} processingState the current processing state
  17222. * @param {number} stateIndex the processing state item that we were on when we triggered a new group header, all
  17223. * processing states after this need to be finalised
  17224. */
  17225. finaliseProcessingState: function( processingState, stateIndex ){
  17226. for ( var i = stateIndex; i < processingState.length; i++){
  17227. processingState[i].initialised = false;
  17228. processingState[i].currentRow = null;
  17229. processingState[i].currentValue = null;
  17230. }
  17231. },
  17232. /**
  17233. * @ngdoc function
  17234. * @name getRowExpandedStates
  17235. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  17236. * @description Extract the groupHeaderCache hash, pulling out only the states.
  17237. *
  17238. * The example below shows a grid that is grouped by gender then age
  17239. *
  17240. * <pre>
  17241. * {
  17242. * male: {
  17243. * state: 'expanded',
  17244. * children: {
  17245. * 22: { state: 'expanded' },
  17246. * 30: { state: 'collapsed' }
  17247. * }
  17248. * },
  17249. * female: {
  17250. * state: 'expanded',
  17251. * children: {
  17252. * 28: { state: 'expanded' },
  17253. * 55: { state: 'collapsed' }
  17254. * }
  17255. * }
  17256. * }
  17257. * </pre>
  17258. *
  17259. * @param {Grid} grid grid object
  17260. * @returns {hash} the expanded states as a hash
  17261. */
  17262. getRowExpandedStates: function(treeChildren){
  17263. if ( typeof(treeChildren) === 'undefined' ){
  17264. return {};
  17265. }
  17266. var newChildren = {};
  17267. angular.forEach( treeChildren, function( value, key ){
  17268. newChildren[key] = { state: value.row.treeNode.state };
  17269. if ( value.children ){
  17270. newChildren[key].children = service.getRowExpandedStates( value.children );
  17271. } else {
  17272. newChildren[key].children = {};
  17273. }
  17274. });
  17275. return newChildren;
  17276. },
  17277. /**
  17278. * @ngdoc function
  17279. * @name applyRowExpandedStates
  17280. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  17281. * @description Take a hash in the format as created by getRowExpandedStates,
  17282. * and apply it to the grid.grouping.groupHeaderCache.
  17283. *
  17284. * Takes a treeSubset, and applies to a treeSubset - so can be called
  17285. * recursively.
  17286. *
  17287. * @param {object} currentNode can be grid.grouping.groupHeaderCache, or any of
  17288. * the children of that hash
  17289. * @returns {hash} expandedStates can be the full expanded states, or children
  17290. * of that expanded states (which hopefully matches the subset of the groupHeaderCache)
  17291. */
  17292. applyRowExpandedStates: function( currentNode, expandedStates ){
  17293. if ( typeof(expandedStates) === 'undefined' ){
  17294. return;
  17295. }
  17296. angular.forEach(expandedStates, function( value, key ) {
  17297. if ( currentNode[key] ){
  17298. currentNode[key].row.treeNode.state = value.state;
  17299. if (value.children && currentNode[key].children){
  17300. service.applyRowExpandedStates( currentNode[key].children, value.children );
  17301. }
  17302. }
  17303. });
  17304. }
  17305. };
  17306. return service;
  17307. }]);
  17308. /**
  17309. * @ngdoc directive
  17310. * @name ui.grid.grouping.directive:uiGridGrouping
  17311. * @element div
  17312. * @restrict A
  17313. *
  17314. * @description Adds grouping features to grid
  17315. *
  17316. * @example
  17317. <example module="app">
  17318. <file name="app.js">
  17319. var app = angular.module('app', ['ui.grid', 'ui.grid.grouping']);
  17320. app.controller('MainCtrl', ['$scope', function ($scope) {
  17321. $scope.data = [
  17322. { name: 'Bob', title: 'CEO' },
  17323. { name: 'Frank', title: 'Lowly Developer' }
  17324. ];
  17325. $scope.columnDefs = [
  17326. {name: 'name', enableCellEdit: true},
  17327. {name: 'title', enableCellEdit: true}
  17328. ];
  17329. $scope.gridOptions = { columnDefs: $scope.columnDefs, data: $scope.data };
  17330. }]);
  17331. </file>
  17332. <file name="index.html">
  17333. <div ng-controller="MainCtrl">
  17334. <div ui-grid="gridOptions" ui-grid-grouping></div>
  17335. </div>
  17336. </file>
  17337. </example>
  17338. */
  17339. module.directive('uiGridGrouping', ['uiGridGroupingConstants', 'uiGridGroupingService', '$templateCache',
  17340. function (uiGridGroupingConstants, uiGridGroupingService, $templateCache) {
  17341. return {
  17342. replace: true,
  17343. priority: 0,
  17344. require: '^uiGrid',
  17345. scope: false,
  17346. compile: function () {
  17347. return {
  17348. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  17349. if (uiGridCtrl.grid.options.enableGrouping !== false){
  17350. uiGridGroupingService.initializeGrid(uiGridCtrl.grid, $scope);
  17351. }
  17352. },
  17353. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  17354. }
  17355. };
  17356. }
  17357. };
  17358. }]);
  17359. })();
  17360. (function () {
  17361. 'use strict';
  17362. /**
  17363. * @ngdoc overview
  17364. * @name ui.grid.importer
  17365. * @description
  17366. *
  17367. * # ui.grid.importer
  17368. *
  17369. * <div class="alert alert-success" role="alert"><strong>Stable</strong> This feature is stable. There should no longer be breaking api changes without a deprecation warning.</div>
  17370. *
  17371. * This module provides the ability to import data into the grid. It
  17372. * uses the column defs to work out which data belongs in which column,
  17373. * and creates entities from a configured class (typically a $resource).
  17374. *
  17375. * If the rowEdit feature is enabled, it also calls save on those newly
  17376. * created objects, and then displays any errors in the imported data.
  17377. *
  17378. * Currently the importer imports only CSV and json files, although provision has been
  17379. * made to process other file formats, and these can be added over time.
  17380. *
  17381. * For json files, the properties within each object in the json must match the column names
  17382. * (to put it another way, the importer doesn't process the json, it just copies the objects
  17383. * within the json into a new instance of the specified object type)
  17384. *
  17385. * For CSV import, the default column identification relies on each column in the
  17386. * header row matching a column.name or column.displayName. Optionally, a column identification
  17387. * callback can be used. This allows matching using other attributes, which is particularly
  17388. * useful if your application has internationalised column headings (i.e. the headings that
  17389. * the user sees don't match the column names).
  17390. *
  17391. * The importer makes use of the grid menu as the UI for requesting an
  17392. * import.
  17393. *
  17394. * <div ui-grid-importer></div>
  17395. */
  17396. var module = angular.module('ui.grid.importer', ['ui.grid']);
  17397. /**
  17398. * @ngdoc object
  17399. * @name ui.grid.importer.constant:uiGridImporterConstants
  17400. *
  17401. * @description constants available in importer module
  17402. */
  17403. module.constant('uiGridImporterConstants', {
  17404. featureName: 'importer'
  17405. });
  17406. /**
  17407. * @ngdoc service
  17408. * @name ui.grid.importer.service:uiGridImporterService
  17409. *
  17410. * @description Services for importer feature
  17411. */
  17412. module.service('uiGridImporterService', ['$q', 'uiGridConstants', 'uiGridImporterConstants', 'gridUtil', '$compile', '$interval', 'i18nService', '$window',
  17413. function ($q, uiGridConstants, uiGridImporterConstants, gridUtil, $compile, $interval, i18nService, $window) {
  17414. var service = {
  17415. initializeGrid: function ($scope, grid) {
  17416. //add feature namespace and any properties to grid for needed state
  17417. grid.importer = {
  17418. $scope: $scope
  17419. };
  17420. this.defaultGridOptions(grid.options);
  17421. /**
  17422. * @ngdoc object
  17423. * @name ui.grid.importer.api:PublicApi
  17424. *
  17425. * @description Public Api for importer feature
  17426. */
  17427. var publicApi = {
  17428. events: {
  17429. importer: {
  17430. }
  17431. },
  17432. methods: {
  17433. importer: {
  17434. /**
  17435. * @ngdoc function
  17436. * @name importFile
  17437. * @methodOf ui.grid.importer.api:PublicApi
  17438. * @description Imports a file into the grid using the file object
  17439. * provided. Bypasses the grid menu
  17440. * @param {File} fileObject the file we want to import, as a javascript
  17441. * File object
  17442. */
  17443. importFile: function ( fileObject ) {
  17444. service.importThisFile( grid, fileObject );
  17445. }
  17446. }
  17447. }
  17448. };
  17449. grid.api.registerEventsFromObject(publicApi.events);
  17450. grid.api.registerMethodsFromObject(publicApi.methods);
  17451. if ( grid.options.enableImporter && grid.options.importerShowMenu ){
  17452. if ( grid.api.core.addToGridMenu ){
  17453. service.addToMenu( grid );
  17454. } else {
  17455. // order of registration is not guaranteed, register in a little while
  17456. $interval( function() {
  17457. if (grid.api.core.addToGridMenu){
  17458. service.addToMenu( grid );
  17459. }
  17460. }, 100, 1);
  17461. }
  17462. }
  17463. },
  17464. defaultGridOptions: function (gridOptions) {
  17465. //default option to true unless it was explicitly set to false
  17466. /**
  17467. * @ngdoc object
  17468. * @name ui.grid.importer.api:GridOptions
  17469. *
  17470. * @description GridOptions for importer feature, these are available to be
  17471. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  17472. */
  17473. /**
  17474. * @ngdoc property
  17475. * @propertyOf ui.grid.importer.api:GridOptions
  17476. * @name enableImporter
  17477. * @description Whether or not importer is enabled. Automatically set
  17478. * to false if the user's browser does not support the required fileApi.
  17479. * Otherwise defaults to true.
  17480. *
  17481. */
  17482. if (gridOptions.enableImporter || gridOptions.enableImporter === undefined) {
  17483. if ( !($window.hasOwnProperty('File') && $window.hasOwnProperty('FileReader') && $window.hasOwnProperty('FileList') && $window.hasOwnProperty('Blob')) ) {
  17484. gridUtil.logError('The File APIs are not fully supported in this browser, grid importer cannot be used.');
  17485. gridOptions.enableImporter = false;
  17486. } else {
  17487. gridOptions.enableImporter = true;
  17488. }
  17489. } else {
  17490. gridOptions.enableImporter = false;
  17491. }
  17492. /**
  17493. * @ngdoc method
  17494. * @name importerProcessHeaders
  17495. * @methodOf ui.grid.importer.api:GridOptions
  17496. * @description A callback function that will process headers using custom
  17497. * logic. Set this callback function if the headers that your user will provide in their
  17498. * import file don't necessarily match the grid header or field names. This might commonly
  17499. * occur where your application is internationalised, and therefore the field names
  17500. * that the user recognises are in a different language than the field names that
  17501. * ui-grid knows about.
  17502. *
  17503. * Defaults to the internal `processHeaders` method, which seeks to match using both
  17504. * displayName and column.name. Any non-matching columns are discarded.
  17505. *
  17506. * Your callback routine should respond by processing the header array, and returning an array
  17507. * of matching column names. A null value in any given position means "don't import this column"
  17508. *
  17509. * <pre>
  17510. * gridOptions.importerProcessHeaders: function( headerArray ) {
  17511. * var myHeaderColumns = [];
  17512. * var thisCol;
  17513. * headerArray.forEach( function( value, index ) {
  17514. * thisCol = mySpecialLookupFunction( value );
  17515. * myHeaderColumns.push( thisCol.name );
  17516. * });
  17517. *
  17518. * return myHeaderCols;
  17519. * })
  17520. * </pre>
  17521. * @param {Grid} grid the grid we're importing into
  17522. * @param {array} headerArray an array of the text from the first row of the csv file,
  17523. * which you need to match to column.names
  17524. * @returns {array} array of matching column names, in the same order as the headerArray
  17525. *
  17526. */
  17527. gridOptions.importerProcessHeaders = gridOptions.importerProcessHeaders || service.processHeaders;
  17528. /**
  17529. * @ngdoc method
  17530. * @name importerHeaderFilter
  17531. * @methodOf ui.grid.importer.api:GridOptions
  17532. * @description A callback function that will filter (usually translate) a single
  17533. * header. Used when you want to match the passed in column names to the column
  17534. * displayName after the header filter.
  17535. *
  17536. * Your callback routine needs to return the filtered header value.
  17537. * <pre>
  17538. * gridOptions.importerHeaderFilter: function( displayName ) {
  17539. * return $translate.instant( displayName );
  17540. * })
  17541. * </pre>
  17542. *
  17543. * or:
  17544. * <pre>
  17545. * gridOptions.importerHeaderFilter: $translate.instant
  17546. * </pre>
  17547. * @param {string} displayName the displayName that we'd like to translate
  17548. * @returns {string} the translated name
  17549. *
  17550. */
  17551. gridOptions.importerHeaderFilter = gridOptions.importerHeaderFilter || function( displayName ) { return displayName; };
  17552. /**
  17553. * @ngdoc method
  17554. * @name importerErrorCallback
  17555. * @methodOf ui.grid.importer.api:GridOptions
  17556. * @description A callback function that provides custom error handling, rather
  17557. * than the standard grid behaviour of an alert box and a console message. You
  17558. * might use this to internationalise the console log messages, or to write to a
  17559. * custom logging routine that returned errors to the server.
  17560. *
  17561. * <pre>
  17562. * gridOptions.importerErrorCallback: function( grid, errorKey, consoleMessage, context ) {
  17563. * myUserDisplayRoutine( errorKey );
  17564. * myLoggingRoutine( consoleMessage, context );
  17565. * })
  17566. * </pre>
  17567. * @param {Grid} grid the grid we're importing into, may be useful if you're positioning messages
  17568. * in some way
  17569. * @param {string} errorKey one of the i18n keys the importer can return - importer.noHeaders,
  17570. * importer.noObjects, importer.invalidCsv, importer.invalidJson, importer.jsonNotArray
  17571. * @param {string} consoleMessage the English console message that importer would have written
  17572. * @param {object} context the context data that importer would have appended to that console message,
  17573. * often the file content itself or the element that is in error
  17574. *
  17575. */
  17576. if ( !gridOptions.importerErrorCallback || typeof(gridOptions.importerErrorCallback) !== 'function' ){
  17577. delete gridOptions.importerErrorCallback;
  17578. }
  17579. /**
  17580. * @ngdoc method
  17581. * @name importerDataAddCallback
  17582. * @methodOf ui.grid.importer.api:GridOptions
  17583. * @description A mandatory callback function that adds data to the source data array. The grid
  17584. * generally doesn't add rows to the source data array, it is tidier to handle this through a user
  17585. * callback.
  17586. *
  17587. * <pre>
  17588. * gridOptions.importerDataAddCallback: function( grid, newObjects ) {
  17589. * $scope.myData = $scope.myData.concat( newObjects );
  17590. * })
  17591. * </pre>
  17592. * @param {Grid} grid the grid we're importing into, may be useful in some way
  17593. * @param {array} newObjects an array of new objects that you should add to your data
  17594. *
  17595. */
  17596. if ( gridOptions.enableImporter === true && !gridOptions.importerDataAddCallback ) {
  17597. gridUtil.logError("You have not set an importerDataAddCallback, importer is disabled");
  17598. gridOptions.enableImporter = false;
  17599. }
  17600. /**
  17601. * @ngdoc object
  17602. * @name importerNewObject
  17603. * @propertyOf ui.grid.importer.api:GridOptions
  17604. * @description An object on which we call `new` to create each new row before inserting it into
  17605. * the data array. Typically this would be a $resource entity, which means that if you're using
  17606. * the rowEdit feature, you can directly call save on this entity when the save event is triggered.
  17607. *
  17608. * Defaults to a vanilla javascript object
  17609. *
  17610. * @example
  17611. * <pre>
  17612. * gridOptions.importerNewObject = MyRes;
  17613. * </pre>
  17614. *
  17615. */
  17616. /**
  17617. * @ngdoc property
  17618. * @propertyOf ui.grid.importer.api:GridOptions
  17619. * @name importerShowMenu
  17620. * @description Whether or not to show an item in the grid menu. Defaults to true.
  17621. *
  17622. */
  17623. gridOptions.importerShowMenu = gridOptions.importerShowMenu !== false;
  17624. /**
  17625. * @ngdoc method
  17626. * @methodOf ui.grid.importer.api:GridOptions
  17627. * @name importerObjectCallback
  17628. * @description A callback that massages the data for each object. For example,
  17629. * you might have data stored as a code value, but display the decode. This callback
  17630. * can be used to change the decoded value back into a code. Defaults to doing nothing.
  17631. * @param {Grid} grid in case you need it
  17632. * @param {object} newObject the new object as importer has created it, modify it
  17633. * then return the modified version
  17634. * @returns {object} the modified object
  17635. * @example
  17636. * <pre>
  17637. * gridOptions.importerObjectCallback = function ( grid, newObject ) {
  17638. * switch newObject.status {
  17639. * case 'Active':
  17640. * newObject.status = 1;
  17641. * break;
  17642. * case 'Inactive':
  17643. * newObject.status = 2;
  17644. * break;
  17645. * }
  17646. * return newObject;
  17647. * };
  17648. * </pre>
  17649. */
  17650. gridOptions.importerObjectCallback = gridOptions.importerObjectCallback || function( grid, newObject ) { return newObject; };
  17651. },
  17652. /**
  17653. * @ngdoc function
  17654. * @name addToMenu
  17655. * @methodOf ui.grid.importer.service:uiGridImporterService
  17656. * @description Adds import menu item to the grid menu,
  17657. * allowing the user to request import of a file
  17658. * @param {Grid} grid the grid into which data should be imported
  17659. */
  17660. addToMenu: function ( grid ) {
  17661. grid.api.core.addToGridMenu( grid, [
  17662. {
  17663. title: i18nService.getSafeText('gridMenu.importerTitle'),
  17664. order: 150
  17665. },
  17666. {
  17667. templateUrl: 'ui-grid/importerMenuItemContainer',
  17668. action: function ($event) {
  17669. this.grid.api.importer.importAFile( grid );
  17670. },
  17671. order: 151
  17672. }
  17673. ]);
  17674. },
  17675. /**
  17676. * @ngdoc function
  17677. * @name importThisFile
  17678. * @methodOf ui.grid.importer.service:uiGridImporterService
  17679. * @description Imports the provided file into the grid using the file object
  17680. * provided. Bypasses the grid menu
  17681. * @param {Grid} grid the grid we're importing into
  17682. * @param {File} fileObject the file we want to import, as returned from the File
  17683. * javascript object
  17684. */
  17685. importThisFile: function ( grid, fileObject ) {
  17686. if (!fileObject){
  17687. gridUtil.logError( 'No file object provided to importThisFile, should be impossible, aborting');
  17688. return;
  17689. }
  17690. var reader = new FileReader();
  17691. switch ( fileObject.type ){
  17692. case 'application/json':
  17693. reader.onload = service.importJsonClosure( grid );
  17694. break;
  17695. default:
  17696. reader.onload = service.importCsvClosure( grid );
  17697. break;
  17698. }
  17699. reader.readAsText( fileObject );
  17700. },
  17701. /**
  17702. * @ngdoc function
  17703. * @name importJson
  17704. * @methodOf ui.grid.importer.service:uiGridImporterService
  17705. * @description Creates a function that imports a json file into the grid.
  17706. * The json data is imported into new objects of type `gridOptions.importerNewObject`,
  17707. * and if the rowEdit feature is enabled the rows are marked as dirty
  17708. * @param {Grid} grid the grid we want to import into
  17709. * @param {FileObject} importFile the file that we want to import, as
  17710. * a FileObject
  17711. */
  17712. importJsonClosure: function( grid ) {
  17713. return function( importFile ){
  17714. var newObjects = [];
  17715. var newObject;
  17716. var importArray = service.parseJson( grid, importFile );
  17717. if (importArray === null){
  17718. return;
  17719. }
  17720. importArray.forEach( function( value, index ) {
  17721. newObject = service.newObject( grid );
  17722. angular.extend( newObject, value );
  17723. newObject = grid.options.importerObjectCallback( grid, newObject );
  17724. newObjects.push( newObject );
  17725. });
  17726. service.addObjects( grid, newObjects );
  17727. };
  17728. },
  17729. /**
  17730. * @ngdoc function
  17731. * @name parseJson
  17732. * @methodOf ui.grid.importer.service:uiGridImporterService
  17733. * @description Parses a json file, returns the parsed data.
  17734. * Displays an error if file doesn't parse
  17735. * @param {Grid} grid the grid that we want to import into
  17736. * @param {FileObject} importFile the file that we want to import, as
  17737. * a FileObject
  17738. * @returns {array} array of objects from the imported json
  17739. */
  17740. parseJson: function( grid, importFile ){
  17741. var loadedObjects;
  17742. try {
  17743. loadedObjects = JSON.parse( importFile.target.result );
  17744. } catch (e) {
  17745. service.alertError( grid, 'importer.invalidJson', 'File could not be processed, is it valid json? Content was: ', importFile.target.result );
  17746. return;
  17747. }
  17748. if ( !Array.isArray( loadedObjects ) ){
  17749. service.alertError( grid, 'importer.jsonNotarray', 'Import failed, file is not an array, file was: ', importFile.target.result );
  17750. return [];
  17751. } else {
  17752. return loadedObjects;
  17753. }
  17754. },
  17755. /**
  17756. * @ngdoc function
  17757. * @name importCsvClosure
  17758. * @methodOf ui.grid.importer.service:uiGridImporterService
  17759. * @description Creates a function that imports a csv file into the grid
  17760. * (allowing it to be used in the reader.onload event)
  17761. * @param {Grid} grid the grid that we want to import into
  17762. * @param {FileObject} importFile the file that we want to import, as
  17763. * a file object
  17764. */
  17765. importCsvClosure: function( grid ) {
  17766. return function( importFile ){
  17767. var importArray = service.parseCsv( importFile );
  17768. if ( !importArray || importArray.length < 1 ){
  17769. service.alertError( grid, 'importer.invalidCsv', 'File could not be processed, is it valid csv? Content was: ', importFile.target.result );
  17770. return;
  17771. }
  17772. var newObjects = service.createCsvObjects( grid, importArray );
  17773. if ( !newObjects || newObjects.length === 0 ){
  17774. service.alertError( grid, 'importer.noObjects', 'Objects were not able to be derived, content was: ', importFile.target.result );
  17775. return;
  17776. }
  17777. service.addObjects( grid, newObjects );
  17778. };
  17779. },
  17780. /**
  17781. * @ngdoc function
  17782. * @name parseCsv
  17783. * @methodOf ui.grid.importer.service:uiGridImporterService
  17784. * @description Parses a csv file into an array of arrays, with the first
  17785. * array being the headers, and the remaining arrays being the data.
  17786. * The logic for this comes from https://github.com/thetalecrafter/excel.js/blob/master/src/csv.js,
  17787. * which is noted as being under the MIT license. The code is modified to pass the jscs yoda condition
  17788. * checker
  17789. * @param {FileObject} importFile the file that we want to import, as a
  17790. * file object
  17791. */
  17792. parseCsv: function( importFile ) {
  17793. var csv = importFile.target.result;
  17794. // use the CSV-JS library to parse
  17795. return CSV.parse(csv);
  17796. },
  17797. /**
  17798. * @ngdoc function
  17799. * @name createCsvObjects
  17800. * @methodOf ui.grid.importer.service:uiGridImporterService
  17801. * @description Converts an array of arrays (representing the csv file)
  17802. * into a set of objects. Uses the provided `gridOptions.importerNewObject`
  17803. * to create the objects, and maps the header row into the individual columns
  17804. * using either `gridOptions.importerProcessHeaders`, or by using a native method
  17805. * of matching to either the displayName, column name or column field of
  17806. * the columns in the column defs. The resulting objects will have attributes
  17807. * that are named based on the column.field or column.name, in that order.
  17808. * @param {Grid} grid the grid that we want to import into
  17809. * @param {Array} importArray the data that we want to import, as an array
  17810. */
  17811. createCsvObjects: function( grid, importArray ){
  17812. // pull off header row and turn into headers
  17813. var headerMapping = grid.options.importerProcessHeaders( grid, importArray.shift() );
  17814. if ( !headerMapping || headerMapping.length === 0 ){
  17815. service.alertError( grid, 'importer.noHeaders', 'Column names could not be derived, content was: ', importArray );
  17816. return [];
  17817. }
  17818. var newObjects = [];
  17819. var newObject;
  17820. importArray.forEach( function( row, index ) {
  17821. newObject = service.newObject( grid );
  17822. if ( row !== null ){
  17823. row.forEach( function( field, index ){
  17824. if ( headerMapping[index] !== null ){
  17825. newObject[ headerMapping[index] ] = field;
  17826. }
  17827. });
  17828. }
  17829. newObject = grid.options.importerObjectCallback( grid, newObject );
  17830. newObjects.push( newObject );
  17831. });
  17832. return newObjects;
  17833. },
  17834. /**
  17835. * @ngdoc function
  17836. * @name processHeaders
  17837. * @methodOf ui.grid.importer.service:uiGridImporterService
  17838. * @description Determines the columns that the header row from
  17839. * a csv (or other) file represents.
  17840. * @param {Grid} grid the grid we're importing into
  17841. * @param {array} headerRow the header row that we wish to match against
  17842. * the column definitions
  17843. * @returns {array} an array of the attribute names that should be used
  17844. * for that column, based on matching the headers or creating the headers
  17845. *
  17846. */
  17847. processHeaders: function( grid, headerRow ) {
  17848. var headers = [];
  17849. if ( !grid.options.columnDefs || grid.options.columnDefs.length === 0 ){
  17850. // we are going to create new columnDefs for all these columns, so just remove
  17851. // spaces from the names to create fields
  17852. headerRow.forEach( function( value, index ) {
  17853. headers.push( value.replace( /[^0-9a-zA-Z\-_]/g, '_' ) );
  17854. });
  17855. return headers;
  17856. } else {
  17857. var lookupHash = service.flattenColumnDefs( grid, grid.options.columnDefs );
  17858. headerRow.forEach( function( value, index ) {
  17859. if ( lookupHash[value] ) {
  17860. headers.push( lookupHash[value] );
  17861. } else if ( lookupHash[ value.toLowerCase() ] ) {
  17862. headers.push( lookupHash[ value.toLowerCase() ] );
  17863. } else {
  17864. headers.push( null );
  17865. }
  17866. });
  17867. return headers;
  17868. }
  17869. },
  17870. /**
  17871. * @name flattenColumnDefs
  17872. * @methodOf ui.grid.importer.service:uiGridImporterService
  17873. * @description Runs through the column defs and creates a hash of
  17874. * the displayName, name and field, and of each of those values forced to lower case,
  17875. * with each pointing to the field or name
  17876. * (whichever is present). Used to lookup column headers and decide what
  17877. * attribute name to give to the resulting field.
  17878. * @param {Grid} grid the grid we're importing into
  17879. * @param {array} columnDefs the columnDefs that we should flatten
  17880. * @returns {hash} the flattened version of the column def information, allowing
  17881. * us to look up a value by `flattenedHash[ headerValue ]`
  17882. */
  17883. flattenColumnDefs: function( grid, columnDefs ){
  17884. var flattenedHash = {};
  17885. columnDefs.forEach( function( columnDef, index) {
  17886. if ( columnDef.name ){
  17887. flattenedHash[ columnDef.name ] = columnDef.field || columnDef.name;
  17888. flattenedHash[ columnDef.name.toLowerCase() ] = columnDef.field || columnDef.name;
  17889. }
  17890. if ( columnDef.field ){
  17891. flattenedHash[ columnDef.field ] = columnDef.field || columnDef.name;
  17892. flattenedHash[ columnDef.field.toLowerCase() ] = columnDef.field || columnDef.name;
  17893. }
  17894. if ( columnDef.displayName ){
  17895. flattenedHash[ columnDef.displayName ] = columnDef.field || columnDef.name;
  17896. flattenedHash[ columnDef.displayName.toLowerCase() ] = columnDef.field || columnDef.name;
  17897. }
  17898. if ( columnDef.displayName && grid.options.importerHeaderFilter ){
  17899. flattenedHash[ grid.options.importerHeaderFilter(columnDef.displayName) ] = columnDef.field || columnDef.name;
  17900. flattenedHash[ grid.options.importerHeaderFilter(columnDef.displayName).toLowerCase() ] = columnDef.field || columnDef.name;
  17901. }
  17902. });
  17903. return flattenedHash;
  17904. },
  17905. /**
  17906. * @ngdoc function
  17907. * @name addObjects
  17908. * @methodOf ui.grid.importer.service:uiGridImporterService
  17909. * @description Inserts our new objects into the grid data, and
  17910. * sets the rows to dirty if the rowEdit feature is being used
  17911. *
  17912. * Does this by registering a watch on dataChanges, which essentially
  17913. * is waiting on the result of the grid data watch, and downstream processing.
  17914. *
  17915. * When the callback is called, it deregisters itself - we don't want to run
  17916. * again next time data is added.
  17917. *
  17918. * If we never get called, we deregister on destroy.
  17919. *
  17920. * @param {Grid} grid the grid we're importing into
  17921. * @param {array} newObjects the objects we want to insert into the grid data
  17922. * @returns {object} the new object
  17923. */
  17924. addObjects: function( grid, newObjects, $scope ){
  17925. if ( grid.api.rowEdit ){
  17926. var dataChangeDereg = grid.registerDataChangeCallback( function() {
  17927. grid.api.rowEdit.setRowsDirty( newObjects );
  17928. dataChangeDereg();
  17929. }, [uiGridConstants.dataChange.ROW] );
  17930. grid.importer.$scope.$on( '$destroy', dataChangeDereg );
  17931. }
  17932. grid.importer.$scope.$apply( grid.options.importerDataAddCallback( grid, newObjects ) );
  17933. },
  17934. /**
  17935. * @ngdoc function
  17936. * @name newObject
  17937. * @methodOf ui.grid.importer.service:uiGridImporterService
  17938. * @description Makes a new object based on `gridOptions.importerNewObject`,
  17939. * or based on an empty object if not present
  17940. * @param {Grid} grid the grid we're importing into
  17941. * @returns {object} the new object
  17942. */
  17943. newObject: function( grid ){
  17944. if ( typeof(grid.options) !== "undefined" && typeof(grid.options.importerNewObject) !== "undefined" ){
  17945. return new grid.options.importerNewObject();
  17946. } else {
  17947. return {};
  17948. }
  17949. },
  17950. /**
  17951. * @ngdoc function
  17952. * @name alertError
  17953. * @methodOf ui.grid.importer.service:uiGridImporterService
  17954. * @description Provides an internationalised user alert for the failure,
  17955. * and logs a console message including diagnostic content.
  17956. * Optionally, if the the `gridOptions.importerErrorCallback` routine
  17957. * is defined, then calls that instead, allowing user specified error routines
  17958. * @param {Grid} grid the grid we're importing into
  17959. * @param {array} headerRow the header row that we wish to match against
  17960. * the column definitions
  17961. */
  17962. alertError: function( grid, alertI18nToken, consoleMessage, context ){
  17963. if ( grid.options.importerErrorCallback ){
  17964. grid.options.importerErrorCallback( grid, alertI18nToken, consoleMessage, context );
  17965. } else {
  17966. $window.alert(i18nService.getSafeText( alertI18nToken ));
  17967. gridUtil.logError(consoleMessage + context );
  17968. }
  17969. }
  17970. };
  17971. return service;
  17972. }
  17973. ]);
  17974. /**
  17975. * @ngdoc directive
  17976. * @name ui.grid.importer.directive:uiGridImporter
  17977. * @element div
  17978. * @restrict A
  17979. *
  17980. * @description Adds importer features to grid
  17981. *
  17982. */
  17983. module.directive('uiGridImporter', ['uiGridImporterConstants', 'uiGridImporterService', 'gridUtil', '$compile',
  17984. function (uiGridImporterConstants, uiGridImporterService, gridUtil, $compile) {
  17985. return {
  17986. replace: true,
  17987. priority: 0,
  17988. require: '^uiGrid',
  17989. scope: false,
  17990. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  17991. uiGridImporterService.initializeGrid($scope, uiGridCtrl.grid);
  17992. }
  17993. };
  17994. }
  17995. ]);
  17996. /**
  17997. * @ngdoc directive
  17998. * @name ui.grid.importer.directive:uiGridImporterMenuItem
  17999. * @element div
  18000. * @restrict A
  18001. *
  18002. * @description Handles the processing from the importer menu item - once a file is
  18003. * selected
  18004. *
  18005. */
  18006. module.directive('uiGridImporterMenuItem', ['uiGridImporterConstants', 'uiGridImporterService', 'gridUtil', '$compile',
  18007. function (uiGridImporterConstants, uiGridImporterService, gridUtil, $compile) {
  18008. return {
  18009. replace: true,
  18010. priority: 0,
  18011. require: '^uiGrid',
  18012. scope: false,
  18013. templateUrl: 'ui-grid/importerMenuItem',
  18014. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  18015. var handleFileSelect = function( event ){
  18016. var target = event.srcElement || event.target;
  18017. if (target && target.files && target.files.length === 1) {
  18018. var fileObject = target.files[0];
  18019. uiGridImporterService.importThisFile( grid, fileObject );
  18020. target.form.reset();
  18021. }
  18022. };
  18023. var fileChooser = $elm[0].querySelectorAll('.ui-grid-importer-file-chooser');
  18024. var grid = uiGridCtrl.grid;
  18025. if ( fileChooser.length !== 1 ){
  18026. gridUtil.logError('Found > 1 or < 1 file choosers within the menu item, error, cannot continue');
  18027. } else {
  18028. fileChooser[0].addEventListener('change', handleFileSelect, false); // TODO: why the false on the end? Google
  18029. }
  18030. }
  18031. };
  18032. }
  18033. ]);
  18034. })();
  18035. (function() {
  18036. 'use strict';
  18037. /**
  18038. * @ngdoc overview
  18039. * @name ui.grid.infiniteScroll
  18040. *
  18041. * @description
  18042. *
  18043. * #ui.grid.infiniteScroll
  18044. *
  18045. * <div class="alert alert-warning" role="alert"><strong>Beta</strong> This feature is ready for testing, but it either hasn't seen a lot of use or has some known bugs.</div>
  18046. *
  18047. * This module provides infinite scroll functionality to ui-grid
  18048. *
  18049. */
  18050. var module = angular.module('ui.grid.infiniteScroll', ['ui.grid']);
  18051. /**
  18052. * @ngdoc service
  18053. * @name ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  18054. *
  18055. * @description Service for infinite scroll features
  18056. */
  18057. module.service('uiGridInfiniteScrollService', ['gridUtil', '$compile', '$timeout', 'uiGridConstants', 'ScrollEvent', '$q', function (gridUtil, $compile, $timeout, uiGridConstants, ScrollEvent, $q) {
  18058. var service = {
  18059. /**
  18060. * @ngdoc function
  18061. * @name initializeGrid
  18062. * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  18063. * @description This method register events and methods into grid public API
  18064. */
  18065. initializeGrid: function(grid, $scope) {
  18066. service.defaultGridOptions(grid.options);
  18067. if (!grid.options.enableInfiniteScroll){
  18068. return;
  18069. }
  18070. grid.infiniteScroll = { dataLoading: false };
  18071. service.setScrollDirections( grid, grid.options.infiniteScrollUp, grid.options.infiniteScrollDown );
  18072. grid.api.core.on.scrollEnd($scope, service.handleScroll);
  18073. /**
  18074. * @ngdoc object
  18075. * @name ui.grid.infiniteScroll.api:PublicAPI
  18076. *
  18077. * @description Public API for infinite scroll feature
  18078. */
  18079. var publicApi = {
  18080. events: {
  18081. infiniteScroll: {
  18082. /**
  18083. * @ngdoc event
  18084. * @name needLoadMoreData
  18085. * @eventOf ui.grid.infiniteScroll.api:PublicAPI
  18086. * @description This event fires when scroll reaches bottom percentage of grid
  18087. * and needs to load data
  18088. */
  18089. needLoadMoreData: function ($scope, fn) {
  18090. },
  18091. /**
  18092. * @ngdoc event
  18093. * @name needLoadMoreDataTop
  18094. * @eventOf ui.grid.infiniteScroll.api:PublicAPI
  18095. * @description This event fires when scroll reaches top percentage of grid
  18096. * and needs to load data
  18097. */
  18098. needLoadMoreDataTop: function ($scope, fn) {
  18099. }
  18100. }
  18101. },
  18102. methods: {
  18103. infiniteScroll: {
  18104. /**
  18105. * @ngdoc function
  18106. * @name dataLoaded
  18107. * @methodOf ui.grid.infiniteScroll.api:PublicAPI
  18108. * @description Call this function when you have loaded the additional data
  18109. * requested. You should set scrollUp and scrollDown to indicate
  18110. * whether there are still more pages in each direction.
  18111. *
  18112. * If you call dataLoaded without first calling `saveScrollPercentage` then we will
  18113. * scroll the user to the start of the newly loaded data, which usually gives a smooth scroll
  18114. * experience, but can give a jumpy experience with large `infiniteScrollRowsFromEnd` values, and
  18115. * on variable speed internet connections. Using `saveScrollPercentage` as demonstrated in the tutorial
  18116. * should give a smoother scrolling experience for users.
  18117. *
  18118. * See infinite_scroll tutorial for example of usage
  18119. * @param {boolean} scrollUp if set to false flags that there are no more pages upwards, so don't fire
  18120. * any more infinite scroll events upward
  18121. * @param {boolean} scrollDown if set to false flags that there are no more pages downwards, so don't
  18122. * fire any more infinite scroll events downward
  18123. * @returns {promise} a promise that is resolved when the grid scrolling is fully adjusted. If you're
  18124. * planning to remove pages, you should wait on this promise first, or you'll break the scroll positioning
  18125. */
  18126. dataLoaded: function( scrollUp, scrollDown ) {
  18127. service.setScrollDirections(grid, scrollUp, scrollDown);
  18128. var promise = service.adjustScroll(grid).then(function() {
  18129. grid.infiniteScroll.dataLoading = false;
  18130. });
  18131. return promise;
  18132. },
  18133. /**
  18134. * @ngdoc function
  18135. * @name resetScroll
  18136. * @methodOf ui.grid.infiniteScroll.api:PublicAPI
  18137. * @description Call this function when you have taken some action that makes the current
  18138. * scroll position invalid. For example, if you're using external sorting and you've resorted
  18139. * then you might reset the scroll, or if you've otherwise substantially changed the data, perhaps
  18140. * you've reused an existing grid for a new data set
  18141. *
  18142. * You must tell us whether there is data upwards or downwards after the reset
  18143. *
  18144. * @param {boolean} scrollUp flag that there are pages upwards, fire
  18145. * infinite scroll events upward
  18146. * @param {boolean} scrollDown flag that there are pages downwards, so
  18147. * fire infinite scroll events downward
  18148. * @returns {promise} promise that is resolved when the scroll reset is complete
  18149. */
  18150. resetScroll: function( scrollUp, scrollDown ) {
  18151. service.setScrollDirections( grid, scrollUp, scrollDown);
  18152. return service.adjustInfiniteScrollPosition(grid, 0);
  18153. },
  18154. /**
  18155. * @ngdoc function
  18156. * @name saveScrollPercentage
  18157. * @methodOf ui.grid.infiniteScroll.api:PublicAPI
  18158. * @description Saves the scroll percentage and number of visible rows before you adjust the data,
  18159. * used if you're subsequently going to call `dataRemovedTop` or `dataRemovedBottom`
  18160. */
  18161. saveScrollPercentage: function() {
  18162. grid.infiniteScroll.prevScrollTop = grid.renderContainers.body.prevScrollTop;
  18163. grid.infiniteScroll.previousVisibleRows = grid.getVisibleRowCount();
  18164. },
  18165. /**
  18166. * @ngdoc function
  18167. * @name dataRemovedTop
  18168. * @methodOf ui.grid.infiniteScroll.api:PublicAPI
  18169. * @description Adjusts the scroll position after you've removed data at the top
  18170. * @param {boolean} scrollUp flag that there are pages upwards, fire
  18171. * infinite scroll events upward
  18172. * @param {boolean} scrollDown flag that there are pages downwards, so
  18173. * fire infinite scroll events downward
  18174. */
  18175. dataRemovedTop: function( scrollUp, scrollDown ) {
  18176. service.dataRemovedTop( grid, scrollUp, scrollDown );
  18177. },
  18178. /**
  18179. * @ngdoc function
  18180. * @name dataRemovedBottom
  18181. * @methodOf ui.grid.infiniteScroll.api:PublicAPI
  18182. * @description Adjusts the scroll position after you've removed data at the bottom
  18183. * @param {boolean} scrollUp flag that there are pages upwards, fire
  18184. * infinite scroll events upward
  18185. * @param {boolean} scrollDown flag that there are pages downwards, so
  18186. * fire infinite scroll events downward
  18187. */
  18188. dataRemovedBottom: function( scrollUp, scrollDown ) {
  18189. service.dataRemovedBottom( grid, scrollUp, scrollDown );
  18190. },
  18191. /**
  18192. * @ngdoc function
  18193. * @name setScrollDirections
  18194. * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  18195. * @description Sets the scrollUp and scrollDown flags, handling nulls and undefined,
  18196. * and also sets the grid.suppressParentScroll
  18197. * @param {boolean} scrollUp whether there are pages available up - defaults to false
  18198. * @param {boolean} scrollDown whether there are pages available down - defaults to true
  18199. */
  18200. setScrollDirections: function ( scrollUp, scrollDown ) {
  18201. service.setScrollDirections( grid, scrollUp, scrollDown );
  18202. }
  18203. }
  18204. }
  18205. };
  18206. grid.api.registerEventsFromObject(publicApi.events);
  18207. grid.api.registerMethodsFromObject(publicApi.methods);
  18208. },
  18209. defaultGridOptions: function (gridOptions) {
  18210. //default option to true unless it was explicitly set to false
  18211. /**
  18212. * @ngdoc object
  18213. * @name ui.grid.infiniteScroll.api:GridOptions
  18214. *
  18215. * @description GridOptions for infinite scroll feature, these are available to be
  18216. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  18217. */
  18218. /**
  18219. * @ngdoc object
  18220. * @name enableInfiniteScroll
  18221. * @propertyOf ui.grid.infiniteScroll.api:GridOptions
  18222. * @description Enable infinite scrolling for this grid
  18223. * <br/>Defaults to true
  18224. */
  18225. gridOptions.enableInfiniteScroll = gridOptions.enableInfiniteScroll !== false;
  18226. /**
  18227. * @ngdoc property
  18228. * @name infiniteScrollRowsFromEnd
  18229. * @propertyOf ui.grid.class:GridOptions
  18230. * @description This setting controls how close to the end of the dataset a user gets before
  18231. * more data is requested by the infinite scroll, whether scrolling up or down. This allows you to
  18232. * 'prefetch' rows before the user actually runs out of scrolling.
  18233. *
  18234. * Note that if you set this value too high it may give jumpy scrolling behaviour, if you're getting
  18235. * this behaviour you could use the `saveScrollPercentageMethod` right before loading your data, and we'll
  18236. * preserve that scroll position
  18237. *
  18238. * <br> Defaults to 20
  18239. */
  18240. gridOptions.infiniteScrollRowsFromEnd = gridOptions.infiniteScrollRowsFromEnd || 20;
  18241. /**
  18242. * @ngdoc property
  18243. * @name infiniteScrollUp
  18244. * @propertyOf ui.grid.class:GridOptions
  18245. * @description Whether you allow infinite scroll up, implying that the first page of data
  18246. * you have displayed is in the middle of your data set. If set to true then we trigger the
  18247. * needMoreDataTop event when the user hits the top of the scrollbar.
  18248. * <br> Defaults to false
  18249. */
  18250. gridOptions.infiniteScrollUp = gridOptions.infiniteScrollUp === true;
  18251. /**
  18252. * @ngdoc property
  18253. * @name infiniteScrollDown
  18254. * @propertyOf ui.grid.class:GridOptions
  18255. * @description Whether you allow infinite scroll down, implying that the first page of data
  18256. * you have displayed is in the middle of your data set. If set to true then we trigger the
  18257. * needMoreData event when the user hits the bottom of the scrollbar.
  18258. * <br> Defaults to true
  18259. */
  18260. gridOptions.infiniteScrollDown = gridOptions.infiniteScrollDown !== false;
  18261. },
  18262. /**
  18263. * @ngdoc function
  18264. * @name setScrollDirections
  18265. * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  18266. * @description Sets the scrollUp and scrollDown flags, handling nulls and undefined,
  18267. * and also sets the grid.suppressParentScroll
  18268. * @param {grid} grid the grid we're operating on
  18269. * @param {boolean} scrollUp whether there are pages available up - defaults to false
  18270. * @param {boolean} scrollDown whether there are pages available down - defaults to true
  18271. */
  18272. setScrollDirections: function ( grid, scrollUp, scrollDown ) {
  18273. grid.infiniteScroll.scrollUp = ( scrollUp === true );
  18274. grid.suppressParentScrollUp = ( scrollUp === true );
  18275. grid.infiniteScroll.scrollDown = ( scrollDown !== false);
  18276. grid.suppressParentScrollDown = ( scrollDown !== false);
  18277. },
  18278. /**
  18279. * @ngdoc function
  18280. * @name handleScroll
  18281. * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  18282. * @description Called whenever the grid scrolls, determines whether the scroll should
  18283. * trigger an infinite scroll request for more data
  18284. * @param {object} args the args from the event
  18285. */
  18286. handleScroll: function (args) {
  18287. // don't request data if already waiting for data, or if source is coming from ui.grid.adjustInfiniteScrollPosition() function
  18288. if ( args.grid.infiniteScroll && args.grid.infiniteScroll.dataLoading || args.source === 'ui.grid.adjustInfiniteScrollPosition' ){
  18289. return;
  18290. }
  18291. if (args.y) {
  18292. var percentage;
  18293. var targetPercentage = args.grid.options.infiniteScrollRowsFromEnd / args.grid.renderContainers.body.visibleRowCache.length;
  18294. if (args.grid.scrollDirection === uiGridConstants.scrollDirection.UP ) {
  18295. percentage = args.y.percentage;
  18296. if (percentage <= targetPercentage){
  18297. service.loadData(args.grid);
  18298. }
  18299. } else if (args.grid.scrollDirection === uiGridConstants.scrollDirection.DOWN) {
  18300. percentage = 1 - args.y.percentage;
  18301. if (percentage <= targetPercentage){
  18302. service.loadData(args.grid);
  18303. }
  18304. }
  18305. }
  18306. },
  18307. /**
  18308. * @ngdoc function
  18309. * @name loadData
  18310. * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  18311. * @description This function fires 'needLoadMoreData' or 'needLoadMoreDataTop' event based on scrollDirection
  18312. * and whether there are more pages upwards or downwards. It also stores the number of rows that we had previously,
  18313. * and clears out any saved scroll position so that we know whether or not the user calls `saveScrollPercentage`
  18314. * @param {Grid} grid the grid we're working on
  18315. */
  18316. loadData: function (grid) {
  18317. // save number of currently visible rows to calculate new scroll position later - we know that we want
  18318. // to be at approximately the row we're currently at
  18319. grid.infiniteScroll.previousVisibleRows = grid.renderContainers.body.visibleRowCache.length;
  18320. grid.infiniteScroll.direction = grid.scrollDirection;
  18321. delete grid.infiniteScroll.prevScrollTop;
  18322. if (grid.scrollDirection === uiGridConstants.scrollDirection.UP && grid.infiniteScroll.scrollUp ) {
  18323. grid.infiniteScroll.dataLoading = true;
  18324. grid.api.infiniteScroll.raise.needLoadMoreDataTop();
  18325. } else if (grid.scrollDirection === uiGridConstants.scrollDirection.DOWN && grid.infiniteScroll.scrollDown ) {
  18326. grid.infiniteScroll.dataLoading = true;
  18327. grid.api.infiniteScroll.raise.needLoadMoreData();
  18328. }
  18329. },
  18330. /**
  18331. * @ngdoc function
  18332. * @name adjustScroll
  18333. * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  18334. * @description Once we are informed that data has been loaded, adjust the scroll position to account for that
  18335. * addition and to make things look clean.
  18336. *
  18337. * If we're scrolling up we scroll to the first row of the old data set -
  18338. * so we're assuming that you would have gotten to the top of the grid (from the 20% need more data trigger) by
  18339. * the time the data comes back. If we're scrolling down we scoll to the last row of the old data set - so we're
  18340. * assuming that you would have gotten to the bottom of the grid (from the 80% need more data trigger) by the time
  18341. * the data comes back.
  18342. *
  18343. * Neither of these are good assumptions, but making this a smoother experience really requires
  18344. * that trigger to not be a percentage, and to be much closer to the end of the data (say, 5 rows off the end). Even then
  18345. * it'd be better still to actually run into the end. But if the data takes a while to come back, they may have scrolled
  18346. * somewhere else in the mean-time, in which case they'll get a jump back to the new data. Anyway, this will do for
  18347. * now, until someone wants to do better.
  18348. * @param {Grid} grid the grid we're working on
  18349. * @returns {promise} a promise that is resolved when scrolling has finished
  18350. */
  18351. adjustScroll: function(grid){
  18352. var promise = $q.defer();
  18353. $timeout(function () {
  18354. var newPercentage, viewportHeight, rowHeight, newVisibleRows, oldTop, newTop;
  18355. viewportHeight = grid.getViewportHeight() + grid.headerHeight - grid.renderContainers.body.headerHeight - grid.scrollbarHeight;
  18356. rowHeight = grid.options.rowHeight;
  18357. if ( grid.infiniteScroll.direction === undefined ){
  18358. // called from initialize, tweak our scroll up a little
  18359. service.adjustInfiniteScrollPosition(grid, 0);
  18360. }
  18361. newVisibleRows = grid.getVisibleRowCount();
  18362. // in case not enough data is loaded to enable scroller - load more data
  18363. var canvasHeight = rowHeight * newVisibleRows;
  18364. if (grid.infiniteScroll.scrollDown && (viewportHeight > canvasHeight)) {
  18365. grid.api.infiniteScroll.raise.needLoadMoreData();
  18366. }
  18367. if ( grid.infiniteScroll.direction === uiGridConstants.scrollDirection.UP ){
  18368. oldTop = grid.infiniteScroll.prevScrollTop || 0;
  18369. newTop = oldTop + (newVisibleRows - grid.infiniteScroll.previousVisibleRows)*rowHeight;
  18370. service.adjustInfiniteScrollPosition(grid, newTop);
  18371. $timeout( function() {
  18372. promise.resolve();
  18373. });
  18374. }
  18375. if ( grid.infiniteScroll.direction === uiGridConstants.scrollDirection.DOWN ){
  18376. newTop = grid.infiniteScroll.prevScrollTop || (grid.infiniteScroll.previousVisibleRows*rowHeight - viewportHeight);
  18377. service.adjustInfiniteScrollPosition(grid, newTop);
  18378. $timeout( function() {
  18379. promise.resolve();
  18380. });
  18381. }
  18382. }, 0);
  18383. return promise.promise;
  18384. },
  18385. /**
  18386. * @ngdoc function
  18387. * @name adjustInfiniteScrollPosition
  18388. * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  18389. * @description This function fires 'needLoadMoreData' or 'needLoadMoreDataTop' event based on scrollDirection
  18390. * @param {Grid} grid the grid we're working on
  18391. * @param {number} scrollTop the position through the grid that we want to scroll to
  18392. * @returns {promise} a promise that is resolved when the scrolling finishes
  18393. */
  18394. adjustInfiniteScrollPosition: function (grid, scrollTop) {
  18395. var scrollEvent = new ScrollEvent(grid, null, null, 'ui.grid.adjustInfiniteScrollPosition'),
  18396. visibleRows = grid.getVisibleRowCount(),
  18397. viewportHeight = grid.getViewportHeight() + grid.headerHeight - grid.renderContainers.body.headerHeight - grid.scrollbarHeight,
  18398. rowHeight = grid.options.rowHeight,
  18399. scrollHeight = visibleRows*rowHeight-viewportHeight;
  18400. //for infinite scroll, if there are pages upwards then never allow it to be at the zero position so the up button can be active
  18401. if (scrollTop === 0 && grid.infiniteScroll.scrollUp) {
  18402. // using pixels results in a relative scroll, hence we have to use percentage
  18403. scrollEvent.y = {percentage: 1/scrollHeight};
  18404. }
  18405. else {
  18406. scrollEvent.y = {percentage: scrollTop/scrollHeight};
  18407. }
  18408. grid.scrollContainers('', scrollEvent);
  18409. },
  18410. /**
  18411. * @ngdoc function
  18412. * @name dataRemovedTop
  18413. * @methodOf ui.grid.infiniteScroll.api:PublicAPI
  18414. * @description Adjusts the scroll position after you've removed data at the top. You should
  18415. * have called `saveScrollPercentage` before you remove the data, and if you're doing this in
  18416. * response to a `needMoreData` you should wait until the promise from `loadData` has resolved
  18417. * before you start removing data
  18418. * @param {Grid} grid the grid we're working on
  18419. * @param {boolean} scrollUp flag that there are pages upwards, fire
  18420. * infinite scroll events upward
  18421. * @param {boolean} scrollDown flag that there are pages downwards, so
  18422. * fire infinite scroll events downward
  18423. * @returns {promise} a promise that is resolved when the scrolling finishes
  18424. */
  18425. dataRemovedTop: function( grid, scrollUp, scrollDown ) {
  18426. var newVisibleRows, oldTop, newTop, rowHeight;
  18427. service.setScrollDirections( grid, scrollUp, scrollDown );
  18428. newVisibleRows = grid.renderContainers.body.visibleRowCache.length;
  18429. oldTop = grid.infiniteScroll.prevScrollTop;
  18430. rowHeight = grid.options.rowHeight;
  18431. // since we removed from the top, our new scroll row will be the old scroll row less the number
  18432. // of rows removed
  18433. newTop = oldTop - ( grid.infiniteScroll.previousVisibleRows - newVisibleRows )*rowHeight;
  18434. return service.adjustInfiniteScrollPosition( grid, newTop );
  18435. },
  18436. /**
  18437. * @ngdoc function
  18438. * @name dataRemovedBottom
  18439. * @methodOf ui.grid.infiniteScroll.api:PublicAPI
  18440. * @description Adjusts the scroll position after you've removed data at the bottom. You should
  18441. * have called `saveScrollPercentage` before you remove the data, and if you're doing this in
  18442. * response to a `needMoreData` you should wait until the promise from `loadData` has resolved
  18443. * before you start removing data
  18444. * @param {Grid} grid the grid we're working on
  18445. * @param {boolean} scrollUp flag that there are pages upwards, fire
  18446. * infinite scroll events upward
  18447. * @param {boolean} scrollDown flag that there are pages downwards, so
  18448. * fire infinite scroll events downward
  18449. */
  18450. dataRemovedBottom: function( grid, scrollUp, scrollDown ) {
  18451. var newTop;
  18452. service.setScrollDirections( grid, scrollUp, scrollDown );
  18453. newTop = grid.infiniteScroll.prevScrollTop;
  18454. return service.adjustInfiniteScrollPosition( grid, newTop );
  18455. }
  18456. };
  18457. return service;
  18458. }]);
  18459. /**
  18460. * @ngdoc directive
  18461. * @name ui.grid.infiniteScroll.directive:uiGridInfiniteScroll
  18462. * @element div
  18463. * @restrict A
  18464. *
  18465. * @description Adds infinite scroll features to grid
  18466. *
  18467. * @example
  18468. <example module="app">
  18469. <file name="app.js">
  18470. var app = angular.module('app', ['ui.grid', 'ui.grid.infiniteScroll']);
  18471. app.controller('MainCtrl', ['$scope', function ($scope) {
  18472. $scope.data = [
  18473. { name: 'Alex', car: 'Toyota' },
  18474. { name: 'Sam', car: 'Lexus' }
  18475. ];
  18476. $scope.columnDefs = [
  18477. {name: 'name'},
  18478. {name: 'car'}
  18479. ];
  18480. }]);
  18481. </file>
  18482. <file name="index.html">
  18483. <div ng-controller="MainCtrl">
  18484. <div ui-grid="{ data: data, columnDefs: columnDefs }" ui-grid-infinite-scroll="20"></div>
  18485. </div>
  18486. </file>
  18487. </example>
  18488. */
  18489. module.directive('uiGridInfiniteScroll', ['uiGridInfiniteScrollService',
  18490. function (uiGridInfiniteScrollService) {
  18491. return {
  18492. priority: -200,
  18493. scope: false,
  18494. require: '^uiGrid',
  18495. compile: function($scope, $elm, $attr){
  18496. return {
  18497. pre: function($scope, $elm, $attr, uiGridCtrl) {
  18498. uiGridInfiniteScrollService.initializeGrid(uiGridCtrl.grid, $scope);
  18499. },
  18500. post: function($scope, $elm, $attr) {
  18501. }
  18502. };
  18503. }
  18504. };
  18505. }]);
  18506. })();
  18507. (function () {
  18508. 'use strict';
  18509. /**
  18510. * @ngdoc overview
  18511. * @name ui.grid.moveColumns
  18512. * @description
  18513. *
  18514. * # ui.grid.moveColumns
  18515. *
  18516. * <div class="alert alert-warning" role="alert"><strong>Alpha</strong> This feature is in development. There will almost certainly be breaking api changes, or there are major outstanding bugs.</div>
  18517. *
  18518. * This module provides column moving capability to ui.grid. It enables to change the position of columns.
  18519. * <div doc-module-components="ui.grid.moveColumns"></div>
  18520. */
  18521. var module = angular.module('ui.grid.moveColumns', ['ui.grid']);
  18522. /**
  18523. * @ngdoc service
  18524. * @name ui.grid.moveColumns.service:uiGridMoveColumnService
  18525. * @description Service for column moving feature.
  18526. */
  18527. module.service('uiGridMoveColumnService', ['$q', '$timeout', '$log', 'ScrollEvent', 'uiGridConstants', 'gridUtil', function ($q, $timeout, $log, ScrollEvent, uiGridConstants, gridUtil) {
  18528. var service = {
  18529. initializeGrid: function (grid) {
  18530. var self = this;
  18531. this.registerPublicApi(grid);
  18532. this.defaultGridOptions(grid.options);
  18533. grid.moveColumns = {orderCache: []}; // Used to cache the order before columns are rebuilt
  18534. grid.registerColumnBuilder(self.movableColumnBuilder);
  18535. grid.registerDataChangeCallback(self.verifyColumnOrder, [uiGridConstants.dataChange.COLUMN]);
  18536. },
  18537. registerPublicApi: function (grid) {
  18538. var self = this;
  18539. /**
  18540. * @ngdoc object
  18541. * @name ui.grid.moveColumns.api:PublicApi
  18542. * @description Public Api for column moving feature.
  18543. */
  18544. var publicApi = {
  18545. events: {
  18546. /**
  18547. * @ngdoc event
  18548. * @name columnPositionChanged
  18549. * @eventOf ui.grid.moveColumns.api:PublicApi
  18550. * @description raised when column is moved
  18551. * <pre>
  18552. * gridApi.colMovable.on.columnPositionChanged(scope,function(colDef, originalPosition, newPosition){})
  18553. * </pre>
  18554. * @param {object} colDef the column that was moved
  18555. * @param {integer} originalPosition of the column
  18556. * @param {integer} finalPosition of the column
  18557. */
  18558. colMovable: {
  18559. columnPositionChanged: function (colDef, originalPosition, newPosition) {
  18560. }
  18561. }
  18562. },
  18563. methods: {
  18564. /**
  18565. * @ngdoc method
  18566. * @name moveColumn
  18567. * @methodOf ui.grid.moveColumns.api:PublicApi
  18568. * @description Method can be used to change column position.
  18569. * <pre>
  18570. * gridApi.colMovable.moveColumn(oldPosition, newPosition)
  18571. * </pre>
  18572. * @param {integer} originalPosition of the column
  18573. * @param {integer} finalPosition of the column
  18574. */
  18575. colMovable: {
  18576. moveColumn: function (originalPosition, finalPosition) {
  18577. var columns = grid.columns;
  18578. if (!angular.isNumber(originalPosition) || !angular.isNumber(finalPosition)) {
  18579. gridUtil.logError('MoveColumn: Please provide valid values for originalPosition and finalPosition');
  18580. return;
  18581. }
  18582. var nonMovableColumns = 0;
  18583. for (var i = 0; i < columns.length; i++) {
  18584. if ((angular.isDefined(columns[i].colDef.visible) && columns[i].colDef.visible === false) || columns[i].isRowHeader === true) {
  18585. nonMovableColumns++;
  18586. }
  18587. }
  18588. if (originalPosition >= (columns.length - nonMovableColumns) || finalPosition >= (columns.length - nonMovableColumns)) {
  18589. gridUtil.logError('MoveColumn: Invalid values for originalPosition, finalPosition');
  18590. return;
  18591. }
  18592. var findPositionForRenderIndex = function (index) {
  18593. var position = index;
  18594. for (var i = 0; i <= position; i++) {
  18595. if (angular.isDefined(columns[i]) && ((angular.isDefined(columns[i].colDef.visible) && columns[i].colDef.visible === false) || columns[i].isRowHeader === true)) {
  18596. position++;
  18597. }
  18598. }
  18599. return position;
  18600. };
  18601. self.redrawColumnAtPosition(grid, findPositionForRenderIndex(originalPosition), findPositionForRenderIndex(finalPosition));
  18602. }
  18603. }
  18604. }
  18605. };
  18606. grid.api.registerEventsFromObject(publicApi.events);
  18607. grid.api.registerMethodsFromObject(publicApi.methods);
  18608. },
  18609. defaultGridOptions: function (gridOptions) {
  18610. /**
  18611. * @ngdoc object
  18612. * @name ui.grid.moveColumns.api:GridOptions
  18613. *
  18614. * @description Options for configuring the move column feature, these are available to be
  18615. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  18616. */
  18617. /**
  18618. * @ngdoc object
  18619. * @name enableColumnMoving
  18620. * @propertyOf ui.grid.moveColumns.api:GridOptions
  18621. * @description If defined, sets the default value for the colMovable flag on each individual colDefs
  18622. * if their individual enableColumnMoving configuration is not defined. Defaults to true.
  18623. */
  18624. gridOptions.enableColumnMoving = gridOptions.enableColumnMoving !== false;
  18625. },
  18626. movableColumnBuilder: function (colDef, col, gridOptions) {
  18627. var promises = [];
  18628. /**
  18629. * @ngdoc object
  18630. * @name ui.grid.moveColumns.api:ColumnDef
  18631. *
  18632. * @description Column Definition for move column feature, these are available to be
  18633. * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs}
  18634. */
  18635. /**
  18636. * @ngdoc object
  18637. * @name enableColumnMoving
  18638. * @propertyOf ui.grid.moveColumns.api:ColumnDef
  18639. * @description Enable column moving for the column.
  18640. */
  18641. colDef.enableColumnMoving = colDef.enableColumnMoving === undefined ? gridOptions.enableColumnMoving
  18642. : colDef.enableColumnMoving;
  18643. return $q.all(promises);
  18644. },
  18645. /**
  18646. * @ngdoc method
  18647. * @name updateColumnCache
  18648. * @methodOf ui.grid.moveColumns
  18649. * @description Cache the current order of columns, so we can restore them after new columnDefs are defined
  18650. */
  18651. updateColumnCache: function(grid){
  18652. grid.moveColumns.orderCache = grid.getOnlyDataColumns();
  18653. },
  18654. /**
  18655. * @ngdoc method
  18656. * @name verifyColumnOrder
  18657. * @methodOf ui.grid.moveColumns
  18658. * @description dataChangeCallback which uses the cached column order to restore the column order
  18659. * when it is reset by altering the columnDefs array.
  18660. */
  18661. verifyColumnOrder: function(grid){
  18662. var headerRowOffset = grid.rowHeaderColumns.length;
  18663. var newIndex;
  18664. angular.forEach(grid.moveColumns.orderCache, function(cacheCol, cacheIndex){
  18665. newIndex = grid.columns.indexOf(cacheCol);
  18666. if ( newIndex !== -1 && newIndex - headerRowOffset !== cacheIndex ){
  18667. var column = grid.columns.splice(newIndex, 1)[0];
  18668. grid.columns.splice(cacheIndex + headerRowOffset, 0, column);
  18669. }
  18670. });
  18671. },
  18672. redrawColumnAtPosition: function (grid, originalPosition, newPosition) {
  18673. if (originalPosition === newPosition) {
  18674. return;
  18675. }
  18676. var columns = grid.columns;
  18677. var originalColumn = columns[originalPosition];
  18678. if (originalColumn.colDef.enableColumnMoving) {
  18679. if (originalPosition > newPosition) {
  18680. for (var i1 = originalPosition; i1 > newPosition; i1--) {
  18681. columns[i1] = columns[i1 - 1];
  18682. }
  18683. }
  18684. else if (newPosition > originalPosition) {
  18685. for (var i2 = originalPosition; i2 < newPosition; i2++) {
  18686. columns[i2] = columns[i2 + 1];
  18687. }
  18688. }
  18689. columns[newPosition] = originalColumn;
  18690. service.updateColumnCache(grid);
  18691. grid.queueGridRefresh();
  18692. $timeout(function () {
  18693. grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
  18694. grid.api.colMovable.raise.columnPositionChanged(originalColumn.colDef, originalPosition, newPosition);
  18695. });
  18696. }
  18697. }
  18698. };
  18699. return service;
  18700. }]);
  18701. /**
  18702. * @ngdoc directive
  18703. * @name ui.grid.moveColumns.directive:uiGridMoveColumns
  18704. * @element div
  18705. * @restrict A
  18706. * @description Adds column moving features to the ui-grid directive.
  18707. * @example
  18708. <example module="app">
  18709. <file name="app.js">
  18710. var app = angular.module('app', ['ui.grid', 'ui.grid.moveColumns']);
  18711. app.controller('MainCtrl', ['$scope', function ($scope) {
  18712. $scope.data = [
  18713. { name: 'Bob', title: 'CEO', age: 45 },
  18714. { name: 'Frank', title: 'Lowly Developer', age: 25 },
  18715. { name: 'Jenny', title: 'Highly Developer', age: 35 }
  18716. ];
  18717. $scope.columnDefs = [
  18718. {name: 'name'},
  18719. {name: 'title'},
  18720. {name: 'age'}
  18721. ];
  18722. }]);
  18723. </file>
  18724. <file name="main.css">
  18725. .grid {
  18726. width: 100%;
  18727. height: 150px;
  18728. }
  18729. </file>
  18730. <file name="index.html">
  18731. <div ng-controller="MainCtrl">
  18732. <div class="grid" ui-grid="{ data: data, columnDefs: columnDefs }" ui-grid-move-columns></div>
  18733. </div>
  18734. </file>
  18735. </example>
  18736. */
  18737. module.directive('uiGridMoveColumns', ['uiGridMoveColumnService', function (uiGridMoveColumnService) {
  18738. return {
  18739. replace: true,
  18740. priority: 0,
  18741. require: '^uiGrid',
  18742. scope: false,
  18743. compile: function () {
  18744. return {
  18745. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  18746. uiGridMoveColumnService.initializeGrid(uiGridCtrl.grid);
  18747. },
  18748. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  18749. }
  18750. };
  18751. }
  18752. };
  18753. }]);
  18754. /**
  18755. * @ngdoc directive
  18756. * @name ui.grid.moveColumns.directive:uiGridHeaderCell
  18757. * @element div
  18758. * @restrict A
  18759. *
  18760. * @description Stacks on top of ui.grid.uiGridHeaderCell to provide capability to be able to move it to reposition column.
  18761. *
  18762. * On receiving mouseDown event headerCell is cloned, now as the mouse moves the cloned header cell also moved in the grid.
  18763. * In case the moving cloned header cell reaches the left or right extreme of grid, grid scrolling is triggered (if horizontal scroll exists).
  18764. * On mouseUp event column is repositioned at position where mouse is released and cloned header cell is removed.
  18765. *
  18766. * Events that invoke cloning of header cell:
  18767. * - mousedown
  18768. *
  18769. * Events that invoke movement of cloned header cell:
  18770. * - mousemove
  18771. *
  18772. * Events that invoke repositioning of column:
  18773. * - mouseup
  18774. */
  18775. module.directive('uiGridHeaderCell', ['$q', 'gridUtil', 'uiGridMoveColumnService', '$document', '$log', 'uiGridConstants', 'ScrollEvent',
  18776. function ($q, gridUtil, uiGridMoveColumnService, $document, $log, uiGridConstants, ScrollEvent) {
  18777. return {
  18778. priority: -10,
  18779. require: '^uiGrid',
  18780. compile: function () {
  18781. return {
  18782. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  18783. if ($scope.col.colDef.enableColumnMoving) {
  18784. /*
  18785. * Our general approach to column move is that we listen to a touchstart or mousedown
  18786. * event over the column header. When we hear one, then we wait for a move of the same type
  18787. * - if we are a touchstart then we listen for a touchmove, if we are a mousedown we listen for
  18788. * a mousemove (i.e. a drag) before we decide that there's a move underway. If there's never a move,
  18789. * and we instead get a mouseup or a touchend, then we just drop out again and do nothing.
  18790. *
  18791. */
  18792. var $contentsElm = angular.element( $elm[0].querySelectorAll('.ui-grid-cell-contents') );
  18793. var gridLeft;
  18794. var previousMouseX;
  18795. var totalMouseMovement;
  18796. var rightMoveLimit;
  18797. var elmCloned = false;
  18798. var movingElm;
  18799. var reducedWidth;
  18800. var moveOccurred = false;
  18801. var downFn = function( event ){
  18802. //Setting some variables required for calculations.
  18803. gridLeft = $scope.grid.element[0].getBoundingClientRect().left;
  18804. if ( $scope.grid.hasLeftContainer() ){
  18805. gridLeft += $scope.grid.renderContainers.left.header[0].getBoundingClientRect().width;
  18806. }
  18807. previousMouseX = event.pageX;
  18808. totalMouseMovement = 0;
  18809. rightMoveLimit = gridLeft + $scope.grid.getViewportWidth();
  18810. if ( event.type === 'mousedown' ){
  18811. $document.on('mousemove', moveFn);
  18812. $document.on('mouseup', upFn);
  18813. } else if ( event.type === 'touchstart' ){
  18814. $document.on('touchmove', moveFn);
  18815. $document.on('touchend', upFn);
  18816. }
  18817. };
  18818. var moveFn = function( event ) {
  18819. var changeValue = event.pageX - previousMouseX;
  18820. if ( changeValue === 0 ){ return; }
  18821. //Disable text selection in Chrome during column move
  18822. document.onselectstart = function() { return false; };
  18823. moveOccurred = true;
  18824. if (!elmCloned) {
  18825. cloneElement();
  18826. }
  18827. else if (elmCloned) {
  18828. moveElement(changeValue);
  18829. previousMouseX = event.pageX;
  18830. }
  18831. };
  18832. var upFn = function( event ){
  18833. //Re-enable text selection after column move
  18834. document.onselectstart = null;
  18835. //Remove the cloned element on mouse up.
  18836. if (movingElm) {
  18837. movingElm.remove();
  18838. elmCloned = false;
  18839. }
  18840. offAllEvents();
  18841. onDownEvents();
  18842. if (!moveOccurred){
  18843. return;
  18844. }
  18845. var columns = $scope.grid.columns;
  18846. var columnIndex = 0;
  18847. for (var i = 0; i < columns.length; i++) {
  18848. if (columns[i].colDef.name !== $scope.col.colDef.name) {
  18849. columnIndex++;
  18850. }
  18851. else {
  18852. break;
  18853. }
  18854. }
  18855. var targetIndex;
  18856. //Case where column should be moved to a position on its left
  18857. if (totalMouseMovement < 0) {
  18858. var totalColumnsLeftWidth = 0;
  18859. var il;
  18860. if ( $scope.grid.isRTL() ){
  18861. for (il = columnIndex + 1; il < columns.length; il++) {
  18862. if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) {
  18863. totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width;
  18864. if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) {
  18865. uiGridMoveColumnService.redrawColumnAtPosition
  18866. ($scope.grid, columnIndex, il - 1);
  18867. break;
  18868. }
  18869. }
  18870. }
  18871. }
  18872. else {
  18873. for (il = columnIndex - 1; il >= 0; il--) {
  18874. if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) {
  18875. totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width;
  18876. if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) {
  18877. uiGridMoveColumnService.redrawColumnAtPosition
  18878. ($scope.grid, columnIndex, il + 1);
  18879. break;
  18880. }
  18881. }
  18882. }
  18883. }
  18884. //Case where column should be moved to beginning (or end in RTL) of the grid.
  18885. if (totalColumnsLeftWidth < Math.abs(totalMouseMovement)) {
  18886. targetIndex = 0;
  18887. if ( $scope.grid.isRTL() ){
  18888. targetIndex = columns.length - 1;
  18889. }
  18890. uiGridMoveColumnService.redrawColumnAtPosition
  18891. ($scope.grid, columnIndex, targetIndex);
  18892. }
  18893. }
  18894. //Case where column should be moved to a position on its right
  18895. else if (totalMouseMovement > 0) {
  18896. var totalColumnsRightWidth = 0;
  18897. var ir;
  18898. if ( $scope.grid.isRTL() ){
  18899. for (ir = columnIndex - 1; ir > 0; ir--) {
  18900. if (angular.isUndefined(columns[ir].colDef.visible) || columns[ir].colDef.visible === true) {
  18901. totalColumnsRightWidth += columns[ir].drawnWidth || columns[ir].width || columns[ir].colDef.width;
  18902. if (totalColumnsRightWidth > totalMouseMovement) {
  18903. uiGridMoveColumnService.redrawColumnAtPosition
  18904. ($scope.grid, columnIndex, ir);
  18905. break;
  18906. }
  18907. }
  18908. }
  18909. }
  18910. else {
  18911. for (ir = columnIndex + 1; ir < columns.length; ir++) {
  18912. if (angular.isUndefined(columns[ir].colDef.visible) || columns[ir].colDef.visible === true) {
  18913. totalColumnsRightWidth += columns[ir].drawnWidth || columns[ir].width || columns[ir].colDef.width;
  18914. if (totalColumnsRightWidth > totalMouseMovement) {
  18915. uiGridMoveColumnService.redrawColumnAtPosition
  18916. ($scope.grid, columnIndex, ir - 1);
  18917. break;
  18918. }
  18919. }
  18920. }
  18921. }
  18922. //Case where column should be moved to end (or beginning in RTL) of the grid.
  18923. if (totalColumnsRightWidth < totalMouseMovement) {
  18924. targetIndex = columns.length - 1;
  18925. if ( $scope.grid.isRTL() ){
  18926. targetIndex = 0;
  18927. }
  18928. uiGridMoveColumnService.redrawColumnAtPosition
  18929. ($scope.grid, columnIndex, targetIndex);
  18930. }
  18931. }
  18932. };
  18933. var onDownEvents = function(){
  18934. $contentsElm.on('touchstart', downFn);
  18935. $contentsElm.on('mousedown', downFn);
  18936. };
  18937. var offAllEvents = function() {
  18938. $contentsElm.off('touchstart', downFn);
  18939. $contentsElm.off('mousedown', downFn);
  18940. $document.off('mousemove', moveFn);
  18941. $document.off('touchmove', moveFn);
  18942. $document.off('mouseup', upFn);
  18943. $document.off('touchend', upFn);
  18944. };
  18945. onDownEvents();
  18946. var cloneElement = function () {
  18947. elmCloned = true;
  18948. //Cloning header cell and appending to current header cell.
  18949. movingElm = $elm.clone();
  18950. $elm.parent().append(movingElm);
  18951. //Left of cloned element should be aligned to original header cell.
  18952. movingElm.addClass('movingColumn');
  18953. var movingElementStyles = {};
  18954. movingElementStyles.left = $elm[0].offsetLeft + 'px';
  18955. var gridRight = $scope.grid.element[0].getBoundingClientRect().right;
  18956. var elmRight = $elm[0].getBoundingClientRect().right;
  18957. if (elmRight > gridRight) {
  18958. reducedWidth = $scope.col.drawnWidth + (gridRight - elmRight);
  18959. movingElementStyles.width = reducedWidth + 'px';
  18960. }
  18961. movingElm.css(movingElementStyles);
  18962. };
  18963. var moveElement = function (changeValue) {
  18964. //Calculate total column width
  18965. var columns = $scope.grid.columns;
  18966. var totalColumnWidth = 0;
  18967. for (var i = 0; i < columns.length; i++) {
  18968. if (angular.isUndefined(columns[i].colDef.visible) || columns[i].colDef.visible === true) {
  18969. totalColumnWidth += columns[i].drawnWidth || columns[i].width || columns[i].colDef.width;
  18970. }
  18971. }
  18972. //Calculate new position of left of column
  18973. var currentElmLeft = movingElm[0].getBoundingClientRect().left - 1;
  18974. var currentElmRight = movingElm[0].getBoundingClientRect().right;
  18975. var newElementLeft;
  18976. newElementLeft = currentElmLeft - gridLeft + changeValue;
  18977. newElementLeft = newElementLeft < rightMoveLimit ? newElementLeft : rightMoveLimit;
  18978. //Update css of moving column to adjust to new left value or fire scroll in case column has reached edge of grid
  18979. if ((currentElmLeft >= gridLeft || changeValue > 0) && (currentElmRight <= rightMoveLimit || changeValue < 0)) {
  18980. movingElm.css({visibility: 'visible', 'left': (movingElm[0].offsetLeft +
  18981. (newElementLeft < rightMoveLimit ? changeValue : (rightMoveLimit - currentElmLeft))) + 'px'});
  18982. }
  18983. else if (totalColumnWidth > Math.ceil(uiGridCtrl.grid.gridWidth)) {
  18984. changeValue *= 8;
  18985. var scrollEvent = new ScrollEvent($scope.col.grid, null, null, 'uiGridHeaderCell.moveElement');
  18986. scrollEvent.x = {pixels: changeValue};
  18987. scrollEvent.grid.scrollContainers('',scrollEvent);
  18988. }
  18989. //Calculate total width of columns on the left of the moving column and the mouse movement
  18990. var totalColumnsLeftWidth = 0;
  18991. for (var il = 0; il < columns.length; il++) {
  18992. if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) {
  18993. if (columns[il].colDef.name !== $scope.col.colDef.name) {
  18994. totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width;
  18995. }
  18996. else {
  18997. break;
  18998. }
  18999. }
  19000. }
  19001. if ($scope.newScrollLeft === undefined) {
  19002. totalMouseMovement += changeValue;
  19003. }
  19004. else {
  19005. totalMouseMovement = $scope.newScrollLeft + newElementLeft - totalColumnsLeftWidth;
  19006. }
  19007. //Increase width of moving column, in case the rightmost column was moved and its width was
  19008. //decreased because of overflow
  19009. if (reducedWidth < $scope.col.drawnWidth) {
  19010. reducedWidth += Math.abs(changeValue);
  19011. movingElm.css({'width': reducedWidth + 'px'});
  19012. }
  19013. };
  19014. }
  19015. }
  19016. };
  19017. }
  19018. };
  19019. }]);
  19020. })();
  19021. (function() {
  19022. 'use strict';
  19023. /**
  19024. * @ngdoc overview
  19025. * @name ui.grid.pagination
  19026. *
  19027. * @description
  19028. *
  19029. * # ui.grid.pagination
  19030. *
  19031. * <div class="alert alert-warning" role="alert"><strong>Alpha</strong> This feature is in development. There will almost certainly be breaking api changes, or there are major outstanding bugs.</div>
  19032. *
  19033. * This module provides pagination support to ui-grid
  19034. */
  19035. var module = angular.module('ui.grid.pagination', ['ng', 'ui.grid']);
  19036. /**
  19037. * @ngdoc service
  19038. * @name ui.grid.pagination.service:uiGridPaginationService
  19039. *
  19040. * @description Service for the pagination feature
  19041. */
  19042. module.service('uiGridPaginationService', ['gridUtil',
  19043. function (gridUtil) {
  19044. var service = {
  19045. /**
  19046. * @ngdoc method
  19047. * @name initializeGrid
  19048. * @methodOf ui.grid.pagination.service:uiGridPaginationService
  19049. * @description Attaches the service to a certain grid
  19050. * @param {Grid} grid The grid we want to work with
  19051. */
  19052. initializeGrid: function (grid) {
  19053. service.defaultGridOptions(grid.options);
  19054. /**
  19055. * @ngdoc object
  19056. * @name ui.grid.pagination.api:PublicAPI
  19057. *
  19058. * @description Public API for the pagination feature
  19059. */
  19060. var publicApi = {
  19061. events: {
  19062. pagination: {
  19063. /**
  19064. * @ngdoc event
  19065. * @name paginationChanged
  19066. * @eventOf ui.grid.pagination.api:PublicAPI
  19067. * @description This event fires when the pageSize or currentPage changes
  19068. * @param {int} currentPage requested page number
  19069. * @param {int} pageSize requested page size
  19070. */
  19071. paginationChanged: function (currentPage, pageSize) { }
  19072. }
  19073. },
  19074. methods: {
  19075. pagination: {
  19076. /**
  19077. * @ngdoc method
  19078. * @name getPage
  19079. * @methodOf ui.grid.pagination.api:PublicAPI
  19080. * @description Returns the number of the current page
  19081. */
  19082. getPage: function () {
  19083. return grid.options.enablePagination ? grid.options.paginationCurrentPage : null;
  19084. },
  19085. /**
  19086. * @ngdoc method
  19087. * @name getTotalPages
  19088. * @methodOf ui.grid.pagination.api:PublicAPI
  19089. * @description Returns the total number of pages
  19090. */
  19091. getTotalPages: function () {
  19092. if (!grid.options.enablePagination) {
  19093. return null;
  19094. }
  19095. return (grid.options.totalItems === 0) ? 1 : Math.ceil(grid.options.totalItems / grid.options.paginationPageSize);
  19096. },
  19097. /**
  19098. * @ngdoc method
  19099. * @name nextPage
  19100. * @methodOf ui.grid.pagination.api:PublicAPI
  19101. * @description Moves to the next page, if possible
  19102. */
  19103. nextPage: function () {
  19104. if (!grid.options.enablePagination) {
  19105. return;
  19106. }
  19107. if (grid.options.totalItems > 0) {
  19108. grid.options.paginationCurrentPage = Math.min(
  19109. grid.options.paginationCurrentPage + 1,
  19110. publicApi.methods.pagination.getTotalPages()
  19111. );
  19112. } else {
  19113. grid.options.paginationCurrentPage++;
  19114. }
  19115. },
  19116. /**
  19117. * @ngdoc method
  19118. * @name previousPage
  19119. * @methodOf ui.grid.pagination.api:PublicAPI
  19120. * @description Moves to the previous page, if we're not on the first page
  19121. */
  19122. previousPage: function () {
  19123. if (!grid.options.enablePagination) {
  19124. return;
  19125. }
  19126. grid.options.paginationCurrentPage = Math.max(grid.options.paginationCurrentPage - 1, 1);
  19127. },
  19128. /**
  19129. * @ngdoc method
  19130. * @name seek
  19131. * @methodOf ui.grid.pagination.api:PublicAPI
  19132. * @description Moves to the requested page
  19133. * @param {int} page The number of the page that should be displayed
  19134. */
  19135. seek: function (page) {
  19136. if (!grid.options.enablePagination) {
  19137. return;
  19138. }
  19139. if (!angular.isNumber(page) || page < 1) {
  19140. throw 'Invalid page number: ' + page;
  19141. }
  19142. grid.options.paginationCurrentPage = Math.min(page, publicApi.methods.pagination.getTotalPages());
  19143. }
  19144. }
  19145. }
  19146. };
  19147. grid.api.registerEventsFromObject(publicApi.events);
  19148. grid.api.registerMethodsFromObject(publicApi.methods);
  19149. var processPagination = function( renderableRows ){
  19150. if (grid.options.useExternalPagination || !grid.options.enablePagination) {
  19151. return renderableRows;
  19152. }
  19153. //client side pagination
  19154. var pageSize = parseInt(grid.options.paginationPageSize, 10);
  19155. var currentPage = parseInt(grid.options.paginationCurrentPage, 10);
  19156. var visibleRows = renderableRows.filter(function (row) { return row.visible; });
  19157. grid.options.totalItems = visibleRows.length;
  19158. var firstRow = (currentPage - 1) * pageSize;
  19159. if (firstRow > visibleRows.length) {
  19160. currentPage = grid.options.paginationCurrentPage = 1;
  19161. firstRow = (currentPage - 1) * pageSize;
  19162. }
  19163. return visibleRows.slice(firstRow, firstRow + pageSize);
  19164. };
  19165. grid.registerRowsProcessor(processPagination, 900 );
  19166. },
  19167. defaultGridOptions: function (gridOptions) {
  19168. /**
  19169. * @ngdoc object
  19170. * @name ui.grid.pagination.api:GridOptions
  19171. *
  19172. * @description GridOptions for the pagination feature, these are available to be
  19173. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  19174. */
  19175. /**
  19176. * @ngdoc property
  19177. * @name enablePagination
  19178. * @propertyOf ui.grid.pagination.api:GridOptions
  19179. * @description Enables pagination. Defaults to true.
  19180. */
  19181. gridOptions.enablePagination = gridOptions.enablePagination !== false;
  19182. /**
  19183. * @ngdoc property
  19184. * @name enablePaginationControls
  19185. * @propertyOf ui.grid.pagination.api:GridOptions
  19186. * @description Enables the paginator at the bottom of the grid. Turn this off if you want to implement your
  19187. * own controls outside the grid.
  19188. */
  19189. gridOptions.enablePaginationControls = gridOptions.enablePaginationControls !== false;
  19190. /**
  19191. * @ngdoc property
  19192. * @name useExternalPagination
  19193. * @propertyOf ui.grid.pagination.api:GridOptions
  19194. * @description Disables client side pagination. When true, handle the paginationChanged event and set data
  19195. * and totalItems. Defaults to `false`
  19196. */
  19197. gridOptions.useExternalPagination = gridOptions.useExternalPagination === true;
  19198. /**
  19199. * @ngdoc property
  19200. * @name totalItems
  19201. * @propertyOf ui.grid.pagination.api:GridOptions
  19202. * @description Total number of items, set automatically when using client side pagination, but needs set by user
  19203. * for server side pagination
  19204. */
  19205. if (gridUtil.isNullOrUndefined(gridOptions.totalItems)) {
  19206. gridOptions.totalItems = 0;
  19207. }
  19208. /**
  19209. * @ngdoc property
  19210. * @name paginationPageSizes
  19211. * @propertyOf ui.grid.pagination.api:GridOptions
  19212. * @description Array of page sizes, defaults to `[250, 500, 1000]`
  19213. */
  19214. if (gridUtil.isNullOrUndefined(gridOptions.paginationPageSizes)) {
  19215. gridOptions.paginationPageSizes = [250, 500, 1000];
  19216. }
  19217. /**
  19218. * @ngdoc property
  19219. * @name paginationPageSize
  19220. * @propertyOf ui.grid.pagination.api:GridOptions
  19221. * @description Page size, defaults to the first item in paginationPageSizes, or 0 if paginationPageSizes is empty
  19222. */
  19223. if (gridUtil.isNullOrUndefined(gridOptions.paginationPageSize)) {
  19224. if (gridOptions.paginationPageSizes.length > 0) {
  19225. gridOptions.paginationPageSize = gridOptions.paginationPageSizes[0];
  19226. } else {
  19227. gridOptions.paginationPageSize = 0;
  19228. }
  19229. }
  19230. /**
  19231. * @ngdoc property
  19232. * @name paginationCurrentPage
  19233. * @propertyOf ui.grid.pagination.api:GridOptions
  19234. * @description Current page number, defaults to 1
  19235. */
  19236. if (gridUtil.isNullOrUndefined(gridOptions.paginationCurrentPage)) {
  19237. gridOptions.paginationCurrentPage = 1;
  19238. }
  19239. /**
  19240. * @ngdoc property
  19241. * @name paginationTemplate
  19242. * @propertyOf ui.grid.pagination.api:GridOptions
  19243. * @description A custom template for the pager, defaults to `ui-grid/pagination`
  19244. */
  19245. if (gridUtil.isNullOrUndefined(gridOptions.paginationTemplate)) {
  19246. gridOptions.paginationTemplate = 'ui-grid/pagination';
  19247. }
  19248. },
  19249. /**
  19250. * @ngdoc method
  19251. * @methodOf ui.grid.pagination.service:uiGridPaginationService
  19252. * @name uiGridPaginationService
  19253. * @description Raises paginationChanged and calls refresh for client side pagination
  19254. * @param {Grid} grid the grid for which the pagination changed
  19255. * @param {int} currentPage requested page number
  19256. * @param {int} pageSize requested page size
  19257. */
  19258. onPaginationChanged: function (grid, currentPage, pageSize) {
  19259. grid.api.pagination.raise.paginationChanged(currentPage, pageSize);
  19260. if (!grid.options.useExternalPagination) {
  19261. grid.queueGridRefresh(); //client side pagination
  19262. }
  19263. }
  19264. };
  19265. return service;
  19266. }
  19267. ]);
  19268. /**
  19269. * @ngdoc directive
  19270. * @name ui.grid.pagination.directive:uiGridPagination
  19271. * @element div
  19272. * @restrict A
  19273. *
  19274. * @description Adds pagination features to grid
  19275. * @example
  19276. <example module="app">
  19277. <file name="app.js">
  19278. var app = angular.module('app', ['ui.grid', 'ui.grid.pagination']);
  19279. app.controller('MainCtrl', ['$scope', function ($scope) {
  19280. $scope.data = [
  19281. { name: 'Alex', car: 'Toyota' },
  19282. { name: 'Sam', car: 'Lexus' },
  19283. { name: 'Joe', car: 'Dodge' },
  19284. { name: 'Bob', car: 'Buick' },
  19285. { name: 'Cindy', car: 'Ford' },
  19286. { name: 'Brian', car: 'Audi' },
  19287. { name: 'Malcom', car: 'Mercedes Benz' },
  19288. { name: 'Dave', car: 'Ford' },
  19289. { name: 'Stacey', car: 'Audi' },
  19290. { name: 'Amy', car: 'Acura' },
  19291. { name: 'Scott', car: 'Toyota' },
  19292. { name: 'Ryan', car: 'BMW' },
  19293. ];
  19294. $scope.gridOptions = {
  19295. data: 'data',
  19296. paginationPageSizes: [5, 10, 25],
  19297. paginationPageSize: 5,
  19298. columnDefs: [
  19299. {name: 'name'},
  19300. {name: 'car'}
  19301. ]
  19302. }
  19303. }]);
  19304. </file>
  19305. <file name="index.html">
  19306. <div ng-controller="MainCtrl">
  19307. <div ui-grid="gridOptions" ui-grid-pagination></div>
  19308. </div>
  19309. </file>
  19310. </example>
  19311. */
  19312. module.directive('uiGridPagination', ['gridUtil', 'uiGridPaginationService',
  19313. function (gridUtil, uiGridPaginationService) {
  19314. return {
  19315. priority: -200,
  19316. scope: false,
  19317. require: 'uiGrid',
  19318. link: {
  19319. pre: function ($scope, $elm, $attr, uiGridCtrl) {
  19320. uiGridPaginationService.initializeGrid(uiGridCtrl.grid);
  19321. gridUtil.getTemplate(uiGridCtrl.grid.options.paginationTemplate)
  19322. .then(function (contents) {
  19323. var template = angular.element(contents);
  19324. $elm.append(template);
  19325. uiGridCtrl.innerCompile(template);
  19326. });
  19327. }
  19328. }
  19329. };
  19330. }
  19331. ]);
  19332. /**
  19333. * @ngdoc directive
  19334. * @name ui.grid.pagination.directive:uiGridPager
  19335. * @element div
  19336. *
  19337. * @description Panel for handling pagination
  19338. */
  19339. module.directive('uiGridPager', ['uiGridPaginationService', 'uiGridConstants', 'gridUtil', 'i18nService',
  19340. function (uiGridPaginationService, uiGridConstants, gridUtil, i18nService) {
  19341. return {
  19342. priority: -200,
  19343. scope: true,
  19344. require: '^uiGrid',
  19345. link: function ($scope, $elm, $attr, uiGridCtrl) {
  19346. var defaultFocusElementSelector = '.ui-grid-pager-control-input';
  19347. $scope.aria = i18nService.getSafeText('pagination.aria'); //Returns an object with all of the aria labels
  19348. $scope.paginationApi = uiGridCtrl.grid.api.pagination;
  19349. $scope.sizesLabel = i18nService.getSafeText('pagination.sizes');
  19350. $scope.totalItemsLabel = i18nService.getSafeText('pagination.totalItems');
  19351. $scope.paginationOf = i18nService.getSafeText('pagination.of');
  19352. $scope.paginationThrough = i18nService.getSafeText('pagination.through');
  19353. var options = uiGridCtrl.grid.options;
  19354. uiGridCtrl.grid.renderContainers.body.registerViewportAdjuster(function (adjustment) {
  19355. adjustment.height = adjustment.height - gridUtil.elementHeight($elm, "padding");
  19356. return adjustment;
  19357. });
  19358. var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback(function (grid) {
  19359. if (!grid.options.useExternalPagination) {
  19360. grid.options.totalItems = grid.rows.length;
  19361. }
  19362. }, [uiGridConstants.dataChange.ROW]);
  19363. $scope.$on('$destroy', dataChangeDereg);
  19364. var setShowing = function () {
  19365. $scope.showingLow = ((options.paginationCurrentPage - 1) * options.paginationPageSize) + 1;
  19366. $scope.showingHigh = Math.min(options.paginationCurrentPage * options.paginationPageSize, options.totalItems);
  19367. };
  19368. var deregT = $scope.$watch('grid.options.totalItems + grid.options.paginationPageSize', setShowing);
  19369. var deregP = $scope.$watch('grid.options.paginationCurrentPage + grid.options.paginationPageSize', function (newValues, oldValues) {
  19370. if (newValues === oldValues || oldValues === undefined) {
  19371. return;
  19372. }
  19373. if (!angular.isNumber(options.paginationCurrentPage) || options.paginationCurrentPage < 1) {
  19374. options.paginationCurrentPage = 1;
  19375. return;
  19376. }
  19377. if (options.totalItems > 0 && options.paginationCurrentPage > $scope.paginationApi.getTotalPages()) {
  19378. options.paginationCurrentPage = $scope.paginationApi.getTotalPages();
  19379. return;
  19380. }
  19381. setShowing();
  19382. uiGridPaginationService.onPaginationChanged($scope.grid, options.paginationCurrentPage, options.paginationPageSize);
  19383. }
  19384. );
  19385. $scope.$on('$destroy', function() {
  19386. deregT();
  19387. deregP();
  19388. });
  19389. $scope.cantPageForward = function () {
  19390. if (options.totalItems > 0) {
  19391. return options.paginationCurrentPage >= $scope.paginationApi.getTotalPages();
  19392. } else {
  19393. return options.data.length < 1;
  19394. }
  19395. };
  19396. $scope.cantPageToLast = function () {
  19397. if (options.totalItems > 0) {
  19398. return $scope.cantPageForward();
  19399. } else {
  19400. return true;
  19401. }
  19402. };
  19403. $scope.cantPageBackward = function () {
  19404. return options.paginationCurrentPage <= 1;
  19405. };
  19406. var focusToInputIf = function(condition){
  19407. if (condition){
  19408. gridUtil.focus.bySelector($elm, defaultFocusElementSelector);
  19409. }
  19410. };
  19411. //Takes care of setting focus to the middle element when focus is lost
  19412. $scope.pageFirstPageClick = function () {
  19413. $scope.paginationApi.seek(1);
  19414. focusToInputIf($scope.cantPageBackward());
  19415. };
  19416. $scope.pagePreviousPageClick = function () {
  19417. $scope.paginationApi.previousPage();
  19418. focusToInputIf($scope.cantPageBackward());
  19419. };
  19420. $scope.pageNextPageClick = function () {
  19421. $scope.paginationApi.nextPage();
  19422. focusToInputIf($scope.cantPageForward());
  19423. };
  19424. $scope.pageLastPageClick = function () {
  19425. $scope.paginationApi.seek($scope.paginationApi.getTotalPages());
  19426. focusToInputIf($scope.cantPageToLast());
  19427. };
  19428. }
  19429. };
  19430. }
  19431. ]);
  19432. })();
  19433. (function () {
  19434. 'use strict';
  19435. /**
  19436. * @ngdoc overview
  19437. * @name ui.grid.pinning
  19438. * @description
  19439. *
  19440. * # ui.grid.pinning
  19441. *
  19442. * <div class="alert alert-success" role="alert"><strong>Stable</strong> This feature is stable. There should no longer be breaking api changes without a deprecation warning.</div>
  19443. *
  19444. * This module provides column pinning to the end user via menu options in the column header
  19445. *
  19446. * <div doc-module-components="ui.grid.pinning"></div>
  19447. */
  19448. var module = angular.module('ui.grid.pinning', ['ui.grid']);
  19449. module.constant('uiGridPinningConstants', {
  19450. container: {
  19451. LEFT: 'left',
  19452. RIGHT: 'right',
  19453. NONE: ''
  19454. }
  19455. });
  19456. module.service('uiGridPinningService', ['gridUtil', 'GridRenderContainer', 'i18nService', 'uiGridPinningConstants', function (gridUtil, GridRenderContainer, i18nService, uiGridPinningConstants) {
  19457. var service = {
  19458. initializeGrid: function (grid) {
  19459. service.defaultGridOptions(grid.options);
  19460. // Register a column builder to add new menu items for pinning left and right
  19461. grid.registerColumnBuilder(service.pinningColumnBuilder);
  19462. /**
  19463. * @ngdoc object
  19464. * @name ui.grid.pinning.api:PublicApi
  19465. *
  19466. * @description Public Api for pinning feature
  19467. */
  19468. var publicApi = {
  19469. events: {
  19470. pinning: {
  19471. /**
  19472. * @ngdoc event
  19473. * @name columnPin
  19474. * @eventOf ui.grid.pinning.api:PublicApi
  19475. * @description raised when column pin state has changed
  19476. * <pre>
  19477. * gridApi.pinning.on.columnPinned(scope, function(colDef){})
  19478. * </pre>
  19479. * @param {object} colDef the column that was changed
  19480. * @param {string} container the render container the column is in ('left', 'right', '')
  19481. */
  19482. columnPinned: function(colDef, container) {
  19483. }
  19484. }
  19485. },
  19486. methods: {
  19487. pinning: {
  19488. /**
  19489. * @ngdoc function
  19490. * @name pinColumn
  19491. * @methodOf ui.grid.pinning.api:PublicApi
  19492. * @description pin column left, right, or none
  19493. * <pre>
  19494. * gridApi.pinning.pinColumn(col, uiGridPinningConstants.container.LEFT)
  19495. * </pre>
  19496. * @param {gridColumn} col the column being pinned
  19497. * @param {string} container one of the recognised types
  19498. * from uiGridPinningConstants
  19499. */
  19500. pinColumn: function(col, container) {
  19501. service.pinColumn(grid, col, container);
  19502. }
  19503. }
  19504. }
  19505. };
  19506. grid.api.registerEventsFromObject(publicApi.events);
  19507. grid.api.registerMethodsFromObject(publicApi.methods);
  19508. },
  19509. defaultGridOptions: function (gridOptions) {
  19510. //default option to true unless it was explicitly set to false
  19511. /**
  19512. * @ngdoc object
  19513. * @name ui.grid.pinning.api:GridOptions
  19514. *
  19515. * @description GridOptions for pinning feature, these are available to be
  19516. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  19517. */
  19518. /**
  19519. * @ngdoc object
  19520. * @name enablePinning
  19521. * @propertyOf ui.grid.pinning.api:GridOptions
  19522. * @description Enable pinning for the entire grid.
  19523. * <br/>Defaults to true
  19524. */
  19525. gridOptions.enablePinning = gridOptions.enablePinning !== false;
  19526. },
  19527. pinningColumnBuilder: function (colDef, col, gridOptions) {
  19528. //default to true unless gridOptions or colDef is explicitly false
  19529. /**
  19530. * @ngdoc object
  19531. * @name ui.grid.pinning.api:ColumnDef
  19532. *
  19533. * @description ColumnDef for pinning feature, these are available to be
  19534. * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs}
  19535. */
  19536. /**
  19537. * @ngdoc object
  19538. * @name enablePinning
  19539. * @propertyOf ui.grid.pinning.api:ColumnDef
  19540. * @description Enable pinning for the individual column.
  19541. * <br/>Defaults to true
  19542. */
  19543. colDef.enablePinning = colDef.enablePinning === undefined ? gridOptions.enablePinning : colDef.enablePinning;
  19544. /**
  19545. * @ngdoc object
  19546. * @name pinnedLeft
  19547. * @propertyOf ui.grid.pinning.api:ColumnDef
  19548. * @description Column is pinned left when grid is rendered
  19549. * <br/>Defaults to false
  19550. */
  19551. /**
  19552. * @ngdoc object
  19553. * @name pinnedRight
  19554. * @propertyOf ui.grid.pinning.api:ColumnDef
  19555. * @description Column is pinned right when grid is rendered
  19556. * <br/>Defaults to false
  19557. */
  19558. if (colDef.pinnedLeft) {
  19559. col.renderContainer = 'left';
  19560. col.grid.createLeftContainer();
  19561. }
  19562. else if (colDef.pinnedRight) {
  19563. col.renderContainer = 'right';
  19564. col.grid.createRightContainer();
  19565. }
  19566. if (!colDef.enablePinning) {
  19567. return;
  19568. }
  19569. var pinColumnLeftAction = {
  19570. name: 'ui.grid.pinning.pinLeft',
  19571. title: i18nService.get().pinning.pinLeft,
  19572. icon: 'ui-grid-icon-left-open',
  19573. shown: function () {
  19574. return typeof(this.context.col.renderContainer) === 'undefined' || !this.context.col.renderContainer || this.context.col.renderContainer !== 'left';
  19575. },
  19576. action: function () {
  19577. service.pinColumn(this.context.col.grid, this.context.col, uiGridPinningConstants.container.LEFT);
  19578. }
  19579. };
  19580. var pinColumnRightAction = {
  19581. name: 'ui.grid.pinning.pinRight',
  19582. title: i18nService.get().pinning.pinRight,
  19583. icon: 'ui-grid-icon-right-open',
  19584. shown: function () {
  19585. return typeof(this.context.col.renderContainer) === 'undefined' || !this.context.col.renderContainer || this.context.col.renderContainer !== 'right';
  19586. },
  19587. action: function () {
  19588. service.pinColumn(this.context.col.grid, this.context.col, uiGridPinningConstants.container.RIGHT);
  19589. }
  19590. };
  19591. var removePinAction = {
  19592. name: 'ui.grid.pinning.unpin',
  19593. title: i18nService.get().pinning.unpin,
  19594. icon: 'ui-grid-icon-cancel',
  19595. shown: function () {
  19596. return typeof(this.context.col.renderContainer) !== 'undefined' && this.context.col.renderContainer !== null && this.context.col.renderContainer !== 'body';
  19597. },
  19598. action: function () {
  19599. service.pinColumn(this.context.col.grid, this.context.col, uiGridPinningConstants.container.NONE);
  19600. }
  19601. };
  19602. if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.pinning.pinLeft')) {
  19603. col.menuItems.push(pinColumnLeftAction);
  19604. }
  19605. if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.pinning.pinRight')) {
  19606. col.menuItems.push(pinColumnRightAction);
  19607. }
  19608. if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.pinning.unpin')) {
  19609. col.menuItems.push(removePinAction);
  19610. }
  19611. },
  19612. pinColumn: function(grid, col, container) {
  19613. if (container === uiGridPinningConstants.container.NONE) {
  19614. col.renderContainer = null;
  19615. col.colDef.pinnedLeft = col.colDef.pinnedRight = false;
  19616. }
  19617. else {
  19618. col.renderContainer = container;
  19619. if (container === uiGridPinningConstants.container.LEFT) {
  19620. grid.createLeftContainer();
  19621. }
  19622. else if (container === uiGridPinningConstants.container.RIGHT) {
  19623. grid.createRightContainer();
  19624. }
  19625. }
  19626. grid.refresh()
  19627. .then(function() {
  19628. grid.api.pinning.raise.columnPinned( col.colDef, container );
  19629. });
  19630. }
  19631. };
  19632. return service;
  19633. }]);
  19634. module.directive('uiGridPinning', ['gridUtil', 'uiGridPinningService',
  19635. function (gridUtil, uiGridPinningService) {
  19636. return {
  19637. require: 'uiGrid',
  19638. scope: false,
  19639. compile: function () {
  19640. return {
  19641. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  19642. uiGridPinningService.initializeGrid(uiGridCtrl.grid);
  19643. },
  19644. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  19645. }
  19646. };
  19647. }
  19648. };
  19649. }]);
  19650. })();
  19651. (function(){
  19652. 'use strict';
  19653. /**
  19654. * @ngdoc overview
  19655. * @name ui.grid.resizeColumns
  19656. * @description
  19657. *
  19658. * # ui.grid.resizeColumns
  19659. *
  19660. * <div class="alert alert-success" role="alert"><strong>Stable</strong> This feature is stable. There should no longer be breaking api changes without a deprecation warning.</div>
  19661. *
  19662. * This module allows columns to be resized.
  19663. */
  19664. var module = angular.module('ui.grid.resizeColumns', ['ui.grid']);
  19665. module.service('uiGridResizeColumnsService', ['gridUtil', '$q', '$timeout',
  19666. function (gridUtil, $q, $timeout) {
  19667. var service = {
  19668. defaultGridOptions: function(gridOptions){
  19669. //default option to true unless it was explicitly set to false
  19670. /**
  19671. * @ngdoc object
  19672. * @name ui.grid.resizeColumns.api:GridOptions
  19673. *
  19674. * @description GridOptions for resizeColumns feature, these are available to be
  19675. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  19676. */
  19677. /**
  19678. * @ngdoc object
  19679. * @name enableColumnResizing
  19680. * @propertyOf ui.grid.resizeColumns.api:GridOptions
  19681. * @description Enable column resizing on the entire grid
  19682. * <br/>Defaults to true
  19683. */
  19684. gridOptions.enableColumnResizing = gridOptions.enableColumnResizing !== false;
  19685. //legacy support
  19686. //use old name if it is explicitly false
  19687. if (gridOptions.enableColumnResize === false){
  19688. gridOptions.enableColumnResizing = false;
  19689. }
  19690. },
  19691. colResizerColumnBuilder: function (colDef, col, gridOptions) {
  19692. var promises = [];
  19693. /**
  19694. * @ngdoc object
  19695. * @name ui.grid.resizeColumns.api:ColumnDef
  19696. *
  19697. * @description ColumnDef for resizeColumns feature, these are available to be
  19698. * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs}
  19699. */
  19700. /**
  19701. * @ngdoc object
  19702. * @name enableColumnResizing
  19703. * @propertyOf ui.grid.resizeColumns.api:ColumnDef
  19704. * @description Enable column resizing on an individual column
  19705. * <br/>Defaults to GridOptions.enableColumnResizing
  19706. */
  19707. //default to true unless gridOptions or colDef is explicitly false
  19708. colDef.enableColumnResizing = colDef.enableColumnResizing === undefined ? gridOptions.enableColumnResizing : colDef.enableColumnResizing;
  19709. //legacy support of old option name
  19710. if (colDef.enableColumnResize === false){
  19711. colDef.enableColumnResizing = false;
  19712. }
  19713. return $q.all(promises);
  19714. },
  19715. registerPublicApi: function (grid) {
  19716. /**
  19717. * @ngdoc object
  19718. * @name ui.grid.resizeColumns.api:PublicApi
  19719. * @description Public Api for column resize feature.
  19720. */
  19721. var publicApi = {
  19722. events: {
  19723. /**
  19724. * @ngdoc event
  19725. * @name columnSizeChanged
  19726. * @eventOf ui.grid.resizeColumns.api:PublicApi
  19727. * @description raised when column is resized
  19728. * <pre>
  19729. * gridApi.colResizable.on.columnSizeChanged(scope,function(colDef, deltaChange){})
  19730. * </pre>
  19731. * @param {object} colDef the column that was resized
  19732. * @param {integer} delta of the column size change
  19733. */
  19734. colResizable: {
  19735. columnSizeChanged: function (colDef, deltaChange) {
  19736. }
  19737. }
  19738. }
  19739. };
  19740. grid.api.registerEventsFromObject(publicApi.events);
  19741. },
  19742. fireColumnSizeChanged: function (grid, colDef, deltaChange) {
  19743. $timeout(function () {
  19744. if ( grid.api.colResizable ){
  19745. grid.api.colResizable.raise.columnSizeChanged(colDef, deltaChange);
  19746. } else {
  19747. gridUtil.logError("The resizeable api is not registered, this may indicate that you've included the module but not added the 'ui-grid-resize-columns' directive to your grid definition. Cannot raise any events.");
  19748. }
  19749. });
  19750. },
  19751. // get either this column, or the column next to this column, to resize,
  19752. // returns the column we're going to resize
  19753. findTargetCol: function(col, position, rtlMultiplier){
  19754. var renderContainer = col.getRenderContainer();
  19755. if (position === 'left') {
  19756. // Get the column to the left of this one
  19757. var colIndex = renderContainer.visibleColumnCache.indexOf(col);
  19758. return renderContainer.visibleColumnCache[colIndex - 1 * rtlMultiplier];
  19759. } else {
  19760. return col;
  19761. }
  19762. }
  19763. };
  19764. return service;
  19765. }]);
  19766. /**
  19767. * @ngdoc directive
  19768. * @name ui.grid.resizeColumns.directive:uiGridResizeColumns
  19769. * @element div
  19770. * @restrict A
  19771. * @description
  19772. * Enables resizing for all columns on the grid. If, for some reason, you want to use the ui-grid-resize-columns directive, but not allow column resizing, you can explicitly set the
  19773. * option to false. This prevents resizing for the entire grid, regardless of individual columnDef options.
  19774. *
  19775. * @example
  19776. <doc:example module="app">
  19777. <doc:source>
  19778. <script>
  19779. var app = angular.module('app', ['ui.grid', 'ui.grid.resizeColumns']);
  19780. app.controller('MainCtrl', ['$scope', function ($scope) {
  19781. $scope.gridOpts = {
  19782. data: [
  19783. { "name": "Ethel Price", "gender": "female", "company": "Enersol" },
  19784. { "name": "Claudine Neal", "gender": "female", "company": "Sealoud" },
  19785. { "name": "Beryl Rice", "gender": "female", "company": "Velity" },
  19786. { "name": "Wilder Gonzales", "gender": "male", "company": "Geekko" }
  19787. ]
  19788. };
  19789. }]);
  19790. </script>
  19791. <div ng-controller="MainCtrl">
  19792. <div class="testGrid" ui-grid="gridOpts" ui-grid-resize-columns ></div>
  19793. </div>
  19794. </doc:source>
  19795. <doc:scenario>
  19796. </doc:scenario>
  19797. </doc:example>
  19798. */
  19799. module.directive('uiGridResizeColumns', ['gridUtil', 'uiGridResizeColumnsService', function (gridUtil, uiGridResizeColumnsService) {
  19800. return {
  19801. replace: true,
  19802. priority: 0,
  19803. require: '^uiGrid',
  19804. scope: false,
  19805. compile: function () {
  19806. return {
  19807. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  19808. uiGridResizeColumnsService.defaultGridOptions(uiGridCtrl.grid.options);
  19809. uiGridCtrl.grid.registerColumnBuilder( uiGridResizeColumnsService.colResizerColumnBuilder);
  19810. uiGridResizeColumnsService.registerPublicApi(uiGridCtrl.grid);
  19811. },
  19812. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  19813. }
  19814. };
  19815. }
  19816. };
  19817. }]);
  19818. // Extend the uiGridHeaderCell directive
  19819. module.directive('uiGridHeaderCell', ['gridUtil', '$templateCache', '$compile', '$q', 'uiGridResizeColumnsService', 'uiGridConstants', '$timeout', function (gridUtil, $templateCache, $compile, $q, uiGridResizeColumnsService, uiGridConstants, $timeout) {
  19820. return {
  19821. // Run after the original uiGridHeaderCell
  19822. priority: -10,
  19823. require: '^uiGrid',
  19824. // scope: false,
  19825. compile: function() {
  19826. return {
  19827. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  19828. var grid = uiGridCtrl.grid;
  19829. if (grid.options.enableColumnResizing) {
  19830. var columnResizerElm = $templateCache.get('ui-grid/columnResizer');
  19831. var rtlMultiplier = 1;
  19832. //when in RTL mode reverse the direction using the rtlMultiplier and change the position to left
  19833. if (grid.isRTL()) {
  19834. $scope.position = 'left';
  19835. rtlMultiplier = -1;
  19836. }
  19837. var displayResizers = function(){
  19838. // remove any existing resizers.
  19839. var resizers = $elm[0].getElementsByClassName('ui-grid-column-resizer');
  19840. for ( var i = 0; i < resizers.length; i++ ){
  19841. angular.element(resizers[i]).remove();
  19842. }
  19843. // get the target column for the left resizer
  19844. var otherCol = uiGridResizeColumnsService.findTargetCol($scope.col, 'left', rtlMultiplier);
  19845. var renderContainer = $scope.col.getRenderContainer();
  19846. // Don't append the left resizer if this is the first column or the column to the left of this one has resizing disabled
  19847. if (otherCol && renderContainer.visibleColumnCache.indexOf($scope.col) !== 0 && otherCol.colDef.enableColumnResizing !== false) {
  19848. var resizerLeft = angular.element(columnResizerElm).clone();
  19849. resizerLeft.attr('position', 'left');
  19850. $elm.prepend(resizerLeft);
  19851. $compile(resizerLeft)($scope);
  19852. }
  19853. // Don't append the right resizer if this column has resizing disabled
  19854. if ($scope.col.colDef.enableColumnResizing !== false) {
  19855. var resizerRight = angular.element(columnResizerElm).clone();
  19856. resizerRight.attr('position', 'right');
  19857. $elm.append(resizerRight);
  19858. $compile(resizerRight)($scope);
  19859. }
  19860. };
  19861. displayResizers();
  19862. var waitDisplay = function(){
  19863. $timeout(displayResizers);
  19864. };
  19865. var dataChangeDereg = grid.registerDataChangeCallback( waitDisplay, [uiGridConstants.dataChange.COLUMN] );
  19866. $scope.$on( '$destroy', dataChangeDereg );
  19867. }
  19868. }
  19869. };
  19870. }
  19871. };
  19872. }]);
  19873. /**
  19874. * @ngdoc directive
  19875. * @name ui.grid.resizeColumns.directive:uiGridColumnResizer
  19876. * @element div
  19877. * @restrict A
  19878. *
  19879. * @description
  19880. * Draggable handle that controls column resizing.
  19881. *
  19882. * @example
  19883. <doc:example module="app">
  19884. <doc:source>
  19885. <script>
  19886. var app = angular.module('app', ['ui.grid', 'ui.grid.resizeColumns']);
  19887. app.controller('MainCtrl', ['$scope', function ($scope) {
  19888. $scope.gridOpts = {
  19889. enableColumnResizing: true,
  19890. data: [
  19891. { "name": "Ethel Price", "gender": "female", "company": "Enersol" },
  19892. { "name": "Claudine Neal", "gender": "female", "company": "Sealoud" },
  19893. { "name": "Beryl Rice", "gender": "female", "company": "Velity" },
  19894. { "name": "Wilder Gonzales", "gender": "male", "company": "Geekko" }
  19895. ]
  19896. };
  19897. }]);
  19898. </script>
  19899. <div ng-controller="MainCtrl">
  19900. <div class="testGrid" ui-grid="gridOpts"></div>
  19901. </div>
  19902. </doc:source>
  19903. <doc:scenario>
  19904. // TODO: e2e specs?
  19905. // TODO: post-resize a horizontal scroll event should be fired
  19906. </doc:scenario>
  19907. </doc:example>
  19908. */
  19909. module.directive('uiGridColumnResizer', ['$document', 'gridUtil', 'uiGridConstants', 'uiGridResizeColumnsService', function ($document, gridUtil, uiGridConstants, uiGridResizeColumnsService) {
  19910. var resizeOverlay = angular.element('<div class="ui-grid-resize-overlay"></div>');
  19911. var resizer = {
  19912. priority: 0,
  19913. scope: {
  19914. col: '=',
  19915. position: '@',
  19916. renderIndex: '='
  19917. },
  19918. require: '?^uiGrid',
  19919. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  19920. var startX = 0,
  19921. x = 0,
  19922. gridLeft = 0,
  19923. rtlMultiplier = 1;
  19924. //when in RTL mode reverse the direction using the rtlMultiplier and change the position to left
  19925. if (uiGridCtrl.grid.isRTL()) {
  19926. $scope.position = 'left';
  19927. rtlMultiplier = -1;
  19928. }
  19929. if ($scope.position === 'left') {
  19930. $elm.addClass('left');
  19931. }
  19932. else if ($scope.position === 'right') {
  19933. $elm.addClass('right');
  19934. }
  19935. // Refresh the grid canvas
  19936. // takes an argument representing the diff along the X-axis that the resize had
  19937. function refreshCanvas(xDiff) {
  19938. // Then refresh the grid canvas, rebuilding the styles so that the scrollbar updates its size
  19939. uiGridCtrl.grid.refreshCanvas(true).then( function() {
  19940. uiGridCtrl.grid.queueGridRefresh();
  19941. });
  19942. }
  19943. // Check that the requested width isn't wider than the maxWidth, or narrower than the minWidth
  19944. // Returns the new recommended with, after constraints applied
  19945. function constrainWidth(col, width){
  19946. var newWidth = width;
  19947. // If the new width would be less than the column's allowably minimum width, don't allow it
  19948. if (col.minWidth && newWidth < col.minWidth) {
  19949. newWidth = col.minWidth;
  19950. }
  19951. else if (col.maxWidth && newWidth > col.maxWidth) {
  19952. newWidth = col.maxWidth;
  19953. }
  19954. return newWidth;
  19955. }
  19956. /*
  19957. * Our approach to event handling aims to deal with both touch devices and mouse devices
  19958. * We register down handlers on both touch and mouse. When a touchstart or mousedown event
  19959. * occurs, we register the corresponding touchmove/touchend, or mousemove/mouseend events.
  19960. *
  19961. * This way we can listen for both without worrying about the fact many touch devices also emulate
  19962. * mouse events - basically whichever one we hear first is what we'll go with.
  19963. */
  19964. function moveFunction(event, args) {
  19965. if (event.originalEvent) { event = event.originalEvent; }
  19966. event.preventDefault();
  19967. x = (event.targetTouches ? event.targetTouches[0] : event).clientX - gridLeft;
  19968. if (x < 0) { x = 0; }
  19969. else if (x > uiGridCtrl.grid.gridWidth) { x = uiGridCtrl.grid.gridWidth; }
  19970. var col = uiGridResizeColumnsService.findTargetCol($scope.col, $scope.position, rtlMultiplier);
  19971. // Don't resize if it's disabled on this column
  19972. if (col.colDef.enableColumnResizing === false) {
  19973. return;
  19974. }
  19975. if (!uiGridCtrl.grid.element.hasClass('column-resizing')) {
  19976. uiGridCtrl.grid.element.addClass('column-resizing');
  19977. }
  19978. // Get the diff along the X axis
  19979. var xDiff = x - startX;
  19980. // Get the width that this mouse would give the column
  19981. var newWidth = parseInt(col.drawnWidth + xDiff * rtlMultiplier, 10);
  19982. // check we're not outside the allowable bounds for this column
  19983. x = x + ( constrainWidth(col, newWidth) - newWidth ) * rtlMultiplier;
  19984. resizeOverlay.css({ left: x + 'px' });
  19985. uiGridCtrl.fireEvent(uiGridConstants.events.ITEM_DRAGGING);
  19986. }
  19987. function upFunction(event, args) {
  19988. if (event.originalEvent) { event = event.originalEvent; }
  19989. event.preventDefault();
  19990. uiGridCtrl.grid.element.removeClass('column-resizing');
  19991. resizeOverlay.remove();
  19992. // Resize the column
  19993. x = (event.changedTouches ? event.changedTouches[0] : event).clientX - gridLeft;
  19994. var xDiff = x - startX;
  19995. if (xDiff === 0) {
  19996. // no movement, so just reset event handlers, including turning back on both
  19997. // down events - we turned one off when this event started
  19998. offAllEvents();
  19999. onDownEvents();
  20000. return;
  20001. }
  20002. var col = uiGridResizeColumnsService.findTargetCol($scope.col, $scope.position, rtlMultiplier);
  20003. // Don't resize if it's disabled on this column
  20004. if (col.colDef.enableColumnResizing === false) {
  20005. return;
  20006. }
  20007. // Get the new width
  20008. var newWidth = parseInt(col.drawnWidth + xDiff * rtlMultiplier, 10);
  20009. // check we're not outside the allowable bounds for this column
  20010. col.width = constrainWidth(col, newWidth);
  20011. col.hasCustomWidth = true;
  20012. refreshCanvas(xDiff);
  20013. uiGridResizeColumnsService.fireColumnSizeChanged(uiGridCtrl.grid, col.colDef, xDiff);
  20014. // stop listening of up and move events - wait for next down
  20015. // reset the down events - we will have turned one off when this event started
  20016. offAllEvents();
  20017. onDownEvents();
  20018. }
  20019. var downFunction = function(event, args) {
  20020. if (event.originalEvent) { event = event.originalEvent; }
  20021. event.stopPropagation();
  20022. // Get the left offset of the grid
  20023. // gridLeft = uiGridCtrl.grid.element[0].offsetLeft;
  20024. gridLeft = uiGridCtrl.grid.element[0].getBoundingClientRect().left;
  20025. // Get the starting X position, which is the X coordinate of the click minus the grid's offset
  20026. startX = (event.targetTouches ? event.targetTouches[0] : event).clientX - gridLeft;
  20027. // Append the resizer overlay
  20028. uiGridCtrl.grid.element.append(resizeOverlay);
  20029. // Place the resizer overlay at the start position
  20030. resizeOverlay.css({ left: startX });
  20031. // Add handlers for move and up events - if we were mousedown then we listen for mousemove and mouseup, if
  20032. // we were touchdown then we listen for touchmove and touchup. Also remove the handler for the equivalent
  20033. // down event - so if we're touchdown, then remove the mousedown handler until this event is over, if we're
  20034. // mousedown then remove the touchdown handler until this event is over, this avoids processing duplicate events
  20035. if ( event.type === 'touchstart' ){
  20036. $document.on('touchend', upFunction);
  20037. $document.on('touchmove', moveFunction);
  20038. $elm.off('mousedown', downFunction);
  20039. } else {
  20040. $document.on('mouseup', upFunction);
  20041. $document.on('mousemove', moveFunction);
  20042. $elm.off('touchstart', downFunction);
  20043. }
  20044. };
  20045. var onDownEvents = function() {
  20046. $elm.on('mousedown', downFunction);
  20047. $elm.on('touchstart', downFunction);
  20048. };
  20049. var offAllEvents = function() {
  20050. $document.off('mouseup', upFunction);
  20051. $document.off('touchend', upFunction);
  20052. $document.off('mousemove', moveFunction);
  20053. $document.off('touchmove', moveFunction);
  20054. $elm.off('mousedown', downFunction);
  20055. $elm.off('touchstart', downFunction);
  20056. };
  20057. onDownEvents();
  20058. // On doubleclick, resize to fit all rendered cells
  20059. var dblClickFn = function(event, args){
  20060. event.stopPropagation();
  20061. var col = uiGridResizeColumnsService.findTargetCol($scope.col, $scope.position, rtlMultiplier);
  20062. // Don't resize if it's disabled on this column
  20063. if (col.colDef.enableColumnResizing === false) {
  20064. return;
  20065. }
  20066. // Go through the rendered rows and find out the max size for the data in this column
  20067. var maxWidth = 0;
  20068. var xDiff = 0;
  20069. // Get the parent render container element
  20070. var renderContainerElm = gridUtil.closestElm($elm, '.ui-grid-render-container');
  20071. // Get the cell contents so we measure correctly. For the header cell we have to account for the sort icon and the menu buttons, if present
  20072. var cells = renderContainerElm.querySelectorAll('.' + uiGridConstants.COL_CLASS_PREFIX + col.uid + ' .ui-grid-cell-contents');
  20073. Array.prototype.forEach.call(cells, function (cell) {
  20074. // Get the cell width
  20075. // gridUtil.logDebug('width', gridUtil.elementWidth(cell));
  20076. // Account for the menu button if it exists
  20077. var menuButton;
  20078. if (angular.element(cell).parent().hasClass('ui-grid-header-cell')) {
  20079. menuButton = angular.element(cell).parent()[0].querySelectorAll('.ui-grid-column-menu-button');
  20080. }
  20081. gridUtil.fakeElement(cell, {}, function(newElm) {
  20082. // Make the element float since it's a div and can expand to fill its container
  20083. var e = angular.element(newElm);
  20084. e.attr('style', 'float: left');
  20085. var width = gridUtil.elementWidth(e);
  20086. if (menuButton) {
  20087. var menuButtonWidth = gridUtil.elementWidth(menuButton);
  20088. width = width + menuButtonWidth;
  20089. }
  20090. if (width > maxWidth) {
  20091. maxWidth = width;
  20092. xDiff = maxWidth - width;
  20093. }
  20094. });
  20095. });
  20096. // check we're not outside the allowable bounds for this column
  20097. col.width = constrainWidth(col, maxWidth);
  20098. col.hasCustomWidth = true;
  20099. refreshCanvas(xDiff);
  20100. uiGridResizeColumnsService.fireColumnSizeChanged(uiGridCtrl.grid, col.colDef, xDiff); };
  20101. $elm.on('dblclick', dblClickFn);
  20102. $elm.on('$destroy', function() {
  20103. $elm.off('dblclick', dblClickFn);
  20104. offAllEvents();
  20105. });
  20106. }
  20107. };
  20108. return resizer;
  20109. }]);
  20110. })();
  20111. (function () {
  20112. 'use strict';
  20113. /**
  20114. * @ngdoc overview
  20115. * @name ui.grid.rowEdit
  20116. * @description
  20117. *
  20118. * # ui.grid.rowEdit
  20119. *
  20120. * <div class="alert alert-success" role="alert"><strong>Stable</strong> This feature is stable. There should no longer be breaking api changes without a deprecation warning.</div>
  20121. *
  20122. * This module extends the edit feature to provide tracking and saving of rows
  20123. * of data. The tutorial provides more information on how this feature is best
  20124. * used {@link tutorial/205_row_editable here}.
  20125. * <br/>
  20126. * This feature depends on usage of the ui-grid-edit feature, and also benefits
  20127. * from use of ui-grid-cellNav to provide the full spreadsheet-like editing
  20128. * experience
  20129. *
  20130. */
  20131. var module = angular.module('ui.grid.rowEdit', ['ui.grid', 'ui.grid.edit', 'ui.grid.cellNav']);
  20132. /**
  20133. * @ngdoc object
  20134. * @name ui.grid.rowEdit.constant:uiGridRowEditConstants
  20135. *
  20136. * @description constants available in row edit module
  20137. */
  20138. module.constant('uiGridRowEditConstants', {
  20139. });
  20140. /**
  20141. * @ngdoc service
  20142. * @name ui.grid.rowEdit.service:uiGridRowEditService
  20143. *
  20144. * @description Services for row editing features
  20145. */
  20146. module.service('uiGridRowEditService', ['$interval', '$q', 'uiGridConstants', 'uiGridRowEditConstants', 'gridUtil',
  20147. function ($interval, $q, uiGridConstants, uiGridRowEditConstants, gridUtil) {
  20148. var service = {
  20149. initializeGrid: function (scope, grid) {
  20150. /**
  20151. * @ngdoc object
  20152. * @name ui.grid.rowEdit.api:PublicApi
  20153. *
  20154. * @description Public Api for rowEdit feature
  20155. */
  20156. grid.rowEdit = {};
  20157. var publicApi = {
  20158. events: {
  20159. rowEdit: {
  20160. /**
  20161. * @ngdoc event
  20162. * @eventOf ui.grid.rowEdit.api:PublicApi
  20163. * @name saveRow
  20164. * @description raised when a row is ready for saving. Once your
  20165. * row has saved you may need to use angular.extend to update the
  20166. * data entity with any changed data from your save (for example,
  20167. * lock version information if you're using optimistic locking,
  20168. * or last update time/user information).
  20169. *
  20170. * Your method should call setSavePromise somewhere in the body before
  20171. * returning control. The feature will then wait, with the gridRow greyed out
  20172. * whilst this promise is being resolved.
  20173. *
  20174. * <pre>
  20175. * gridApi.rowEdit.on.saveRow(scope,function(rowEntity){})
  20176. * </pre>
  20177. * and somewhere within the event handler:
  20178. * <pre>
  20179. * gridApi.rowEdit.setSavePromise( rowEntity, savePromise)
  20180. * </pre>
  20181. * @param {object} rowEntity the options.data element that was edited
  20182. * @returns {promise} Your saveRow method should return a promise, the
  20183. * promise should either be resolved (implying successful save), or
  20184. * rejected (implying an error).
  20185. */
  20186. saveRow: function (rowEntity) {
  20187. }
  20188. }
  20189. },
  20190. methods: {
  20191. rowEdit: {
  20192. /**
  20193. * @ngdoc method
  20194. * @methodOf ui.grid.rowEdit.api:PublicApi
  20195. * @name setSavePromise
  20196. * @description Sets the promise associated with the row save, mandatory that
  20197. * the saveRow event handler calls this method somewhere before returning.
  20198. * <pre>
  20199. * gridApi.rowEdit.setSavePromise(rowEntity, savePromise)
  20200. * </pre>
  20201. * @param {object} rowEntity a data row from the grid for which a save has
  20202. * been initiated
  20203. * @param {promise} savePromise the promise that will be resolved when the
  20204. * save is successful, or rejected if the save fails
  20205. *
  20206. */
  20207. setSavePromise: function ( rowEntity, savePromise) {
  20208. service.setSavePromise(grid, rowEntity, savePromise);
  20209. },
  20210. /**
  20211. * @ngdoc method
  20212. * @methodOf ui.grid.rowEdit.api:PublicApi
  20213. * @name getDirtyRows
  20214. * @description Returns all currently dirty rows
  20215. * <pre>
  20216. * gridApi.rowEdit.getDirtyRows(grid)
  20217. * </pre>
  20218. * @returns {array} An array of gridRows that are currently dirty
  20219. *
  20220. */
  20221. getDirtyRows: function () {
  20222. return grid.rowEdit.dirtyRows ? grid.rowEdit.dirtyRows : [];
  20223. },
  20224. /**
  20225. * @ngdoc method
  20226. * @methodOf ui.grid.rowEdit.api:PublicApi
  20227. * @name getErrorRows
  20228. * @description Returns all currently errored rows
  20229. * <pre>
  20230. * gridApi.rowEdit.getErrorRows(grid)
  20231. * </pre>
  20232. * @returns {array} An array of gridRows that are currently in error
  20233. *
  20234. */
  20235. getErrorRows: function () {
  20236. return grid.rowEdit.errorRows ? grid.rowEdit.errorRows : [];
  20237. },
  20238. /**
  20239. * @ngdoc method
  20240. * @methodOf ui.grid.rowEdit.api:PublicApi
  20241. * @name flushDirtyRows
  20242. * @description Triggers a save event for all currently dirty rows, could
  20243. * be used where user presses a save button or navigates away from the page
  20244. * <pre>
  20245. * gridApi.rowEdit.flushDirtyRows(grid)
  20246. * </pre>
  20247. * @returns {promise} a promise that represents the aggregate of all
  20248. * of the individual save promises - i.e. it will be resolved when all
  20249. * the individual save promises have been resolved.
  20250. *
  20251. */
  20252. flushDirtyRows: function () {
  20253. return service.flushDirtyRows(grid);
  20254. },
  20255. /**
  20256. * @ngdoc method
  20257. * @methodOf ui.grid.rowEdit.api:PublicApi
  20258. * @name setRowsDirty
  20259. * @description Sets each of the rows passed in dataRows
  20260. * to be dirty. note that if you have only just inserted the
  20261. * rows into your data you will need to wait for a $digest cycle
  20262. * before the gridRows are present - so often you would wrap this
  20263. * call in a $interval or $timeout
  20264. * <pre>
  20265. * $interval( function() {
  20266. * gridApi.rowEdit.setRowsDirty(myDataRows);
  20267. * }, 0, 1);
  20268. * </pre>
  20269. * @param {array} dataRows the data entities for which the gridRows
  20270. * should be set dirty.
  20271. *
  20272. */
  20273. setRowsDirty: function ( dataRows) {
  20274. service.setRowsDirty(grid, dataRows);
  20275. },
  20276. /**
  20277. * @ngdoc method
  20278. * @methodOf ui.grid.rowEdit.api:PublicApi
  20279. * @name setRowsClean
  20280. * @description Sets each of the rows passed in dataRows
  20281. * to be clean, removing them from the dirty cache and the error cache,
  20282. * and clearing the error flag and the dirty flag
  20283. * <pre>
  20284. * var gridRows = $scope.gridApi.rowEdit.getDirtyRows();
  20285. * var dataRows = gridRows.map( function( gridRow ) { return gridRow.entity; });
  20286. * $scope.gridApi.rowEdit.setRowsClean( dataRows );
  20287. * </pre>
  20288. * @param {array} dataRows the data entities for which the gridRows
  20289. * should be set clean.
  20290. *
  20291. */
  20292. setRowsClean: function ( dataRows) {
  20293. service.setRowsClean(grid, dataRows);
  20294. }
  20295. }
  20296. }
  20297. };
  20298. grid.api.registerEventsFromObject(publicApi.events);
  20299. grid.api.registerMethodsFromObject(publicApi.methods);
  20300. grid.api.core.on.renderingComplete( scope, function ( gridApi ) {
  20301. grid.api.edit.on.afterCellEdit( scope, service.endEditCell );
  20302. grid.api.edit.on.beginCellEdit( scope, service.beginEditCell );
  20303. grid.api.edit.on.cancelCellEdit( scope, service.cancelEditCell );
  20304. if ( grid.api.cellNav ) {
  20305. grid.api.cellNav.on.navigate( scope, service.navigate );
  20306. }
  20307. });
  20308. },
  20309. defaultGridOptions: function (gridOptions) {
  20310. /**
  20311. * @ngdoc object
  20312. * @name ui.grid.rowEdit.api:GridOptions
  20313. *
  20314. * @description Options for configuring the rowEdit feature, these are available to be
  20315. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  20316. */
  20317. },
  20318. /**
  20319. * @ngdoc method
  20320. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20321. * @name saveRow
  20322. * @description Returns a function that saves the specified row from the grid,
  20323. * and returns a promise
  20324. * @param {object} grid the grid for which dirty rows should be flushed
  20325. * @param {GridRow} gridRow the row that should be saved
  20326. * @returns {function} the saveRow function returns a function. That function
  20327. * in turn, when called, returns a promise relating to the save callback
  20328. */
  20329. saveRow: function ( grid, gridRow ) {
  20330. var self = this;
  20331. return function() {
  20332. gridRow.isSaving = true;
  20333. if ( gridRow.rowEditSavePromise ){
  20334. // don't save the row again if it's already saving - that causes stale object exceptions
  20335. return gridRow.rowEditSavePromise;
  20336. }
  20337. var promise = grid.api.rowEdit.raise.saveRow( gridRow.entity );
  20338. if ( gridRow.rowEditSavePromise ){
  20339. gridRow.rowEditSavePromise.then( self.processSuccessPromise( grid, gridRow ), self.processErrorPromise( grid, gridRow ));
  20340. } else {
  20341. gridUtil.logError( 'A promise was not returned when saveRow event was raised, either nobody is listening to event, or event handler did not return a promise' );
  20342. }
  20343. return promise;
  20344. };
  20345. },
  20346. /**
  20347. * @ngdoc method
  20348. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20349. * @name setSavePromise
  20350. * @description Sets the promise associated with the row save, mandatory that
  20351. * the saveRow event handler calls this method somewhere before returning.
  20352. * <pre>
  20353. * gridApi.rowEdit.setSavePromise(grid, rowEntity)
  20354. * </pre>
  20355. * @param {object} grid the grid for which dirty rows should be returned
  20356. * @param {object} rowEntity a data row from the grid for which a save has
  20357. * been initiated
  20358. * @param {promise} savePromise the promise that will be resolved when the
  20359. * save is successful, or rejected if the save fails
  20360. *
  20361. */
  20362. setSavePromise: function (grid, rowEntity, savePromise) {
  20363. var gridRow = grid.getRow( rowEntity );
  20364. gridRow.rowEditSavePromise = savePromise;
  20365. },
  20366. /**
  20367. * @ngdoc method
  20368. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20369. * @name processSuccessPromise
  20370. * @description Returns a function that processes the successful
  20371. * resolution of a save promise
  20372. * @param {object} grid the grid for which the promise should be processed
  20373. * @param {GridRow} gridRow the row that has been saved
  20374. * @returns {function} the success handling function
  20375. */
  20376. processSuccessPromise: function ( grid, gridRow ) {
  20377. var self = this;
  20378. return function() {
  20379. delete gridRow.isSaving;
  20380. delete gridRow.isDirty;
  20381. delete gridRow.isError;
  20382. delete gridRow.rowEditSaveTimer;
  20383. delete gridRow.rowEditSavePromise;
  20384. self.removeRow( grid.rowEdit.errorRows, gridRow );
  20385. self.removeRow( grid.rowEdit.dirtyRows, gridRow );
  20386. };
  20387. },
  20388. /**
  20389. * @ngdoc method
  20390. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20391. * @name processErrorPromise
  20392. * @description Returns a function that processes the failed
  20393. * resolution of a save promise
  20394. * @param {object} grid the grid for which the promise should be processed
  20395. * @param {GridRow} gridRow the row that is now in error
  20396. * @returns {function} the error handling function
  20397. */
  20398. processErrorPromise: function ( grid, gridRow ) {
  20399. return function() {
  20400. delete gridRow.isSaving;
  20401. delete gridRow.rowEditSaveTimer;
  20402. delete gridRow.rowEditSavePromise;
  20403. gridRow.isError = true;
  20404. if (!grid.rowEdit.errorRows){
  20405. grid.rowEdit.errorRows = [];
  20406. }
  20407. if (!service.isRowPresent( grid.rowEdit.errorRows, gridRow ) ){
  20408. grid.rowEdit.errorRows.push( gridRow );
  20409. }
  20410. };
  20411. },
  20412. /**
  20413. * @ngdoc method
  20414. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20415. * @name removeRow
  20416. * @description Removes a row from a cache of rows - either
  20417. * grid.rowEdit.errorRows or grid.rowEdit.dirtyRows. If the row
  20418. * is not present silently does nothing.
  20419. * @param {array} rowArray the array from which to remove the row
  20420. * @param {GridRow} gridRow the row that should be removed
  20421. */
  20422. removeRow: function( rowArray, removeGridRow ){
  20423. if (typeof(rowArray) === 'undefined' || rowArray === null){
  20424. return;
  20425. }
  20426. rowArray.forEach( function( gridRow, index ){
  20427. if ( gridRow.uid === removeGridRow.uid ){
  20428. rowArray.splice( index, 1);
  20429. }
  20430. });
  20431. },
  20432. /**
  20433. * @ngdoc method
  20434. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20435. * @name isRowPresent
  20436. * @description Checks whether a row is already present
  20437. * in the given array
  20438. * @param {array} rowArray the array in which to look for the row
  20439. * @param {GridRow} gridRow the row that should be looked for
  20440. */
  20441. isRowPresent: function( rowArray, removeGridRow ){
  20442. var present = false;
  20443. rowArray.forEach( function( gridRow, index ){
  20444. if ( gridRow.uid === removeGridRow.uid ){
  20445. present = true;
  20446. }
  20447. });
  20448. return present;
  20449. },
  20450. /**
  20451. * @ngdoc method
  20452. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20453. * @name flushDirtyRows
  20454. * @description Triggers a save event for all currently dirty rows, could
  20455. * be used where user presses a save button or navigates away from the page
  20456. * <pre>
  20457. * gridApi.rowEdit.flushDirtyRows(grid)
  20458. * </pre>
  20459. * @param {object} grid the grid for which dirty rows should be flushed
  20460. * @returns {promise} a promise that represents the aggregate of all
  20461. * of the individual save promises - i.e. it will be resolved when all
  20462. * the individual save promises have been resolved.
  20463. *
  20464. */
  20465. flushDirtyRows: function(grid){
  20466. var promises = [];
  20467. grid.api.rowEdit.getDirtyRows().forEach( function( gridRow ){
  20468. service.saveRow( grid, gridRow )();
  20469. promises.push( gridRow.rowEditSavePromise );
  20470. });
  20471. return $q.all( promises );
  20472. },
  20473. /**
  20474. * @ngdoc method
  20475. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20476. * @name endEditCell
  20477. * @description Receives an afterCellEdit event from the edit function,
  20478. * and sets flags as appropriate. Only the rowEntity parameter
  20479. * is processed, although other params are available. Grid
  20480. * is automatically provided by the gridApi.
  20481. * @param {object} rowEntity the data entity for which the cell
  20482. * was edited
  20483. */
  20484. endEditCell: function( rowEntity, colDef, newValue, previousValue ){
  20485. var grid = this.grid;
  20486. var gridRow = grid.getRow( rowEntity );
  20487. if ( !gridRow ){ gridUtil.logError( 'Unable to find rowEntity in grid data, dirty flag cannot be set' ); return; }
  20488. if ( newValue !== previousValue || gridRow.isDirty ){
  20489. if ( !grid.rowEdit.dirtyRows ){
  20490. grid.rowEdit.dirtyRows = [];
  20491. }
  20492. if ( !gridRow.isDirty ){
  20493. gridRow.isDirty = true;
  20494. grid.rowEdit.dirtyRows.push( gridRow );
  20495. }
  20496. delete gridRow.isError;
  20497. service.considerSetTimer( grid, gridRow );
  20498. }
  20499. },
  20500. /**
  20501. * @ngdoc method
  20502. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20503. * @name beginEditCell
  20504. * @description Receives a beginCellEdit event from the edit function,
  20505. * and cancels any rowEditSaveTimers if present, as the user is still editing
  20506. * this row. Only the rowEntity parameter
  20507. * is processed, although other params are available. Grid
  20508. * is automatically provided by the gridApi.
  20509. * @param {object} rowEntity the data entity for which the cell
  20510. * editing has commenced
  20511. */
  20512. beginEditCell: function( rowEntity, colDef ){
  20513. var grid = this.grid;
  20514. var gridRow = grid.getRow( rowEntity );
  20515. if ( !gridRow ){ gridUtil.logError( 'Unable to find rowEntity in grid data, timer cannot be cancelled' ); return; }
  20516. service.cancelTimer( grid, gridRow );
  20517. },
  20518. /**
  20519. * @ngdoc method
  20520. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20521. * @name cancelEditCell
  20522. * @description Receives a cancelCellEdit event from the edit function,
  20523. * and if the row was already dirty, restarts the save timer. If the row
  20524. * was not already dirty, then it's not dirty now either and does nothing.
  20525. *
  20526. * Only the rowEntity parameter
  20527. * is processed, although other params are available. Grid
  20528. * is automatically provided by the gridApi.
  20529. *
  20530. * @param {object} rowEntity the data entity for which the cell
  20531. * editing was cancelled
  20532. */
  20533. cancelEditCell: function( rowEntity, colDef ){
  20534. var grid = this.grid;
  20535. var gridRow = grid.getRow( rowEntity );
  20536. if ( !gridRow ){ gridUtil.logError( 'Unable to find rowEntity in grid data, timer cannot be set' ); return; }
  20537. service.considerSetTimer( grid, gridRow );
  20538. },
  20539. /**
  20540. * @ngdoc method
  20541. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20542. * @name navigate
  20543. * @description cellNav tells us that the selected cell has changed. If
  20544. * the new row had a timer running, then stop it similar to in a beginCellEdit
  20545. * call. If the old row is dirty and not the same as the new row, then
  20546. * start a timer on it.
  20547. * @param {object} newRowCol the row and column that were selected
  20548. * @param {object} oldRowCol the row and column that was left
  20549. *
  20550. */
  20551. navigate: function( newRowCol, oldRowCol ){
  20552. var grid = this.grid;
  20553. if ( newRowCol.row.rowEditSaveTimer ){
  20554. service.cancelTimer( grid, newRowCol.row );
  20555. }
  20556. if ( oldRowCol && oldRowCol.row && oldRowCol.row !== newRowCol.row ){
  20557. service.considerSetTimer( grid, oldRowCol.row );
  20558. }
  20559. },
  20560. /**
  20561. * @ngdoc property
  20562. * @propertyOf ui.grid.rowEdit.api:GridOptions
  20563. * @name rowEditWaitInterval
  20564. * @description How long the grid should wait for another change on this row
  20565. * before triggering a save (in milliseconds). If set to -1, then saves are
  20566. * never triggered by timer (implying that the user will call flushDirtyRows()
  20567. * manually)
  20568. *
  20569. * @example
  20570. * Setting the wait interval to 4 seconds
  20571. * <pre>
  20572. * $scope.gridOptions = { rowEditWaitInterval: 4000 }
  20573. * </pre>
  20574. *
  20575. */
  20576. /**
  20577. * @ngdoc method
  20578. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20579. * @name considerSetTimer
  20580. * @description Consider setting a timer on this row (if it is dirty). if there is a timer running
  20581. * on the row and the row isn't currently saving, cancel it, using cancelTimer, then if the row is
  20582. * dirty and not currently saving then set a new timer
  20583. * @param {object} grid the grid for which we are processing
  20584. * @param {GridRow} gridRow the row for which the timer should be adjusted
  20585. *
  20586. */
  20587. considerSetTimer: function( grid, gridRow ){
  20588. service.cancelTimer( grid, gridRow );
  20589. if ( gridRow.isDirty && !gridRow.isSaving ){
  20590. if ( grid.options.rowEditWaitInterval !== -1 ){
  20591. var waitTime = grid.options.rowEditWaitInterval ? grid.options.rowEditWaitInterval : 2000;
  20592. gridRow.rowEditSaveTimer = $interval( service.saveRow( grid, gridRow ), waitTime, 1);
  20593. }
  20594. }
  20595. },
  20596. /**
  20597. * @ngdoc method
  20598. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20599. * @name cancelTimer
  20600. * @description cancel the $interval for any timer running on this row
  20601. * then delete the timer itself
  20602. * @param {object} grid the grid for which we are processing
  20603. * @param {GridRow} gridRow the row for which the timer should be adjusted
  20604. *
  20605. */
  20606. cancelTimer: function( grid, gridRow ){
  20607. if ( gridRow.rowEditSaveTimer && !gridRow.isSaving ){
  20608. $interval.cancel(gridRow.rowEditSaveTimer);
  20609. delete gridRow.rowEditSaveTimer;
  20610. }
  20611. },
  20612. /**
  20613. * @ngdoc method
  20614. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20615. * @name setRowsDirty
  20616. * @description Sets each of the rows passed in dataRows
  20617. * to be dirty. note that if you have only just inserted the
  20618. * rows into your data you will need to wait for a $digest cycle
  20619. * before the gridRows are present - so often you would wrap this
  20620. * call in a $interval or $timeout
  20621. * <pre>
  20622. * $interval( function() {
  20623. * gridApi.rowEdit.setRowsDirty( myDataRows);
  20624. * }, 0, 1);
  20625. * </pre>
  20626. * @param {object} grid the grid for which rows should be set dirty
  20627. * @param {array} dataRows the data entities for which the gridRows
  20628. * should be set dirty.
  20629. *
  20630. */
  20631. setRowsDirty: function( grid, myDataRows ) {
  20632. var gridRow;
  20633. myDataRows.forEach( function( value, index ){
  20634. gridRow = grid.getRow( value );
  20635. if ( gridRow ){
  20636. if ( !grid.rowEdit.dirtyRows ){
  20637. grid.rowEdit.dirtyRows = [];
  20638. }
  20639. if ( !gridRow.isDirty ){
  20640. gridRow.isDirty = true;
  20641. grid.rowEdit.dirtyRows.push( gridRow );
  20642. }
  20643. delete gridRow.isError;
  20644. service.considerSetTimer( grid, gridRow );
  20645. } else {
  20646. gridUtil.logError( "requested row not found in rowEdit.setRowsDirty, row was: " + value );
  20647. }
  20648. });
  20649. },
  20650. /**
  20651. * @ngdoc method
  20652. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  20653. * @name setRowsClean
  20654. * @description Sets each of the rows passed in dataRows
  20655. * to be clean, clearing the dirty flag and the error flag, and removing
  20656. * the rows from the dirty and error caches.
  20657. * @param {object} grid the grid for which rows should be set clean
  20658. * @param {array} dataRows the data entities for which the gridRows
  20659. * should be set clean.
  20660. *
  20661. */
  20662. setRowsClean: function( grid, myDataRows ) {
  20663. var gridRow;
  20664. myDataRows.forEach( function( value, index ){
  20665. gridRow = grid.getRow( value );
  20666. if ( gridRow ){
  20667. delete gridRow.isDirty;
  20668. service.removeRow( grid.rowEdit.dirtyRows, gridRow );
  20669. service.cancelTimer( grid, gridRow );
  20670. delete gridRow.isError;
  20671. service.removeRow( grid.rowEdit.errorRows, gridRow );
  20672. } else {
  20673. gridUtil.logError( "requested row not found in rowEdit.setRowsClean, row was: " + value );
  20674. }
  20675. });
  20676. }
  20677. };
  20678. return service;
  20679. }]);
  20680. /**
  20681. * @ngdoc directive
  20682. * @name ui.grid.rowEdit.directive:uiGridEdit
  20683. * @element div
  20684. * @restrict A
  20685. *
  20686. * @description Adds row editing features to the ui-grid-edit directive.
  20687. *
  20688. */
  20689. module.directive('uiGridRowEdit', ['gridUtil', 'uiGridRowEditService', 'uiGridEditConstants',
  20690. function (gridUtil, uiGridRowEditService, uiGridEditConstants) {
  20691. return {
  20692. replace: true,
  20693. priority: 0,
  20694. require: '^uiGrid',
  20695. scope: false,
  20696. compile: function () {
  20697. return {
  20698. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  20699. uiGridRowEditService.initializeGrid($scope, uiGridCtrl.grid);
  20700. },
  20701. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  20702. }
  20703. };
  20704. }
  20705. };
  20706. }]);
  20707. /**
  20708. * @ngdoc directive
  20709. * @name ui.grid.rowEdit.directive:uiGridViewport
  20710. * @element div
  20711. *
  20712. * @description Stacks on top of ui.grid.uiGridViewport to alter the attributes used
  20713. * for the grid row to allow coloring of saving and error rows
  20714. */
  20715. module.directive('uiGridViewport',
  20716. ['$compile', 'uiGridConstants', 'gridUtil', '$parse',
  20717. function ($compile, uiGridConstants, gridUtil, $parse) {
  20718. return {
  20719. priority: -200, // run after default directive
  20720. scope: false,
  20721. compile: function ($elm, $attrs) {
  20722. var rowRepeatDiv = angular.element($elm.children().children()[0]);
  20723. var existingNgClass = rowRepeatDiv.attr("ng-class");
  20724. var newNgClass = '';
  20725. if ( existingNgClass ) {
  20726. newNgClass = existingNgClass.slice(0, -1) + ", 'ui-grid-row-dirty': row.isDirty, 'ui-grid-row-saving': row.isSaving, 'ui-grid-row-error': row.isError}";
  20727. } else {
  20728. newNgClass = "{'ui-grid-row-dirty': row.isDirty, 'ui-grid-row-saving': row.isSaving, 'ui-grid-row-error': row.isError}";
  20729. }
  20730. rowRepeatDiv.attr("ng-class", newNgClass);
  20731. return {
  20732. pre: function ($scope, $elm, $attrs, controllers) {
  20733. },
  20734. post: function ($scope, $elm, $attrs, controllers) {
  20735. }
  20736. };
  20737. }
  20738. };
  20739. }]);
  20740. })();
  20741. (function () {
  20742. 'use strict';
  20743. /**
  20744. * @ngdoc overview
  20745. * @name ui.grid.saveState
  20746. * @description
  20747. *
  20748. * # ui.grid.saveState
  20749. *
  20750. * <div class="alert alert-success" role="alert"><strong>Stable</strong> This feature is stable. There should no longer be breaking api changes without a deprecation warning.</div>
  20751. *
  20752. * This module provides the ability to save the grid state, and restore
  20753. * it when the user returns to the page.
  20754. *
  20755. * No UI is provided, the caller should provide their own UI/buttons
  20756. * as appropriate. Usually the navigate events would be used to save
  20757. * the grid state and restore it.
  20758. *
  20759. * <br/>
  20760. * <br/>
  20761. *
  20762. * <div doc-module-components="ui.grid.save-state"></div>
  20763. */
  20764. var module = angular.module('ui.grid.saveState', ['ui.grid', 'ui.grid.selection', 'ui.grid.cellNav', 'ui.grid.grouping', 'ui.grid.pinning', 'ui.grid.treeView']);
  20765. /**
  20766. * @ngdoc object
  20767. * @name ui.grid.saveState.constant:uiGridSaveStateConstants
  20768. *
  20769. * @description constants available in save state module
  20770. */
  20771. module.constant('uiGridSaveStateConstants', {
  20772. featureName: 'saveState'
  20773. });
  20774. /**
  20775. * @ngdoc service
  20776. * @name ui.grid.saveState.service:uiGridSaveStateService
  20777. *
  20778. * @description Services for saveState feature
  20779. */
  20780. module.service('uiGridSaveStateService', ['$q', 'uiGridSaveStateConstants', 'gridUtil', '$compile', '$interval', 'uiGridConstants',
  20781. function ($q, uiGridSaveStateConstants, gridUtil, $compile, $interval, uiGridConstants ) {
  20782. var service = {
  20783. initializeGrid: function (grid) {
  20784. //add feature namespace and any properties to grid for needed state
  20785. grid.saveState = {};
  20786. this.defaultGridOptions(grid.options);
  20787. /**
  20788. * @ngdoc object
  20789. * @name ui.grid.saveState.api:PublicApi
  20790. *
  20791. * @description Public Api for saveState feature
  20792. */
  20793. var publicApi = {
  20794. events: {
  20795. saveState: {
  20796. }
  20797. },
  20798. methods: {
  20799. saveState: {
  20800. /**
  20801. * @ngdoc function
  20802. * @name save
  20803. * @methodOf ui.grid.saveState.api:PublicApi
  20804. * @description Packages the current state of the grid into
  20805. * an object, and provides it to the user for saving
  20806. * @returns {object} the state as a javascript object that can be saved
  20807. */
  20808. save: function () {
  20809. return service.save(grid);
  20810. },
  20811. /**
  20812. * @ngdoc function
  20813. * @name restore
  20814. * @methodOf ui.grid.saveState.api:PublicApi
  20815. * @description Restores the provided state into the grid
  20816. * @param {scope} $scope a scope that we can broadcast on
  20817. * @param {object} state the state that should be restored into the grid
  20818. */
  20819. restore: function ( $scope, state) {
  20820. service.restore(grid, $scope, state);
  20821. }
  20822. }
  20823. }
  20824. };
  20825. grid.api.registerEventsFromObject(publicApi.events);
  20826. grid.api.registerMethodsFromObject(publicApi.methods);
  20827. },
  20828. defaultGridOptions: function (gridOptions) {
  20829. //default option to true unless it was explicitly set to false
  20830. /**
  20831. * @ngdoc object
  20832. * @name ui.grid.saveState.api:GridOptions
  20833. *
  20834. * @description GridOptions for saveState feature, these are available to be
  20835. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  20836. */
  20837. /**
  20838. * @ngdoc object
  20839. * @name saveWidths
  20840. * @propertyOf ui.grid.saveState.api:GridOptions
  20841. * @description Save the current column widths. Note that unless
  20842. * you've provided the user with some way to resize their columns (say
  20843. * the resize columns feature), then this makes little sense.
  20844. * <br/>Defaults to true
  20845. */
  20846. gridOptions.saveWidths = gridOptions.saveWidths !== false;
  20847. /**
  20848. * @ngdoc object
  20849. * @name saveOrder
  20850. * @propertyOf ui.grid.saveState.api:GridOptions
  20851. * @description Restore the current column order. Note that unless
  20852. * you've provided the user with some way to reorder their columns (for
  20853. * example the move columns feature), this makes little sense.
  20854. * <br/>Defaults to true
  20855. */
  20856. gridOptions.saveOrder = gridOptions.saveOrder !== false;
  20857. /**
  20858. * @ngdoc object
  20859. * @name saveScroll
  20860. * @propertyOf ui.grid.saveState.api:GridOptions
  20861. * @description Save the current scroll position. Note that this
  20862. * is saved as the percentage of the grid scrolled - so if your
  20863. * user returns to a grid with a significantly different number of
  20864. * rows (perhaps some data has been deleted) then the scroll won't
  20865. * actually show the same rows as before. If you want to scroll to
  20866. * a specific row then you should instead use the saveFocus option, which
  20867. * is the default.
  20868. *
  20869. * Note that this element will only be saved if the cellNav feature is
  20870. * enabled
  20871. * <br/>Defaults to false
  20872. */
  20873. gridOptions.saveScroll = gridOptions.saveScroll === true;
  20874. /**
  20875. * @ngdoc object
  20876. * @name saveFocus
  20877. * @propertyOf ui.grid.saveState.api:GridOptions
  20878. * @description Save the current focused cell. On returning
  20879. * to this focused cell we'll also scroll. This option is
  20880. * preferred to the saveScroll option, so is set to true by
  20881. * default. If saveScroll is set to true then this option will
  20882. * be disabled.
  20883. *
  20884. * By default this option saves the current row number and column
  20885. * number, and returns to that row and column. However, if you define
  20886. * a saveRowIdentity function, then it will return you to the currently
  20887. * selected column within that row (in a business sense - so if some
  20888. * rows have been deleted, it will still find the same data, presuming it
  20889. * still exists in the list. If it isn't in the list then it will instead
  20890. * return to the same row number - i.e. scroll percentage)
  20891. *
  20892. * Note that this option will do nothing if the cellNav
  20893. * feature is not enabled.
  20894. *
  20895. * <br/>Defaults to true (unless saveScroll is true)
  20896. */
  20897. gridOptions.saveFocus = gridOptions.saveScroll !== true && gridOptions.saveFocus !== false;
  20898. /**
  20899. * @ngdoc object
  20900. * @name saveRowIdentity
  20901. * @propertyOf ui.grid.saveState.api:GridOptions
  20902. * @description A function that can be called, passing in a rowEntity,
  20903. * and that will return a unique id for that row. This might simply
  20904. * return the `id` field from that row (if you have one), or it might
  20905. * concatenate some fields within the row to make a unique value.
  20906. *
  20907. * This value will be used to find the same row again and set the focus
  20908. * to it, if it exists when we return.
  20909. *
  20910. * <br/>Defaults to undefined
  20911. */
  20912. /**
  20913. * @ngdoc object
  20914. * @name saveVisible
  20915. * @propertyOf ui.grid.saveState.api:GridOptions
  20916. * @description Save whether or not columns are visible.
  20917. *
  20918. * <br/>Defaults to true
  20919. */
  20920. gridOptions.saveVisible = gridOptions.saveVisible !== false;
  20921. /**
  20922. * @ngdoc object
  20923. * @name saveSort
  20924. * @propertyOf ui.grid.saveState.api:GridOptions
  20925. * @description Save the current sort state for each column
  20926. *
  20927. * <br/>Defaults to true
  20928. */
  20929. gridOptions.saveSort = gridOptions.saveSort !== false;
  20930. /**
  20931. * @ngdoc object
  20932. * @name saveFilter
  20933. * @propertyOf ui.grid.saveState.api:GridOptions
  20934. * @description Save the current filter state for each column
  20935. *
  20936. * <br/>Defaults to true
  20937. */
  20938. gridOptions.saveFilter = gridOptions.saveFilter !== false;
  20939. /**
  20940. * @ngdoc object
  20941. * @name saveSelection
  20942. * @propertyOf ui.grid.saveState.api:GridOptions
  20943. * @description Save the currently selected rows. If the `saveRowIdentity` callback
  20944. * is defined, then it will save the id of the row and select that. If not, then
  20945. * it will attempt to select the rows by row number, which will give the wrong results
  20946. * if the data set has changed in the mean-time.
  20947. *
  20948. * Note that this option only does anything
  20949. * if the selection feature is enabled.
  20950. *
  20951. * <br/>Defaults to true
  20952. */
  20953. gridOptions.saveSelection = gridOptions.saveSelection !== false;
  20954. /**
  20955. * @ngdoc object
  20956. * @name saveGrouping
  20957. * @propertyOf ui.grid.saveState.api:GridOptions
  20958. * @description Save the grouping configuration. If set to true and the
  20959. * grouping feature is not enabled then does nothing.
  20960. *
  20961. * <br/>Defaults to true
  20962. */
  20963. gridOptions.saveGrouping = gridOptions.saveGrouping !== false;
  20964. /**
  20965. * @ngdoc object
  20966. * @name saveGroupingExpandedStates
  20967. * @propertyOf ui.grid.saveState.api:GridOptions
  20968. * @description Save the grouping row expanded states. If set to true and the
  20969. * grouping feature is not enabled then does nothing.
  20970. *
  20971. * This can be quite a bit of data, in many cases you wouldn't want to save this
  20972. * information.
  20973. *
  20974. * <br/>Defaults to false
  20975. */
  20976. gridOptions.saveGroupingExpandedStates = gridOptions.saveGroupingExpandedStates === true;
  20977. /**
  20978. * @ngdoc object
  20979. * @name savePinning
  20980. * @propertyOf ui.grid.saveState.api:GridOptions
  20981. * @description Save pinning state for columns.
  20982. *
  20983. * <br/>Defaults to true
  20984. */
  20985. gridOptions.savePinning = gridOptions.savePinning !== false;
  20986. /**
  20987. * @ngdoc object
  20988. * @name saveTreeView
  20989. * @propertyOf ui.grid.saveState.api:GridOptions
  20990. * @description Save the treeView configuration. If set to true and the
  20991. * treeView feature is not enabled then does nothing.
  20992. *
  20993. * <br/>Defaults to true
  20994. */
  20995. gridOptions.saveTreeView = gridOptions.saveTreeView !== false;
  20996. },
  20997. /**
  20998. * @ngdoc function
  20999. * @name save
  21000. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21001. * @description Saves the current grid state into an object, and
  21002. * passes that object back to the caller
  21003. * @param {Grid} grid the grid whose state we'd like to save
  21004. * @returns {object} the state ready to be saved
  21005. */
  21006. save: function (grid) {
  21007. var savedState = {};
  21008. savedState.columns = service.saveColumns( grid );
  21009. savedState.scrollFocus = service.saveScrollFocus( grid );
  21010. savedState.selection = service.saveSelection( grid );
  21011. savedState.grouping = service.saveGrouping( grid );
  21012. savedState.treeView = service.saveTreeView( grid );
  21013. savedState.pagination = service.savePagination( grid );
  21014. return savedState;
  21015. },
  21016. /**
  21017. * @ngdoc function
  21018. * @name restore
  21019. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21020. * @description Applies the provided state to the grid
  21021. *
  21022. * @param {Grid} grid the grid whose state we'd like to restore
  21023. * @param {scope} $scope a scope that we can broadcast on
  21024. * @param {object} state the state we'd like to restore
  21025. */
  21026. restore: function( grid, $scope, state ){
  21027. if ( state.columns ) {
  21028. service.restoreColumns( grid, state.columns );
  21029. }
  21030. if ( state.scrollFocus ){
  21031. service.restoreScrollFocus( grid, $scope, state.scrollFocus );
  21032. }
  21033. if ( state.selection ){
  21034. service.restoreSelection( grid, state.selection );
  21035. }
  21036. if ( state.grouping ){
  21037. service.restoreGrouping( grid, state.grouping );
  21038. }
  21039. if ( state.treeView ){
  21040. service.restoreTreeView( grid, state.treeView );
  21041. }
  21042. if ( state.pagination ){
  21043. service.restorePagination( grid, state.pagination );
  21044. }
  21045. grid.refresh();
  21046. },
  21047. /**
  21048. * @ngdoc function
  21049. * @name saveColumns
  21050. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21051. * @description Saves the column setup, including sort, filters, ordering,
  21052. * pinning and column widths.
  21053. *
  21054. * Works through the current columns, storing them in order. Stores the
  21055. * column name, then the visible flag, width, sort and filters for each column.
  21056. *
  21057. * @param {Grid} grid the grid whose state we'd like to save
  21058. * @returns {array} the columns state ready to be saved
  21059. */
  21060. saveColumns: function( grid ) {
  21061. var columns = [];
  21062. grid.getOnlyDataColumns().forEach( function( column ) {
  21063. var savedColumn = {};
  21064. savedColumn.name = column.name;
  21065. if ( grid.options.saveVisible ){
  21066. savedColumn.visible = column.visible;
  21067. }
  21068. if ( grid.options.saveWidths ){
  21069. savedColumn.width = column.width;
  21070. }
  21071. // these two must be copied, not just pointed too - otherwise our saved state is pointing to the same object as current state
  21072. if ( grid.options.saveSort ){
  21073. savedColumn.sort = angular.copy( column.sort );
  21074. }
  21075. if ( grid.options.saveFilter ){
  21076. savedColumn.filters = [];
  21077. column.filters.forEach( function( filter ){
  21078. var copiedFilter = {};
  21079. angular.forEach( filter, function( value, key) {
  21080. if ( key !== 'condition' && key !== '$$hashKey' && key !== 'placeholder'){
  21081. copiedFilter[key] = value;
  21082. }
  21083. });
  21084. savedColumn.filters.push(copiedFilter);
  21085. });
  21086. }
  21087. if ( !!grid.api.pinning && grid.options.savePinning ){
  21088. savedColumn.pinned = column.renderContainer ? column.renderContainer : '';
  21089. }
  21090. columns.push( savedColumn );
  21091. });
  21092. return columns;
  21093. },
  21094. /**
  21095. * @ngdoc function
  21096. * @name saveScrollFocus
  21097. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21098. * @description Saves the currently scroll or focus.
  21099. *
  21100. * If cellNav isn't present then does nothing - we can't return
  21101. * to the scroll position without cellNav anyway.
  21102. *
  21103. * If the cellNav module is present, and saveFocus is true, then
  21104. * it saves the currently focused cell. If rowIdentity is present
  21105. * then saves using rowIdentity, otherwise saves visibleRowNum.
  21106. *
  21107. * If the cellNav module is not present, and saveScroll is true, then
  21108. * it approximates the current scroll row and column, and saves that.
  21109. *
  21110. * @param {Grid} grid the grid whose state we'd like to save
  21111. * @returns {object} the selection state ready to be saved
  21112. */
  21113. saveScrollFocus: function( grid ){
  21114. if ( !grid.api.cellNav ){
  21115. return {};
  21116. }
  21117. var scrollFocus = {};
  21118. if ( grid.options.saveFocus ){
  21119. scrollFocus.focus = true;
  21120. var rowCol = grid.api.cellNav.getFocusedCell();
  21121. if ( rowCol !== null ) {
  21122. if ( rowCol.col !== null ){
  21123. scrollFocus.colName = rowCol.col.colDef.name;
  21124. }
  21125. if ( rowCol.row !== null ){
  21126. scrollFocus.rowVal = service.getRowVal( grid, rowCol.row );
  21127. }
  21128. }
  21129. }
  21130. if ( grid.options.saveScroll || grid.options.saveFocus && !scrollFocus.colName && !scrollFocus.rowVal ) {
  21131. scrollFocus.focus = false;
  21132. if ( grid.renderContainers.body.prevRowScrollIndex ){
  21133. scrollFocus.rowVal = service.getRowVal( grid, grid.renderContainers.body.visibleRowCache[ grid.renderContainers.body.prevRowScrollIndex ]);
  21134. }
  21135. if ( grid.renderContainers.body.prevColScrollIndex ){
  21136. scrollFocus.colName = grid.renderContainers.body.visibleColumnCache[ grid.renderContainers.body.prevColScrollIndex ].name;
  21137. }
  21138. }
  21139. return scrollFocus;
  21140. },
  21141. /**
  21142. * @ngdoc function
  21143. * @name saveSelection
  21144. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21145. * @description Saves the currently selected rows, if the selection feature is enabled
  21146. * @param {Grid} grid the grid whose state we'd like to save
  21147. * @returns {array} the selection state ready to be saved
  21148. */
  21149. saveSelection: function( grid ){
  21150. if ( !grid.api.selection || !grid.options.saveSelection ){
  21151. return [];
  21152. }
  21153. var selection = grid.api.selection.getSelectedGridRows().map( function( gridRow ) {
  21154. return service.getRowVal( grid, gridRow );
  21155. });
  21156. return selection;
  21157. },
  21158. /**
  21159. * @ngdoc function
  21160. * @name saveGrouping
  21161. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21162. * @description Saves the grouping state, if the grouping feature is enabled
  21163. * @param {Grid} grid the grid whose state we'd like to save
  21164. * @returns {object} the grouping state ready to be saved
  21165. */
  21166. saveGrouping: function( grid ){
  21167. if ( !grid.api.grouping || !grid.options.saveGrouping ){
  21168. return {};
  21169. }
  21170. return grid.api.grouping.getGrouping( grid.options.saveGroupingExpandedStates );
  21171. },
  21172. /**
  21173. * @ngdoc function
  21174. * @name savePagination
  21175. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21176. * @description Saves the pagination state, if the pagination feature is enabled
  21177. * @param {Grid} grid the grid whose state we'd like to save
  21178. * @returns {object} the pagination state ready to be saved
  21179. */
  21180. savePagination: function( grid ) {
  21181. if ( !grid.api.pagination || !grid.options.paginationPageSize ){
  21182. return {};
  21183. }
  21184. return {
  21185. paginationCurrentPage: grid.options.paginationCurrentPage,
  21186. paginationPageSize: grid.options.paginationPageSize
  21187. };
  21188. },
  21189. /**
  21190. * @ngdoc function
  21191. * @name saveTreeView
  21192. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21193. * @description Saves the tree view state, if the tree feature is enabled
  21194. * @param {Grid} grid the grid whose state we'd like to save
  21195. * @returns {object} the tree view state ready to be saved
  21196. */
  21197. saveTreeView: function( grid ){
  21198. if ( !grid.api.treeView || !grid.options.saveTreeView ){
  21199. return {};
  21200. }
  21201. return grid.api.treeView.getTreeView();
  21202. },
  21203. /**
  21204. * @ngdoc function
  21205. * @name getRowVal
  21206. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21207. * @description Helper function that gets either the rowNum or
  21208. * the saveRowIdentity, given a gridRow
  21209. * @param {Grid} grid the grid the row is in
  21210. * @param {GridRow} gridRow the row we want the rowNum for
  21211. * @returns {object} an object containing { identity: true/false, row: rowNumber/rowIdentity }
  21212. *
  21213. */
  21214. getRowVal: function( grid, gridRow ){
  21215. if ( !gridRow ) {
  21216. return null;
  21217. }
  21218. var rowVal = {};
  21219. if ( grid.options.saveRowIdentity ){
  21220. rowVal.identity = true;
  21221. rowVal.row = grid.options.saveRowIdentity( gridRow.entity );
  21222. } else {
  21223. rowVal.identity = false;
  21224. rowVal.row = grid.renderContainers.body.visibleRowCache.indexOf( gridRow );
  21225. }
  21226. return rowVal;
  21227. },
  21228. /**
  21229. * @ngdoc function
  21230. * @name restoreColumns
  21231. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21232. * @description Restores the columns, including order, visible, width,
  21233. * pinning, sort and filters.
  21234. *
  21235. * @param {Grid} grid the grid whose state we'd like to restore
  21236. * @param {object} columnsState the list of columns we had before, with their state
  21237. */
  21238. restoreColumns: function( grid, columnsState ){
  21239. var isSortChanged = false;
  21240. columnsState.forEach( function( columnState, index ) {
  21241. var currentCol = grid.getColumn( columnState.name );
  21242. if ( currentCol && !grid.isRowHeaderColumn(currentCol) ){
  21243. if ( grid.options.saveVisible &&
  21244. ( currentCol.visible !== columnState.visible ||
  21245. currentCol.colDef.visible !== columnState.visible ) ){
  21246. currentCol.visible = columnState.visible;
  21247. currentCol.colDef.visible = columnState.visible;
  21248. grid.api.core.raise.columnVisibilityChanged(currentCol);
  21249. }
  21250. if ( grid.options.saveWidths && currentCol.width !== columnState.width){
  21251. currentCol.width = columnState.width;
  21252. currentCol.hasCustomWidth = true;
  21253. }
  21254. if ( grid.options.saveSort &&
  21255. !angular.equals(currentCol.sort, columnState.sort) &&
  21256. !( currentCol.sort === undefined && angular.isEmpty(columnState.sort) ) ){
  21257. currentCol.sort = angular.copy( columnState.sort );
  21258. isSortChanged = true;
  21259. }
  21260. if ( grid.options.saveFilter &&
  21261. !angular.equals(currentCol.filters, columnState.filters ) ){
  21262. columnState.filters.forEach( function( filter, index ){
  21263. angular.extend( currentCol.filters[index], filter );
  21264. if ( typeof(filter.term) === 'undefined' || filter.term === null ){
  21265. delete currentCol.filters[index].term;
  21266. }
  21267. });
  21268. grid.api.core.raise.filterChanged();
  21269. }
  21270. if ( !!grid.api.pinning && grid.options.savePinning && currentCol.renderContainer !== columnState.pinned ){
  21271. grid.api.pinning.pinColumn(currentCol, columnState.pinned);
  21272. }
  21273. var currentIndex = grid.getOnlyDataColumns().indexOf( currentCol );
  21274. if (currentIndex !== -1) {
  21275. if (grid.options.saveOrder && currentIndex !== index) {
  21276. var column = grid.columns.splice(currentIndex + grid.rowHeaderColumns.length, 1)[0];
  21277. grid.columns.splice(index + grid.rowHeaderColumns.length, 0, column);
  21278. }
  21279. }
  21280. }
  21281. });
  21282. if ( isSortChanged ) {
  21283. grid.api.core.raise.sortChanged( grid, grid.getColumnSorting() );
  21284. }
  21285. },
  21286. /**
  21287. * @ngdoc function
  21288. * @name restoreScrollFocus
  21289. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21290. * @description Scrolls to the position that was saved. If focus is true, then
  21291. * sets focus to the specified row/col. If focus is false, then scrolls to the
  21292. * specified row/col.
  21293. *
  21294. * @param {Grid} grid the grid whose state we'd like to restore
  21295. * @param {scope} $scope a scope that we can broadcast on
  21296. * @param {object} scrollFocusState the scroll/focus state ready to be restored
  21297. */
  21298. restoreScrollFocus: function( grid, $scope, scrollFocusState ){
  21299. if ( !grid.api.cellNav ){
  21300. return;
  21301. }
  21302. var colDef, row;
  21303. if ( scrollFocusState.colName ){
  21304. var colDefs = grid.options.columnDefs.filter( function( colDef ) { return colDef.name === scrollFocusState.colName; });
  21305. if ( colDefs.length > 0 ){
  21306. colDef = colDefs[0];
  21307. }
  21308. }
  21309. if ( scrollFocusState.rowVal && scrollFocusState.rowVal.row ){
  21310. if ( scrollFocusState.rowVal.identity ){
  21311. row = service.findRowByIdentity( grid, scrollFocusState.rowVal );
  21312. } else {
  21313. row = grid.renderContainers.body.visibleRowCache[ scrollFocusState.rowVal.row ];
  21314. }
  21315. }
  21316. var entity = row && row.entity ? row.entity : null ;
  21317. if ( colDef || entity ) {
  21318. if (scrollFocusState.focus ){
  21319. grid.api.cellNav.scrollToFocus( entity, colDef );
  21320. } else {
  21321. grid.scrollTo( entity, colDef );
  21322. }
  21323. }
  21324. },
  21325. /**
  21326. * @ngdoc function
  21327. * @name restoreSelection
  21328. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21329. * @description Selects the rows that are provided in the selection
  21330. * state. If you are using `saveRowIdentity` and more than one row matches the identity
  21331. * function then only the first is selected.
  21332. * @param {Grid} grid the grid whose state we'd like to restore
  21333. * @param {object} selectionState the selection state ready to be restored
  21334. */
  21335. restoreSelection: function( grid, selectionState ){
  21336. if ( !grid.api.selection ){
  21337. return;
  21338. }
  21339. grid.api.selection.clearSelectedRows();
  21340. selectionState.forEach( function( rowVal ) {
  21341. if ( rowVal.identity ){
  21342. var foundRow = service.findRowByIdentity( grid, rowVal );
  21343. if ( foundRow ){
  21344. grid.api.selection.selectRow( foundRow.entity );
  21345. }
  21346. } else {
  21347. grid.api.selection.selectRowByVisibleIndex( rowVal.row );
  21348. }
  21349. });
  21350. },
  21351. /**
  21352. * @ngdoc function
  21353. * @name restoreGrouping
  21354. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21355. * @description Restores the grouping configuration, if the grouping feature
  21356. * is enabled.
  21357. * @param {Grid} grid the grid whose state we'd like to restore
  21358. * @param {object} groupingState the grouping state ready to be restored
  21359. */
  21360. restoreGrouping: function( grid, groupingState ){
  21361. if ( !grid.api.grouping || typeof(groupingState) === 'undefined' || groupingState === null || angular.equals(groupingState, {}) ){
  21362. return;
  21363. }
  21364. grid.api.grouping.setGrouping( groupingState );
  21365. },
  21366. /**
  21367. * @ngdoc function
  21368. * @name restoreTreeView
  21369. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21370. * @description Restores the tree view configuration, if the tree view feature
  21371. * is enabled.
  21372. * @param {Grid} grid the grid whose state we'd like to restore
  21373. * @param {object} treeViewState the tree view state ready to be restored
  21374. */
  21375. restoreTreeView: function( grid, treeViewState ){
  21376. if ( !grid.api.treeView || typeof(treeViewState) === 'undefined' || treeViewState === null || angular.equals(treeViewState, {}) ){
  21377. return;
  21378. }
  21379. grid.api.treeView.setTreeView( treeViewState );
  21380. },
  21381. /**
  21382. * @ngdoc function
  21383. * @name restorePagination
  21384. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21385. * @description Restores the pagination information, if pagination is enabled.
  21386. * @param {Grid} grid the grid whose state we'd like to restore
  21387. * @param {object} pagination the pagination object to be restored
  21388. * @param {number} pagination.paginationCurrentPage the page number to restore
  21389. * @param {number} pagination.paginationPageSize the number of items displayed per page
  21390. */
  21391. restorePagination: function( grid, pagination ){
  21392. if ( !grid.api.pagination || !grid.options.paginationPageSize ){
  21393. return;
  21394. }
  21395. grid.options.paginationCurrentPage = pagination.paginationCurrentPage;
  21396. grid.options.paginationPageSize = pagination.paginationPageSize;
  21397. },
  21398. /**
  21399. * @ngdoc function
  21400. * @name findRowByIdentity
  21401. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  21402. * @description Finds a row given it's identity value, returns the first found row
  21403. * if any are found, otherwise returns null if no rows are found.
  21404. * @param {Grid} grid the grid whose state we'd like to restore
  21405. * @param {object} rowVal the row we'd like to find
  21406. * @returns {gridRow} the found row, or null if none found
  21407. */
  21408. findRowByIdentity: function( grid, rowVal ){
  21409. if ( !grid.options.saveRowIdentity ){
  21410. return null;
  21411. }
  21412. var filteredRows = grid.rows.filter( function( gridRow ) {
  21413. if ( grid.options.saveRowIdentity( gridRow.entity ) === rowVal.row ){
  21414. return true;
  21415. } else {
  21416. return false;
  21417. }
  21418. });
  21419. if ( filteredRows.length > 0 ){
  21420. return filteredRows[0];
  21421. } else {
  21422. return null;
  21423. }
  21424. }
  21425. };
  21426. return service;
  21427. }
  21428. ]);
  21429. /**
  21430. * @ngdoc directive
  21431. * @name ui.grid.saveState.directive:uiGridSaveState
  21432. * @element div
  21433. * @restrict A
  21434. *
  21435. * @description Adds saveState features to grid
  21436. *
  21437. * @example
  21438. <example module="app">
  21439. <file name="app.js">
  21440. var app = angular.module('app', ['ui.grid', 'ui.grid.saveState']);
  21441. app.controller('MainCtrl', ['$scope', function ($scope) {
  21442. $scope.data = [
  21443. { name: 'Bob', title: 'CEO' },
  21444. { name: 'Frank', title: 'Lowly Developer' }
  21445. ];
  21446. $scope.gridOptions = {
  21447. columnDefs: [
  21448. {name: 'name'},
  21449. {name: 'title', enableCellEdit: true}
  21450. ],
  21451. data: $scope.data
  21452. };
  21453. }]);
  21454. </file>
  21455. <file name="index.html">
  21456. <div ng-controller="MainCtrl">
  21457. <div ui-grid="gridOptions" ui-grid-save-state></div>
  21458. </div>
  21459. </file>
  21460. </example>
  21461. */
  21462. module.directive('uiGridSaveState', ['uiGridSaveStateConstants', 'uiGridSaveStateService', 'gridUtil', '$compile',
  21463. function (uiGridSaveStateConstants, uiGridSaveStateService, gridUtil, $compile) {
  21464. return {
  21465. replace: true,
  21466. priority: 0,
  21467. require: '^uiGrid',
  21468. scope: false,
  21469. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  21470. uiGridSaveStateService.initializeGrid(uiGridCtrl.grid);
  21471. }
  21472. };
  21473. }
  21474. ]);
  21475. })();
  21476. (function () {
  21477. 'use strict';
  21478. /**
  21479. * @ngdoc overview
  21480. * @name ui.grid.selection
  21481. * @description
  21482. *
  21483. * # ui.grid.selection
  21484. * This module provides row selection
  21485. *
  21486. * <div class="alert alert-success" role="alert"><strong>Stable</strong> This feature is stable. There should no longer be breaking api changes without a deprecation warning.</div>
  21487. *
  21488. * <div doc-module-components="ui.grid.selection"></div>
  21489. */
  21490. var module = angular.module('ui.grid.selection', ['ui.grid']);
  21491. /**
  21492. * @ngdoc object
  21493. * @name ui.grid.selection.constant:uiGridSelectionConstants
  21494. *
  21495. * @description constants available in selection module
  21496. */
  21497. module.constant('uiGridSelectionConstants', {
  21498. featureName: "selection",
  21499. selectionRowHeaderColName: 'selectionRowHeaderCol'
  21500. });
  21501. //add methods to GridRow
  21502. angular.module('ui.grid').config(['$provide', function($provide) {
  21503. $provide.decorator('GridRow', ['$delegate', function($delegate) {
  21504. /**
  21505. * @ngdoc object
  21506. * @name ui.grid.selection.api:GridRow
  21507. *
  21508. * @description GridRow prototype functions added for selection
  21509. */
  21510. /**
  21511. * @ngdoc object
  21512. * @name enableSelection
  21513. * @propertyOf ui.grid.selection.api:GridRow
  21514. * @description Enable row selection for this row, only settable by internal code.
  21515. *
  21516. * The grouping feature, for example, might set group header rows to not be selectable.
  21517. * <br/>Defaults to true
  21518. */
  21519. /**
  21520. * @ngdoc object
  21521. * @name isSelected
  21522. * @propertyOf ui.grid.selection.api:GridRow
  21523. * @description Selected state of row. Should be readonly. Make any changes to selected state using setSelected().
  21524. * <br/>Defaults to false
  21525. */
  21526. /**
  21527. * @ngdoc function
  21528. * @name setSelected
  21529. * @methodOf ui.grid.selection.api:GridRow
  21530. * @description Sets the isSelected property and updates the selectedCount
  21531. * Changes to isSelected state should only be made via this function
  21532. * @param {bool} selected value to set
  21533. */
  21534. $delegate.prototype.setSelected = function(selected) {
  21535. this.isSelected = selected;
  21536. if (selected) {
  21537. this.grid.selection.selectedCount++;
  21538. }
  21539. else {
  21540. this.grid.selection.selectedCount--;
  21541. }
  21542. };
  21543. return $delegate;
  21544. }]);
  21545. }]);
  21546. /**
  21547. * @ngdoc service
  21548. * @name ui.grid.selection.service:uiGridSelectionService
  21549. *
  21550. * @description Services for selection features
  21551. */
  21552. module.service('uiGridSelectionService', ['$q', '$templateCache', 'uiGridSelectionConstants', 'gridUtil',
  21553. function ($q, $templateCache, uiGridSelectionConstants, gridUtil) {
  21554. var service = {
  21555. initializeGrid: function (grid) {
  21556. //add feature namespace and any properties to grid for needed
  21557. /**
  21558. * @ngdoc object
  21559. * @name ui.grid.selection.grid:selection
  21560. *
  21561. * @description Grid properties and functions added for selection
  21562. */
  21563. grid.selection = {};
  21564. grid.selection.lastSelectedRow = null;
  21565. grid.selection.selectAll = false;
  21566. /**
  21567. * @ngdoc object
  21568. * @name selectedCount
  21569. * @propertyOf ui.grid.selection.grid:selection
  21570. * @description Current count of selected rows
  21571. * @example
  21572. * var count = grid.selection.selectedCount
  21573. */
  21574. grid.selection.selectedCount = 0;
  21575. service.defaultGridOptions(grid.options);
  21576. /**
  21577. * @ngdoc object
  21578. * @name ui.grid.selection.api:PublicApi
  21579. *
  21580. * @description Public Api for selection feature
  21581. */
  21582. var publicApi = {
  21583. events: {
  21584. selection: {
  21585. /**
  21586. * @ngdoc event
  21587. * @name rowSelectionChanged
  21588. * @eventOf ui.grid.selection.api:PublicApi
  21589. * @description is raised after the row.isSelected state is changed
  21590. * @param {GridRow} row the row that was selected/deselected
  21591. * @param {Event} event object if raised from an event
  21592. */
  21593. rowSelectionChanged: function (scope, row, evt) {
  21594. },
  21595. /**
  21596. * @ngdoc event
  21597. * @name rowSelectionChangedBatch
  21598. * @eventOf ui.grid.selection.api:PublicApi
  21599. * @description is raised after the row.isSelected state is changed
  21600. * in bulk, if the `enableSelectionBatchEvent` option is set to true
  21601. * (which it is by default). This allows more efficient processing
  21602. * of bulk events.
  21603. * @param {array} rows the rows that were selected/deselected
  21604. * @param {Event} event object if raised from an event
  21605. */
  21606. rowSelectionChangedBatch: function (scope, rows, evt) {
  21607. }
  21608. }
  21609. },
  21610. methods: {
  21611. selection: {
  21612. /**
  21613. * @ngdoc function
  21614. * @name toggleRowSelection
  21615. * @methodOf ui.grid.selection.api:PublicApi
  21616. * @description Toggles data row as selected or unselected
  21617. * @param {object} rowEntity gridOptions.data[] array instance
  21618. * @param {Event} event object if raised from an event
  21619. */
  21620. toggleRowSelection: function (rowEntity, evt) {
  21621. var row = grid.getRow(rowEntity);
  21622. if (row !== null) {
  21623. service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect);
  21624. }
  21625. },
  21626. /**
  21627. * @ngdoc function
  21628. * @name selectRow
  21629. * @methodOf ui.grid.selection.api:PublicApi
  21630. * @description Select the data row
  21631. * @param {object} rowEntity gridOptions.data[] array instance
  21632. * @param {Event} event object if raised from an event
  21633. */
  21634. selectRow: function (rowEntity, evt) {
  21635. var row = grid.getRow(rowEntity);
  21636. if (row !== null && !row.isSelected) {
  21637. service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect);
  21638. }
  21639. },
  21640. /**
  21641. * @ngdoc function
  21642. * @name selectRowByVisibleIndex
  21643. * @methodOf ui.grid.selection.api:PublicApi
  21644. * @description Select the specified row by visible index (i.e. if you
  21645. * specify row 0 you'll get the first visible row selected). In this context
  21646. * visible means of those rows that are theoretically visible (i.e. not filtered),
  21647. * rather than rows currently rendered on the screen.
  21648. * @param {number} index index within the rowsVisible array
  21649. * @param {Event} event object if raised from an event
  21650. */
  21651. selectRowByVisibleIndex: function ( rowNum, evt ) {
  21652. var row = grid.renderContainers.body.visibleRowCache[rowNum];
  21653. if (row !== null && typeof(row) !== 'undefined' && !row.isSelected) {
  21654. service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect);
  21655. }
  21656. },
  21657. /**
  21658. * @ngdoc function
  21659. * @name unSelectRow
  21660. * @methodOf ui.grid.selection.api:PublicApi
  21661. * @description UnSelect the data row
  21662. * @param {object} rowEntity gridOptions.data[] array instance
  21663. * @param {Event} event object if raised from an event
  21664. */
  21665. unSelectRow: function (rowEntity, evt) {
  21666. var row = grid.getRow(rowEntity);
  21667. if (row !== null && row.isSelected) {
  21668. service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect);
  21669. }
  21670. },
  21671. /**
  21672. * @ngdoc function
  21673. * @name selectAllRows
  21674. * @methodOf ui.grid.selection.api:PublicApi
  21675. * @description Selects all rows. Does nothing if multiSelect = false
  21676. * @param {Event} event object if raised from an event
  21677. */
  21678. selectAllRows: function (evt) {
  21679. if (grid.options.multiSelect === false) {
  21680. return;
  21681. }
  21682. var changedRows = [];
  21683. grid.rows.forEach(function (row) {
  21684. if ( !row.isSelected && row.enableSelection !== false ){
  21685. row.setSelected(true);
  21686. service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
  21687. }
  21688. });
  21689. service.decideRaiseSelectionBatchEvent( grid, changedRows, evt );
  21690. grid.selection.selectAll = true;
  21691. },
  21692. /**
  21693. * @ngdoc function
  21694. * @name selectAllVisibleRows
  21695. * @methodOf ui.grid.selection.api:PublicApi
  21696. * @description Selects all visible rows. Does nothing if multiSelect = false
  21697. * @param {Event} event object if raised from an event
  21698. */
  21699. selectAllVisibleRows: function (evt) {
  21700. if (grid.options.multiSelect === false) {
  21701. return;
  21702. }
  21703. var changedRows = [];
  21704. grid.rows.forEach(function (row) {
  21705. if (row.visible) {
  21706. if (!row.isSelected && row.enableSelection !== false){
  21707. row.setSelected(true);
  21708. service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
  21709. }
  21710. } else {
  21711. if (row.isSelected){
  21712. row.setSelected(false);
  21713. service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
  21714. }
  21715. }
  21716. });
  21717. service.decideRaiseSelectionBatchEvent( grid, changedRows, evt );
  21718. grid.selection.selectAll = true;
  21719. },
  21720. /**
  21721. * @ngdoc function
  21722. * @name clearSelectedRows
  21723. * @methodOf ui.grid.selection.api:PublicApi
  21724. * @description Unselects all rows
  21725. * @param {Event} event object if raised from an event
  21726. */
  21727. clearSelectedRows: function (evt) {
  21728. service.clearSelectedRows(grid, evt);
  21729. },
  21730. /**
  21731. * @ngdoc function
  21732. * @name getSelectedRows
  21733. * @methodOf ui.grid.selection.api:PublicApi
  21734. * @description returns all selectedRow's entity references
  21735. */
  21736. getSelectedRows: function () {
  21737. return service.getSelectedRows(grid).map(function (gridRow) {
  21738. return gridRow.entity;
  21739. });
  21740. },
  21741. /**
  21742. * @ngdoc function
  21743. * @name getSelectedGridRows
  21744. * @methodOf ui.grid.selection.api:PublicApi
  21745. * @description returns all selectedRow's as gridRows
  21746. */
  21747. getSelectedGridRows: function () {
  21748. return service.getSelectedRows(grid);
  21749. },
  21750. /**
  21751. * @ngdoc function
  21752. * @name getSelectedCount
  21753. * @methodOf ui.grid.selection.api:PublicApi
  21754. * @description returns the number of rows selected
  21755. */
  21756. getSelectedCount: function () {
  21757. return grid.selection.selectedCount;
  21758. },
  21759. /**
  21760. * @ngdoc function
  21761. * @name setMultiSelect
  21762. * @methodOf ui.grid.selection.api:PublicApi
  21763. * @description Sets the current gridOption.multiSelect to true or false
  21764. * @param {bool} multiSelect true to allow multiple rows
  21765. */
  21766. setMultiSelect: function (multiSelect) {
  21767. grid.options.multiSelect = multiSelect;
  21768. },
  21769. /**
  21770. * @ngdoc function
  21771. * @name setModifierKeysToMultiSelect
  21772. * @methodOf ui.grid.selection.api:PublicApi
  21773. * @description Sets the current gridOption.modifierKeysToMultiSelect to true or false
  21774. * @param {bool} modifierKeysToMultiSelect true to only allow multiple rows when using ctrlKey or shiftKey is used
  21775. */
  21776. setModifierKeysToMultiSelect: function (modifierKeysToMultiSelect) {
  21777. grid.options.modifierKeysToMultiSelect = modifierKeysToMultiSelect;
  21778. },
  21779. /**
  21780. * @ngdoc function
  21781. * @name getSelectAllState
  21782. * @methodOf ui.grid.selection.api:PublicApi
  21783. * @description Returns whether or not the selectAll checkbox is currently ticked. The
  21784. * grid doesn't automatically select rows when you add extra data - so when you add data
  21785. * you need to explicitly check whether the selectAll is set, and then call setVisible rows
  21786. * if it is
  21787. */
  21788. getSelectAllState: function () {
  21789. return grid.selection.selectAll;
  21790. }
  21791. }
  21792. }
  21793. };
  21794. grid.api.registerEventsFromObject(publicApi.events);
  21795. grid.api.registerMethodsFromObject(publicApi.methods);
  21796. },
  21797. defaultGridOptions: function (gridOptions) {
  21798. //default option to true unless it was explicitly set to false
  21799. /**
  21800. * @ngdoc object
  21801. * @name ui.grid.selection.api:GridOptions
  21802. *
  21803. * @description GridOptions for selection feature, these are available to be
  21804. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  21805. */
  21806. /**
  21807. * @ngdoc object
  21808. * @name enableRowSelection
  21809. * @propertyOf ui.grid.selection.api:GridOptions
  21810. * @description Enable row selection for entire grid.
  21811. * <br/>Defaults to true
  21812. */
  21813. gridOptions.enableRowSelection = gridOptions.enableRowSelection !== false;
  21814. /**
  21815. * @ngdoc object
  21816. * @name multiSelect
  21817. * @propertyOf ui.grid.selection.api:GridOptions
  21818. * @description Enable multiple row selection for entire grid
  21819. * <br/>Defaults to true
  21820. */
  21821. gridOptions.multiSelect = gridOptions.multiSelect !== false;
  21822. /**
  21823. * @ngdoc object
  21824. * @name noUnselect
  21825. * @propertyOf ui.grid.selection.api:GridOptions
  21826. * @description Prevent a row from being unselected. Works in conjunction
  21827. * with `multiselect = false` and `gridApi.selection.selectRow()` to allow
  21828. * you to create a single selection only grid - a row is always selected, you
  21829. * can only select different rows, you can't unselect the row.
  21830. * <br/>Defaults to false
  21831. */
  21832. gridOptions.noUnselect = gridOptions.noUnselect === true;
  21833. /**
  21834. * @ngdoc object
  21835. * @name modifierKeysToMultiSelect
  21836. * @propertyOf ui.grid.selection.api:GridOptions
  21837. * @description Enable multiple row selection only when using the ctrlKey or shiftKey. Requires multiSelect to be true.
  21838. * <br/>Defaults to false
  21839. */
  21840. gridOptions.modifierKeysToMultiSelect = gridOptions.modifierKeysToMultiSelect === true;
  21841. /**
  21842. * @ngdoc object
  21843. * @name enableRowHeaderSelection
  21844. * @propertyOf ui.grid.selection.api:GridOptions
  21845. * @description Enable a row header to be used for selection
  21846. * <br/>Defaults to true
  21847. */
  21848. gridOptions.enableRowHeaderSelection = gridOptions.enableRowHeaderSelection !== false;
  21849. /**
  21850. * @ngdoc object
  21851. * @name enableFullRowSelection
  21852. * @propertyOf ui.grid.selection.api:GridOptions
  21853. * @description Enable selection by clicking anywhere on the row. Defaults to
  21854. * false if `enableRowHeaderSelection` is true, otherwise defaults to false.
  21855. */
  21856. if ( typeof(gridOptions.enableFullRowSelection) === 'undefined' ){
  21857. gridOptions.enableFullRowSelection = !gridOptions.enableRowHeaderSelection;
  21858. }
  21859. /**
  21860. * @ngdoc object
  21861. * @name enableSelectAll
  21862. * @propertyOf ui.grid.selection.api:GridOptions
  21863. * @description Enable the select all checkbox at the top of the selectionRowHeader
  21864. * <br/>Defaults to true
  21865. */
  21866. gridOptions.enableSelectAll = gridOptions.enableSelectAll !== false;
  21867. /**
  21868. * @ngdoc object
  21869. * @name enableSelectionBatchEvent
  21870. * @propertyOf ui.grid.selection.api:GridOptions
  21871. * @description If selected rows are changed in bulk, either via the API or
  21872. * via the selectAll checkbox, then a separate event is fired. Setting this
  21873. * option to false will cause the rowSelectionChanged event to be called multiple times
  21874. * instead
  21875. * <br/>Defaults to true
  21876. */
  21877. gridOptions.enableSelectionBatchEvent = gridOptions.enableSelectionBatchEvent !== false;
  21878. /**
  21879. * @ngdoc object
  21880. * @name selectionRowHeaderWidth
  21881. * @propertyOf ui.grid.selection.api:GridOptions
  21882. * @description can be used to set a custom width for the row header selection column
  21883. * <br/>Defaults to 30px
  21884. */
  21885. gridOptions.selectionRowHeaderWidth = angular.isDefined(gridOptions.selectionRowHeaderWidth) ? gridOptions.selectionRowHeaderWidth : 30;
  21886. /**
  21887. * @ngdoc object
  21888. * @name enableFooterTotalSelected
  21889. * @propertyOf ui.grid.selection.api:GridOptions
  21890. * @description Shows the total number of selected items in footer if true.
  21891. * <br/>Defaults to true.
  21892. * <br/>GridOptions.showGridFooter must also be set to true.
  21893. */
  21894. gridOptions.enableFooterTotalSelected = gridOptions.enableFooterTotalSelected !== false;
  21895. /**
  21896. * @ngdoc object
  21897. * @name isRowSelectable
  21898. * @propertyOf ui.grid.selection.api:GridOptions
  21899. * @description Makes it possible to specify a method that evaluates for each row and sets its "enableSelection" property.
  21900. */
  21901. gridOptions.isRowSelectable = angular.isDefined(gridOptions.isRowSelectable) ? gridOptions.isRowSelectable : angular.noop;
  21902. },
  21903. /**
  21904. * @ngdoc function
  21905. * @name toggleRowSelection
  21906. * @methodOf ui.grid.selection.service:uiGridSelectionService
  21907. * @description Toggles row as selected or unselected
  21908. * @param {Grid} grid grid object
  21909. * @param {GridRow} row row to select or deselect
  21910. * @param {Event} event object if resulting from event
  21911. * @param {bool} multiSelect if false, only one row at time can be selected
  21912. * @param {bool} noUnselect if true then rows cannot be unselected
  21913. */
  21914. toggleRowSelection: function (grid, row, evt, multiSelect, noUnselect) {
  21915. var selected = row.isSelected;
  21916. if ( row.enableSelection === false && !selected ){
  21917. return;
  21918. }
  21919. var selectedRows;
  21920. if (!multiSelect && !selected) {
  21921. service.clearSelectedRows(grid, evt);
  21922. } else if (!multiSelect && selected) {
  21923. selectedRows = service.getSelectedRows(grid);
  21924. if (selectedRows.length > 1) {
  21925. selected = false; // Enable reselect of the row
  21926. service.clearSelectedRows(grid, evt);
  21927. }
  21928. }
  21929. if (selected && noUnselect){
  21930. // don't deselect the row
  21931. } else {
  21932. row.setSelected(!selected);
  21933. if (row.isSelected === true) {
  21934. grid.selection.lastSelectedRow = row;
  21935. }
  21936. selectedRows = service.getSelectedRows(grid);
  21937. grid.selection.selectAll = grid.rows.length === selectedRows.length;
  21938. grid.api.selection.raise.rowSelectionChanged(row, evt);
  21939. }
  21940. },
  21941. /**
  21942. * @ngdoc function
  21943. * @name shiftSelect
  21944. * @methodOf ui.grid.selection.service:uiGridSelectionService
  21945. * @description selects a group of rows from the last selected row using the shift key
  21946. * @param {Grid} grid grid object
  21947. * @param {GridRow} clicked row
  21948. * @param {Event} event object if raised from an event
  21949. * @param {bool} multiSelect if false, does nothing this is for multiSelect only
  21950. */
  21951. shiftSelect: function (grid, row, evt, multiSelect) {
  21952. if (!multiSelect) {
  21953. return;
  21954. }
  21955. var selectedRows = service.getSelectedRows(grid);
  21956. var fromRow = selectedRows.length > 0 ? grid.renderContainers.body.visibleRowCache.indexOf(grid.selection.lastSelectedRow) : 0;
  21957. var toRow = grid.renderContainers.body.visibleRowCache.indexOf(row);
  21958. //reverse select direction
  21959. if (fromRow > toRow) {
  21960. var tmp = fromRow;
  21961. fromRow = toRow;
  21962. toRow = tmp;
  21963. }
  21964. var changedRows = [];
  21965. for (var i = fromRow; i <= toRow; i++) {
  21966. var rowToSelect = grid.renderContainers.body.visibleRowCache[i];
  21967. if (rowToSelect) {
  21968. if ( !rowToSelect.isSelected && rowToSelect.enableSelection !== false ){
  21969. rowToSelect.setSelected(true);
  21970. grid.selection.lastSelectedRow = rowToSelect;
  21971. service.decideRaiseSelectionEvent( grid, rowToSelect, changedRows, evt );
  21972. }
  21973. }
  21974. }
  21975. service.decideRaiseSelectionBatchEvent( grid, changedRows, evt );
  21976. },
  21977. /**
  21978. * @ngdoc function
  21979. * @name getSelectedRows
  21980. * @methodOf ui.grid.selection.service:uiGridSelectionService
  21981. * @description Returns all the selected rows
  21982. * @param {Grid} grid grid object
  21983. */
  21984. getSelectedRows: function (grid) {
  21985. return grid.rows.filter(function (row) {
  21986. return row.isSelected;
  21987. });
  21988. },
  21989. /**
  21990. * @ngdoc function
  21991. * @name clearSelectedRows
  21992. * @methodOf ui.grid.selection.service:uiGridSelectionService
  21993. * @description Clears all selected rows
  21994. * @param {Grid} grid grid object
  21995. * @param {Event} event object if raised from an event
  21996. */
  21997. clearSelectedRows: function (grid, evt) {
  21998. var changedRows = [];
  21999. service.getSelectedRows(grid).forEach(function (row) {
  22000. if ( row.isSelected ){
  22001. row.setSelected(false);
  22002. service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
  22003. }
  22004. });
  22005. service.decideRaiseSelectionBatchEvent( grid, changedRows, evt );
  22006. grid.selection.selectAll = false;
  22007. grid.selection.selectedCount = 0;
  22008. },
  22009. /**
  22010. * @ngdoc function
  22011. * @name decideRaiseSelectionEvent
  22012. * @methodOf ui.grid.selection.service:uiGridSelectionService
  22013. * @description Decides whether to raise a single event or a batch event
  22014. * @param {Grid} grid grid object
  22015. * @param {GridRow} row row that has changed
  22016. * @param {array} changedRows an array to which we can append the changed
  22017. * @param {Event} event object if raised from an event
  22018. * row if we're doing batch events
  22019. */
  22020. decideRaiseSelectionEvent: function( grid, row, changedRows, evt ){
  22021. if ( !grid.options.enableSelectionBatchEvent ){
  22022. grid.api.selection.raise.rowSelectionChanged(row, evt);
  22023. } else {
  22024. changedRows.push(row);
  22025. }
  22026. },
  22027. /**
  22028. * @ngdoc function
  22029. * @name raiseSelectionEvent
  22030. * @methodOf ui.grid.selection.service:uiGridSelectionService
  22031. * @description Decides whether we need to raise a batch event, and
  22032. * raises it if we do.
  22033. * @param {Grid} grid grid object
  22034. * @param {array} changedRows an array of changed rows, only populated
  22035. * @param {Event} event object if raised from an event
  22036. * if we're doing batch events
  22037. */
  22038. decideRaiseSelectionBatchEvent: function( grid, changedRows, evt ){
  22039. if ( changedRows.length > 0 ){
  22040. grid.api.selection.raise.rowSelectionChangedBatch(changedRows, evt);
  22041. }
  22042. }
  22043. };
  22044. return service;
  22045. }]);
  22046. /**
  22047. * @ngdoc directive
  22048. * @name ui.grid.selection.directive:uiGridSelection
  22049. * @element div
  22050. * @restrict A
  22051. *
  22052. * @description Adds selection features to grid
  22053. *
  22054. * @example
  22055. <example module="app">
  22056. <file name="app.js">
  22057. var app = angular.module('app', ['ui.grid', 'ui.grid.selection']);
  22058. app.controller('MainCtrl', ['$scope', function ($scope) {
  22059. $scope.data = [
  22060. { name: 'Bob', title: 'CEO' },
  22061. { name: 'Frank', title: 'Lowly Developer' }
  22062. ];
  22063. $scope.columnDefs = [
  22064. {name: 'name', enableCellEdit: true},
  22065. {name: 'title', enableCellEdit: true}
  22066. ];
  22067. }]);
  22068. </file>
  22069. <file name="index.html">
  22070. <div ng-controller="MainCtrl">
  22071. <div ui-grid="{ data: data, columnDefs: columnDefs }" ui-grid-selection></div>
  22072. </div>
  22073. </file>
  22074. </example>
  22075. */
  22076. module.directive('uiGridSelection', ['uiGridSelectionConstants', 'uiGridSelectionService', '$templateCache', 'uiGridConstants',
  22077. function (uiGridSelectionConstants, uiGridSelectionService, $templateCache, uiGridConstants) {
  22078. return {
  22079. replace: true,
  22080. priority: 0,
  22081. require: '^uiGrid',
  22082. scope: false,
  22083. compile: function () {
  22084. return {
  22085. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  22086. uiGridSelectionService.initializeGrid(uiGridCtrl.grid);
  22087. if (uiGridCtrl.grid.options.enableRowHeaderSelection) {
  22088. var selectionRowHeaderDef = {
  22089. name: uiGridSelectionConstants.selectionRowHeaderColName,
  22090. displayName: '',
  22091. width: uiGridCtrl.grid.options.selectionRowHeaderWidth,
  22092. minWidth: 10,
  22093. cellTemplate: 'ui-grid/selectionRowHeader',
  22094. headerCellTemplate: 'ui-grid/selectionHeaderCell',
  22095. enableColumnResizing: false,
  22096. enableColumnMenu: false,
  22097. exporterSuppressExport: true,
  22098. allowCellFocus: true
  22099. };
  22100. uiGridCtrl.grid.addRowHeaderColumn(selectionRowHeaderDef);
  22101. }
  22102. var processorSet = false;
  22103. var processSelectableRows = function( rows ){
  22104. rows.forEach(function(row){
  22105. row.enableSelection = uiGridCtrl.grid.options.isRowSelectable(row);
  22106. });
  22107. return rows;
  22108. };
  22109. var updateOptions = function(){
  22110. if (uiGridCtrl.grid.options.isRowSelectable !== angular.noop && processorSet !== true) {
  22111. uiGridCtrl.grid.registerRowsProcessor(processSelectableRows, 500);
  22112. processorSet = true;
  22113. }
  22114. };
  22115. updateOptions();
  22116. var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback( updateOptions, [uiGridConstants.dataChange.OPTIONS] );
  22117. $scope.$on( '$destroy', dataChangeDereg);
  22118. },
  22119. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  22120. }
  22121. };
  22122. }
  22123. };
  22124. }]);
  22125. module.directive('uiGridSelectionRowHeaderButtons', ['$templateCache', 'uiGridSelectionService', 'gridUtil',
  22126. function ($templateCache, uiGridSelectionService, gridUtil) {
  22127. return {
  22128. replace: true,
  22129. restrict: 'E',
  22130. template: $templateCache.get('ui-grid/selectionRowHeaderButtons'),
  22131. scope: true,
  22132. require: '^uiGrid',
  22133. link: function($scope, $elm, $attrs, uiGridCtrl) {
  22134. var self = uiGridCtrl.grid;
  22135. $scope.selectButtonClick = selectButtonClick;
  22136. // On IE, prevent mousedowns on the select button from starting a selection.
  22137. // If this is not done and you shift+click on another row, the browser will select a big chunk of text
  22138. if (gridUtil.detectBrowser() === 'ie') {
  22139. $elm.on('mousedown', selectButtonMouseDown);
  22140. }
  22141. function selectButtonClick(row, evt) {
  22142. evt.stopPropagation();
  22143. if (evt.shiftKey) {
  22144. uiGridSelectionService.shiftSelect(self, row, evt, self.options.multiSelect);
  22145. }
  22146. else if (evt.ctrlKey || evt.metaKey) {
  22147. uiGridSelectionService.toggleRowSelection(self, row, evt, self.options.multiSelect, self.options.noUnselect);
  22148. }
  22149. else {
  22150. uiGridSelectionService.toggleRowSelection(self, row, evt, (self.options.multiSelect && !self.options.modifierKeysToMultiSelect), self.options.noUnselect);
  22151. }
  22152. }
  22153. function selectButtonMouseDown(evt) {
  22154. if (evt.ctrlKey || evt.shiftKey) {
  22155. evt.target.onselectstart = function () { return false; };
  22156. window.setTimeout(function () { evt.target.onselectstart = null; }, 0);
  22157. }
  22158. }
  22159. }
  22160. };
  22161. }]);
  22162. module.directive('uiGridSelectionSelectAllButtons', ['$templateCache', 'uiGridSelectionService',
  22163. function ($templateCache, uiGridSelectionService) {
  22164. return {
  22165. replace: true,
  22166. restrict: 'E',
  22167. template: $templateCache.get('ui-grid/selectionSelectAllButtons'),
  22168. scope: false,
  22169. link: function($scope, $elm, $attrs, uiGridCtrl) {
  22170. var self = $scope.col.grid;
  22171. $scope.headerButtonClick = function(row, evt) {
  22172. if ( self.selection.selectAll ){
  22173. uiGridSelectionService.clearSelectedRows(self, evt);
  22174. if ( self.options.noUnselect ){
  22175. self.api.selection.selectRowByVisibleIndex(0, evt);
  22176. }
  22177. self.selection.selectAll = false;
  22178. } else {
  22179. if ( self.options.multiSelect ){
  22180. self.api.selection.selectAllVisibleRows(evt);
  22181. self.selection.selectAll = true;
  22182. }
  22183. }
  22184. };
  22185. }
  22186. };
  22187. }]);
  22188. /**
  22189. * @ngdoc directive
  22190. * @name ui.grid.selection.directive:uiGridViewport
  22191. * @element div
  22192. *
  22193. * @description Stacks on top of ui.grid.uiGridViewport to alter the attributes used
  22194. * for the grid row
  22195. */
  22196. module.directive('uiGridViewport',
  22197. ['$compile', 'uiGridConstants', 'uiGridSelectionConstants', 'gridUtil', '$parse', 'uiGridSelectionService',
  22198. function ($compile, uiGridConstants, uiGridSelectionConstants, gridUtil, $parse, uiGridSelectionService) {
  22199. return {
  22200. priority: -200, // run after default directive
  22201. scope: false,
  22202. compile: function ($elm, $attrs) {
  22203. var rowRepeatDiv = angular.element($elm.children().children()[0]);
  22204. var existingNgClass = rowRepeatDiv.attr("ng-class");
  22205. var newNgClass = '';
  22206. if ( existingNgClass ) {
  22207. newNgClass = existingNgClass.slice(0, -1) + ",'ui-grid-row-selected': row.isSelected}";
  22208. } else {
  22209. newNgClass = "{'ui-grid-row-selected': row.isSelected}";
  22210. }
  22211. rowRepeatDiv.attr("ng-class", newNgClass);
  22212. return {
  22213. pre: function ($scope, $elm, $attrs, controllers) {
  22214. },
  22215. post: function ($scope, $elm, $attrs, controllers) {
  22216. }
  22217. };
  22218. }
  22219. };
  22220. }]);
  22221. /**
  22222. * @ngdoc directive
  22223. * @name ui.grid.selection.directive:uiGridCell
  22224. * @element div
  22225. * @restrict A
  22226. *
  22227. * @description Stacks on top of ui.grid.uiGridCell to provide selection feature
  22228. */
  22229. module.directive('uiGridCell',
  22230. ['$compile', 'uiGridConstants', 'uiGridSelectionConstants', 'gridUtil', '$parse', 'uiGridSelectionService', '$timeout',
  22231. function ($compile, uiGridConstants, uiGridSelectionConstants, gridUtil, $parse, uiGridSelectionService, $timeout) {
  22232. return {
  22233. priority: -200, // run after default uiGridCell directive
  22234. restrict: 'A',
  22235. require: '?^uiGrid',
  22236. scope: false,
  22237. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  22238. var touchStartTime = 0;
  22239. var touchTimeout = 300;
  22240. // Bind to keydown events in the render container
  22241. if (uiGridCtrl.grid.api.cellNav) {
  22242. uiGridCtrl.grid.api.cellNav.on.viewPortKeyDown($scope, function (evt, rowCol) {
  22243. if (rowCol === null ||
  22244. rowCol.row !== $scope.row ||
  22245. rowCol.col !== $scope.col) {
  22246. return;
  22247. }
  22248. if (evt.keyCode === 32 && $scope.col.colDef.name === "selectionRowHeaderCol") {
  22249. uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, ($scope.grid.options.multiSelect && !$scope.grid.options.modifierKeysToMultiSelect), $scope.grid.options.noUnselect);
  22250. $scope.$apply();
  22251. }
  22252. // uiGridCellNavService.scrollToIfNecessary(uiGridCtrl.grid, rowCol.row, rowCol.col);
  22253. });
  22254. }
  22255. //$elm.bind('keydown', function (evt) {
  22256. // if (evt.keyCode === 32 && $scope.col.colDef.name === "selectionRowHeaderCol") {
  22257. // uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, ($scope.grid.options.multiSelect && !$scope.grid.options.modifierKeysToMultiSelect), $scope.grid.options.noUnselect);
  22258. // $scope.$apply();
  22259. // }
  22260. //});
  22261. var selectCells = function(evt){
  22262. // if we get a click, then stop listening for touchend
  22263. $elm.off('touchend', touchEnd);
  22264. if (evt.shiftKey) {
  22265. uiGridSelectionService.shiftSelect($scope.grid, $scope.row, evt, $scope.grid.options.multiSelect);
  22266. }
  22267. else if (evt.ctrlKey || evt.metaKey) {
  22268. uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, $scope.grid.options.multiSelect, $scope.grid.options.noUnselect);
  22269. }
  22270. else {
  22271. uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, ($scope.grid.options.multiSelect && !$scope.grid.options.modifierKeysToMultiSelect), $scope.grid.options.noUnselect);
  22272. }
  22273. $scope.$apply();
  22274. // don't re-enable the touchend handler for a little while - some devices generate both, and it will
  22275. // take a little while to move your hand from the mouse to the screen if you have both modes of input
  22276. $timeout(function() {
  22277. $elm.on('touchend', touchEnd);
  22278. }, touchTimeout);
  22279. };
  22280. var touchStart = function(evt){
  22281. touchStartTime = (new Date()).getTime();
  22282. // if we get a touch event, then stop listening for click
  22283. $elm.off('click', selectCells);
  22284. };
  22285. var touchEnd = function(evt) {
  22286. var touchEndTime = (new Date()).getTime();
  22287. var touchTime = touchEndTime - touchStartTime;
  22288. if (touchTime < touchTimeout ) {
  22289. // short touch
  22290. selectCells(evt);
  22291. }
  22292. // don't re-enable the click handler for a little while - some devices generate both, and it will
  22293. // take a little while to move your hand from the screen to the mouse if you have both modes of input
  22294. $timeout(function() {
  22295. $elm.on('click', selectCells);
  22296. }, touchTimeout);
  22297. };
  22298. function registerRowSelectionEvents() {
  22299. if ($scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection) {
  22300. $elm.addClass('ui-grid-disable-selection');
  22301. $elm.on('touchstart', touchStart);
  22302. $elm.on('touchend', touchEnd);
  22303. $elm.on('click', selectCells);
  22304. $scope.registered = true;
  22305. }
  22306. }
  22307. function deregisterRowSelectionEvents() {
  22308. if ($scope.registered){
  22309. $elm.removeClass('ui-grid-disable-selection');
  22310. $elm.off('touchstart', touchStart);
  22311. $elm.off('touchend', touchEnd);
  22312. $elm.off('click', selectCells);
  22313. $scope.registered = false;
  22314. }
  22315. }
  22316. registerRowSelectionEvents();
  22317. // register a dataChange callback so that we can change the selection configuration dynamically
  22318. // if the user changes the options
  22319. var dataChangeDereg = $scope.grid.registerDataChangeCallback( function() {
  22320. if ( $scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection &&
  22321. !$scope.registered ){
  22322. registerRowSelectionEvents();
  22323. } else if ( ( !$scope.grid.options.enableRowSelection || !$scope.grid.options.enableFullRowSelection ) &&
  22324. $scope.registered ){
  22325. deregisterRowSelectionEvents();
  22326. }
  22327. }, [uiGridConstants.dataChange.OPTIONS] );
  22328. $elm.on( '$destroy', dataChangeDereg);
  22329. }
  22330. };
  22331. }]);
  22332. module.directive('uiGridGridFooter', ['$compile', 'uiGridConstants', 'gridUtil', function ($compile, uiGridConstants, gridUtil) {
  22333. return {
  22334. restrict: 'EA',
  22335. replace: true,
  22336. priority: -1000,
  22337. require: '^uiGrid',
  22338. scope: true,
  22339. compile: function ($elm, $attrs) {
  22340. return {
  22341. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  22342. if (!uiGridCtrl.grid.options.showGridFooter) {
  22343. return;
  22344. }
  22345. gridUtil.getTemplate('ui-grid/gridFooterSelectedItems')
  22346. .then(function (contents) {
  22347. var template = angular.element(contents);
  22348. var newElm = $compile(template)($scope);
  22349. angular.element($elm[0].getElementsByClassName('ui-grid-grid-footer')[0]).append(newElm);
  22350. });
  22351. },
  22352. post: function ($scope, $elm, $attrs, controllers) {
  22353. }
  22354. };
  22355. }
  22356. };
  22357. }]);
  22358. })();
  22359. (function () {
  22360. 'use strict';
  22361. /**
  22362. * @ngdoc overview
  22363. * @name ui.grid.treeBase
  22364. * @description
  22365. *
  22366. * # ui.grid.treeBase
  22367. *
  22368. * <div class="alert alert-warning" role="alert"><strong>Beta</strong> This feature is ready for testing, but it either hasn't seen a lot of use or has some known bugs.</div>
  22369. *
  22370. * This module provides base tree handling functions that are shared by other features, notably grouping
  22371. * and treeView. It provides a tree view of the data, with nodes in that
  22372. * tree and leaves.
  22373. *
  22374. * Design information:
  22375. * -------------------
  22376. *
  22377. * The raw data that is provided must come with a $$treeLevel on any non-leaf node. Grouping will create
  22378. * these on all the group header rows, treeView will expect these to be set in the raw data by the user.
  22379. * TreeBase will run a rowsProcessor that:
  22380. * - builds `treeBase.tree` out of the provided rows
  22381. * - permits a recursive sort of the tree
  22382. * - maintains the expand/collapse state of each node
  22383. * - provides the expand/collapse all button and the expand/collapse buttons
  22384. * - maintains the count of children for each node
  22385. *
  22386. * Each row is updated with a link to the tree node that represents it. Refer {@link ui.grid.treeBase.grid:treeBase.tree tree documentation}
  22387. * for information.
  22388. *
  22389. * TreeBase adds information to the rows
  22390. * - treeLevel: if present and > -1 tells us the level (level 0 is the top level)
  22391. * - treeNode: pointer to the node in the grid.treeBase.tree that refers
  22392. * to this row, allowing us to manipulate the state
  22393. *
  22394. * Since the logic is baked into the rowsProcessors, it should get triggered whenever
  22395. * row order or filtering or anything like that is changed. We recall the expanded state
  22396. * across invocations of the rowsProcessors by the reference to the treeNode on the individual
  22397. * rows. We rebuild the tree itself quite frequently, when we do this we use the saved treeNodes to
  22398. * get the state, but we overwrite the other data in that treeNode.
  22399. *
  22400. * By default rows are collapsed, which means all data rows have their visible property
  22401. * set to false, and only level 0 group rows are set to visible.
  22402. *
  22403. * We rely on the rowsProcessors to do the actual expanding and collapsing, so we set the flags we want into
  22404. * grid.treeBase.tree, then call refresh. This is because we can't easily change the visible
  22405. * row cache without calling the processors, and once we've built the logic into the rowProcessors we may as
  22406. * well use it all the time.
  22407. *
  22408. * Tree base provides sorting (on non-grouped columns).
  22409. *
  22410. * Sorting works in two passes. The standard sorting is performed for any columns that are important to building
  22411. * the tree (for example, any grouped columns). Then after the tree is built, a recursive tree sort is performed
  22412. * for the remaining sort columns (including the original sort) - these columns are sorted within each tree level
  22413. * (so all the level 1 nodes are sorted, then all the level 2 nodes within each level 1 node etc).
  22414. *
  22415. * To achieve this we make use of the `ignoreSort` property on the sort configuration. The parent feature (treeView or grouping)
  22416. * must provide a rowsProcessor that runs with very low priority (typically in the 60-65 range), and that sets
  22417. * the `ignoreSort`on any sort that it wants to run on the tree. TreeBase will clear the ignoreSort on all sorts - so it
  22418. * will turn on any sorts that haven't run. It will then call a recursive sort on the tree.
  22419. *
  22420. * Tree base provides treeAggregation. It checks the treeAggregation configuration on each column, and aggregates based on
  22421. * the logic provided as it builds the tree. Footer aggregation from the uiGrid core should not be used with treeBase aggregation,
  22422. * since it operates on all visible rows, as opposed to to leaf nodes only. Setting `showColumnFooter: true` will show the
  22423. * treeAggregations in the column footer. Aggregation information will be collected in the format:
  22424. *
  22425. * ```
  22426. * {
  22427. * type: 'count',
  22428. * value: 4,
  22429. * label: 'count: ',
  22430. * rendered: 'count: 4'
  22431. * }
  22432. * ```
  22433. *
  22434. * A callback is provided to format the value once it is finalised (aka a valueFilter).
  22435. *
  22436. * <br/>
  22437. * <br/>
  22438. *
  22439. * <div doc-module-components="ui.grid.treeBase"></div>
  22440. */
  22441. var module = angular.module('ui.grid.treeBase', ['ui.grid']);
  22442. /**
  22443. * @ngdoc object
  22444. * @name ui.grid.treeBase.constant:uiGridTreeBaseConstants
  22445. *
  22446. * @description constants available in treeBase module.
  22447. *
  22448. * These constants are manually copied into grouping and treeView,
  22449. * as I haven't found a way to simply include them, and it's not worth
  22450. * investing time in for something that changes very infrequently.
  22451. *
  22452. */
  22453. module.constant('uiGridTreeBaseConstants', {
  22454. featureName: "treeBase",
  22455. rowHeaderColName: 'treeBaseRowHeaderCol',
  22456. EXPANDED: 'expanded',
  22457. COLLAPSED: 'collapsed',
  22458. aggregation: {
  22459. COUNT: 'count',
  22460. SUM: 'sum',
  22461. MAX: 'max',
  22462. MIN: 'min',
  22463. AVG: 'avg'
  22464. }
  22465. });
  22466. /**
  22467. * @ngdoc service
  22468. * @name ui.grid.treeBase.service:uiGridTreeBaseService
  22469. *
  22470. * @description Services for treeBase feature
  22471. */
  22472. /**
  22473. * @ngdoc object
  22474. * @name ui.grid.treeBase.api:ColumnDef
  22475. *
  22476. * @description ColumnDef for tree feature, these are available to be
  22477. * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs}
  22478. */
  22479. module.service('uiGridTreeBaseService', ['$q', 'uiGridTreeBaseConstants', 'gridUtil', 'GridRow', 'gridClassFactory', 'i18nService', 'uiGridConstants', 'rowSorter',
  22480. function ($q, uiGridTreeBaseConstants, gridUtil, GridRow, gridClassFactory, i18nService, uiGridConstants, rowSorter) {
  22481. var service = {
  22482. initializeGrid: function (grid, $scope) {
  22483. //add feature namespace and any properties to grid for needed
  22484. /**
  22485. * @ngdoc object
  22486. * @name ui.grid.treeBase.grid:treeBase
  22487. *
  22488. * @description Grid properties and functions added for treeBase
  22489. */
  22490. grid.treeBase = {};
  22491. /**
  22492. * @ngdoc property
  22493. * @propertyOf ui.grid.treeBase.grid:treeBase
  22494. * @name numberLevels
  22495. *
  22496. * @description Total number of tree levels currently used, calculated by the rowsProcessor by
  22497. * retaining the highest tree level it sees
  22498. */
  22499. grid.treeBase.numberLevels = 0;
  22500. /**
  22501. * @ngdoc property
  22502. * @propertyOf ui.grid.treeBase.grid:treeBase
  22503. * @name expandAll
  22504. *
  22505. * @description Whether or not the expandAll box is selected
  22506. */
  22507. grid.treeBase.expandAll = false;
  22508. /**
  22509. * @ngdoc property
  22510. * @propertyOf ui.grid.treeBase.grid:treeBase
  22511. * @name tree
  22512. *
  22513. * @description Tree represented as a nested array that holds the state of each node, along with a
  22514. * pointer to the row. The array order is material - we will display the children in the order
  22515. * they are stored in the array
  22516. *
  22517. * Each node stores:
  22518. *
  22519. * - the state of this node
  22520. * - an array of children of this node
  22521. * - a pointer to the parent of this node (reverse pointer, allowing us to walk up the tree)
  22522. * - the number of children of this node
  22523. * - aggregation information calculated from the nodes
  22524. *
  22525. * ```
  22526. * [{
  22527. * state: 'expanded',
  22528. * row: <reference to row>,
  22529. * parentRow: null,
  22530. * aggregations: [{
  22531. * type: 'count',
  22532. * col: <gridCol>,
  22533. * value: 2,
  22534. * label: 'count: ',
  22535. * rendered: 'count: 2'
  22536. * }],
  22537. * children: [
  22538. * {
  22539. * state: 'expanded',
  22540. * row: <reference to row>,
  22541. * parentRow: <reference to row>,
  22542. * aggregations: [{
  22543. * type: 'count',
  22544. * col: '<gridCol>,
  22545. * value: 4,
  22546. * label: 'count: ',
  22547. * rendered: 'count: 4'
  22548. * }],
  22549. * children: [
  22550. * { state: 'expanded', row: <reference to row>, parentRow: <reference to row> },
  22551. * { state: 'collapsed', row: <reference to row>, parentRow: <reference to row> },
  22552. * { state: 'expanded', row: <reference to row>, parentRow: <reference to row> },
  22553. * { state: 'collapsed', row: <reference to row>, parentRow: <reference to row> }
  22554. * ]
  22555. * },
  22556. * {
  22557. * state: 'collapsed',
  22558. * row: <reference to row>,
  22559. * parentRow: <reference to row>,
  22560. * aggregations: [{
  22561. * type: 'count',
  22562. * col: <gridCol>,
  22563. * value: 3,
  22564. * label: 'count: ',
  22565. * rendered: 'count: 3'
  22566. * }],
  22567. * children: [
  22568. * { state: 'expanded', row: <reference to row>, parentRow: <reference to row> },
  22569. * { state: 'collapsed', row: <reference to row>, parentRow: <reference to row> },
  22570. * { state: 'expanded', row: <reference to row>, parentRow: <reference to row> }
  22571. * ]
  22572. * }
  22573. * ]
  22574. * }, {<another level 0 node maybe>} ]
  22575. * ```
  22576. * Missing state values are false - meaning they aren't expanded.
  22577. *
  22578. * This is used because the rowProcessors run every time the grid is refreshed, so
  22579. * we'd lose the expanded state every time the grid was refreshed. This instead gives
  22580. * us a reliable lookup that persists across rowProcessors.
  22581. *
  22582. * This tree is rebuilt every time we run the rowsProcessors. Since each row holds a pointer
  22583. * to it's tree node we can persist expand/collapse state across calls to rowsProcessor, we discard
  22584. * all transient information on the tree (children, childCount) and recalculate it
  22585. *
  22586. */
  22587. grid.treeBase.tree = [];
  22588. service.defaultGridOptions(grid.options);
  22589. grid.registerRowsProcessor(service.treeRows, 410);
  22590. grid.registerColumnBuilder( service.treeBaseColumnBuilder );
  22591. service.createRowHeader( grid );
  22592. /**
  22593. * @ngdoc object
  22594. * @name ui.grid.treeBase.api:PublicApi
  22595. *
  22596. * @description Public Api for treeBase feature
  22597. */
  22598. var publicApi = {
  22599. events: {
  22600. treeBase: {
  22601. /**
  22602. * @ngdoc event
  22603. * @eventOf ui.grid.treeBase.api:PublicApi
  22604. * @name rowExpanded
  22605. * @description raised whenever a row is expanded. If you are dynamically
  22606. * rendering your tree you can listen to this event, and then retrieve
  22607. * the children of this row and load them into the grid data.
  22608. *
  22609. * When the data is loaded the grid will automatically refresh to show these new rows
  22610. *
  22611. * <pre>
  22612. * gridApi.treeBase.on.rowExpanded(scope,function(row){})
  22613. * </pre>
  22614. * @param {gridRow} row the row that was expanded. You can also
  22615. * retrieve the grid from this row with row.grid
  22616. */
  22617. rowExpanded: {},
  22618. /**
  22619. * @ngdoc event
  22620. * @eventOf ui.grid.treeBase.api:PublicApi
  22621. * @name rowCollapsed
  22622. * @description raised whenever a row is collapsed. Doesn't really have
  22623. * a purpose at the moment, included for symmetry
  22624. *
  22625. * <pre>
  22626. * gridApi.treeBase.on.rowCollapsed(scope,function(row){})
  22627. * </pre>
  22628. * @param {gridRow} row the row that was collapsed. You can also
  22629. * retrieve the grid from this row with row.grid
  22630. */
  22631. rowCollapsed: {}
  22632. }
  22633. },
  22634. methods: {
  22635. treeBase: {
  22636. /**
  22637. * @ngdoc function
  22638. * @name expandAllRows
  22639. * @methodOf ui.grid.treeBase.api:PublicApi
  22640. * @description Expands all tree rows
  22641. */
  22642. expandAllRows: function () {
  22643. service.expandAllRows(grid);
  22644. },
  22645. /**
  22646. * @ngdoc function
  22647. * @name collapseAllRows
  22648. * @methodOf ui.grid.treeBase.api:PublicApi
  22649. * @description collapse all tree rows
  22650. */
  22651. collapseAllRows: function () {
  22652. service.collapseAllRows(grid);
  22653. },
  22654. /**
  22655. * @ngdoc function
  22656. * @name toggleRowTreeState
  22657. * @methodOf ui.grid.treeBase.api:PublicApi
  22658. * @description call expand if the row is collapsed, collapse if it is expanded
  22659. * @param {gridRow} row the row you wish to toggle
  22660. */
  22661. toggleRowTreeState: function (row) {
  22662. service.toggleRowTreeState(grid, row);
  22663. },
  22664. /**
  22665. * @ngdoc function
  22666. * @name expandRow
  22667. * @methodOf ui.grid.treeBase.api:PublicApi
  22668. * @description expand the immediate children of the specified row
  22669. * @param {gridRow} row the row you wish to expand
  22670. */
  22671. expandRow: function (row) {
  22672. service.expandRow(grid, row);
  22673. },
  22674. /**
  22675. * @ngdoc function
  22676. * @name expandRowChildren
  22677. * @methodOf ui.grid.treeBase.api:PublicApi
  22678. * @description expand all children of the specified row
  22679. * @param {gridRow} row the row you wish to expand
  22680. */
  22681. expandRowChildren: function (row) {
  22682. service.expandRowChildren(grid, row);
  22683. },
  22684. /**
  22685. * @ngdoc function
  22686. * @name collapseRow
  22687. * @methodOf ui.grid.treeBase.api:PublicApi
  22688. * @description collapse the specified row. When
  22689. * you expand the row again, all grandchildren will retain their state
  22690. * @param {gridRow} row the row you wish to collapse
  22691. */
  22692. collapseRow: function ( row ) {
  22693. service.collapseRow(grid, row);
  22694. },
  22695. /**
  22696. * @ngdoc function
  22697. * @name collapseRowChildren
  22698. * @methodOf ui.grid.treeBase.api:PublicApi
  22699. * @description collapse all children of the specified row. When
  22700. * you expand the row again, all grandchildren will be collapsed
  22701. * @param {gridRow} row the row you wish to collapse children for
  22702. */
  22703. collapseRowChildren: function ( row ) {
  22704. service.collapseRowChildren(grid, row);
  22705. },
  22706. /**
  22707. * @ngdoc function
  22708. * @name getTreeState
  22709. * @methodOf ui.grid.treeBase.api:PublicApi
  22710. * @description Get the tree state for this grid,
  22711. * used by the saveState feature
  22712. * Returned treeState as an object
  22713. * `{ expandedState: { uid: 'expanded', uid: 'collapsed' } }`
  22714. * where expandedState is a hash of row uid and the current expanded state
  22715. *
  22716. * @returns {object} tree state
  22717. *
  22718. * TODO - this needs work - we need an identifier that persists across instantiations,
  22719. * not uid. This really means we need a row identity defined, but that won't work for
  22720. * grouping. Perhaps this needs to be moved up to treeView and grouping, rather than
  22721. * being in base.
  22722. */
  22723. getTreeExpandedState: function () {
  22724. return { expandedState: service.getTreeState(grid) };
  22725. },
  22726. /**
  22727. * @ngdoc function
  22728. * @name setTreeState
  22729. * @methodOf ui.grid.treeBase.api:PublicApi
  22730. * @description Set the expanded states of the tree
  22731. * @param {object} config the config you want to apply, in the format
  22732. * provided by getTreeState
  22733. */
  22734. setTreeState: function ( config ) {
  22735. service.setTreeState( grid, config );
  22736. },
  22737. /**
  22738. * @ngdoc function
  22739. * @name getRowChildren
  22740. * @methodOf ui.grid.treeBase.api:PublicApi
  22741. * @description Get the children of the specified row
  22742. * @param {GridRow} row the row you want the children of
  22743. * @returns {Array} array of children of this row, the children
  22744. * are all gridRows
  22745. */
  22746. getRowChildren: function ( row ){
  22747. return row.treeNode.children.map( function( childNode ){
  22748. return childNode.row;
  22749. });
  22750. }
  22751. }
  22752. }
  22753. };
  22754. grid.api.registerEventsFromObject(publicApi.events);
  22755. grid.api.registerMethodsFromObject(publicApi.methods);
  22756. },
  22757. defaultGridOptions: function (gridOptions) {
  22758. //default option to true unless it was explicitly set to false
  22759. /**
  22760. * @ngdoc object
  22761. * @name ui.grid.treeBase.api:GridOptions
  22762. *
  22763. * @description GridOptions for treeBase feature, these are available to be
  22764. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  22765. */
  22766. /**
  22767. * @ngdoc object
  22768. * @name treeRowHeaderBaseWidth
  22769. * @propertyOf ui.grid.treeBase.api:GridOptions
  22770. * @description Base width of the tree header, provides for a single level of tree. This
  22771. * is incremented by `treeIndent` for each extra level
  22772. * <br/>Defaults to 30
  22773. */
  22774. gridOptions.treeRowHeaderBaseWidth = gridOptions.treeRowHeaderBaseWidth || 30;
  22775. /**
  22776. * @ngdoc object
  22777. * @name treeIndent
  22778. * @propertyOf ui.grid.treeBase.api:GridOptions
  22779. * @description Number of pixels of indent for the icon at each tree level, wider indents are visually more pleasing,
  22780. * but will make the tree row header wider
  22781. * <br/>Defaults to 10
  22782. */
  22783. gridOptions.treeIndent = gridOptions.treeIndent || 10;
  22784. /**
  22785. * @ngdoc object
  22786. * @name showTreeRowHeader
  22787. * @propertyOf ui.grid.treeBase.api:GridOptions
  22788. * @description If set to false, don't create the row header. Youll need to programatically control the expand
  22789. * states
  22790. * <br/>Defaults to true
  22791. */
  22792. gridOptions.showTreeRowHeader = gridOptions.showTreeRowHeader !== false;
  22793. /**
  22794. * @ngdoc object
  22795. * @name showTreeExpandNoChildren
  22796. * @propertyOf ui.grid.treeBase.api:GridOptions
  22797. * @description If set to true, show the expand/collapse button even if there are no
  22798. * children of a node. You'd use this if you're planning to dynamically load the children
  22799. *
  22800. * <br/>Defaults to true, grouping overrides to false
  22801. */
  22802. gridOptions.showTreeExpandNoChildren = gridOptions.showTreeExpandNoChildren !== false;
  22803. /**
  22804. * @ngdoc object
  22805. * @name treeRowHeaderAlwaysVisible
  22806. * @propertyOf ui.grid.treeBase.api:GridOptions
  22807. * @description If set to true, row header even if there are no tree nodes
  22808. *
  22809. * <br/>Defaults to true
  22810. */
  22811. gridOptions.treeRowHeaderAlwaysVisible = gridOptions.treeRowHeaderAlwaysVisible !== false;
  22812. /**
  22813. * @ngdoc object
  22814. * @name treeCustomAggregations
  22815. * @propertyOf ui.grid.treeBase.api:GridOptions
  22816. * @description Define custom aggregation functions. The properties of this object will be
  22817. * aggregation types available for use on columnDef with {@link ui.grid.treeBase.api:ColumnDef treeAggregationType} or through the column menu.
  22818. * If a function defined here uses the same name as one of the native aggregations, this one will take precedence.
  22819. * The object format is:
  22820. *
  22821. * <pre>
  22822. * {
  22823. * aggregationName: {
  22824. * label: (optional) string,
  22825. * aggregationFn: function( aggregation, fieldValue, numValue, row ){...},
  22826. * finalizerFn: (optional) function( aggregation ){...}
  22827. * },
  22828. * mean: {
  22829. * label: 'mean',
  22830. * aggregationFn: function( aggregation, fieldValue, numValue ){
  22831. * aggregation.count = (aggregation.count || 1) + 1;
  22832. * aggregation.sum = (aggregation.sum || 0) + numValue;
  22833. * },
  22834. * finalizerFn: function( aggregation ){
  22835. * aggregation.value = aggregation.sum / aggregation.count
  22836. * }
  22837. * }
  22838. * }
  22839. * </pre>
  22840. *
  22841. * <br/>The `finalizerFn` may be used to manipulate the value before rendering, or to
  22842. * apply a custom rendered value. If `aggregation.rendered` is left undefined, the value will be
  22843. * rendered. Note that the native aggregation functions use an `finalizerFn` to concatenate
  22844. * the label and the value.
  22845. *
  22846. * <br/>Defaults to {}
  22847. */
  22848. gridOptions.treeCustomAggregations = gridOptions.treeCustomAggregations || {};
  22849. /**
  22850. * @ngdoc object
  22851. * @name enableExpandAll
  22852. * @propertyOf ui.grid.treeBase.api:GridOptions
  22853. * @description Enable the expand all button at the top of the row header
  22854. *
  22855. * <br/>Defaults to true
  22856. */
  22857. gridOptions.enableExpandAll = gridOptions.enableExpandAll !== false;
  22858. },
  22859. /**
  22860. * @ngdoc function
  22861. * @name treeBaseColumnBuilder
  22862. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  22863. * @description Sets the tree defaults based on the columnDefs
  22864. *
  22865. * @param {object} colDef columnDef we're basing on
  22866. * @param {GridCol} col the column we're to update
  22867. * @param {object} gridOptions the options we should use
  22868. * @returns {promise} promise for the builder - actually we do it all inline so it's immediately resolved
  22869. */
  22870. treeBaseColumnBuilder: function (colDef, col, gridOptions) {
  22871. /**
  22872. * @ngdoc object
  22873. * @name customTreeAggregationFn
  22874. * @propertyOf ui.grid.treeBase.api:ColumnDef
  22875. * @description A custom function that aggregates rows into some form of
  22876. * total. Aggregations run row-by-row, the function needs to be capable of
  22877. * creating a running total.
  22878. *
  22879. * The function will be provided the aggregation item (in which you can store running
  22880. * totals), the row value that is to be aggregated, and that same row value converted to
  22881. * a number (most aggregations work on numbers)
  22882. * @example
  22883. * <pre>
  22884. * customTreeAggregationFn = function ( aggregation, fieldValue, numValue, row ){
  22885. * // calculates the average of the squares of the values
  22886. * if ( typeof(aggregation.count) === 'undefined' ){
  22887. * aggregation.count = 0;
  22888. * }
  22889. * aggregation.count++;
  22890. *
  22891. * if ( !isNaN(numValue) ){
  22892. * if ( typeof(aggregation.total) === 'undefined' ){
  22893. * aggregation.total = 0;
  22894. * }
  22895. * aggregation.total = aggregation.total + numValue * numValue;
  22896. * }
  22897. *
  22898. * aggregation.value = aggregation.total / aggregation.count;
  22899. * }
  22900. * </pre>
  22901. * <br/>Defaults to undefined. May be overwritten by treeAggregationType, the two options should not be used together.
  22902. */
  22903. if ( typeof(colDef.customTreeAggregationFn) !== 'undefined' ){
  22904. col.treeAggregationFn = colDef.customTreeAggregationFn;
  22905. }
  22906. /**
  22907. * @ngdoc object
  22908. * @name treeAggregationType
  22909. * @propertyOf ui.grid.treeBase.api:ColumnDef
  22910. * @description Use one of the native or grid-level aggregation methods for calculating aggregations on this column.
  22911. * Native method are in the constants file and include: SUM, COUNT, MIN, MAX, AVG. This may also be the property the
  22912. * name of an aggregation function defined with {@link ui.grid.treeBase.api:GridOptions treeCustomAggregations}.
  22913. *
  22914. * <pre>
  22915. * treeAggregationType = uiGridTreeBaseConstants.aggregation.SUM,
  22916. * }
  22917. * </pre>
  22918. *
  22919. * If you are using aggregations you should either:
  22920. *
  22921. * - also use grouping, in which case the aggregations are displayed in the group header, OR
  22922. * - use treeView, in which case you can set `treeAggregationUpdateEntity: true` in the colDef, and
  22923. * treeBase will store the aggregation information in the entity, or you can set `treeAggregationUpdateEntity: false`
  22924. * in the colDef, and you need to manual retrieve the calculated aggregations from the row.treeNode.aggregations
  22925. *
  22926. * <br/>Takes precendence over a treeAggregationFn, the two options should not be used together.
  22927. * <br/>Defaults to undefined.
  22928. */
  22929. if ( typeof(colDef.treeAggregationType) !== 'undefined' ){
  22930. col.treeAggregation = { type: colDef.treeAggregationType };
  22931. if ( typeof(gridOptions.treeCustomAggregations[colDef.treeAggregationType]) !== 'undefined' ){
  22932. col.treeAggregationFn = gridOptions.treeCustomAggregations[colDef.treeAggregationType].aggregationFn;
  22933. col.treeAggregationFinalizerFn = gridOptions.treeCustomAggregations[colDef.treeAggregationType].finalizerFn;
  22934. col.treeAggregation.label = gridOptions.treeCustomAggregations[colDef.treeAggregationType].label;
  22935. } else if ( typeof(service.nativeAggregations()[colDef.treeAggregationType]) !== 'undefined' ){
  22936. col.treeAggregationFn = service.nativeAggregations()[colDef.treeAggregationType].aggregationFn;
  22937. col.treeAggregation.label = service.nativeAggregations()[colDef.treeAggregationType].label;
  22938. }
  22939. }
  22940. /**
  22941. * @ngdoc object
  22942. * @name treeAggregationLabel
  22943. * @propertyOf ui.grid.treeBase.api:ColumnDef
  22944. * @description A custom label to use for this aggregation. If provided we don't use native i18n.
  22945. */
  22946. if ( typeof(colDef.treeAggregationLabel) !== 'undefined' ){
  22947. if (typeof(col.treeAggregation) === 'undefined' ){
  22948. col.treeAggregation = {};
  22949. }
  22950. col.treeAggregation.label = colDef.treeAggregationLabel;
  22951. }
  22952. /**
  22953. * @ngdoc object
  22954. * @name treeAggregationUpdateEntity
  22955. * @propertyOf ui.grid.treeBase.api:ColumnDef
  22956. * @description Store calculated aggregations into the entity, allowing them
  22957. * to be displayed in the grid using a standard cellTemplate. This defaults to true,
  22958. * if you are using grouping then you shouldn't set it to false, as then the aggregations won't
  22959. * display.
  22960. *
  22961. * If you are using treeView in most cases you'll want to set this to true. This will result in
  22962. * getCellValue returning the aggregation rather than whatever was stored in the cell attribute on
  22963. * the entity. If you want to render the underlying entity value (and do something else with the aggregation)
  22964. * then you could use a custom cellTemplate to display `row.entity.myAttribute`, rather than using getCellValue.
  22965. *
  22966. * <br/>Defaults to true
  22967. *
  22968. * @example
  22969. * <pre>
  22970. * gridOptions.columns = [{
  22971. * name: 'myCol',
  22972. * treeAggregation: { type: uiGridTreeBaseConstants.aggregation.SUM },
  22973. * treeAggregationUpdateEntity: true
  22974. * cellTemplate: '<div>{{row.entity.myCol + " " + row.treeNode.aggregations[0].rendered}}</div>'
  22975. * }];
  22976. * </pre>
  22977. */
  22978. col.treeAggregationUpdateEntity = colDef.treeAggregationUpdateEntity !== false;
  22979. /**
  22980. * @ngdoc object
  22981. * @name customTreeAggregationFinalizerFn
  22982. * @propertyOf ui.grid.treeBase.api:ColumnDef
  22983. * @description A custom function that populates aggregation.rendered, this is called when
  22984. * a particular aggregation has been fully calculated, and we want to render the value.
  22985. *
  22986. * With the native aggregation options we just concatenate `aggregation.label` and
  22987. * `aggregation.value`, but if you wanted to apply a filter or otherwise manipulate the label
  22988. * or the value, you can do so with this function. This function will be called after the
  22989. * the default `finalizerFn`.
  22990. *
  22991. * @example
  22992. * <pre>
  22993. * customTreeAggregationFinalizerFn = function ( aggregation ){
  22994. * aggregation.rendered = aggregation.label + aggregation.value / 100 + '%';
  22995. * }
  22996. * </pre>
  22997. * <br/>Defaults to undefined.
  22998. */
  22999. if ( typeof(col.customTreeAggregationFinalizerFn) === 'undefined' ){
  23000. col.customTreeAggregationFinalizerFn = colDef.customTreeAggregationFinalizerFn;
  23001. }
  23002. },
  23003. /**
  23004. * @ngdoc function
  23005. * @name createRowHeader
  23006. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23007. * @description Create the rowHeader. If treeRowHeaderAlwaysVisible then
  23008. * set it to visible, otherwise set it to invisible
  23009. *
  23010. * @param {Grid} grid grid object
  23011. */
  23012. createRowHeader: function( grid ){
  23013. var rowHeaderColumnDef = {
  23014. name: uiGridTreeBaseConstants.rowHeaderColName,
  23015. displayName: '',
  23016. width: grid.options.treeRowHeaderBaseWidth,
  23017. minWidth: 10,
  23018. cellTemplate: 'ui-grid/treeBaseRowHeader',
  23019. headerCellTemplate: 'ui-grid/treeBaseHeaderCell',
  23020. enableColumnResizing: false,
  23021. enableColumnMenu: false,
  23022. exporterSuppressExport: true,
  23023. allowCellFocus: true
  23024. };
  23025. rowHeaderColumnDef.visible = grid.options.treeRowHeaderAlwaysVisible;
  23026. grid.addRowHeaderColumn( rowHeaderColumnDef );
  23027. },
  23028. /**
  23029. * @ngdoc function
  23030. * @name expandAllRows
  23031. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23032. * @description Expands all nodes in the tree
  23033. *
  23034. * @param {Grid} grid grid object
  23035. */
  23036. expandAllRows: function (grid) {
  23037. grid.treeBase.tree.forEach( function( node ) {
  23038. service.setAllNodes( grid, node, uiGridTreeBaseConstants.EXPANDED);
  23039. });
  23040. grid.treeBase.expandAll = true;
  23041. grid.queueGridRefresh();
  23042. },
  23043. /**
  23044. * @ngdoc function
  23045. * @name collapseAllRows
  23046. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23047. * @description Collapses all nodes in the tree
  23048. *
  23049. * @param {Grid} grid grid object
  23050. */
  23051. collapseAllRows: function (grid) {
  23052. grid.treeBase.tree.forEach( function( node ) {
  23053. service.setAllNodes( grid, node, uiGridTreeBaseConstants.COLLAPSED);
  23054. });
  23055. grid.treeBase.expandAll = false;
  23056. grid.queueGridRefresh();
  23057. },
  23058. /**
  23059. * @ngdoc function
  23060. * @name setAllNodes
  23061. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23062. * @description Works through a subset of grid.treeBase.rowExpandedStates, setting
  23063. * all child nodes (and their descendents) of the provided node to the given state.
  23064. *
  23065. * Calls itself recursively on all nodes so as to achieve this.
  23066. *
  23067. * @param {Grid} grid the grid we're operating on (so we can raise events)
  23068. * @param {object} treeNode a node in the tree that we want to update
  23069. * @param {string} targetState the state we want to set it to
  23070. */
  23071. setAllNodes: function (grid, treeNode, targetState) {
  23072. if ( typeof(treeNode.state) !== 'undefined' && treeNode.state !== targetState ){
  23073. treeNode.state = targetState;
  23074. if ( targetState === uiGridTreeBaseConstants.EXPANDED ){
  23075. grid.api.treeBase.raise.rowExpanded(treeNode.row);
  23076. } else {
  23077. grid.api.treeBase.raise.rowCollapsed(treeNode.row);
  23078. }
  23079. }
  23080. // set all child nodes
  23081. if ( treeNode.children ){
  23082. treeNode.children.forEach(function( childNode ){
  23083. service.setAllNodes(grid, childNode, targetState);
  23084. });
  23085. }
  23086. },
  23087. /**
  23088. * @ngdoc function
  23089. * @name toggleRowTreeState
  23090. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23091. * @description Toggles the expand or collapse state of this grouped row, if
  23092. * it's a parent row
  23093. *
  23094. * @param {Grid} grid grid object
  23095. * @param {GridRow} row the row we want to toggle
  23096. */
  23097. toggleRowTreeState: function ( grid, row ){
  23098. if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){
  23099. return;
  23100. }
  23101. if (row.treeNode.state === uiGridTreeBaseConstants.EXPANDED){
  23102. service.collapseRow(grid, row);
  23103. } else {
  23104. service.expandRow(grid, row);
  23105. }
  23106. grid.queueGridRefresh();
  23107. },
  23108. /**
  23109. * @ngdoc function
  23110. * @name expandRow
  23111. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23112. * @description Expands this specific row, showing only immediate children.
  23113. *
  23114. * @param {Grid} grid grid object
  23115. * @param {GridRow} row the row we want to expand
  23116. */
  23117. expandRow: function ( grid, row ){
  23118. if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){
  23119. return;
  23120. }
  23121. if ( row.treeNode.state !== uiGridTreeBaseConstants.EXPANDED ){
  23122. row.treeNode.state = uiGridTreeBaseConstants.EXPANDED;
  23123. grid.api.treeBase.raise.rowExpanded(row);
  23124. grid.treeBase.expandAll = service.allExpanded(grid.treeBase.tree);
  23125. grid.queueGridRefresh();
  23126. }
  23127. },
  23128. /**
  23129. * @ngdoc function
  23130. * @name expandRowChildren
  23131. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23132. * @description Expands this specific row, showing all children.
  23133. *
  23134. * @param {Grid} grid grid object
  23135. * @param {GridRow} row the row we want to expand
  23136. */
  23137. expandRowChildren: function ( grid, row ){
  23138. if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){
  23139. return;
  23140. }
  23141. service.setAllNodes(grid, row.treeNode, uiGridTreeBaseConstants.EXPANDED);
  23142. grid.treeBase.expandAll = service.allExpanded(grid.treeBase.tree);
  23143. grid.queueGridRefresh();
  23144. },
  23145. /**
  23146. * @ngdoc function
  23147. * @name collapseRow
  23148. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23149. * @description Collapses this specific row
  23150. *
  23151. * @param {Grid} grid grid object
  23152. * @param {GridRow} row the row we want to collapse
  23153. */
  23154. collapseRow: function( grid, row ){
  23155. if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){
  23156. return;
  23157. }
  23158. if ( row.treeNode.state !== uiGridTreeBaseConstants.COLLAPSED ){
  23159. row.treeNode.state = uiGridTreeBaseConstants.COLLAPSED;
  23160. grid.treeBase.expandAll = false;
  23161. grid.api.treeBase.raise.rowCollapsed(row);
  23162. grid.queueGridRefresh();
  23163. }
  23164. },
  23165. /**
  23166. * @ngdoc function
  23167. * @name collapseRowChildren
  23168. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23169. * @description Collapses this specific row and all children
  23170. *
  23171. * @param {Grid} grid grid object
  23172. * @param {GridRow} row the row we want to collapse
  23173. */
  23174. collapseRowChildren: function( grid, row ){
  23175. if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){
  23176. return;
  23177. }
  23178. service.setAllNodes(grid, row.treeNode, uiGridTreeBaseConstants.COLLAPSED);
  23179. grid.treeBase.expandAll = false;
  23180. grid.queueGridRefresh();
  23181. },
  23182. /**
  23183. * @ngdoc function
  23184. * @name allExpanded
  23185. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23186. * @description Returns true if all rows are expanded, false
  23187. * if they're not. Walks the tree to determine this. Used
  23188. * to set the expandAll state.
  23189. *
  23190. * If the node has no children, then return true (it's immaterial
  23191. * whether it is expanded). If the node has children, then return
  23192. * false if this node is collapsed, or if any child node is not all expanded
  23193. *
  23194. * @param {object} tree the grid to check
  23195. * @returns {boolean} whether or not the tree is all expanded
  23196. */
  23197. allExpanded: function( tree ){
  23198. var allExpanded = true;
  23199. tree.forEach( function( node ){
  23200. if ( !service.allExpandedInternal( node ) ){
  23201. allExpanded = false;
  23202. }
  23203. });
  23204. return allExpanded;
  23205. },
  23206. allExpandedInternal: function( treeNode ){
  23207. if ( treeNode.children && treeNode.children.length > 0 ){
  23208. if ( treeNode.state === uiGridTreeBaseConstants.COLLAPSED ){
  23209. return false;
  23210. }
  23211. var allExpanded = true;
  23212. treeNode.children.forEach( function( node ){
  23213. if ( !service.allExpandedInternal( node ) ){
  23214. allExpanded = false;
  23215. }
  23216. });
  23217. return allExpanded;
  23218. } else {
  23219. return true;
  23220. }
  23221. },
  23222. /**
  23223. * @ngdoc function
  23224. * @name treeRows
  23225. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23226. * @description The rowProcessor that adds the nodes to the tree, and sets the visible
  23227. * state of each row based on it's parent state
  23228. *
  23229. * Assumes it is always called after the sorting processor, and the grouping processor if there is one.
  23230. * Performs any tree sorts itself after having built the tree
  23231. *
  23232. * Processes all the rows in order, setting the group level based on the $$treeLevel in the associated
  23233. * entity, and setting the visible state based on the parent's state.
  23234. *
  23235. * Calculates the deepest level of tree whilst it goes, and updates that so that the header column can be correctly
  23236. * sized.
  23237. *
  23238. * Aggregates if necessary along the way.
  23239. *
  23240. * @param {array} renderableRows the rows we want to process, usually the output from the previous rowProcessor
  23241. * @returns {array} the updated rows
  23242. */
  23243. treeRows: function( renderableRows ) {
  23244. if (renderableRows.length === 0){
  23245. return renderableRows;
  23246. }
  23247. var grid = this;
  23248. var currentLevel = 0;
  23249. var currentState = uiGridTreeBaseConstants.EXPANDED;
  23250. var parents = [];
  23251. grid.treeBase.tree = service.createTree( grid, renderableRows );
  23252. service.updateRowHeaderWidth( grid );
  23253. service.sortTree( grid );
  23254. service.fixFilter( grid );
  23255. return service.renderTree( grid.treeBase.tree );
  23256. },
  23257. /**
  23258. * @ngdoc function
  23259. * @name createOrUpdateRowHeaderWidth
  23260. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23261. * @description Calculates the rowHeader width.
  23262. *
  23263. * If rowHeader is always present, updates the width.
  23264. *
  23265. * If rowHeader is only sometimes present (`treeRowHeaderAlwaysVisible: false`), determines whether there
  23266. * should be one, then creates or removes it as appropriate, with the created rowHeader having the
  23267. * right width.
  23268. *
  23269. * If there's never a rowHeader then never creates one: `showTreeRowHeader: false`
  23270. *
  23271. * @param {Grid} grid the grid we want to set the row header on
  23272. */
  23273. updateRowHeaderWidth: function( grid ){
  23274. var rowHeader = grid.getColumn(uiGridTreeBaseConstants.rowHeaderColName);
  23275. var newWidth = grid.options.treeRowHeaderBaseWidth + grid.options.treeIndent * Math.max(grid.treeBase.numberLevels - 1, 0);
  23276. if ( rowHeader && newWidth !== rowHeader.width ){
  23277. rowHeader.width = newWidth;
  23278. grid.queueRefresh();
  23279. }
  23280. var newVisibility = true;
  23281. if ( grid.options.showTreeRowHeader === false ){
  23282. newVisibility = false;
  23283. }
  23284. if ( grid.options.treeRowHeaderAlwaysVisible === false && grid.treeBase.numberLevels <= 0 ){
  23285. newVisibility = false;
  23286. }
  23287. if ( rowHeader.visible !== newVisibility ) {
  23288. rowHeader.visible = newVisibility;
  23289. rowHeader.colDef.visible = newVisibility;
  23290. grid.queueGridRefresh();
  23291. }
  23292. },
  23293. /**
  23294. * @ngdoc function
  23295. * @name renderTree
  23296. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23297. * @description Creates an array of rows based on the tree, exporting only
  23298. * the visible nodes and leaves
  23299. *
  23300. * @param {array} nodeList the list of nodes - can be grid.treeBase.tree, or can be node.children when
  23301. * we're calling recursively
  23302. * @returns {array} renderable rows
  23303. */
  23304. renderTree: function( nodeList ){
  23305. var renderableRows = [];
  23306. nodeList.forEach( function ( node ){
  23307. if ( node.row.visible ){
  23308. renderableRows.push( node.row );
  23309. }
  23310. if ( node.state === uiGridTreeBaseConstants.EXPANDED && node.children && node.children.length > 0 ){
  23311. renderableRows = renderableRows.concat( service.renderTree( node.children ) );
  23312. }
  23313. });
  23314. return renderableRows;
  23315. },
  23316. /**
  23317. * @ngdoc function
  23318. * @name createTree
  23319. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23320. * @description Creates a tree from the renderableRows
  23321. *
  23322. * @param {Grid} grid the grid
  23323. * @param {array} renderableRows the rows we want to create a tree from
  23324. * @returns {object} the tree we've build
  23325. */
  23326. createTree: function( grid, renderableRows ) {
  23327. var currentLevel = -1;
  23328. var parents = [];
  23329. var currentState;
  23330. grid.treeBase.tree = [];
  23331. grid.treeBase.numberLevels = 0;
  23332. var aggregations = service.getAggregations( grid );
  23333. var createNode = function( row ){
  23334. if ( typeof(row.entity.$$treeLevel) !== 'undefined' && row.treeLevel !== row.entity.$$treeLevel ){
  23335. row.treeLevel = row.entity.$$treeLevel;
  23336. }
  23337. if ( row.treeLevel <= currentLevel ){
  23338. // pop any levels that aren't parents of this level, formatting the aggregation at the same time
  23339. while ( row.treeLevel <= currentLevel ){
  23340. var lastParent = parents.pop();
  23341. service.finaliseAggregations( lastParent );
  23342. currentLevel--;
  23343. }
  23344. // reset our current state based on the new parent, set to expanded if this is a level 0 node
  23345. if ( parents.length > 0 ){
  23346. currentState = service.setCurrentState(parents);
  23347. } else {
  23348. currentState = uiGridTreeBaseConstants.EXPANDED;
  23349. }
  23350. }
  23351. // aggregate if this is a leaf node
  23352. if ( ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) && row.visible ){
  23353. service.aggregate( grid, row, parents );
  23354. }
  23355. // add this node to the tree
  23356. service.addOrUseNode(grid, row, parents, aggregations);
  23357. if ( typeof(row.treeLevel) !== 'undefined' && row.treeLevel !== null && row.treeLevel >= 0 ){
  23358. parents.push(row);
  23359. currentLevel++;
  23360. currentState = service.setCurrentState(parents);
  23361. }
  23362. // update the tree number of levels, so we can set header width if we need to
  23363. if ( grid.treeBase.numberLevels < row.treeLevel + 1){
  23364. grid.treeBase.numberLevels = row.treeLevel + 1;
  23365. }
  23366. };
  23367. renderableRows.forEach( createNode );
  23368. // finalise remaining aggregations
  23369. while ( parents.length > 0 ){
  23370. var lastParent = parents.pop();
  23371. service.finaliseAggregations( lastParent );
  23372. }
  23373. return grid.treeBase.tree;
  23374. },
  23375. /**
  23376. * @ngdoc function
  23377. * @name addOrUseNode
  23378. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23379. * @description Creates a tree node for this row. If this row already has a treeNode
  23380. * recorded against it, preserves the state, but otherwise overwrites the data.
  23381. *
  23382. * @param {grid} grid the grid we're operating on
  23383. * @param {gridRow} row the row we want to set
  23384. * @param {array} parents an array of the parents this row should have
  23385. * @param {array} aggregationBase empty aggregation information
  23386. * @returns {undefined} updates the parents array, updates the row to have a treeNode, and updates the
  23387. * grid.treeBase.tree
  23388. */
  23389. addOrUseNode: function( grid, row, parents, aggregationBase ){
  23390. var newAggregations = [];
  23391. aggregationBase.forEach( function(aggregation){
  23392. newAggregations.push(service.buildAggregationObject(aggregation.col));
  23393. });
  23394. var newNode = { state: uiGridTreeBaseConstants.COLLAPSED, row: row, parentRow: null, aggregations: newAggregations, children: [] };
  23395. if ( row.treeNode ){
  23396. newNode.state = row.treeNode.state;
  23397. }
  23398. if ( parents.length > 0 ){
  23399. newNode.parentRow = parents[parents.length - 1];
  23400. }
  23401. row.treeNode = newNode;
  23402. if ( parents.length === 0 ){
  23403. grid.treeBase.tree.push( newNode );
  23404. } else {
  23405. parents[parents.length - 1].treeNode.children.push( newNode );
  23406. }
  23407. },
  23408. /**
  23409. * @ngdoc function
  23410. * @name setCurrentState
  23411. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23412. * @description Looks at the parents array to determine our current state.
  23413. * If any node in the hierarchy is collapsed, then return collapsed, otherwise return
  23414. * expanded.
  23415. *
  23416. * @param {array} parents an array of the parents this row should have
  23417. * @returns {string} the state we should be setting to any nodes we see
  23418. */
  23419. setCurrentState: function( parents ){
  23420. var currentState = uiGridTreeBaseConstants.EXPANDED;
  23421. parents.forEach( function(parent){
  23422. if ( parent.treeNode.state === uiGridTreeBaseConstants.COLLAPSED ){
  23423. currentState = uiGridTreeBaseConstants.COLLAPSED;
  23424. }
  23425. });
  23426. return currentState;
  23427. },
  23428. /**
  23429. * @ngdoc function
  23430. * @name sortTree
  23431. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23432. * @description Performs a recursive sort on the tree nodes, sorting the
  23433. * children of each node and putting them back into the children array.
  23434. *
  23435. * Before doing this it turns back on all the sortIgnore - things that were previously
  23436. * ignored we process now. Since we're sorting within the nodes, presumably anything
  23437. * that was already sorted is how we derived the nodes, we can keep those sorts too.
  23438. *
  23439. * We only sort tree nodes that are expanded - no point in wasting effort sorting collapsed
  23440. * nodes
  23441. *
  23442. * @param {Grid} grid the grid to get the aggregation information from
  23443. * @returns {array} the aggregation information
  23444. */
  23445. sortTree: function( grid ){
  23446. grid.columns.forEach( function( column ) {
  23447. if ( column.sort && column.sort.ignoreSort ){
  23448. delete column.sort.ignoreSort;
  23449. }
  23450. });
  23451. grid.treeBase.tree = service.sortInternal( grid, grid.treeBase.tree );
  23452. },
  23453. sortInternal: function( grid, treeList ){
  23454. var rows = treeList.map( function( node ){
  23455. return node.row;
  23456. });
  23457. rows = rowSorter.sort( grid, rows, grid.columns );
  23458. var treeNodes = rows.map( function( row ){
  23459. return row.treeNode;
  23460. });
  23461. treeNodes.forEach( function( node ){
  23462. if ( node.state === uiGridTreeBaseConstants.EXPANDED && node.children && node.children.length > 0 ){
  23463. node.children = service.sortInternal( grid, node.children );
  23464. }
  23465. });
  23466. return treeNodes;
  23467. },
  23468. /**
  23469. * @ngdoc function
  23470. * @name fixFilter
  23471. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23472. * @description After filtering has run, we need to go back through the tree
  23473. * and make sure the parent rows are always visible if any of the child rows
  23474. * are visible (filtering may make a child visible, but the parent may not
  23475. * match the filter criteria)
  23476. *
  23477. * This has a risk of being computationally expensive, we do it by walking
  23478. * the tree and remembering whether there are any invisible nodes on the
  23479. * way down.
  23480. *
  23481. * @param {Grid} grid the grid to fix filters on
  23482. */
  23483. fixFilter: function( grid ){
  23484. var parentsVisible;
  23485. grid.treeBase.tree.forEach( function( node ){
  23486. if ( node.children && node.children.length > 0 ){
  23487. parentsVisible = node.row.visible;
  23488. service.fixFilterInternal( node.children, parentsVisible );
  23489. }
  23490. });
  23491. },
  23492. fixFilterInternal: function( nodes, parentsVisible) {
  23493. nodes.forEach( function( node ){
  23494. if ( node.row.visible && !parentsVisible ){
  23495. service.setParentsVisible( node );
  23496. parentsVisible = true;
  23497. }
  23498. if ( node.children && node.children.length > 0 ){
  23499. if ( service.fixFilterInternal( node.children, ( parentsVisible && node.row.visible ) ) ) {
  23500. parentsVisible = true;
  23501. }
  23502. }
  23503. });
  23504. return parentsVisible;
  23505. },
  23506. setParentsVisible: function( node ){
  23507. while ( node.parentRow ){
  23508. node.parentRow.visible = true;
  23509. node = node.parentRow.treeNode;
  23510. }
  23511. },
  23512. /**
  23513. * @ngdoc function
  23514. * @name buildAggregationObject
  23515. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23516. * @description Build the object which is stored on the column for holding meta-data about the aggregation.
  23517. * This method should only be called with columns which have an aggregation.
  23518. *
  23519. * @param {Column} the column which this object relates to
  23520. * @returns {object} {col: Column object, label: string, type: string (optional)}
  23521. */
  23522. buildAggregationObject: function( column ){
  23523. var newAggregation = { col: column };
  23524. if ( column.treeAggregation && column.treeAggregation.type ){
  23525. newAggregation.type = column.treeAggregation.type;
  23526. }
  23527. if ( column.treeAggregation && column.treeAggregation.label ){
  23528. newAggregation.label = column.treeAggregation.label;
  23529. }
  23530. return newAggregation;
  23531. },
  23532. /**
  23533. * @ngdoc function
  23534. * @name getAggregations
  23535. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23536. * @description Looks through the grid columns to find those with aggregations,
  23537. * and collates the aggregation information into an array, returns that array
  23538. *
  23539. * @param {Grid} grid the grid to get the aggregation information from
  23540. * @returns {array} the aggregation information
  23541. */
  23542. getAggregations: function( grid ){
  23543. var aggregateArray = [];
  23544. grid.columns.forEach( function(column){
  23545. if ( typeof(column.treeAggregationFn) !== 'undefined' ){
  23546. aggregateArray.push( service.buildAggregationObject(column) );
  23547. if ( grid.options.showColumnFooter && typeof(column.colDef.aggregationType) === 'undefined' && column.treeAggregation ){
  23548. // Add aggregation object for footer
  23549. column.treeFooterAggregation = service.buildAggregationObject(column);
  23550. column.aggregationType = service.treeFooterAggregationType;
  23551. }
  23552. }
  23553. });
  23554. return aggregateArray;
  23555. },
  23556. /**
  23557. * @ngdoc function
  23558. * @name aggregate
  23559. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23560. * @description Accumulate the data from this row onto the aggregations for each parent
  23561. *
  23562. * Iterate over the parents, then iterate over the aggregations for each of those parents,
  23563. * and perform the aggregation for each individual aggregation
  23564. *
  23565. * @param {Grid} grid grid object
  23566. * @param {GridRow} row the row we want to set grouping visibility on
  23567. * @param {array} parents the parents that we would want to aggregate onto
  23568. */
  23569. aggregate: function( grid, row, parents ){
  23570. if ( parents.length === 0 && row.treeNode && row.treeNode.aggregations ){
  23571. row.treeNode.aggregations.forEach(function(aggregation){
  23572. // Calculate aggregations for footer even if there are no grouped rows
  23573. if ( typeof(aggregation.col.treeFooterAggregation) !== 'undefined' ) {
  23574. var fieldValue = grid.getCellValue(row, aggregation.col);
  23575. var numValue = Number(fieldValue);
  23576. aggregation.col.treeAggregationFn(aggregation.col.treeFooterAggregation, fieldValue, numValue, row);
  23577. }
  23578. });
  23579. }
  23580. parents.forEach( function( parent, index ){
  23581. if ( parent.treeNode.aggregations ){
  23582. parent.treeNode.aggregations.forEach( function( aggregation ){
  23583. var fieldValue = grid.getCellValue(row, aggregation.col);
  23584. var numValue = Number(fieldValue);
  23585. aggregation.col.treeAggregationFn(aggregation, fieldValue, numValue, row);
  23586. if ( index === 0 && typeof(aggregation.col.treeFooterAggregation) !== 'undefined' ){
  23587. aggregation.col.treeAggregationFn(aggregation.col.treeFooterAggregation, fieldValue, numValue, row);
  23588. }
  23589. });
  23590. }
  23591. });
  23592. },
  23593. // Aggregation routines - no doco needed as self evident
  23594. nativeAggregations: function() {
  23595. var nativeAggregations = {
  23596. count: {
  23597. label: i18nService.get().aggregation.count,
  23598. menuTitle: i18nService.get().grouping.aggregate_count,
  23599. aggregationFn: function (aggregation, fieldValue, numValue) {
  23600. if (typeof(aggregation.value) === 'undefined') {
  23601. aggregation.value = 1;
  23602. } else {
  23603. aggregation.value++;
  23604. }
  23605. }
  23606. },
  23607. sum: {
  23608. label: i18nService.get().aggregation.sum,
  23609. menuTitle: i18nService.get().grouping.aggregate_sum,
  23610. aggregationFn: function( aggregation, fieldValue, numValue ) {
  23611. if (!isNaN(numValue)) {
  23612. if (typeof(aggregation.value) === 'undefined') {
  23613. aggregation.value = numValue;
  23614. } else {
  23615. aggregation.value += numValue;
  23616. }
  23617. }
  23618. }
  23619. },
  23620. min: {
  23621. label: i18nService.get().aggregation.min,
  23622. menuTitle: i18nService.get().grouping.aggregate_min,
  23623. aggregationFn: function( aggregation, fieldValue, numValue ) {
  23624. if (typeof(aggregation.value) === 'undefined') {
  23625. aggregation.value = fieldValue;
  23626. } else {
  23627. if (typeof(fieldValue) !== 'undefined' && fieldValue !== null && (fieldValue < aggregation.value || aggregation.value === null)) {
  23628. aggregation.value = fieldValue;
  23629. }
  23630. }
  23631. }
  23632. },
  23633. max: {
  23634. label: i18nService.get().aggregation.max,
  23635. menuTitle: i18nService.get().grouping.aggregate_max,
  23636. aggregationFn: function( aggregation, fieldValue, numValue ){
  23637. if ( typeof(aggregation.value) === 'undefined' ){
  23638. aggregation.value = fieldValue;
  23639. } else {
  23640. if ( typeof(fieldValue) !== 'undefined' && fieldValue !== null && (fieldValue > aggregation.value || aggregation.value === null)){
  23641. aggregation.value = fieldValue;
  23642. }
  23643. }
  23644. }
  23645. },
  23646. avg: {
  23647. label: i18nService.get().aggregation.avg,
  23648. menuTitle: i18nService.get().grouping.aggregate_avg,
  23649. aggregationFn: function( aggregation, fieldValue, numValue ){
  23650. if ( typeof(aggregation.count) === 'undefined' ){
  23651. aggregation.count = 1;
  23652. } else {
  23653. aggregation.count++;
  23654. }
  23655. if ( isNaN(numValue) ){
  23656. return;
  23657. }
  23658. if ( typeof(aggregation.value) === 'undefined' || typeof(aggregation.sum) === 'undefined' ){
  23659. aggregation.value = numValue;
  23660. aggregation.sum = numValue;
  23661. } else {
  23662. aggregation.sum += numValue;
  23663. aggregation.value = aggregation.sum / aggregation.count;
  23664. }
  23665. }
  23666. }
  23667. };
  23668. return nativeAggregations;
  23669. },
  23670. /**
  23671. * @ngdoc function
  23672. * @name finaliseAggregation
  23673. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23674. * @description Helper function used to finalize aggregation nodes and footer cells
  23675. *
  23676. * @param {gridRow} row the parent we're finalising
  23677. * @param {aggregation} the aggregation object manipulated by the aggregationFn
  23678. */
  23679. finaliseAggregation: function(row, aggregation){
  23680. if ( aggregation.col.treeAggregationUpdateEntity && typeof(row) !== 'undefined' && typeof(row.entity[ '$$' + aggregation.col.uid ]) !== 'undefined' ){
  23681. angular.extend( aggregation, row.entity[ '$$' + aggregation.col.uid ]);
  23682. }
  23683. if ( typeof(aggregation.col.treeAggregationFinalizerFn) === 'function' ){
  23684. aggregation.col.treeAggregationFinalizerFn( aggregation );
  23685. }
  23686. if ( typeof(aggregation.col.customTreeAggregationFinalizerFn) === 'function' ){
  23687. aggregation.col.customTreeAggregationFinalizerFn( aggregation );
  23688. }
  23689. if ( typeof(aggregation.rendered) === 'undefined' ){
  23690. aggregation.rendered = aggregation.label ? aggregation.label + aggregation.value : aggregation.value;
  23691. }
  23692. },
  23693. /**
  23694. * @ngdoc function
  23695. * @name finaliseAggregations
  23696. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23697. * @description Format the data from the aggregation into the rendered text
  23698. * e.g. if we had label: 'sum: ' and value: 25, we'd create 'sum: 25'.
  23699. *
  23700. * As part of this we call any formatting callback routines we've been provided.
  23701. *
  23702. * We write our aggregation out to the row.entity if treeAggregationUpdateEntity is
  23703. * set on the column - we don't overwrite any information that's already there, we append
  23704. * to it so that grouping can have set the groupVal beforehand without us overwriting it.
  23705. *
  23706. * We need to copy the data from the row.entity first before we finalise the aggregation,
  23707. * we need that information for the finaliserFn
  23708. *
  23709. * @param {gridRow} row the parent we're finalising
  23710. */
  23711. finaliseAggregations: function( row ){
  23712. if ( typeof(row.treeNode.aggregations) === 'undefined' ){
  23713. return;
  23714. }
  23715. row.treeNode.aggregations.forEach( function( aggregation ) {
  23716. service.finaliseAggregation(row, aggregation);
  23717. if ( aggregation.col.treeAggregationUpdateEntity ){
  23718. var aggregationCopy = {};
  23719. angular.forEach( aggregation, function( value, key ){
  23720. if ( aggregation.hasOwnProperty(key) && key !== 'col' ){
  23721. aggregationCopy[key] = value;
  23722. }
  23723. });
  23724. row.entity[ '$$' + aggregation.col.uid ] = aggregationCopy;
  23725. }
  23726. });
  23727. },
  23728. /**
  23729. * @ngdoc function
  23730. * @name treeFooterAggregationType
  23731. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23732. * @description Uses the tree aggregation functions and finalizers to set the
  23733. * column footer aggregations.
  23734. *
  23735. * @param {rows} visible rows. not used, but accepted to match signature of GridColumn.aggregationType
  23736. * @param {gridColumn} the column we are finalizing
  23737. */
  23738. treeFooterAggregationType: function( rows, column ) {
  23739. service.finaliseAggregation(undefined, column.treeFooterAggregation);
  23740. if ( typeof(column.treeFooterAggregation.value) === 'undefined' || column.treeFooterAggregation.rendered === null ){
  23741. // The was apparently no aggregation performed (perhaps this is a grouped column
  23742. return '';
  23743. }
  23744. return column.treeFooterAggregation.rendered;
  23745. }
  23746. };
  23747. return service;
  23748. }]);
  23749. /**
  23750. * @ngdoc directive
  23751. * @name ui.grid.treeBase.directive:uiGridTreeRowHeaderButtons
  23752. * @element div
  23753. *
  23754. * @description Provides the expand/collapse button on rows
  23755. */
  23756. module.directive('uiGridTreeBaseRowHeaderButtons', ['$templateCache', 'uiGridTreeBaseService',
  23757. function ($templateCache, uiGridTreeBaseService) {
  23758. return {
  23759. replace: true,
  23760. restrict: 'E',
  23761. template: $templateCache.get('ui-grid/treeBaseRowHeaderButtons'),
  23762. scope: true,
  23763. require: '^uiGrid',
  23764. link: function($scope, $elm, $attrs, uiGridCtrl) {
  23765. var self = uiGridCtrl.grid;
  23766. $scope.treeButtonClick = function(row, evt) {
  23767. uiGridTreeBaseService.toggleRowTreeState(self, row, evt);
  23768. };
  23769. }
  23770. };
  23771. }]);
  23772. /**
  23773. * @ngdoc directive
  23774. * @name ui.grid.treeBase.directive:uiGridTreeBaseExpandAllButtons
  23775. * @element div
  23776. *
  23777. * @description Provides the expand/collapse all button
  23778. */
  23779. module.directive('uiGridTreeBaseExpandAllButtons', ['$templateCache', 'uiGridTreeBaseService',
  23780. function ($templateCache, uiGridTreeBaseService) {
  23781. return {
  23782. replace: true,
  23783. restrict: 'E',
  23784. template: $templateCache.get('ui-grid/treeBaseExpandAllButtons'),
  23785. scope: false,
  23786. link: function($scope, $elm, $attrs, uiGridCtrl) {
  23787. var self = $scope.col.grid;
  23788. $scope.headerButtonClick = function(row, evt) {
  23789. if ( self.treeBase.expandAll ){
  23790. uiGridTreeBaseService.collapseAllRows(self, evt);
  23791. } else {
  23792. uiGridTreeBaseService.expandAllRows(self, evt);
  23793. }
  23794. };
  23795. }
  23796. };
  23797. }]);
  23798. /**
  23799. * @ngdoc directive
  23800. * @name ui.grid.treeBase.directive:uiGridViewport
  23801. * @element div
  23802. *
  23803. * @description Stacks on top of ui.grid.uiGridViewport to set formatting on a tree header row
  23804. */
  23805. module.directive('uiGridViewport',
  23806. ['$compile', 'uiGridConstants', 'gridUtil', '$parse',
  23807. function ($compile, uiGridConstants, gridUtil, $parse) {
  23808. return {
  23809. priority: -200, // run after default directive
  23810. scope: false,
  23811. compile: function ($elm, $attrs) {
  23812. var rowRepeatDiv = angular.element($elm.children().children()[0]);
  23813. var existingNgClass = rowRepeatDiv.attr("ng-class");
  23814. var newNgClass = '';
  23815. if ( existingNgClass ) {
  23816. newNgClass = existingNgClass.slice(0, -1) + ",'ui-grid-tree-header-row': row.treeLevel > -1}";
  23817. } else {
  23818. newNgClass = "{'ui-grid-tree-header-row': row.treeLevel > -1}";
  23819. }
  23820. rowRepeatDiv.attr("ng-class", newNgClass);
  23821. return {
  23822. pre: function ($scope, $elm, $attrs, controllers) {
  23823. },
  23824. post: function ($scope, $elm, $attrs, controllers) {
  23825. }
  23826. };
  23827. }
  23828. };
  23829. }]);
  23830. })();
  23831. (function () {
  23832. 'use strict';
  23833. /**
  23834. * @ngdoc overview
  23835. * @name ui.grid.treeView
  23836. * @description
  23837. *
  23838. * # ui.grid.treeView
  23839. *
  23840. * <div class="alert alert-warning" role="alert"><strong>Beta</strong> This feature is ready for testing, but it either hasn't seen a lot of use or has some known bugs.</div>
  23841. *
  23842. * This module provides a tree view of the data that it is provided, with nodes in that
  23843. * tree and leaves. Unlike grouping, the tree is an inherent property of the data and must
  23844. * be provided with your data array.
  23845. *
  23846. * Design information:
  23847. * -------------------
  23848. *
  23849. * TreeView uses treeBase for the underlying functionality, and is a very thin wrapper around
  23850. * that logic. Most of the design information has now moved to treebase.
  23851. * <br/>
  23852. * <br/>
  23853. *
  23854. * <div doc-module-components="ui.grid.treeView"></div>
  23855. */
  23856. var module = angular.module('ui.grid.treeView', ['ui.grid', 'ui.grid.treeBase']);
  23857. /**
  23858. * @ngdoc object
  23859. * @name ui.grid.treeView.constant:uiGridTreeViewConstants
  23860. *
  23861. * @description constants available in treeView module, this includes
  23862. * all the constants declared in the treeBase module (these are manually copied
  23863. * as there isn't an easy way to include constants in another constants file, and
  23864. * we don't want to make users include treeBase)
  23865. *
  23866. */
  23867. module.constant('uiGridTreeViewConstants', {
  23868. featureName: "treeView",
  23869. rowHeaderColName: 'treeBaseRowHeaderCol',
  23870. EXPANDED: 'expanded',
  23871. COLLAPSED: 'collapsed',
  23872. aggregation: {
  23873. COUNT: 'count',
  23874. SUM: 'sum',
  23875. MAX: 'max',
  23876. MIN: 'min',
  23877. AVG: 'avg'
  23878. }
  23879. });
  23880. /**
  23881. * @ngdoc service
  23882. * @name ui.grid.treeView.service:uiGridTreeViewService
  23883. *
  23884. * @description Services for treeView features
  23885. */
  23886. module.service('uiGridTreeViewService', ['$q', 'uiGridTreeViewConstants', 'uiGridTreeBaseConstants', 'uiGridTreeBaseService', 'gridUtil', 'GridRow', 'gridClassFactory', 'i18nService', 'uiGridConstants',
  23887. function ($q, uiGridTreeViewConstants, uiGridTreeBaseConstants, uiGridTreeBaseService, gridUtil, GridRow, gridClassFactory, i18nService, uiGridConstants) {
  23888. var service = {
  23889. initializeGrid: function (grid, $scope) {
  23890. uiGridTreeBaseService.initializeGrid( grid, $scope );
  23891. /**
  23892. * @ngdoc object
  23893. * @name ui.grid.treeView.grid:treeView
  23894. *
  23895. * @description Grid properties and functions added for treeView
  23896. */
  23897. grid.treeView = {};
  23898. grid.registerRowsProcessor(service.adjustSorting, 60);
  23899. /**
  23900. * @ngdoc object
  23901. * @name ui.grid.treeView.api:PublicApi
  23902. *
  23903. * @description Public Api for treeView feature
  23904. */
  23905. var publicApi = {
  23906. events: {
  23907. treeView: {
  23908. }
  23909. },
  23910. methods: {
  23911. treeView: {
  23912. }
  23913. }
  23914. };
  23915. grid.api.registerEventsFromObject(publicApi.events);
  23916. grid.api.registerMethodsFromObject(publicApi.methods);
  23917. },
  23918. defaultGridOptions: function (gridOptions) {
  23919. //default option to true unless it was explicitly set to false
  23920. /**
  23921. * @ngdoc object
  23922. * @name ui.grid.treeView.api:GridOptions
  23923. *
  23924. * @description GridOptions for treeView feature, these are available to be
  23925. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  23926. *
  23927. * Many tree options are set on treeBase, make sure to look at that feature in
  23928. * conjunction with these options.
  23929. */
  23930. /**
  23931. * @ngdoc object
  23932. * @name enableTreeView
  23933. * @propertyOf ui.grid.treeView.api:GridOptions
  23934. * @description Enable row tree view for entire grid.
  23935. * <br/>Defaults to true
  23936. */
  23937. gridOptions.enableTreeView = gridOptions.enableTreeView !== false;
  23938. },
  23939. /**
  23940. * @ngdoc function
  23941. * @name adjustSorting
  23942. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  23943. * @description Trees cannot be sorted the same as flat lists of rows -
  23944. * trees are sorted recursively within each level - so the children of each
  23945. * node are sorted, but not the full set of rows.
  23946. *
  23947. * To achieve this, we suppress the normal sorting by setting ignoreSort on
  23948. * each of the sort columns. When the treeBase rowsProcessor runs it will then
  23949. * unignore these, and will perform a recursive sort against the tree that it builds.
  23950. *
  23951. * @param {array} renderableRows the rows that we need to pass on through
  23952. * @returns {array} renderableRows that we passed on through
  23953. */
  23954. adjustSorting: function( renderableRows ) {
  23955. var grid = this;
  23956. grid.columns.forEach( function( column ){
  23957. if ( column.sort ){
  23958. column.sort.ignoreSort = true;
  23959. }
  23960. });
  23961. return renderableRows;
  23962. }
  23963. };
  23964. return service;
  23965. }]);
  23966. /**
  23967. * @ngdoc directive
  23968. * @name ui.grid.treeView.directive:uiGridTreeView
  23969. * @element div
  23970. * @restrict A
  23971. *
  23972. * @description Adds treeView features to grid
  23973. *
  23974. * @example
  23975. <example module="app">
  23976. <file name="app.js">
  23977. var app = angular.module('app', ['ui.grid', 'ui.grid.treeView']);
  23978. app.controller('MainCtrl', ['$scope', function ($scope) {
  23979. $scope.data = [
  23980. { name: 'Bob', title: 'CEO' },
  23981. { name: 'Frank', title: 'Lowly Developer' }
  23982. ];
  23983. $scope.columnDefs = [
  23984. {name: 'name', enableCellEdit: true},
  23985. {name: 'title', enableCellEdit: true}
  23986. ];
  23987. $scope.gridOptions = { columnDefs: $scope.columnDefs, data: $scope.data };
  23988. }]);
  23989. </file>
  23990. <file name="index.html">
  23991. <div ng-controller="MainCtrl">
  23992. <div ui-grid="gridOptions" ui-grid-tree-view></div>
  23993. </div>
  23994. </file>
  23995. </example>
  23996. */
  23997. module.directive('uiGridTreeView', ['uiGridTreeViewConstants', 'uiGridTreeViewService', '$templateCache',
  23998. function (uiGridTreeViewConstants, uiGridTreeViewService, $templateCache) {
  23999. return {
  24000. replace: true,
  24001. priority: 0,
  24002. require: '^uiGrid',
  24003. scope: false,
  24004. compile: function () {
  24005. return {
  24006. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  24007. if (uiGridCtrl.grid.options.enableTreeView !== false){
  24008. uiGridTreeViewService.initializeGrid(uiGridCtrl.grid, $scope);
  24009. }
  24010. },
  24011. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  24012. }
  24013. };
  24014. }
  24015. };
  24016. }]);
  24017. })();
  24018. (function () {
  24019. 'use strict';
  24020. /**
  24021. * @ngdoc overview
  24022. * @name ui.grid.validate
  24023. * @description
  24024. *
  24025. * # ui.grid.validate
  24026. *
  24027. * <div class="alert alert-warning" role="alert"><strong>Alpha</strong> This feature is in development. There will almost certainly be breaking api changes, or there are major outstanding bugs.</div>
  24028. *
  24029. * This module provides the ability to validate cells upon change.
  24030. *
  24031. * Design information:
  24032. * -------------------
  24033. *
  24034. * Validation is not based on angularjs validation, since it would work only when editing the field.
  24035. *
  24036. * Instead it adds custom properties to any field considered as invalid.
  24037. *
  24038. * <br/>
  24039. * <br/>
  24040. *
  24041. * <div doc-module-components="ui.grid.expandable"></div>
  24042. */
  24043. var module = angular.module('ui.grid.validate', ['ui.grid']);
  24044. /**
  24045. * @ngdoc service
  24046. * @name ui.grid.validate.service:uiGridValidateService
  24047. *
  24048. * @description Services for validation features
  24049. */
  24050. module.service('uiGridValidateService', ['$sce', '$q', '$http', 'i18nService', 'uiGridConstants', function ($sce, $q, $http, i18nService, uiGridConstants) {
  24051. var service = {
  24052. /**
  24053. * @ngdoc object
  24054. * @name validatorFactories
  24055. * @propertyOf ui.grid.validate.service:uiGridValidateService
  24056. * @description object containing all the factories used to validate data.<br/>
  24057. * These factories will be in the form <br/>
  24058. * ```
  24059. * {
  24060. * validatorFactory: function(argument) {
  24061. * return function(newValue, oldValue, rowEntity, colDef) {
  24062. * return true || false || promise
  24063. * }
  24064. * },
  24065. * messageFunction: function(argument) {
  24066. * return string
  24067. * }
  24068. * }
  24069. * ```
  24070. *
  24071. * Promises should return true or false as result according to the result of validation.
  24072. */
  24073. validatorFactories: {},
  24074. /**
  24075. * @ngdoc service
  24076. * @name setExternalFactoryFunction
  24077. * @methodOf ui.grid.validate.service:uiGridValidateService
  24078. * @description Adds a way to retrieve validators from an external service
  24079. * <p>Validators from this external service have a higher priority than default
  24080. * ones
  24081. * @param {function} externalFactoryFunction a function that accepts name and argument to pass to a
  24082. * validator factory and that returns an object with the same properties as
  24083. * you can see in {@link ui.grid.validate.service:uiGridValidateService#properties_validatorFactories validatorFactories}
  24084. */
  24085. setExternalFactoryFunction: function(externalFactoryFunction) {
  24086. service.externalFactoryFunction = externalFactoryFunction;
  24087. },
  24088. /**
  24089. * @ngdoc service
  24090. * @name clearExternalFactory
  24091. * @methodOf ui.grid.validate.service:uiGridValidateService
  24092. * @description Removes any link to external factory from this service
  24093. */
  24094. clearExternalFactory: function() {
  24095. delete service.externalFactoryFunction;
  24096. },
  24097. /**
  24098. * @ngdoc service
  24099. * @name getValidatorFromExternalFactory
  24100. * @methodOf ui.grid.validate.service:uiGridValidateService
  24101. * @description Retrieves a validator by executing a validatorFactory
  24102. * stored in an external service.
  24103. * @param {string} name the name of the validator to retrieve
  24104. * @param {object} argument an argument to pass to the validator factory
  24105. */
  24106. getValidatorFromExternalFactory: function(name, argument) {
  24107. return service.externalFactoryFunction(name, argument).validatorFactory(argument);
  24108. },
  24109. /**
  24110. * @ngdoc service
  24111. * @name getMessageFromExternalFactory
  24112. * @methodOf ui.grid.validate.service:uiGridValidateService
  24113. * @description Retrieves a message stored in an external service.
  24114. * @param {string} name the name of the validator
  24115. * @param {object} argument an argument to pass to the message function
  24116. */
  24117. getMessageFromExternalFactory: function(name, argument) {
  24118. return service.externalFactoryFunction(name, argument).messageFunction(argument);
  24119. },
  24120. /**
  24121. * @ngdoc service
  24122. * @name setValidator
  24123. * @methodOf ui.grid.validate.service:uiGridValidateService
  24124. * @description Adds a new validator to the service
  24125. * @param {string} name the name of the validator, must be unique
  24126. * @param {function} validatorFactory a factory that return a validatorFunction
  24127. * @param {function} messageFunction a function that return the error message
  24128. */
  24129. setValidator: function(name, validatorFactory, messageFunction) {
  24130. service.validatorFactories[name] = {
  24131. validatorFactory: validatorFactory,
  24132. messageFunction: messageFunction
  24133. };
  24134. },
  24135. /**
  24136. * @ngdoc service
  24137. * @name getValidator
  24138. * @methodOf ui.grid.validate.service:uiGridValidateService
  24139. * @description Returns a validator registered to the service
  24140. * or retrieved from the external factory
  24141. * @param {string} name the name of the validator to retrieve
  24142. * @param {object} argument an argument to pass to the validator factory
  24143. * @returns {object} the validator function
  24144. */
  24145. getValidator: function(name, argument) {
  24146. if (service.externalFactoryFunction) {
  24147. var validator = service.getValidatorFromExternalFactory(name, argument);
  24148. if (validator) {
  24149. return validator;
  24150. }
  24151. }
  24152. if (!service.validatorFactories[name]) {
  24153. throw ("Invalid validator name: " + name);
  24154. }
  24155. return service.validatorFactories[name].validatorFactory(argument);
  24156. },
  24157. /**
  24158. * @ngdoc service
  24159. * @name getMessage
  24160. * @methodOf ui.grid.validate.service:uiGridValidateService
  24161. * @description Returns the error message related to the validator
  24162. * @param {string} name the name of the validator
  24163. * @param {object} argument an argument to pass to the message function
  24164. * @returns {string} the error message related to the validator
  24165. */
  24166. getMessage: function(name, argument) {
  24167. if (service.externalFactoryFunction) {
  24168. var message = service.getMessageFromExternalFactory(name, argument);
  24169. if (message) {
  24170. return message;
  24171. }
  24172. }
  24173. return service.validatorFactories[name].messageFunction(argument);
  24174. },
  24175. /**
  24176. * @ngdoc service
  24177. * @name isInvalid
  24178. * @methodOf ui.grid.validate.service:uiGridValidateService
  24179. * @description Returns true if the cell (identified by rowEntity, colDef) is invalid
  24180. * @param {object} rowEntity the row entity of the cell
  24181. * @param {object} colDef the colDef of the cell
  24182. * @returns {boolean} true if the cell is invalid
  24183. */
  24184. isInvalid: function (rowEntity, colDef) {
  24185. return rowEntity['$$invalid'+colDef.name];
  24186. },
  24187. /**
  24188. * @ngdoc service
  24189. * @name setInvalid
  24190. * @methodOf ui.grid.validate.service:uiGridValidateService
  24191. * @description Makes the cell invalid by adding the proper field to the entity
  24192. * @param {object} rowEntity the row entity of the cell
  24193. * @param {object} colDef the colDef of the cell
  24194. */
  24195. setInvalid: function (rowEntity, colDef) {
  24196. rowEntity['$$invalid'+colDef.name] = true;
  24197. },
  24198. /**
  24199. * @ngdoc service
  24200. * @name setValid
  24201. * @methodOf ui.grid.validate.service:uiGridValidateService
  24202. * @description Makes the cell valid by removing the proper error field from the entity
  24203. * @param {object} rowEntity the row entity of the cell
  24204. * @param {object} colDef the colDef of the cell
  24205. */
  24206. setValid: function (rowEntity, colDef) {
  24207. delete rowEntity['$$invalid'+colDef.name];
  24208. },
  24209. /**
  24210. * @ngdoc service
  24211. * @name setError
  24212. * @methodOf ui.grid.validate.service:uiGridValidateService
  24213. * @description Adds the proper error to the entity errors field
  24214. * @param {object} rowEntity the row entity of the cell
  24215. * @param {object} colDef the colDef of the cell
  24216. * @param {string} validatorName the name of the validator that is failing
  24217. */
  24218. setError: function(rowEntity, colDef, validatorName) {
  24219. if (!rowEntity['$$errors'+colDef.name]) {
  24220. rowEntity['$$errors'+colDef.name] = {};
  24221. }
  24222. rowEntity['$$errors'+colDef.name][validatorName] = true;
  24223. },
  24224. /**
  24225. * @ngdoc service
  24226. * @name clearError
  24227. * @methodOf ui.grid.validate.service:uiGridValidateService
  24228. * @description Removes the proper error from the entity errors field
  24229. * @param {object} rowEntity the row entity of the cell
  24230. * @param {object} colDef the colDef of the cell
  24231. * @param {string} validatorName the name of the validator that is failing
  24232. */
  24233. clearError: function(rowEntity, colDef, validatorName) {
  24234. if (!rowEntity['$$errors'+colDef.name]) {
  24235. return;
  24236. }
  24237. if (validatorName in rowEntity['$$errors'+colDef.name]) {
  24238. delete rowEntity['$$errors'+colDef.name][validatorName];
  24239. }
  24240. },
  24241. /**
  24242. * @ngdoc function
  24243. * @name getErrorMessages
  24244. * @methodOf ui.grid.validate.service:uiGridValidateService
  24245. * @description returns an array of i18n-ed error messages.
  24246. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for
  24247. * @param {object} colDef the column whose errors we are looking for
  24248. * @returns {array} An array of strings containing all the error messages for the cell
  24249. */
  24250. getErrorMessages: function(rowEntity, colDef) {
  24251. var errors = [];
  24252. if (!rowEntity['$$errors'+colDef.name] || Object.keys(rowEntity['$$errors'+colDef.name]).length === 0) {
  24253. return errors;
  24254. }
  24255. Object.keys(rowEntity['$$errors'+colDef.name]).sort().forEach(function(validatorName) {
  24256. errors.push(service.getMessage(validatorName, colDef.validators[validatorName]));
  24257. });
  24258. return errors;
  24259. },
  24260. /**
  24261. * @ngdoc function
  24262. * @name getFormattedErrors
  24263. * @methodOf ui.grid.validate.service:uiGridValidateService
  24264. * @description returns the error i18n-ed and formatted in html to be shown inside the page.
  24265. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for
  24266. * @param {object} colDef the column whose errors we are looking for
  24267. * @returns {object} An object that can be used in a template (like a cellTemplate) to display the
  24268. * message inside the page (i.e. inside a div)
  24269. */
  24270. getFormattedErrors: function(rowEntity, colDef) {
  24271. var msgString = "";
  24272. var errors = service.getErrorMessages(rowEntity, colDef);
  24273. if (!errors.length) {
  24274. return;
  24275. }
  24276. errors.forEach(function(errorMsg) {
  24277. msgString += errorMsg + "<br/>";
  24278. });
  24279. return $sce.trustAsHtml('<p><b>' + i18nService.getSafeText('validate.error') + '</b></p>' + msgString );
  24280. },
  24281. /**
  24282. * @ngdoc function
  24283. * @name getTitleFormattedErrors
  24284. * @methodOf ui.grid.validate.service:uiGridValidateService
  24285. * @description returns the error i18n-ed and formatted in javaScript to be shown inside an html
  24286. * title attribute.
  24287. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for
  24288. * @param {object} colDef the column whose errors we are looking for
  24289. * @returns {object} An object that can be used in a template (like a cellTemplate) to display the
  24290. * message inside an html title attribute
  24291. */
  24292. getTitleFormattedErrors: function(rowEntity, colDef) {
  24293. var newLine = "\n";
  24294. var msgString = "";
  24295. var errors = service.getErrorMessages(rowEntity, colDef);
  24296. if (!errors.length) {
  24297. return;
  24298. }
  24299. errors.forEach(function(errorMsg) {
  24300. msgString += errorMsg + newLine;
  24301. });
  24302. return $sce.trustAsHtml(i18nService.getSafeText('validate.error') + newLine + msgString);
  24303. },
  24304. /**
  24305. * @ngdoc function
  24306. * @name getTitleFormattedErrors
  24307. * @methodOf ui.grid.validate.service:uiGridValidateService
  24308. * @description Executes all validators on a cell (identified by row entity and column definition) and sets or clears errors
  24309. * @param {object} rowEntity the row entity of the cell we want to run the validators on
  24310. * @param {object} colDef the column definition of the cell we want to run the validators on
  24311. * @param {object} newValue the value the user just entered
  24312. * @param {object} oldValue the value the field had before
  24313. */
  24314. runValidators: function(rowEntity, colDef, newValue, oldValue, grid) {
  24315. if (newValue === oldValue) {
  24316. // If the value has not changed we perform no validation
  24317. return;
  24318. }
  24319. if (typeof(colDef.name) === 'undefined' || !colDef.name) {
  24320. throw new Error('colDef.name is required to perform validation');
  24321. }
  24322. service.setValid(rowEntity, colDef);
  24323. var validateClosureFactory = function(rowEntity, colDef, validatorName) {
  24324. return function(value) {
  24325. if (!value) {
  24326. service.setInvalid(rowEntity, colDef);
  24327. service.setError(rowEntity, colDef, validatorName);
  24328. if (grid) {
  24329. grid.api.validate.raise.validationFailed(rowEntity, colDef, newValue, oldValue);
  24330. }
  24331. }
  24332. };
  24333. };
  24334. for (var validatorName in colDef.validators) {
  24335. service.clearError(rowEntity, colDef, validatorName);
  24336. var msg;
  24337. var validatorFunction = service.getValidator(validatorName, colDef.validators[validatorName]);
  24338. // We pass the arguments as oldValue, newValue so they are in the same order
  24339. // as ng-model validators (modelValue, viewValue)
  24340. $q.when(validatorFunction(oldValue, newValue, rowEntity, colDef))
  24341. .then(validateClosureFactory(rowEntity, colDef, validatorName)
  24342. );
  24343. }
  24344. },
  24345. /**
  24346. * @ngdoc function
  24347. * @name createDefaultValidators
  24348. * @methodOf ui.grid.validate.service:uiGridValidateService
  24349. * @description adds the basic validators to the list of service validators
  24350. */
  24351. createDefaultValidators: function() {
  24352. service.setValidator('minLength',
  24353. function (argument) {
  24354. return function (oldValue, newValue, rowEntity, colDef) {
  24355. if (newValue === undefined || newValue === null || newValue === '') {
  24356. return true;
  24357. }
  24358. return newValue.length >= argument;
  24359. };
  24360. },
  24361. function(argument) {
  24362. return i18nService.getSafeText('validate.minLength').replace('THRESHOLD', argument);
  24363. });
  24364. service.setValidator('maxLength',
  24365. function (argument) {
  24366. return function (oldValue, newValue, rowEntity, colDef) {
  24367. if (newValue === undefined || newValue === null || newValue === '') {
  24368. return true;
  24369. }
  24370. return newValue.length <= argument;
  24371. };
  24372. },
  24373. function(threshold) {
  24374. return i18nService.getSafeText('validate.maxLength').replace('THRESHOLD', threshold);
  24375. });
  24376. service.setValidator('required',
  24377. function (argument) {
  24378. return function (oldValue, newValue, rowEntity, colDef) {
  24379. if (argument) {
  24380. return !(newValue === undefined || newValue === null || newValue === '');
  24381. }
  24382. return true;
  24383. };
  24384. },
  24385. function(argument) {
  24386. return i18nService.getSafeText('validate.required');
  24387. });
  24388. },
  24389. initializeGrid: function (scope, grid) {
  24390. grid.validate = {
  24391. isInvalid: service.isInvalid,
  24392. getFormattedErrors: service.getFormattedErrors,
  24393. getTitleFormattedErrors: service.getTitleFormattedErrors,
  24394. runValidators: service.runValidators
  24395. };
  24396. /**
  24397. * @ngdoc object
  24398. * @name ui.grid.validate.api:PublicApi
  24399. *
  24400. * @description Public Api for validation feature
  24401. */
  24402. var publicApi = {
  24403. events: {
  24404. validate: {
  24405. /**
  24406. * @ngdoc event
  24407. * @name validationFailed
  24408. * @eventOf ui.grid.validate.api:PublicApi
  24409. * @description raised when one or more failure happened during validation
  24410. * <pre>
  24411. * gridApi.validate.on.validationFailed(scope, function(rowEntity, colDef, newValue, oldValue){...})
  24412. * </pre>
  24413. * @param {object} rowEntity the options.data element whose validation failed
  24414. * @param {object} colDef the column whose validation failed
  24415. * @param {object} newValue new value
  24416. * @param {object} oldValue old value
  24417. */
  24418. validationFailed: function (rowEntity, colDef, newValue, oldValue) {
  24419. }
  24420. }
  24421. },
  24422. methods: {
  24423. validate: {
  24424. /**
  24425. * @ngdoc function
  24426. * @name isInvalid
  24427. * @methodOf ui.grid.validate.api:PublicApi
  24428. * @description checks if a cell (identified by rowEntity, colDef) is invalid
  24429. * @param {object} rowEntity gridOptions.data[] array instance we want to check
  24430. * @param {object} colDef the column whose errors we want to check
  24431. * @returns {boolean} true if the cell value is not valid
  24432. */
  24433. isInvalid: function(rowEntity, colDef) {
  24434. return grid.validate.isInvalid(rowEntity, colDef);
  24435. },
  24436. /**
  24437. * @ngdoc function
  24438. * @name getErrorMessages
  24439. * @methodOf ui.grid.validate.api:PublicApi
  24440. * @description returns an array of i18n-ed error messages.
  24441. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for
  24442. * @param {object} colDef the column whose errors we are looking for
  24443. * @returns {array} An array of strings containing all the error messages for the cell
  24444. */
  24445. getErrorMessages: function (rowEntity, colDef) {
  24446. return grid.validate.getErrorMessages(rowEntity, colDef);
  24447. },
  24448. /**
  24449. * @ngdoc function
  24450. * @name getFormattedErrors
  24451. * @methodOf ui.grid.validate.api:PublicApi
  24452. * @description returns the error i18n-ed and formatted in html to be shown inside the page.
  24453. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for
  24454. * @param {object} colDef the column whose errors we are looking for
  24455. * @returns {object} An object that can be used in a template (like a cellTemplate) to display the
  24456. * message inside the page (i.e. inside a div)
  24457. */
  24458. getFormattedErrors: function (rowEntity, colDef) {
  24459. return grid.validate.getFormattedErrors(rowEntity, colDef);
  24460. },
  24461. /**
  24462. * @ngdoc function
  24463. * @name getTitleFormattedErrors
  24464. * @methodOf ui.grid.validate.api:PublicApi
  24465. * @description returns the error i18n-ed and formatted in javaScript to be shown inside an html
  24466. * title attribute.
  24467. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for
  24468. * @param {object} colDef the column whose errors we are looking for
  24469. * @returns {object} An object that can be used in a template (like a cellTemplate) to display the
  24470. * message inside an html title attribute
  24471. */
  24472. getTitleFormattedErrors: function (rowEntity, colDef) {
  24473. return grid.validate.getTitleFormattedErrors(rowEntity, colDef);
  24474. }
  24475. }
  24476. }
  24477. };
  24478. grid.api.registerEventsFromObject(publicApi.events);
  24479. grid.api.registerMethodsFromObject(publicApi.methods);
  24480. if (grid.edit) {
  24481. grid.api.edit.on.afterCellEdit(scope, function(rowEntity, colDef, newValue, oldValue) {
  24482. grid.validate.runValidators(rowEntity, colDef, newValue, oldValue, grid);
  24483. });
  24484. }
  24485. service.createDefaultValidators();
  24486. }
  24487. };
  24488. return service;
  24489. }]);
  24490. /**
  24491. * @ngdoc directive
  24492. * @name ui.grid.validate.directive:uiGridValidate
  24493. * @element div
  24494. * @restrict A
  24495. * @description Adds validating features to the ui-grid directive.
  24496. * @example
  24497. <example module="app">
  24498. <file name="app.js">
  24499. var app = angular.module('app', ['ui.grid', 'ui.grid.edit', 'ui.grid.validate']);
  24500. app.controller('MainCtrl', ['$scope', function ($scope) {
  24501. $scope.data = [
  24502. { name: 'Bob', title: 'CEO' },
  24503. { name: 'Frank', title: 'Lowly Developer' }
  24504. ];
  24505. $scope.columnDefs = [
  24506. {name: 'name', enableCellEdit: true, validators: {minLength: 3, maxLength: 9}, cellTemplate: 'ui-grid/cellTitleValidator'},
  24507. {name: 'title', enableCellEdit: true, validators: {required: true}, cellTemplate: 'ui-grid/cellTitleValidator'}
  24508. ];
  24509. }]);
  24510. </file>
  24511. <file name="index.html">
  24512. <div ng-controller="MainCtrl">
  24513. <div ui-grid="{ data: data, columnDefs: columnDefs }" ui-grid-edit ui-grid-validate></div>
  24514. </div>
  24515. </file>
  24516. </example>
  24517. */
  24518. module.directive('uiGridValidate', ['gridUtil', 'uiGridValidateService', function (gridUtil, uiGridValidateService) {
  24519. return {
  24520. priority: 0,
  24521. replace: true,
  24522. require: '^uiGrid',
  24523. scope: false,
  24524. compile: function () {
  24525. return {
  24526. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  24527. uiGridValidateService.initializeGrid($scope, uiGridCtrl.grid);
  24528. },
  24529. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  24530. }
  24531. };
  24532. }
  24533. };
  24534. }]);
  24535. })();
  24536. angular.module('ui.grid').run(['$templateCache', function($templateCache) {
  24537. 'use strict';
  24538. $templateCache.put('ui-grid/ui-grid-filter',
  24539. "<div class=\"ui-grid-filter-container\" ng-repeat=\"colFilter in col.filters\" ng-class=\"{'ui-grid-filter-cancel-button-hidden' : colFilter.disableCancelFilterButton === true }\"><div ng-if=\"colFilter.type !== 'select'\"><input type=\"text\" class=\"ui-grid-filter-input ui-grid-filter-input-{{$index}}\" ng-model=\"colFilter.term\" ng-attr-placeholder=\"{{colFilter.placeholder || ''}}\" aria-label=\"{{colFilter.ariaLabel || aria.defaultFilterLabel}}\"><div role=\"button\" class=\"ui-grid-filter-button\" ng-click=\"removeFilter(colFilter, $index)\" ng-if=\"!colFilter.disableCancelFilterButton\" ng-disabled=\"colFilter.term === undefined || colFilter.term === null || colFilter.term === ''\" ng-show=\"colFilter.term !== undefined && colFilter.term !== null && colFilter.term !== ''\"><i class=\"ui-grid-icon-cancel\" ui-grid-one-bind-aria-label=\"aria.removeFilter\">&nbsp;</i></div></div><div ng-if=\"colFilter.type === 'select'\"><select class=\"ui-grid-filter-select ui-grid-filter-input-{{$index}}\" ng-model=\"colFilter.term\" ng-attr-placeholder=\"{{colFilter.placeholder || aria.defaultFilterLabel}}\" aria-label=\"{{colFilter.ariaLabel || ''}}\" ng-options=\"option.value as option.label for option in colFilter.selectOptions\"><option value=\"\"></option></select><div role=\"button\" class=\"ui-grid-filter-button-select\" ng-click=\"removeFilter(colFilter, $index)\" ng-if=\"!colFilter.disableCancelFilterButton\" ng-disabled=\"colFilter.term === undefined || colFilter.term === null || colFilter.term === ''\" ng-show=\"colFilter.term !== undefined && colFilter.term != null\"><i class=\"ui-grid-icon-cancel\" ui-grid-one-bind-aria-label=\"aria.removeFilter\">&nbsp;</i></div></div></div>"
  24540. );
  24541. $templateCache.put('ui-grid/ui-grid-footer',
  24542. "<div class=\"ui-grid-footer-panel ui-grid-footer-aggregates-row\"><!-- tfooter --><div class=\"ui-grid-footer ui-grid-footer-viewport\"><div class=\"ui-grid-footer-canvas\"><div class=\"ui-grid-footer-cell-wrapper\" ng-style=\"colContainer.headerCellWrapperStyle()\"><div role=\"row\" class=\"ui-grid-footer-cell-row\"><div ui-grid-footer-cell role=\"gridcell\" ng-repeat=\"col in colContainer.renderedColumns track by col.uid\" col=\"col\" render-index=\"$index\" class=\"ui-grid-footer-cell ui-grid-clearfix\"></div></div></div></div></div></div>"
  24543. );
  24544. $templateCache.put('ui-grid/ui-grid-grid-footer',
  24545. "<div class=\"ui-grid-footer-info ui-grid-grid-footer\"><span>{{'search.totalItems' | t}} {{grid.rows.length}}</span> <span ng-if=\"grid.renderContainers.body.visibleRowCache.length !== grid.rows.length\" class=\"ngLabel\">({{\"search.showingItems\" | t}} {{grid.renderContainers.body.visibleRowCache.length}})</span></div>"
  24546. );
  24547. $templateCache.put('ui-grid/ui-grid-group-panel',
  24548. "<div class=\"ui-grid-group-panel\"><div ui-t=\"groupPanel.description\" class=\"description\" ng-show=\"groupings.length == 0\"></div><ul ng-show=\"groupings.length > 0\" class=\"ngGroupList\"><li class=\"ngGroupItem\" ng-repeat=\"group in configGroups\"><span class=\"ngGroupElement\"><span class=\"ngGroupName\">{{group.displayName}} <span ng-click=\"removeGroup($index)\" class=\"ngRemoveGroup\">x</span></span> <span ng-hide=\"$last\" class=\"ngGroupArrow\"></span></span></li></ul></div>"
  24549. );
  24550. $templateCache.put('ui-grid/ui-grid-header',
  24551. "<div role=\"rowgroup\" class=\"ui-grid-header\"><!-- theader --><div class=\"ui-grid-top-panel\"><div class=\"ui-grid-header-viewport\"><div class=\"ui-grid-header-canvas\"><div class=\"ui-grid-header-cell-wrapper\" ng-style=\"colContainer.headerCellWrapperStyle()\"><div role=\"row\" class=\"ui-grid-header-cell-row\"><div class=\"ui-grid-header-cell ui-grid-clearfix\" ng-repeat=\"col in colContainer.renderedColumns track by col.uid\" ui-grid-header-cell col=\"col\" render-index=\"$index\"></div></div></div></div></div></div></div>"
  24552. );
  24553. $templateCache.put('ui-grid/ui-grid-menu-button',
  24554. "<div class=\"ui-grid-menu-button\"><div role=\"button\" ui-grid-one-bind-id-grid=\"'grid-menu'\" class=\"ui-grid-icon-container\" ng-click=\"toggleMenu()\" aria-haspopup=\"true\"><i class=\"ui-grid-icon-menu\" ui-grid-one-bind-aria-label=\"i18n.aria.buttonLabel\">&nbsp;</i></div><div ui-grid-menu menu-items=\"menuItems\"></div></div>"
  24555. );
  24556. $templateCache.put('ui-grid/ui-grid-no-header',
  24557. "<div class=\"ui-grid-top-panel\"></div>"
  24558. );
  24559. $templateCache.put('ui-grid/ui-grid-row',
  24560. "<div ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.uid\" ui-grid-one-bind-id-grid=\"rowRenderIndex + '-' + col.uid + '-cell'\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" role=\"{{col.isRowHeader ? 'rowheader' : 'gridcell'}}\" ui-grid-cell></div>"
  24561. );
  24562. $templateCache.put('ui-grid/ui-grid',
  24563. "<div ui-i18n=\"en\" class=\"ui-grid\"><!-- TODO (c0bra): add \"scoped\" attr here, eventually? --><style ui-grid-style>.grid{{ grid.id }} {\n" +
  24564. " /* Styles for the grid */\n" +
  24565. " }\n" +
  24566. "\n" +
  24567. " .grid{{ grid.id }} .ui-grid-row, .grid{{ grid.id }} .ui-grid-cell, .grid{{ grid.id }} .ui-grid-cell .ui-grid-vertical-bar {\n" +
  24568. " height: {{ grid.options.rowHeight }}px;\n" +
  24569. " }\n" +
  24570. "\n" +
  24571. " .grid{{ grid.id }} .ui-grid-row:last-child .ui-grid-cell {\n" +
  24572. " border-bottom-width: {{ ((grid.getTotalRowHeight() < grid.getViewportHeight()) && '1') || '0' }}px;\n" +
  24573. " }\n" +
  24574. "\n" +
  24575. " {{ grid.verticalScrollbarStyles }}\n" +
  24576. " {{ grid.horizontalScrollbarStyles }}\n" +
  24577. "\n" +
  24578. " /*\n" +
  24579. " .ui-grid[dir=rtl] .ui-grid-viewport {\n" +
  24580. " padding-left: {{ grid.verticalScrollbarWidth }}px;\n" +
  24581. " }\n" +
  24582. " */\n" +
  24583. "\n" +
  24584. " {{ grid.customStyles }}</style><div class=\"ui-grid-contents-wrapper\"><div ui-grid-menu-button ng-if=\"grid.options.enableGridMenu\"></div><div ng-if=\"grid.hasLeftContainer()\" style=\"width: 0\" ui-grid-pinned-container=\"'left'\"></div><div ui-grid-render-container container-id=\"'body'\" col-container-name=\"'body'\" row-container-name=\"'body'\" bind-scroll-horizontal=\"true\" bind-scroll-vertical=\"true\" enable-horizontal-scrollbar=\"grid.options.enableHorizontalScrollbar\" enable-vertical-scrollbar=\"grid.options.enableVerticalScrollbar\"></div><div ng-if=\"grid.hasRightContainer()\" style=\"width: 0\" ui-grid-pinned-container=\"'right'\"></div><div ui-grid-grid-footer ng-if=\"grid.options.showGridFooter\"></div><div ui-grid-column-menu ng-if=\"grid.options.enableColumnMenus\"></div><div ng-transclude></div></div></div>"
  24585. );
  24586. $templateCache.put('ui-grid/uiGridCell',
  24587. "<div class=\"ui-grid-cell-contents\" title=\"TOOLTIP\">{{COL_FIELD CUSTOM_FILTERS}}</div>"
  24588. );
  24589. $templateCache.put('ui-grid/uiGridColumnMenu',
  24590. "<div class=\"ui-grid-column-menu\"><div ui-grid-menu menu-items=\"menuItems\"><!-- <div class=\"ui-grid-column-menu\">\n" +
  24591. " <div class=\"inner\" ng-show=\"menuShown\">\n" +
  24592. " <ul>\n" +
  24593. " <div ng-show=\"grid.options.enableSorting\">\n" +
  24594. " <li ng-click=\"sortColumn($event, asc)\" ng-class=\"{ 'selected' : col.sort.direction == asc }\"><i class=\"ui-grid-icon-sort-alt-up\"></i> Sort Ascending</li>\n" +
  24595. " <li ng-click=\"sortColumn($event, desc)\" ng-class=\"{ 'selected' : col.sort.direction == desc }\"><i class=\"ui-grid-icon-sort-alt-down\"></i> Sort Descending</li>\n" +
  24596. " <li ng-show=\"col.sort.direction\" ng-click=\"unsortColumn()\"><i class=\"ui-grid-icon-cancel\"></i> Remove Sort</li>\n" +
  24597. " </div>\n" +
  24598. " </ul>\n" +
  24599. " </div>\n" +
  24600. " </div> --></div></div>"
  24601. );
  24602. $templateCache.put('ui-grid/uiGridFooterCell',
  24603. "<div class=\"ui-grid-cell-contents\" col-index=\"renderIndex\"><div>{{ col.getAggregationText() + ( col.getAggregationValue() CUSTOM_FILTERS ) }}</div></div>"
  24604. );
  24605. $templateCache.put('ui-grid/uiGridHeaderCell',
  24606. "<div role=\"columnheader\" ng-class=\"{ 'sortable': sortable }\" ui-grid-one-bind-aria-labelledby-grid=\"col.uid + '-header-text ' + col.uid + '-sortdir-text'\" aria-sort=\"{{col.sort.direction == asc ? 'ascending' : ( col.sort.direction == desc ? 'descending' : (!col.sort.direction ? 'none' : 'other'))}}\"><div role=\"button\" tabindex=\"0\" class=\"ui-grid-cell-contents ui-grid-header-cell-primary-focus\" col-index=\"renderIndex\" title=\"TOOLTIP\"><span class=\"ui-grid-header-cell-label\" ui-grid-one-bind-id-grid=\"col.uid + '-header-text'\">{{ col.displayName CUSTOM_FILTERS }}</span> <span ui-grid-one-bind-id-grid=\"col.uid + '-sortdir-text'\" ui-grid-visible=\"col.sort.direction\" aria-label=\"{{getSortDirectionAriaLabel()}}\"><i ng-class=\"{ 'ui-grid-icon-up-dir': col.sort.direction == asc, 'ui-grid-icon-down-dir': col.sort.direction == desc, 'ui-grid-icon-blank': !col.sort.direction }\" title=\"{{isSortPriorityVisible() ? i18n.headerCell.priority + ' ' + ( col.sort.priority + 1 ) : null}}\" aria-hidden=\"true\"></i> <sub ui-grid-visible=\"isSortPriorityVisible()\" class=\"ui-grid-sort-priority-number\">{{col.sort.priority + 1}}</sub></span></div><div role=\"button\" tabindex=\"0\" ui-grid-one-bind-id-grid=\"col.uid + '-menu-button'\" class=\"ui-grid-column-menu-button\" ng-if=\"grid.options.enableColumnMenus && !col.isRowHeader && col.colDef.enableColumnMenu !== false\" ng-click=\"toggleMenu($event)\" ng-class=\"{'ui-grid-column-menu-button-last-col': isLastCol}\" ui-grid-one-bind-aria-label=\"i18n.headerCell.aria.columnMenuButtonLabel\" aria-haspopup=\"true\"><i class=\"ui-grid-icon-angle-down\" aria-hidden=\"true\">&nbsp;</i></div><div ui-grid-filter></div></div>"
  24607. );
  24608. $templateCache.put('ui-grid/uiGridMenu',
  24609. "<div class=\"ui-grid-menu\" ng-if=\"shown\"><style ui-grid-style>{{dynamicStyles}}</style><div class=\"ui-grid-menu-mid\" ng-show=\"shownMid\"><div class=\"ui-grid-menu-inner\"><ul role=\"menu\" class=\"ui-grid-menu-items\"><li ng-repeat=\"item in menuItems\" role=\"menuitem\" ui-grid-menu-item ui-grid-one-bind-id=\"'menuitem-'+$index\" action=\"item.action\" name=\"item.title\" active=\"item.active\" icon=\"item.icon\" shown=\"item.shown\" context=\"item.context\" template-url=\"item.templateUrl\" leave-open=\"item.leaveOpen\" screen-reader-only=\"item.screenReaderOnly\"></li></ul></div></div></div>"
  24610. );
  24611. $templateCache.put('ui-grid/uiGridMenuItem',
  24612. "<button type=\"button\" class=\"ui-grid-menu-item\" ng-click=\"itemAction($event, title)\" ng-show=\"itemShown()\" ng-class=\"{ 'ui-grid-menu-item-active': active(), 'ui-grid-sr-only': (!focus && screenReaderOnly) }\" aria-pressed=\"{{active()}}\" tabindex=\"0\" ng-focus=\"focus=true\" ng-blur=\"focus=false\"><i ng-class=\"icon\" aria-hidden=\"true\">&nbsp;</i> {{ name }}</button>"
  24613. );
  24614. $templateCache.put('ui-grid/uiGridRenderContainer',
  24615. "<div role=\"grid\" ui-grid-one-bind-id-grid=\"'grid-container'\" class=\"ui-grid-render-container\" ng-style=\"{ 'margin-left': colContainer.getMargin('left') + 'px', 'margin-right': colContainer.getMargin('right') + 'px' }\"><!-- All of these dom elements are replaced in place --><div ui-grid-header></div><div ui-grid-viewport></div><div ng-if=\"colContainer.needsHScrollbarPlaceholder()\" class=\"ui-grid-scrollbar-placeholder\" ng-style=\"{height:colContainer.grid.scrollbarHeight + 'px'}\"></div><ui-grid-footer ng-if=\"grid.options.showColumnFooter\"></ui-grid-footer></div>"
  24616. );
  24617. $templateCache.put('ui-grid/uiGridViewport',
  24618. "<div role=\"rowgroup\" class=\"ui-grid-viewport\" ng-style=\"colContainer.getViewportStyle()\"><!-- tbody --><div class=\"ui-grid-canvas\"><div ng-repeat=\"(rowRenderIndex, row) in rowContainer.renderedRows track by $index\" class=\"ui-grid-row\" ng-style=\"Viewport.rowStyle(rowRenderIndex)\"><div role=\"row\" ui-grid-row=\"row\" row-render-index=\"rowRenderIndex\"></div></div></div></div>"
  24619. );
  24620. $templateCache.put('ui-grid/cellEditor',
  24621. "<div><form name=\"inputForm\"><input type=\"INPUT_TYPE\" ng-class=\"'colt' + col.uid\" ui-grid-editor ng-model=\"MODEL_COL_FIELD\"></form></div>"
  24622. );
  24623. $templateCache.put('ui-grid/dropdownEditor',
  24624. "<div><form name=\"inputForm\"><select ng-class=\"'colt' + col.uid\" ui-grid-edit-dropdown ng-model=\"MODEL_COL_FIELD\" ng-options=\"field[editDropdownIdLabel] as field[editDropdownValueLabel] CUSTOM_FILTERS for field in editDropdownOptionsArray\"></select></form></div>"
  24625. );
  24626. $templateCache.put('ui-grid/fileChooserEditor',
  24627. "<div><form name=\"inputForm\"><input ng-class=\"'colt' + col.uid\" ui-grid-edit-file-chooser type=\"file\" id=\"files\" name=\"files[]\" ng-model=\"MODEL_COL_FIELD\"></form></div>"
  24628. );
  24629. $templateCache.put('ui-grid/expandableRow',
  24630. "<div ui-grid-expandable-row ng-if=\"expandableRow.shouldRenderExpand()\" class=\"expandableRow\" style=\"float:left; margin-top: 1px; margin-bottom: 1px\" ng-style=\"{width: (grid.renderContainers.body.getCanvasWidth()) + 'px', height: row.expandedRowHeight + 'px'}\"></div>"
  24631. );
  24632. $templateCache.put('ui-grid/expandableRowHeader',
  24633. "<div class=\"ui-grid-row-header-cell ui-grid-expandable-buttons-cell\"><div class=\"ui-grid-cell-contents\"><i ng-class=\"{ 'ui-grid-icon-plus-squared' : !row.isExpanded, 'ui-grid-icon-minus-squared' : row.isExpanded }\" ng-click=\"grid.api.expandable.toggleRowExpansion(row.entity)\"></i></div></div>"
  24634. );
  24635. $templateCache.put('ui-grid/expandableScrollFiller',
  24636. "<div ng-if=\"expandableRow.shouldRenderFiller()\" ng-class=\"{scrollFiller:true, scrollFillerClass:(colContainer.name === 'body')}\" ng-style=\"{ width: (grid.getViewportWidth()) + 'px', height: row.expandedRowHeight + 2 + 'px', 'margin-left': grid.options.rowHeader.rowHeaderWidth + 'px' }\"><i class=\"ui-grid-icon-spin5 ui-grid-animate-spin\" ng-style=\"{'margin-top': ( row.expandedRowHeight/2 - 5) + 'px', 'margin-left' : ((grid.getViewportWidth() - grid.options.rowHeader.rowHeaderWidth)/2 - 5) + 'px'}\"></i></div>"
  24637. );
  24638. $templateCache.put('ui-grid/expandableTopRowHeader',
  24639. "<div class=\"ui-grid-row-header-cell ui-grid-expandable-buttons-cell\"><div class=\"ui-grid-cell-contents\"><i ng-class=\"{ 'ui-grid-icon-plus-squared' : !grid.expandable.expandedAll, 'ui-grid-icon-minus-squared' : grid.expandable.expandedAll }\" ng-click=\"grid.api.expandable.toggleAllRows()\"></i></div></div>"
  24640. );
  24641. $templateCache.put('ui-grid/csvLink',
  24642. "<span class=\"ui-grid-exporter-csv-link-span\"><a href=\"data:text/csv;charset=UTF-8,CSV_CONTENT\" download=\"FILE_NAME\">LINK_LABEL</a></span>"
  24643. );
  24644. $templateCache.put('ui-grid/importerMenuItem',
  24645. "<li class=\"ui-grid-menu-item\"><form><input class=\"ui-grid-importer-file-chooser\" type=\"file\" id=\"files\" name=\"files[]\"></form></li>"
  24646. );
  24647. $templateCache.put('ui-grid/importerMenuItemContainer',
  24648. "<div ui-grid-importer-menu-item></div>"
  24649. );
  24650. $templateCache.put('ui-grid/pagination',
  24651. "<div role=\"contentinfo\" class=\"ui-grid-pager-panel\" ui-grid-pager ng-show=\"grid.options.enablePaginationControls\"><div role=\"navigation\" class=\"ui-grid-pager-container\"><div role=\"menubar\" class=\"ui-grid-pager-control\"><button type=\"button\" role=\"menuitem\" class=\"ui-grid-pager-first\" ui-grid-one-bind-title=\"aria.pageToFirst\" ui-grid-one-bind-aria-label=\"aria.pageToFirst\" ng-click=\"pageFirstPageClick()\" ng-disabled=\"cantPageBackward()\"><div ng-class=\"grid.isRTL() ? 'last-triangle' : 'first-triangle'\"><div ng-class=\"grid.isRTL() ? 'last-bar-rtl' : 'first-bar'\"></div></div></button> <button type=\"button\" role=\"menuitem\" class=\"ui-grid-pager-previous\" ui-grid-one-bind-title=\"aria.pageBack\" ui-grid-one-bind-aria-label=\"aria.pageBack\" ng-click=\"pagePreviousPageClick()\" ng-disabled=\"cantPageBackward()\"><div ng-class=\"grid.isRTL() ? 'last-triangle prev-triangle' : 'first-triangle prev-triangle'\"></div></button> <input type=\"number\" ui-grid-one-bind-title=\"aria.pageSelected\" ui-grid-one-bind-aria-label=\"aria.pageSelected\" class=\"ui-grid-pager-control-input\" ng-model=\"grid.options.paginationCurrentPage\" min=\"1\" max=\"{{ paginationApi.getTotalPages() }}\" required> <span class=\"ui-grid-pager-max-pages-number\" ng-show=\"paginationApi.getTotalPages() > 0\"><abbr ui-grid-one-bind-title=\"paginationOf\">/</abbr> {{ paginationApi.getTotalPages() }}</span> <button type=\"button\" role=\"menuitem\" class=\"ui-grid-pager-next\" ui-grid-one-bind-title=\"aria.pageForward\" ui-grid-one-bind-aria-label=\"aria.pageForward\" ng-click=\"pageNextPageClick()\" ng-disabled=\"cantPageForward()\"><div ng-class=\"grid.isRTL() ? 'first-triangle next-triangle' : 'last-triangle next-triangle'\"></div></button> <button type=\"button\" role=\"menuitem\" class=\"ui-grid-pager-last\" ui-grid-one-bind-title=\"aria.pageToLast\" ui-grid-one-bind-aria-label=\"aria.pageToLast\" ng-click=\"pageLastPageClick()\" ng-disabled=\"cantPageToLast()\"><div ng-class=\"grid.isRTL() ? 'first-triangle' : 'last-triangle'\"><div ng-class=\"grid.isRTL() ? 'first-bar-rtl' : 'last-bar'\"></div></div></button></div><div class=\"ui-grid-pager-row-count-picker\" ng-if=\"grid.options.paginationPageSizes.length > 1\"><select ui-grid-one-bind-aria-labelledby-grid=\"'items-per-page-label'\" ng-model=\"grid.options.paginationPageSize\" ng-options=\"o as o for o in grid.options.paginationPageSizes\"></select><span ui-grid-one-bind-id-grid=\"'items-per-page-label'\" class=\"ui-grid-pager-row-count-label\">&nbsp;{{sizesLabel}}</span></div><span ng-if=\"grid.options.paginationPageSizes.length <= 1\" class=\"ui-grid-pager-row-count-label\">{{grid.options.paginationPageSize}}&nbsp;{{sizesLabel}}</span></div><div class=\"ui-grid-pager-count-container\"><div class=\"ui-grid-pager-count\"><span ng-show=\"grid.options.totalItems > 0\">{{showingLow}} <abbr ui-grid-one-bind-title=\"paginationThrough\">-</abbr> {{showingHigh}} {{paginationOf}} {{grid.options.totalItems}} {{totalItemsLabel}}</span></div></div></div>"
  24652. );
  24653. $templateCache.put('ui-grid/columnResizer',
  24654. "<div ui-grid-column-resizer ng-if=\"grid.options.enableColumnResizing\" class=\"ui-grid-column-resizer\" col=\"col\" position=\"right\" render-index=\"renderIndex\" unselectable=\"on\"></div>"
  24655. );
  24656. $templateCache.put('ui-grid/gridFooterSelectedItems',
  24657. "<span ng-if=\"grid.selection.selectedCount !== 0 && grid.options.enableFooterTotalSelected\">({{\"search.selectedItems\" | t}} {{grid.selection.selectedCount}})</span>"
  24658. );
  24659. $templateCache.put('ui-grid/selectionHeaderCell',
  24660. "<div><!-- <div class=\"ui-grid-vertical-bar\">&nbsp;</div> --><div class=\"ui-grid-cell-contents\" col-index=\"renderIndex\"><ui-grid-selection-select-all-buttons ng-if=\"grid.options.enableSelectAll\"></ui-grid-selection-select-all-buttons></div></div>"
  24661. );
  24662. $templateCache.put('ui-grid/selectionRowHeader',
  24663. "<div class=\"ui-grid-disable-selection\"><div class=\"ui-grid-cell-contents\"><ui-grid-selection-row-header-buttons></ui-grid-selection-row-header-buttons></div></div>"
  24664. );
  24665. $templateCache.put('ui-grid/selectionRowHeaderButtons',
  24666. "<div class=\"ui-grid-selection-row-header-buttons ui-grid-icon-ok\" ng-class=\"{'ui-grid-row-selected': row.isSelected}\" ng-click=\"selectButtonClick(row, $event)\">&nbsp;</div>"
  24667. );
  24668. $templateCache.put('ui-grid/selectionSelectAllButtons',
  24669. "<div class=\"ui-grid-selection-row-header-buttons ui-grid-icon-ok\" ng-class=\"{'ui-grid-all-selected': grid.selection.selectAll}\" ng-click=\"headerButtonClick($event)\"></div>"
  24670. );
  24671. $templateCache.put('ui-grid/treeBaseExpandAllButtons',
  24672. "<div class=\"ui-grid-tree-base-row-header-buttons\" ng-class=\"{'ui-grid-icon-minus-squared': grid.treeBase.numberLevels > 0 && grid.treeBase.expandAll, 'ui-grid-icon-plus-squared': grid.treeBase.numberLevels > 0 && !grid.treeBase.expandAll}\" ng-click=\"headerButtonClick($event)\"></div>"
  24673. );
  24674. $templateCache.put('ui-grid/treeBaseHeaderCell',
  24675. "<div><div class=\"ui-grid-cell-contents\" col-index=\"renderIndex\"><ui-grid-tree-base-expand-all-buttons ng-if=\"grid.options.enableExpandAll\"></ui-grid-tree-base-expand-all-buttons></div></div>"
  24676. );
  24677. $templateCache.put('ui-grid/treeBaseRowHeader',
  24678. "<div class=\"ui-grid-cell-contents\"><ui-grid-tree-base-row-header-buttons></ui-grid-tree-base-row-header-buttons></div>"
  24679. );
  24680. $templateCache.put('ui-grid/treeBaseRowHeaderButtons',
  24681. "<div class=\"ui-grid-tree-base-row-header-buttons\" ng-class=\"{'ui-grid-tree-base-header': row.treeLevel > -1 }\" ng-click=\"treeButtonClick(row, $event)\"><i ng-class=\"{'ui-grid-icon-minus-squared': ( ( grid.options.showTreeExpandNoChildren && row.treeLevel > -1 ) || ( row.treeNode.children && row.treeNode.children.length > 0 ) ) && row.treeNode.state === 'expanded', 'ui-grid-icon-plus-squared': ( ( grid.options.showTreeExpandNoChildren && row.treeLevel > -1 ) || ( row.treeNode.children && row.treeNode.children.length > 0 ) ) && row.treeNode.state === 'collapsed'}\" ng-style=\"{'padding-left': grid.options.treeIndent * row.treeLevel + 'px'}\"></i> &nbsp;</div>"
  24682. );
  24683. $templateCache.put('ui-grid/cellTitleValidator',
  24684. "<div class=\"ui-grid-cell-contents\" ng-class=\"{invalid:grid.validate.isInvalid(row.entity,col.colDef)}\" title=\"{{grid.validate.getTitleFormattedErrors(row.entity,col.colDef)}}\">{{COL_FIELD CUSTOM_FILTERS}}</div>"
  24685. );
  24686. $templateCache.put('ui-grid/cellTooltipValidator',
  24687. "<div class=\"ui-grid-cell-contents\" ng-class=\"{invalid:grid.validate.isInvalid(row.entity,col.colDef)}\" tooltip-html-unsafe=\"{{grid.validate.getFormattedErrors(row.entity,col.colDef)}}\" tooltip-enable=\"grid.validate.isInvalid(row.entity,col.colDef)\" tooltip-append-to-body=\"true\" tooltip-placement=\"top\" title=\"TOOLTIP\">{{COL_FIELD CUSTOM_FILTERS}}</div>"
  24688. );
  24689. }]);