ui-grid.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086
  1. /*!
  2. * ui-grid - v4.4.6 - 2018-04-06
  3. * Copyright (c) 2018 ; 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. /**
  13. * @ngdoc object
  14. * @name ui.grid.service:uiGridConstants
  15. * @description Constants for use across many grid features
  16. *
  17. */
  18. angular.module('ui.grid').constant('uiGridConstants', {
  19. LOG_DEBUG_MESSAGES: true,
  20. LOG_WARN_MESSAGES: true,
  21. LOG_ERROR_MESSAGES: true,
  22. CUSTOM_FILTERS: /CUSTOM_FILTERS/g,
  23. COL_FIELD: /COL_FIELD/g,
  24. MODEL_COL_FIELD: /MODEL_COL_FIELD/g,
  25. TOOLTIP: /title=\"TOOLTIP\"/g,
  26. DISPLAY_CELL_TEMPLATE: /DISPLAY_CELL_TEMPLATE/g,
  27. TEMPLATE_REGEXP: /<.+>/,
  28. FUNC_REGEXP: /(\([^)]*\))?$/,
  29. DOT_REGEXP: /\./g,
  30. APOS_REGEXP: /'/g,
  31. BRACKET_REGEXP: /^(.*)((?:\s*\[\s*\d+\s*\]\s*)|(?:\s*\[\s*"(?:[^"\\]|\\.)*"\s*\]\s*)|(?:\s*\[\s*'(?:[^'\\]|\\.)*'\s*\]\s*))(.*)$/,
  32. COL_CLASS_PREFIX: 'ui-grid-col',
  33. ENTITY_BINDING: '$$this',
  34. events: {
  35. GRID_SCROLL: 'uiGridScroll',
  36. COLUMN_MENU_SHOWN: 'uiGridColMenuShown',
  37. ITEM_DRAGGING: 'uiGridItemDragStart', // For any item being dragged
  38. COLUMN_HEADER_CLICK: 'uiGridColumnHeaderClick'
  39. },
  40. // copied from http://www.lsauer.com/2011/08/javascript-keymap-keycodes-in-json.html
  41. keymap: {
  42. TAB: 9,
  43. STRG: 17,
  44. CAPSLOCK: 20,
  45. CTRL: 17,
  46. CTRLRIGHT: 18,
  47. CTRLR: 18,
  48. SHIFT: 16,
  49. RETURN: 13,
  50. ENTER: 13,
  51. BACKSPACE: 8,
  52. BCKSP: 8,
  53. ALT: 18,
  54. ALTR: 17,
  55. ALTRIGHT: 17,
  56. SPACE: 32,
  57. WIN: 91,
  58. MAC: 91,
  59. FN: null,
  60. PG_UP: 33,
  61. PG_DOWN: 34,
  62. UP: 38,
  63. DOWN: 40,
  64. LEFT: 37,
  65. RIGHT: 39,
  66. ESC: 27,
  67. DEL: 46,
  68. F1: 112,
  69. F2: 113,
  70. F3: 114,
  71. F4: 115,
  72. F5: 116,
  73. F6: 117,
  74. F7: 118,
  75. F8: 119,
  76. F9: 120,
  77. F10: 121,
  78. F11: 122,
  79. F12: 123
  80. },
  81. /**
  82. * @ngdoc object
  83. * @name ASC
  84. * @propertyOf ui.grid.service:uiGridConstants
  85. * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort} and
  86. * {@link ui.grid.class:GridOptions.columnDef#properties_sortDirectionCycle columnDef.sortDirectionCycle}
  87. * to configure the sorting direction of the column
  88. */
  89. ASC: 'asc',
  90. /**
  91. * @ngdoc object
  92. * @name DESC
  93. * @propertyOf ui.grid.service:uiGridConstants
  94. * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort} and
  95. * {@link ui.grid.class:GridOptions.columnDef#properties_sortDirectionCycle columnDef.sortDirectionCycle}
  96. * to configure the sorting direction of the column
  97. */
  98. DESC: 'desc',
  99. /**
  100. * @ngdoc object
  101. * @name filter
  102. * @propertyOf ui.grid.service:uiGridConstants
  103. * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_filter columnDef.filter}
  104. * to configure filtering on the column
  105. *
  106. * `SELECT` and `INPUT` are used with the `type` property of the filter, the rest are used to specify
  107. * one of the built-in conditions.
  108. *
  109. * Available `condition` options are:
  110. * - `uiGridConstants.filter.STARTS_WITH`
  111. * - `uiGridConstants.filter.ENDS_WITH`
  112. * - `uiGridConstants.filter.CONTAINS`
  113. * - `uiGridConstants.filter.GREATER_THAN`
  114. * - `uiGridConstants.filter.GREATER_THAN_OR_EQUAL`
  115. * - `uiGridConstants.filter.LESS_THAN`
  116. * - `uiGridConstants.filter.LESS_THAN_OR_EQUAL`
  117. * - `uiGridConstants.filter.NOT_EQUAL`
  118. *
  119. *
  120. * Available `type` options are:
  121. * - `uiGridConstants.filter.SELECT` - use a dropdown box for the cell header filter field
  122. * - `uiGridConstants.filter.INPUT` - use a text box for the cell header filter field
  123. */
  124. filter: {
  125. STARTS_WITH: 2,
  126. ENDS_WITH: 4,
  127. EXACT: 8,
  128. CONTAINS: 16,
  129. GREATER_THAN: 32,
  130. GREATER_THAN_OR_EQUAL: 64,
  131. LESS_THAN: 128,
  132. LESS_THAN_OR_EQUAL: 256,
  133. NOT_EQUAL: 512,
  134. SELECT: 'select',
  135. INPUT: 'input'
  136. },
  137. /**
  138. * @ngdoc object
  139. * @name aggregationTypes
  140. * @propertyOf ui.grid.service:uiGridConstants
  141. * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_aggregationType columnDef.aggregationType}
  142. * to specify the type of built-in aggregation the column should use.
  143. *
  144. * Available options are:
  145. * - `uiGridConstants.aggregationTypes.sum` - add the values in this column to produce the aggregated value
  146. * - `uiGridConstants.aggregationTypes.count` - count the number of rows to produce the aggregated value
  147. * - `uiGridConstants.aggregationTypes.avg` - average the values in this column to produce the aggregated value
  148. * - `uiGridConstants.aggregationTypes.min` - use the minimum value in this column as the aggregated value
  149. * - `uiGridConstants.aggregationTypes.max` - use the maximum value in this column as the aggregated value
  150. */
  151. aggregationTypes: {
  152. sum: 2,
  153. count: 4,
  154. avg: 8,
  155. min: 16,
  156. max: 32
  157. },
  158. /**
  159. * @ngdoc array
  160. * @name CURRENCY_SYMBOLS
  161. * @propertyOf ui.grid.service:uiGridConstants
  162. * @description A list of all presently circulating currency symbols that was copied from
  163. * https://en.wikipedia.org/wiki/Currency_symbol#List_of_presently-circulating_currency_symbols
  164. *
  165. * Can be used on {@link ui.grid.class:rowSorter} to create a number string regex that ignores currency symbols.
  166. */
  167. CURRENCY_SYMBOLS: ['¤', '؋', 'Ar', 'Ƀ', '฿', 'B/.', 'Br', 'Bs.', 'Bs.F.', 'GH₵', '¢', 'c', 'Ch.', '₡', 'C$', 'D', 'ден',
  168. 'دج', '.د.ب', 'د.ع', 'JD', 'د.ك', 'ل.د', 'дин', 'د.ت', 'د.م.', 'د.إ', 'Db', '$', '₫', 'Esc', '€', 'ƒ', 'Ft', 'FBu',
  169. 'FCFA', 'CFA', 'Fr', 'FRw', 'G', 'gr', '₲', 'h', '₴', '₭', 'Kč', 'kr', 'kn', 'MK', 'ZK', 'Kz', 'K', 'L', 'Le', 'лв',
  170. 'E', 'lp', 'M', 'KM', 'MT', '₥', 'Nfk', '₦', 'Nu.', 'UM', 'T$', 'MOP$', '₱', 'Pt.', '£', 'ج.م.', 'LL', 'LS', 'P', 'Q',
  171. 'q', 'R', 'R$', 'ر.ع.', 'ر.ق', 'ر.س', '៛', 'RM', 'p', 'Rf.', '₹', '₨', 'SRe', 'Rp', '₪', 'Ksh', 'Sh.So.', 'USh', 'S/',
  172. 'SDR', 'сом', '৳ ', 'WS$', '₮', 'VT', '₩', '¥', 'zł'],
  173. /**
  174. * @ngdoc object
  175. * @name scrollDirection
  176. * @propertyOf ui.grid.service:uiGridConstants
  177. * @description Set on {@link ui.grid.class:Grid#properties_scrollDirection Grid.scrollDirection},
  178. * to indicate the direction the grid is currently scrolling in
  179. *
  180. * Available options are:
  181. * - `uiGridConstants.scrollDirection.UP` - set when the grid is scrolling up
  182. * - `uiGridConstants.scrollDirection.DOWN` - set when the grid is scrolling down
  183. * - `uiGridConstants.scrollDirection.LEFT` - set when the grid is scrolling left
  184. * - `uiGridConstants.scrollDirection.RIGHT` - set when the grid is scrolling right
  185. * - `uiGridConstants.scrollDirection.NONE` - set when the grid is not scrolling, this is the default
  186. */
  187. scrollDirection: {
  188. UP: 'up',
  189. DOWN: 'down',
  190. LEFT: 'left',
  191. RIGHT: 'right',
  192. NONE: 'none'
  193. },
  194. /**
  195. * @ngdoc object
  196. * @name dataChange
  197. * @propertyOf ui.grid.service:uiGridConstants
  198. * @description Used with {@link ui.grid.core.api:PublicApi#methods_notifyDataChange PublicApi.notifyDataChange},
  199. * {@link ui.grid.class:Grid#methods_callDataChangeCallbacks Grid.callDataChangeCallbacks},
  200. * and {@link ui.grid.class:Grid#methods_registerDataChangeCallback Grid.registerDataChangeCallback}
  201. * to specify the type of the event(s).
  202. *
  203. * Available options are:
  204. * - `uiGridConstants.dataChange.ALL` - listeners fired on any of these events, fires listeners on all events.
  205. * - `uiGridConstants.dataChange.EDIT` - fired when the data in a cell is edited
  206. * - `uiGridConstants.dataChange.ROW` - fired when a row is added or removed
  207. * - `uiGridConstants.dataChange.COLUMN` - fired when the column definitions are modified
  208. * - `uiGridConstants.dataChange.OPTIONS` - fired when the grid options are modified
  209. */
  210. dataChange: {
  211. ALL: 'all',
  212. EDIT: 'edit',
  213. ROW: 'row',
  214. COLUMN: 'column',
  215. OPTIONS: 'options'
  216. },
  217. /**
  218. * @ngdoc object
  219. * @name scrollbars
  220. * @propertyOf ui.grid.service:uiGridConstants
  221. * @description Used with {@link ui.grid.class:GridOptions#properties_enableHorizontalScrollbar GridOptions.enableHorizontalScrollbar}
  222. * and {@link ui.grid.class:GridOptions#properties_enableVerticalScrollbar GridOptions.enableVerticalScrollbar}
  223. * to specify the scrollbar policy for that direction.
  224. *
  225. * Available options are:
  226. * - `uiGridConstants.scrollbars.NEVER` - never show scrollbars in this direction
  227. * - `uiGridConstants.scrollbars.ALWAYS` - always show scrollbars in this direction
  228. * - `uiGridConstants.scrollbars.WHEN_NEEDED` - shows scrollbars in this direction when needed
  229. */
  230. scrollbars: {
  231. NEVER: 0,
  232. ALWAYS: 1,
  233. WHEN_NEEDED: 2
  234. }
  235. });
  236. })();
  237. angular.module('ui.grid').directive('uiGridCell', ['$compile', '$parse', 'gridUtil', 'uiGridConstants', function ($compile, $parse, gridUtil, uiGridConstants) {
  238. var uiGridCell = {
  239. priority: 0,
  240. scope: false,
  241. require: '?^uiGrid',
  242. compile: function() {
  243. return {
  244. pre: function($scope, $elm, $attrs, uiGridCtrl) {
  245. function compileTemplate() {
  246. var compiledElementFn = $scope.col.compiledElementFn;
  247. compiledElementFn($scope, function(clonedElement, scope) {
  248. $elm.append(clonedElement);
  249. });
  250. }
  251. // If the grid controller is present, use it to get the compiled cell template function
  252. if (uiGridCtrl && $scope.col.compiledElementFn) {
  253. compileTemplate();
  254. }
  255. // No controller, compile the element manually (for unit tests)
  256. else {
  257. if ( uiGridCtrl && !$scope.col.compiledElementFn ){
  258. // gridUtil.logError('Render has been called before precompile. Please log a ui-grid issue');
  259. $scope.col.getCompiledElementFn()
  260. .then(function (compiledElementFn) {
  261. compiledElementFn($scope, function(clonedElement, scope) {
  262. $elm.append(clonedElement);
  263. });
  264. }).catch(angular.noop);
  265. }
  266. else {
  267. var html = $scope.col.cellTemplate
  268. .replace(uiGridConstants.MODEL_COL_FIELD, 'row.entity.' + gridUtil.preEval($scope.col.field))
  269. .replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)');
  270. var cellElement = $compile(html)($scope);
  271. $elm.append(cellElement);
  272. }
  273. }
  274. },
  275. post: function($scope, $elm, $attrs, uiGridCtrl) {
  276. var initColClass = $scope.col.getColClass(false);
  277. $elm.addClass(initColClass);
  278. var classAdded;
  279. var updateClass = function( grid ){
  280. var contents = $elm;
  281. if ( classAdded ){
  282. contents.removeClass( classAdded );
  283. classAdded = null;
  284. }
  285. if (angular.isFunction($scope.col.cellClass)) {
  286. classAdded = $scope.col.cellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex);
  287. }
  288. else {
  289. classAdded = $scope.col.cellClass;
  290. }
  291. contents.addClass(classAdded);
  292. };
  293. if ($scope.col.cellClass) {
  294. updateClass();
  295. }
  296. // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs
  297. var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateClass, [uiGridConstants.dataChange.COLUMN, uiGridConstants.dataChange.EDIT]);
  298. // watch the col and row to see if they change - which would indicate that we've scrolled or sorted or otherwise
  299. // changed the row/col that this cell relates to, and we need to re-evaluate cell classes and maybe other things
  300. var cellChangeFunction = function( n, o ){
  301. if ( n !== o ) {
  302. if ( classAdded || $scope.col.cellClass ){
  303. updateClass();
  304. }
  305. // See if the column's internal class has changed
  306. var newColClass = $scope.col.getColClass(false);
  307. if (newColClass !== initColClass) {
  308. $elm.removeClass(initColClass);
  309. $elm.addClass(newColClass);
  310. initColClass = newColClass;
  311. }
  312. }
  313. };
  314. // TODO(c0bra): Turn this into a deep array watch
  315. /* shouldn't be needed any more given track by col.name
  316. var colWatchDereg = $scope.$watch( 'col', cellChangeFunction );
  317. */
  318. var rowWatchDereg = $scope.$watch( 'row', cellChangeFunction );
  319. var deregisterFunction = function() {
  320. dataChangeDereg();
  321. // colWatchDereg();
  322. rowWatchDereg();
  323. };
  324. $scope.$on( '$destroy', deregisterFunction );
  325. $elm.on( '$destroy', deregisterFunction );
  326. }
  327. };
  328. }
  329. };
  330. return uiGridCell;
  331. }]);
  332. (function(){
  333. angular.module('ui.grid')
  334. .service('uiGridColumnMenuService', [ 'i18nService', 'uiGridConstants', 'gridUtil',
  335. function ( i18nService, uiGridConstants, gridUtil ) {
  336. /**
  337. * @ngdoc service
  338. * @name ui.grid.service:uiGridColumnMenuService
  339. *
  340. * @description Services for working with column menus, factored out
  341. * to make the code easier to understand
  342. */
  343. var service = {
  344. /**
  345. * @ngdoc method
  346. * @methodOf ui.grid.service:uiGridColumnMenuService
  347. * @name initialize
  348. * @description Sets defaults, puts a reference to the $scope on
  349. * the uiGridController
  350. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  351. * @param {controller} uiGridCtrl the uiGridController for the grid
  352. * we're on
  353. *
  354. */
  355. initialize: function( $scope, uiGridCtrl ){
  356. $scope.grid = uiGridCtrl.grid;
  357. // Store a reference to this link/controller in the main uiGrid controller
  358. // to allow showMenu later
  359. uiGridCtrl.columnMenuScope = $scope;
  360. // Save whether we're shown or not so the columns can check
  361. $scope.menuShown = false;
  362. },
  363. /**
  364. * @ngdoc method
  365. * @methodOf ui.grid.service:uiGridColumnMenuService
  366. * @name setColMenuItemWatch
  367. * @description Setup a watch on $scope.col.menuItems, and update
  368. * menuItems based on this. $scope.col needs to be set by the column
  369. * before calling the menu.
  370. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  371. * @param {controller} uiGridCtrl the uiGridController for the grid
  372. * we're on
  373. *
  374. */
  375. setColMenuItemWatch: function ( $scope ){
  376. var deregFunction = $scope.$watch('col.menuItems', function (n) {
  377. if (typeof(n) !== 'undefined' && n && angular.isArray(n)) {
  378. n.forEach(function (item) {
  379. if (typeof(item.context) === 'undefined' || !item.context) {
  380. item.context = {};
  381. }
  382. item.context.col = $scope.col;
  383. });
  384. $scope.menuItems = $scope.defaultMenuItems.concat(n);
  385. }
  386. else {
  387. $scope.menuItems = $scope.defaultMenuItems;
  388. }
  389. });
  390. $scope.$on( '$destroy', deregFunction );
  391. },
  392. /**
  393. * @ngdoc boolean
  394. * @name enableSorting
  395. * @propertyOf ui.grid.class:GridOptions.columnDef
  396. * @description (optional) True by default. When enabled, this setting adds sort
  397. * widgets to the column header, allowing sorting of the data in the individual column.
  398. */
  399. /**
  400. * @ngdoc method
  401. * @methodOf ui.grid.service:uiGridColumnMenuService
  402. * @name sortable
  403. * @description determines whether this column is sortable
  404. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  405. *
  406. */
  407. sortable: function( $scope ) {
  408. if ( $scope.grid.options.enableSorting && typeof($scope.col) !== 'undefined' && $scope.col && $scope.col.enableSorting) {
  409. return true;
  410. }
  411. else {
  412. return false;
  413. }
  414. },
  415. /**
  416. * @ngdoc method
  417. * @methodOf ui.grid.service:uiGridColumnMenuService
  418. * @name isActiveSort
  419. * @description determines whether the requested sort direction is current active, to
  420. * allow highlighting in the menu
  421. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  422. * @param {string} direction the direction that we'd have selected for us to be active
  423. *
  424. */
  425. isActiveSort: function( $scope, direction ){
  426. return (typeof($scope.col) !== 'undefined' && typeof($scope.col.sort) !== 'undefined' &&
  427. typeof($scope.col.sort.direction) !== 'undefined' && $scope.col.sort.direction === direction);
  428. },
  429. /**
  430. * @ngdoc method
  431. * @methodOf ui.grid.service:uiGridColumnMenuService
  432. * @name suppressRemoveSort
  433. * @description determines whether we should suppress the removeSort option
  434. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  435. *
  436. */
  437. suppressRemoveSort: function( $scope ) {
  438. if ($scope.col && $scope.col.suppressRemoveSort) {
  439. return true;
  440. }
  441. else {
  442. return false;
  443. }
  444. },
  445. /**
  446. * @ngdoc boolean
  447. * @name enableHiding
  448. * @propertyOf ui.grid.class:GridOptions.columnDef
  449. * @description (optional) True by default. When set to false, this setting prevents a user from hiding the column
  450. * using the column menu or the grid menu.
  451. */
  452. /**
  453. * @ngdoc method
  454. * @methodOf ui.grid.service:uiGridColumnMenuService
  455. * @name hideable
  456. * @description determines whether a column can be hidden, by checking the enableHiding columnDef option
  457. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  458. *
  459. */
  460. hideable: function( $scope ) {
  461. if (typeof($scope.col) !== 'undefined' && $scope.col && $scope.col.colDef && $scope.col.colDef.enableHiding === false ) {
  462. return false;
  463. }
  464. else {
  465. return true;
  466. }
  467. },
  468. /**
  469. * @ngdoc method
  470. * @methodOf ui.grid.service:uiGridColumnMenuService
  471. * @name getDefaultMenuItems
  472. * @description returns the default menu items for a column menu
  473. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  474. *
  475. */
  476. getDefaultMenuItems: function( $scope ){
  477. return [
  478. {
  479. title: function(){return i18nService.getSafeText('sort.ascending');},
  480. icon: 'ui-grid-icon-sort-alt-up',
  481. action: function($event) {
  482. $event.stopPropagation();
  483. $scope.sortColumn($event, uiGridConstants.ASC);
  484. },
  485. shown: function () {
  486. return service.sortable( $scope );
  487. },
  488. active: function() {
  489. return service.isActiveSort( $scope, uiGridConstants.ASC);
  490. }
  491. },
  492. {
  493. title: function(){return i18nService.getSafeText('sort.descending');},
  494. icon: 'ui-grid-icon-sort-alt-down',
  495. action: function($event) {
  496. $event.stopPropagation();
  497. $scope.sortColumn($event, uiGridConstants.DESC);
  498. },
  499. shown: function() {
  500. return service.sortable( $scope );
  501. },
  502. active: function() {
  503. return service.isActiveSort( $scope, uiGridConstants.DESC);
  504. }
  505. },
  506. {
  507. title: function(){return i18nService.getSafeText('sort.remove');},
  508. icon: 'ui-grid-icon-cancel',
  509. action: function ($event) {
  510. $event.stopPropagation();
  511. $scope.unsortColumn();
  512. },
  513. shown: function() {
  514. return service.sortable( $scope ) &&
  515. typeof($scope.col) !== 'undefined' && (typeof($scope.col.sort) !== 'undefined' &&
  516. typeof($scope.col.sort.direction) !== 'undefined') && $scope.col.sort.direction !== null &&
  517. !service.suppressRemoveSort( $scope );
  518. }
  519. },
  520. {
  521. title: function(){return i18nService.getSafeText('column.hide');},
  522. icon: 'ui-grid-icon-cancel',
  523. shown: function() {
  524. return service.hideable( $scope );
  525. },
  526. action: function ($event) {
  527. $event.stopPropagation();
  528. $scope.hideColumn();
  529. }
  530. }
  531. ];
  532. },
  533. /**
  534. * @ngdoc method
  535. * @methodOf ui.grid.service:uiGridColumnMenuService
  536. * @name getColumnElementPosition
  537. * @description gets the position information needed to place the column
  538. * menu below the column header
  539. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  540. * @param {GridCol} column the column we want to position below
  541. * @param {element} $columnElement the column element we want to position below
  542. * @returns {hash} containing left, top, offset, height, width
  543. *
  544. */
  545. getColumnElementPosition: function( $scope, column, $columnElement ){
  546. var positionData = {};
  547. positionData.left = $columnElement[0].offsetLeft;
  548. positionData.top = $columnElement[0].offsetTop;
  549. positionData.parentLeft = $columnElement[0].offsetParent.offsetLeft;
  550. // Get the grid scrollLeft
  551. positionData.offset = 0;
  552. if (column.grid.options.offsetLeft) {
  553. positionData.offset = column.grid.options.offsetLeft;
  554. }
  555. positionData.height = gridUtil.elementHeight($columnElement, true);
  556. positionData.width = gridUtil.elementWidth($columnElement, true);
  557. return positionData;
  558. },
  559. /**
  560. * @ngdoc method
  561. * @methodOf ui.grid.service:uiGridColumnMenuService
  562. * @name repositionMenu
  563. * @description Reposition the menu below the new column. If the menu has no child nodes
  564. * (i.e. it's not currently visible) then we guess it's width at 100, we'll be called again
  565. * later to fix it
  566. * @param {$scope} $scope the $scope from the uiGridColumnMenu
  567. * @param {GridCol} column the column we want to position below
  568. * @param {hash} positionData a hash containing left, top, offset, height, width
  569. * @param {element} $elm the column menu element that we want to reposition
  570. * @param {element} $columnElement the column element that we want to reposition underneath
  571. *
  572. */
  573. repositionMenu: function( $scope, column, positionData, $elm, $columnElement ) {
  574. var menu = $elm[0].querySelectorAll('.ui-grid-menu');
  575. // It's possible that the render container of the column we're attaching to is
  576. // offset from the grid (i.e. pinned containers), we need to get the difference in the offsetLeft
  577. // between the render container and the grid
  578. var renderContainerElm = gridUtil.closestElm($columnElement, '.ui-grid-render-container');
  579. var renderContainerOffset = renderContainerElm.getBoundingClientRect().left - $scope.grid.element[0].getBoundingClientRect().left;
  580. var containerScrollLeft = renderContainerElm.querySelectorAll('.ui-grid-viewport')[0].scrollLeft;
  581. // repositionMenu is now always called after it's visible in the DOM,
  582. // allowing us to simply get the width every time the menu is opened
  583. var myWidth = gridUtil.elementWidth(menu, true);
  584. var paddingRight = column.lastMenuPaddingRight ? column.lastMenuPaddingRight : ( $scope.lastMenuPaddingRight ? $scope.lastMenuPaddingRight : 10);
  585. if ( menu.length !== 0 ){
  586. var mid = menu[0].querySelectorAll('.ui-grid-menu-mid');
  587. if ( mid.length !== 0 ) {
  588. // TODO(c0bra): use padding-left/padding-right based on document direction (ltr/rtl), place menu on proper side
  589. // Get the column menu right padding
  590. paddingRight = parseInt(gridUtil.getStyles(angular.element(menu)[0])['paddingRight'], 10);
  591. $scope.lastMenuPaddingRight = paddingRight;
  592. column.lastMenuPaddingRight = paddingRight;
  593. }
  594. }
  595. var left = positionData.left + renderContainerOffset - containerScrollLeft + positionData.parentLeft + positionData.width + paddingRight;
  596. if (left < positionData.offset + myWidth) {
  597. left = Math.max(positionData.left - containerScrollLeft + positionData.parentLeft - paddingRight + myWidth, positionData.offset + myWidth);
  598. }
  599. $elm.css('left', left + 'px');
  600. $elm.css('top', (positionData.top + positionData.height) + 'px');
  601. }
  602. };
  603. return service;
  604. }])
  605. .directive('uiGridColumnMenu', ['$timeout', 'gridUtil', 'uiGridConstants', 'uiGridColumnMenuService', '$document',
  606. function ($timeout, gridUtil, uiGridConstants, uiGridColumnMenuService, $document) {
  607. /**
  608. * @ngdoc directive
  609. * @name ui.grid.directive:uiGridColumnMenu
  610. * @description Provides the column menu framework, leverages uiGridMenu underneath
  611. *
  612. */
  613. var uiGridColumnMenu = {
  614. priority: 0,
  615. scope: true,
  616. require: '^uiGrid',
  617. templateUrl: 'ui-grid/uiGridColumnMenu',
  618. replace: true,
  619. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  620. uiGridColumnMenuService.initialize( $scope, uiGridCtrl );
  621. $scope.defaultMenuItems = uiGridColumnMenuService.getDefaultMenuItems( $scope );
  622. // Set the menu items for use with the column menu. The user can later add additional items via the watch
  623. $scope.menuItems = $scope.defaultMenuItems;
  624. uiGridColumnMenuService.setColMenuItemWatch( $scope );
  625. /**
  626. * @ngdoc method
  627. * @methodOf ui.grid.directive:uiGridColumnMenu
  628. * @name showMenu
  629. * @description Shows the column menu. If the menu is already displayed it
  630. * calls the menu to ask it to hide (it will animate), then it repositions the menu
  631. * to the right place whilst hidden (it will make an assumption on menu width),
  632. * then it asks the menu to show (it will animate), then it repositions the menu again
  633. * once we can calculate it's size.
  634. * @param {GridCol} column the column we want to position below
  635. * @param {element} $columnElement the column element we want to position below
  636. */
  637. $scope.showMenu = function(column, $columnElement, event) {
  638. // Swap to this column
  639. $scope.col = column;
  640. // Get the position information for the column element
  641. var colElementPosition = uiGridColumnMenuService.getColumnElementPosition( $scope, column, $columnElement );
  642. if ($scope.menuShown) {
  643. // we want to hide, then reposition, then show, but we want to wait for animations
  644. // we set a variable, and then rely on the menu-hidden event to call the reposition and show
  645. $scope.colElement = $columnElement;
  646. $scope.colElementPosition = colElementPosition;
  647. $scope.hideThenShow = true;
  648. $scope.$broadcast('hide-menu', { originalEvent: event });
  649. } else {
  650. $scope.menuShown = true;
  651. $scope.colElement = $columnElement;
  652. $scope.colElementPosition = colElementPosition;
  653. $scope.$broadcast('show-menu', { originalEvent: event });
  654. }
  655. };
  656. /**
  657. * @ngdoc method
  658. * @methodOf ui.grid.directive:uiGridColumnMenu
  659. * @name hideMenu
  660. * @description Hides the column menu.
  661. * @param {boolean} broadcastTrigger true if we were triggered by a broadcast
  662. * from the menu itself - in which case don't broadcast again as we'll get
  663. * an infinite loop
  664. */
  665. $scope.hideMenu = function( broadcastTrigger ) {
  666. $scope.menuShown = false;
  667. if ( !broadcastTrigger ){
  668. $scope.$broadcast('hide-menu');
  669. }
  670. };
  671. $scope.$on('menu-hidden', function() {
  672. var menuItems = angular.element($elm[0].querySelector('.ui-grid-menu-items'))[0];
  673. $elm[0].removeAttribute('style');
  674. if ( $scope.hideThenShow ){
  675. delete $scope.hideThenShow;
  676. $scope.$broadcast('show-menu');
  677. $scope.menuShown = true;
  678. } else {
  679. $scope.hideMenu( true );
  680. if ($scope.col) {
  681. //Focus on the menu button
  682. gridUtil.focus.bySelector($document, '.ui-grid-header-cell.' + $scope.col.getColClass()+ ' .ui-grid-column-menu-button', $scope.col.grid, false);
  683. }
  684. }
  685. if (menuItems) {
  686. menuItems.onkeydown = null;
  687. angular.forEach(menuItems.children, function removeHandlers(item) {
  688. item.onkeydown = null;
  689. });
  690. }
  691. });
  692. $scope.$on('menu-shown', function() {
  693. $timeout( function() {
  694. uiGridColumnMenuService.repositionMenu( $scope, $scope.col, $scope.colElementPosition, $elm, $scope.colElement );
  695. //automatically set the focus to the first button element in the now open menu.
  696. gridUtil.focus.bySelector($document, '.ui-grid-menu-items .ui-grid-menu-item:not(.ng-hide)', true);
  697. delete $scope.colElementPosition;
  698. delete $scope.columnElement;
  699. addKeydownHandlersToMenu();
  700. });
  701. });
  702. /* Column methods */
  703. $scope.sortColumn = function (event, dir) {
  704. event.stopPropagation();
  705. $scope.grid.sortColumn($scope.col, dir, true)
  706. .then(function () {
  707. $scope.grid.refresh();
  708. $scope.hideMenu();
  709. }).catch(angular.noop);
  710. };
  711. $scope.unsortColumn = function () {
  712. $scope.col.unsort();
  713. $scope.grid.refresh();
  714. $scope.hideMenu();
  715. };
  716. function addKeydownHandlersToMenu() {
  717. var menu = angular.element($elm[0].querySelector('.ui-grid-menu-items'))[0],
  718. menuItems,
  719. visibleMenuItems = [];
  720. if (menu) {
  721. menu.onkeydown = function closeMenu(event) {
  722. if (event.keyCode === uiGridConstants.keymap.ESC) {
  723. event.preventDefault();
  724. $scope.hideMenu();
  725. }
  726. };
  727. menuItems = menu.querySelectorAll('.ui-grid-menu-item:not(.ng-hide)');
  728. angular.forEach(menuItems, function filterVisibleItems(item) {
  729. if (item.offsetParent !== null) {
  730. this.push(item);
  731. }
  732. }, visibleMenuItems);
  733. if (visibleMenuItems.length) {
  734. if (visibleMenuItems.length === 1) {
  735. visibleMenuItems[0].onkeydown = function singleItemHandler(event) {
  736. circularFocusHandler(event, true);
  737. };
  738. } else {
  739. visibleMenuItems[0].onkeydown = function firstItemHandler(event) {
  740. circularFocusHandler(event, false, event.shiftKey, visibleMenuItems.length - 1);
  741. };
  742. visibleMenuItems[visibleMenuItems.length - 1].onkeydown = function lastItemHandler(event) {
  743. circularFocusHandler(event, false, !event.shiftKey, 0);
  744. };
  745. }
  746. }
  747. }
  748. function circularFocusHandler(event, isSingleItem, shiftKeyStatus, index) {
  749. if (event.keyCode === uiGridConstants.keymap.TAB) {
  750. if (isSingleItem) {
  751. event.preventDefault();
  752. } else if (shiftKeyStatus) {
  753. event.preventDefault();
  754. visibleMenuItems[index].focus();
  755. }
  756. }
  757. }
  758. }
  759. // Since we are hiding this column the default hide action will fail so we need to focus somewhere else.
  760. var setFocusOnHideColumn = function(){
  761. $timeout(function() {
  762. // Get the UID of the first
  763. var focusToGridMenu = function(){
  764. return gridUtil.focus.byId('grid-menu', $scope.grid);
  765. };
  766. var thisIndex;
  767. $scope.grid.columns.some(function(element, index){
  768. if (angular.equals(element, $scope.col)) {
  769. thisIndex = index;
  770. return true;
  771. }
  772. });
  773. var previousVisibleCol;
  774. // Try and find the next lower or nearest column to focus on
  775. $scope.grid.columns.some(function(element, index){
  776. if (!element.visible){
  777. return false;
  778. } // This columns index is below the current column index
  779. else if ( index < thisIndex){
  780. previousVisibleCol = element;
  781. } // This elements index is above this column index and we haven't found one that is lower
  782. else if ( index > thisIndex && !previousVisibleCol) {
  783. // This is the next best thing
  784. previousVisibleCol = element;
  785. // We've found one so use it.
  786. return true;
  787. } // We've reached an element with an index above this column and the previousVisibleCol variable has been set
  788. else if (index > thisIndex && previousVisibleCol) {
  789. // We are done.
  790. return true;
  791. }
  792. });
  793. // If found then focus on it
  794. if (previousVisibleCol){
  795. var colClass = previousVisibleCol.getColClass();
  796. gridUtil.focus.bySelector($document, '.ui-grid-header-cell.' + colClass+ ' .ui-grid-header-cell-primary-focus', true).then(angular.noop, function(reason){
  797. if (reason !== 'canceled'){ // If this is canceled then don't perform the action
  798. //The fallback action is to focus on the grid menu
  799. return focusToGridMenu();
  800. }
  801. }).catch(angular.noop);
  802. } else {
  803. // Fallback action to focus on the grid menu
  804. focusToGridMenu();
  805. }
  806. });
  807. };
  808. $scope.hideColumn = function () {
  809. $scope.col.colDef.visible = false;
  810. $scope.col.visible = false;
  811. $scope.grid.queueGridRefresh();
  812. $scope.hideMenu();
  813. $scope.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
  814. $scope.grid.api.core.raise.columnVisibilityChanged( $scope.col );
  815. // We are hiding so the default action of focusing on the button that opened this menu will fail.
  816. setFocusOnHideColumn();
  817. };
  818. },
  819. controller: ['$scope', function ($scope) {
  820. var self = this;
  821. $scope.$watch('menuItems', function (n) {
  822. self.menuItems = n;
  823. });
  824. }]
  825. };
  826. return uiGridColumnMenu;
  827. }]);
  828. })();
  829. (function(){
  830. 'use strict';
  831. angular.module('ui.grid').directive('uiGridFilter', ['$compile', '$templateCache', 'i18nService', 'gridUtil', function ($compile, $templateCache, i18nService, gridUtil) {
  832. return {
  833. compile: function() {
  834. return {
  835. pre: function ($scope, $elm, $attrs, controllers) {
  836. $scope.col.updateFilters = function( filterable ){
  837. $elm.children().remove();
  838. if ( filterable ) {
  839. var template = $scope.col.filterHeaderTemplate;
  840. if (template === undefined && $scope.col.providedFilterHeaderTemplate !== '') {
  841. if ($scope.col.filterHeaderTemplatePromise) {
  842. $scope.col.filterHeaderTemplatePromise.then(function () {
  843. template = $scope.col.filterHeaderTemplate;
  844. $elm.append($compile(template)($scope));
  845. });
  846. }
  847. }
  848. else {
  849. $elm.append($compile(template)($scope));
  850. }
  851. }
  852. };
  853. $scope.$on( '$destroy', function() {
  854. delete $scope.col.updateFilters;
  855. });
  856. },
  857. post: function ($scope, $elm, $attrs, controllers){
  858. $scope.aria = i18nService.getSafeText('headerCell.aria');
  859. $scope.removeFilter = function(colFilter, index){
  860. colFilter.term = null;
  861. //Set the focus to the filter input after the action disables the button
  862. gridUtil.focus.bySelector($elm, '.ui-grid-filter-input-' + index);
  863. };
  864. }
  865. };
  866. }
  867. };
  868. }]);
  869. })();
  870. (function () {
  871. 'use strict';
  872. angular.module('ui.grid').directive('uiGridFooterCell', ['$timeout', 'gridUtil', 'uiGridConstants', '$compile',
  873. function ($timeout, gridUtil, uiGridConstants, $compile) {
  874. var uiGridFooterCell = {
  875. priority: 0,
  876. scope: {
  877. col: '=',
  878. row: '=',
  879. renderIndex: '='
  880. },
  881. replace: true,
  882. require: '^uiGrid',
  883. compile: function compile(tElement, tAttrs, transclude) {
  884. return {
  885. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  886. var template = $scope.col.footerCellTemplate;
  887. if (template === undefined && $scope.col.providedFooterCellTemplate !== '') {
  888. if ($scope.col.footerCellTemplatePromise) {
  889. $scope.col.footerCellTemplatePromise.then(function () {
  890. template = $scope.col.footerCellTemplate;
  891. $elm.append($compile(template)($scope));
  892. });
  893. }
  894. }
  895. else {
  896. $elm.append($compile(template)($scope));
  897. }
  898. },
  899. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  900. //$elm.addClass($scope.col.getColClass(false));
  901. $scope.grid = uiGridCtrl.grid;
  902. var initColClass = $scope.col.getColClass(false);
  903. $elm.addClass(initColClass);
  904. // apply any footerCellClass
  905. var classAdded;
  906. var updateClass = function( grid ){
  907. var contents = $elm;
  908. if ( classAdded ){
  909. contents.removeClass( classAdded );
  910. classAdded = null;
  911. }
  912. if (angular.isFunction($scope.col.footerCellClass)) {
  913. classAdded = $scope.col.footerCellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex);
  914. }
  915. else {
  916. classAdded = $scope.col.footerCellClass;
  917. }
  918. contents.addClass(classAdded);
  919. };
  920. if ($scope.col.footerCellClass) {
  921. updateClass();
  922. }
  923. $scope.col.updateAggregationValue();
  924. // Watch for column changes so we can alter the col cell class properly
  925. /* shouldn't be needed any more, given track by col.name
  926. $scope.$watch('col', function (n, o) {
  927. if (n !== o) {
  928. // See if the column's internal class has changed
  929. var newColClass = $scope.col.getColClass(false);
  930. if (newColClass !== initColClass) {
  931. $elm.removeClass(initColClass);
  932. $elm.addClass(newColClass);
  933. initColClass = newColClass;
  934. }
  935. }
  936. });
  937. */
  938. // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs
  939. var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateClass, [uiGridConstants.dataChange.COLUMN]);
  940. // listen for visible rows change and update aggregation values
  941. $scope.grid.api.core.on.rowsRendered( $scope, $scope.col.updateAggregationValue );
  942. $scope.grid.api.core.on.rowsRendered( $scope, updateClass );
  943. $scope.$on( '$destroy', dataChangeDereg );
  944. }
  945. };
  946. }
  947. };
  948. return uiGridFooterCell;
  949. }]);
  950. })();
  951. (function () {
  952. 'use strict';
  953. angular.module('ui.grid').directive('uiGridFooter', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', function ($templateCache, $compile, uiGridConstants, gridUtil, $timeout) {
  954. return {
  955. restrict: 'EA',
  956. replace: true,
  957. // priority: 1000,
  958. require: ['^uiGrid', '^uiGridRenderContainer'],
  959. scope: true,
  960. compile: function ($elm, $attrs) {
  961. return {
  962. pre: function ($scope, $elm, $attrs, controllers) {
  963. var uiGridCtrl = controllers[0];
  964. var containerCtrl = controllers[1];
  965. $scope.grid = uiGridCtrl.grid;
  966. $scope.colContainer = containerCtrl.colContainer;
  967. containerCtrl.footer = $elm;
  968. var footerTemplate = $scope.grid.options.footerTemplate;
  969. gridUtil.getTemplate(footerTemplate)
  970. .then(function (contents) {
  971. var template = angular.element(contents);
  972. var newElm = $compile(template)($scope);
  973. $elm.append(newElm);
  974. if (containerCtrl) {
  975. // Inject a reference to the footer viewport (if it exists) into the grid controller for use in the horizontal scroll handler below
  976. var footerViewport = $elm[0].getElementsByClassName('ui-grid-footer-viewport')[0];
  977. if (footerViewport) {
  978. containerCtrl.footerViewport = footerViewport;
  979. }
  980. }
  981. }).catch(angular.noop);
  982. },
  983. post: function ($scope, $elm, $attrs, controllers) {
  984. var uiGridCtrl = controllers[0];
  985. var containerCtrl = controllers[1];
  986. // gridUtil.logDebug('ui-grid-footer link');
  987. var grid = uiGridCtrl.grid;
  988. // Don't animate footer cells
  989. gridUtil.disableAnimations($elm);
  990. containerCtrl.footer = $elm;
  991. var footerViewport = $elm[0].getElementsByClassName('ui-grid-footer-viewport')[0];
  992. if (footerViewport) {
  993. containerCtrl.footerViewport = footerViewport;
  994. }
  995. }
  996. };
  997. }
  998. };
  999. }]);
  1000. })();
  1001. (function () {
  1002. 'use strict';
  1003. angular.module('ui.grid').directive('uiGridGridFooter', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', function ($templateCache, $compile, uiGridConstants, gridUtil, $timeout) {
  1004. return {
  1005. restrict: 'EA',
  1006. replace: true,
  1007. // priority: 1000,
  1008. require: '^uiGrid',
  1009. scope: true,
  1010. compile: function ($elm, $attrs) {
  1011. return {
  1012. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  1013. $scope.grid = uiGridCtrl.grid;
  1014. var footerTemplate = $scope.grid.options.gridFooterTemplate;
  1015. gridUtil.getTemplate(footerTemplate)
  1016. .then(function (contents) {
  1017. var template = angular.element(contents);
  1018. var newElm = $compile(template)($scope);
  1019. $elm.append(newElm);
  1020. }).catch(angular.noop);
  1021. },
  1022. post: function ($scope, $elm, $attrs, controllers) {
  1023. }
  1024. };
  1025. }
  1026. };
  1027. }]);
  1028. })();
  1029. (function(){
  1030. 'use strict';
  1031. angular.module('ui.grid').directive('uiGridHeaderCell', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants', 'ScrollEvent', 'i18nService',
  1032. function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, ScrollEvent, i18nService) {
  1033. // Do stuff after mouse has been down this many ms on the header cell
  1034. var mousedownTimeout = 500;
  1035. var changeModeTimeout = 500; // length of time between a touch event and a mouse event being recognised again, and vice versa
  1036. var uiGridHeaderCell = {
  1037. priority: 0,
  1038. scope: {
  1039. col: '=',
  1040. row: '=',
  1041. renderIndex: '='
  1042. },
  1043. require: ['^uiGrid', '^uiGridRenderContainer'],
  1044. replace: true,
  1045. compile: function() {
  1046. return {
  1047. pre: function ($scope, $elm, $attrs) {
  1048. var template = $scope.col.headerCellTemplate;
  1049. if (template === undefined && $scope.col.providedHeaderCellTemplate !== '') {
  1050. if ($scope.col.headerCellTemplatePromise) {
  1051. $scope.col.headerCellTemplatePromise.then(function () {
  1052. template = $scope.col.headerCellTemplate;
  1053. $elm.append($compile(template)($scope));
  1054. });
  1055. }
  1056. }
  1057. else {
  1058. $elm.append($compile(template)($scope));
  1059. }
  1060. },
  1061. post: function ($scope, $elm, $attrs, controllers) {
  1062. var uiGridCtrl = controllers[0];
  1063. var renderContainerCtrl = controllers[1];
  1064. $scope.i18n = {
  1065. headerCell: i18nService.getSafeText('headerCell'),
  1066. sort: i18nService.getSafeText('sort')
  1067. };
  1068. $scope.isSortPriorityVisible = function() {
  1069. //show sort priority if column is sorted and there is at least one other sorted column
  1070. return angular.isNumber($scope.col.sort.priority) && $scope.grid.columns.some(function(element, index){
  1071. return angular.isNumber(element.sort.priority) && element !== $scope.col;
  1072. });
  1073. };
  1074. $scope.getSortDirectionAriaLabel = function(){
  1075. var col = $scope.col;
  1076. //Trying to recreate this sort of thing but it was getting messy having it in the template.
  1077. //Sort direction {{col.sort.direction == asc ? 'ascending' : ( col.sort.direction == desc ? 'descending':'none')}}. {{col.sort.priority ? {{columnPriorityText}} {{col.sort.priority}} : ''}
  1078. var sortDirectionText = col.sort.direction === uiGridConstants.ASC ? $scope.i18n.sort.ascending : ( col.sort.direction === uiGridConstants.DESC ? $scope.i18n.sort.descending : $scope.i18n.sort.none);
  1079. var label = sortDirectionText;
  1080. if ($scope.isSortPriorityVisible()) {
  1081. label = label + '. ' + $scope.i18n.headerCell.priority + ' ' + (col.sort.priority + 1);
  1082. }
  1083. return label;
  1084. };
  1085. $scope.grid = uiGridCtrl.grid;
  1086. $scope.renderContainer = uiGridCtrl.grid.renderContainers[renderContainerCtrl.containerId];
  1087. var initColClass = $scope.col.getColClass(false);
  1088. $elm.addClass(initColClass);
  1089. // Hide the menu by default
  1090. $scope.menuShown = false;
  1091. // Put asc and desc sort directions in scope
  1092. $scope.asc = uiGridConstants.ASC;
  1093. $scope.desc = uiGridConstants.DESC;
  1094. // Store a reference to menu element
  1095. var $colMenu = angular.element( $elm[0].querySelectorAll('.ui-grid-header-cell-menu') );
  1096. var $contentsElm = angular.element( $elm[0].querySelectorAll('.ui-grid-cell-contents') );
  1097. // apply any headerCellClass
  1098. var classAdded;
  1099. var previousMouseX;
  1100. // filter watchers
  1101. var filterDeregisters = [];
  1102. /*
  1103. * Our basic approach here for event handlers is that we listen for a down event (mousedown or touchstart).
  1104. * Once we have a down event, we need to work out whether we have a click, a drag, or a
  1105. * hold. A click would sort the grid (if sortable). A drag would be used by moveable, so
  1106. * we ignore it. A hold would open the menu.
  1107. *
  1108. * So, on down event, we put in place handlers for move and up events, and a timer. If the
  1109. * timer expires before we see a move or up, then we have a long press and hence a column menu open.
  1110. * If the up happens before the timer, then we have a click, and we sort if the column is sortable.
  1111. * If a move happens before the timer, then we are doing column move, so we do nothing, the moveable feature
  1112. * will handle it.
  1113. *
  1114. * To deal with touch enabled devices that also have mice, we only create our handlers when
  1115. * we get the down event, and we create the corresponding handlers - if we're touchstart then
  1116. * we get touchmove and touchend, if we're mousedown then we get mousemove and mouseup.
  1117. *
  1118. * We also suppress the click action whilst this is happening - otherwise after the mouseup there
  1119. * will be a click event and that can cause the column menu to close
  1120. *
  1121. */
  1122. $scope.downFn = function( event ){
  1123. event.stopPropagation();
  1124. if (typeof(event.originalEvent) !== 'undefined' && event.originalEvent !== undefined) {
  1125. event = event.originalEvent;
  1126. }
  1127. // Don't show the menu if it's not the left button
  1128. if (event.button && event.button !== 0) {
  1129. return;
  1130. }
  1131. previousMouseX = event.pageX;
  1132. $scope.mousedownStartTime = (new Date()).getTime();
  1133. $scope.mousedownTimeout = $timeout(function() { }, mousedownTimeout);
  1134. $scope.mousedownTimeout.then(function () {
  1135. if ( $scope.colMenu ) {
  1136. uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm, event);
  1137. }
  1138. }).catch(angular.noop);
  1139. uiGridCtrl.fireEvent(uiGridConstants.events.COLUMN_HEADER_CLICK, {event: event, columnName: $scope.col.colDef.name});
  1140. $scope.offAllEvents();
  1141. if ( event.type === 'touchstart'){
  1142. $document.on('touchend', $scope.upFn);
  1143. $document.on('touchmove', $scope.moveFn);
  1144. } else if ( event.type === 'mousedown' ){
  1145. $document.on('mouseup', $scope.upFn);
  1146. $document.on('mousemove', $scope.moveFn);
  1147. }
  1148. };
  1149. $scope.upFn = function( event ){
  1150. event.stopPropagation();
  1151. $timeout.cancel($scope.mousedownTimeout);
  1152. $scope.offAllEvents();
  1153. $scope.onDownEvents(event.type);
  1154. var mousedownEndTime = (new Date()).getTime();
  1155. var mousedownTime = mousedownEndTime - $scope.mousedownStartTime;
  1156. if (mousedownTime > mousedownTimeout) {
  1157. // long click, handled above with mousedown
  1158. }
  1159. else {
  1160. // short click
  1161. if ( $scope.sortable ){
  1162. $scope.handleClick(event);
  1163. }
  1164. }
  1165. };
  1166. $scope.handleKeyDown = function(event) {
  1167. if (event.keyCode === 32) {
  1168. event.preventDefault();
  1169. }
  1170. };
  1171. $scope.moveFn = function( event ){
  1172. // Chrome is known to fire some bogus move events.
  1173. var changeValue = event.pageX - previousMouseX;
  1174. if ( changeValue === 0 ){ return; }
  1175. // we're a move, so do nothing and leave for column move (if enabled) to take over
  1176. $timeout.cancel($scope.mousedownTimeout);
  1177. $scope.offAllEvents();
  1178. $scope.onDownEvents(event.type);
  1179. };
  1180. $scope.clickFn = function ( event ){
  1181. event.stopPropagation();
  1182. $contentsElm.off('click', $scope.clickFn);
  1183. };
  1184. $scope.offAllEvents = function(){
  1185. $contentsElm.off('touchstart', $scope.downFn);
  1186. $contentsElm.off('mousedown', $scope.downFn);
  1187. $document.off('touchend', $scope.upFn);
  1188. $document.off('mouseup', $scope.upFn);
  1189. $document.off('touchmove', $scope.moveFn);
  1190. $document.off('mousemove', $scope.moveFn);
  1191. $contentsElm.off('click', $scope.clickFn);
  1192. };
  1193. $scope.onDownEvents = function( type ){
  1194. // If there is a previous event, then wait a while before
  1195. // activating the other mode - i.e. if the last event was a touch event then
  1196. // don't enable mouse events for a wee while (500ms or so)
  1197. // Avoids problems with devices that emulate mouse events when you have touch events
  1198. switch (type){
  1199. case 'touchmove':
  1200. case 'touchend':
  1201. $contentsElm.on('click', $scope.clickFn);
  1202. $contentsElm.on('touchstart', $scope.downFn);
  1203. $timeout(function(){
  1204. $contentsElm.on('mousedown', $scope.downFn);
  1205. }, changeModeTimeout);
  1206. break;
  1207. case 'mousemove':
  1208. case 'mouseup':
  1209. $contentsElm.on('click', $scope.clickFn);
  1210. $contentsElm.on('mousedown', $scope.downFn);
  1211. $timeout(function(){
  1212. $contentsElm.on('touchstart', $scope.downFn);
  1213. }, changeModeTimeout);
  1214. break;
  1215. default:
  1216. $contentsElm.on('click', $scope.clickFn);
  1217. $contentsElm.on('touchstart', $scope.downFn);
  1218. $contentsElm.on('mousedown', $scope.downFn);
  1219. }
  1220. };
  1221. var updateHeaderOptions = function( grid ){
  1222. var contents = $elm;
  1223. if ( classAdded ){
  1224. contents.removeClass( classAdded );
  1225. classAdded = null;
  1226. }
  1227. if (angular.isFunction($scope.col.headerCellClass)) {
  1228. classAdded = $scope.col.headerCellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex);
  1229. }
  1230. else {
  1231. classAdded = $scope.col.headerCellClass;
  1232. }
  1233. contents.addClass(classAdded);
  1234. $scope.$applyAsync(function() {
  1235. var rightMostContainer = $scope.grid.renderContainers['right'] && $scope.grid.renderContainers['right'].visibleColumnCache.length ?
  1236. $scope.grid.renderContainers['right'] : $scope.grid.renderContainers['body'];
  1237. $scope.isLastCol = uiGridCtrl.grid.options && uiGridCtrl.grid.options.enableGridMenu &&
  1238. $scope.col === rightMostContainer.visibleColumnCache[ rightMostContainer.visibleColumnCache.length - 1 ];
  1239. });
  1240. // Figure out whether this column is sortable or not
  1241. $scope.sortable = Boolean($scope.col.enableSorting);
  1242. // Figure out whether this column is filterable or not
  1243. var oldFilterable = $scope.filterable;
  1244. $scope.filterable = Boolean(uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering);
  1245. if ( oldFilterable !== $scope.filterable){
  1246. if ( typeof($scope.col.updateFilters) !== 'undefined' ){
  1247. $scope.col.updateFilters($scope.filterable);
  1248. }
  1249. // if column is filterable add a filter watcher
  1250. if ($scope.filterable) {
  1251. $scope.col.filters.forEach( function(filter, i) {
  1252. filterDeregisters.push($scope.$watch('col.filters[' + i + '].term', function(n, o) {
  1253. if (n !== o) {
  1254. uiGridCtrl.grid.api.core.raise.filterChanged();
  1255. uiGridCtrl.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
  1256. uiGridCtrl.grid.queueGridRefresh();
  1257. }
  1258. }));
  1259. });
  1260. $scope.$on('$destroy', function() {
  1261. filterDeregisters.forEach( function(filterDeregister) {
  1262. filterDeregister();
  1263. });
  1264. });
  1265. } else {
  1266. filterDeregisters.forEach( function(filterDeregister) {
  1267. filterDeregister();
  1268. });
  1269. }
  1270. }
  1271. // figure out whether we support column menus
  1272. if ($scope.col.grid.options && $scope.col.grid.options.enableColumnMenus !== false &&
  1273. $scope.col.colDef && $scope.col.colDef.enableColumnMenu !== false){
  1274. $scope.colMenu = true;
  1275. } else {
  1276. $scope.colMenu = false;
  1277. }
  1278. /**
  1279. * @ngdoc property
  1280. * @name enableColumnMenu
  1281. * @propertyOf ui.grid.class:GridOptions.columnDef
  1282. * @description if column menus are enabled, controls the column menus for this specific
  1283. * column (i.e. if gridOptions.enableColumnMenus, then you can control column menus
  1284. * using this option. If gridOptions.enableColumnMenus === false then you get no column
  1285. * menus irrespective of the value of this option ). Defaults to true.
  1286. *
  1287. * By default column menu's trigger is hidden before mouse over, but you can always force it to be visible with CSS:
  1288. *
  1289. * <pre>
  1290. * .ui-grid-column-menu-button {
  1291. * display: block;
  1292. * }
  1293. * </pre>
  1294. */
  1295. /**
  1296. * @ngdoc property
  1297. * @name enableColumnMenus
  1298. * @propertyOf ui.grid.class:GridOptions.columnDef
  1299. * @description Override for column menus everywhere - if set to false then you get no
  1300. * column menus. Defaults to true.
  1301. *
  1302. */
  1303. $scope.offAllEvents();
  1304. if ($scope.sortable || $scope.colMenu) {
  1305. $scope.onDownEvents();
  1306. $scope.$on('$destroy', function () {
  1307. $scope.offAllEvents();
  1308. });
  1309. }
  1310. };
  1311. /*
  1312. $scope.$watch('col', function (n, o) {
  1313. if (n !== o) {
  1314. // See if the column's internal class has changed
  1315. var newColClass = $scope.col.getColClass(false);
  1316. if (newColClass !== initColClass) {
  1317. $elm.removeClass(initColClass);
  1318. $elm.addClass(newColClass);
  1319. initColClass = newColClass;
  1320. }
  1321. }
  1322. });
  1323. */
  1324. updateHeaderOptions();
  1325. // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs
  1326. var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateHeaderOptions, [uiGridConstants.dataChange.COLUMN]);
  1327. $scope.$on( '$destroy', dataChangeDereg );
  1328. $scope.handleClick = function(event) {
  1329. // If the shift key is being held down, add this column to the sort
  1330. var add = false;
  1331. if (event.shiftKey) {
  1332. add = true;
  1333. }
  1334. // Sort this column then rebuild the grid's rows
  1335. uiGridCtrl.grid.sortColumn($scope.col, add)
  1336. .then(function () {
  1337. if (uiGridCtrl.columnMenuScope) { uiGridCtrl.columnMenuScope.hideMenu(); }
  1338. uiGridCtrl.grid.refresh();
  1339. }).catch(angular.noop);
  1340. };
  1341. $scope.headerCellArrowKeyDown = function(event) {
  1342. if (event.keyCode === 32 || event.keyCode === 13) {
  1343. event.preventDefault();
  1344. $scope.toggleMenu(event);
  1345. }
  1346. };
  1347. $scope.toggleMenu = function(event) {
  1348. event.stopPropagation();
  1349. // If the menu is already showing...
  1350. if (uiGridCtrl.columnMenuScope.menuShown) {
  1351. // ... and we're the column the menu is on...
  1352. if (uiGridCtrl.columnMenuScope.col === $scope.col) {
  1353. // ... hide it
  1354. uiGridCtrl.columnMenuScope.hideMenu();
  1355. }
  1356. // ... and we're NOT the column the menu is on
  1357. else {
  1358. // ... move the menu to our column
  1359. uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm);
  1360. }
  1361. }
  1362. // If the menu is NOT showing
  1363. else {
  1364. // ... show it on our column
  1365. uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm);
  1366. }
  1367. };
  1368. }
  1369. };
  1370. }
  1371. };
  1372. return uiGridHeaderCell;
  1373. }]);
  1374. })();
  1375. (function(){
  1376. 'use strict';
  1377. angular.module('ui.grid').directive('uiGridHeader', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', 'ScrollEvent',
  1378. function($templateCache, $compile, uiGridConstants, gridUtil, $timeout, ScrollEvent) {
  1379. var defaultTemplate = 'ui-grid/ui-grid-header';
  1380. var emptyTemplate = 'ui-grid/ui-grid-no-header';
  1381. return {
  1382. restrict: 'EA',
  1383. // templateUrl: 'ui-grid/ui-grid-header',
  1384. replace: true,
  1385. // priority: 1000,
  1386. require: ['^uiGrid', '^uiGridRenderContainer'],
  1387. scope: true,
  1388. compile: function($elm, $attrs) {
  1389. return {
  1390. pre: function ($scope, $elm, $attrs, controllers) {
  1391. var uiGridCtrl = controllers[0];
  1392. var containerCtrl = controllers[1];
  1393. $scope.grid = uiGridCtrl.grid;
  1394. $scope.colContainer = containerCtrl.colContainer;
  1395. updateHeaderReferences();
  1396. var headerTemplate;
  1397. if (!$scope.grid.options.showHeader) {
  1398. headerTemplate = emptyTemplate;
  1399. }
  1400. else {
  1401. headerTemplate = ($scope.grid.options.headerTemplate) ? $scope.grid.options.headerTemplate : defaultTemplate;
  1402. }
  1403. gridUtil.getTemplate(headerTemplate)
  1404. .then(function (contents) {
  1405. var template = angular.element(contents);
  1406. var newElm = $compile(template)($scope);
  1407. $elm.replaceWith(newElm);
  1408. // And update $elm to be the new element
  1409. $elm = newElm;
  1410. updateHeaderReferences();
  1411. if (containerCtrl) {
  1412. // Inject a reference to the header viewport (if it exists) into the grid controller for use in the horizontal scroll handler below
  1413. var headerViewport = $elm[0].getElementsByClassName('ui-grid-header-viewport')[0];
  1414. if (headerViewport) {
  1415. containerCtrl.headerViewport = headerViewport;
  1416. angular.element(headerViewport).on('scroll', scrollHandler);
  1417. $scope.$on('$destroy', function () {
  1418. angular.element(headerViewport).off('scroll', scrollHandler);
  1419. });
  1420. }
  1421. }
  1422. $scope.grid.queueRefresh();
  1423. }).catch(angular.noop);
  1424. function updateHeaderReferences() {
  1425. containerCtrl.header = containerCtrl.colContainer.header = $elm;
  1426. var headerCanvases = $elm[0].getElementsByClassName('ui-grid-header-canvas');
  1427. if (headerCanvases.length > 0) {
  1428. containerCtrl.headerCanvas = containerCtrl.colContainer.headerCanvas = headerCanvases[0];
  1429. }
  1430. else {
  1431. containerCtrl.headerCanvas = null;
  1432. }
  1433. }
  1434. function scrollHandler(evt) {
  1435. if (uiGridCtrl.grid.isScrollingHorizontally) {
  1436. return;
  1437. }
  1438. var newScrollLeft = gridUtil.normalizeScrollLeft(containerCtrl.headerViewport, uiGridCtrl.grid);
  1439. var horizScrollPercentage = containerCtrl.colContainer.scrollHorizontal(newScrollLeft);
  1440. var scrollEvent = new ScrollEvent(uiGridCtrl.grid, null, containerCtrl.colContainer, ScrollEvent.Sources.ViewPortScroll);
  1441. scrollEvent.newScrollLeft = newScrollLeft;
  1442. if ( horizScrollPercentage > -1 ){
  1443. scrollEvent.x = { percentage: horizScrollPercentage };
  1444. }
  1445. uiGridCtrl.grid.scrollContainers(null, scrollEvent);
  1446. }
  1447. },
  1448. post: function ($scope, $elm, $attrs, controllers) {
  1449. var uiGridCtrl = controllers[0];
  1450. var containerCtrl = controllers[1];
  1451. // gridUtil.logDebug('ui-grid-header link');
  1452. var grid = uiGridCtrl.grid;
  1453. // Don't animate header cells
  1454. gridUtil.disableAnimations($elm);
  1455. function updateColumnWidths() {
  1456. // this styleBuilder always runs after the renderContainer, so we can rely on the column widths
  1457. // already being populated correctly
  1458. var columnCache = containerCtrl.colContainer.visibleColumnCache;
  1459. // Build the CSS
  1460. // uiGridCtrl.grid.columns.forEach(function (column) {
  1461. var ret = '';
  1462. var canvasWidth = 0;
  1463. columnCache.forEach(function (column) {
  1464. ret = ret + column.getColClassDefinition();
  1465. canvasWidth += column.drawnWidth;
  1466. });
  1467. containerCtrl.colContainer.canvasWidth = canvasWidth;
  1468. // Return the styles back to buildStyles which pops them into the `customStyles` scope variable
  1469. return ret;
  1470. }
  1471. containerCtrl.header = $elm;
  1472. var headerViewport = $elm[0].getElementsByClassName('ui-grid-header-viewport')[0];
  1473. if (headerViewport) {
  1474. containerCtrl.headerViewport = headerViewport;
  1475. }
  1476. //todo: remove this if by injecting gridCtrl into unit tests
  1477. if (uiGridCtrl) {
  1478. uiGridCtrl.grid.registerStyleComputation({
  1479. priority: 15,
  1480. func: updateColumnWidths
  1481. });
  1482. }
  1483. }
  1484. };
  1485. }
  1486. };
  1487. }]);
  1488. })();
  1489. (function(){
  1490. angular.module('ui.grid')
  1491. .service('uiGridGridMenuService', [ 'gridUtil', 'i18nService', 'uiGridConstants', function( gridUtil, i18nService, uiGridConstants ) {
  1492. /**
  1493. * @ngdoc service
  1494. * @name ui.grid.uiGridGridMenuService
  1495. *
  1496. * @description Methods for working with the grid menu
  1497. */
  1498. var service = {
  1499. /**
  1500. * @ngdoc method
  1501. * @methodOf ui.grid.uiGridGridMenuService
  1502. * @name initialize
  1503. * @description Sets up the gridMenu. Most importantly, sets our
  1504. * scope onto the grid object as grid.gridMenuScope, allowing us
  1505. * to operate when passed only the grid. Second most importantly,
  1506. * we register the 'addToGridMenu' and 'removeFromGridMenu' methods
  1507. * on the core api.
  1508. * @param {$scope} $scope the scope of this gridMenu
  1509. * @param {Grid} grid the grid to which this gridMenu is associated
  1510. */
  1511. initialize: function( $scope, grid ){
  1512. grid.gridMenuScope = $scope;
  1513. $scope.grid = grid;
  1514. $scope.registeredMenuItems = [];
  1515. // not certain this is needed, but would be bad to create a memory leak
  1516. $scope.$on('$destroy', function() {
  1517. if ( $scope.grid && $scope.grid.gridMenuScope ){
  1518. $scope.grid.gridMenuScope = null;
  1519. }
  1520. if ( $scope.grid ){
  1521. $scope.grid = null;
  1522. }
  1523. if ( $scope.registeredMenuItems ){
  1524. $scope.registeredMenuItems = null;
  1525. }
  1526. });
  1527. $scope.registeredMenuItems = [];
  1528. /**
  1529. * @ngdoc function
  1530. * @name addToGridMenu
  1531. * @methodOf ui.grid.core.api:PublicApi
  1532. * @description add items to the grid menu. Used by features
  1533. * to add their menu items if they are enabled, can also be used by
  1534. * end users to add menu items. This method has the advantage of allowing
  1535. * remove again, which can simplify management of which items are included
  1536. * in the menu when. (Noting that in most cases the shown and active functions
  1537. * provide a better way to handle visibility of menu items)
  1538. * @param {Grid} grid the grid on which we are acting
  1539. * @param {array} items menu items in the format as described in the tutorial, with
  1540. * the added note that if you want to use remove you must also specify an `id` field,
  1541. * which is provided when you want to remove an item. The id should be unique.
  1542. *
  1543. */
  1544. grid.api.registerMethod( 'core', 'addToGridMenu', service.addToGridMenu );
  1545. /**
  1546. * @ngdoc function
  1547. * @name removeFromGridMenu
  1548. * @methodOf ui.grid.core.api:PublicApi
  1549. * @description Remove an item from the grid menu based on a provided id. Assumes
  1550. * that the id is unique, removes only the last instance of that id. Does nothing if
  1551. * the specified id is not found
  1552. * @param {Grid} grid the grid on which we are acting
  1553. * @param {string} id the id we'd like to remove from the menu
  1554. *
  1555. */
  1556. grid.api.registerMethod( 'core', 'removeFromGridMenu', service.removeFromGridMenu );
  1557. },
  1558. /**
  1559. * @ngdoc function
  1560. * @name addToGridMenu
  1561. * @propertyOf ui.grid.uiGridGridMenuService
  1562. * @description add items to the grid menu. Used by features
  1563. * to add their menu items if they are enabled, can also be used by
  1564. * end users to add menu items. This method has the advantage of allowing
  1565. * remove again, which can simplify management of which items are included
  1566. * in the menu when. (Noting that in most cases the shown and active functions
  1567. * provide a better way to handle visibility of menu items)
  1568. * @param {Grid} grid the grid on which we are acting
  1569. * @param {array} menuItems menu items in the format as described in the tutorial, with
  1570. * the added note that if you want to use remove you must also specify an `id` field,
  1571. * which is provided when you want to remove an item. The id should be unique.
  1572. *
  1573. */
  1574. addToGridMenu: function( grid, menuItems ) {
  1575. if ( !angular.isArray( menuItems ) ) {
  1576. gridUtil.logError( 'addToGridMenu: menuItems must be an array, and is not, not adding any items');
  1577. } else {
  1578. if ( grid.gridMenuScope ){
  1579. grid.gridMenuScope.registeredMenuItems = grid.gridMenuScope.registeredMenuItems ? grid.gridMenuScope.registeredMenuItems : [];
  1580. grid.gridMenuScope.registeredMenuItems = grid.gridMenuScope.registeredMenuItems.concat( menuItems );
  1581. } else {
  1582. gridUtil.logError( 'Asked to addToGridMenu, but gridMenuScope not present. Timing issue? Please log issue with ui-grid');
  1583. }
  1584. }
  1585. },
  1586. /**
  1587. * @ngdoc function
  1588. * @name removeFromGridMenu
  1589. * @methodOf ui.grid.uiGridGridMenuService
  1590. * @description Remove an item from the grid menu based on a provided id. Assumes
  1591. * that the id is unique, removes only the last instance of that id. Does nothing if
  1592. * the specified id is not found. If there is no gridMenuScope or registeredMenuItems
  1593. * then do nothing silently - the desired result is those menu items not be present and they
  1594. * aren't.
  1595. * @param {Grid} grid the grid on which we are acting
  1596. * @param {string} id the id we'd like to remove from the menu
  1597. *
  1598. */
  1599. removeFromGridMenu: function( grid, id ){
  1600. var foundIndex = -1;
  1601. if ( grid && grid.gridMenuScope ){
  1602. grid.gridMenuScope.registeredMenuItems.forEach( function( value, index ) {
  1603. if ( value.id === id ){
  1604. if (foundIndex > -1) {
  1605. gridUtil.logError( 'removeFromGridMenu: found multiple items with the same id, removing only the last' );
  1606. } else {
  1607. foundIndex = index;
  1608. }
  1609. }
  1610. });
  1611. }
  1612. if ( foundIndex > -1 ){
  1613. grid.gridMenuScope.registeredMenuItems.splice( foundIndex, 1 );
  1614. }
  1615. },
  1616. /**
  1617. * @ngdoc array
  1618. * @name gridMenuCustomItems
  1619. * @propertyOf ui.grid.class:GridOptions
  1620. * @description (optional) An array of menu items that should be added to
  1621. * the gridMenu. Follow the format documented in the tutorial for column
  1622. * menu customisation. The context provided to the action function will
  1623. * include context.grid. An alternative if working with dynamic menus is to use the
  1624. * provided api - core.addToGridMenu and core.removeFromGridMenu, which handles
  1625. * some of the management of items for you.
  1626. *
  1627. */
  1628. /**
  1629. * @ngdoc boolean
  1630. * @name gridMenuShowHideColumns
  1631. * @propertyOf ui.grid.class:GridOptions
  1632. * @description true by default, whether the grid menu should allow hide/show
  1633. * of columns
  1634. *
  1635. */
  1636. /**
  1637. * @ngdoc method
  1638. * @methodOf ui.grid.uiGridGridMenuService
  1639. * @name getMenuItems
  1640. * @description Decides the menu items to show in the menu. This is a
  1641. * combination of:
  1642. *
  1643. * - the default menu items that are always included,
  1644. * - any menu items that have been provided through the addMenuItem api. These
  1645. * are typically added by features within the grid
  1646. * - any menu items included in grid.options.gridMenuCustomItems. These can be
  1647. * changed dynamically, as they're always recalculated whenever we show the
  1648. * menu
  1649. * @param {$scope} $scope the scope of this gridMenu, from which we can find all
  1650. * the information that we need
  1651. * @returns {Array} an array of menu items that can be shown
  1652. */
  1653. getMenuItems: function( $scope ) {
  1654. var menuItems = [
  1655. // this is where we add any menu items we want to always include
  1656. ];
  1657. if ( $scope.grid.options.gridMenuCustomItems ){
  1658. if ( !angular.isArray( $scope.grid.options.gridMenuCustomItems ) ){
  1659. gridUtil.logError( 'gridOptions.gridMenuCustomItems must be an array, and is not');
  1660. } else {
  1661. menuItems = menuItems.concat( $scope.grid.options.gridMenuCustomItems );
  1662. }
  1663. }
  1664. var clearFilters = [{
  1665. title: i18nService.getSafeText('gridMenu.clearAllFilters'),
  1666. action: function ($event) {
  1667. $scope.grid.clearAllFilters();
  1668. },
  1669. shown: function() {
  1670. return $scope.grid.options.enableFiltering;
  1671. },
  1672. order: 100
  1673. }];
  1674. menuItems = menuItems.concat( clearFilters );
  1675. menuItems = menuItems.concat( $scope.registeredMenuItems );
  1676. if ( $scope.grid.options.gridMenuShowHideColumns !== false ){
  1677. menuItems = menuItems.concat( service.showHideColumns( $scope ) );
  1678. }
  1679. menuItems.sort(function(a, b){
  1680. return a.order - b.order;
  1681. });
  1682. return menuItems;
  1683. },
  1684. /**
  1685. * @ngdoc array
  1686. * @name gridMenuTitleFilter
  1687. * @propertyOf ui.grid.class:GridOptions
  1688. * @description (optional) A function that takes a title string
  1689. * (usually the col.displayName), and converts it into a display value. The function
  1690. * must return either a string or a promise.
  1691. *
  1692. * Used for internationalization of the grid menu column names - for angular-translate
  1693. * you can pass $translate as the function, for i18nService you can pass getSafeText as the
  1694. * function
  1695. * @example
  1696. * <pre>
  1697. * gridOptions = {
  1698. * gridMenuTitleFilter: $translate
  1699. * }
  1700. * </pre>
  1701. */
  1702. /**
  1703. * @ngdoc method
  1704. * @methodOf ui.grid.uiGridGridMenuService
  1705. * @name showHideColumns
  1706. * @description Adds two menu items for each of the columns in columnDefs. One
  1707. * menu item for hide, one menu item for show. Each is visible when appropriate
  1708. * (show when column is not visible, hide when column is visible). Each toggles
  1709. * the visible property on the columnDef using toggleColumnVisibility
  1710. * @param {$scope} $scope of a gridMenu, which contains a reference to the grid
  1711. */
  1712. showHideColumns: function( $scope ){
  1713. var showHideColumns = [];
  1714. if ( !$scope.grid.options.columnDefs || $scope.grid.options.columnDefs.length === 0 || $scope.grid.columns.length === 0 ) {
  1715. return showHideColumns;
  1716. }
  1717. function isColumnVisible(colDef) {
  1718. return colDef.visible === true || colDef.visible === undefined;
  1719. }
  1720. // add header for columns
  1721. showHideColumns.push({
  1722. title: i18nService.getSafeText('gridMenu.columns'),
  1723. order: 300
  1724. });
  1725. $scope.grid.options.gridMenuTitleFilter = $scope.grid.options.gridMenuTitleFilter ? $scope.grid.options.gridMenuTitleFilter : function( title ) { return title; };
  1726. $scope.grid.options.columnDefs.forEach( function( colDef, index ){
  1727. if ( colDef.enableHiding !== false ){
  1728. // add hide menu item - shows an OK icon as we only show when column is already visible
  1729. var menuItem = {
  1730. icon: isColumnVisible(colDef) ? 'ui-grid-icon-ok' : 'ui-grid-icon-cancel',
  1731. action: function($event) {
  1732. $event.stopPropagation();
  1733. service.toggleColumnVisibility( this.context.gridCol );
  1734. if ($event.target && $event.target.firstChild) {
  1735. $event.target.firstChild.className = isColumnVisible(this.context.gridCol.colDef) ?
  1736. 'ui-grid-icon-ok' : 'ui-grid-icon-cancel';
  1737. }
  1738. },
  1739. shown: function() {
  1740. return this.context.gridCol.colDef.enableHiding !== false;
  1741. },
  1742. context: { gridCol: $scope.grid.getColumn(colDef.name || colDef.field) },
  1743. leaveOpen: true,
  1744. order: 301 + index
  1745. };
  1746. service.setMenuItemTitle( menuItem, colDef, $scope.grid );
  1747. showHideColumns.push( menuItem );
  1748. }
  1749. });
  1750. return showHideColumns;
  1751. },
  1752. /**
  1753. * @ngdoc method
  1754. * @methodOf ui.grid.uiGridGridMenuService
  1755. * @name setMenuItemTitle
  1756. * @description Handles the response from gridMenuTitleFilter, adding it directly to the menu
  1757. * item if it returns a string, otherwise waiting for the promise to resolve or reject then
  1758. * putting the result into the title
  1759. * @param {object} menuItem the menuItem we want to put the title on
  1760. * @param {object} colDef the colDef from which we can get displayName, name or field
  1761. * @param {Grid} grid the grid, from which we can get the options.gridMenuTitleFilter
  1762. *
  1763. */
  1764. setMenuItemTitle: function( menuItem, colDef, grid ){
  1765. var title = grid.options.gridMenuTitleFilter( colDef.displayName || gridUtil.readableColumnName(colDef.name) || colDef.field );
  1766. if ( typeof(title) === 'string' ){
  1767. menuItem.title = title;
  1768. } else if ( title.then ){
  1769. // must be a promise
  1770. menuItem.title = "";
  1771. title.then( function( successValue ) {
  1772. menuItem.title = successValue;
  1773. }, function( errorValue ) {
  1774. menuItem.title = errorValue;
  1775. }).catch(angular.noop);
  1776. } else {
  1777. gridUtil.logError('Expected gridMenuTitleFilter to return a string or a promise, it has returned neither, bad config');
  1778. menuItem.title = 'badconfig';
  1779. }
  1780. },
  1781. /**
  1782. * @ngdoc method
  1783. * @methodOf ui.grid.uiGridGridMenuService
  1784. * @name toggleColumnVisibility
  1785. * @description Toggles the visibility of an individual column. Expects to be
  1786. * provided a context that has on it a gridColumn, which is the column that
  1787. * we'll operate upon. We change the visibility, and refresh the grid as appropriate
  1788. * @param {GridColumn} gridCol the column that we want to toggle
  1789. *
  1790. */
  1791. toggleColumnVisibility: function( gridCol ) {
  1792. gridCol.colDef.visible = !( gridCol.colDef.visible === true || gridCol.colDef.visible === undefined );
  1793. gridCol.grid.refresh();
  1794. gridCol.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
  1795. gridCol.grid.api.core.raise.columnVisibilityChanged( gridCol );
  1796. }
  1797. };
  1798. return service;
  1799. }])
  1800. .directive('uiGridMenuButton', ['gridUtil', 'uiGridConstants', 'uiGridGridMenuService', 'i18nService',
  1801. function (gridUtil, uiGridConstants, uiGridGridMenuService, i18nService) {
  1802. return {
  1803. priority: 0,
  1804. scope: true,
  1805. require: ['^uiGrid'],
  1806. templateUrl: 'ui-grid/ui-grid-menu-button',
  1807. replace: true,
  1808. link: function ($scope, $elm, $attrs, controllers) {
  1809. var uiGridCtrl = controllers[0];
  1810. // For the aria label
  1811. $scope.i18n = {
  1812. aria: i18nService.getSafeText('gridMenu.aria')
  1813. };
  1814. uiGridGridMenuService.initialize($scope, uiGridCtrl.grid);
  1815. $scope.shown = false;
  1816. $scope.toggleMenu = function () {
  1817. if ( $scope.shown ){
  1818. $scope.$broadcast('hide-menu');
  1819. $scope.shown = false;
  1820. } else {
  1821. $scope.menuItems = uiGridGridMenuService.getMenuItems( $scope );
  1822. $scope.$broadcast('show-menu');
  1823. $scope.shown = true;
  1824. }
  1825. };
  1826. $scope.$on('menu-hidden', function() {
  1827. $scope.shown = false;
  1828. gridUtil.focus.bySelector($elm, '.ui-grid-icon-container');
  1829. });
  1830. }
  1831. };
  1832. }]);
  1833. })();
  1834. (function(){
  1835. /**
  1836. * @ngdoc directive
  1837. * @name ui.grid.directive:uiGridMenu
  1838. * @element style
  1839. * @restrict A
  1840. *
  1841. * @description
  1842. * Allows us to interpolate expressions in `<style>` elements. Angular doesn't do this by default as it can/will/might? break in IE8.
  1843. *
  1844. * @example
  1845. <doc:example module="app">
  1846. <doc:source>
  1847. <script>
  1848. var app = angular.module('app', ['ui.grid']);
  1849. app.controller('MainCtrl', ['$scope', function ($scope) {
  1850. }]);
  1851. </script>
  1852. <div ng-controller="MainCtrl">
  1853. <div ui-grid-menu shown="true" ></div>
  1854. </div>
  1855. </doc:source>
  1856. <doc:scenario>
  1857. </doc:scenario>
  1858. </doc:example>
  1859. */
  1860. angular.module('ui.grid')
  1861. .directive('uiGridMenu', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants', 'i18nService',
  1862. function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18nService) {
  1863. var uiGridMenu = {
  1864. priority: 0,
  1865. scope: {
  1866. // shown: '&',
  1867. menuItems: '=',
  1868. autoHide: '=?'
  1869. },
  1870. require: '?^uiGrid',
  1871. templateUrl: 'ui-grid/uiGridMenu',
  1872. replace: false,
  1873. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  1874. $scope.dynamicStyles = '';
  1875. if (uiGridCtrl && uiGridCtrl.grid && uiGridCtrl.grid.options && uiGridCtrl.grid.options.gridMenuTemplate) {
  1876. var gridMenuTemplate = uiGridCtrl.grid.options.gridMenuTemplate;
  1877. gridUtil.getTemplate(gridMenuTemplate).then(function (contents) {
  1878. var template = angular.element(contents);
  1879. var newElm = $compile(template)($scope);
  1880. $elm.replaceWith(newElm);
  1881. }).catch(angular.noop);
  1882. }
  1883. var setupHeightStyle = function(gridHeight) {
  1884. //menu appears under header row, so substract that height from it's total
  1885. // additional 20px for general padding
  1886. var gridMenuMaxHeight = gridHeight - uiGridCtrl.grid.headerHeight - 20;
  1887. $scope.dynamicStyles = [
  1888. '.grid' + uiGridCtrl.grid.id + ' .ui-grid-menu-mid {',
  1889. 'max-height: ' + gridMenuMaxHeight + 'px;',
  1890. '}'
  1891. ].join(' ');
  1892. };
  1893. if (uiGridCtrl) {
  1894. setupHeightStyle(uiGridCtrl.grid.gridHeight);
  1895. uiGridCtrl.grid.api.core.on.gridDimensionChanged($scope, function(oldGridHeight, oldGridWidth, newGridHeight, newGridWidth) {
  1896. setupHeightStyle(newGridHeight);
  1897. });
  1898. }
  1899. $scope.i18n = {
  1900. close: i18nService.getSafeText('columnMenu.close')
  1901. };
  1902. // *** Show/Hide functions ******
  1903. $scope.showMenu = function(event, args) {
  1904. if ( !$scope.shown ){
  1905. /*
  1906. * In order to animate cleanly we remove the ng-if, wait a digest cycle, then
  1907. * animate the removal of the ng-hide. We can't successfully (so far as I can tell)
  1908. * animate removal of the ng-if, as the menu items aren't there yet. And we don't want
  1909. * to rely on ng-show only, as that leaves elements in the DOM that are needlessly evaluated
  1910. * on scroll events.
  1911. *
  1912. * Note when testing animation that animations don't run on the tutorials. When debugging it looks
  1913. * like they do, but angular has a default $animate provider that is just a stub, and that's what's
  1914. * being called. ALso don't be fooled by the fact that your browser has actually loaded the
  1915. * angular-translate.js, it's not using it. You need to test animations in an external application.
  1916. */
  1917. $scope.shown = true;
  1918. // Must be a timeout in order to work properly in Firefox. Issue #6533
  1919. $timeout(function() {
  1920. $scope.shownMid = true;
  1921. $scope.$emit('menu-shown');
  1922. });
  1923. } else if ( !$scope.shownMid ) {
  1924. // we're probably doing a hide then show, so we don't need to wait for ng-if
  1925. $scope.shownMid = true;
  1926. $scope.$emit('menu-shown');
  1927. }
  1928. var docEventType = 'click';
  1929. if (args && args.originalEvent && args.originalEvent.type && args.originalEvent.type === 'touchstart') {
  1930. docEventType = args.originalEvent.type;
  1931. }
  1932. // Turn off an existing document click handler
  1933. angular.element(document).off('click touchstart', applyHideMenu);
  1934. $elm.off('keyup', checkKeyUp);
  1935. $elm.off('keydown', checkKeyDown);
  1936. // Turn on the document click handler, but in a timeout so it doesn't apply to THIS click if there is one
  1937. $timeout(function() {
  1938. angular.element(document).on(docEventType, applyHideMenu);
  1939. $elm.on('keyup', checkKeyUp);
  1940. $elm.on('keydown', checkKeyDown);
  1941. });
  1942. };
  1943. $scope.hideMenu = function(event) {
  1944. if ( $scope.shown ){
  1945. /*
  1946. * In order to animate cleanly we animate the addition of ng-hide, then use a $timeout to
  1947. * set the ng-if (shown = false) after the animation runs. In theory we can cascade off the
  1948. * callback on the addClass method, but it is very unreliable with unit tests for no discernable reason.
  1949. *
  1950. * The user may have clicked on the menu again whilst
  1951. * we're waiting, so we check that the mid isn't shown before applying the ng-if.
  1952. */
  1953. $scope.shownMid = false;
  1954. $timeout( function() {
  1955. if ( !$scope.shownMid ){
  1956. $scope.shown = false;
  1957. $scope.$emit('menu-hidden');
  1958. }
  1959. }, 40);
  1960. }
  1961. angular.element(document).off('click touchstart', applyHideMenu);
  1962. $elm.off('keyup', checkKeyUp);
  1963. $elm.off('keydown', checkKeyDown);
  1964. };
  1965. $scope.$on('hide-menu', function (event, args) {
  1966. $scope.hideMenu(event, args);
  1967. });
  1968. $scope.$on('show-menu', function (event, args) {
  1969. $scope.showMenu(event, args);
  1970. });
  1971. // *** Auto hide when click elsewhere ******
  1972. var applyHideMenu = function(){
  1973. if ($scope.shown) {
  1974. $scope.$apply(function () {
  1975. $scope.hideMenu();
  1976. });
  1977. }
  1978. };
  1979. // close menu on ESC and keep tab cyclical
  1980. var checkKeyUp = function(event) {
  1981. if (event.keyCode === 27) {
  1982. $scope.hideMenu();
  1983. }
  1984. };
  1985. var checkKeyDown = function(event) {
  1986. var setFocus = function(elm) {
  1987. elm.focus();
  1988. event.preventDefault();
  1989. return false;
  1990. };
  1991. if (event.keyCode === 9) {
  1992. var firstMenuItem, lastMenuItem;
  1993. var menuItemButtons = $elm[0].querySelectorAll('button:not(.ng-hide)');
  1994. if (menuItemButtons.length > 0) {
  1995. firstMenuItem = menuItemButtons[0];
  1996. lastMenuItem = menuItemButtons[menuItemButtons.length - 1];
  1997. if (event.target === lastMenuItem && !event.shiftKey) {
  1998. setFocus(firstMenuItem);
  1999. } else if (event.target === firstMenuItem && event.shiftKey) {
  2000. setFocus(lastMenuItem);
  2001. }
  2002. }
  2003. }
  2004. };
  2005. if (typeof($scope.autoHide) === 'undefined' || $scope.autoHide === undefined) {
  2006. $scope.autoHide = true;
  2007. }
  2008. if ($scope.autoHide) {
  2009. angular.element($window).on('resize', applyHideMenu);
  2010. }
  2011. $scope.$on('$destroy', function unbindEvents() {
  2012. angular.element($window).off('resize', applyHideMenu);
  2013. angular.element(document).off('click touchstart', applyHideMenu);
  2014. $elm.off('keyup', checkKeyUp);
  2015. $elm.off('keydown', checkKeyDown);
  2016. });
  2017. if (uiGridCtrl) {
  2018. $scope.$on('$destroy', uiGridCtrl.grid.api.core.on.scrollBegin($scope, applyHideMenu ));
  2019. }
  2020. $scope.$on('$destroy', $scope.$on(uiGridConstants.events.ITEM_DRAGGING, applyHideMenu ));
  2021. }
  2022. };
  2023. return uiGridMenu;
  2024. }])
  2025. .directive('uiGridMenuItem', ['gridUtil', '$compile', 'i18nService', function (gridUtil, $compile, i18nService) {
  2026. var uiGridMenuItem = {
  2027. priority: 0,
  2028. scope: {
  2029. name: '=',
  2030. active: '=',
  2031. action: '=',
  2032. icon: '=',
  2033. shown: '=',
  2034. context: '=',
  2035. templateUrl: '=',
  2036. leaveOpen: '=',
  2037. screenReaderOnly: '='
  2038. },
  2039. require: ['?^uiGrid'],
  2040. templateUrl: 'ui-grid/uiGridMenuItem',
  2041. replace: false,
  2042. compile: function() {
  2043. return {
  2044. pre: function ($scope, $elm) {
  2045. if ($scope.templateUrl) {
  2046. gridUtil.getTemplate($scope.templateUrl)
  2047. .then(function (contents) {
  2048. var template = angular.element(contents);
  2049. var newElm = $compile(template)($scope);
  2050. $elm.replaceWith(newElm);
  2051. }).catch(angular.noop);
  2052. }
  2053. },
  2054. post: function ($scope, $elm, $attrs, controllers) {
  2055. var uiGridCtrl = controllers[0];
  2056. // TODO(c0bra): validate that shown and active are functions if they're defined. An exception is already thrown above this though
  2057. // if (typeof($scope.shown) !== 'undefined' && $scope.shown && typeof($scope.shown) !== 'function') {
  2058. // throw new TypeError("$scope.shown is defined but not a function");
  2059. // }
  2060. if (typeof($scope.shown) === 'undefined' || $scope.shown === null) {
  2061. $scope.shown = function() { return true; };
  2062. }
  2063. $scope.itemShown = function () {
  2064. var context = {};
  2065. if ($scope.context) {
  2066. context.context = $scope.context;
  2067. }
  2068. if (typeof(uiGridCtrl) !== 'undefined' && uiGridCtrl) {
  2069. context.grid = uiGridCtrl.grid;
  2070. }
  2071. return $scope.shown.call(context);
  2072. };
  2073. $scope.itemAction = function($event,title) {
  2074. $event.stopPropagation();
  2075. if (typeof($scope.action) === 'function') {
  2076. var context = {};
  2077. if ($scope.context) {
  2078. context.context = $scope.context;
  2079. }
  2080. // Add the grid to the function call context if the uiGrid controller is present
  2081. if (typeof(uiGridCtrl) !== 'undefined' && uiGridCtrl) {
  2082. context.grid = uiGridCtrl.grid;
  2083. }
  2084. $scope.action.call(context, $event, title);
  2085. if ( !$scope.leaveOpen ){
  2086. $scope.$emit('hide-menu');
  2087. } else {
  2088. // Maintain focus on the selected item
  2089. var correctParent = $event.target.parentElement;
  2090. // nodeName of 'I' means target is i element, need the next parent
  2091. if (angular.element($event.target)[0].nodeName === 'I') {
  2092. correctParent = correctParent.parentElement;
  2093. }
  2094. gridUtil.focus.bySelector(correctParent, 'button[type=button]', true);
  2095. }
  2096. }
  2097. };
  2098. $scope.label = function(){
  2099. var toBeDisplayed = $scope.name;
  2100. if (typeof($scope.name) === 'function'){
  2101. toBeDisplayed = $scope.name.call();
  2102. }
  2103. return toBeDisplayed;
  2104. };
  2105. $scope.i18n = i18nService.get();
  2106. }
  2107. };
  2108. }
  2109. };
  2110. return uiGridMenuItem;
  2111. }]);
  2112. })();
  2113. (function(){
  2114. 'use strict';
  2115. /**
  2116. * @ngdoc overview
  2117. * @name ui.grid.directive:uiGridOneBind
  2118. * @summary A group of directives that provide a one time bind to a dom element.
  2119. * @description A group of directives that provide a one time bind to a dom element.
  2120. * As one time bindings are not supported in Angular 1.2.* this directive provdes this capability.
  2121. * This is done to reduce the number of watchers on the dom.
  2122. * <br/>
  2123. * <h2>Short Example ({@link ui.grid.directive:uiGridOneBindSrc ui-grid-one-bind-src})</h2>
  2124. * <pre>
  2125. <div ng-init="imageName = 'myImageDir.jpg'">
  2126. <img ui-grid-one-bind-src="imageName"></img>
  2127. </div>
  2128. </pre>
  2129. * Will become:
  2130. * <pre>
  2131. <div ng-init="imageName = 'myImageDir.jpg'">
  2132. <img ui-grid-one-bind-src="imageName" src="myImageDir.jpg"></img>
  2133. </div>
  2134. </pre>
  2135. </br>
  2136. <h2>Short Example ({@link ui.grid.directive:uiGridOneBindText ui-grid-one-bind-text})</h2>
  2137. * <pre>
  2138. <div ng-init="text='Add this text'" ui-grid-one-bind-text="text"></div>
  2139. </pre>
  2140. * Will become:
  2141. * <pre>
  2142. <div ng-init="text='Add this text'" ui-grid-one-bind-text="text">Add this text</div>
  2143. </pre>
  2144. </br>
  2145. * <b>Note:</b> This behavior is slightly different for the {@link ui.grid.directive:uiGridOneBindIdGrid uiGridOneBindIdGrid}
  2146. * and {@link ui.grid.directive:uiGridOneBindAriaLabelledbyGrid uiGridOneBindAriaLabelledbyGrid} directives.
  2147. *
  2148. */
  2149. //https://github.com/joshkurz/Black-Belt-AngularJS-Directives/blob/master/directives/Optimization/oneBind.js
  2150. var oneBinders = angular.module('ui.grid');
  2151. angular.forEach([
  2152. /**
  2153. * @ngdoc directive
  2154. * @name ui.grid.directive:uiGridOneBindSrc
  2155. * @memberof ui.grid.directive:uiGridOneBind
  2156. * @element img
  2157. * @restrict A
  2158. * @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>.
  2159. * @description One time binding for the src dom tag.
  2160. *
  2161. */
  2162. {tag: 'Src', method: 'attr'},
  2163. /**
  2164. * @ngdoc directive
  2165. * @name ui.grid.directive:uiGridOneBindText
  2166. * @element div
  2167. * @restrict A
  2168. * @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>.
  2169. * @description One time binding for the text dom tag.
  2170. */
  2171. {tag: 'Text', method: 'text'},
  2172. /**
  2173. * @ngdoc directive
  2174. * @name ui.grid.directive:uiGridOneBindHref
  2175. * @element div
  2176. * @restrict A
  2177. * @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>.
  2178. * @description One time binding for the href dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2179. */
  2180. {tag: 'Href', method: 'attr'},
  2181. /**
  2182. * @ngdoc directive
  2183. * @name ui.grid.directive:uiGridOneBindClass
  2184. * @element div
  2185. * @restrict A
  2186. * @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>.
  2187. * @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.
  2188. * this is to prevent the watcher from being removed before the scope is initialized.
  2189. * @param {Array} uiGridOneBindClass An array of classes to bind to this element.
  2190. * @description One time binding for the class dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2191. */
  2192. {tag: 'Class', method: 'addClass'},
  2193. /**
  2194. * @ngdoc directive
  2195. * @name ui.grid.directive:uiGridOneBindHtml
  2196. * @element div
  2197. * @restrict A
  2198. * @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>.
  2199. * @description One time binding for the html method on a dom element. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2200. */
  2201. {tag: 'Html', method: 'html'},
  2202. /**
  2203. * @ngdoc directive
  2204. * @name ui.grid.directive:uiGridOneBindAlt
  2205. * @element div
  2206. * @restrict A
  2207. * @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>.
  2208. * @description One time binding for the alt dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2209. */
  2210. {tag: 'Alt', method: 'attr'},
  2211. /**
  2212. * @ngdoc directive
  2213. * @name ui.grid.directive:uiGridOneBindStyle
  2214. * @element div
  2215. * @restrict A
  2216. * @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>.
  2217. * @description One time binding for the style dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2218. */
  2219. {tag: 'Style', method: 'css'},
  2220. /**
  2221. * @ngdoc directive
  2222. * @name ui.grid.directive:uiGridOneBindValue
  2223. * @element div
  2224. * @restrict A
  2225. * @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>.
  2226. * @description One time binding for the value dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2227. */
  2228. {tag: 'Value', method: 'attr'},
  2229. /**
  2230. * @ngdoc directive
  2231. * @name ui.grid.directive:uiGridOneBindId
  2232. * @element div
  2233. * @restrict A
  2234. * @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>.
  2235. * @description One time binding for the value dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2236. */
  2237. {tag: 'Id', method: 'attr'},
  2238. /**
  2239. * @ngdoc directive
  2240. * @name ui.grid.directive:uiGridOneBindIdGrid
  2241. * @element div
  2242. * @restrict A
  2243. * @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>.
  2244. * @description One time binding for the id dom tag.
  2245. * <h1>Important Note!</h1>
  2246. * If the id tag passed as a parameter does <b>not</b> contain the grid id as a substring
  2247. * then the directive will search the scope and the parent controller (if it is a uiGridController) for the grid.id value.
  2248. * 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.
  2249. * This is done in order to ensure uniqueness of id tags across the grid.
  2250. * This is to prevent two grids in the same document having duplicate id tags.
  2251. */
  2252. {tag: 'Id', directiveName:'IdGrid', method: 'attr', appendGridId: true},
  2253. /**
  2254. * @ngdoc directive
  2255. * @name ui.grid.directive:uiGridOneBindTitle
  2256. * @element div
  2257. * @restrict A
  2258. * @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>.
  2259. * @description One time binding for the title dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2260. */
  2261. {tag: 'Title', method: 'attr'},
  2262. /**
  2263. * @ngdoc directive
  2264. * @name ui.grid.directive:uiGridOneBindAriaLabel
  2265. * @element div
  2266. * @restrict A
  2267. * @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>.
  2268. * @description One time binding for the aria-label dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2269. *<br/>
  2270. * <pre>
  2271. <div ng-init="text='Add this text'" ui-grid-one-bind-aria-label="text"></div>
  2272. </pre>
  2273. * Will become:
  2274. * <pre>
  2275. <div ng-init="text='Add this text'" ui-grid-one-bind-aria-label="text" aria-label="Add this text"></div>
  2276. </pre>
  2277. */
  2278. {tag: 'Label', method: 'attr', aria:true},
  2279. /**
  2280. * @ngdoc directive
  2281. * @name ui.grid.directive:uiGridOneBindAriaLabelledby
  2282. * @element div
  2283. * @restrict A
  2284. * @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>.
  2285. * @description One time binding for the aria-labelledby dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2286. *<br/>
  2287. * <pre>
  2288. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-labelledby="anId"></div>
  2289. </pre>
  2290. * Will become:
  2291. * <pre>
  2292. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-labelledby="anId" aria-labelledby="gridID32"></div>
  2293. </pre>
  2294. */
  2295. {tag: 'Labelledby', method: 'attr', aria:true},
  2296. /**
  2297. * @ngdoc directive
  2298. * @name ui.grid.directive:uiGridOneBindAriaLabelledbyGrid
  2299. * @element div
  2300. * @restrict A
  2301. * @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>.
  2302. * @description One time binding for the aria-labelledby dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2303. * 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
  2304. * grid id to each one.
  2305. *<br/>
  2306. * <pre>
  2307. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-labelledby-grid="anId"></div>
  2308. </pre>
  2309. * Will become ([grid.id] will be replaced by the actual grid id):
  2310. * <pre>
  2311. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-labelledby-grid="anId" aria-labelledby-Grid="[grid.id]-gridID32"></div>
  2312. </pre>
  2313. */
  2314. {tag: 'Labelledby', directiveName:'LabelledbyGrid', appendGridId:true, method: 'attr', aria:true},
  2315. /**
  2316. * @ngdoc directive
  2317. * @name ui.grid.directive:uiGridOneBindAriaDescribedby
  2318. * @element ANY
  2319. * @restrict A
  2320. * @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>.
  2321. * @description One time binding for the aria-describedby dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2322. *<br/>
  2323. * <pre>
  2324. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-describedby="anId"></div>
  2325. </pre>
  2326. * Will become:
  2327. * <pre>
  2328. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-describedby="anId" aria-describedby="gridID32"></div>
  2329. </pre>
  2330. */
  2331. {tag: 'Describedby', method: 'attr', aria:true},
  2332. /**
  2333. * @ngdoc directive
  2334. * @name ui.grid.directive:uiGridOneBindAriaDescribedbyGrid
  2335. * @element ANY
  2336. * @restrict A
  2337. * @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>.
  2338. * @description One time binding for the aria-labelledby dom tag. For more information see {@link ui.grid.directive:uiGridOneBind}.
  2339. * 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
  2340. * grid id to each one.
  2341. *<br/>
  2342. * <pre>
  2343. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-describedby-grid="anId"></div>
  2344. </pre>
  2345. * Will become ([grid.id] will be replaced by the actual grid id):
  2346. * <pre>
  2347. <div ng-init="anId = 'gridID32'" ui-grid-one-bind-aria-describedby-grid="anId" aria-describedby="[grid.id]-gridID32"></div>
  2348. </pre>
  2349. */
  2350. {tag: 'Describedby', directiveName:'DescribedbyGrid', appendGridId:true, method: 'attr', aria:true}],
  2351. function(v){
  2352. var baseDirectiveName = 'uiGridOneBind';
  2353. //If it is an aria tag then append the aria label seperately
  2354. //This is done because the aria tags are formatted aria-* and the directive name can't have a '-' character in it.
  2355. //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.
  2356. var directiveName = (v.aria ? baseDirectiveName + 'Aria' : baseDirectiveName) + (v.directiveName ? v.directiveName : v.tag);
  2357. oneBinders.directive(directiveName, ['gridUtil', function(gridUtil){
  2358. return {
  2359. restrict: 'A',
  2360. require: ['?uiGrid','?^uiGrid'],
  2361. link: function(scope, iElement, iAttrs, controllers){
  2362. /* Appends the grid id to the beginnig of the value. */
  2363. var appendGridId = function(val){
  2364. var grid; //Get an instance of the grid if its available
  2365. //If its available in the scope then we don't need to try to find it elsewhere
  2366. if (scope.grid) {
  2367. grid = scope.grid;
  2368. }
  2369. //Another possible location to try to find the grid
  2370. else if (scope.col && scope.col.grid){
  2371. grid = scope.col.grid;
  2372. }
  2373. //Last ditch effort: Search through the provided controllers.
  2374. else if (!controllers.some( //Go through the controllers till one has the element we need
  2375. function(controller){
  2376. if (controller && controller.grid) {
  2377. grid = controller.grid;
  2378. return true; //We've found the grid
  2379. }
  2380. })){
  2381. //We tried our best to find it for you
  2382. gridUtil.logError("["+directiveName+"] A valid grid could not be found to bind id. Are you using this directive " +
  2383. "within the correct scope? Trying to generate id: [gridID]-" + val);
  2384. throw new Error("No valid grid could be found");
  2385. }
  2386. if (grid){
  2387. var idRegex = new RegExp(grid.id.toString());
  2388. //If the grid id hasn't been appended already in the template declaration
  2389. if (!idRegex.test(val)){
  2390. val = grid.id.toString() + '-' + val;
  2391. }
  2392. }
  2393. return val;
  2394. };
  2395. // The watch returns a function to remove itself.
  2396. var rmWatcher = scope.$watch(iAttrs[directiveName], function(newV){
  2397. if (newV){
  2398. //If we are trying to add an id element then we also apply the grid id if it isn't already there
  2399. if (v.appendGridId) {
  2400. var newIdString = null;
  2401. //Append the id to all of the new ids.
  2402. angular.forEach( newV.split(' '), function(s){
  2403. newIdString = (newIdString ? (newIdString + ' ') : '') + appendGridId(s);
  2404. });
  2405. newV = newIdString;
  2406. }
  2407. // Append this newValue to the dom element.
  2408. switch (v.method) {
  2409. case 'attr': //The attr method takes two paraams the tag and the value
  2410. if (v.aria) {
  2411. //If it is an aria element then append the aria prefix
  2412. iElement[v.method]('aria-' + v.tag.toLowerCase(),newV);
  2413. } else {
  2414. iElement[v.method](v.tag.toLowerCase(),newV);
  2415. }
  2416. break;
  2417. case 'addClass':
  2418. //Pulled from https://github.com/Pasvaz/bindonce/blob/master/bindonce.js
  2419. if (angular.isObject(newV) && !angular.isArray(newV)) {
  2420. var results = [];
  2421. var nonNullFound = false; //We don't want to remove the binding unless the key is actually defined
  2422. angular.forEach(newV, function (value, index) {
  2423. if (value !== null && typeof(value) !== "undefined"){
  2424. nonNullFound = true; //A non null value for a key was found so the object must have been initialized
  2425. if (value) {results.push(index);}
  2426. }
  2427. });
  2428. //A non null value for a key wasn't found so assume that the scope values haven't been fully initialized
  2429. if (!nonNullFound){
  2430. return; // If not initialized then the watcher should not be removed yet.
  2431. }
  2432. newV = results;
  2433. }
  2434. if (newV) {
  2435. iElement.addClass(angular.isArray(newV) ? newV.join(' ') : newV);
  2436. } else {
  2437. return;
  2438. }
  2439. break;
  2440. default:
  2441. iElement[v.method](newV);
  2442. break;
  2443. }
  2444. //Removes the watcher on itself after the bind
  2445. rmWatcher();
  2446. }
  2447. // True ensures that equality is determined using angular.equals instead of ===
  2448. }, true); //End rm watchers
  2449. } //End compile function
  2450. }; //End directive return
  2451. } // End directive function
  2452. ]); //End directive
  2453. }); // End angular foreach
  2454. })();
  2455. (function () {
  2456. 'use strict';
  2457. var module = angular.module('ui.grid');
  2458. module.directive('uiGridRenderContainer', ['$timeout', '$document', 'uiGridConstants', 'gridUtil', 'ScrollEvent',
  2459. function($timeout, $document, uiGridConstants, gridUtil, ScrollEvent) {
  2460. return {
  2461. replace: true,
  2462. transclude: true,
  2463. templateUrl: 'ui-grid/uiGridRenderContainer',
  2464. require: ['^uiGrid', 'uiGridRenderContainer'],
  2465. scope: {
  2466. containerId: '=',
  2467. rowContainerName: '=',
  2468. colContainerName: '=',
  2469. bindScrollHorizontal: '=',
  2470. bindScrollVertical: '=',
  2471. enableVerticalScrollbar: '=',
  2472. enableHorizontalScrollbar: '='
  2473. },
  2474. controller: 'uiGridRenderContainer as RenderContainer',
  2475. compile: function () {
  2476. return {
  2477. pre: function prelink($scope, $elm, $attrs, controllers) {
  2478. var uiGridCtrl = controllers[0];
  2479. var containerCtrl = controllers[1];
  2480. var grid = $scope.grid = uiGridCtrl.grid;
  2481. // Verify that the render container for this element exists
  2482. if (!$scope.rowContainerName) {
  2483. throw new Error("No row render container name specified");
  2484. }
  2485. if (!$scope.colContainerName) {
  2486. throw new Error("No column render container name specified");
  2487. }
  2488. if (!grid.renderContainers[$scope.rowContainerName]) {
  2489. throw new Error("Row render container '" + $scope.rowContainerName + "' is not registered.");
  2490. }
  2491. if (!grid.renderContainers[$scope.colContainerName]) {
  2492. throw new Error("Column render container '" + $scope.colContainerName + "' is not registered.");
  2493. }
  2494. var rowContainer = $scope.rowContainer = grid.renderContainers[$scope.rowContainerName];
  2495. var colContainer = $scope.colContainer = grid.renderContainers[$scope.colContainerName];
  2496. containerCtrl.containerId = $scope.containerId;
  2497. containerCtrl.rowContainer = rowContainer;
  2498. containerCtrl.colContainer = colContainer;
  2499. },
  2500. post: function postlink($scope, $elm, $attrs, controllers) {
  2501. var uiGridCtrl = controllers[0];
  2502. var containerCtrl = controllers[1];
  2503. var grid = uiGridCtrl.grid;
  2504. var rowContainer = containerCtrl.rowContainer;
  2505. var colContainer = containerCtrl.colContainer;
  2506. var scrollTop = null;
  2507. var scrollLeft = null;
  2508. var renderContainer = grid.renderContainers[$scope.containerId];
  2509. // Put the container name on this element as a class
  2510. $elm.addClass('ui-grid-render-container-' + $scope.containerId);
  2511. // Scroll the render container viewport when the mousewheel is used
  2512. gridUtil.on.mousewheel($elm, function (event) {
  2513. var scrollEvent = new ScrollEvent(grid, rowContainer, colContainer, ScrollEvent.Sources.RenderContainerMouseWheel);
  2514. if (event.deltaY !== 0) {
  2515. var scrollYAmount = event.deltaY * -1 * event.deltaFactor;
  2516. scrollTop = containerCtrl.viewport[0].scrollTop;
  2517. // Get the scroll percentage
  2518. scrollEvent.verticalScrollLength = rowContainer.getVerticalScrollLength();
  2519. var scrollYPercentage = (scrollTop + scrollYAmount) / scrollEvent.verticalScrollLength;
  2520. // If we should be scrolled 100%, make sure the scrollTop matches the maximum scroll length
  2521. // Viewports that have "overflow: hidden" don't let the mousewheel scroll all the way to the bottom without this check
  2522. if (scrollYPercentage >= 1 && scrollTop < scrollEvent.verticalScrollLength) {
  2523. containerCtrl.viewport[0].scrollTop = scrollEvent.verticalScrollLength;
  2524. }
  2525. // Keep scrollPercentage within the range 0-1.
  2526. if (scrollYPercentage < 0) { scrollYPercentage = 0; }
  2527. else if (scrollYPercentage > 1) { scrollYPercentage = 1; }
  2528. scrollEvent.y = { percentage: scrollYPercentage, pixels: scrollYAmount };
  2529. }
  2530. if (event.deltaX !== 0) {
  2531. var scrollXAmount = event.deltaX * event.deltaFactor;
  2532. // Get the scroll percentage
  2533. scrollLeft = gridUtil.normalizeScrollLeft(containerCtrl.viewport, grid);
  2534. scrollEvent.horizontalScrollLength = (colContainer.getCanvasWidth() - colContainer.getViewportWidth());
  2535. var scrollXPercentage = (scrollLeft + scrollXAmount) / scrollEvent.horizontalScrollLength;
  2536. // Keep scrollPercentage within the range 0-1.
  2537. if (scrollXPercentage < 0) { scrollXPercentage = 0; }
  2538. else if (scrollXPercentage > 1) { scrollXPercentage = 1; }
  2539. scrollEvent.x = { percentage: scrollXPercentage, pixels: scrollXAmount };
  2540. }
  2541. // Let the parent container scroll if the grid is already at the top/bottom
  2542. if ((event.deltaY !== 0 && (scrollEvent.atTop(scrollTop) || scrollEvent.atBottom(scrollTop))) ||
  2543. (event.deltaX !== 0 && (scrollEvent.atLeft(scrollLeft) || scrollEvent.atRight(scrollLeft)))) {
  2544. //parent controller scrolls
  2545. }
  2546. else {
  2547. event.preventDefault();
  2548. event.stopPropagation();
  2549. scrollEvent.fireThrottledScrollingEvent('', scrollEvent);
  2550. }
  2551. });
  2552. $elm.bind('$destroy', function() {
  2553. $elm.unbind('keydown');
  2554. ['touchstart', 'touchmove', 'touchend','keydown', 'wheel', 'mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'].forEach(function (eventName) {
  2555. $elm.unbind(eventName);
  2556. });
  2557. });
  2558. // TODO(c0bra): Handle resizing the inner canvas based on the number of elements
  2559. function update() {
  2560. var ret = '';
  2561. var canvasWidth = colContainer.canvasWidth;
  2562. var viewportWidth = colContainer.getViewportWidth();
  2563. var canvasHeight = rowContainer.getCanvasHeight();
  2564. //add additional height for scrollbar on left and right container
  2565. //if ($scope.containerId !== 'body') {
  2566. // canvasHeight -= grid.scrollbarHeight;
  2567. //}
  2568. var viewportHeight = rowContainer.getViewportHeight();
  2569. //shorten the height to make room for a scrollbar placeholder
  2570. if (colContainer.needsHScrollbarPlaceholder()) {
  2571. viewportHeight -= grid.scrollbarHeight;
  2572. }
  2573. var headerViewportWidth,
  2574. footerViewportWidth;
  2575. headerViewportWidth = footerViewportWidth = colContainer.getHeaderViewportWidth();
  2576. // Set canvas dimensions
  2577. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId + ' .ui-grid-canvas { width: ' + canvasWidth + 'px; height: ' + canvasHeight + 'px; }';
  2578. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId + ' .ui-grid-header-canvas { width: ' + (canvasWidth + grid.scrollbarWidth) + 'px; }';
  2579. if (renderContainer.explicitHeaderCanvasHeight) {
  2580. // get height from body container
  2581. var reHCHeight = document.querySelector(
  2582. '.grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-body .ui-grid-header-canvas');
  2583. if (reHCHeight) {
  2584. renderContainer.explicitHeaderCanvasHeight = reHCHeight.offsetHeight;
  2585. }
  2586. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId +
  2587. ' .ui-grid-header-canvas { height: ' + renderContainer.explicitHeaderCanvasHeight + 'px; }';
  2588. }
  2589. else {
  2590. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId + ' .ui-grid-header-canvas { height: inherit; }';
  2591. }
  2592. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId +
  2593. ' .ui-grid-viewport { width: ' + viewportWidth + 'px; height: ' + viewportHeight + 'px; }';
  2594. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId +
  2595. ' .ui-grid-header-viewport { width: ' + headerViewportWidth + 'px; }';
  2596. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId +
  2597. ' .ui-grid-footer-canvas { width: ' + (canvasWidth + grid.scrollbarWidth) + 'px; }';
  2598. ret += '\n .grid' + uiGridCtrl.grid.id + ' .ui-grid-render-container-' + $scope.containerId +
  2599. ' .ui-grid-footer-viewport { width: ' + footerViewportWidth + 'px; }';
  2600. return ret;
  2601. }
  2602. uiGridCtrl.grid.registerStyleComputation({
  2603. priority: 6,
  2604. func: update
  2605. });
  2606. }
  2607. };
  2608. }
  2609. };
  2610. }]);
  2611. module.controller('uiGridRenderContainer', ['$scope', 'gridUtil', function ($scope, gridUtil) {
  2612. }]);
  2613. })();
  2614. (function(){
  2615. 'use strict';
  2616. angular.module('ui.grid').directive('uiGridRow', ['gridUtil', function(gridUtil) {
  2617. return {
  2618. replace: true,
  2619. // priority: 2001,
  2620. // templateUrl: 'ui-grid/ui-grid-row',
  2621. require: ['^uiGrid', '^uiGridRenderContainer'],
  2622. scope: {
  2623. row: '=uiGridRow',
  2624. //rowRenderIndex is added to scope to give the true visual index of the row to any directives that need it
  2625. rowRenderIndex: '='
  2626. },
  2627. compile: function() {
  2628. return {
  2629. pre: function($scope, $elm, $attrs, controllers) {
  2630. var uiGridCtrl = controllers[0];
  2631. var containerCtrl = controllers[1];
  2632. var grid = uiGridCtrl.grid;
  2633. $scope.grid = uiGridCtrl.grid;
  2634. $scope.colContainer = containerCtrl.colContainer;
  2635. // Function for attaching the template to this scope
  2636. var clonedElement, cloneScope;
  2637. function compileTemplate() {
  2638. $scope.row.getRowTemplateFn.then(function (compiledElementFn) {
  2639. // var compiledElementFn = $scope.row.compiledElementFn;
  2640. // Create a new scope for the contents of this row, so we can destroy it later if need be
  2641. var newScope = $scope.$new();
  2642. compiledElementFn(newScope, function (newElm, scope) {
  2643. // If we already have a cloned element, we need to remove it and destroy its scope
  2644. if (clonedElement) {
  2645. clonedElement.remove();
  2646. cloneScope.$destroy();
  2647. }
  2648. // Empty the row and append the new element
  2649. $elm.empty().append(newElm);
  2650. // Save the new cloned element and scope
  2651. clonedElement = newElm;
  2652. cloneScope = newScope;
  2653. });
  2654. }).catch(angular.noop);
  2655. }
  2656. // Initially attach the compiled template to this scope
  2657. compileTemplate();
  2658. // If the row's compiled element function changes, we need to replace this element's contents with the new compiled template
  2659. $scope.$watch('row.getRowTemplateFn', function (newFunc, oldFunc) {
  2660. if (newFunc !== oldFunc) {
  2661. compileTemplate();
  2662. }
  2663. });
  2664. },
  2665. post: function($scope, $elm, $attrs, controllers) {
  2666. }
  2667. };
  2668. }
  2669. };
  2670. }]);
  2671. })();
  2672. (function(){
  2673. // 'use strict';
  2674. /**
  2675. * @ngdoc directive
  2676. * @name ui.grid.directive:uiGridStyle
  2677. * @element style
  2678. * @restrict A
  2679. *
  2680. * @description
  2681. * Allows us to interpolate expressions in `<style>` elements. Angular doesn't do this by default as it can/will/might? break in IE8.
  2682. *
  2683. * @example
  2684. <doc:example module="app">
  2685. <doc:source>
  2686. <script>
  2687. var app = angular.module('app', ['ui.grid']);
  2688. app.controller('MainCtrl', ['$scope', function ($scope) {
  2689. $scope.myStyle = '.blah { border: 1px solid }';
  2690. }]);
  2691. </script>
  2692. <div ng-controller="MainCtrl">
  2693. <style ui-grid-style>{{ myStyle }}</style>
  2694. <span class="blah">I am in a box.</span>
  2695. </div>
  2696. </doc:source>
  2697. <doc:scenario>
  2698. it('should apply the right class to the element', function () {
  2699. element(by.css('.blah')).getCssValue('border-top-width')
  2700. .then(function(c) {
  2701. expect(c).toContain('1px');
  2702. });
  2703. });
  2704. </doc:scenario>
  2705. </doc:example>
  2706. */
  2707. angular.module('ui.grid').directive('uiGridStyle', ['gridUtil', '$interpolate', function(gridUtil, $interpolate) {
  2708. return {
  2709. // restrict: 'A',
  2710. // priority: 1000,
  2711. // require: '?^uiGrid',
  2712. link: function($scope, $elm, $attrs, uiGridCtrl) {
  2713. // gridUtil.logDebug('ui-grid-style link');
  2714. // if (uiGridCtrl === undefined) {
  2715. // gridUtil.logWarn('[ui-grid-style link] uiGridCtrl is undefined!');
  2716. // }
  2717. var interpolateFn = $interpolate($elm.text(), true);
  2718. if (interpolateFn) {
  2719. $scope.$watch(interpolateFn, function(value) {
  2720. $elm.text(value);
  2721. });
  2722. }
  2723. // uiGridCtrl.recalcRowStyles = function() {
  2724. // var offset = (scope.options.offsetTop || 0) - (scope.options.excessRows * scope.options.rowHeight);
  2725. // var rowHeight = scope.options.rowHeight;
  2726. // var ret = '';
  2727. // var rowStyleCount = uiGridCtrl.minRowsToRender() + (scope.options.excessRows * 2);
  2728. // for (var i = 1; i <= rowStyleCount; i++) {
  2729. // ret = ret + ' .grid' + scope.gridId + ' .ui-grid-row:nth-child(' + i + ') { top: ' + offset + 'px; }';
  2730. // offset = offset + rowHeight;
  2731. // }
  2732. // scope.rowStyles = ret;
  2733. // };
  2734. // uiGridCtrl.styleComputions.push(uiGridCtrl.recalcRowStyles);
  2735. }
  2736. };
  2737. }]);
  2738. })();
  2739. (function(){
  2740. 'use strict';
  2741. angular.module('ui.grid').directive('uiGridViewport', ['gridUtil','ScrollEvent','uiGridConstants', '$log',
  2742. function(gridUtil, ScrollEvent, uiGridConstants, $log) {
  2743. return {
  2744. replace: true,
  2745. scope: {},
  2746. controllerAs: 'Viewport',
  2747. templateUrl: 'ui-grid/uiGridViewport',
  2748. require: ['^uiGrid', '^uiGridRenderContainer'],
  2749. link: function($scope, $elm, $attrs, controllers) {
  2750. // gridUtil.logDebug('viewport post-link');
  2751. var uiGridCtrl = controllers[0];
  2752. var containerCtrl = controllers[1];
  2753. $scope.containerCtrl = containerCtrl;
  2754. var rowContainer = containerCtrl.rowContainer;
  2755. var colContainer = containerCtrl.colContainer;
  2756. var grid = uiGridCtrl.grid;
  2757. $scope.grid = uiGridCtrl.grid;
  2758. // Put the containers in scope so we can get rows and columns from them
  2759. $scope.rowContainer = containerCtrl.rowContainer;
  2760. $scope.colContainer = containerCtrl.colContainer;
  2761. // Register this viewport with its container
  2762. containerCtrl.viewport = $elm;
  2763. /**
  2764. * @ngdoc function
  2765. * @name customScroller
  2766. * @methodOf ui.grid.class:GridOptions
  2767. * @description (optional) uiGridViewport.on('scroll', scrollHandler) by default.
  2768. * A function that allows you to provide your own scroller function. It is particularly helpful if you want to use third party scrollers
  2769. * as this allows you to do that.
  2770. *
  2771. * <div class="alert alert-info" role="alert"> <strong>NOTE:</strong> It is important to remember to always pass in an event object to
  2772. * the scrollHandler as the grid scrolling behavior will break without it.</div>
  2773. * <h5>Example</h5>
  2774. * <pre>
  2775. * $scope.gridOptions = {
  2776. * customScroller: function myScrolling(uiGridViewport, scrollHandler) {
  2777. * uiGridViewport.on('scroll', function myScrollingOverride(event) {
  2778. * // Do something here
  2779. *
  2780. * scrollHandler(event);
  2781. * });
  2782. * }
  2783. * };
  2784. * </pre>
  2785. * @param {object} uiGridViewport Element being scrolled. (this gets passed in by the grid).
  2786. * @param {function} scrollHandler Function that needs to be called when scrolling happens. (this gets passed in by the grid).
  2787. */
  2788. if (grid && grid.options && grid.options.customScroller) {
  2789. grid.options.customScroller($elm, scrollHandler);
  2790. } else {
  2791. $elm.on('scroll', scrollHandler);
  2792. }
  2793. var ignoreScroll = false;
  2794. function scrollHandler(evt) {
  2795. //Leaving in this commented code in case it can someday be used
  2796. //It does improve performance, but because the horizontal scroll is normalized,
  2797. // using this code will lead to the column header getting slightly out of line with columns
  2798. //
  2799. //if (ignoreScroll && (grid.isScrollingHorizontally || grid.isScrollingHorizontally)) {
  2800. // //don't ask for scrollTop if we just set it
  2801. // ignoreScroll = false;
  2802. // return;
  2803. //}
  2804. //ignoreScroll = true;
  2805. var newScrollTop = $elm[0].scrollTop;
  2806. var newScrollLeft = gridUtil.normalizeScrollLeft($elm, grid);
  2807. var vertScrollPercentage = rowContainer.scrollVertical(newScrollTop);
  2808. var horizScrollPercentage = colContainer.scrollHorizontal(newScrollLeft);
  2809. var scrollEvent = new ScrollEvent(grid, rowContainer, colContainer, ScrollEvent.Sources.ViewPortScroll);
  2810. scrollEvent.newScrollLeft = newScrollLeft;
  2811. scrollEvent.newScrollTop = newScrollTop;
  2812. if ( horizScrollPercentage > -1 ){
  2813. scrollEvent.x = { percentage: horizScrollPercentage };
  2814. }
  2815. if ( vertScrollPercentage > -1 ){
  2816. scrollEvent.y = { percentage: vertScrollPercentage };
  2817. }
  2818. grid.scrollContainers($scope.$parent.containerId, scrollEvent);
  2819. }
  2820. if ($scope.$parent.bindScrollVertical) {
  2821. grid.addVerticalScrollSync($scope.$parent.containerId, syncVerticalScroll);
  2822. }
  2823. if ($scope.$parent.bindScrollHorizontal) {
  2824. grid.addHorizontalScrollSync($scope.$parent.containerId, syncHorizontalScroll);
  2825. grid.addHorizontalScrollSync($scope.$parent.containerId + 'header', syncHorizontalHeader);
  2826. grid.addHorizontalScrollSync($scope.$parent.containerId + 'footer', syncHorizontalFooter);
  2827. }
  2828. function syncVerticalScroll(scrollEvent){
  2829. containerCtrl.prevScrollArgs = scrollEvent;
  2830. var newScrollTop = scrollEvent.getNewScrollTop(rowContainer,containerCtrl.viewport);
  2831. $elm[0].scrollTop = newScrollTop;
  2832. }
  2833. function syncHorizontalScroll(scrollEvent){
  2834. containerCtrl.prevScrollArgs = scrollEvent;
  2835. var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport);
  2836. $elm[0].scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid);
  2837. }
  2838. function syncHorizontalHeader(scrollEvent){
  2839. var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport);
  2840. if (containerCtrl.headerViewport) {
  2841. containerCtrl.headerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid);
  2842. }
  2843. }
  2844. function syncHorizontalFooter(scrollEvent){
  2845. var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport);
  2846. if (containerCtrl.footerViewport) {
  2847. containerCtrl.footerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid);
  2848. }
  2849. }
  2850. $scope.$on('$destroy', function unbindEvents() {
  2851. $elm.off();
  2852. });
  2853. },
  2854. controller: ['$scope', function ($scope) {
  2855. this.rowStyle = function (index) {
  2856. var rowContainer = $scope.rowContainer;
  2857. var colContainer = $scope.colContainer;
  2858. var styles = {};
  2859. if (rowContainer.currentTopRow !== 0){
  2860. //top offset based on hidden rows count
  2861. var translateY = "translateY("+ (rowContainer.currentTopRow * rowContainer.grid.options.rowHeight) +"px)";
  2862. styles['transform'] = translateY;
  2863. styles['-webkit-transform'] = translateY;
  2864. styles['-ms-transform'] = translateY;
  2865. }
  2866. if (colContainer.currentFirstColumn !== 0) {
  2867. if (colContainer.grid.isRTL()) {
  2868. styles['margin-right'] = colContainer.columnOffset + 'px';
  2869. }
  2870. else {
  2871. styles['margin-left'] = colContainer.columnOffset + 'px';
  2872. }
  2873. }
  2874. return styles;
  2875. };
  2876. }]
  2877. };
  2878. }
  2879. ]);
  2880. })();
  2881. (function() {
  2882. angular.module('ui.grid')
  2883. .directive('uiGridVisible', function uiGridVisibleAction() {
  2884. return function ($scope, $elm, $attr) {
  2885. $scope.$watch($attr.uiGridVisible, function (visible) {
  2886. // $elm.css('visibility', visible ? 'visible' : 'hidden');
  2887. $elm[visible ? 'removeClass' : 'addClass']('ui-grid-invisible');
  2888. });
  2889. };
  2890. });
  2891. })();
  2892. (function () {
  2893. 'use strict';
  2894. angular.module('ui.grid').controller('uiGridController', ['$scope', '$element', '$attrs', 'gridUtil', '$q', 'uiGridConstants',
  2895. 'gridClassFactory', '$parse', '$compile',
  2896. function ($scope, $elm, $attrs, gridUtil, $q, uiGridConstants,
  2897. gridClassFactory, $parse, $compile) {
  2898. // gridUtil.logDebug('ui-grid controller');
  2899. var self = this;
  2900. var deregFunctions = [];
  2901. self.grid = gridClassFactory.createGrid($scope.uiGrid);
  2902. //assign $scope.$parent if appScope not already assigned
  2903. self.grid.appScope = self.grid.appScope || $scope.$parent;
  2904. $elm.addClass('grid' + self.grid.id);
  2905. self.grid.rtl = gridUtil.getStyles($elm[0])['direction'] === 'rtl';
  2906. // angular.extend(self.grid.options, );
  2907. //all properties of grid are available on scope
  2908. $scope.grid = self.grid;
  2909. if ($attrs.uiGridColumns) {
  2910. deregFunctions.push( $attrs.$observe('uiGridColumns', function(value) {
  2911. self.grid.options.columnDefs = angular.isString(value) ? angular.fromJson(value) : value;
  2912. self.grid.buildColumns()
  2913. .then(function(){
  2914. self.grid.preCompileCellTemplates();
  2915. self.grid.refreshCanvas(true);
  2916. }).catch(angular.noop);
  2917. }) );
  2918. }
  2919. // prevents an error from being thrown when the array is not defined yet and fastWatch is on
  2920. function getSize(array) {
  2921. return array ? array.length : 0;
  2922. }
  2923. // if fastWatch is set we watch only the length and the reference, not every individual object
  2924. if (self.grid.options.fastWatch) {
  2925. self.uiGrid = $scope.uiGrid;
  2926. if (angular.isString($scope.uiGrid.data)) {
  2927. deregFunctions.push( $scope.$parent.$watch($scope.uiGrid.data, dataWatchFunction) );
  2928. deregFunctions.push( $scope.$parent.$watch(function() {
  2929. if ( self.grid.appScope[$scope.uiGrid.data] ){
  2930. return self.grid.appScope[$scope.uiGrid.data].length;
  2931. } else {
  2932. return undefined;
  2933. }
  2934. }, dataWatchFunction) );
  2935. } else {
  2936. deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.data; }, dataWatchFunction) );
  2937. deregFunctions.push( $scope.$parent.$watch(function() { return getSize($scope.uiGrid.data); }, function(){ dataWatchFunction($scope.uiGrid.data); }) );
  2938. }
  2939. deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.columnDefs; }, columnDefsWatchFunction) );
  2940. deregFunctions.push( $scope.$parent.$watch(function() { return getSize($scope.uiGrid.columnDefs); }, function(){ columnDefsWatchFunction($scope.uiGrid.columnDefs); }) );
  2941. } else {
  2942. if (angular.isString($scope.uiGrid.data)) {
  2943. deregFunctions.push( $scope.$parent.$watchCollection($scope.uiGrid.data, dataWatchFunction) );
  2944. } else {
  2945. deregFunctions.push( $scope.$parent.$watchCollection(function() { return $scope.uiGrid.data; }, dataWatchFunction) );
  2946. }
  2947. deregFunctions.push( $scope.$parent.$watchCollection(function() { return $scope.uiGrid.columnDefs; }, columnDefsWatchFunction) );
  2948. }
  2949. function columnDefsWatchFunction(n, o) {
  2950. if (n && n !== o) {
  2951. self.grid.options.columnDefs = $scope.uiGrid.columnDefs;
  2952. self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.COLUMN, {
  2953. orderByColumnDefs: true,
  2954. preCompileCellTemplates: true
  2955. });
  2956. }
  2957. }
  2958. var mostRecentData;
  2959. function dataWatchFunction(newData) {
  2960. // gridUtil.logDebug('dataWatch fired');
  2961. var promises = [];
  2962. if ( self.grid.options.fastWatch ) {
  2963. if (angular.isString($scope.uiGrid.data)) {
  2964. newData = self.grid.appScope.$eval($scope.uiGrid.data);
  2965. } else {
  2966. newData = $scope.uiGrid.data;
  2967. }
  2968. }
  2969. mostRecentData = newData;
  2970. if (newData) {
  2971. // columns length is greater than the number of row header columns, which don't count because they're created automatically
  2972. var hasColumns = self.grid.columns.length > (self.grid.rowHeaderColumns ? self.grid.rowHeaderColumns.length : 0);
  2973. if (
  2974. // If we have no columns
  2975. !hasColumns &&
  2976. // ... and we don't have a ui-grid-columns attribute, which would define columns for us
  2977. !$attrs.uiGridColumns &&
  2978. // ... and we have no pre-defined columns
  2979. self.grid.options.columnDefs.length === 0 &&
  2980. // ... but we DO have data
  2981. newData.length > 0
  2982. ) {
  2983. // ... then build the column definitions from the data that we have
  2984. self.grid.buildColumnDefsFromData(newData);
  2985. }
  2986. // If we haven't built columns before and either have some columns defined or some data defined
  2987. if (!hasColumns && (self.grid.options.columnDefs.length > 0 || newData.length > 0)) {
  2988. // Build the column set, then pre-compile the column cell templates
  2989. promises.push(self.grid.buildColumns()
  2990. .then(function() {
  2991. self.grid.preCompileCellTemplates();
  2992. }).catch(angular.noop));
  2993. }
  2994. $q.all(promises).then(function() {
  2995. // use most recent data, rather than the potentially outdated data passed into watcher handler
  2996. self.grid.modifyRows(mostRecentData)
  2997. .then(function () {
  2998. // if (self.viewport) {
  2999. self.grid.redrawInPlace(true);
  3000. // }
  3001. $scope.$evalAsync(function() {
  3002. self.grid.refreshCanvas(true);
  3003. self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.ROW);
  3004. });
  3005. }).catch(angular.noop);
  3006. }).catch(angular.noop);
  3007. }
  3008. }
  3009. var styleWatchDereg = $scope.$watch(function () { return self.grid.styleComputations; }, function() {
  3010. self.grid.refreshCanvas(true);
  3011. });
  3012. $scope.$on('$destroy', function() {
  3013. deregFunctions.forEach( function( deregFn ){ deregFn(); });
  3014. styleWatchDereg();
  3015. });
  3016. self.fireEvent = function(eventName, args) {
  3017. args = args || {};
  3018. // Add the grid to the event arguments if it's not there
  3019. if (angular.isUndefined(args.grid)) {
  3020. args.grid = self.grid;
  3021. }
  3022. $scope.$broadcast(eventName, args);
  3023. };
  3024. self.innerCompile = function innerCompile(elm) {
  3025. $compile(elm)($scope);
  3026. };
  3027. }]);
  3028. /**
  3029. * @ngdoc directive
  3030. * @name ui.grid.directive:uiGrid
  3031. * @element div
  3032. * @restrict EA
  3033. * @param {Object} uiGrid Options for the grid to use
  3034. *
  3035. * @description Create a very basic grid.
  3036. *
  3037. * @example
  3038. <example module="app">
  3039. <file name="app.js">
  3040. var app = angular.module('app', ['ui.grid']);
  3041. app.controller('MainCtrl', ['$scope', function ($scope) {
  3042. $scope.data = [
  3043. { name: 'Bob', title: 'CEO' },
  3044. { name: 'Frank', title: 'Lowly Developer' }
  3045. ];
  3046. }]);
  3047. </file>
  3048. <file name="index.html">
  3049. <div ng-controller="MainCtrl">
  3050. <div ui-grid="{ data: data }"></div>
  3051. </div>
  3052. </file>
  3053. </example>
  3054. */
  3055. angular.module('ui.grid').directive('uiGrid', uiGridDirective);
  3056. uiGridDirective.$inject = ['$window', 'gridUtil', 'uiGridConstants'];
  3057. function uiGridDirective($window, gridUtil, uiGridConstants) {
  3058. return {
  3059. templateUrl: 'ui-grid/ui-grid',
  3060. scope: {
  3061. uiGrid: '='
  3062. },
  3063. replace: true,
  3064. transclude: true,
  3065. controller: 'uiGridController',
  3066. compile: function () {
  3067. return {
  3068. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  3069. var grid = uiGridCtrl.grid;
  3070. // Initialize scrollbars (TODO: move to controller??)
  3071. uiGridCtrl.scrollbars = [];
  3072. grid.element = $elm;
  3073. // See if the grid has a rendered width, if not, wait a bit and try again
  3074. var sizeCheckInterval = 100; // ms
  3075. var maxSizeChecks = 20; // 2 seconds total
  3076. var sizeChecks = 0;
  3077. // Setup (event listeners) the grid
  3078. setup();
  3079. // And initialize it
  3080. init();
  3081. // Mark rendering complete so API events can happen
  3082. grid.renderingComplete();
  3083. // If the grid doesn't have size currently, wait for a bit to see if it gets size
  3084. checkSize();
  3085. /*-- Methods --*/
  3086. function checkSize() {
  3087. // If the grid has no width and we haven't checked more than <maxSizeChecks> times, check again in <sizeCheckInterval> milliseconds
  3088. if ($elm[0].offsetWidth <= 0 && sizeChecks < maxSizeChecks) {
  3089. setTimeout(checkSize, sizeCheckInterval);
  3090. sizeChecks++;
  3091. } else {
  3092. $scope.$applyAsync(init);
  3093. }
  3094. }
  3095. // Setup event listeners and watchers
  3096. function setup() {
  3097. var deregisterLeftWatcher, deregisterRightWatcher;
  3098. // Bind to window resize events
  3099. angular.element($window).on('resize', gridResize);
  3100. // Unbind from window resize events when the grid is destroyed
  3101. $elm.on('$destroy', function () {
  3102. angular.element($window).off('resize', gridResize);
  3103. deregisterLeftWatcher();
  3104. deregisterRightWatcher();
  3105. });
  3106. // If we add a left container after render, we need to watch and react
  3107. deregisterLeftWatcher = $scope.$watch(function () { return grid.hasLeftContainer();}, function (newValue, oldValue) {
  3108. if (newValue === oldValue) {
  3109. return;
  3110. }
  3111. grid.refreshCanvas(true);
  3112. });
  3113. // If we add a right container after render, we need to watch and react
  3114. deregisterRightWatcher = $scope.$watch(function () { return grid.hasRightContainer();}, function (newValue, oldValue) {
  3115. if (newValue === oldValue) {
  3116. return;
  3117. }
  3118. grid.refreshCanvas(true);
  3119. });
  3120. }
  3121. // Initialize the directive
  3122. function init() {
  3123. grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm);
  3124. // Default canvasWidth to the grid width, in case we don't get any column definitions to calculate it from
  3125. grid.canvasWidth = uiGridCtrl.grid.gridWidth;
  3126. grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm);
  3127. // 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
  3128. if (grid.gridHeight - grid.scrollbarHeight <= grid.options.rowHeight && grid.options.enableMinHeightCheck) {
  3129. autoAdjustHeight();
  3130. }
  3131. // Run initial canvas refresh
  3132. grid.refreshCanvas(true);
  3133. }
  3134. // Set the grid's height ourselves in the case that its height would be unusably small
  3135. function autoAdjustHeight() {
  3136. // Figure out the new height
  3137. var contentHeight = grid.options.minRowsToShow * grid.options.rowHeight;
  3138. var headerHeight = grid.options.showHeader ? grid.options.headerRowHeight : 0;
  3139. var footerHeight = grid.calcFooterHeight();
  3140. var scrollbarHeight = 0;
  3141. if (grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.ALWAYS) {
  3142. scrollbarHeight = gridUtil.getScrollbarWidth();
  3143. }
  3144. var maxNumberOfFilters = 0;
  3145. // Calculates the maximum number of filters in the columns
  3146. angular.forEach(grid.options.columnDefs, function(col) {
  3147. if (col.hasOwnProperty('filter')) {
  3148. if (maxNumberOfFilters < 1) {
  3149. maxNumberOfFilters = 1;
  3150. }
  3151. }
  3152. else if (col.hasOwnProperty('filters')) {
  3153. if (maxNumberOfFilters < col.filters.length) {
  3154. maxNumberOfFilters = col.filters.length;
  3155. }
  3156. }
  3157. });
  3158. if (grid.options.enableFiltering && !maxNumberOfFilters) {
  3159. var allColumnsHaveFilteringTurnedOff = grid.options.columnDefs.length && grid.options.columnDefs.every(function(col) {
  3160. return col.enableFiltering === false;
  3161. });
  3162. if (!allColumnsHaveFilteringTurnedOff) {
  3163. maxNumberOfFilters = 1;
  3164. }
  3165. }
  3166. var filterHeight = maxNumberOfFilters * headerHeight;
  3167. var newHeight = headerHeight + contentHeight + footerHeight + scrollbarHeight + filterHeight;
  3168. $elm.css('height', newHeight + 'px');
  3169. grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm);
  3170. }
  3171. // Resize the grid on window resize events
  3172. function gridResize() {
  3173. grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm);
  3174. grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm);
  3175. grid.refreshCanvas(true);
  3176. }
  3177. }
  3178. };
  3179. }
  3180. };
  3181. }
  3182. })();
  3183. (function(){
  3184. 'use strict';
  3185. // TODO: rename this file to ui-grid-pinned-container.js
  3186. angular.module('ui.grid').directive('uiGridPinnedContainer', ['gridUtil', function (gridUtil) {
  3187. return {
  3188. restrict: 'EA',
  3189. replace: true,
  3190. 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>',
  3191. scope: {
  3192. side: '=uiGridPinnedContainer'
  3193. },
  3194. require: '^uiGrid',
  3195. compile: function compile() {
  3196. return {
  3197. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  3198. // gridUtil.logDebug('ui-grid-pinned-container ' + $scope.side + ' link');
  3199. var grid = uiGridCtrl.grid;
  3200. var myWidth = 0;
  3201. $elm.addClass('ui-grid-pinned-container-' + $scope.side);
  3202. // Monkey-patch the viewport width function
  3203. if ($scope.side === 'left' || $scope.side === 'right') {
  3204. grid.renderContainers[$scope.side].getViewportWidth = monkeyPatchedGetViewportWidth;
  3205. }
  3206. function monkeyPatchedGetViewportWidth() {
  3207. /*jshint validthis: true */
  3208. var self = this;
  3209. var viewportWidth = 0;
  3210. self.visibleColumnCache.forEach(function (column) {
  3211. viewportWidth += column.drawnWidth;
  3212. });
  3213. var adjustment = self.getViewportAdjustment();
  3214. viewportWidth = viewportWidth + adjustment.width;
  3215. return viewportWidth;
  3216. }
  3217. function updateContainerWidth() {
  3218. if ($scope.side === 'left' || $scope.side === 'right') {
  3219. var cols = grid.renderContainers[$scope.side].visibleColumnCache;
  3220. var width = 0;
  3221. for (var i = 0; i < cols.length; i++) {
  3222. var col = cols[i];
  3223. width += col.drawnWidth || col.width || 0;
  3224. }
  3225. return width;
  3226. }
  3227. }
  3228. function updateContainerDimensions() {
  3229. var ret = '';
  3230. // Column containers
  3231. if ($scope.side === 'left' || $scope.side === 'right') {
  3232. myWidth = updateContainerWidth();
  3233. // gridUtil.logDebug('myWidth', myWidth);
  3234. // TODO(c0bra): Subtract sum of col widths from grid viewport width and update it
  3235. $elm.attr('style', null);
  3236. // var myHeight = grid.renderContainers.body.getViewportHeight(); // + grid.horizontalScrollbarHeight;
  3237. 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; } ';
  3238. }
  3239. return ret;
  3240. }
  3241. grid.renderContainers.body.registerViewportAdjuster(function (adjustment) {
  3242. myWidth = updateContainerWidth();
  3243. // Subtract our own width
  3244. adjustment.width -= myWidth;
  3245. adjustment.side = $scope.side;
  3246. return adjustment;
  3247. });
  3248. // Register style computation to adjust for columns in `side`'s render container
  3249. grid.registerStyleComputation({
  3250. priority: 15,
  3251. func: updateContainerDimensions
  3252. });
  3253. }
  3254. };
  3255. }
  3256. };
  3257. }]);
  3258. })();
  3259. (function(){
  3260. angular.module('ui.grid')
  3261. .factory('Grid', ['$q', '$compile', '$parse', 'gridUtil', 'uiGridConstants', 'GridOptions', 'GridColumn', 'GridRow', 'GridApi', 'rowSorter', 'rowSearcher', 'GridRenderContainer', '$timeout','ScrollEvent',
  3262. function($q, $compile, $parse, gridUtil, uiGridConstants, GridOptions, GridColumn, GridRow, GridApi, rowSorter, rowSearcher, GridRenderContainer, $timeout, ScrollEvent) {
  3263. /**
  3264. * @ngdoc object
  3265. * @name ui.grid.core.api:PublicApi
  3266. * @description Public Api for the core grid features
  3267. *
  3268. */
  3269. /**
  3270. * @ngdoc function
  3271. * @name ui.grid.class:Grid
  3272. * @description Grid is the main viewModel. Any properties or methods needed to maintain state are defined in
  3273. * this prototype. One instance of Grid is created per Grid directive instance.
  3274. * @param {object} options Object map of options to pass into the grid. An 'id' property is expected.
  3275. */
  3276. var Grid = function Grid(options) {
  3277. var self = this;
  3278. // Get the id out of the options, then remove it
  3279. if (options !== undefined && typeof(options.id) !== 'undefined' && options.id) {
  3280. if (!/^[_a-zA-Z0-9-]+$/.test(options.id)) {
  3281. throw new Error("Grid id '" + options.id + '" is invalid. It must follow CSS selector syntax rules.');
  3282. }
  3283. }
  3284. else {
  3285. throw new Error('No ID provided. An ID must be given when creating a grid.');
  3286. }
  3287. self.id = options.id;
  3288. delete options.id;
  3289. // Get default options
  3290. self.options = GridOptions.initialize( options );
  3291. /**
  3292. * @ngdoc object
  3293. * @name appScope
  3294. * @propertyOf ui.grid.class:Grid
  3295. * @description reference to the application scope (the parent scope of the ui-grid element). Assigned in ui-grid controller
  3296. * <br/>
  3297. * use gridOptions.appScopeProvider to override the default assignment of $scope.$parent with any reference
  3298. */
  3299. self.appScope = self.options.appScopeProvider;
  3300. self.headerHeight = self.options.headerRowHeight;
  3301. /**
  3302. * @ngdoc object
  3303. * @name footerHeight
  3304. * @propertyOf ui.grid.class:Grid
  3305. * @description returns the total footer height gridFooter + columnFooter
  3306. */
  3307. self.footerHeight = self.calcFooterHeight();
  3308. /**
  3309. * @ngdoc object
  3310. * @name columnFooterHeight
  3311. * @propertyOf ui.grid.class:Grid
  3312. * @description returns the total column footer height
  3313. */
  3314. self.columnFooterHeight = self.calcColumnFooterHeight();
  3315. self.rtl = false;
  3316. self.gridHeight = 0;
  3317. self.gridWidth = 0;
  3318. self.columnBuilders = [];
  3319. self.rowBuilders = [];
  3320. self.rowsProcessors = [];
  3321. self.columnsProcessors = [];
  3322. self.styleComputations = [];
  3323. self.viewportAdjusters = [];
  3324. self.rowHeaderColumns = [];
  3325. self.dataChangeCallbacks = {};
  3326. self.verticalScrollSyncCallBackFns = {};
  3327. self.horizontalScrollSyncCallBackFns = {};
  3328. // self.visibleRowCache = [];
  3329. // Set of 'render' containers for self grid, which can render sets of rows
  3330. self.renderContainers = {};
  3331. // Create a
  3332. self.renderContainers.body = new GridRenderContainer('body', self);
  3333. self.cellValueGetterCache = {};
  3334. // Cached function to use with custom row templates
  3335. self.getRowTemplateFn = null;
  3336. //representation of the rows on the grid.
  3337. //these are wrapped references to the actual data rows (options.data)
  3338. self.rows = [];
  3339. //represents the columns on the grid
  3340. self.columns = [];
  3341. /**
  3342. * @ngdoc boolean
  3343. * @name isScrollingVertically
  3344. * @propertyOf ui.grid.class:Grid
  3345. * @description set to true when Grid is scrolling vertically. Set to false via debounced method
  3346. */
  3347. self.isScrollingVertically = false;
  3348. /**
  3349. * @ngdoc boolean
  3350. * @name isScrollingHorizontally
  3351. * @propertyOf ui.grid.class:Grid
  3352. * @description set to true when Grid is scrolling horizontally. Set to false via debounced method
  3353. */
  3354. self.isScrollingHorizontally = false;
  3355. /**
  3356. * @ngdoc property
  3357. * @name scrollDirection
  3358. * @propertyOf ui.grid.class:Grid
  3359. * @description set one of the {@link ui.grid.service:uiGridConstants#properties_scrollDirection uiGridConstants.scrollDirection}
  3360. * values (UP, DOWN, LEFT, RIGHT, NONE), which tells us which direction we are scrolling.
  3361. * Set to NONE via debounced method
  3362. */
  3363. self.scrollDirection = uiGridConstants.scrollDirection.NONE;
  3364. //if true, grid will not respond to any scroll events
  3365. self.disableScrolling = false;
  3366. function vertical (scrollEvent) {
  3367. self.isScrollingVertically = false;
  3368. self.api.core.raise.scrollEnd(scrollEvent);
  3369. self.scrollDirection = uiGridConstants.scrollDirection.NONE;
  3370. }
  3371. var debouncedVertical = gridUtil.debounce(vertical, self.options.scrollDebounce);
  3372. var debouncedVerticalMinDelay = gridUtil.debounce(vertical, 0);
  3373. function horizontal (scrollEvent) {
  3374. self.isScrollingHorizontally = false;
  3375. self.api.core.raise.scrollEnd(scrollEvent);
  3376. self.scrollDirection = uiGridConstants.scrollDirection.NONE;
  3377. }
  3378. var debouncedHorizontal = gridUtil.debounce(horizontal, self.options.scrollDebounce);
  3379. var debouncedHorizontalMinDelay = gridUtil.debounce(horizontal, 0);
  3380. /**
  3381. * @ngdoc function
  3382. * @name flagScrollingVertically
  3383. * @methodOf ui.grid.class:Grid
  3384. * @description sets isScrollingVertically to true and sets it to false in a debounced function
  3385. */
  3386. self.flagScrollingVertically = function(scrollEvent) {
  3387. if (!self.isScrollingVertically && !self.isScrollingHorizontally) {
  3388. self.api.core.raise.scrollBegin(scrollEvent);
  3389. }
  3390. self.isScrollingVertically = true;
  3391. if (self.options.scrollDebounce === 0 || !scrollEvent.withDelay) {
  3392. debouncedVerticalMinDelay(scrollEvent);
  3393. }
  3394. else {
  3395. debouncedVertical(scrollEvent);
  3396. }
  3397. };
  3398. /**
  3399. * @ngdoc function
  3400. * @name flagScrollingHorizontally
  3401. * @methodOf ui.grid.class:Grid
  3402. * @description sets isScrollingHorizontally to true and sets it to false in a debounced function
  3403. */
  3404. self.flagScrollingHorizontally = function(scrollEvent) {
  3405. if (!self.isScrollingVertically && !self.isScrollingHorizontally) {
  3406. self.api.core.raise.scrollBegin(scrollEvent);
  3407. }
  3408. self.isScrollingHorizontally = true;
  3409. if (self.options.scrollDebounce === 0 || !scrollEvent.withDelay) {
  3410. debouncedHorizontalMinDelay(scrollEvent);
  3411. }
  3412. else {
  3413. debouncedHorizontal(scrollEvent);
  3414. }
  3415. };
  3416. self.scrollbarHeight = 0;
  3417. self.scrollbarWidth = 0;
  3418. if (self.options.enableHorizontalScrollbar !== uiGridConstants.scrollbars.NEVER) {
  3419. self.scrollbarHeight = gridUtil.getScrollbarWidth();
  3420. }
  3421. if (self.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER) {
  3422. self.scrollbarWidth = gridUtil.getScrollbarWidth();
  3423. }
  3424. self.api = new GridApi(self);
  3425. /**
  3426. * @ngdoc function
  3427. * @name refresh
  3428. * @methodOf ui.grid.core.api:PublicApi
  3429. * @description Refresh the rendered grid on screen.
  3430. * The refresh method re-runs both the columnProcessors and the
  3431. * rowProcessors, as well as calling refreshCanvas to update all
  3432. * the grid sizing. In general you should prefer to use queueGridRefresh
  3433. * instead, which is basically a debounced version of refresh.
  3434. *
  3435. * If you only want to resize the grid, not regenerate all the rows
  3436. * and columns, you should consider directly calling refreshCanvas instead.
  3437. *
  3438. * @param {boolean} [rowsAltered] Optional flag for refreshing when the number of rows has changed
  3439. */
  3440. self.api.registerMethod( 'core', 'refresh', this.refresh );
  3441. /**
  3442. * @ngdoc function
  3443. * @name queueGridRefresh
  3444. * @methodOf ui.grid.core.api:PublicApi
  3445. * @description Request a refresh of the rendered grid on screen, if multiple
  3446. * calls to queueGridRefresh are made within a digest cycle only one will execute.
  3447. * The refresh method re-runs both the columnProcessors and the
  3448. * rowProcessors, as well as calling refreshCanvas to update all
  3449. * the grid sizing. In general you should prefer to use queueGridRefresh
  3450. * instead, which is basically a debounced version of refresh.
  3451. *
  3452. */
  3453. self.api.registerMethod( 'core', 'queueGridRefresh', this.queueGridRefresh );
  3454. /**
  3455. * @ngdoc function
  3456. * @name refreshRows
  3457. * @methodOf ui.grid.core.api:PublicApi
  3458. * @description Runs only the rowProcessors, columns remain as they were.
  3459. * It then calls redrawInPlace and refreshCanvas, which adjust the grid sizing.
  3460. * @returns {promise} promise that is resolved when render completes?
  3461. *
  3462. */
  3463. self.api.registerMethod( 'core', 'refreshRows', this.refreshRows );
  3464. /**
  3465. * @ngdoc function
  3466. * @name queueRefresh
  3467. * @methodOf ui.grid.core.api:PublicApi
  3468. * @description Requests execution of refreshCanvas, if multiple requests are made
  3469. * during a digest cycle only one will run. RefreshCanvas updates the grid sizing.
  3470. * @returns {promise} promise that is resolved when render completes?
  3471. *
  3472. */
  3473. self.api.registerMethod( 'core', 'queueRefresh', this.queueRefresh );
  3474. /**
  3475. * @ngdoc function
  3476. * @name handleWindowResize
  3477. * @methodOf ui.grid.core.api:PublicApi
  3478. * @description Trigger a grid resize, normally this would be picked
  3479. * up by a watch on window size, but in some circumstances it is necessary
  3480. * to call this manually
  3481. * @returns {promise} promise that is resolved when render completes?
  3482. *
  3483. */
  3484. self.api.registerMethod( 'core', 'handleWindowResize', this.handleWindowResize );
  3485. /**
  3486. * @ngdoc function
  3487. * @name addRowHeaderColumn
  3488. * @methodOf ui.grid.core.api:PublicApi
  3489. * @description adds a row header column to the grid
  3490. * @param {object} column def
  3491. * @param {number} order Determines order of header column on grid. Lower order means header
  3492. * is positioned to the left of higher order headers
  3493. *
  3494. */
  3495. self.api.registerMethod( 'core', 'addRowHeaderColumn', this.addRowHeaderColumn );
  3496. /**
  3497. * @ngdoc function
  3498. * @name scrollToIfNecessary
  3499. * @methodOf ui.grid.core.api:PublicApi
  3500. * @description Scrolls the grid to make a certain row and column combo visible,
  3501. * in the case that it is not completely visible on the screen already.
  3502. * @param {GridRow} gridRow row to make visible
  3503. * @param {GridColumn} gridCol column to make visible
  3504. * @returns {promise} a promise that is resolved when scrolling is complete
  3505. *
  3506. */
  3507. self.api.registerMethod( 'core', 'scrollToIfNecessary', function(gridRow, gridCol) { return self.scrollToIfNecessary(gridRow, gridCol);} );
  3508. /**
  3509. * @ngdoc function
  3510. * @name scrollTo
  3511. * @methodOf ui.grid.core.api:PublicApi
  3512. * @description Scroll the grid such that the specified
  3513. * row and column is in view
  3514. * @param {object} rowEntity gridOptions.data[] array instance to make visible
  3515. * @param {object} colDef to make visible
  3516. * @returns {promise} a promise that is resolved after any scrolling is finished
  3517. */
  3518. self.api.registerMethod( 'core', 'scrollTo', function (rowEntity, colDef) { return self.scrollTo(rowEntity, colDef);} );
  3519. /**
  3520. * @ngdoc function
  3521. * @name registerRowsProcessor
  3522. * @methodOf ui.grid.core.api:PublicApi
  3523. * @description
  3524. * Register a "rows processor" function. When the rows are updated,
  3525. * the grid calls each registered "rows processor", which has a chance
  3526. * to alter the set of rows (sorting, etc) as long as the count is not
  3527. * modified.
  3528. *
  3529. * @param {function(renderedRowsToProcess, columns )} processorFunction rows processor function, which
  3530. * is run in the context of the grid (i.e. this for the function will be the grid), and must
  3531. * return the updated rows list, which is passed to the next processor in the chain
  3532. * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room
  3533. * for other people to inject rows processors at intermediate priorities. Lower priority rowsProcessors run earlier.
  3534. *
  3535. * At present allRowsVisible is running at 50, sort manipulations running at 60-65, filter is running at 100,
  3536. * sort is at 200, grouping and treeview at 400-410, selectable rows at 500, pagination at 900 (pagination will generally want to be last)
  3537. */
  3538. self.api.registerMethod( 'core', 'registerRowsProcessor', this.registerRowsProcessor );
  3539. /**
  3540. * @ngdoc function
  3541. * @name registerColumnsProcessor
  3542. * @methodOf ui.grid.core.api:PublicApi
  3543. * @description
  3544. * Register a "columns processor" function. When the columns are updated,
  3545. * the grid calls each registered "columns processor", which has a chance
  3546. * to alter the set of columns as long as the count is not
  3547. * modified.
  3548. *
  3549. * @param {function(renderedColumnsToProcess, rows )} processorFunction columns processor function, which
  3550. * is run in the context of the grid (i.e. this for the function will be the grid), and must
  3551. * return the updated columns list, which is passed to the next processor in the chain
  3552. * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room
  3553. * for other people to inject columns processors at intermediate priorities. Lower priority columnsProcessors run earlier.
  3554. *
  3555. * 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)
  3556. */
  3557. self.api.registerMethod( 'core', 'registerColumnsProcessor', this.registerColumnsProcessor );
  3558. /**
  3559. * @ngdoc function
  3560. * @name sortHandleNulls
  3561. * @methodOf ui.grid.core.api:PublicApi
  3562. * @description A null handling method that can be used when building custom sort
  3563. * functions
  3564. * @example
  3565. * <pre>
  3566. * mySortFn = function(a, b) {
  3567. * var nulls = $scope.gridApi.core.sortHandleNulls(a, b);
  3568. * if ( nulls !== null ){
  3569. * return nulls;
  3570. * } else {
  3571. * // your code for sorting here
  3572. * };
  3573. * </pre>
  3574. * @param {object} a sort value a
  3575. * @param {object} b sort value b
  3576. * @returns {number} null if there were no nulls/undefineds, otherwise returns
  3577. * a sort value that should be passed back from the sort function
  3578. *
  3579. */
  3580. self.api.registerMethod( 'core', 'sortHandleNulls', rowSorter.handleNulls );
  3581. /**
  3582. * @ngdoc function
  3583. * @name sortChanged
  3584. * @methodOf ui.grid.core.api:PublicApi
  3585. * @description The sort criteria on one or more columns has
  3586. * changed. Provides as parameters the grid and the output of
  3587. * getColumnSorting, which is an array of gridColumns
  3588. * that have sorting on them, sorted in priority order.
  3589. *
  3590. * @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed.
  3591. * @param {Function} callBack Will be called when the event is emited. The function passes back the grid and an array of
  3592. * columns with sorts on them, in priority order.
  3593. *
  3594. * @example
  3595. * <pre>
  3596. * gridApi.core.on.sortChanged( $scope, function(grid, sortColumns){
  3597. * // do something
  3598. * });
  3599. * </pre>
  3600. */
  3601. self.api.registerEvent( 'core', 'sortChanged' );
  3602. /**
  3603. * @ngdoc function
  3604. * @name columnVisibilityChanged
  3605. * @methodOf ui.grid.core.api:PublicApi
  3606. * @description The visibility of a column has changed,
  3607. * the column itself is passed out as a parameter of the event.
  3608. *
  3609. * @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed.
  3610. * @param {Function} callBack Will be called when the event is emited. The function passes back the GridCol that has changed.
  3611. *
  3612. * @example
  3613. * <pre>
  3614. * gridApi.core.on.columnVisibilityChanged( $scope, function (column) {
  3615. * // do something
  3616. * } );
  3617. * </pre>
  3618. */
  3619. self.api.registerEvent( 'core', 'columnVisibilityChanged' );
  3620. /**
  3621. * @ngdoc method
  3622. * @name notifyDataChange
  3623. * @methodOf ui.grid.core.api:PublicApi
  3624. * @description Notify the grid that a data or config change has occurred,
  3625. * where that change isn't something the grid was otherwise noticing. This
  3626. * might be particularly relevant where you've changed values within the data
  3627. * and you'd like cell classes to be re-evaluated, or changed config within
  3628. * the columnDef and you'd like headerCellClasses to be re-evaluated.
  3629. * @param {string} type one of the
  3630. * {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange}
  3631. * values (ALL, ROW, EDIT, COLUMN, OPTIONS), which tells us which refreshes to fire.
  3632. *
  3633. * - ALL: listeners fired on any of these events, fires listeners on all events.
  3634. * - ROW: fired when a row is added or removed.
  3635. * - EDIT: fired when the data in a cell is edited.
  3636. * - COLUMN: fired when the column definitions are modified.
  3637. * - OPTIONS: fired when the grid options are modified.
  3638. */
  3639. self.api.registerMethod( 'core', 'notifyDataChange', this.notifyDataChange );
  3640. /**
  3641. * @ngdoc method
  3642. * @name clearAllFilters
  3643. * @methodOf ui.grid.core.api:PublicApi
  3644. * @description Clears all filters and optionally refreshes the visible rows.
  3645. * @param {object} refreshRows Defaults to true.
  3646. * @param {object} clearConditions Defaults to false.
  3647. * @param {object} clearFlags Defaults to false.
  3648. * @returns {promise} If `refreshRows` is true, returns a promise of the rows refreshing.
  3649. */
  3650. self.api.registerMethod('core', 'clearAllFilters', this.clearAllFilters);
  3651. self.registerDataChangeCallback( self.columnRefreshCallback, [uiGridConstants.dataChange.COLUMN]);
  3652. self.registerDataChangeCallback( self.processRowsCallback, [uiGridConstants.dataChange.EDIT]);
  3653. self.registerDataChangeCallback( self.updateFooterHeightCallback, [uiGridConstants.dataChange.OPTIONS]);
  3654. self.registerStyleComputation({
  3655. priority: 10,
  3656. func: self.getFooterStyles
  3657. });
  3658. };
  3659. Grid.prototype.calcFooterHeight = function () {
  3660. if (!this.hasFooter()) {
  3661. return 0;
  3662. }
  3663. var height = 0;
  3664. if (this.options.showGridFooter) {
  3665. height += this.options.gridFooterHeight;
  3666. }
  3667. height += this.calcColumnFooterHeight();
  3668. return height;
  3669. };
  3670. Grid.prototype.calcColumnFooterHeight = function () {
  3671. var height = 0;
  3672. if (this.options.showColumnFooter) {
  3673. height += this.options.columnFooterHeight;
  3674. }
  3675. return height;
  3676. };
  3677. Grid.prototype.getFooterStyles = function () {
  3678. var style = '.grid' + this.id + ' .ui-grid-footer-aggregates-row { height: ' + this.options.columnFooterHeight + 'px; }';
  3679. style += ' .grid' + this.id + ' .ui-grid-footer-info { height: ' + this.options.gridFooterHeight + 'px; }';
  3680. return style;
  3681. };
  3682. Grid.prototype.hasFooter = function () {
  3683. return this.options.showGridFooter || this.options.showColumnFooter;
  3684. };
  3685. /**
  3686. * @ngdoc function
  3687. * @name isRTL
  3688. * @methodOf ui.grid.class:Grid
  3689. * @description Returns true if grid is RightToLeft
  3690. */
  3691. Grid.prototype.isRTL = function () {
  3692. return this.rtl;
  3693. };
  3694. /**
  3695. * @ngdoc function
  3696. * @name registerColumnBuilder
  3697. * @methodOf ui.grid.class:Grid
  3698. * @description When the build creates columns from column definitions, the columnbuilders will be called to add
  3699. * additional properties to the column.
  3700. * @param {function(colDef, col, gridOptions)} columnBuilder function to be called
  3701. */
  3702. Grid.prototype.registerColumnBuilder = function registerColumnBuilder(columnBuilder) {
  3703. this.columnBuilders.push(columnBuilder);
  3704. };
  3705. /**
  3706. * @ngdoc function
  3707. * @name buildColumnDefsFromData
  3708. * @methodOf ui.grid.class:Grid
  3709. * @description Populates columnDefs from the provided data
  3710. * @param {function(colDef, col, gridOptions)} rowBuilder function to be called
  3711. */
  3712. Grid.prototype.buildColumnDefsFromData = function (dataRows){
  3713. this.options.columnDefs = gridUtil.getColumnsFromData(dataRows, this.options.excludeProperties);
  3714. };
  3715. /**
  3716. * @ngdoc function
  3717. * @name registerRowBuilder
  3718. * @methodOf ui.grid.class:Grid
  3719. * @description When the build creates rows from gridOptions.data, the rowBuilders will be called to add
  3720. * additional properties to the row.
  3721. * @param {function(row, gridOptions)} rowBuilder function to be called
  3722. */
  3723. Grid.prototype.registerRowBuilder = function registerRowBuilder(rowBuilder) {
  3724. this.rowBuilders.push(rowBuilder);
  3725. };
  3726. /**
  3727. * @ngdoc function
  3728. * @name registerDataChangeCallback
  3729. * @methodOf ui.grid.class:Grid
  3730. * @description When a data change occurs, the data change callbacks of the specified type
  3731. * will be called. The rules are:
  3732. *
  3733. * - when the data watch fires, that is considered a ROW change (the data watch only notices
  3734. * added or removed rows)
  3735. * - when the api is called to inform us of a change, the declared type of that change is used
  3736. * - when a cell edit completes, the EDIT callbacks are triggered
  3737. * - when the columnDef watch fires, the COLUMN callbacks are triggered
  3738. * - when the options watch fires, the OPTIONS callbacks are triggered
  3739. *
  3740. * For a given event:
  3741. * - ALL calls ROW, EDIT, COLUMN, OPTIONS and ALL callbacks
  3742. * - ROW calls ROW and ALL callbacks
  3743. * - EDIT calls EDIT and ALL callbacks
  3744. * - COLUMN calls COLUMN and ALL callbacks
  3745. * - OPTIONS calls OPTIONS and ALL callbacks
  3746. *
  3747. * @param {function(grid)} callback function to be called
  3748. * @param {array} types the types of data change you want to be informed of. Values from
  3749. * the {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange}
  3750. * values ( ALL, EDIT, ROW, COLUMN, OPTIONS ). Optional and defaults to ALL
  3751. * @returns {function} deregister function - a function that can be called to deregister this callback
  3752. */
  3753. Grid.prototype.registerDataChangeCallback = function registerDataChangeCallback(callback, types, _this) {
  3754. var uid = gridUtil.nextUid();
  3755. if ( !types ){
  3756. types = [uiGridConstants.dataChange.ALL];
  3757. }
  3758. if ( !Array.isArray(types)){
  3759. gridUtil.logError("Expected types to be an array or null in registerDataChangeCallback, value passed was: " + types );
  3760. }
  3761. this.dataChangeCallbacks[uid] = { callback: callback, types: types, _this:_this };
  3762. var self = this;
  3763. var deregisterFunction = function() {
  3764. delete self.dataChangeCallbacks[uid];
  3765. };
  3766. return deregisterFunction;
  3767. };
  3768. /**
  3769. * @ngdoc function
  3770. * @name callDataChangeCallbacks
  3771. * @methodOf ui.grid.class:Grid
  3772. * @description Calls the callbacks based on the type of data change that
  3773. * has occurred. Always calls the ALL callbacks, calls the ROW, EDIT, COLUMN and OPTIONS callbacks if the
  3774. * event type is matching, or if the type is ALL.
  3775. * @param {string} type the type of event that occurred - one of the
  3776. * {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange}
  3777. * values (ALL, ROW, EDIT, COLUMN, OPTIONS)
  3778. */
  3779. Grid.prototype.callDataChangeCallbacks = function callDataChangeCallbacks(type, options) {
  3780. angular.forEach( this.dataChangeCallbacks, function( callback, uid ){
  3781. if ( callback.types.indexOf( uiGridConstants.dataChange.ALL ) !== -1 ||
  3782. callback.types.indexOf( type ) !== -1 ||
  3783. type === uiGridConstants.dataChange.ALL ) {
  3784. if (callback._this) {
  3785. callback.callback.apply(callback._this, this, options);
  3786. }
  3787. else {
  3788. callback.callback(this, options);
  3789. }
  3790. }
  3791. }, this);
  3792. };
  3793. /**
  3794. * @ngdoc function
  3795. * @name notifyDataChange
  3796. * @methodOf ui.grid.class:Grid
  3797. * @description Notifies us that a data change has occurred, used in the public
  3798. * api for users to tell us when they've changed data or some other event that
  3799. * our watches cannot pick up
  3800. * @param {string} type the type of event that occurred - one of the
  3801. * uiGridConstants.dataChange values (ALL, ROW, EDIT, COLUMN, OPTIONS)
  3802. *
  3803. * - ALL: listeners fired on any of these events, fires listeners on all events.
  3804. * - ROW: fired when a row is added or removed.
  3805. * - EDIT: fired when the data in a cell is edited.
  3806. * - COLUMN: fired when the column definitions are modified.
  3807. * - OPTIONS: fired when the grid options are modified.
  3808. */
  3809. Grid.prototype.notifyDataChange = function notifyDataChange(type) {
  3810. var constants = uiGridConstants.dataChange;
  3811. if ( type === constants.ALL ||
  3812. type === constants.COLUMN ||
  3813. type === constants.EDIT ||
  3814. type === constants.ROW ||
  3815. type === constants.OPTIONS ){
  3816. this.callDataChangeCallbacks( type );
  3817. } else {
  3818. gridUtil.logError("Notified of a data change, but the type was not recognised, so no action taken, type was: " + type);
  3819. }
  3820. };
  3821. /**
  3822. * @ngdoc function
  3823. * @name columnRefreshCallback
  3824. * @methodOf ui.grid.class:Grid
  3825. * @description refreshes the grid when a column refresh
  3826. * is notified, which triggers handling of the visible flag.
  3827. * This is called on uiGridConstants.dataChange.COLUMN, and is
  3828. * registered as a dataChangeCallback in grid.js
  3829. * @param {object} grid The grid object.
  3830. * @param {object} options Any options passed into the callback.
  3831. */
  3832. Grid.prototype.columnRefreshCallback = function columnRefreshCallback(grid, options){
  3833. grid.buildColumns(options);
  3834. grid.queueGridRefresh();
  3835. };
  3836. /**
  3837. * @ngdoc function
  3838. * @name processRowsCallback
  3839. * @methodOf ui.grid.class:Grid
  3840. * @description calls the row processors, specifically
  3841. * intended to reset the sorting when an edit is called,
  3842. * registered as a dataChangeCallback on uiGridConstants.dataChange.EDIT
  3843. * @param {string} name column name
  3844. */
  3845. Grid.prototype.processRowsCallback = function processRowsCallback( grid ){
  3846. grid.queueGridRefresh();
  3847. };
  3848. /**
  3849. * @ngdoc function
  3850. * @name updateFooterHeightCallback
  3851. * @methodOf ui.grid.class:Grid
  3852. * @description recalculates the footer height,
  3853. * registered as a dataChangeCallback on uiGridConstants.dataChange.OPTIONS
  3854. * @param {string} name column name
  3855. */
  3856. Grid.prototype.updateFooterHeightCallback = function updateFooterHeightCallback( grid ){
  3857. grid.footerHeight = grid.calcFooterHeight();
  3858. grid.columnFooterHeight = grid.calcColumnFooterHeight();
  3859. };
  3860. /**
  3861. * @ngdoc function
  3862. * @name getColumn
  3863. * @methodOf ui.grid.class:Grid
  3864. * @description returns a grid column for the column name
  3865. * @param {string} name column name
  3866. */
  3867. Grid.prototype.getColumn = function getColumn(name) {
  3868. var columns = this.columns.filter(function (column) {
  3869. return column.colDef.name === name;
  3870. });
  3871. return columns.length > 0 ? columns[0] : null;
  3872. };
  3873. /**
  3874. * @ngdoc function
  3875. * @name getColDef
  3876. * @methodOf ui.grid.class:Grid
  3877. * @description returns a grid colDef for the column name
  3878. * @param {string} name column.field
  3879. */
  3880. Grid.prototype.getColDef = function getColDef(name) {
  3881. var colDefs = this.options.columnDefs.filter(function (colDef) {
  3882. return colDef.name === name;
  3883. });
  3884. return colDefs.length > 0 ? colDefs[0] : null;
  3885. };
  3886. /**
  3887. * @ngdoc function
  3888. * @name assignTypes
  3889. * @methodOf ui.grid.class:Grid
  3890. * @description uses the first row of data to assign colDef.type for any types not defined.
  3891. */
  3892. /**
  3893. * @ngdoc property
  3894. * @name type
  3895. * @propertyOf ui.grid.class:GridOptions.columnDef
  3896. * @description the type of the column, used in sorting. If not provided then the
  3897. * grid will guess the type. Add this only if the grid guessing is not to your
  3898. * satisfaction. One of:
  3899. * - 'string'
  3900. * - 'boolean'
  3901. * - 'number'
  3902. * - 'date'
  3903. * - 'object'
  3904. * - 'numberStr'
  3905. * Note that if you choose date, your dates should be in a javascript date type
  3906. *
  3907. */
  3908. Grid.prototype.assignTypes = function(){
  3909. var self = this;
  3910. self.options.columnDefs.forEach(function (colDef, index) {
  3911. //Assign colDef type if not specified
  3912. if (!colDef.type) {
  3913. var col = new GridColumn(colDef, index, self);
  3914. var firstRow = self.rows.length > 0 ? self.rows[0] : null;
  3915. if (firstRow) {
  3916. colDef.type = gridUtil.guessType(self.getCellValue(firstRow, col));
  3917. }
  3918. else {
  3919. colDef.type = 'string';
  3920. }
  3921. }
  3922. });
  3923. };
  3924. /**
  3925. * @ngdoc function
  3926. * @name isRowHeaderColumn
  3927. * @methodOf ui.grid.class:Grid
  3928. * @description returns true if the column is a row Header
  3929. * @param {object} column column
  3930. */
  3931. Grid.prototype.isRowHeaderColumn = function isRowHeaderColumn(column) {
  3932. return this.rowHeaderColumns.indexOf(column) !== -1;
  3933. };
  3934. /**
  3935. * @ngdoc function
  3936. * @name addRowHeaderColumn
  3937. * @methodOf ui.grid.class:Grid
  3938. * @description adds a row header column to the grid
  3939. * @param {object} colDef Column definition object.
  3940. * @param {float} order Number that indicates where the column should be placed in the grid.
  3941. * @param {boolean} stopColumnBuild Prevents the buildColumn callback from being triggered. This is useful to improve
  3942. * performance of the grid during initial load.
  3943. */
  3944. Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef, order, stopColumnBuild) {
  3945. var self = this;
  3946. //default order
  3947. if (order === undefined) {
  3948. order = 0;
  3949. }
  3950. var rowHeaderCol = new GridColumn(colDef, gridUtil.nextUid(), self);
  3951. rowHeaderCol.isRowHeader = true;
  3952. if (self.isRTL()) {
  3953. self.createRightContainer();
  3954. rowHeaderCol.renderContainer = 'right';
  3955. }
  3956. else {
  3957. self.createLeftContainer();
  3958. rowHeaderCol.renderContainer = 'left';
  3959. }
  3960. // relies on the default column builder being first in array, as it is instantiated
  3961. // as part of grid creation
  3962. self.columnBuilders[0](colDef,rowHeaderCol,self.options)
  3963. .then(function(){
  3964. rowHeaderCol.enableFiltering = false;
  3965. rowHeaderCol.enableSorting = false;
  3966. rowHeaderCol.enableHiding = false;
  3967. rowHeaderCol.headerPriority = order;
  3968. self.rowHeaderColumns.push(rowHeaderCol);
  3969. self.rowHeaderColumns = self.rowHeaderColumns.sort(function (a, b) {
  3970. return a.headerPriority - b.headerPriority;
  3971. });
  3972. if (!stopColumnBuild) {
  3973. self.buildColumns()
  3974. .then(function() {
  3975. self.preCompileCellTemplates();
  3976. self.queueGridRefresh();
  3977. }).catch(angular.noop);
  3978. }
  3979. }).catch(angular.noop);
  3980. };
  3981. /**
  3982. * @ngdoc function
  3983. * @name getOnlyDataColumns
  3984. * @methodOf ui.grid.class:Grid
  3985. * @description returns all columns except for rowHeader columns
  3986. */
  3987. Grid.prototype.getOnlyDataColumns = function getOnlyDataColumns() {
  3988. var self = this;
  3989. var cols = [];
  3990. self.columns.forEach(function (col) {
  3991. if (self.rowHeaderColumns.indexOf(col) === -1) {
  3992. cols.push(col);
  3993. }
  3994. });
  3995. return cols;
  3996. };
  3997. /**
  3998. * @ngdoc function
  3999. * @name buildColumns
  4000. * @methodOf ui.grid.class:Grid
  4001. * @description creates GridColumn objects from the columnDefinition. Calls each registered
  4002. * columnBuilder to further process the column
  4003. * @param {object} options An object contains options to use when building columns
  4004. *
  4005. * * **orderByColumnDefs**: defaults to **false**. When true, `buildColumns` will reorder existing columns according to the order within the column definitions.
  4006. *
  4007. * @returns {Promise} a promise to load any needed column resources
  4008. */
  4009. Grid.prototype.buildColumns = function buildColumns(opts) {
  4010. var options = {
  4011. orderByColumnDefs: false
  4012. };
  4013. angular.extend(options, opts);
  4014. // gridUtil.logDebug('buildColumns');
  4015. var self = this;
  4016. var builderPromises = [];
  4017. var headerOffset = self.rowHeaderColumns.length;
  4018. var i;
  4019. // Remove any columns for which a columnDef cannot be found
  4020. // Deliberately don't use forEach, as it doesn't like splice being called in the middle
  4021. // Also don't cache columns.length, as it will change during this operation
  4022. for (i = 0; i < self.columns.length; i++){
  4023. if (!self.getColDef(self.columns[i].name)) {
  4024. self.columns.splice(i, 1);
  4025. i--;
  4026. }
  4027. }
  4028. //add row header columns to the grid columns array _after_ columns without columnDefs have been removed
  4029. //rowHeaderColumns is ordered by priority so insert in reverse
  4030. for (var j = self.rowHeaderColumns.length - 1; j >= 0; j--) {
  4031. self.columns.unshift(self.rowHeaderColumns[j]);
  4032. }
  4033. // look at each column def, and update column properties to match. If the column def
  4034. // doesn't have a column, then splice in a new gridCol
  4035. self.options.columnDefs.forEach(function (colDef, index) {
  4036. self.preprocessColDef(colDef);
  4037. var col = self.getColumn(colDef.name);
  4038. if (!col) {
  4039. col = new GridColumn(colDef, gridUtil.nextUid(), self);
  4040. self.columns.splice(index + headerOffset, 0, col);
  4041. }
  4042. else {
  4043. // tell updateColumnDef that the column was pre-existing
  4044. col.updateColumnDef(colDef, false);
  4045. }
  4046. self.columnBuilders.forEach(function (builder) {
  4047. builderPromises.push(builder.call(self, colDef, col, self.options));
  4048. });
  4049. });
  4050. /*** Reorder columns if necessary ***/
  4051. if (!!options.orderByColumnDefs) {
  4052. // Create a shallow copy of the columns as a cache
  4053. var columnCache = self.columns.slice(0);
  4054. // We need to allow for the "row headers" when mapping from the column defs array to the columns array
  4055. // 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]
  4056. // 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
  4057. // columns will be shorter than columnDefs. In this situation we'll avoid an error, but the user will still get an unexpected result
  4058. var len = Math.min(self.options.columnDefs.length, self.columns.length);
  4059. for (i = 0; i < len; i++) {
  4060. // If the column at this index has a different name than the column at the same index in the column defs...
  4061. if (self.columns[i + headerOffset].name !== self.options.columnDefs[i].name) {
  4062. // Replace the one in the cache with the appropriate column
  4063. columnCache[i + headerOffset] = self.getColumn(self.options.columnDefs[i].name);
  4064. }
  4065. else {
  4066. // Otherwise just copy over the one from the initial columns
  4067. columnCache[i + headerOffset] = self.columns[i + headerOffset];
  4068. }
  4069. }
  4070. // Empty out the columns array, non-destructively
  4071. self.columns.length = 0;
  4072. // And splice in the updated, ordered columns from the cache
  4073. Array.prototype.splice.apply(self.columns, [0, 0].concat(columnCache));
  4074. }
  4075. return $q.all(builderPromises).then(function(){
  4076. if (self.rows.length > 0){
  4077. self.assignTypes();
  4078. }
  4079. if (options.preCompileCellTemplates) {
  4080. self.preCompileCellTemplates();
  4081. }
  4082. }).catch(angular.noop);
  4083. };
  4084. Grid.prototype.preCompileCellTemplate = function(col) {
  4085. var self = this;
  4086. var html = col.cellTemplate.replace(uiGridConstants.MODEL_COL_FIELD, self.getQualifiedColField(col));
  4087. html = html.replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)');
  4088. col.compiledElementFn = $compile(html);
  4089. if (col.compiledElementFnDefer) {
  4090. col.compiledElementFnDefer.resolve(col.compiledElementFn);
  4091. }
  4092. };
  4093. /**
  4094. * @ngdoc function
  4095. * @name preCompileCellTemplates
  4096. * @methodOf ui.grid.class:Grid
  4097. * @description precompiles all cell templates
  4098. */
  4099. Grid.prototype.preCompileCellTemplates = function() {
  4100. var self = this;
  4101. self.columns.forEach(function (col) {
  4102. if ( col.cellTemplate ){
  4103. self.preCompileCellTemplate( col );
  4104. } else if ( col.cellTemplatePromise ){
  4105. col.cellTemplatePromise.then( function() {
  4106. self.preCompileCellTemplate( col );
  4107. }).catch(angular.noop);
  4108. }
  4109. });
  4110. };
  4111. /**
  4112. * @ngdoc function
  4113. * @name getGridQualifiedColField
  4114. * @methodOf ui.grid.class:Grid
  4115. * @description Returns the $parse-able accessor for a column within its $scope
  4116. * @param {GridColumn} col col object
  4117. */
  4118. Grid.prototype.getQualifiedColField = function (col) {
  4119. var base = 'row.entity';
  4120. if ( col.field === uiGridConstants.ENTITY_BINDING ) {
  4121. return base;
  4122. }
  4123. return gridUtil.preEval(base + '.' + col.field);
  4124. };
  4125. /**
  4126. * @ngdoc function
  4127. * @name createLeftContainer
  4128. * @methodOf ui.grid.class:Grid
  4129. * @description creates the left render container if it doesn't already exist
  4130. */
  4131. Grid.prototype.createLeftContainer = function() {
  4132. if (!this.hasLeftContainer()) {
  4133. this.renderContainers.left = new GridRenderContainer('left', this, { disableColumnOffset: true });
  4134. }
  4135. };
  4136. /**
  4137. * @ngdoc function
  4138. * @name createRightContainer
  4139. * @methodOf ui.grid.class:Grid
  4140. * @description creates the right render container if it doesn't already exist
  4141. */
  4142. Grid.prototype.createRightContainer = function() {
  4143. if (!this.hasRightContainer()) {
  4144. this.renderContainers.right = new GridRenderContainer('right', this, { disableColumnOffset: true });
  4145. }
  4146. };
  4147. /**
  4148. * @ngdoc function
  4149. * @name hasLeftContainer
  4150. * @methodOf ui.grid.class:Grid
  4151. * @description returns true if leftContainer exists
  4152. */
  4153. Grid.prototype.hasLeftContainer = function() {
  4154. return this.renderContainers.left !== undefined;
  4155. };
  4156. /**
  4157. * @ngdoc function
  4158. * @name hasRightContainer
  4159. * @methodOf ui.grid.class:Grid
  4160. * @description returns true if rightContainer exists
  4161. */
  4162. Grid.prototype.hasRightContainer = function() {
  4163. return this.renderContainers.right !== undefined;
  4164. };
  4165. /**
  4166. * undocumented function
  4167. * @name preprocessColDef
  4168. * @methodOf ui.grid.class:Grid
  4169. * @description defaults the name property from field to maintain backwards compatibility with 2.x
  4170. * validates that name or field is present
  4171. */
  4172. Grid.prototype.preprocessColDef = function preprocessColDef(colDef) {
  4173. var self = this;
  4174. if (!colDef.field && !colDef.name) {
  4175. throw new Error('colDef.name or colDef.field property is required');
  4176. }
  4177. //maintain backwards compatibility with 2.x
  4178. //field was required in 2.x. now name is required
  4179. if (colDef.name === undefined && colDef.field !== undefined) {
  4180. // See if the column name already exists:
  4181. var newName = colDef.field,
  4182. counter = 2;
  4183. while (self.getColumn(newName)) {
  4184. newName = colDef.field + counter.toString();
  4185. counter++;
  4186. }
  4187. colDef.name = newName;
  4188. }
  4189. };
  4190. // 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
  4191. Grid.prototype.newInN = function newInN(o, n, oAccessor, nAccessor) {
  4192. var self = this;
  4193. var t = [];
  4194. for (var i = 0; i < n.length; i++) {
  4195. var nV = nAccessor ? n[i][nAccessor] : n[i];
  4196. var found = false;
  4197. for (var j = 0; j < o.length; j++) {
  4198. var oV = oAccessor ? o[j][oAccessor] : o[j];
  4199. if (self.options.rowEquality(nV, oV)) {
  4200. found = true;
  4201. break;
  4202. }
  4203. }
  4204. if (!found) {
  4205. t.push(nV);
  4206. }
  4207. }
  4208. return t;
  4209. };
  4210. /**
  4211. * @ngdoc function
  4212. * @name getRow
  4213. * @methodOf ui.grid.class:Grid
  4214. * @description returns the GridRow that contains the rowEntity
  4215. * @param {object} rowEntity the gridOptions.data array element instance
  4216. * @param {array} lookInRows [optional] the rows to look in - if not provided then
  4217. * looks in grid.rows
  4218. */
  4219. Grid.prototype.getRow = function getRow(rowEntity, lookInRows) {
  4220. var self = this;
  4221. lookInRows = typeof(lookInRows) === 'undefined' ? self.rows : lookInRows;
  4222. var rows = lookInRows.filter(function (row) {
  4223. return self.options.rowEquality(row.entity, rowEntity);
  4224. });
  4225. return rows.length > 0 ? rows[0] : null;
  4226. };
  4227. /**
  4228. * @ngdoc function
  4229. * @name modifyRows
  4230. * @methodOf ui.grid.class:Grid
  4231. * @description creates or removes GridRow objects from the newRawData array. Calls each registered
  4232. * rowBuilder to further process the row
  4233. * @param {array} newRawData Modified set of data
  4234. *
  4235. * This method aims to achieve three things:
  4236. * 1. the resulting rows array is in the same order as the newRawData, we'll call
  4237. * rowsProcessors immediately after to sort the data anyway
  4238. * 2. if we have row hashing available, we try to use the rowHash to find the row
  4239. * 3. no memory leaks - rows that are no longer in newRawData need to be garbage collected
  4240. *
  4241. * The basic logic flow makes use of the newRawData, oldRows and oldHash, and creates
  4242. * the newRows and newHash
  4243. *
  4244. * ```
  4245. * newRawData.forEach newEntity
  4246. * if (hashing enabled)
  4247. * check oldHash for newEntity
  4248. * else
  4249. * look for old row directly in oldRows
  4250. * if !oldRowFound // must be a new row
  4251. * create newRow
  4252. * append to the newRows and add to newHash
  4253. * run the processors
  4254. * ```
  4255. *
  4256. * Rows are identified using the hashKey if configured. If not configured, then rows
  4257. * are identified using the gridOptions.rowEquality function
  4258. *
  4259. * This method is useful when trying to select rows immediately after loading data without
  4260. * using a $timeout/$interval, e.g.:
  4261. *
  4262. * $scope.gridOptions.data = someData;
  4263. * $scope.gridApi.grid.modifyRows($scope.gridOptions.data);
  4264. * $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
  4265. *
  4266. * OR to persist row selection after data update (e.g. rows selected, new data loaded, want
  4267. * originally selected rows to be re-selected))
  4268. */
  4269. Grid.prototype.modifyRows = function modifyRows(newRawData) {
  4270. var self = this;
  4271. var oldRows = self.rows.slice(0);
  4272. var oldRowHash = self.rowHashMap || self.createRowHashMap();
  4273. var allRowsSelected = true;
  4274. self.rowHashMap = self.createRowHashMap();
  4275. self.rows.length = 0;
  4276. newRawData.forEach( function( newEntity, i ) {
  4277. var newRow, oldRow;
  4278. if ( self.options.enableRowHashing ){
  4279. // if hashing is enabled, then this row will be in the hash if we already know about it
  4280. oldRow = oldRowHash.get( newEntity );
  4281. } else {
  4282. // otherwise, manually search the oldRows to see if we can find this row
  4283. oldRow = self.getRow(newEntity, oldRows);
  4284. }
  4285. // update newRow to have an entity
  4286. if ( oldRow ) {
  4287. newRow = oldRow;
  4288. newRow.entity = newEntity;
  4289. }
  4290. // if we didn't find the row, it must be new, so create it
  4291. if ( !newRow ){
  4292. newRow = self.processRowBuilders(new GridRow(newEntity, i, self));
  4293. }
  4294. self.rows.push( newRow );
  4295. self.rowHashMap.put( newEntity, newRow );
  4296. if (!newRow.isSelected) {
  4297. allRowsSelected = false;
  4298. }
  4299. });
  4300. if (self.selection && self.rows.length) {
  4301. self.selection.selectAll = allRowsSelected;
  4302. }
  4303. self.assignTypes();
  4304. var p1 = $q.when(self.processRowsProcessors(self.rows))
  4305. .then(function (renderableRows) {
  4306. return self.setVisibleRows(renderableRows);
  4307. }).catch(angular.noop);
  4308. var p2 = $q.when(self.processColumnsProcessors(self.columns))
  4309. .then(function (renderableColumns) {
  4310. return self.setVisibleColumns(renderableColumns);
  4311. }).catch(angular.noop);
  4312. return $q.all([p1, p2]);
  4313. };
  4314. /**
  4315. * Private Undocumented Method
  4316. * @name addRows
  4317. * @methodOf ui.grid.class:Grid
  4318. * @description adds the newRawData array of rows to the grid and calls all registered
  4319. * rowBuilders. this keyword will reference the grid
  4320. */
  4321. Grid.prototype.addRows = function addRows(newRawData) {
  4322. var self = this;
  4323. var existingRowCount = self.rows.length;
  4324. for (var i = 0; i < newRawData.length; i++) {
  4325. var newRow = self.processRowBuilders(new GridRow(newRawData[i], i + existingRowCount, self));
  4326. if (self.options.enableRowHashing) {
  4327. var found = self.rowHashMap.get(newRow.entity);
  4328. if (found) {
  4329. found.row = newRow;
  4330. }
  4331. }
  4332. self.rows.push(newRow);
  4333. }
  4334. };
  4335. /**
  4336. * @ngdoc function
  4337. * @name processRowBuilders
  4338. * @methodOf ui.grid.class:Grid
  4339. * @description processes all RowBuilders for the gridRow
  4340. * @param {GridRow} gridRow reference to gridRow
  4341. * @returns {GridRow} the gridRow with all additional behavior added
  4342. */
  4343. Grid.prototype.processRowBuilders = function processRowBuilders(gridRow) {
  4344. var self = this;
  4345. self.rowBuilders.forEach(function (builder) {
  4346. builder.call(self, gridRow, self.options);
  4347. });
  4348. return gridRow;
  4349. };
  4350. /**
  4351. * @ngdoc function
  4352. * @name registerStyleComputation
  4353. * @methodOf ui.grid.class:Grid
  4354. * @description registered a styleComputation function
  4355. *
  4356. * If the function returns a value it will be appended into the grid's `<style>` block
  4357. * @param {function($scope)} styleComputationInfo function
  4358. */
  4359. Grid.prototype.registerStyleComputation = function registerStyleComputation(styleComputationInfo) {
  4360. this.styleComputations.push(styleComputationInfo);
  4361. };
  4362. // NOTE (c0bra): We already have rowBuilders. I think these do exactly the same thing...
  4363. // Grid.prototype.registerRowFilter = function(filter) {
  4364. // // TODO(c0bra): validate filter?
  4365. // this.rowFilters.push(filter);
  4366. // };
  4367. // Grid.prototype.removeRowFilter = function(filter) {
  4368. // var idx = this.rowFilters.indexOf(filter);
  4369. // if (typeof(idx) !== 'undefined' && idx !== undefined) {
  4370. // this.rowFilters.slice(idx, 1);
  4371. // }
  4372. // };
  4373. // Grid.prototype.processRowFilters = function(rows) {
  4374. // var self = this;
  4375. // self.rowFilters.forEach(function (filter) {
  4376. // filter.call(self, rows);
  4377. // });
  4378. // };
  4379. /**
  4380. * @ngdoc function
  4381. * @name registerRowsProcessor
  4382. * @methodOf ui.grid.class:Grid
  4383. * @description
  4384. *
  4385. * Register a "rows processor" function. When the rows are updated,
  4386. * the grid calls each registered "rows processor", which has a chance
  4387. * to alter the set of rows (sorting, etc) as long as the count is not
  4388. * modified.
  4389. *
  4390. * @param {function(renderedRowsToProcess, columns )} processor rows processor function, which
  4391. * is run in the context of the grid (i.e. this for the function will be the grid), and must
  4392. * return the updated rows list, which is passed to the next processor in the chain
  4393. * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room
  4394. * for other people to inject rows processors at intermediate priorities. Lower priority rowsProcessors run earlier.
  4395. *
  4396. * 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)
  4397. *
  4398. */
  4399. Grid.prototype.registerRowsProcessor = function registerRowsProcessor(processor, priority) {
  4400. if (!angular.isFunction(processor)) {
  4401. throw 'Attempt to register non-function rows processor: ' + processor;
  4402. }
  4403. this.rowsProcessors.push({processor: processor, priority: priority});
  4404. this.rowsProcessors.sort(function sortByPriority( a, b ){
  4405. return a.priority - b.priority;
  4406. });
  4407. };
  4408. /**
  4409. * @ngdoc function
  4410. * @name removeRowsProcessor
  4411. * @methodOf ui.grid.class:Grid
  4412. * @param {function(renderableRows)} processor processor function
  4413. * @description Remove a registered rows processor
  4414. */
  4415. Grid.prototype.removeRowsProcessor = function removeRowsProcessor(processor) {
  4416. var idx = -1;
  4417. this.rowsProcessors.forEach(function(rowsProcessor, index){
  4418. if ( rowsProcessor.processor === processor ){
  4419. idx = index;
  4420. }
  4421. });
  4422. if ( idx !== -1 ) {
  4423. this.rowsProcessors.splice(idx, 1);
  4424. }
  4425. };
  4426. /**
  4427. * Private Undocumented Method
  4428. * @name processRowsProcessors
  4429. * @methodOf ui.grid.class:Grid
  4430. * @param {Array[GridRow]} renderableRows The array of "renderable" rows
  4431. * @description Run all the registered rows processors on the array of renderable rows
  4432. */
  4433. Grid.prototype.processRowsProcessors = function processRowsProcessors(renderableRows) {
  4434. var self = this;
  4435. // Create a shallow copy of the rows so that we can safely sort them without altering the original grid.rows sort order
  4436. var myRenderableRows = renderableRows.slice(0);
  4437. // Return myRenderableRows with no processing if we have no rows processors
  4438. if (self.rowsProcessors.length === 0) {
  4439. return $q.when(myRenderableRows);
  4440. }
  4441. // Counter for iterating through rows processors
  4442. var i = 0;
  4443. // Promise for when we're done with all the processors
  4444. var finished = $q.defer();
  4445. // This function will call the processor in self.rowsProcessors at index 'i', and then
  4446. // when done will call the next processor in the list, using the output from the processor
  4447. // at i as the argument for 'renderedRowsToProcess' on the next iteration.
  4448. //
  4449. // If we're at the end of the list of processors, we resolve our 'finished' callback with
  4450. // the result.
  4451. function startProcessor(i, renderedRowsToProcess) {
  4452. // Get the processor at 'i'
  4453. var processor = self.rowsProcessors[i].processor;
  4454. // Call the processor, passing in the rows to process and the current columns
  4455. // (note: it's wrapped in $q.when() in case the processor does not return a promise)
  4456. return $q.when( processor.call(self, renderedRowsToProcess, self.columns) )
  4457. .then(function handleProcessedRows(processedRows) {
  4458. // Check for errors
  4459. if (!processedRows) {
  4460. throw "Processor at index " + i + " did not return a set of renderable rows";
  4461. }
  4462. if (!angular.isArray(processedRows)) {
  4463. throw "Processor at index " + i + " did not return an array";
  4464. }
  4465. // Processor is done, increment the counter
  4466. i++;
  4467. // If we're not done with the processors, call the next one
  4468. if (i <= self.rowsProcessors.length - 1) {
  4469. return startProcessor(i, processedRows);
  4470. }
  4471. // We're done! Resolve the 'finished' promise
  4472. else {
  4473. finished.resolve(processedRows);
  4474. }
  4475. }).catch(function(error) {
  4476. throw error;
  4477. });
  4478. }
  4479. // Start on the first processor
  4480. startProcessor(0, myRenderableRows);
  4481. return finished.promise;
  4482. };
  4483. Grid.prototype.setVisibleRows = function setVisibleRows(rows) {
  4484. var self = this;
  4485. // Reset all the render container row caches
  4486. for (var i in self.renderContainers) {
  4487. var container = self.renderContainers[i];
  4488. container.canvasHeightShouldUpdate = true;
  4489. if ( typeof(container.visibleRowCache) === 'undefined' ){
  4490. container.visibleRowCache = [];
  4491. } else {
  4492. container.visibleRowCache.length = 0;
  4493. }
  4494. }
  4495. // rows.forEach(function (row) {
  4496. for (var ri = 0; ri < rows.length; ri++) {
  4497. var row = rows[ri];
  4498. var targetContainer = (typeof(row.renderContainer) !== 'undefined' && row.renderContainer) ? row.renderContainer : 'body';
  4499. // If the row is visible
  4500. if (row.visible) {
  4501. self.renderContainers[targetContainer].visibleRowCache.push(row);
  4502. }
  4503. }
  4504. self.api.core.raise.rowsVisibleChanged(this.api);
  4505. self.api.core.raise.rowsRendered(this.api);
  4506. };
  4507. /**
  4508. * @ngdoc function
  4509. * @name registerColumnsProcessor
  4510. * @methodOf ui.grid.class:Grid
  4511. * @param {function(renderedColumnsToProcess, rows)} processor column processor function, which
  4512. * is run in the context of the grid (i.e. this for the function will be the grid), and
  4513. * which must return an updated renderedColumnsToProcess which can be passed to the next processor
  4514. * in the chain
  4515. * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room
  4516. * for other people to inject columns processors at intermediate priorities. Lower priority columnsProcessors run earlier.
  4517. *
  4518. * 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)
  4519. * @description
  4520. Register a "columns processor" function. When the columns are updated,
  4521. the grid calls each registered "columns processor", which has a chance
  4522. to alter the set of columns, as long as the count is not modified.
  4523. */
  4524. Grid.prototype.registerColumnsProcessor = function registerColumnsProcessor(processor, priority) {
  4525. if (!angular.isFunction(processor)) {
  4526. throw 'Attempt to register non-function rows processor: ' + processor;
  4527. }
  4528. this.columnsProcessors.push({processor: processor, priority: priority});
  4529. this.columnsProcessors.sort(function sortByPriority( a, b ){
  4530. return a.priority - b.priority;
  4531. });
  4532. };
  4533. Grid.prototype.removeColumnsProcessor = function removeColumnsProcessor(processor) {
  4534. var idx = this.columnsProcessors.indexOf(processor);
  4535. if (typeof(idx) !== 'undefined' && idx !== undefined) {
  4536. this.columnsProcessors.splice(idx, 1);
  4537. }
  4538. };
  4539. Grid.prototype.processColumnsProcessors = function processColumnsProcessors(renderableColumns) {
  4540. var self = this;
  4541. // Create a shallow copy of the rows so that we can safely sort them without altering the original grid.rows sort order
  4542. var myRenderableColumns = renderableColumns.slice(0);
  4543. // Return myRenderableRows with no processing if we have no rows processors
  4544. if (self.columnsProcessors.length === 0) {
  4545. return $q.when(myRenderableColumns);
  4546. }
  4547. // Counter for iterating through rows processors
  4548. var i = 0;
  4549. // Promise for when we're done with all the processors
  4550. var finished = $q.defer();
  4551. // This function will call the processor in self.rowsProcessors at index 'i', and then
  4552. // when done will call the next processor in the list, using the output from the processor
  4553. // at i as the argument for 'renderedRowsToProcess' on the next iteration.
  4554. //
  4555. // If we're at the end of the list of processors, we resolve our 'finished' callback with
  4556. // the result.
  4557. function startProcessor(i, renderedColumnsToProcess) {
  4558. // Get the processor at 'i'
  4559. var processor = self.columnsProcessors[i].processor;
  4560. // Call the processor, passing in the rows to process and the current columns
  4561. // (note: it's wrapped in $q.when() in case the processor does not return a promise)
  4562. return $q.when( processor.call(self, renderedColumnsToProcess, self.rows) )
  4563. .then(function handleProcessedRows(processedColumns) {
  4564. // Check for errors
  4565. if (!processedColumns) {
  4566. throw "Processor at index " + i + " did not return a set of renderable rows";
  4567. }
  4568. if (!angular.isArray(processedColumns)) {
  4569. throw "Processor at index " + i + " did not return an array";
  4570. }
  4571. // Processor is done, increment the counter
  4572. i++;
  4573. // If we're not done with the processors, call the next one
  4574. if (i <= self.columnsProcessors.length - 1) {
  4575. return startProcessor(i, myRenderableColumns);
  4576. }
  4577. // We're done! Resolve the 'finished' promise
  4578. else {
  4579. finished.resolve(myRenderableColumns);
  4580. }
  4581. }).catch(angular.noop);
  4582. }
  4583. // Start on the first processor
  4584. startProcessor(0, myRenderableColumns);
  4585. return finished.promise;
  4586. };
  4587. Grid.prototype.setVisibleColumns = function setVisibleColumns(columns) {
  4588. // gridUtil.logDebug('setVisibleColumns');
  4589. var self = this;
  4590. // Reset all the render container row caches
  4591. for (var i in self.renderContainers) {
  4592. var container = self.renderContainers[i];
  4593. container.visibleColumnCache.length = 0;
  4594. }
  4595. for (var ci = 0; ci < columns.length; ci++) {
  4596. var column = columns[ci];
  4597. // If the column is visible
  4598. if (column.visible) {
  4599. // If the column has a container specified
  4600. if (typeof(column.renderContainer) !== 'undefined' && column.renderContainer) {
  4601. self.renderContainers[column.renderContainer].visibleColumnCache.push(column);
  4602. }
  4603. // If not, put it into the body container
  4604. else {
  4605. self.renderContainers.body.visibleColumnCache.push(column);
  4606. }
  4607. }
  4608. }
  4609. };
  4610. /**
  4611. * @ngdoc function
  4612. * @name handleWindowResize
  4613. * @methodOf ui.grid.class:Grid
  4614. * @description Triggered when the browser window resizes; automatically resizes the grid
  4615. * @returns {Promise} A resolved promise once the window resize has completed.
  4616. */
  4617. Grid.prototype.handleWindowResize = function handleWindowResize($event) {
  4618. var self = this;
  4619. self.gridWidth = gridUtil.elementWidth(self.element);
  4620. self.gridHeight = gridUtil.elementHeight(self.element);
  4621. return self.queueRefresh();
  4622. };
  4623. /**
  4624. * @ngdoc function
  4625. * @name queueRefresh
  4626. * @methodOf ui.grid.class:Grid
  4627. * @description queues a grid refreshCanvas, a way of debouncing all the refreshes we might otherwise issue
  4628. */
  4629. Grid.prototype.queueRefresh = function queueRefresh() {
  4630. var self = this;
  4631. if (self.refreshCanceller) {
  4632. $timeout.cancel(self.refreshCanceller);
  4633. }
  4634. self.refreshCanceller = $timeout(function () {
  4635. self.refreshCanvas(true);
  4636. });
  4637. self.refreshCanceller.then(function () {
  4638. self.refreshCanceller = null;
  4639. }).catch(angular.noop);
  4640. return self.refreshCanceller;
  4641. };
  4642. /**
  4643. * @ngdoc function
  4644. * @name queueGridRefresh
  4645. * @methodOf ui.grid.class:Grid
  4646. * @description queues a grid refresh, a way of debouncing all the refreshes we might otherwise issue
  4647. */
  4648. Grid.prototype.queueGridRefresh = function queueGridRefresh() {
  4649. var self = this;
  4650. if (self.gridRefreshCanceller) {
  4651. $timeout.cancel(self.gridRefreshCanceller);
  4652. }
  4653. self.gridRefreshCanceller = $timeout(function () {
  4654. self.refresh(true);
  4655. });
  4656. self.gridRefreshCanceller.then(function () {
  4657. self.gridRefreshCanceller = null;
  4658. }).catch(angular.noop);
  4659. return self.gridRefreshCanceller;
  4660. };
  4661. /**
  4662. * @ngdoc function
  4663. * @name updateCanvasHeight
  4664. * @methodOf ui.grid.class:Grid
  4665. * @description flags all render containers to update their canvas height
  4666. */
  4667. Grid.prototype.updateCanvasHeight = function updateCanvasHeight() {
  4668. var self = this;
  4669. for (var containerId in self.renderContainers) {
  4670. if (self.renderContainers.hasOwnProperty(containerId)) {
  4671. var container = self.renderContainers[containerId];
  4672. container.canvasHeightShouldUpdate = true;
  4673. }
  4674. }
  4675. };
  4676. /**
  4677. * @ngdoc function
  4678. * @name buildStyles
  4679. * @methodOf ui.grid.class:Grid
  4680. * @description calls each styleComputation function
  4681. */
  4682. Grid.prototype.buildStyles = function buildStyles() {
  4683. var self = this;
  4684. // gridUtil.logDebug('buildStyles');
  4685. self.customStyles = '';
  4686. self.styleComputations
  4687. .sort(function(a, b) {
  4688. if (a.priority === null) { return 1; }
  4689. if (b.priority === null) { return -1; }
  4690. if (a.priority === null && b.priority === null) { return 0; }
  4691. return a.priority - b.priority;
  4692. })
  4693. .forEach(function (compInfo) {
  4694. // this used to provide $scope as a second parameter, but I couldn't find any
  4695. // style builders that used it, so removed it as part of moving to grid from controller
  4696. var ret = compInfo.func.call(self);
  4697. if (angular.isString(ret)) {
  4698. self.customStyles += '\n' + ret;
  4699. }
  4700. });
  4701. };
  4702. Grid.prototype.minColumnsToRender = function minColumnsToRender() {
  4703. var self = this;
  4704. var viewport = this.getViewportWidth();
  4705. var min = 0;
  4706. var totalWidth = 0;
  4707. self.columns.forEach(function(col, i) {
  4708. if (totalWidth < viewport) {
  4709. totalWidth += col.drawnWidth;
  4710. min++;
  4711. }
  4712. else {
  4713. var currWidth = 0;
  4714. for (var j = i; j >= i - min; j--) {
  4715. currWidth += self.columns[j].drawnWidth;
  4716. }
  4717. if (currWidth < viewport) {
  4718. min++;
  4719. }
  4720. }
  4721. });
  4722. return min;
  4723. };
  4724. Grid.prototype.getBodyHeight = function getBodyHeight() {
  4725. // Start with the viewportHeight
  4726. var bodyHeight = this.getViewportHeight();
  4727. // Add the horizontal scrollbar height if there is one
  4728. //if (typeof(this.horizontalScrollbarHeight) !== 'undefined' && this.horizontalScrollbarHeight !== undefined && this.horizontalScrollbarHeight > 0) {
  4729. // bodyHeight = bodyHeight + this.horizontalScrollbarHeight;
  4730. //}
  4731. return bodyHeight;
  4732. };
  4733. // NOTE: viewport drawable height is the height of the grid minus the header row height (including any border)
  4734. // TODO(c0bra): account for footer height
  4735. Grid.prototype.getViewportHeight = function getViewportHeight() {
  4736. var self = this;
  4737. var viewPortHeight = this.gridHeight - this.headerHeight - this.footerHeight;
  4738. // Account for native horizontal scrollbar, if present
  4739. //if (typeof(this.horizontalScrollbarHeight) !== 'undefined' && this.horizontalScrollbarHeight !== undefined && this.horizontalScrollbarHeight > 0) {
  4740. // viewPortHeight = viewPortHeight - this.horizontalScrollbarHeight;
  4741. //}
  4742. var adjustment = self.getViewportAdjustment();
  4743. viewPortHeight = viewPortHeight + adjustment.height;
  4744. //gridUtil.logDebug('viewPortHeight', viewPortHeight);
  4745. return viewPortHeight;
  4746. };
  4747. Grid.prototype.getViewportWidth = function getViewportWidth() {
  4748. var self = this;
  4749. var viewPortWidth = this.gridWidth;
  4750. //if (typeof(this.verticalScrollbarWidth) !== 'undefined' && this.verticalScrollbarWidth !== undefined && this.verticalScrollbarWidth > 0) {
  4751. // viewPortWidth = viewPortWidth - this.verticalScrollbarWidth;
  4752. //}
  4753. var adjustment = self.getViewportAdjustment();
  4754. viewPortWidth = viewPortWidth + adjustment.width;
  4755. //gridUtil.logDebug('getviewPortWidth', viewPortWidth);
  4756. return viewPortWidth;
  4757. };
  4758. Grid.prototype.getHeaderViewportWidth = function getHeaderViewportWidth() {
  4759. var viewPortWidth = this.getViewportWidth();
  4760. //if (typeof(this.verticalScrollbarWidth) !== 'undefined' && this.verticalScrollbarWidth !== undefined && this.verticalScrollbarWidth > 0) {
  4761. // viewPortWidth = viewPortWidth + this.verticalScrollbarWidth;
  4762. //}
  4763. return viewPortWidth;
  4764. };
  4765. Grid.prototype.addVerticalScrollSync = function (containerId, callBackFn) {
  4766. this.verticalScrollSyncCallBackFns[containerId] = callBackFn;
  4767. };
  4768. Grid.prototype.addHorizontalScrollSync = function (containerId, callBackFn) {
  4769. this.horizontalScrollSyncCallBackFns[containerId] = callBackFn;
  4770. };
  4771. /**
  4772. * Scroll needed containers by calling their ScrollSyncs
  4773. * @param sourceContainerId the containerId that has already set it's top/left.
  4774. * can be empty string which means all containers need to set top/left
  4775. * @param scrollEvent
  4776. */
  4777. Grid.prototype.scrollContainers = function (sourceContainerId, scrollEvent) {
  4778. if (scrollEvent.y) {
  4779. //default for no container Id (ex. mousewheel means that all containers must set scrollTop/Left)
  4780. var verts = ['body','left', 'right'];
  4781. this.flagScrollingVertically(scrollEvent);
  4782. if (sourceContainerId === 'body') {
  4783. verts = ['left', 'right'];
  4784. }
  4785. else if (sourceContainerId === 'left') {
  4786. verts = ['body', 'right'];
  4787. }
  4788. else if (sourceContainerId === 'right') {
  4789. verts = ['body', 'left'];
  4790. }
  4791. for (var i = 0; i < verts.length; i++) {
  4792. var id = verts[i];
  4793. if (this.verticalScrollSyncCallBackFns[id]) {
  4794. this.verticalScrollSyncCallBackFns[id](scrollEvent);
  4795. }
  4796. }
  4797. }
  4798. if (scrollEvent.x) {
  4799. //default for no container Id (ex. mousewheel means that all containers must set scrollTop/Left)
  4800. var horizs = ['body','bodyheader', 'bodyfooter'];
  4801. this.flagScrollingHorizontally(scrollEvent);
  4802. if (sourceContainerId === 'body') {
  4803. horizs = ['bodyheader', 'bodyfooter'];
  4804. }
  4805. for (var j = 0; j < horizs.length; j++) {
  4806. var idh = horizs[j];
  4807. if (this.horizontalScrollSyncCallBackFns[idh]) {
  4808. this.horizontalScrollSyncCallBackFns[idh](scrollEvent);
  4809. }
  4810. }
  4811. }
  4812. };
  4813. Grid.prototype.registerViewportAdjuster = function registerViewportAdjuster(func) {
  4814. this.viewportAdjusters.push(func);
  4815. };
  4816. Grid.prototype.removeViewportAdjuster = function registerViewportAdjuster(func) {
  4817. var idx = this.viewportAdjusters.indexOf(func);
  4818. if (typeof(idx) !== 'undefined' && idx !== undefined) {
  4819. this.viewportAdjusters.splice(idx, 1);
  4820. }
  4821. };
  4822. Grid.prototype.getViewportAdjustment = function getViewportAdjustment() {
  4823. var self = this;
  4824. var adjustment = { height: 0, width: 0 };
  4825. self.viewportAdjusters.forEach(function (func) {
  4826. adjustment = func.call(this, adjustment);
  4827. });
  4828. return adjustment;
  4829. };
  4830. Grid.prototype.getVisibleRowCount = function getVisibleRowCount() {
  4831. // var count = 0;
  4832. // this.rows.forEach(function (row) {
  4833. // if (row.visible) {
  4834. // count++;
  4835. // }
  4836. // });
  4837. // return this.visibleRowCache.length;
  4838. return this.renderContainers.body.visibleRowCache.length;
  4839. };
  4840. Grid.prototype.getVisibleRows = function getVisibleRows() {
  4841. return this.renderContainers.body.visibleRowCache;
  4842. };
  4843. Grid.prototype.getVisibleColumnCount = function getVisibleColumnCount() {
  4844. // var count = 0;
  4845. // this.rows.forEach(function (row) {
  4846. // if (row.visible) {
  4847. // count++;
  4848. // }
  4849. // });
  4850. // return this.visibleRowCache.length;
  4851. return this.renderContainers.body.visibleColumnCache.length;
  4852. };
  4853. Grid.prototype.searchRows = function searchRows(renderableRows) {
  4854. return rowSearcher.search(this, renderableRows, this.columns);
  4855. };
  4856. Grid.prototype.sortByColumn = function sortByColumn(renderableRows) {
  4857. return rowSorter.sort(this, renderableRows, this.columns);
  4858. };
  4859. /**
  4860. * @ngdoc function
  4861. * @name getCellValue
  4862. * @methodOf ui.grid.class:Grid
  4863. * @description Gets the value of a cell for a particular row and column
  4864. * @param {GridRow} row Row to access
  4865. * @param {GridColumn} col Column to access
  4866. */
  4867. Grid.prototype.getCellValue = function getCellValue(row, col){
  4868. if ( typeof(row.entity[ '$$' + col.uid ]) !== 'undefined' ) {
  4869. return row.entity[ '$$' + col.uid].rendered;
  4870. } else if (this.options.flatEntityAccess && typeof(col.field) !== 'undefined' ){
  4871. return row.entity[col.field];
  4872. } else {
  4873. if (!col.cellValueGetterCache) {
  4874. col.cellValueGetterCache = $parse(row.getEntityQualifiedColField(col));
  4875. }
  4876. return col.cellValueGetterCache(row);
  4877. }
  4878. };
  4879. /**
  4880. * @ngdoc function
  4881. * @name getCellDisplayValue
  4882. * @methodOf ui.grid.class:Grid
  4883. * @description Gets the displayed value of a cell after applying any the `cellFilter`
  4884. * @param {GridRow} row Row to access
  4885. * @param {GridColumn} col Column to access
  4886. */
  4887. Grid.prototype.getCellDisplayValue = function getCellDisplayValue(row, col) {
  4888. if ( !col.cellDisplayGetterCache ) {
  4889. var custom_filter = col.cellFilter ? " | " + col.cellFilter : "";
  4890. if (typeof(row.entity['$$' + col.uid]) !== 'undefined') {
  4891. col.cellDisplayGetterCache = $parse(row.entity['$$' + col.uid].rendered + custom_filter);
  4892. } else if (this.options.flatEntityAccess && typeof(col.field) !== 'undefined') {
  4893. var colField = col.field.replace(/(')|(\\)/g, "\\$&");
  4894. col.cellDisplayGetterCache = $parse('entity[\'' + colField + '\']' + custom_filter);
  4895. } else {
  4896. col.cellDisplayGetterCache = $parse(row.getEntityQualifiedColField(col) + custom_filter);
  4897. }
  4898. }
  4899. var rowWithCol = angular.extend({}, row, {col: col});
  4900. return col.cellDisplayGetterCache(rowWithCol);
  4901. };
  4902. Grid.prototype.getNextColumnSortPriority = function getNextColumnSortPriority() {
  4903. var self = this,
  4904. p = 0;
  4905. self.columns.forEach(function (col) {
  4906. if (col.sort && col.sort.priority !== undefined && col.sort.priority >= p) {
  4907. p = col.sort.priority + 1;
  4908. }
  4909. });
  4910. return p;
  4911. };
  4912. /**
  4913. * @ngdoc function
  4914. * @name resetColumnSorting
  4915. * @methodOf ui.grid.class:Grid
  4916. * @description Return the columns that the grid is currently being sorted by
  4917. * @param {GridColumn} [excludedColumn] Optional GridColumn to exclude from having its sorting reset
  4918. */
  4919. Grid.prototype.resetColumnSorting = function resetColumnSorting(excludeCol) {
  4920. var self = this;
  4921. self.columns.forEach(function (col) {
  4922. if (col !== excludeCol && !col.suppressRemoveSort) {
  4923. col.sort = {};
  4924. }
  4925. });
  4926. };
  4927. /**
  4928. * @ngdoc function
  4929. * @name getColumnSorting
  4930. * @methodOf ui.grid.class:Grid
  4931. * @description Return the columns that the grid is currently being sorted by
  4932. * @returns {Array[GridColumn]} An array of GridColumn objects
  4933. */
  4934. Grid.prototype.getColumnSorting = function getColumnSorting() {
  4935. var self = this;
  4936. var sortedCols = [], myCols;
  4937. // Iterate through all the columns, sorted by priority
  4938. // Make local copy of column list, because sorting is in-place and we do not want to
  4939. // change the original sequence of columns
  4940. myCols = self.columns.slice(0);
  4941. myCols.sort(rowSorter.prioritySort).forEach(function (col) {
  4942. if (col.sort && typeof(col.sort.direction) !== 'undefined' && col.sort.direction && (col.sort.direction === uiGridConstants.ASC || col.sort.direction === uiGridConstants.DESC)) {
  4943. sortedCols.push(col);
  4944. }
  4945. });
  4946. return sortedCols;
  4947. };
  4948. /**
  4949. * @ngdoc function
  4950. * @name sortColumn
  4951. * @methodOf ui.grid.class:Grid
  4952. * @description Set the sorting on a given column, optionally resetting any existing sorting on the Grid.
  4953. * Emits the sortChanged event whenever the sort criteria are changed.
  4954. * @param {GridColumn} column Column to set the sorting on
  4955. * @param {uiGridConstants.ASC|uiGridConstants.DESC} [direction] Direction to sort by, either descending or ascending.
  4956. * If not provided, the column will iterate through the sort directions
  4957. * specified in the {@link ui.grid.class:GridOptions.columnDef#sortDirectionCycle sortDirectionCycle} attribute.
  4958. * @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
  4959. * by this column only
  4960. * @returns {Promise} A resolved promise that supplies the column.
  4961. */
  4962. Grid.prototype.sortColumn = function sortColumn(column, directionOrAdd, add) {
  4963. var self = this,
  4964. direction = null;
  4965. if (typeof(column) === 'undefined' || !column) {
  4966. throw new Error('No column parameter provided');
  4967. }
  4968. // Second argument can either be a direction or whether to add this column to the existing sort.
  4969. // If it's a boolean, it's an add, otherwise, it's a direction
  4970. if (typeof(directionOrAdd) === 'boolean') {
  4971. add = directionOrAdd;
  4972. }
  4973. else {
  4974. direction = directionOrAdd;
  4975. }
  4976. if (!add) {
  4977. self.resetColumnSorting(column);
  4978. column.sort.priority = undefined;
  4979. // Get the actual priority since there may be columns which have suppressRemoveSort set
  4980. column.sort.priority = self.getNextColumnSortPriority();
  4981. }
  4982. else if (column.sort.priority === undefined){
  4983. column.sort.priority = self.getNextColumnSortPriority();
  4984. }
  4985. if (!direction) {
  4986. // Find the current position in the cycle (or -1).
  4987. var i = column.sortDirectionCycle.indexOf(column.sort.direction ? column.sort.direction : null);
  4988. // Proceed to the next position in the cycle (or start at the beginning).
  4989. i = (i+1) % column.sortDirectionCycle.length;
  4990. // If suppressRemoveSort is set, and the next position in the cycle would
  4991. // remove the sort, skip it.
  4992. if (column.colDef && column.suppressRemoveSort && !column.sortDirectionCycle[i]) {
  4993. i = (i+1) % column.sortDirectionCycle.length;
  4994. }
  4995. if (column.sortDirectionCycle[i]) {
  4996. column.sort.direction = column.sortDirectionCycle[i];
  4997. } else {
  4998. removeSortOfColumn(column, self);
  4999. }
  5000. }
  5001. else {
  5002. column.sort.direction = direction;
  5003. }
  5004. self.api.core.raise.sortChanged( self, self.getColumnSorting() );
  5005. return $q.when(column);
  5006. };
  5007. var removeSortOfColumn = function removeSortOfColumn(column, grid) {
  5008. //Decrease priority for every col where priority is higher than the removed sort's priority.
  5009. grid.columns.forEach(function (col) {
  5010. if (col.sort && col.sort.priority !== undefined && col.sort.priority > column.sort.priority) {
  5011. col.sort.priority -= 1;
  5012. }
  5013. });
  5014. //Remove sort
  5015. column.sort = {};
  5016. };
  5017. /**
  5018. * communicate to outside world that we are done with initial rendering
  5019. */
  5020. Grid.prototype.renderingComplete = function(){
  5021. if (angular.isFunction(this.options.onRegisterApi)) {
  5022. this.options.onRegisterApi(this.api);
  5023. }
  5024. this.api.core.raise.renderingComplete( this.api );
  5025. };
  5026. Grid.prototype.createRowHashMap = function createRowHashMap() {
  5027. var self = this;
  5028. var hashMap = new RowHashMap();
  5029. hashMap.grid = self;
  5030. return hashMap;
  5031. };
  5032. /**
  5033. * @ngdoc function
  5034. * @name refresh
  5035. * @methodOf ui.grid.class:Grid
  5036. * @description Refresh the rendered grid on screen.
  5037. * @param {boolean} [rowsAltered] Optional flag for refreshing when the number of rows has changed.
  5038. */
  5039. Grid.prototype.refresh = function refresh(rowsAltered) {
  5040. var self = this;
  5041. var p1 = self.processRowsProcessors(self.rows).then(function (renderableRows) {
  5042. self.setVisibleRows(renderableRows);
  5043. }).catch(angular.noop);
  5044. var p2 = self.processColumnsProcessors(self.columns).then(function (renderableColumns) {
  5045. self.setVisibleColumns(renderableColumns);
  5046. }).catch(angular.noop);
  5047. return $q.all([p1, p2]).then(function () {
  5048. self.refreshCanvas(true);
  5049. self.redrawInPlace(rowsAltered);
  5050. }).catch(angular.noop);
  5051. };
  5052. /**
  5053. * @ngdoc function
  5054. * @name refreshRows
  5055. * @methodOf ui.grid.class:Grid
  5056. * @description Refresh the rendered rows on screen? Note: not functional at present
  5057. * @returns {promise} promise that is resolved when render completes?
  5058. *
  5059. */
  5060. Grid.prototype.refreshRows = function refreshRows() {
  5061. var self = this;
  5062. return self.processRowsProcessors(self.rows)
  5063. .then(function (renderableRows) {
  5064. self.setVisibleRows(renderableRows);
  5065. self.redrawInPlace();
  5066. self.refreshCanvas( true );
  5067. }).catch(angular.noop);
  5068. };
  5069. /**
  5070. * @ngdoc function
  5071. * @name refreshCanvas
  5072. * @methodOf ui.grid.class:Grid
  5073. * @description Builds all styles and recalculates much of the grid sizing
  5074. * @param {object} buildStyles optional parameter. Use TBD
  5075. * @returns {promise} promise that is resolved when the canvas
  5076. * has been refreshed
  5077. *
  5078. */
  5079. Grid.prototype.refreshCanvas = function(buildStyles) {
  5080. var self = this;
  5081. // gridUtil.logDebug('refreshCanvas');
  5082. var p = $q.defer();
  5083. // Get all the header heights
  5084. var containerHeadersToRecalc = [];
  5085. for (var containerId in self.renderContainers) {
  5086. if (self.renderContainers.hasOwnProperty(containerId)) {
  5087. var container = self.renderContainers[containerId];
  5088. // Skip containers that have no canvasWidth set yet
  5089. if (container.canvasWidth === null || isNaN(container.canvasWidth)) {
  5090. continue;
  5091. }
  5092. if (container.header || container.headerCanvas) {
  5093. container.explicitHeaderHeight = container.explicitHeaderHeight || null;
  5094. container.explicitHeaderCanvasHeight = container.explicitHeaderCanvasHeight || null;
  5095. containerHeadersToRecalc.push(container);
  5096. }
  5097. }
  5098. }
  5099. // Build the styles without the explicit header heights
  5100. if (buildStyles) {
  5101. self.buildStyles();
  5102. }
  5103. /*
  5104. *
  5105. * Here we loop through the headers, measuring each element as well as any header "canvas" it has within it.
  5106. *
  5107. * If any header is less than the largest header height, it will be resized to that so that we don't have headers
  5108. * with different heights, which looks like a rendering problem
  5109. *
  5110. * We'll do the same thing with the header canvases, and give the header CELLS an explicit height if their canvas
  5111. * is smaller than the largest canvas height. That was header cells without extra controls like filtering don't
  5112. * appear shorter than other cells.
  5113. *
  5114. */
  5115. if (containerHeadersToRecalc.length > 0) {
  5116. // Putting in a timeout as it's not calculating after the grid element is rendered and filled out
  5117. $timeout(function() {
  5118. // var oldHeaderHeight = self.grid.headerHeight;
  5119. // self.grid.headerHeight = gridUtil.outerElementHeight(self.header);
  5120. var rebuildStyles = false;
  5121. // Get all the header heights
  5122. var maxHeaderHeight = 0;
  5123. var maxHeaderCanvasHeight = 0;
  5124. var i, container;
  5125. var getHeight = function(oldVal, newVal){
  5126. if ( oldVal !== newVal){
  5127. rebuildStyles = true;
  5128. }
  5129. return newVal;
  5130. };
  5131. for (i = 0; i < containerHeadersToRecalc.length; i++) {
  5132. container = containerHeadersToRecalc[i];
  5133. // Skip containers that have no canvasWidth set yet
  5134. if (container.canvasWidth === null || isNaN(container.canvasWidth)) {
  5135. continue;
  5136. }
  5137. if (container.header) {
  5138. var headerHeight = container.headerHeight = getHeight(container.headerHeight, gridUtil.outerElementHeight(container.header));
  5139. // 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
  5140. var topBorder = gridUtil.getBorderSize(container.header, 'top');
  5141. var bottomBorder = gridUtil.getBorderSize(container.header, 'bottom');
  5142. var innerHeaderHeight = parseInt(headerHeight - topBorder - bottomBorder, 10);
  5143. innerHeaderHeight = innerHeaderHeight < 0 ? 0 : innerHeaderHeight;
  5144. container.innerHeaderHeight = innerHeaderHeight;
  5145. // If the header doesn't have an explicit height set, save the largest header height for use later
  5146. // 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
  5147. if (!container.explicitHeaderHeight && innerHeaderHeight > maxHeaderHeight) {
  5148. maxHeaderHeight = innerHeaderHeight;
  5149. }
  5150. }
  5151. if (container.headerCanvas) {
  5152. var headerCanvasHeight = container.headerCanvasHeight = getHeight(container.headerCanvasHeight, parseInt(gridUtil.outerElementHeight(container.headerCanvas), 10));
  5153. // If the header doesn't have an explicit canvas height, save the largest header canvas height for use later
  5154. // 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
  5155. if (!container.explicitHeaderCanvasHeight && headerCanvasHeight > maxHeaderCanvasHeight) {
  5156. maxHeaderCanvasHeight = headerCanvasHeight;
  5157. }
  5158. }
  5159. }
  5160. // Go through all the headers
  5161. for (i = 0; i < containerHeadersToRecalc.length; i++) {
  5162. container = containerHeadersToRecalc[i];
  5163. /* If:
  5164. 1. We have a max header height
  5165. 2. This container has a header height defined
  5166. 3. And either this container has an explicit header height set, OR its header height is less than the max
  5167. then:
  5168. Give this container's header an explicit height so it will line up with the tallest header
  5169. */
  5170. if (
  5171. maxHeaderHeight > 0 && typeof(container.headerHeight) !== 'undefined' && container.headerHeight !== null &&
  5172. (container.explicitHeaderHeight || container.headerHeight < maxHeaderHeight)
  5173. ) {
  5174. container.explicitHeaderHeight = getHeight(container.explicitHeaderHeight, maxHeaderHeight);
  5175. }
  5176. // Do the same as above except for the header canvas
  5177. if (
  5178. maxHeaderCanvasHeight > 0 && typeof(container.headerCanvasHeight) !== 'undefined' && container.headerCanvasHeight !== null &&
  5179. (container.explicitHeaderCanvasHeight || container.headerCanvasHeight < maxHeaderCanvasHeight)
  5180. ) {
  5181. container.explicitHeaderCanvasHeight = getHeight(container.explicitHeaderCanvasHeight, maxHeaderCanvasHeight);
  5182. }
  5183. }
  5184. // Rebuild styles if the header height has changed
  5185. // The header height is used in body/viewport calculations and those are then used in other styles so we need it to be available
  5186. if (buildStyles && rebuildStyles) {
  5187. self.buildStyles();
  5188. }
  5189. p.resolve();
  5190. });
  5191. }
  5192. else {
  5193. // Timeout still needs to be here to trigger digest after styles have been rebuilt
  5194. $timeout(function() {
  5195. p.resolve();
  5196. });
  5197. }
  5198. return p.promise;
  5199. };
  5200. /**
  5201. * @ngdoc function
  5202. * @name redrawInPlace
  5203. * @methodOf ui.grid.class:Grid
  5204. * @description Redraw the rows and columns based on our current scroll position
  5205. * @param {boolean} [rowsAdded] Optional to indicate rows are added and the scroll percentage must be recalculated
  5206. *
  5207. */
  5208. Grid.prototype.redrawInPlace = function redrawInPlace(rowsAdded) {
  5209. // gridUtil.logDebug('redrawInPlace');
  5210. var self = this;
  5211. for (var i in self.renderContainers) {
  5212. var container = self.renderContainers[i];
  5213. // gridUtil.logDebug('redrawing container', i);
  5214. if (rowsAdded) {
  5215. container.adjustRows(container.prevScrollTop, null);
  5216. container.adjustColumns(container.prevScrollLeft, null);
  5217. }
  5218. else {
  5219. container.adjustRows(null, container.prevScrolltopPercentage);
  5220. container.adjustColumns(null, container.prevScrollleftPercentage);
  5221. }
  5222. }
  5223. };
  5224. /**
  5225. * @ngdoc function
  5226. * @name hasLeftContainerColumns
  5227. * @methodOf ui.grid.class:Grid
  5228. * @description returns true if leftContainer has columns
  5229. */
  5230. Grid.prototype.hasLeftContainerColumns = function () {
  5231. return this.hasLeftContainer() && this.renderContainers.left.renderedColumns.length > 0;
  5232. };
  5233. /**
  5234. * @ngdoc function
  5235. * @name hasRightContainerColumns
  5236. * @methodOf ui.grid.class:Grid
  5237. * @description returns true if rightContainer has columns
  5238. */
  5239. Grid.prototype.hasRightContainerColumns = function () {
  5240. return this.hasRightContainer() && this.renderContainers.right.renderedColumns.length > 0;
  5241. };
  5242. // Turn the scroll position into a percentage and make it an argument for a scroll event
  5243. function getScrollPercentage(scrollPixels, scrollLength) {
  5244. var percentage = scrollPixels / scrollLength;
  5245. // if the percentage is greater than 1, set it to 1
  5246. return percentage <= 1 ? percentage : 1;
  5247. }
  5248. // Only returns the scroll Y position if the percentage is different from the previous
  5249. function getScrollY(scrollPixels, scrollLength, prevScrolltopPercentage) {
  5250. var scrollPercentage = getScrollPercentage(scrollPixels, scrollLength);
  5251. if (scrollPercentage !== prevScrolltopPercentage) {
  5252. return { percentage: getScrollPercentage(scrollPixels, scrollLength) };
  5253. }
  5254. return undefined;
  5255. }
  5256. // Only returns the scroll X position if the percentage is different from the previous
  5257. function getScrollX(horizScrollPixels, horizScrollLength, prevScrollleftPercentage) {
  5258. var horizPercentage = horizScrollPixels / horizScrollLength;
  5259. horizPercentage = (horizPercentage > 1) ? 1 : horizPercentage;
  5260. if (horizPercentage !== prevScrollleftPercentage) {
  5261. return { percentage: horizPercentage };
  5262. }
  5263. return undefined;
  5264. }
  5265. /**
  5266. * @ngdoc method
  5267. * @methodOf ui.grid.class:Grid
  5268. * @name scrollToIfNecessary
  5269. * @description Scrolls the grid to make a certain row and column combo visible,
  5270. * in the case that it is not completely visible on the screen already.
  5271. * @param {GridRow} gridRow row to make visible
  5272. * @param {GridColumn} gridCol column to make visible
  5273. * @returns {promise} a promise that is resolved when scrolling is complete
  5274. */
  5275. Grid.prototype.scrollToIfNecessary = function (gridRow, gridCol) {
  5276. var self = this;
  5277. var scrollEvent = new ScrollEvent(self, 'uiGrid.scrollToIfNecessary');
  5278. // Alias the visible row and column caches
  5279. var visRowCache = self.renderContainers.body.visibleRowCache;
  5280. var visColCache = self.renderContainers.body.visibleColumnCache;
  5281. /*-- Get the top, left, right, and bottom "scrolled" edges of the grid --*/
  5282. // 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
  5283. var topBound = self.renderContainers.body.prevScrollTop + self.headerHeight;
  5284. // Don't the let top boundary be less than 0
  5285. topBound = (topBound < 0) ? 0 : topBound;
  5286. // The left boundary is the current X scroll position
  5287. var leftBound = self.renderContainers.body.prevScrollLeft;
  5288. // The bottom boundary is the current Y scroll position, plus the height of the grid, but minus the header height.
  5289. // Basically this is the viewport height added on to the scroll position
  5290. var bottomBound = self.renderContainers.body.prevScrollTop + self.gridHeight - self.renderContainers.body.headerHeight - self.footerHeight - self.scrollbarWidth;
  5291. // If there's a horizontal scrollbar, remove its height from the bottom boundary, otherwise we'll be letting it obscure rows
  5292. //if (self.horizontalScrollbarHeight) {
  5293. // bottomBound = bottomBound - self.horizontalScrollbarHeight;
  5294. //}
  5295. // The right position is the current X scroll position minus the grid width
  5296. var rightBound = self.renderContainers.body.prevScrollLeft + Math.ceil(self.renderContainers.body.getViewportWidth());
  5297. // If there's a vertical scrollbar, subtract it from the right boundary or we'll allow it to obscure cells
  5298. //if (self.verticalScrollbarWidth) {
  5299. // rightBound = rightBound - self.verticalScrollbarWidth;
  5300. //}
  5301. // We were given a row to scroll to
  5302. if (gridRow !== null) {
  5303. // This is the index of the row we want to scroll to, within the list of rows that can be visible
  5304. var seekRowIndex = visRowCache.indexOf(gridRow);
  5305. // Total vertical scroll length of the grid
  5306. var scrollLength = (self.renderContainers.body.getCanvasHeight() - self.renderContainers.body.getViewportHeight());
  5307. // Add the height of the native horizontal scrollbar to the scroll length, if it's there. Otherwise it will mask over the final row
  5308. //if (self.horizontalScrollbarHeight && self.horizontalScrollbarHeight > 0) {
  5309. // scrollLength = scrollLength + self.horizontalScrollbarHeight;
  5310. //}
  5311. // This is the minimum amount of pixels we need to scroll vertical in order to see this row.
  5312. var pixelsToSeeRow = (seekRowIndex * self.options.rowHeight + self.headerHeight);
  5313. // Don't let the pixels required to see the row be less than zero
  5314. pixelsToSeeRow = (pixelsToSeeRow < 0) ? 0 : pixelsToSeeRow;
  5315. var scrollPixels;
  5316. // 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...
  5317. if (pixelsToSeeRow < topBound) {
  5318. // Get the different between the top boundary and the required scroll position and subtract it from the current scroll position\
  5319. // to get the full position we need
  5320. scrollPixels = self.renderContainers.body.prevScrollTop - (topBound - pixelsToSeeRow);
  5321. scrollEvent.y = getScrollY(scrollPixels, scrollLength, self.renderContainers.body.prevScrolltopPercentage);
  5322. }
  5323. // 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...
  5324. else if (pixelsToSeeRow > bottomBound) {
  5325. // Get the different between the bottom boundary and the required scroll position and add it to the current scroll position
  5326. // to get the full position we need
  5327. scrollPixels = pixelsToSeeRow - bottomBound + self.renderContainers.body.prevScrollTop;
  5328. scrollEvent.y = getScrollY(scrollPixels, scrollLength,self.renderContainers.body.prevScrolltopPercentage);
  5329. }
  5330. }
  5331. // We were given a column to scroll to
  5332. if (gridCol !== null) {
  5333. // This is the index of the column we want to scroll to, within the list of columns that can be visible
  5334. var seekColumnIndex = visColCache.indexOf(gridCol);
  5335. // Total horizontal scroll length of the grid
  5336. var horizScrollLength = (self.renderContainers.body.getCanvasWidth() - self.renderContainers.body.getViewportWidth());
  5337. // This is the minimum amount of pixels we need to scroll horizontal in order to see this column
  5338. var columnLeftEdge = 0;
  5339. for (var i = 0; i < seekColumnIndex; i++) {
  5340. var col = visColCache[i];
  5341. columnLeftEdge += col.drawnWidth;
  5342. }
  5343. columnLeftEdge = (columnLeftEdge < 0) ? 0 : columnLeftEdge;
  5344. var columnRightEdge = columnLeftEdge + gridCol.drawnWidth;
  5345. // Don't let the pixels required to see the column be less than zero
  5346. columnRightEdge = (columnRightEdge < 0) ? 0 : columnRightEdge;
  5347. var horizScrollPixels;
  5348. // If the scroll position we need to see the column is LESS than the left boundary, i.e. obscured before the left of the self...
  5349. if (columnLeftEdge < leftBound) {
  5350. // Get the different between the left boundary and the required scroll position and subtract it from the current scroll position\
  5351. // to get the full position we need
  5352. horizScrollPixels = self.renderContainers.body.prevScrollLeft - (leftBound - columnLeftEdge);
  5353. // Turn the scroll position into a percentage and make it an argument for a scroll event
  5354. scrollEvent.x = getScrollX(horizScrollPixels, horizScrollLength, self.renderContainers.body.prevScrollleftPercentage);
  5355. }
  5356. // Otherwise if the scroll position we need to see the column is MORE than the right boundary, i.e. obscured after the right of the self...
  5357. else if (columnRightEdge > rightBound) {
  5358. // Get the different between the right boundary and the required scroll position and add it to the current scroll position
  5359. // to get the full position we need
  5360. horizScrollPixels = columnRightEdge - rightBound + self.renderContainers.body.prevScrollLeft;
  5361. // Turn the scroll position into a percentage and make it an argument for a scroll event
  5362. scrollEvent.x = getScrollX(horizScrollPixels, horizScrollLength, self.renderContainers.body.prevScrollleftPercentage);
  5363. }
  5364. }
  5365. var deferred = $q.defer();
  5366. // If we need to scroll on either the x or y axes, fire a scroll event
  5367. if (scrollEvent.y || scrollEvent.x) {
  5368. scrollEvent.withDelay = false;
  5369. self.scrollContainers('',scrollEvent);
  5370. var dereg = self.api.core.on.scrollEnd(null,function() {
  5371. deferred.resolve(scrollEvent);
  5372. dereg();
  5373. });
  5374. }
  5375. else {
  5376. deferred.resolve();
  5377. }
  5378. return deferred.promise;
  5379. };
  5380. /**
  5381. * @ngdoc method
  5382. * @methodOf ui.grid.class:Grid
  5383. * @name scrollTo
  5384. * @description Scroll the grid such that the specified
  5385. * row and column is in view
  5386. * @param {object} rowEntity gridOptions.data[] array instance to make visible
  5387. * @param {object} colDef to make visible
  5388. * @returns {promise} a promise that is resolved after any scrolling is finished
  5389. */
  5390. Grid.prototype.scrollTo = function (rowEntity, colDef) {
  5391. var gridRow = null, gridCol = null;
  5392. if (rowEntity !== null && typeof(rowEntity) !== 'undefined' ) {
  5393. gridRow = this.getRow(rowEntity);
  5394. }
  5395. if (colDef !== null && typeof(colDef) !== 'undefined' ) {
  5396. gridCol = this.getColumn(colDef.name ? colDef.name : colDef.field);
  5397. }
  5398. return this.scrollToIfNecessary(gridRow, gridCol);
  5399. };
  5400. /**
  5401. * @ngdoc function
  5402. * @name clearAllFilters
  5403. * @methodOf ui.grid.class:Grid
  5404. * @description Clears all filters and optionally refreshes the visible rows.
  5405. * @param {object} refreshRows Defaults to true.
  5406. * @param {object} clearConditions Defaults to false.
  5407. * @param {object} clearFlags Defaults to false.
  5408. * @returns {promise} If `refreshRows` is true, returns a promise of the rows refreshing.
  5409. */
  5410. Grid.prototype.clearAllFilters = function clearAllFilters(refreshRows, clearConditions, clearFlags) {
  5411. // Default `refreshRows` to true because it will be the most commonly desired behaviour.
  5412. if (refreshRows === undefined) {
  5413. refreshRows = true;
  5414. }
  5415. if (clearConditions === undefined) {
  5416. clearConditions = false;
  5417. }
  5418. if (clearFlags === undefined) {
  5419. clearFlags = false;
  5420. }
  5421. this.columns.forEach(function(column) {
  5422. column.filters.forEach(function(filter) {
  5423. filter.term = undefined;
  5424. if (clearConditions) {
  5425. filter.condition = undefined;
  5426. }
  5427. if (clearFlags) {
  5428. filter.flags = undefined;
  5429. }
  5430. });
  5431. });
  5432. if (refreshRows) {
  5433. return this.refreshRows();
  5434. }
  5435. };
  5436. // Blatantly stolen from Angular as it isn't exposed (yet? 2.0?)
  5437. function RowHashMap() {}
  5438. RowHashMap.prototype = {
  5439. /**
  5440. * Store key value pair
  5441. * @param key key to store can be any type
  5442. * @param value value to store can be any type
  5443. */
  5444. put: function(key, value) {
  5445. this[this.grid.options.rowIdentity(key)] = value;
  5446. },
  5447. /**
  5448. * @param key
  5449. * @returns {Object} the value for the key
  5450. */
  5451. get: function(key) {
  5452. return this[this.grid.options.rowIdentity(key)];
  5453. },
  5454. /**
  5455. * Remove the key/value pair
  5456. * @param key
  5457. */
  5458. remove: function(key) {
  5459. var value = this[key = this.grid.options.rowIdentity(key)];
  5460. delete this[key];
  5461. return value;
  5462. }
  5463. };
  5464. return Grid;
  5465. }]);
  5466. })();
  5467. (function () {
  5468. angular.module('ui.grid')
  5469. .factory('GridApi', ['$q', '$rootScope', 'gridUtil', 'uiGridConstants', 'GridRow', 'uiGridGridMenuService',
  5470. function ($q, $rootScope, gridUtil, uiGridConstants, GridRow, uiGridGridMenuService) {
  5471. /**
  5472. * @ngdoc function
  5473. * @name ui.grid.class:GridApi
  5474. * @description GridApi provides the ability to register public methods events inside the grid and allow
  5475. * for other components to use the api via featureName.raise.methodName and featureName.on.eventName(function(args){}.
  5476. * <br/>
  5477. * To listen to events, you must add a callback to gridOptions.onRegisterApi
  5478. * <pre>
  5479. * $scope.gridOptions.onRegisterApi = function(gridApi){
  5480. * gridApi.cellNav.on.navigate($scope,function(newRowCol, oldRowCol){
  5481. * $log.log('navigation event');
  5482. * });
  5483. * };
  5484. * </pre>
  5485. * @param {object} grid grid that owns api
  5486. */
  5487. var GridApi = function GridApi(grid) {
  5488. this.grid = grid;
  5489. this.listeners = [];
  5490. /**
  5491. * @ngdoc function
  5492. * @name renderingComplete
  5493. * @methodOf ui.grid.core.api:PublicApi
  5494. * @description Rendering is complete, called at the same
  5495. * time as `onRegisterApi`, but provides a way to obtain
  5496. * that same event within features without stopping end
  5497. * users from getting at the onRegisterApi method.
  5498. *
  5499. * Included in gridApi so that it's always there - otherwise
  5500. * there is still a timing problem with when a feature can
  5501. * call this.
  5502. *
  5503. * @param {GridApi} gridApi the grid api, as normally
  5504. * returned in the onRegisterApi method
  5505. *
  5506. * @example
  5507. * <pre>
  5508. * gridApi.core.on.renderingComplete( grid );
  5509. * </pre>
  5510. */
  5511. this.registerEvent( 'core', 'renderingComplete' );
  5512. /**
  5513. * @ngdoc event
  5514. * @name filterChanged
  5515. * @eventOf ui.grid.core.api:PublicApi
  5516. * @description is raised after the filter is changed. The nature
  5517. * of the watch expression doesn't allow notification of what changed,
  5518. * so the receiver of this event will need to re-extract the filter
  5519. * conditions from the columns.
  5520. *
  5521. */
  5522. this.registerEvent( 'core', 'filterChanged' );
  5523. /**
  5524. * @ngdoc function
  5525. * @name setRowInvisible
  5526. * @methodOf ui.grid.core.api:PublicApi
  5527. * @description Sets an override on the row to make it always invisible,
  5528. * which will override any filtering or other visibility calculations.
  5529. * If the row is currently visible then sets it to invisible and calls
  5530. * both grid refresh and emits the rowsVisibleChanged event
  5531. * @param {GridRow} row the row we want to make invisible
  5532. */
  5533. this.registerMethod( 'core', 'setRowInvisible', GridRow.prototype.setRowInvisible );
  5534. /**
  5535. * @ngdoc function
  5536. * @name clearRowInvisible
  5537. * @methodOf ui.grid.core.api:PublicApi
  5538. * @description Clears any override on visibility for the row so that it returns to
  5539. * using normal filtering and other visibility calculations.
  5540. * If the row is currently invisible then sets it to visible and calls
  5541. * both grid refresh and emits the rowsVisibleChanged event
  5542. * TODO: if a filter is active then we can't just set it to visible?
  5543. * @param {GridRow} row the row we want to make visible
  5544. */
  5545. this.registerMethod( 'core', 'clearRowInvisible', GridRow.prototype.clearRowInvisible );
  5546. /**
  5547. * @ngdoc function
  5548. * @name getVisibleRows
  5549. * @methodOf ui.grid.core.api:PublicApi
  5550. * @description Returns all visible rows
  5551. * @param {Grid} grid the grid you want to get visible rows from
  5552. * @returns {array} an array of gridRow
  5553. */
  5554. this.registerMethod( 'core', 'getVisibleRows', this.grid.getVisibleRows );
  5555. /**
  5556. * @ngdoc event
  5557. * @name rowsVisibleChanged
  5558. * @eventOf ui.grid.core.api:PublicApi
  5559. * @description is raised after the rows that are visible
  5560. * change. The filtering is zero-based, so it isn't possible
  5561. * to say which rows changed (unlike in the selection feature).
  5562. * We can plausibly know which row was changed when setRowInvisible
  5563. * is called, but in that situation the user already knows which row
  5564. * they changed. When a filter runs we don't know what changed,
  5565. * and that is the one that would have been useful.
  5566. *
  5567. */
  5568. this.registerEvent( 'core', 'rowsVisibleChanged' );
  5569. /**
  5570. * @ngdoc event
  5571. * @name rowsRendered
  5572. * @eventOf ui.grid.core.api:PublicApi
  5573. * @description is raised after the cache of visible rows is changed.
  5574. */
  5575. this.registerEvent( 'core', 'rowsRendered' );
  5576. /**
  5577. * @ngdoc event
  5578. * @name scrollBegin
  5579. * @eventOf ui.grid.core.api:PublicApi
  5580. * @description is raised when scroll begins. Is throttled, so won't be raised too frequently
  5581. */
  5582. this.registerEvent( 'core', 'scrollBegin' );
  5583. /**
  5584. * @ngdoc event
  5585. * @name scrollEnd
  5586. * @eventOf ui.grid.core.api:PublicApi
  5587. * @description is raised when scroll has finished. Is throttled, so won't be raised too frequently
  5588. */
  5589. this.registerEvent( 'core', 'scrollEnd' );
  5590. /**
  5591. * @ngdoc event
  5592. * @name canvasHeightChanged
  5593. * @eventOf ui.grid.core.api:PublicApi
  5594. * @description is raised when the canvas height has changed
  5595. * <br/>
  5596. * arguments: oldHeight, newHeight
  5597. */
  5598. this.registerEvent( 'core', 'canvasHeightChanged');
  5599. /**
  5600. * @ngdoc event
  5601. * @name gridDimensionChanged
  5602. * @eventOf ui.grid.core.api:PublicApi
  5603. * @description is raised when the grid dimensions have changed (when autoResize is on)
  5604. * <br/>
  5605. * arguments: oldGridHeight, oldGridWidth, newGridHeight, newGridWidth
  5606. */
  5607. this.registerEvent( 'core', 'gridDimensionChanged');
  5608. };
  5609. /**
  5610. * @ngdoc function
  5611. * @name ui.grid.class:suppressEvents
  5612. * @methodOf ui.grid.class:GridApi
  5613. * @description Used to execute a function while disabling the specified event listeners.
  5614. * Disables the listenerFunctions, executes the callbackFn, and then enables
  5615. * the listenerFunctions again
  5616. * @param {object} listenerFuncs listenerFunc or array of listenerFuncs to suppress. These must be the same
  5617. * functions that were used in the .on.eventName method
  5618. * @param {object} callBackFn function to execute
  5619. * @example
  5620. * <pre>
  5621. * var navigate = function (newRowCol, oldRowCol){
  5622. * //do something on navigate
  5623. * }
  5624. *
  5625. * gridApi.cellNav.on.navigate(scope,navigate);
  5626. *
  5627. *
  5628. * //call the scrollTo event and suppress our navigate listener
  5629. * //scrollTo will still raise the event for other listeners
  5630. * gridApi.suppressEvents(navigate, function(){
  5631. * gridApi.cellNav.scrollTo(aRow, aCol);
  5632. * });
  5633. *
  5634. * </pre>
  5635. */
  5636. GridApi.prototype.suppressEvents = function (listenerFuncs, callBackFn) {
  5637. var self = this;
  5638. var listeners = angular.isArray(listenerFuncs) ? listenerFuncs : [listenerFuncs];
  5639. //find all registered listeners
  5640. var foundListeners = self.listeners.filter(function(listener) {
  5641. return listeners.some(function(l) {
  5642. return listener.handler === l;
  5643. });
  5644. });
  5645. //deregister all the listeners
  5646. foundListeners.forEach(function(l){
  5647. l.dereg();
  5648. });
  5649. callBackFn();
  5650. //reregister all the listeners
  5651. foundListeners.forEach(function(l){
  5652. l.dereg = registerEventWithAngular(l.eventId, l.handler, self.grid, l._this);
  5653. });
  5654. };
  5655. /**
  5656. * @ngdoc function
  5657. * @name registerEvent
  5658. * @methodOf ui.grid.class:GridApi
  5659. * @description Registers a new event for the given feature. The event will get a
  5660. * .raise and .on prepended to it
  5661. * <br>
  5662. * .raise.eventName() - takes no arguments
  5663. * <br/>
  5664. * <br/>
  5665. * .on.eventName(scope, callBackFn, _this)
  5666. * <br/>
  5667. * scope - a scope reference to add a deregister call to the scopes .$on('destroy'). Scope is optional and can be a null value,
  5668. * but in this case you must deregister it yourself via the returned deregister function
  5669. * <br/>
  5670. * callBackFn - The function to call
  5671. * <br/>
  5672. * _this - optional this context variable for callbackFn. If omitted, grid.api will be used for the context
  5673. * <br/>
  5674. * .on.eventName returns a dereg funtion that will remove the listener. It's not necessary to use it as the listener
  5675. * will be removed when the scope is destroyed.
  5676. * @param {string} featureName name of the feature that raises the event
  5677. * @param {string} eventName name of the event
  5678. */
  5679. GridApi.prototype.registerEvent = function (featureName, eventName) {
  5680. var self = this;
  5681. if (!self[featureName]) {
  5682. self[featureName] = {};
  5683. }
  5684. var feature = self[featureName];
  5685. if (!feature.on) {
  5686. feature.on = {};
  5687. feature.raise = {};
  5688. }
  5689. var eventId = self.grid.id + featureName + eventName;
  5690. // gridUtil.logDebug('Creating raise event method ' + featureName + '.raise.' + eventName);
  5691. feature.raise[eventName] = function () {
  5692. $rootScope.$emit.apply($rootScope, [eventId].concat(Array.prototype.slice.call(arguments)));
  5693. };
  5694. // gridUtil.logDebug('Creating on event method ' + featureName + '.on.' + eventName);
  5695. feature.on[eventName] = function (scope, handler, _this) {
  5696. if ( scope !== null && typeof(scope.$on) === 'undefined' ){
  5697. 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');
  5698. return;
  5699. }
  5700. var deregAngularOn = registerEventWithAngular(eventId, handler, self.grid, _this);
  5701. //track our listener so we can turn off and on
  5702. var listener = {handler: handler, dereg: deregAngularOn, eventId: eventId, scope: scope, _this:_this};
  5703. self.listeners.push(listener);
  5704. var removeListener = function(){
  5705. listener.dereg();
  5706. var index = self.listeners.indexOf(listener);
  5707. self.listeners.splice(index,1);
  5708. };
  5709. //destroy tracking when scope is destroyed
  5710. if (scope) {
  5711. scope.$on('$destroy', function() {
  5712. removeListener();
  5713. });
  5714. }
  5715. return removeListener;
  5716. };
  5717. };
  5718. function registerEventWithAngular(eventId, handler, grid, _this) {
  5719. return $rootScope.$on(eventId, function (event) {
  5720. var args = Array.prototype.slice.call(arguments);
  5721. args.splice(0, 1); //remove evt argument
  5722. handler.apply(_this ? _this : grid.api, args);
  5723. });
  5724. }
  5725. /**
  5726. * @ngdoc function
  5727. * @name registerEventsFromObject
  5728. * @methodOf ui.grid.class:GridApi
  5729. * @description Registers features and events from a simple objectMap.
  5730. * eventObjectMap must be in this format (multiple features allowed)
  5731. * <pre>
  5732. * {featureName:
  5733. * {
  5734. * eventNameOne:function(args){},
  5735. * eventNameTwo:function(args){}
  5736. * }
  5737. * }
  5738. * </pre>
  5739. * @param {object} eventObjectMap map of feature/event names
  5740. */
  5741. GridApi.prototype.registerEventsFromObject = function (eventObjectMap) {
  5742. var self = this;
  5743. var features = [];
  5744. angular.forEach(eventObjectMap, function (featProp, featPropName) {
  5745. var feature = {name: featPropName, events: []};
  5746. angular.forEach(featProp, function (prop, propName) {
  5747. feature.events.push(propName);
  5748. });
  5749. features.push(feature);
  5750. });
  5751. features.forEach(function (feature) {
  5752. feature.events.forEach(function (event) {
  5753. self.registerEvent(feature.name, event);
  5754. });
  5755. });
  5756. };
  5757. /**
  5758. * @ngdoc function
  5759. * @name registerMethod
  5760. * @methodOf ui.grid.class:GridApi
  5761. * @description Registers a new event for the given feature
  5762. * @param {string} featureName name of the feature
  5763. * @param {string} methodName name of the method
  5764. * @param {object} callBackFn function to execute
  5765. * @param {object} _this binds callBackFn 'this' to _this. Defaults to gridApi.grid
  5766. */
  5767. GridApi.prototype.registerMethod = function (featureName, methodName, callBackFn, _this) {
  5768. if (!this[featureName]) {
  5769. this[featureName] = {};
  5770. }
  5771. var feature = this[featureName];
  5772. feature[methodName] = gridUtil.createBoundedWrapper(_this || this.grid, callBackFn);
  5773. };
  5774. /**
  5775. * @ngdoc function
  5776. * @name registerMethodsFromObject
  5777. * @methodOf ui.grid.class:GridApi
  5778. * @description Registers features and methods from a simple objectMap.
  5779. * eventObjectMap must be in this format (multiple features allowed)
  5780. * <br>
  5781. * {featureName:
  5782. * {
  5783. * methodNameOne:function(args){},
  5784. * methodNameTwo:function(args){}
  5785. * }
  5786. * @param {object} eventObjectMap map of feature/event names
  5787. * @param {object} _this binds this to _this for all functions. Defaults to gridApi.grid
  5788. */
  5789. GridApi.prototype.registerMethodsFromObject = function (methodMap, _this) {
  5790. var self = this;
  5791. var features = [];
  5792. angular.forEach(methodMap, function (featProp, featPropName) {
  5793. var feature = {name: featPropName, methods: []};
  5794. angular.forEach(featProp, function (prop, propName) {
  5795. feature.methods.push({name: propName, fn: prop});
  5796. });
  5797. features.push(feature);
  5798. });
  5799. features.forEach(function (feature) {
  5800. feature.methods.forEach(function (method) {
  5801. self.registerMethod(feature.name, method.name, method.fn, _this);
  5802. });
  5803. });
  5804. };
  5805. return GridApi;
  5806. }]);
  5807. })();
  5808. (function(){
  5809. angular.module('ui.grid')
  5810. .factory('GridColumn', ['gridUtil', 'uiGridConstants', 'i18nService', function(gridUtil, uiGridConstants, i18nService) {
  5811. /**
  5812. * ******************************************************************************************
  5813. * PaulL1: Ugly hack here in documentation. These properties are clearly properties of GridColumn,
  5814. * and need to be noted as such for those extending and building ui-grid itself.
  5815. * However, from an end-developer perspective, they interact with all these through columnDefs,
  5816. * and they really need to be documented there. I feel like they're relatively static, and
  5817. * I can't find an elegant way for ngDoc to reference to both....so I've duplicated each
  5818. * comment block. Ugh.
  5819. *
  5820. */
  5821. /**
  5822. * @ngdoc property
  5823. * @name name
  5824. * @propertyOf ui.grid.class:GridColumn
  5825. * @description (mandatory) Each column should have a name, although for backward
  5826. * compatibility with 2.x name can be omitted if field is present.
  5827. *
  5828. * Important - This must be unique to each column on a web page since it can
  5829. * be used as a key for retrieving information such as custom sort algorithms.
  5830. *
  5831. */
  5832. /**
  5833. * @ngdoc property
  5834. * @name name
  5835. * @propertyOf ui.grid.class:GridOptions.columnDef
  5836. * @description (mandatory) Each column should have a name, although for backward
  5837. * compatibility with 2.x name can be omitted if field is present.
  5838. *
  5839. * Important - This must be unique to each column on a web page since it can
  5840. * be used as a key for retrieving information such as custom sort algorithms.
  5841. *
  5842. */
  5843. /**
  5844. * @ngdoc property
  5845. * @name displayName
  5846. * @propertyOf ui.grid.class:GridColumn
  5847. * @description Column name that will be shown in the header. If displayName is not
  5848. * provided then one is generated using the name.
  5849. *
  5850. */
  5851. /**
  5852. * @ngdoc property
  5853. * @name displayName
  5854. * @propertyOf ui.grid.class:GridOptions.columnDef
  5855. * @description Column name that will be shown in the header. If displayName is not
  5856. * provided then one is generated using the name.
  5857. *
  5858. */
  5859. /**
  5860. * @ngdoc property
  5861. * @name field
  5862. * @propertyOf ui.grid.class:GridColumn
  5863. * @description field must be provided if you wish to bind to a
  5864. * property in the data source. Should be an angular expression that evaluates against grid.options.data
  5865. * array element. Can be a complex expression: <code>employee.address.city</code>, or can be a function: <code>employee.getFullAddress()</code>.
  5866. * See the angular docs on binding expressions.
  5867. *
  5868. */
  5869. /**
  5870. * @ngdoc property
  5871. * @name field
  5872. * @propertyOf ui.grid.class:GridOptions.columnDef
  5873. * @description field must be provided if you wish to bind to a
  5874. * property in the data source. Should be an angular expression that evaluates against grid.options.data
  5875. * 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. *
  5876. */
  5877. /**
  5878. * @ngdoc property
  5879. * @name filter
  5880. * @propertyOf ui.grid.class:GridColumn
  5881. * @description Filter on this column.
  5882. *
  5883. * Available built-in conditions and types are listed under {@link jui.grid.service:uiGridConstants#properties_filter uiGridOptions.filter}
  5884. * @example
  5885. * <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>
  5886. *
  5887. */
  5888. /**
  5889. * @ngdoc property
  5890. * @name extraStyle
  5891. * @propertyOf ui.grid.class:GridColumn
  5892. * @description additional on this column.
  5893. * @example
  5894. * <pre>{extraStyle: {display:'table-cell'}}</pre>
  5895. *
  5896. */
  5897. /**
  5898. * @ngdoc object
  5899. * @name ui.grid.class:GridColumn
  5900. * @description Represents the viewModel for each column. Any state or methods needed for a Grid Column
  5901. * are defined on this prototype
  5902. * @param {ColumnDef} colDef the column def to associate with this column
  5903. * @param {number} uid the unique and immutable uid we'd like to allocate to this column
  5904. * @param {Grid} grid the grid we'd like to create this column in
  5905. */
  5906. function GridColumn(colDef, uid, grid) {
  5907. var self = this;
  5908. self.grid = grid;
  5909. self.uid = uid;
  5910. self.updateColumnDef(colDef, true);
  5911. self.aggregationValue = undefined;
  5912. // The footer cell registers to listen for the rowsRendered event, and calls this. Needed to be
  5913. // in something with a scope so that the dereg would get called
  5914. self.updateAggregationValue = function() {
  5915. // gridUtil.logDebug('getAggregationValue for Column ' + self.colDef.name);
  5916. /**
  5917. * @ngdoc property
  5918. * @name aggregationType
  5919. * @propertyOf ui.grid.class:GridOptions.columnDef
  5920. * @description The aggregation that you'd like to show in the columnFooter for this
  5921. * column. Valid values are in
  5922. * {@link ui.grid.service:uiGridConstants#properties_aggregationTypes uiGridConstants.aggregationTypes},
  5923. * and currently include `uiGridConstants.aggregationTypes.count`,
  5924. * `uiGridConstants.aggregationTypes.sum`, `uiGridConstants.aggregationTypes.avg`, `uiGridConstants.aggregationTypes.min`,
  5925. * `uiGridConstants.aggregationTypes.max`.
  5926. *
  5927. * You can also provide a function as the aggregation type, in this case your function needs to accept the full
  5928. * set of visible rows, and return a value that should be shown
  5929. */
  5930. if (!self.aggregationType) {
  5931. self.aggregationValue = undefined;
  5932. return;
  5933. }
  5934. var result = 0;
  5935. var visibleRows = self.grid.getVisibleRows();
  5936. var cellValues = function(){
  5937. var values = [];
  5938. visibleRows.forEach(function (row) {
  5939. var cellValue = self.grid.getCellValue(row, self);
  5940. var cellNumber = Number(cellValue);
  5941. if (!isNaN(cellNumber)) {
  5942. values.push(cellNumber);
  5943. }
  5944. });
  5945. return values;
  5946. };
  5947. if (angular.isFunction(self.aggregationType)) {
  5948. self.aggregationValue = self.aggregationType(visibleRows, self);
  5949. }
  5950. else if (self.aggregationType === uiGridConstants.aggregationTypes.count) {
  5951. self.aggregationValue = self.grid.getVisibleRowCount();
  5952. }
  5953. else if (self.aggregationType === uiGridConstants.aggregationTypes.sum) {
  5954. cellValues().forEach(function (value) {
  5955. result += value;
  5956. });
  5957. self.aggregationValue = result;
  5958. }
  5959. else if (self.aggregationType === uiGridConstants.aggregationTypes.avg) {
  5960. cellValues().forEach(function (value) {
  5961. result += value;
  5962. });
  5963. result = result / cellValues().length;
  5964. self.aggregationValue = result;
  5965. }
  5966. else if (self.aggregationType === uiGridConstants.aggregationTypes.min) {
  5967. self.aggregationValue = Math.min.apply(null, cellValues());
  5968. }
  5969. else if (self.aggregationType === uiGridConstants.aggregationTypes.max) {
  5970. self.aggregationValue = Math.max.apply(null, cellValues());
  5971. }
  5972. else {
  5973. self.aggregationValue = '\u00A0';
  5974. }
  5975. };
  5976. // var throttledUpdateAggregationValue = gridUtil.throttle(updateAggregationValue, self.grid.options.aggregationCalcThrottle, { trailing: true, context: self.name });
  5977. /**
  5978. * @ngdoc function
  5979. * @name getAggregationValue
  5980. * @methodOf ui.grid.class:GridColumn
  5981. * @description gets the aggregation value based on the aggregation type for this column.
  5982. * Debounced using scrollDebounce option setting
  5983. */
  5984. this.getAggregationValue = function() {
  5985. // if (!self.grid.isScrollingVertically && !self.grid.isScrollingHorizontally) {
  5986. // throttledUpdateAggregationValue();
  5987. // }
  5988. return self.aggregationValue;
  5989. };
  5990. }
  5991. /**
  5992. * @ngdoc function
  5993. * @name hideColumn
  5994. * @methodOf ui.grid.class:GridColumn
  5995. * @description Hides the column by setting colDef.visible = false
  5996. */
  5997. GridColumn.prototype.hideColumn = function() {
  5998. this.colDef.visible = false;
  5999. };
  6000. /**
  6001. * @ngdoc method
  6002. * @methodOf ui.grid.class:GridColumn
  6003. * @name setPropertyOrDefault
  6004. * @description Sets a property on the column using the passed in columnDef, and
  6005. * setting the defaultValue if the value cannot be found on the colDef
  6006. * @param {ColumnDef} colDef the column def to look in for the property value
  6007. * @param {string} propName the property name we'd like to set
  6008. * @param {object} defaultValue the value to use if the colDef doesn't provide the setting
  6009. */
  6010. GridColumn.prototype.setPropertyOrDefault = function (colDef, propName, defaultValue) {
  6011. var self = this;
  6012. // Use the column definition filter if we were passed it
  6013. if (typeof(colDef[propName]) !== 'undefined' && colDef[propName]) {
  6014. self[propName] = colDef[propName];
  6015. }
  6016. // Otherwise use our own if it's set
  6017. else if (typeof(self[propName]) !== 'undefined') {
  6018. self[propName] = self[propName];
  6019. }
  6020. // Default to empty object for the filter
  6021. else {
  6022. self[propName] = defaultValue ? defaultValue : {};
  6023. }
  6024. };
  6025. /**
  6026. * @ngdoc property
  6027. * @name width
  6028. * @propertyOf ui.grid.class:GridOptions.columnDef
  6029. * @description sets the column width. Can be either
  6030. * a number or a percentage, or an * for auto.
  6031. * @example
  6032. * <pre> $scope.gridOptions.columnDefs = [ { field: 'field1', width: 100},
  6033. * { field: 'field2', width: '20%'},
  6034. * { field: 'field3', width: '*' }]; </pre>
  6035. *
  6036. */
  6037. /**
  6038. * @ngdoc property
  6039. * @name minWidth
  6040. * @propertyOf ui.grid.class:GridOptions.columnDef
  6041. * @description Sets the minimum column width. Should be a number.
  6042. * Defaults to gridOptions.minimumColumnSize if minWidth is not provided.
  6043. * @example
  6044. * <pre> $scope.gridOptions.columnDefs = [ { field: 'field1', minWidth: 100}]; </pre>
  6045. *
  6046. */
  6047. /**
  6048. * @ngdoc property
  6049. * @name maxWidth
  6050. * @propertyOf ui.grid.class:GridOptions.columnDef
  6051. * @description sets the maximum column width. Should be a number.
  6052. * @example
  6053. * <pre> $scope.gridOptions.columnDefs = [ { field: 'field1', maxWidth: 100}]; </pre>
  6054. *
  6055. */
  6056. /**
  6057. * @ngdoc property
  6058. * @name visible
  6059. * @propertyOf ui.grid.class:GridOptions.columnDef
  6060. * @description sets whether or not the column is visible
  6061. * </br>Default is true
  6062. * @example
  6063. * <pre> $scope.gridOptions.columnDefs = [
  6064. * { field: 'field1', visible: true},
  6065. * { field: 'field2', visible: false }
  6066. * ]; </pre>
  6067. *
  6068. */
  6069. /**
  6070. * @ngdoc property
  6071. * @name sort
  6072. * @propertyOf ui.grid.class:GridOptions.columnDef
  6073. * @description An object of sort information, attributes are:
  6074. *
  6075. * - direction: values are {@link ui.grid.service:uiGridConstants#properties_ASC uiGridConstants.ASC}
  6076. * or {@link ui.grid.service:uiGridConstants#properties_DESC uiGridConstants.DESC}
  6077. * - ignoreSort: if set to true this sort is ignored (used by tree to manipulate the sort functionality)
  6078. * - priority: says what order to sort the columns in (lower priority gets sorted first).
  6079. * @example
  6080. * <pre>
  6081. * $scope.gridOptions.columnDefs = [{
  6082. * field: 'field1',
  6083. * sort: {
  6084. * direction: uiGridConstants.ASC,
  6085. * ignoreSort: true,
  6086. * priority: 0
  6087. * }
  6088. * }];
  6089. * </pre>
  6090. */
  6091. /**
  6092. * @ngdoc property
  6093. * @name sortingAlgorithm
  6094. * @propertyOf ui.grid.class:GridOptions.columnDef
  6095. * @description Algorithm to use for sorting this column. Takes 'a' and 'b' parameters
  6096. * like any normal sorting function with additional 'rowA', 'rowB', and 'direction' parameters
  6097. * that are the row objects and the current direction of the sort respectively.
  6098. *
  6099. */
  6100. /**
  6101. * @ngdoc property
  6102. * @name defaultSort
  6103. * @propertyOf ui.grid.class:GridOptions.columnDef
  6104. * @description An object of sort information, provides a hidden default ordering of the data
  6105. * when no user sorts are applied, or when a user-provided sort deems two rows to be equal.
  6106. *
  6107. * May be combined with a regular {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort}
  6108. * to explicitly sort by that column by default.
  6109. *
  6110. * Shares the same object format as {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort}.
  6111. *
  6112. * Note that a defaultSort can never take priority over an explicit sort.
  6113. * @example
  6114. * <pre>
  6115. * $scope.gridOptions.columnDefs = [{
  6116. * field: 'field1',
  6117. * defaultSort: {
  6118. * direction: uiGridConstants.ASC,
  6119. * priority: 0
  6120. * }
  6121. * }];
  6122. * </pre>
  6123. */
  6124. /**
  6125. * @ngdoc array
  6126. * @name filters
  6127. * @propertyOf ui.grid.class:GridOptions.columnDef
  6128. * @description Specify multiple filter fields.
  6129. * @example
  6130. * <pre>$scope.gridOptions.columnDefs = [
  6131. * {
  6132. * field: 'field1', filters: [
  6133. * {
  6134. * term: 'aa',
  6135. * condition: uiGridConstants.filter.STARTS_WITH,
  6136. * placeholder: 'starts with...',
  6137. * ariaLabel: 'Filter for field1',
  6138. * flags: { caseSensitive: false },
  6139. * type: uiGridConstants.filter.SELECT,
  6140. * selectOptions: [ { value: 1, label: 'male' }, { value: 2, label: 'female' } ]
  6141. * },
  6142. * {
  6143. * condition: uiGridConstants.filter.ENDS_WITH,
  6144. * placeholder: 'ends with...'
  6145. * }
  6146. * ]
  6147. * }
  6148. * ]; </pre>
  6149. *
  6150. *
  6151. */
  6152. /**
  6153. * @ngdoc array
  6154. * @name filters
  6155. * @propertyOf ui.grid.class:GridColumn
  6156. * @description Filters for this column. Includes 'term' property bound to filter input elements.
  6157. * @example
  6158. * <pre>[
  6159. * {
  6160. * term: 'foo', // ngModel for <input>
  6161. * condition: uiGridConstants.filter.STARTS_WITH,
  6162. * placeholder: 'starts with...',
  6163. * ariaLabel: 'Filter for foo',
  6164. * flags: { caseSensitive: false },
  6165. * type: uiGridConstants.filter.SELECT,
  6166. * selectOptions: [ { value: 1, label: 'male' }, { value: 2, label: 'female' } ]
  6167. * },
  6168. * {
  6169. * term: 'baz',
  6170. * condition: uiGridConstants.filter.ENDS_WITH,
  6171. * placeholder: 'ends with...'
  6172. * }
  6173. * ] </pre>
  6174. *
  6175. *
  6176. */
  6177. /**
  6178. * @ngdoc array
  6179. * @name menuItems
  6180. * @propertyOf ui.grid.class:GridOptions.columnDef
  6181. * @description used to add menu items to a column. Refer to the tutorial on this
  6182. * functionality. A number of settings are supported:
  6183. *
  6184. * - title: controls the title that is displayed in the menu
  6185. * - icon: the icon shown alongside that title
  6186. * - action: the method to call when the menu is clicked
  6187. * - shown: a function to evaluate to determine whether or not to show the item
  6188. * - active: a function to evaluate to determine whether or not the item is currently selected
  6189. * - context: context to pass to the action function, available in this.context in your handler
  6190. * - leaveOpen: if set to true, the menu should stay open after the action, defaults to false
  6191. * @example
  6192. * <pre> $scope.gridOptions.columnDefs = [
  6193. * { field: 'field1', menuItems: [
  6194. * {
  6195. * title: 'Outer Scope Alert',
  6196. * icon: 'ui-grid-icon-info-circled',
  6197. * action: function($event) {
  6198. * this.context.blargh(); // $scope.blargh() would work too, this is just an example
  6199. * },
  6200. * shown: function() { return true; },
  6201. * active: function() { return true; },
  6202. * context: $scope
  6203. * },
  6204. * {
  6205. * title: 'Grid ID',
  6206. * action: function() {
  6207. * alert('Grid ID: ' + this.grid.id);
  6208. * }
  6209. * }
  6210. * ] }]; </pre>
  6211. *
  6212. */
  6213. /**
  6214. * @ngdoc method
  6215. * @methodOf ui.grid.class:GridColumn
  6216. * @name updateColumnDef
  6217. * @description Moves settings from the columnDef down onto the column,
  6218. * and sets properties as appropriate
  6219. * @param {ColumnDef} colDef the column def to look in for the property value
  6220. * @param {boolean} isNew whether the column is being newly created, if not
  6221. * we're updating an existing column, and some items such as the sort shouldn't
  6222. * be copied down
  6223. */
  6224. GridColumn.prototype.updateColumnDef = function(colDef, isNew) {
  6225. var self = this;
  6226. self.colDef = colDef;
  6227. if (colDef.name === undefined) {
  6228. throw new Error('colDef.name is required for column at index ' + self.grid.options.columnDefs.indexOf(colDef));
  6229. }
  6230. self.displayName = (colDef.displayName === undefined) ? gridUtil.readableColumnName(colDef.name) : colDef.displayName;
  6231. if (!angular.isNumber(self.width) || !self.hasCustomWidth || colDef.allowCustomWidthOverride) {
  6232. var colDefWidth = colDef.width;
  6233. var parseErrorMsg = "Cannot parse column width '" + colDefWidth + "' for column named '" + colDef.name + "'";
  6234. self.hasCustomWidth = false;
  6235. if (!angular.isString(colDefWidth) && !angular.isNumber(colDefWidth)) {
  6236. self.width = '*';
  6237. } else if (angular.isString(colDefWidth)) {
  6238. // See if it ends with a percent
  6239. if (gridUtil.endsWith(colDefWidth, '%')) {
  6240. // If so we should be able to parse the non-percent-sign part to a number
  6241. var percentStr = colDefWidth.replace(/%/g, '');
  6242. var percent = parseInt(percentStr, 10);
  6243. if (isNaN(percent)) {
  6244. throw new Error(parseErrorMsg);
  6245. }
  6246. self.width = colDefWidth;
  6247. }
  6248. // And see if it's a number string
  6249. else if (colDefWidth.match(/^(\d+)$/)) {
  6250. self.width = parseInt(colDefWidth.match(/^(\d+)$/)[1], 10);
  6251. }
  6252. // Otherwise it should be a string of asterisks
  6253. else if (colDefWidth.match(/^\*+$/)) {
  6254. self.width = colDefWidth;
  6255. }
  6256. // No idea, throw an Error
  6257. else {
  6258. throw new Error(parseErrorMsg);
  6259. }
  6260. }
  6261. // Is a number, use it as the width
  6262. else {
  6263. self.width = colDefWidth;
  6264. }
  6265. }
  6266. function isValidWidthValue(value) {
  6267. return angular.isString(value) || angular.isNumber(value);
  6268. }
  6269. ['minWidth', 'maxWidth'].forEach(function (name) {
  6270. var minOrMaxWidth = colDef[name];
  6271. var parseErrorMsg = "Cannot parse column " + name + " '" + minOrMaxWidth + "' for column named '" + colDef.name + "'";
  6272. // default minWidth to the minimumColumnSize
  6273. if (name === 'minWidth' && !isValidWidthValue(minOrMaxWidth) && angular.isDefined(self.grid.options.minimumColumnSize)) {
  6274. minOrMaxWidth = self.grid.options.minimumColumnSize;
  6275. }
  6276. if (!isValidWidthValue(minOrMaxWidth)) {
  6277. // Sets default minWidth and maxWidth values
  6278. self[name] = ((name === 'minWidth') ? 30 : 9000);
  6279. } else if (angular.isString(minOrMaxWidth)) {
  6280. if (minOrMaxWidth.match(/^(\d+)$/)) {
  6281. self[name] = parseInt(minOrMaxWidth.match(/^(\d+)$/)[1], 10);
  6282. } else {
  6283. throw new Error(parseErrorMsg);
  6284. }
  6285. } else {
  6286. self[name] = minOrMaxWidth;
  6287. }
  6288. });
  6289. //use field if it is defined; name if it is not
  6290. self.field = (colDef.field === undefined) ? colDef.name : colDef.field;
  6291. if ( typeof( self.field ) !== 'string' ){
  6292. gridUtil.logError( 'Field is not a string, this is likely to break the code, Field is: ' + self.field );
  6293. }
  6294. self.name = colDef.name;
  6295. // Use colDef.displayName as long as it's not undefined, otherwise default to the field name
  6296. self.displayName = (colDef.displayName === undefined) ? gridUtil.readableColumnName(colDef.name) : colDef.displayName;
  6297. //self.originalIndex = index;
  6298. self.aggregationType = angular.isDefined(colDef.aggregationType) ? colDef.aggregationType : null;
  6299. self.footerCellTemplate = angular.isDefined(colDef.footerCellTemplate) ? colDef.footerCellTemplate : null;
  6300. /**
  6301. * @ngdoc property
  6302. * @name cellTooltip
  6303. * @propertyOf ui.grid.class:GridOptions.columnDef
  6304. * @description Whether or not to show a tooltip when a user hovers over the cell.
  6305. * If set to false, no tooltip. If true, the cell value is shown in the tooltip (useful
  6306. * if you have long values in your cells), if a function then that function is called
  6307. * passing in the row and the col `cellTooltip( row, col )`, and the return value is shown in the tooltip,
  6308. * if it is a static string then displays that static string.
  6309. *
  6310. * Defaults to false
  6311. *
  6312. */
  6313. if ( typeof(colDef.cellTooltip) === 'undefined' || colDef.cellTooltip === false ) {
  6314. self.cellTooltip = false;
  6315. } else if ( colDef.cellTooltip === true ){
  6316. self.cellTooltip = function(row, col) {
  6317. return self.grid.getCellValue( row, col );
  6318. };
  6319. } else if (typeof(colDef.cellTooltip) === 'function' ){
  6320. self.cellTooltip = colDef.cellTooltip;
  6321. } else {
  6322. self.cellTooltip = function ( row, col ){
  6323. return col.colDef.cellTooltip;
  6324. };
  6325. }
  6326. /**
  6327. * @ngdoc property
  6328. * @name headerTooltip
  6329. * @propertyOf ui.grid.class:GridOptions.columnDef
  6330. * @description Whether or not to show a tooltip when a user hovers over the header cell.
  6331. * If set to false, no tooltip. If true, the displayName is shown in the tooltip (useful
  6332. * if you have long values in your headers), if a function then that function is called
  6333. * passing in the row and the col `headerTooltip( col )`, and the return value is shown in the tooltip,
  6334. * if a static string then shows that static string.
  6335. *
  6336. * Defaults to false
  6337. *
  6338. */
  6339. if ( typeof(colDef.headerTooltip) === 'undefined' || colDef.headerTooltip === false ) {
  6340. self.headerTooltip = false;
  6341. } else if ( colDef.headerTooltip === true ){
  6342. self.headerTooltip = function(col) {
  6343. return col.displayName;
  6344. };
  6345. } else if (typeof(colDef.headerTooltip) === 'function' ){
  6346. self.headerTooltip = colDef.headerTooltip;
  6347. } else {
  6348. self.headerTooltip = function ( col ) {
  6349. return col.colDef.headerTooltip;
  6350. };
  6351. }
  6352. /**
  6353. * @ngdoc property
  6354. * @name footerCellClass
  6355. * @propertyOf ui.grid.class:GridOptions.columnDef
  6356. * @description footerCellClass can be a string specifying the class to append to a cell
  6357. * or it can be a function(grid, row, col, rowRenderIndex, colRenderIndex) that returns a class name
  6358. *
  6359. */
  6360. self.footerCellClass = colDef.footerCellClass;
  6361. /**
  6362. * @ngdoc property
  6363. * @name cellClass
  6364. * @propertyOf ui.grid.class:GridOptions.columnDef
  6365. * @description cellClass can be a string specifying the class to append to a cell
  6366. * or it can be a function(grid, row, col, rowRenderIndex, colRenderIndex) that returns a class name
  6367. *
  6368. */
  6369. self.cellClass = colDef.cellClass;
  6370. /**
  6371. * @ngdoc property
  6372. * @name headerCellClass
  6373. * @propertyOf ui.grid.class:GridOptions.columnDef
  6374. * @description headerCellClass can be a string specifying the class to append to a cell
  6375. * or it can be a function(grid, row, col, rowRenderIndex, colRenderIndex) that returns a class name
  6376. *
  6377. */
  6378. self.headerCellClass = colDef.headerCellClass;
  6379. /**
  6380. * @ngdoc property
  6381. * @name cellFilter
  6382. * @propertyOf ui.grid.class:GridOptions.columnDef
  6383. * @description cellFilter is a filter to apply to the content of each cell
  6384. * @example
  6385. * <pre>
  6386. * gridOptions.columnDefs[0].cellFilter = 'date'
  6387. *
  6388. */
  6389. self.cellFilter = colDef.cellFilter ? colDef.cellFilter : "";
  6390. /**
  6391. * @ngdoc boolean
  6392. * @name sortCellFiltered
  6393. * @propertyOf ui.grid.class:GridOptions.columnDef
  6394. * @description (optional) False by default. When `true` uiGrid will apply the cellFilter before
  6395. * sorting the data. Note that when using this option uiGrid will assume that the displayed value is
  6396. * a string, and use the {@link ui.grid.class:RowSorter#sortAlpha sortAlpha} `sortFn`. It is possible
  6397. * 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}
  6398. * for the column which hanldes the returned type. You may specify one of the `sortingAlgorithms`
  6399. * found in the {@link ui.grid.RowSorter rowSorter} service.
  6400. */
  6401. self.sortCellFiltered = colDef.sortCellFiltered ? true : false;
  6402. /**
  6403. * @ngdoc boolean
  6404. * @name filterCellFiltered
  6405. * @propertyOf ui.grid.class:GridOptions.columnDef
  6406. * @description (optional) False by default. When `true` uiGrid will apply the cellFilter before
  6407. * applying "search" `filters`.
  6408. */
  6409. self.filterCellFiltered = colDef.filterCellFiltered ? true : false;
  6410. /**
  6411. * @ngdoc property
  6412. * @name headerCellFilter
  6413. * @propertyOf ui.grid.class:GridOptions.columnDef
  6414. * @description headerCellFilter is a filter to apply to the content of the column header
  6415. * @example
  6416. * <pre>
  6417. * gridOptions.columnDefs[0].headerCellFilter = 'translate'
  6418. *
  6419. */
  6420. self.headerCellFilter = colDef.headerCellFilter ? colDef.headerCellFilter : "";
  6421. /**
  6422. * @ngdoc property
  6423. * @name footerCellFilter
  6424. * @propertyOf ui.grid.class:GridOptions.columnDef
  6425. * @description footerCellFilter is a filter to apply to the content of the column footer
  6426. * @example
  6427. * <pre>
  6428. * gridOptions.columnDefs[0].footerCellFilter = 'date'
  6429. *
  6430. */
  6431. self.footerCellFilter = colDef.footerCellFilter ? colDef.footerCellFilter : "";
  6432. self.visible = gridUtil.isNullOrUndefined(colDef.visible) || colDef.visible;
  6433. self.headerClass = colDef.headerClass;
  6434. //self.cursor = self.sortable ? 'pointer' : 'default';
  6435. // Turn on sorting by default
  6436. self.enableSorting = typeof(colDef.enableSorting) !== 'undefined' ? colDef.enableSorting : self.grid.options.enableSorting;
  6437. self.sortingAlgorithm = colDef.sortingAlgorithm;
  6438. /**
  6439. * @ngdoc property
  6440. * @name sortDirectionCycle
  6441. * @propertyOf ui.grid.class:GridOptions.columnDef
  6442. * @description (optional) An array of {@link ui.grid.service:uiGridConstants#properties_ASC sort directions},
  6443. * specifying the order that they should cycle through as the user repeatedly clicks on the column heading.
  6444. * The default is `[null, uiGridConstants.ASC, uiGridConstants.DESC]`. Null
  6445. * refers to the unsorted state. This does not affect the initial sort
  6446. * direction; use the {@link ui.grid.class:GridOptions.columnDef#sort sort}
  6447. * property for that. If
  6448. * {@link ui.grid.class:GridOptions.columnDef#suppressRemoveSort suppressRemoveSort}
  6449. * is also set, the unsorted state will be skipped even if it is listed here.
  6450. * Each direction may not appear in the list more than once (e.g. `[ASC,
  6451. * DESC, DESC]` is not allowed), and the list may not be empty.
  6452. */
  6453. self.sortDirectionCycle = typeof(colDef.sortDirectionCycle) !== 'undefined' ?
  6454. colDef.sortDirectionCycle :
  6455. [null, uiGridConstants.ASC, uiGridConstants.DESC];
  6456. /**
  6457. * @ngdoc boolean
  6458. * @name suppressRemoveSort
  6459. * @propertyOf ui.grid.class:GridOptions.columnDef
  6460. * @description (optional) False by default. When enabled, this setting hides the removeSort option
  6461. * in the menu, and prevents users from manually removing the sort
  6462. */
  6463. if ( typeof(self.suppressRemoveSort) === 'undefined'){
  6464. self.suppressRemoveSort = typeof(colDef.suppressRemoveSort) !== 'undefined' ? colDef.suppressRemoveSort : false;
  6465. }
  6466. /**
  6467. * @ngdoc property
  6468. * @name enableFiltering
  6469. * @propertyOf ui.grid.class:GridOptions.columnDef
  6470. * @description turn off filtering for an individual column, where
  6471. * you've turned on filtering for the overall grid
  6472. * @example
  6473. * <pre>
  6474. * gridOptions.columnDefs[0].enableFiltering = false;
  6475. *
  6476. */
  6477. // Turn on filtering by default (it's disabled by default at the Grid level)
  6478. self.enableFiltering = typeof(colDef.enableFiltering) !== 'undefined' ? colDef.enableFiltering : true;
  6479. // self.menuItems = colDef.menuItems;
  6480. self.setPropertyOrDefault(colDef, 'menuItems', []);
  6481. // Use the column definition sort if we were passed it, but only if this is a newly added column
  6482. if ( isNew ){
  6483. self.setPropertyOrDefault(colDef, 'sort');
  6484. }
  6485. // Use the column definition defaultSort always, unlike normal sort
  6486. self.setPropertyOrDefault(colDef, 'defaultSort');
  6487. // Set up default filters array for when one is not provided.
  6488. // In other words, this (in column def):
  6489. //
  6490. // filter: { term: 'something', flags: {}, condition: [CONDITION] }
  6491. //
  6492. // is just shorthand for this:
  6493. //
  6494. // filters: [{ term: 'something', flags: {}, condition: [CONDITION] }]
  6495. //
  6496. var defaultFilters = [];
  6497. if (colDef.filter) {
  6498. defaultFilters.push(colDef.filter);
  6499. }
  6500. else if ( colDef.filters ){
  6501. defaultFilters = colDef.filters;
  6502. } else {
  6503. // Add an empty filter definition object, which will
  6504. // translate to a guessed condition and no pre-populated
  6505. // value for the filter <input>.
  6506. defaultFilters.push({});
  6507. }
  6508. /**
  6509. * @ngdoc property
  6510. * @name filter
  6511. * @propertyOf ui.grid.class:GridOptions.columnDef
  6512. * @description Specify a single filter field on this column.
  6513. *
  6514. * A filter consists of a condition, a term, and a placeholder:
  6515. *
  6516. * - condition defines how rows are chosen as matching the filter term. This can be set to
  6517. * one of the constants in {@link ui.grid.service:uiGridConstants#properties_filter uiGridConstants.filter},
  6518. * or you can supply a custom filter function
  6519. * that gets passed the following arguments: [searchTerm, cellValue, row, column].
  6520. * - term: If set, the filter field will be pre-populated
  6521. * with this value.
  6522. * - placeholder: String that will be set to the `<input>.placeholder` attribute.
  6523. * - ariaLabel: String that will be set to the `<input>.ariaLabel` attribute. This is what is read as a label to screen reader users.
  6524. * - noTerm: set this to true if you have defined a custom function in condition, and
  6525. * your custom function doesn't require a term (so it can run even when the term is null)
  6526. * - rawTerm: set this to true if you have defined a custom function in condition, and
  6527. * your custom function requires access to the raw unmodified search term that was entered
  6528. * - flags: only flag currently available is `caseSensitive`, set to false if you don't want
  6529. * case sensitive matching
  6530. * - type: defaults to {@link ui.grid.service:uiGridConstants#properties_filter uiGridConstants.filter.INPUT},
  6531. * which gives a text box. If set to {@link ui.grid.service:uiGridConstants#properties_filter uiGridConstants.filter.SELECT}
  6532. * then a select box will be shown with options selectOptions
  6533. * - selectOptions: options in the format `[ { value: 1, label: 'male' }]`. No i18n filter is provided, you need
  6534. * to perform the i18n on the values before you provide them
  6535. * - disableCancelFilterButton: defaults to false. If set to true then the 'x' button that cancels/clears the filter
  6536. * will not be shown.
  6537. * @example
  6538. * <pre>$scope.gridOptions.columnDefs = [
  6539. * {
  6540. * field: 'field1',
  6541. * filter: {
  6542. * term: 'xx',
  6543. * condition: uiGridConstants.filter.STARTS_WITH,
  6544. * placeholder: 'starts with...',
  6545. * ariaLabel: 'Starts with filter for field1',
  6546. * flags: { caseSensitive: false },
  6547. * type: uiGridConstants.filter.SELECT,
  6548. * selectOptions: [ { value: 1, label: 'male' }, { value: 2, label: 'female' } ],
  6549. * disableCancelFilterButton: true
  6550. * }
  6551. * }
  6552. * ]; </pre>
  6553. *
  6554. */
  6555. /*
  6556. /*
  6557. self.filters = [
  6558. {
  6559. term: 'search term'
  6560. condition: uiGridConstants.filter.CONTAINS,
  6561. placeholder: 'my placeholder',
  6562. ariaLabel: 'Starts with filter for field1',
  6563. flags: {
  6564. caseSensitive: true
  6565. }
  6566. }
  6567. ]
  6568. */
  6569. // Only set filter if this is a newly added column, if we're updating an existing
  6570. // column then we don't want to put the default filter back if the user may have already
  6571. // removed it.
  6572. // However, we do want to keep the settings if they change, just not the term
  6573. if ( isNew ) {
  6574. self.setPropertyOrDefault(colDef, 'filter');
  6575. self.setPropertyOrDefault(colDef, 'extraStyle');
  6576. self.setPropertyOrDefault(colDef, 'filters', defaultFilters);
  6577. } else if ( self.filters.length === defaultFilters.length ) {
  6578. self.filters.forEach( function( filter, index ){
  6579. if (typeof(defaultFilters[index].placeholder) !== 'undefined') {
  6580. filter.placeholder = defaultFilters[index].placeholder;
  6581. }
  6582. if (typeof(defaultFilters[index].ariaLabel) !== 'undefined') {
  6583. filter.ariaLabel = defaultFilters[index].ariaLabel;
  6584. }
  6585. if (typeof(defaultFilters[index].flags) !== 'undefined') {
  6586. filter.flags = defaultFilters[index].flags;
  6587. }
  6588. if (typeof(defaultFilters[index].type) !== 'undefined') {
  6589. filter.type = defaultFilters[index].type;
  6590. }
  6591. if (typeof(defaultFilters[index].selectOptions) !== 'undefined') {
  6592. filter.selectOptions = defaultFilters[index].selectOptions;
  6593. }
  6594. });
  6595. }
  6596. };
  6597. /**
  6598. * @ngdoc function
  6599. * @name unsort
  6600. * @methodOf ui.grid.class:GridColumn
  6601. * @description Removes column from the grid sorting
  6602. */
  6603. GridColumn.prototype.unsort = function () {
  6604. //Decrease priority for every col where priority is higher than the removed sort's priority.
  6605. var thisPriority = this.sort.priority;
  6606. this.grid.columns.forEach(function (col) {
  6607. if (col.sort && col.sort.priority !== undefined && col.sort.priority > thisPriority) {
  6608. col.sort.priority -= 1;
  6609. }
  6610. });
  6611. this.sort = {};
  6612. this.grid.api.core.raise.sortChanged( this.grid, this.grid.getColumnSorting() );
  6613. };
  6614. /**
  6615. * @ngdoc function
  6616. * @name getColClass
  6617. * @methodOf ui.grid.class:GridColumn
  6618. * @description Returns the class name for the column
  6619. * @param {bool} prefixDot if true, will return .className instead of className
  6620. */
  6621. GridColumn.prototype.getColClass = function (prefixDot) {
  6622. var cls = uiGridConstants.COL_CLASS_PREFIX + this.uid;
  6623. return prefixDot ? '.' + cls : cls;
  6624. };
  6625. /**
  6626. * @ngdoc function
  6627. * @name isPinnedLeft
  6628. * @methodOf ui.grid.class:GridColumn
  6629. * @description Returns true if column is in the left render container
  6630. */
  6631. GridColumn.prototype.isPinnedLeft = function () {
  6632. return this.renderContainer === 'left';
  6633. };
  6634. /**
  6635. * @ngdoc function
  6636. * @name isPinnedRight
  6637. * @methodOf ui.grid.class:GridColumn
  6638. * @description Returns true if column is in the right render container
  6639. */
  6640. GridColumn.prototype.isPinnedRight = function () {
  6641. return this.renderContainer === 'right';
  6642. };
  6643. /**
  6644. * @ngdoc function
  6645. * @name getColClassDefinition
  6646. * @methodOf ui.grid.class:GridColumn
  6647. * @description Returns the class definition for th column
  6648. */
  6649. GridColumn.prototype.getColClassDefinition = function () {
  6650. return ' .grid' + this.grid.id + ' ' + this.getColClass(true) + ' { min-width: ' + this.drawnWidth + 'px; max-width: ' + this.drawnWidth + 'px; }';
  6651. };
  6652. /**
  6653. * @ngdoc function
  6654. * @name getRenderContainer
  6655. * @methodOf ui.grid.class:GridColumn
  6656. * @description Returns the render container object that this column belongs to.
  6657. *
  6658. * Columns will be default be in the `body` render container if they aren't allocated to one specifically.
  6659. */
  6660. GridColumn.prototype.getRenderContainer = function getRenderContainer() {
  6661. var self = this;
  6662. var containerId = self.renderContainer;
  6663. if (containerId === null || containerId === '' || containerId === undefined) {
  6664. containerId = 'body';
  6665. }
  6666. return self.grid.renderContainers[containerId];
  6667. };
  6668. /**
  6669. * @ngdoc function
  6670. * @name showColumn
  6671. * @methodOf ui.grid.class:GridColumn
  6672. * @description Makes the column visible by setting colDef.visible = true
  6673. */
  6674. GridColumn.prototype.showColumn = function() {
  6675. this.colDef.visible = true;
  6676. };
  6677. /**
  6678. * @ngdoc property
  6679. * @name aggregationHideLabel
  6680. * @propertyOf ui.grid.class:GridOptions.columnDef
  6681. * @description defaults to false, if set to true hides the label text
  6682. * in the aggregation footer, so only the value is displayed.
  6683. *
  6684. */
  6685. /**
  6686. * @ngdoc function
  6687. * @name getAggregationText
  6688. * @methodOf ui.grid.class:GridColumn
  6689. * @description Gets the aggregation label from colDef.aggregationLabel if
  6690. * specified or by using i18n, including deciding whether or not to display
  6691. * based on colDef.aggregationHideLabel.
  6692. *
  6693. * @param {string} label the i18n lookup value to use for the column label
  6694. *
  6695. */
  6696. GridColumn.prototype.getAggregationText = function () {
  6697. var self = this;
  6698. if ( self.colDef.aggregationHideLabel ){
  6699. return '';
  6700. }
  6701. else if ( self.colDef.aggregationLabel ) {
  6702. return self.colDef.aggregationLabel;
  6703. }
  6704. else {
  6705. switch ( self.colDef.aggregationType ){
  6706. case uiGridConstants.aggregationTypes.count:
  6707. return i18nService.getSafeText('aggregation.count');
  6708. case uiGridConstants.aggregationTypes.sum:
  6709. return i18nService.getSafeText('aggregation.sum');
  6710. case uiGridConstants.aggregationTypes.avg:
  6711. return i18nService.getSafeText('aggregation.avg');
  6712. case uiGridConstants.aggregationTypes.min:
  6713. return i18nService.getSafeText('aggregation.min');
  6714. case uiGridConstants.aggregationTypes.max:
  6715. return i18nService.getSafeText('aggregation.max');
  6716. default:
  6717. return '';
  6718. }
  6719. }
  6720. };
  6721. GridColumn.prototype.getCellTemplate = function () {
  6722. var self = this;
  6723. return self.cellTemplatePromise;
  6724. };
  6725. GridColumn.prototype.getCompiledElementFn = function () {
  6726. var self = this;
  6727. return self.compiledElementFnDefer.promise;
  6728. };
  6729. return GridColumn;
  6730. }]);
  6731. })();
  6732. (function(){
  6733. angular.module('ui.grid')
  6734. .factory('GridOptions', ['gridUtil','uiGridConstants', function(gridUtil,uiGridConstants) {
  6735. /**
  6736. * @ngdoc function
  6737. * @name ui.grid.class:GridOptions
  6738. * @description Default GridOptions class. GridOptions are defined by the application developer and overlaid
  6739. * over this object. Setting gridOptions within your controller is the most common method for an application
  6740. * developer to configure the behaviour of their ui-grid
  6741. *
  6742. * @example To define your gridOptions within your controller:
  6743. * <pre>$scope.gridOptions = {
  6744. * data: $scope.myData,
  6745. * columnDefs: [
  6746. * { name: 'field1', displayName: 'pretty display name' },
  6747. * { name: 'field2', visible: false }
  6748. * ]
  6749. * };</pre>
  6750. *
  6751. * You can then use this within your html template, when you define your grid:
  6752. * <pre>&lt;div ui-grid="gridOptions"&gt;&lt;/div&gt;</pre>
  6753. *
  6754. * To provide default options for all of the grids within your application, use an angular
  6755. * decorator to modify the GridOptions factory.
  6756. * <pre>
  6757. * app.config(function($provide){
  6758. * $provide.decorator('GridOptions',function($delegate){
  6759. * var gridOptions;
  6760. * gridOptions = angular.copy($delegate);
  6761. * gridOptions.initialize = function(options) {
  6762. * var initOptions;
  6763. * initOptions = $delegate.initialize(options);
  6764. * initOptions.enableColumnMenus = false;
  6765. * return initOptions;
  6766. * };
  6767. * return gridOptions;
  6768. * });
  6769. * });
  6770. * </pre>
  6771. */
  6772. return {
  6773. initialize: function( baseOptions ){
  6774. /**
  6775. * @ngdoc function
  6776. * @name onRegisterApi
  6777. * @propertyOf ui.grid.class:GridOptions
  6778. * @description A callback that returns the gridApi once the grid is instantiated, which is
  6779. * then used to interact with the grid programatically.
  6780. *
  6781. * Note that the gridApi.core.renderingComplete event is identical to this
  6782. * callback, but has the advantage that it can be called from multiple places
  6783. * if needed
  6784. *
  6785. * @example
  6786. * <pre>
  6787. * $scope.gridOptions.onRegisterApi = function ( gridApi ) {
  6788. * $scope.gridApi = gridApi;
  6789. * $scope.gridApi.selection.selectAllRows( $scope.gridApi.grid );
  6790. * };
  6791. * </pre>
  6792. *
  6793. */
  6794. baseOptions.onRegisterApi = baseOptions.onRegisterApi || angular.noop();
  6795. /**
  6796. * @ngdoc object
  6797. * @name data
  6798. * @propertyOf ui.grid.class:GridOptions
  6799. * @description (mandatory) Array of data to be rendered into the grid, providing the data source or data binding for
  6800. * the grid.
  6801. *
  6802. * Most commonly the data is an array of objects, where each object has a number of attributes.
  6803. * Each attribute automatically becomes a column in your grid. This array could, for example, be sourced from
  6804. * an angularJS $resource query request. The array can also contain complex objects, refer the binding tutorial
  6805. * for examples of that.
  6806. *
  6807. * The most flexible usage is to set your data on $scope:
  6808. *
  6809. * `$scope.data = data;`
  6810. *
  6811. * And then direct the grid to resolve whatever is in $scope.data:
  6812. *
  6813. * `$scope.gridOptions.data = 'data';`
  6814. *
  6815. * This is the most flexible approach as it allows you to replace $scope.data whenever you feel like it without
  6816. * getting pointer issues.
  6817. *
  6818. * Alternatively you can directly set the data array:
  6819. *
  6820. * `$scope.gridOptions.data = [ ];`
  6821. * or
  6822. *
  6823. * `$http.get('/data/100.json')
  6824. * .success(function(data) {
  6825. * $scope.myData = data;
  6826. * $scope.gridOptions.data = $scope.myData;
  6827. * });`
  6828. *
  6829. * Where you do this, you need to take care in updating the data - you can't just update `$scope.myData` to some other
  6830. * array, you need to update $scope.gridOptions.data to point to that new array as well.
  6831. *
  6832. */
  6833. baseOptions.data = baseOptions.data || [];
  6834. /**
  6835. * @ngdoc array
  6836. * @name columnDefs
  6837. * @propertyOf ui.grid.class:GridOptions
  6838. * @description Array of columnDef objects. Only required property is name.
  6839. * The individual options available in columnDefs are documented in the
  6840. * {@link ui.grid.class:GridOptions.columnDef columnDef} section
  6841. * </br>_field property can be used in place of name for backwards compatibility with 2.x_
  6842. * @example
  6843. *
  6844. * <pre>var columnDefs = [{name:'field1'}, {name:'field2'}];</pre>
  6845. *
  6846. */
  6847. baseOptions.columnDefs = baseOptions.columnDefs || [];
  6848. /**
  6849. * @ngdoc object
  6850. * @name ui.grid.class:GridOptions.columnDef
  6851. * @description Definition / configuration of an individual column, which would typically be
  6852. * one of many column definitions within the gridOptions.columnDefs array
  6853. * @example
  6854. * <pre>{name:'field1', field: 'field1', filter: { term: 'xxx' }}</pre>
  6855. *
  6856. */
  6857. /**
  6858. * @ngdoc object
  6859. * @name enableGridMenu
  6860. * @propertyOf ui.grid.class:GridOptions
  6861. * @description Takes a boolean that adds a settings icon in the top right of the grid, which floats above
  6862. * the column header, when true. The menu by default gives access to show/hide columns, but can be
  6863. * customised to show additional actions.
  6864. *
  6865. * See the {@link #!/tutorial/121_grid_menu Grid Menu tutorial} for more detailed information.
  6866. */
  6867. /**
  6868. * @ngdoc array
  6869. * @name excludeProperties
  6870. * @propertyOf ui.grid.class:GridOptions
  6871. * @description Array of property names in data to ignore when auto-generating column names. Provides the
  6872. * inverse of columnDefs - columnDefs is a list of columns to include, excludeProperties is a list of columns
  6873. * to exclude.
  6874. *
  6875. * If columnDefs is defined, this will be ignored.
  6876. *
  6877. * Defaults to ['$$hashKey']
  6878. */
  6879. baseOptions.excludeProperties = baseOptions.excludeProperties || ['$$hashKey'];
  6880. /**
  6881. * @ngdoc boolean
  6882. * @name enableRowHashing
  6883. * @propertyOf ui.grid.class:GridOptions
  6884. * @description True by default. When enabled, this setting allows uiGrid to add
  6885. * `$$hashKey`-type properties (similar to Angular) to elements in the `data` array. This allows
  6886. * the grid to maintain state while vastly speeding up the process of altering `data` by adding/moving/removing rows.
  6887. *
  6888. * Note that this DOES add properties to your data that you may not want, but they are stripped out when using `angular.toJson()`. IF
  6889. * 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
  6890. * and are altering the data set often.
  6891. */
  6892. baseOptions.enableRowHashing = baseOptions.enableRowHashing !== false;
  6893. /**
  6894. * @ngdoc function
  6895. * @name rowIdentity
  6896. * @methodOf ui.grid.class:GridOptions
  6897. * @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).
  6898. *
  6899. * By default it returns the `$$hashKey` property if it exists. If it doesn't it uses gridUtil.nextUid() to generate one
  6900. */
  6901. baseOptions.rowIdentity = baseOptions.rowIdentity || function rowIdentity(row) {
  6902. return gridUtil.hashKey(row);
  6903. };
  6904. /**
  6905. * @ngdoc function
  6906. * @name getRowIdentity
  6907. * @methodOf ui.grid.class:GridOptions
  6908. * @description This function returns the identity value uniquely identifying this row, if one is not present it does not set it.
  6909. *
  6910. * By default it returns the `$$hashKey` property but can be overridden to use any property or set of properties you want.
  6911. */
  6912. baseOptions.getRowIdentity = baseOptions.getRowIdentity || function getRowIdentity(row) {
  6913. return row.$$hashKey;
  6914. };
  6915. /**
  6916. * @ngdoc property
  6917. * @name flatEntityAccess
  6918. * @propertyOf ui.grid.class:GridOptions
  6919. * @description Set to true if your columns are all related directly to fields in a flat object structure - i.e.
  6920. * each of your columns associate directly with a property on each of the entities in your data array.
  6921. *
  6922. * In that situation we can avoid all the logic associated with complex binding to functions or to properties of sub-objects,
  6923. * which can provide a significant speed improvement with large data sets when filtering or sorting.
  6924. *
  6925. * By default false
  6926. */
  6927. baseOptions.flatEntityAccess = baseOptions.flatEntityAccess === true;
  6928. /**
  6929. * @ngdoc property
  6930. * @name showHeader
  6931. * @propertyOf ui.grid.class:GridOptions
  6932. * @description True by default. When set to false, this setting will replace the
  6933. * standard header template with '<div></div>', resulting in no header being shown.
  6934. */
  6935. baseOptions.showHeader = typeof(baseOptions.showHeader) !== "undefined" ? baseOptions.showHeader : true;
  6936. /* (NOTE): Don't show this in the docs. We only use it internally
  6937. * @ngdoc property
  6938. * @name headerRowHeight
  6939. * @propertyOf ui.grid.class:GridOptions
  6940. * @description The height of the header in pixels, defaults to 30
  6941. *
  6942. */
  6943. if (!baseOptions.showHeader) {
  6944. baseOptions.headerRowHeight = 0;
  6945. }
  6946. else {
  6947. baseOptions.headerRowHeight = typeof(baseOptions.headerRowHeight) !== "undefined" ? baseOptions.headerRowHeight : 30;
  6948. }
  6949. /**
  6950. * @ngdoc property
  6951. * @name rowHeight
  6952. * @propertyOf ui.grid.class:GridOptions
  6953. * @description The height of the row in pixels, Can be passed as integer or string. defaults to 30.
  6954. *
  6955. */
  6956. if (typeof baseOptions.rowHeight === "string") {
  6957. baseOptions.rowHeight = parseInt(baseOptions.rowHeight) || 30;
  6958. }
  6959. else {
  6960. baseOptions.rowHeight = baseOptions.rowHeight || 30;
  6961. }
  6962. /**
  6963. * @ngdoc integer
  6964. * @name minRowsToShow
  6965. * @propertyOf ui.grid.class:GridOptions
  6966. * @description Minimum number of rows to show when the grid doesn't have a defined height. Defaults to "10".
  6967. */
  6968. baseOptions.minRowsToShow = typeof(baseOptions.minRowsToShow) !== "undefined" ? baseOptions.minRowsToShow : 10;
  6969. /**
  6970. * @ngdoc property
  6971. * @name showGridFooter
  6972. * @propertyOf ui.grid.class:GridOptions
  6973. * @description Whether or not to show the footer, defaults to false
  6974. * The footer display Total Rows and Visible Rows (filtered rows)
  6975. */
  6976. baseOptions.showGridFooter = baseOptions.showGridFooter === true;
  6977. /**
  6978. * @ngdoc property
  6979. * @name showColumnFooter
  6980. * @propertyOf ui.grid.class:GridOptions
  6981. * @description Whether or not to show the column footer, defaults to false
  6982. * The column footer displays column aggregates
  6983. */
  6984. baseOptions.showColumnFooter = baseOptions.showColumnFooter === true;
  6985. /**
  6986. * @ngdoc property
  6987. * @name columnFooterHeight
  6988. * @propertyOf ui.grid.class:GridOptions
  6989. * @description The height of the footer rows (column footer and grid footer) in pixels
  6990. *
  6991. */
  6992. baseOptions.columnFooterHeight = typeof(baseOptions.columnFooterHeight) !== "undefined" ? baseOptions.columnFooterHeight : 30;
  6993. baseOptions.gridFooterHeight = typeof(baseOptions.gridFooterHeight) !== "undefined" ? baseOptions.gridFooterHeight : 30;
  6994. baseOptions.columnWidth = typeof(baseOptions.columnWidth) !== "undefined" ? baseOptions.columnWidth : 50;
  6995. /**
  6996. * @ngdoc property
  6997. * @name maxVisibleColumnCount
  6998. * @propertyOf ui.grid.class:GridOptions
  6999. * @description Defaults to 200
  7000. *
  7001. */
  7002. baseOptions.maxVisibleColumnCount = typeof(baseOptions.maxVisibleColumnCount) !== "undefined" ? baseOptions.maxVisibleColumnCount : 200;
  7003. /**
  7004. * @ngdoc property
  7005. * @name virtualizationThreshold
  7006. * @propertyOf ui.grid.class:GridOptions
  7007. * @description Turn virtualization on when number of data elements goes over this number, defaults to 20
  7008. */
  7009. baseOptions.virtualizationThreshold = typeof(baseOptions.virtualizationThreshold) !== "undefined" ? baseOptions.virtualizationThreshold : 20;
  7010. /**
  7011. * @ngdoc property
  7012. * @name columnVirtualizationThreshold
  7013. * @propertyOf ui.grid.class:GridOptions
  7014. * @description Turn virtualization on when number of columns goes over this number, defaults to 10
  7015. */
  7016. baseOptions.columnVirtualizationThreshold = typeof(baseOptions.columnVirtualizationThreshold) !== "undefined" ? baseOptions.columnVirtualizationThreshold : 10;
  7017. /**
  7018. * @ngdoc property
  7019. * @name excessRows
  7020. * @propertyOf ui.grid.class:GridOptions
  7021. * @description Extra rows to to render outside of the viewport, which helps with smoothness of scrolling.
  7022. * Defaults to 4
  7023. */
  7024. baseOptions.excessRows = typeof(baseOptions.excessRows) !== "undefined" ? baseOptions.excessRows : 4;
  7025. /**
  7026. * @ngdoc property
  7027. * @name scrollThreshold
  7028. * @propertyOf ui.grid.class:GridOptions
  7029. * @description Defaults to 4
  7030. */
  7031. baseOptions.scrollThreshold = typeof(baseOptions.scrollThreshold) !== "undefined" ? baseOptions.scrollThreshold : 4;
  7032. /**
  7033. * @ngdoc property
  7034. * @name excessColumns
  7035. * @propertyOf ui.grid.class:GridOptions
  7036. * @description Extra columns to to render outside of the viewport, which helps with smoothness of scrolling.
  7037. * Defaults to 4
  7038. */
  7039. baseOptions.excessColumns = typeof(baseOptions.excessColumns) !== "undefined" ? baseOptions.excessColumns : 4;
  7040. /**
  7041. * @ngdoc property
  7042. * @name horizontalScrollThreshold
  7043. * @propertyOf ui.grid.class:GridOptions
  7044. * @description Defaults to 4
  7045. */
  7046. baseOptions.horizontalScrollThreshold = typeof(baseOptions.horizontalScrollThreshold) !== "undefined" ? baseOptions.horizontalScrollThreshold : 2;
  7047. /**
  7048. * @ngdoc property
  7049. * @name aggregationCalcThrottle
  7050. * @propertyOf ui.grid.class:GridOptions
  7051. * @description Default time in milliseconds to throttle aggregation calcuations, defaults to 500ms
  7052. */
  7053. baseOptions.aggregationCalcThrottle = typeof(baseOptions.aggregationCalcThrottle) !== "undefined" ? baseOptions.aggregationCalcThrottle : 500;
  7054. /**
  7055. * @ngdoc property
  7056. * @name wheelScrollThrottle
  7057. * @propertyOf ui.grid.class:GridOptions
  7058. * @description Default time in milliseconds to throttle scroll events to, defaults to 70ms
  7059. */
  7060. baseOptions.wheelScrollThrottle = typeof(baseOptions.wheelScrollThrottle) !== "undefined" ? baseOptions.wheelScrollThrottle : 70;
  7061. /**
  7062. * @ngdoc property
  7063. * @name scrollDebounce
  7064. * @propertyOf ui.grid.class:GridOptions
  7065. * @description Default time in milliseconds to debounce scroll events, defaults to 300ms
  7066. */
  7067. baseOptions.scrollDebounce = typeof(baseOptions.scrollDebounce) !== "undefined" ? baseOptions.scrollDebounce : 300;
  7068. /**
  7069. * @ngdoc boolean
  7070. * @name enableSorting
  7071. * @propertyOf ui.grid.class:GridOptions
  7072. * @description True by default. When enabled, this setting adds sort
  7073. * widgets to the column headers, allowing sorting of the data for the entire grid.
  7074. * Sorting can then be disabled / enabled on individual columns using the columnDefs,
  7075. * if it set, it will override GridOptions enableSorting setting.
  7076. */
  7077. baseOptions.enableSorting = baseOptions.enableSorting !== false;
  7078. /**
  7079. * @ngdoc boolean
  7080. * @name enableFiltering
  7081. * @propertyOf ui.grid.class:GridOptions
  7082. * @description False by default. When enabled, this setting adds filter
  7083. * boxes to each column header, allowing filtering within the column for the entire grid.
  7084. * Filtering can then be disabled on individual columns using the columnDefs.
  7085. */
  7086. baseOptions.enableFiltering = baseOptions.enableFiltering === true;
  7087. /**
  7088. * @ngdoc boolean
  7089. * @name enableColumnMenus
  7090. * @propertyOf ui.grid.class:GridOptions
  7091. * @description True by default. When enabled, this setting displays a column
  7092. * menu within each column.
  7093. * By default column menu's trigger is hidden before mouse over, but you can always force it to be visible with CSS:
  7094. *
  7095. * <pre>
  7096. * .ui-grid-column-menu-button {
  7097. * display: block;
  7098. * }
  7099. * </pre>
  7100. */
  7101. baseOptions.enableColumnMenus = baseOptions.enableColumnMenus !== false;
  7102. /**
  7103. * @ngdoc boolean
  7104. * @name enableVerticalScrollbar
  7105. * @propertyOf ui.grid.class:GridOptions
  7106. * @description {@link ui.grid.service:uiGridConstants#properties_scrollbars uiGridConstants.scrollbars.ALWAYS} by default.
  7107. * This settings controls the vertical scrollbar for the grid.
  7108. * Supported values: uiGridConstants.scrollbars.ALWAYS, uiGridConstants.scrollbars.NEVER, uiGridConstants.scrollbars.WHEN_NEEDED
  7109. */
  7110. baseOptions.enableVerticalScrollbar = typeof(baseOptions.enableVerticalScrollbar) !== "undefined" ? baseOptions.enableVerticalScrollbar : uiGridConstants.scrollbars.ALWAYS;
  7111. /**
  7112. * @ngdoc boolean
  7113. * @name enableHorizontalScrollbar
  7114. * @propertyOf ui.grid.class:GridOptions
  7115. * @description {@link ui.grid.service:uiGridConstants#properties_scrollbars uiGridConstants.scrollbars.ALWAYS} by default.
  7116. * This settings controls the horizontal scrollbar for the grid.
  7117. * Supported values: uiGridConstants.scrollbars.ALWAYS, uiGridConstants.scrollbars.NEVER, uiGridConstants.scrollbars.WHEN_NEEDED
  7118. */
  7119. baseOptions.enableHorizontalScrollbar = typeof(baseOptions.enableHorizontalScrollbar) !== "undefined" ? baseOptions.enableHorizontalScrollbar : uiGridConstants.scrollbars.ALWAYS;
  7120. /**
  7121. * @ngdoc boolean
  7122. * @name enableMinHeightCheck
  7123. * @propertyOf ui.grid.class:GridOptions
  7124. * @description True by default. When enabled, a newly initialized grid will check to see if it is tall enough to display
  7125. * at least one row of data. If the grid is not tall enough, it will resize the DOM element to display minRowsToShow number
  7126. * of rows.
  7127. */
  7128. baseOptions.enableMinHeightCheck = baseOptions.enableMinHeightCheck !== false;
  7129. /**
  7130. * @ngdoc boolean
  7131. * @name minimumColumnSize
  7132. * @propertyOf ui.grid.class:GridOptions
  7133. * @description Sets the default minimum column width, in other words,
  7134. * it defines the default value for a column minWidth attribute if that is not otherwise specified.
  7135. * Should be a number. Defaults to 30 pixels.
  7136. */
  7137. baseOptions.minimumColumnSize = typeof(baseOptions.minimumColumnSize) !== "undefined" ? baseOptions.minimumColumnSize : 30;
  7138. /**
  7139. * @ngdoc function
  7140. * @name rowEquality
  7141. * @methodOf ui.grid.class:GridOptions
  7142. * @description By default, rows are compared using object equality. This option can be overridden
  7143. * to compare on any data item property or function
  7144. * @param {object} entityA First Data Item to compare
  7145. * @param {object} entityB Second Data Item to compare
  7146. */
  7147. baseOptions.rowEquality = baseOptions.rowEquality || function(entityA, entityB) {
  7148. return entityA === entityB;
  7149. };
  7150. /**
  7151. * @ngdoc string
  7152. * @name headerTemplate
  7153. * @propertyOf ui.grid.class:GridOptions
  7154. * @description Null by default. When provided, this setting uses a custom header
  7155. * template, rather than the default template. Can be set to either the name of a template file:
  7156. * <pre> $scope.gridOptions.headerTemplate = 'header_template.html';</pre>
  7157. * inline html
  7158. * <pre> $scope.gridOptions.headerTemplate = '<div class="ui-grid-top-panel" style="text-align: center">I am a Custom Grid Header</div>'</pre>
  7159. * or the id of a precompiled template (TBD how to use this).
  7160. * </br>Refer to the custom header tutorial for more information.
  7161. * If you want no header at all, you can set to an empty div:
  7162. * <pre> $scope.gridOptions.headerTemplate = '<div></div>';</pre>
  7163. *
  7164. * If you want to only have a static header, then you can set to static content. If
  7165. * you want to tailor the existing column headers, then you should look at the
  7166. * current 'ui-grid-header.html' template in github as your starting point.
  7167. *
  7168. */
  7169. baseOptions.headerTemplate = baseOptions.headerTemplate || null;
  7170. /**
  7171. * @ngdoc string
  7172. * @name footerTemplate
  7173. * @propertyOf ui.grid.class:GridOptions
  7174. * @description (optional) ui-grid/ui-grid-footer by default. This footer shows the per-column
  7175. * aggregation totals.
  7176. * 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
  7177. * <pre>'<div class="ui-grid-bottom-panel" style="text-align: center">I am a Custom Grid Footer</div>'</pre>, or the id
  7178. * of a precompiled template (TBD how to use this). Refer to the custom footer tutorial for more information.
  7179. */
  7180. baseOptions.footerTemplate = baseOptions.footerTemplate || 'ui-grid/ui-grid-footer';
  7181. /**
  7182. * @ngdoc string
  7183. * @name gridFooterTemplate
  7184. * @propertyOf ui.grid.class:GridOptions
  7185. * @description (optional) ui-grid/ui-grid-grid-footer by default. This template by default shows the
  7186. * total items at the bottom of the grid, and the selected items if selection is enabled.
  7187. */
  7188. baseOptions.gridFooterTemplate = baseOptions.gridFooterTemplate || 'ui-grid/ui-grid-grid-footer';
  7189. /**
  7190. * @ngdoc string
  7191. * @name rowTemplate
  7192. * @propertyOf ui.grid.class:GridOptions
  7193. * @description 'ui-grid/ui-grid-row' by default. When provided, this setting uses a
  7194. * custom row template. Can be set to either the name of a template file:
  7195. * <pre> $scope.gridOptions.rowTemplate = 'row_template.html';</pre>
  7196. * inline html
  7197. * <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>
  7198. * or the id of a precompiled template (TBD how to use this) can be provided.
  7199. * </br>Refer to the custom row template tutorial for more information.
  7200. */
  7201. baseOptions.rowTemplate = baseOptions.rowTemplate || 'ui-grid/ui-grid-row';
  7202. /**
  7203. * @ngdoc string
  7204. * @name gridMenuTemplate
  7205. * @propertyOf ui.grid.class:GridOptions
  7206. * @description 'ui-grid/uiGridMenu' by default. When provided, this setting uses a
  7207. * custom grid menu template.
  7208. */
  7209. baseOptions.gridMenuTemplate = baseOptions.gridMenuTemplate || 'ui-grid/uiGridMenu';
  7210. /**
  7211. * @ngdoc object
  7212. * @name appScopeProvider
  7213. * @propertyOf ui.grid.class:GridOptions
  7214. * @description by default, the parent scope of the ui-grid element will be assigned to grid.appScope
  7215. * this property allows you to assign any reference you want to grid.appScope
  7216. */
  7217. baseOptions.appScopeProvider = baseOptions.appScopeProvider || null;
  7218. return baseOptions;
  7219. }
  7220. };
  7221. }]);
  7222. })();
  7223. (function(){
  7224. angular.module('ui.grid')
  7225. /**
  7226. * @ngdoc function
  7227. * @name ui.grid.class:GridRenderContainer
  7228. * @description The grid has render containers, allowing the ability to have pinned columns. If the grid
  7229. * is right-to-left then there may be a right render container, if left-to-right then there may
  7230. * be a left render container. There is always a body render container.
  7231. * @param {string} name The name of the render container ('body', 'left', or 'right')
  7232. * @param {Grid} grid the grid the render container is in
  7233. * @param {object} options the render container options
  7234. */
  7235. .factory('GridRenderContainer', ['gridUtil', 'uiGridConstants', function(gridUtil, uiGridConstants) {
  7236. function GridRenderContainer(name, grid, options) {
  7237. var self = this;
  7238. // if (gridUtil.type(grid) !== 'Grid') {
  7239. // throw new Error('Grid argument is not a Grid object');
  7240. // }
  7241. self.name = name;
  7242. self.grid = grid;
  7243. // self.rowCache = [];
  7244. // self.columnCache = [];
  7245. self.visibleRowCache = [];
  7246. self.visibleColumnCache = [];
  7247. self.renderedRows = [];
  7248. self.renderedColumns = [];
  7249. self.prevScrollTop = 0;
  7250. self.prevScrolltopPercentage = 0;
  7251. self.prevRowScrollIndex = 0;
  7252. self.prevScrollLeft = 0;
  7253. self.prevScrollleftPercentage = 0;
  7254. self.prevColumnScrollIndex = 0;
  7255. self.columnStyles = '';
  7256. self.viewportAdjusters = [];
  7257. /**
  7258. * @ngdoc boolean
  7259. * @name hasHScrollbar
  7260. * @propertyOf ui.grid.class:GridRenderContainer
  7261. * @description flag to signal that container has a horizontal scrollbar
  7262. */
  7263. self.hasHScrollbar = false;
  7264. /**
  7265. * @ngdoc boolean
  7266. * @name hasVScrollbar
  7267. * @propertyOf ui.grid.class:GridRenderContainer
  7268. * @description flag to signal that container has a vertical scrollbar
  7269. */
  7270. self.hasVScrollbar = false;
  7271. /**
  7272. * @ngdoc boolean
  7273. * @name canvasHeightShouldUpdate
  7274. * @propertyOf ui.grid.class:GridRenderContainer
  7275. * @description flag to signal that container should recalculate the canvas size
  7276. */
  7277. self.canvasHeightShouldUpdate = true;
  7278. /**
  7279. * @ngdoc boolean
  7280. * @name canvasHeight
  7281. * @propertyOf ui.grid.class:GridRenderContainer
  7282. * @description last calculated canvas height value
  7283. */
  7284. self.$$canvasHeight = 0;
  7285. if (options && angular.isObject(options)) {
  7286. angular.extend(self, options);
  7287. }
  7288. grid.registerStyleComputation({
  7289. priority: 5,
  7290. func: function () {
  7291. self.updateColumnWidths();
  7292. return self.columnStyles;
  7293. }
  7294. });
  7295. }
  7296. GridRenderContainer.prototype.reset = function reset() {
  7297. // this.rowCache.length = 0;
  7298. // this.columnCache.length = 0;
  7299. this.visibleColumnCache.length = 0;
  7300. this.visibleRowCache.length = 0;
  7301. this.renderedRows.length = 0;
  7302. this.renderedColumns.length = 0;
  7303. };
  7304. // TODO(c0bra): calculate size?? Should this be in a stackable directive?
  7305. GridRenderContainer.prototype.containsColumn = function (col) {
  7306. return this.visibleColumnCache.indexOf(col) !== -1;
  7307. };
  7308. GridRenderContainer.prototype.minRowsToRender = function minRowsToRender() {
  7309. var self = this;
  7310. var minRows = 0;
  7311. var rowAddedHeight = 0;
  7312. var viewPortHeight = self.getViewportHeight();
  7313. for (var i = self.visibleRowCache.length - 1; rowAddedHeight < viewPortHeight && i >= 0; i--) {
  7314. rowAddedHeight += self.visibleRowCache[i].height;
  7315. minRows++;
  7316. }
  7317. return minRows;
  7318. };
  7319. GridRenderContainer.prototype.minColumnsToRender = function minColumnsToRender() {
  7320. var self = this;
  7321. var viewportWidth = this.getViewportWidth();
  7322. var min = 0;
  7323. var totalWidth = 0;
  7324. for (var i = 0; i < self.visibleColumnCache.length; i++) {
  7325. var col = self.visibleColumnCache[i];
  7326. if (totalWidth < viewportWidth) {
  7327. totalWidth += col.drawnWidth ? col.drawnWidth : 0;
  7328. min++;
  7329. }
  7330. else {
  7331. var currWidth = 0;
  7332. for (var j = i; j >= i - min; j--) {
  7333. currWidth += self.visibleColumnCache[j].drawnWidth ? self.visibleColumnCache[j].drawnWidth : 0;
  7334. }
  7335. if (currWidth < viewportWidth) {
  7336. min++;
  7337. }
  7338. }
  7339. }
  7340. return min;
  7341. };
  7342. GridRenderContainer.prototype.getVisibleRowCount = function getVisibleRowCount() {
  7343. return this.visibleRowCache.length;
  7344. };
  7345. /**
  7346. * @ngdoc function
  7347. * @name registerViewportAdjuster
  7348. * @methodOf ui.grid.class:GridRenderContainer
  7349. * @description Registers an adjuster to the render container's available width or height. Adjusters are used
  7350. * to tell the render container that there is something else consuming space, and to adjust it's size
  7351. * appropriately.
  7352. * @param {function} func the adjuster function we want to register
  7353. */
  7354. GridRenderContainer.prototype.registerViewportAdjuster = function registerViewportAdjuster(func) {
  7355. this.viewportAdjusters.push(func);
  7356. };
  7357. /**
  7358. * @ngdoc function
  7359. * @name removeViewportAdjuster
  7360. * @methodOf ui.grid.class:GridRenderContainer
  7361. * @description Removes an adjuster, should be used when your element is destroyed
  7362. * @param {function} func the adjuster function we want to remove
  7363. */
  7364. GridRenderContainer.prototype.removeViewportAdjuster = function removeViewportAdjuster(func) {
  7365. var idx = this.viewportAdjusters.indexOf(func);
  7366. if (idx > -1) {
  7367. this.viewportAdjusters.splice(idx, 1);
  7368. }
  7369. };
  7370. /**
  7371. * @ngdoc function
  7372. * @name getViewportAdjustment
  7373. * @methodOf ui.grid.class:GridRenderContainer
  7374. * @description Gets the adjustment based on the viewportAdjusters.
  7375. * @returns {object} a hash of { height: x, width: y }. Usually the values will be negative
  7376. */
  7377. GridRenderContainer.prototype.getViewportAdjustment = function getViewportAdjustment() {
  7378. var self = this;
  7379. var adjustment = { height: 0, width: 0 };
  7380. self.viewportAdjusters.forEach(function (func) {
  7381. adjustment = func.call(this, adjustment);
  7382. });
  7383. return adjustment;
  7384. };
  7385. GridRenderContainer.prototype.getMargin = function getMargin(side) {
  7386. var self = this;
  7387. var amount = 0;
  7388. self.viewportAdjusters.forEach(function (func) {
  7389. var adjustment = func.call(this, { height: 0, width: 0 });
  7390. if (adjustment.side && adjustment.side === side) {
  7391. amount += adjustment.width * -1;
  7392. }
  7393. });
  7394. return amount;
  7395. };
  7396. GridRenderContainer.prototype.getViewportHeight = function getViewportHeight() {
  7397. var self = this;
  7398. var headerHeight = (self.headerHeight) ? self.headerHeight : self.grid.headerHeight;
  7399. var viewPortHeight = self.grid.gridHeight - headerHeight - self.grid.footerHeight;
  7400. var adjustment = self.getViewportAdjustment();
  7401. viewPortHeight = viewPortHeight + adjustment.height;
  7402. return viewPortHeight;
  7403. };
  7404. GridRenderContainer.prototype.getViewportWidth = function getViewportWidth() {
  7405. var self = this;
  7406. var viewportWidth = self.grid.gridWidth;
  7407. //if (typeof(self.grid.verticalScrollbarWidth) !== 'undefined' && self.grid.verticalScrollbarWidth !== undefined && self.grid.verticalScrollbarWidth > 0) {
  7408. // viewPortWidth = viewPortWidth - self.grid.verticalScrollbarWidth;
  7409. //}
  7410. // var viewportWidth = 0;\
  7411. // self.visibleColumnCache.forEach(function (column) {
  7412. // viewportWidth += column.drawnWidth;
  7413. // });
  7414. var adjustment = self.getViewportAdjustment();
  7415. viewportWidth = viewportWidth + adjustment.width;
  7416. return viewportWidth;
  7417. };
  7418. GridRenderContainer.prototype.getHeaderViewportWidth = function getHeaderViewportWidth() {
  7419. var self = this;
  7420. var viewportWidth = this.getViewportWidth();
  7421. //if (typeof(self.grid.verticalScrollbarWidth) !== 'undefined' && self.grid.verticalScrollbarWidth !== undefined && self.grid.verticalScrollbarWidth > 0) {
  7422. // viewPortWidth = viewPortWidth + self.grid.verticalScrollbarWidth;
  7423. //}
  7424. // var adjustment = self.getViewportAdjustment();
  7425. // viewPortWidth = viewPortWidth + adjustment.width;
  7426. return viewportWidth;
  7427. };
  7428. /**
  7429. * @ngdoc function
  7430. * @name getCanvasHeight
  7431. * @methodOf ui.grid.class:GridRenderContainer
  7432. * @description Returns the total canvas height. Only recalculates if canvasHeightShouldUpdate = false
  7433. * @returns {number} total height of all the visible rows in the container
  7434. */
  7435. GridRenderContainer.prototype.getCanvasHeight = function getCanvasHeight() {
  7436. var self = this;
  7437. if (!self.canvasHeightShouldUpdate) {
  7438. return self.$$canvasHeight;
  7439. }
  7440. var oldCanvasHeight = self.$$canvasHeight;
  7441. self.$$canvasHeight = 0;
  7442. self.visibleRowCache.forEach(function(row){
  7443. self.$$canvasHeight += row.height;
  7444. });
  7445. self.canvasHeightShouldUpdate = false;
  7446. self.grid.api.core.raise.canvasHeightChanged(oldCanvasHeight, self.$$canvasHeight);
  7447. return self.$$canvasHeight;
  7448. };
  7449. GridRenderContainer.prototype.getVerticalScrollLength = function getVerticalScrollLength() {
  7450. return this.getCanvasHeight() - this.getViewportHeight() + this.grid.scrollbarHeight !== 0 ? this.getCanvasHeight() - this.getViewportHeight() + this.grid.scrollbarHeight : -1;
  7451. };
  7452. GridRenderContainer.prototype.getHorizontalScrollLength = function getHorizontalScrollLength() {
  7453. return this.getCanvasWidth() - this.getViewportWidth() + this.grid.scrollbarWidth !== 0 ? this.getCanvasWidth() - this.getViewportWidth() + this.grid.scrollbarWidth : -1;
  7454. };
  7455. GridRenderContainer.prototype.getCanvasWidth = function getCanvasWidth() {
  7456. var self = this;
  7457. return self.canvasWidth;
  7458. };
  7459. GridRenderContainer.prototype.setRenderedRows = function setRenderedRows(newRows) {
  7460. this.renderedRows.length = newRows.length;
  7461. for (var i = 0; i < newRows.length; i++) {
  7462. this.renderedRows[i] = newRows[i];
  7463. }
  7464. };
  7465. GridRenderContainer.prototype.setRenderedColumns = function setRenderedColumns(newColumns) {
  7466. var self = this;
  7467. // OLD:
  7468. this.renderedColumns.length = newColumns.length;
  7469. for (var i = 0; i < newColumns.length; i++) {
  7470. this.renderedColumns[i] = newColumns[i];
  7471. }
  7472. this.updateColumnOffset();
  7473. };
  7474. GridRenderContainer.prototype.updateColumnOffset = function updateColumnOffset() {
  7475. // Calculate the width of the columns on the left side that are no longer rendered.
  7476. // That will be the offset for the columns as we scroll horizontally.
  7477. var hiddenColumnsWidth = 0;
  7478. for (var i = 0; i < this.currentFirstColumn; i++) {
  7479. hiddenColumnsWidth += this.visibleColumnCache[i].drawnWidth;
  7480. }
  7481. this.columnOffset = hiddenColumnsWidth;
  7482. };
  7483. GridRenderContainer.prototype.scrollVertical = function (newScrollTop) {
  7484. var vertScrollPercentage = -1;
  7485. if (newScrollTop !== this.prevScrollTop) {
  7486. var yDiff = newScrollTop - this.prevScrollTop;
  7487. if (yDiff > 0 ) { this.grid.scrollDirection = uiGridConstants.scrollDirection.DOWN; }
  7488. if (yDiff < 0 ) { this.grid.scrollDirection = uiGridConstants.scrollDirection.UP; }
  7489. var vertScrollLength = this.getVerticalScrollLength();
  7490. vertScrollPercentage = newScrollTop / vertScrollLength;
  7491. // console.log('vert', vertScrollPercentage, newScrollTop, vertScrollLength);
  7492. if (vertScrollPercentage > 1) { vertScrollPercentage = 1; }
  7493. if (vertScrollPercentage < 0) { vertScrollPercentage = 0; }
  7494. this.adjustScrollVertical(newScrollTop, vertScrollPercentage);
  7495. return vertScrollPercentage;
  7496. }
  7497. };
  7498. GridRenderContainer.prototype.scrollHorizontal = function(newScrollLeft){
  7499. var horizScrollPercentage = -1;
  7500. // Handle RTL here
  7501. if (newScrollLeft !== this.prevScrollLeft) {
  7502. var xDiff = newScrollLeft - this.prevScrollLeft;
  7503. if (xDiff > 0) { this.grid.scrollDirection = uiGridConstants.scrollDirection.RIGHT; }
  7504. if (xDiff < 0) { this.grid.scrollDirection = uiGridConstants.scrollDirection.LEFT; }
  7505. var horizScrollLength = this.getHorizontalScrollLength();
  7506. if (horizScrollLength !== 0) {
  7507. horizScrollPercentage = newScrollLeft / horizScrollLength;
  7508. }
  7509. else {
  7510. horizScrollPercentage = 0;
  7511. }
  7512. this.adjustScrollHorizontal(newScrollLeft, horizScrollPercentage);
  7513. return horizScrollPercentage;
  7514. }
  7515. };
  7516. GridRenderContainer.prototype.adjustScrollVertical = function adjustScrollVertical(scrollTop, scrollPercentage, force) {
  7517. if (this.prevScrollTop === scrollTop && !force) {
  7518. return;
  7519. }
  7520. if (typeof(scrollTop) === 'undefined' || scrollTop === undefined || scrollTop === null) {
  7521. scrollTop = (this.getCanvasHeight() - this.getViewportHeight()) * scrollPercentage;
  7522. }
  7523. this.adjustRows(scrollTop, scrollPercentage, false);
  7524. this.prevScrollTop = scrollTop;
  7525. this.prevScrolltopPercentage = scrollPercentage;
  7526. this.grid.queueRefresh();
  7527. };
  7528. GridRenderContainer.prototype.adjustScrollHorizontal = function adjustScrollHorizontal(scrollLeft, scrollPercentage, force) {
  7529. if (this.prevScrollLeft === scrollLeft && !force) {
  7530. return;
  7531. }
  7532. if (typeof(scrollLeft) === 'undefined' || scrollLeft === undefined || scrollLeft === null) {
  7533. scrollLeft = (this.getCanvasWidth() - this.getViewportWidth()) * scrollPercentage;
  7534. }
  7535. this.adjustColumns(scrollLeft, scrollPercentage);
  7536. this.prevScrollLeft = scrollLeft;
  7537. this.prevScrollleftPercentage = scrollPercentage;
  7538. this.grid.queueRefresh();
  7539. };
  7540. GridRenderContainer.prototype.adjustRows = function adjustRows(scrollTop, scrollPercentage, postDataLoaded) {
  7541. var self = this;
  7542. var minRows = self.minRowsToRender();
  7543. var rowCache = self.visibleRowCache;
  7544. var maxRowIndex = rowCache.length - minRows;
  7545. // console.log('scroll%1', scrollPercentage);
  7546. // Calculate the scroll percentage according to the scrollTop location, if no percentage was provided
  7547. if ((typeof(scrollPercentage) === 'undefined' || scrollPercentage === null) && scrollTop) {
  7548. scrollPercentage = scrollTop / self.getVerticalScrollLength();
  7549. }
  7550. var rowIndex = Math.ceil(Math.min(maxRowIndex, maxRowIndex * scrollPercentage));
  7551. // console.log('maxRowIndex / scroll%', maxRowIndex, scrollPercentage, rowIndex);
  7552. // Define a max row index that we can't scroll past
  7553. if (rowIndex > maxRowIndex) {
  7554. rowIndex = maxRowIndex;
  7555. }
  7556. var newRange = [];
  7557. if (rowCache.length > self.grid.options.virtualizationThreshold) {
  7558. if (!(typeof(scrollTop) === 'undefined' || scrollTop === null)) {
  7559. // Have we hit the threshold going down?
  7560. if ( !self.grid.suppressParentScrollDown && self.prevScrollTop < scrollTop && rowIndex < self.prevRowScrollIndex + self.grid.options.scrollThreshold && rowIndex < maxRowIndex) {
  7561. return;
  7562. }
  7563. //Have we hit the threshold going up?
  7564. if ( !self.grid.suppressParentScrollUp && self.prevScrollTop > scrollTop && rowIndex > self.prevRowScrollIndex - self.grid.options.scrollThreshold && rowIndex < maxRowIndex) {
  7565. return;
  7566. }
  7567. }
  7568. var rangeStart = Math.max(0, rowIndex - self.grid.options.excessRows);
  7569. var rangeEnd = Math.min(rowCache.length, rowIndex + minRows + self.grid.options.excessRows);
  7570. newRange = [rangeStart, rangeEnd];
  7571. }
  7572. else {
  7573. var maxLen = self.visibleRowCache.length;
  7574. newRange = [0, Math.max(maxLen, minRows + self.grid.options.excessRows)];
  7575. }
  7576. self.updateViewableRowRange(newRange);
  7577. self.prevRowScrollIndex = rowIndex;
  7578. };
  7579. GridRenderContainer.prototype.adjustColumns = function adjustColumns(scrollLeft, scrollPercentage) {
  7580. var self = this;
  7581. var minCols = self.minColumnsToRender();
  7582. var columnCache = self.visibleColumnCache;
  7583. var maxColumnIndex = columnCache.length - minCols;
  7584. // Calculate the scroll percentage according to the scrollLeft location, if no percentage was provided
  7585. if ((typeof(scrollPercentage) === 'undefined' || scrollPercentage === null) && scrollLeft) {
  7586. scrollPercentage = scrollLeft / self.getHorizontalScrollLength();
  7587. }
  7588. var colIndex = Math.ceil(Math.min(maxColumnIndex, maxColumnIndex * scrollPercentage));
  7589. // Define a max row index that we can't scroll past
  7590. if (colIndex > maxColumnIndex) {
  7591. colIndex = maxColumnIndex;
  7592. }
  7593. var newRange = [];
  7594. if (columnCache.length > self.grid.options.columnVirtualizationThreshold && self.getCanvasWidth() > self.getViewportWidth()) {
  7595. /* Commented the following lines because otherwise the moved column wasn't visible immediately on the new position
  7596. * in the case of many columns with horizontal scroll, one had to scroll left or right and then return in order to see it
  7597. // Have we hit the threshold going down?
  7598. if (self.prevScrollLeft < scrollLeft && colIndex < self.prevColumnScrollIndex + self.grid.options.horizontalScrollThreshold && colIndex < maxColumnIndex) {
  7599. return;
  7600. }
  7601. //Have we hit the threshold going up?
  7602. if (self.prevScrollLeft > scrollLeft && colIndex > self.prevColumnScrollIndex - self.grid.options.horizontalScrollThreshold && colIndex < maxColumnIndex) {
  7603. return;
  7604. }*/
  7605. var rangeStart = Math.max(0, colIndex - self.grid.options.excessColumns);
  7606. var rangeEnd = Math.min(columnCache.length, colIndex + minCols + self.grid.options.excessColumns);
  7607. newRange = [rangeStart, rangeEnd];
  7608. }
  7609. else {
  7610. var maxLen = self.visibleColumnCache.length;
  7611. newRange = [0, Math.max(maxLen, minCols + self.grid.options.excessColumns)];
  7612. }
  7613. self.updateViewableColumnRange(newRange);
  7614. self.prevColumnScrollIndex = colIndex;
  7615. };
  7616. // Method for updating the visible rows
  7617. GridRenderContainer.prototype.updateViewableRowRange = function updateViewableRowRange(renderedRange) {
  7618. // Slice out the range of rows from the data
  7619. // var rowArr = uiGridCtrl.grid.rows.slice(renderedRange[0], renderedRange[1]);
  7620. var rowArr = this.visibleRowCache.slice(renderedRange[0], renderedRange[1]);
  7621. // Define the top-most rendered row
  7622. this.currentTopRow = renderedRange[0];
  7623. this.setRenderedRows(rowArr);
  7624. };
  7625. // Method for updating the visible columns
  7626. GridRenderContainer.prototype.updateViewableColumnRange = function updateViewableColumnRange(renderedRange) {
  7627. // Slice out the range of rows from the data
  7628. // var columnArr = uiGridCtrl.grid.columns.slice(renderedRange[0], renderedRange[1]);
  7629. var columnArr = this.visibleColumnCache.slice(renderedRange[0], renderedRange[1]);
  7630. // Define the left-most rendered columns
  7631. this.currentFirstColumn = renderedRange[0];
  7632. this.setRenderedColumns(columnArr);
  7633. };
  7634. GridRenderContainer.prototype.headerCellWrapperStyle = function () {
  7635. var self = this;
  7636. if (self.currentFirstColumn !== 0) {
  7637. var offset = self.columnOffset;
  7638. if (self.grid.isRTL()) {
  7639. return { 'margin-right': offset + 'px' };
  7640. }
  7641. else {
  7642. return { 'margin-left': offset + 'px' };
  7643. }
  7644. }
  7645. return null;
  7646. };
  7647. /**
  7648. * @ngdoc boolean
  7649. * @name updateColumnWidths
  7650. * @propertyOf ui.grid.class:GridRenderContainer
  7651. * @description Determine the appropriate column width of each column across all render containers.
  7652. *
  7653. * Column width is easy when each column has a specified width. When columns are variable width (i.e.
  7654. * have an * or % of the viewport) then we try to calculate so that things fit in. The problem is that
  7655. * we have multiple render containers, and we don't want one render container to just take the whole viewport
  7656. * when it doesn't need to - we want things to balance out across the render containers.
  7657. *
  7658. * To do this, we use this method to calculate all the renderContainers, recognising that in a given render
  7659. * cycle it'll get called once per render container, so it needs to return the same values each time.
  7660. *
  7661. * The constraints on this method are therefore:
  7662. * - must return the same value when called multiple times, to do this it needs to rely on properties of the
  7663. * columns, but not properties that change when this is called (so it shouldn't rely on drawnWidth)
  7664. *
  7665. * The general logic of this method is:
  7666. * - calculate our total available width
  7667. * - look at all the columns across all render containers, and work out which have widths and which have
  7668. * constraints such as % or * or something else
  7669. * - for those with *, count the total number of * we see and add it onto a running total, add this column to an * array
  7670. * - for those with a %, allocate the % as a percentage of the viewport, having consideration of min and max
  7671. * - for those with manual width (in pixels) we set the drawnWidth to the specified width
  7672. * - we end up with an asterisks array still to process
  7673. * - we look at our remaining width. If it's greater than zero, we divide it up among the asterisk columns, then process
  7674. * them for min and max width constraints
  7675. * - if it's zero or less, we set the asterisk columns to their minimum widths
  7676. * - we use parseInt quite a bit, as we try to make all our column widths integers
  7677. */
  7678. GridRenderContainer.prototype.updateColumnWidths = function () {
  7679. var self = this;
  7680. var asterisksArray = [],
  7681. asteriskNum = 0,
  7682. usedWidthSum = 0,
  7683. ret = '',
  7684. pinRightColumn = false,
  7685. fixedNumberArray = [],
  7686. percentageArray = [],
  7687. totalPercentage = 0;
  7688. // Get the width of the viewport
  7689. var availableWidth = self.grid.getViewportWidth() - self.grid.scrollbarWidth;
  7690. // get all the columns across all render containers, we have to calculate them all or one render container
  7691. // could consume the whole viewport
  7692. var columnCache = [];
  7693. angular.forEach(self.grid.renderContainers, function (container) {
  7694. columnCache = columnCache.concat(container.visibleColumnCache);
  7695. });
  7696. // look at each column, process any manual values or %, put the * into an array to look at later
  7697. columnCache.forEach(function (column) {
  7698. var width = 0;
  7699. // Skip hidden columns
  7700. if (!column.visible) { return; }
  7701. if (pinRightColumn) {
  7702. availableWidth += self.grid.scrollbarWidth;
  7703. }
  7704. if (!pinRightColumn && column.colDef.pinnedRight) {
  7705. pinRightColumn = true;
  7706. }
  7707. if (angular.isNumber(column.width)) {
  7708. // pixel width, set to this value
  7709. width = parseInt(column.width, 10);
  7710. usedWidthSum = usedWidthSum + width;
  7711. column.drawnWidth = width;
  7712. fixedNumberArray.push(column);
  7713. } else if (gridUtil.endsWith(column.width, '%')) {
  7714. // percentage width, set to percentage of the viewport
  7715. // round down to int - some browsers don't play nice with float maxWidth
  7716. var percentageIntegerValue = parseInt(column.width.replace(/%/g, ''), 10);
  7717. width = parseInt(percentageIntegerValue / 100 * availableWidth);
  7718. if (width > column.maxWidth) {
  7719. width = column.maxWidth;
  7720. }
  7721. if (width < column.minWidth) {
  7722. width = column.minWidth;
  7723. }
  7724. usedWidthSum = usedWidthSum + width;
  7725. column.drawnWidth = width;
  7726. totalPercentage = totalPercentage + percentageIntegerValue;
  7727. percentageArray.push(column);
  7728. } else if (angular.isString(column.width) && column.width.indexOf('*') !== -1) {
  7729. // is an asterisk column, the gridColumn already checked the string consists only of '****'
  7730. asteriskNum = asteriskNum + column.width.length;
  7731. asterisksArray.push(column);
  7732. }
  7733. });
  7734. // Get the remaining width (available width subtracted by the used widths sum)
  7735. var remainingWidth = availableWidth - usedWidthSum;
  7736. if (asterisksArray.length > 0) {
  7737. // the width that each asterisk value would be assigned (this can be negative)
  7738. var asteriskVal = remainingWidth / asteriskNum;
  7739. asterisksArray.forEach(function (column) {
  7740. var width = parseInt(column.width.length * asteriskVal, 10);
  7741. if (width > column.maxWidth) {
  7742. width = column.maxWidth;
  7743. }
  7744. if (width < column.minWidth) {
  7745. width = column.minWidth;
  7746. }
  7747. usedWidthSum = usedWidthSum + width;
  7748. column.drawnWidth = width;
  7749. });
  7750. }
  7751. // If there are no columns with asterisk widths then check if there are any with % widths and
  7752. // use them as a fallback for adjusting column widths up or down if we have remaining grid width
  7753. // or need to claw some width back
  7754. var variableWidthColumnArray;
  7755. if (asterisksArray.length > 0) {
  7756. variableWidthColumnArray = asterisksArray;
  7757. } else if (percentageArray.length > 0 && fixedNumberArray.length === 0 && totalPercentage === 100) {
  7758. variableWidthColumnArray = percentageArray;
  7759. }
  7760. if (!angular.isUndefined(variableWidthColumnArray)) {
  7761. // If the grid width didn't divide evenly into the column widths and we have pixels left over, or our
  7762. // calculated widths would have the grid narrower than the available space,
  7763. // dole the remainder out one by one to make everything fit
  7764. var processColumnUpwards = function (column) {
  7765. if (column.drawnWidth < column.maxWidth && leftoverWidth > 0) {
  7766. column.drawnWidth++;
  7767. usedWidthSum++;
  7768. leftoverWidth--;
  7769. columnsToChange = true;
  7770. }
  7771. };
  7772. var leftoverWidth = availableWidth - usedWidthSum;
  7773. var columnsToChange = true;
  7774. while (leftoverWidth > 0 && columnsToChange) {
  7775. columnsToChange = false;
  7776. variableWidthColumnArray.forEach(processColumnUpwards);
  7777. }
  7778. // We can end up with too much width even though some columns aren't at their max width, in this situation
  7779. // we can trim the columns a little
  7780. var processColumnDownwards = function (column) {
  7781. if (column.drawnWidth > column.minWidth && excessWidth > 0) {
  7782. column.drawnWidth--;
  7783. usedWidthSum--;
  7784. excessWidth--;
  7785. columnsToChange = true;
  7786. }
  7787. };
  7788. var excessWidth = usedWidthSum - availableWidth;
  7789. columnsToChange = true;
  7790. while (excessWidth > 0 && columnsToChange) {
  7791. columnsToChange = false;
  7792. variableWidthColumnArray.forEach(processColumnDownwards);
  7793. }
  7794. }
  7795. // all that was across all the renderContainers, now we need to work out what that calculation decided for
  7796. // our renderContainer
  7797. var canvasWidth = 0;
  7798. self.visibleColumnCache.forEach(function(column){
  7799. if ( column.visible ){
  7800. canvasWidth = canvasWidth + column.drawnWidth;
  7801. }
  7802. });
  7803. // Build the CSS
  7804. columnCache.forEach(function (column) {
  7805. ret = ret + column.getColClassDefinition();
  7806. });
  7807. self.canvasWidth = canvasWidth;
  7808. // Return the styles back to buildStyles which pops them into the `customStyles` scope variable
  7809. // return ret;
  7810. // Set this render container's column styles so they can be used in style computation
  7811. this.columnStyles = ret;
  7812. };
  7813. GridRenderContainer.prototype.needsHScrollbarPlaceholder = function () {
  7814. var self = this,
  7815. containerBody;
  7816. if (self.name === 'left' || self.name === 'right' && !this.hasHScrollbar && !this.grid.disableScrolling) {
  7817. if (self.grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.ALWAYS) {
  7818. return true;
  7819. }
  7820. containerBody = this.grid.element[0].querySelector('.ui-grid-render-container-body .ui-grid-viewport');
  7821. return containerBody.scrollWidth > containerBody.offsetWidth;
  7822. }
  7823. return false;
  7824. };
  7825. GridRenderContainer.prototype.getViewportStyle = function () {
  7826. var self = this;
  7827. var styles = {};
  7828. var scrollbarVisibility = {};
  7829. scrollbarVisibility[uiGridConstants.scrollbars.ALWAYS] = 'scroll';
  7830. scrollbarVisibility[uiGridConstants.scrollbars.WHEN_NEEDED] = 'auto';
  7831. self.hasHScrollbar = false;
  7832. self.hasVScrollbar = false;
  7833. if (self.grid.disableScrolling) {
  7834. styles['overflow-x'] = 'hidden';
  7835. styles['overflow-y'] = 'hidden';
  7836. return styles;
  7837. }
  7838. if (self.name === 'body') {
  7839. self.hasHScrollbar = self.grid.options.enableHorizontalScrollbar !== uiGridConstants.scrollbars.NEVER;
  7840. if (!self.grid.isRTL()) {
  7841. if (!self.grid.hasRightContainerColumns()) {
  7842. self.hasVScrollbar = self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER;
  7843. }
  7844. }
  7845. else {
  7846. if (!self.grid.hasLeftContainerColumns()) {
  7847. self.hasVScrollbar = self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER;
  7848. }
  7849. }
  7850. }
  7851. else if (self.name === 'left') {
  7852. self.hasVScrollbar = self.grid.isRTL() ? self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER : false;
  7853. }
  7854. else {
  7855. self.hasVScrollbar = !self.grid.isRTL() ? self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER : false;
  7856. }
  7857. styles['overflow-x'] = self.hasHScrollbar ? scrollbarVisibility[self.grid.options.enableHorizontalScrollbar] : 'hidden';
  7858. styles['overflow-y'] = self.hasVScrollbar ? scrollbarVisibility[self.grid.options.enableVerticalScrollbar] : 'hidden';
  7859. return styles;
  7860. };
  7861. return GridRenderContainer;
  7862. }]);
  7863. })();
  7864. (function(){
  7865. angular.module('ui.grid')
  7866. .factory('GridRow', ['gridUtil', 'uiGridConstants', function(gridUtil, uiGridConstants) {
  7867. /**
  7868. * @class GridRow
  7869. * @ngdoc function
  7870. * @name ui.grid.class:GridRow
  7871. * @description GridRow is the viewModel for one logical row on the grid. A grid Row is not necessarily a one-to-one
  7872. * relation to gridOptions.data.
  7873. * @param {object} entity the array item from GridOptions.data
  7874. * @param {number} index the current position of the row in the array
  7875. * @param {Grid} grid reference to the parent grid
  7876. */
  7877. function GridRow(entity, index, grid) {
  7878. /**
  7879. * @ngdoc object
  7880. * @name grid
  7881. * @propertyOf ui.grid.class:GridRow
  7882. * @description A reference back to the grid
  7883. */
  7884. this.grid = grid;
  7885. /**
  7886. * @ngdoc object
  7887. * @name entity
  7888. * @propertyOf ui.grid.class:GridRow
  7889. * @description A reference to an item in gridOptions.data[]
  7890. */
  7891. this.entity = entity;
  7892. /**
  7893. * @ngdoc object
  7894. * @name uid
  7895. * @propertyOf ui.grid.class:GridRow
  7896. * @description UniqueId of row
  7897. */
  7898. this.uid = gridUtil.nextUid();
  7899. /**
  7900. * @ngdoc object
  7901. * @name visible
  7902. * @propertyOf ui.grid.class:GridRow
  7903. * @description If true, the row will be rendered
  7904. */
  7905. // Default to true
  7906. this.visible = true;
  7907. /**
  7908. * @ngdoc object
  7909. * @name isSelected
  7910. * @propertyOf ui.grid.class:GridRow
  7911. * @description Marks if the row has been selected
  7912. */
  7913. // Default to false
  7914. this.isSelected = false;
  7915. this.$$height = grid.options.rowHeight;
  7916. }
  7917. /**
  7918. * @ngdoc object
  7919. * @name height
  7920. * @propertyOf ui.grid.class:GridRow
  7921. * @description height of each individual row. changing the height will flag all
  7922. * row renderContainers to recalculate their canvas height
  7923. */
  7924. Object.defineProperty(GridRow.prototype, 'height', {
  7925. get: function() {
  7926. return this.$$height;
  7927. },
  7928. set: function(height) {
  7929. if (height !== this.$$height) {
  7930. this.grid.updateCanvasHeight();
  7931. this.$$height = height;
  7932. }
  7933. }
  7934. });
  7935. /**
  7936. * @ngdoc function
  7937. * @name getQualifiedColField
  7938. * @methodOf ui.grid.class:GridRow
  7939. * @description returns the qualified field name as it exists on scope
  7940. * ie: row.entity.fieldA
  7941. * @param {GridColumn} col column instance
  7942. * @returns {string} resulting name that can be evaluated on scope
  7943. */
  7944. GridRow.prototype.getQualifiedColField = function(col) {
  7945. return 'row.' + this.getEntityQualifiedColField(col);
  7946. };
  7947. /**
  7948. * @ngdoc function
  7949. * @name getEntityQualifiedColField
  7950. * @methodOf ui.grid.class:GridRow
  7951. * @description returns the qualified field name minus the row path
  7952. * ie: entity.fieldA
  7953. * @param {GridColumn} col column instance
  7954. * @returns {string} resulting name that can be evaluated against a row
  7955. */
  7956. GridRow.prototype.getEntityQualifiedColField = function(col) {
  7957. var base = 'entity';
  7958. if ( col.field === uiGridConstants.ENTITY_BINDING ) {
  7959. return base;
  7960. }
  7961. return gridUtil.preEval(base + '.' + col.field);
  7962. };
  7963. /**
  7964. * @ngdoc function
  7965. * @name setRowInvisible
  7966. * @methodOf ui.grid.class:GridRow
  7967. * @description Sets an override on the row that forces it to always
  7968. * be invisible. Emits the rowsVisibleChanged event if it changed the row visibility.
  7969. *
  7970. * This method can be called from the api, passing in the gridRow we want
  7971. * altered. It should really work by calling gridRow.setRowInvisible, but that's
  7972. * not the way I coded it, and too late to change now. Changed to just call
  7973. * the internal function row.setThisRowInvisible().
  7974. *
  7975. * @param {GridRow} row the row we want to set to invisible
  7976. *
  7977. */
  7978. GridRow.prototype.setRowInvisible = function ( row ) {
  7979. if (row && row.setThisRowInvisible){
  7980. row.setThisRowInvisible( 'user' );
  7981. }
  7982. };
  7983. /**
  7984. * @ngdoc function
  7985. * @name clearRowInvisible
  7986. * @methodOf ui.grid.class:GridRow
  7987. * @description Clears an override on the row that forces it to always
  7988. * be invisible. Emits the rowsVisibleChanged event if it changed the row visibility.
  7989. *
  7990. * This method can be called from the api, passing in the gridRow we want
  7991. * altered. It should really work by calling gridRow.clearRowInvisible, but that's
  7992. * not the way I coded it, and too late to change now. Changed to just call
  7993. * the internal function row.clearThisRowInvisible().
  7994. *
  7995. * @param {GridRow} row the row we want to clear the invisible flag
  7996. *
  7997. */
  7998. GridRow.prototype.clearRowInvisible = function ( row ) {
  7999. if (row && row.clearThisRowInvisible){
  8000. row.clearThisRowInvisible( 'user' );
  8001. }
  8002. };
  8003. /**
  8004. * @ngdoc function
  8005. * @name setThisRowInvisible
  8006. * @methodOf ui.grid.class:GridRow
  8007. * @description Sets an override on the row that forces it to always
  8008. * be invisible. Emits the rowsVisibleChanged event if it changed the row visibility
  8009. *
  8010. * @param {string} reason the reason (usually the module) for the row to be invisible.
  8011. * E.g. grouping, user, filter
  8012. * @param {boolean} fromRowsProcessor whether we were called from a rowsProcessor, passed through to evaluateRowVisibility
  8013. */
  8014. GridRow.prototype.setThisRowInvisible = function ( reason, fromRowsProcessor ) {
  8015. if ( !this.invisibleReason ){
  8016. this.invisibleReason = {};
  8017. }
  8018. this.invisibleReason[reason] = true;
  8019. this.evaluateRowVisibility( fromRowsProcessor);
  8020. };
  8021. /**
  8022. * @ngdoc function
  8023. * @name clearRowInvisible
  8024. * @methodOf ui.grid.class:GridRow
  8025. * @description Clears any override on the row visibility, returning it
  8026. * to normal visibility calculations. Emits the rowsVisibleChanged
  8027. * event
  8028. *
  8029. * @param {string} reason the reason (usually the module) for the row to be invisible.
  8030. * E.g. grouping, user, filter
  8031. * @param {boolean} fromRowsProcessor whether we were called from a rowsProcessor, passed through to evaluateRowVisibility
  8032. */
  8033. GridRow.prototype.clearThisRowInvisible = function ( reason, fromRowsProcessor ) {
  8034. if (typeof(this.invisibleReason) !== 'undefined' ) {
  8035. delete this.invisibleReason[reason];
  8036. }
  8037. this.evaluateRowVisibility( fromRowsProcessor );
  8038. };
  8039. /**
  8040. * @ngdoc function
  8041. * @name evaluateRowVisibility
  8042. * @methodOf ui.grid.class:GridRow
  8043. * @description Determines whether the row should be visible based on invisibleReason,
  8044. * and if it changes the row visibility, then emits the rowsVisibleChanged event.
  8045. *
  8046. * Queues a grid refresh, but doesn't call it directly to avoid hitting lots of grid refreshes.
  8047. * @param {boolean} fromRowProcessor if true, then it won't raise events or queue the refresh, the
  8048. * row processor does that already
  8049. */
  8050. GridRow.prototype.evaluateRowVisibility = function ( fromRowProcessor ) {
  8051. var newVisibility = true;
  8052. if ( typeof(this.invisibleReason) !== 'undefined' ){
  8053. angular.forEach(this.invisibleReason, function( value, key ){
  8054. if ( value ){
  8055. newVisibility = false;
  8056. }
  8057. });
  8058. }
  8059. if ( typeof(this.visible) === 'undefined' || this.visible !== newVisibility ){
  8060. this.visible = newVisibility;
  8061. if ( !fromRowProcessor ){
  8062. this.grid.queueGridRefresh();
  8063. this.grid.api.core.raise.rowsVisibleChanged(this);
  8064. }
  8065. }
  8066. };
  8067. return GridRow;
  8068. }]);
  8069. })();
  8070. (function(){
  8071. 'use strict';
  8072. /**
  8073. * @ngdoc object
  8074. * @name ui.grid.class:GridRowColumn
  8075. * @param {GridRow} row The row for this pair
  8076. * @param {GridColumn} column The column for this pair
  8077. * @description A row and column pair that represents the intersection of these two entities.
  8078. * Must be instantiated as a constructor using the `new` keyword.
  8079. */
  8080. angular.module('ui.grid')
  8081. .factory('GridRowColumn', ['$parse', '$filter',
  8082. function GridRowColumnFactory($parse, $filter){
  8083. var GridRowColumn = function GridRowColumn(row, col) {
  8084. if ( !(this instanceof GridRowColumn)){
  8085. throw "Using GridRowColumn as a function insead of as a constructor. Must be called with `new` keyword";
  8086. }
  8087. /**
  8088. * @ngdoc object
  8089. * @name row
  8090. * @propertyOf ui.grid.class:GridRowColumn
  8091. * @description {@link ui.grid.class:GridRow }
  8092. */
  8093. this.row = row;
  8094. /**
  8095. * @ngdoc object
  8096. * @name col
  8097. * @propertyOf ui.grid.class:GridRowColumn
  8098. * @description {@link ui.grid.class:GridColumn }
  8099. */
  8100. this.col = col;
  8101. };
  8102. /**
  8103. * @ngdoc function
  8104. * @name getIntersectionValueRaw
  8105. * @methodOf ui.grid.class:GridRowColumn
  8106. * @description Gets the intersection of where the row and column meet.
  8107. * @returns {String|Number|Object} The value from the grid data that this GridRowColumn points too.
  8108. * If the column has a cellFilter this will NOT return the filtered value.
  8109. */
  8110. GridRowColumn.prototype.getIntersectionValueRaw = function(){
  8111. var getter = $parse(this.row.getEntityQualifiedColField(this.col));
  8112. var context = this.row;
  8113. return getter(context);
  8114. };
  8115. return GridRowColumn;
  8116. }
  8117. ]);
  8118. })();
  8119. (function () {
  8120. angular.module('ui.grid')
  8121. .factory('ScrollEvent', ['gridUtil', function (gridUtil) {
  8122. /**
  8123. * @ngdoc function
  8124. * @name ui.grid.class:ScrollEvent
  8125. * @description Model for all scrollEvents
  8126. * @param {Grid} grid that owns the scroll event
  8127. * @param {GridRenderContainer} sourceRowContainer that owns the scroll event. Can be null
  8128. * @param {GridRenderContainer} sourceColContainer that owns the scroll event. Can be null
  8129. * @param {string} source the source of the event - from uiGridConstants.scrollEventSources or a string value of directive/service/factory.functionName
  8130. */
  8131. function ScrollEvent(grid, sourceRowContainer, sourceColContainer, source) {
  8132. var self = this;
  8133. if (!grid) {
  8134. throw new Error("grid argument is required");
  8135. }
  8136. /**
  8137. * @ngdoc object
  8138. * @name grid
  8139. * @propertyOf ui.grid.class:ScrollEvent
  8140. * @description A reference back to the grid
  8141. */
  8142. self.grid = grid;
  8143. /**
  8144. * @ngdoc object
  8145. * @name source
  8146. * @propertyOf ui.grid.class:ScrollEvent
  8147. * @description the source of the scroll event. limited to values from uiGridConstants.scrollEventSources
  8148. */
  8149. self.source = source;
  8150. /**
  8151. * @ngdoc object
  8152. * @name noDelay
  8153. * @propertyOf ui.grid.class:ScrollEvent
  8154. * @description most scroll events from the mouse or trackpad require delay to operate properly
  8155. * set to false to eliminate delay. Useful for scroll events that the grid causes, such as scrolling to make a row visible.
  8156. */
  8157. self.withDelay = true;
  8158. self.sourceRowContainer = sourceRowContainer;
  8159. self.sourceColContainer = sourceColContainer;
  8160. self.newScrollLeft = null;
  8161. self.newScrollTop = null;
  8162. self.x = null;
  8163. self.y = null;
  8164. self.verticalScrollLength = -9999999;
  8165. self.horizontalScrollLength = -999999;
  8166. /**
  8167. * @ngdoc function
  8168. * @name fireThrottledScrollingEvent
  8169. * @methodOf ui.grid.class:ScrollEvent
  8170. * @description fires a throttled event using grid.api.core.raise.scrollEvent
  8171. */
  8172. self.fireThrottledScrollingEvent = gridUtil.throttle(function(sourceContainerId) {
  8173. self.grid.scrollContainers(sourceContainerId, self);
  8174. }, self.grid.options.wheelScrollThrottle, {trailing: true});
  8175. }
  8176. /**
  8177. * @ngdoc function
  8178. * @name getNewScrollLeft
  8179. * @methodOf ui.grid.class:ScrollEvent
  8180. * @description returns newScrollLeft property if available; calculates a new value if it isn't
  8181. */
  8182. ScrollEvent.prototype.getNewScrollLeft = function(colContainer, viewport){
  8183. var self = this;
  8184. if (!self.newScrollLeft){
  8185. var scrollWidth = (colContainer.getCanvasWidth() - colContainer.getViewportWidth());
  8186. var oldScrollLeft = gridUtil.normalizeScrollLeft(viewport, self.grid);
  8187. var scrollXPercentage;
  8188. if (typeof(self.x.percentage) !== 'undefined' && self.x.percentage !== undefined) {
  8189. scrollXPercentage = self.x.percentage;
  8190. }
  8191. else if (typeof(self.x.pixels) !== 'undefined' && self.x.pixels !== undefined) {
  8192. scrollXPercentage = self.x.percentage = (oldScrollLeft + self.x.pixels) / scrollWidth;
  8193. }
  8194. else {
  8195. throw new Error("No percentage or pixel value provided for scroll event X axis");
  8196. }
  8197. return Math.max(0, scrollXPercentage * scrollWidth);
  8198. }
  8199. return self.newScrollLeft;
  8200. };
  8201. /**
  8202. * @ngdoc function
  8203. * @name getNewScrollTop
  8204. * @methodOf ui.grid.class:ScrollEvent
  8205. * @description returns newScrollTop property if available; calculates a new value if it isn't
  8206. */
  8207. ScrollEvent.prototype.getNewScrollTop = function(rowContainer, viewport){
  8208. var self = this;
  8209. if (!self.newScrollTop){
  8210. var scrollLength = rowContainer.getVerticalScrollLength();
  8211. var oldScrollTop = viewport[0].scrollTop;
  8212. var scrollYPercentage;
  8213. if (typeof(self.y.percentage) !== 'undefined' && self.y.percentage !== undefined) {
  8214. scrollYPercentage = self.y.percentage;
  8215. }
  8216. else if (typeof(self.y.pixels) !== 'undefined' && self.y.pixels !== undefined) {
  8217. scrollYPercentage = self.y.percentage = (oldScrollTop + self.y.pixels) / scrollLength;
  8218. }
  8219. else {
  8220. throw new Error("No percentage or pixel value provided for scroll event Y axis");
  8221. }
  8222. return Math.max(0, scrollYPercentage * scrollLength);
  8223. }
  8224. return self.newScrollTop;
  8225. };
  8226. ScrollEvent.prototype.atTop = function(scrollTop) {
  8227. return (this.y && (this.y.percentage === 0 || this.verticalScrollLength < 0) && scrollTop === 0);
  8228. };
  8229. ScrollEvent.prototype.atBottom = function(scrollTop) {
  8230. return (this.y && (this.y.percentage === 1 || this.verticalScrollLength === 0) && scrollTop > 0);
  8231. };
  8232. ScrollEvent.prototype.atLeft = function(scrollLeft) {
  8233. return (this.x && (this.x.percentage === 0 || this.horizontalScrollLength < 0) && scrollLeft === 0);
  8234. };
  8235. ScrollEvent.prototype.atRight = function(scrollLeft) {
  8236. return (this.x && (this.x.percentage === 1 || this.horizontalScrollLength ===0) && scrollLeft > 0);
  8237. };
  8238. ScrollEvent.Sources = {
  8239. ViewPortScroll: 'ViewPortScroll',
  8240. RenderContainerMouseWheel: 'RenderContainerMouseWheel',
  8241. RenderContainerTouchMove: 'RenderContainerTouchMove',
  8242. Other: 99
  8243. };
  8244. return ScrollEvent;
  8245. }]);
  8246. })();
  8247. (function () {
  8248. 'use strict';
  8249. /**
  8250. * @ngdoc object
  8251. * @name ui.grid.service:gridClassFactory
  8252. *
  8253. * @description factory to return dom specific instances of a grid
  8254. *
  8255. */
  8256. angular.module('ui.grid').service('gridClassFactory', ['gridUtil', '$q', '$compile', '$templateCache', 'uiGridConstants', 'Grid', 'GridColumn', 'GridRow',
  8257. function (gridUtil, $q, $compile, $templateCache, uiGridConstants, Grid, GridColumn, GridRow) {
  8258. var service = {
  8259. /**
  8260. * @ngdoc method
  8261. * @name createGrid
  8262. * @methodOf ui.grid.service:gridClassFactory
  8263. * @description Creates a new grid instance. Each instance will have a unique id
  8264. * @param {object} options An object map of options to pass into the created grid instance.
  8265. * @returns {Grid} grid
  8266. */
  8267. createGrid : function(options) {
  8268. options = (typeof(options) !== 'undefined') ? options : {};
  8269. options.id = gridUtil.newId();
  8270. var grid = new Grid(options);
  8271. // NOTE/TODO: rowTemplate should always be defined...
  8272. if (grid.options.rowTemplate) {
  8273. var rowTemplateFnPromise = $q.defer();
  8274. grid.getRowTemplateFn = rowTemplateFnPromise.promise;
  8275. gridUtil.getTemplate(grid.options.rowTemplate)
  8276. .then(
  8277. function (template) {
  8278. var rowTemplateFn = $compile(template);
  8279. rowTemplateFnPromise.resolve(rowTemplateFn);
  8280. },
  8281. function (res) {
  8282. // Todo handle response error here?
  8283. throw new Error("Couldn't fetch/use row template '" + grid.options.rowTemplate + "'");
  8284. }).catch(angular.noop);
  8285. }
  8286. grid.registerColumnBuilder(service.defaultColumnBuilder);
  8287. // Row builder for custom row templates
  8288. grid.registerRowBuilder(service.rowTemplateAssigner);
  8289. // Reset all rows to visible initially
  8290. grid.registerRowsProcessor(function allRowsVisible(rows) {
  8291. rows.forEach(function (row) {
  8292. row.evaluateRowVisibility( true );
  8293. });
  8294. return rows;
  8295. }, 50);
  8296. grid.registerColumnsProcessor(function applyColumnVisibility(columns) {
  8297. columns.forEach(function (column) {
  8298. column.visible = angular.isDefined(column.colDef.visible) ? column.colDef.visible : true;
  8299. });
  8300. return columns;
  8301. }, 50);
  8302. grid.registerRowsProcessor(grid.searchRows, 100);
  8303. // Register the default row processor, it sorts rows by selected columns
  8304. if (grid.options.externalSort && angular.isFunction(grid.options.externalSort)) {
  8305. grid.registerRowsProcessor(grid.options.externalSort, 200);
  8306. }
  8307. else {
  8308. grid.registerRowsProcessor(grid.sortByColumn, 200);
  8309. }
  8310. return grid;
  8311. },
  8312. /**
  8313. * @ngdoc function
  8314. * @name defaultColumnBuilder
  8315. * @methodOf ui.grid.service:gridClassFactory
  8316. * @description Processes designTime column definitions and applies them to col for the
  8317. * core grid features
  8318. * @param {object} colDef reference to column definition
  8319. * @param {GridColumn} col reference to gridCol
  8320. * @param {object} gridOptions reference to grid options
  8321. */
  8322. defaultColumnBuilder: function (colDef, col, gridOptions) {
  8323. var templateGetPromises = [];
  8324. // Abstracts the standard template processing we do for every template type.
  8325. var processTemplate = function( templateType, providedType, defaultTemplate, filterType, tooltipType ) {
  8326. if ( !colDef[templateType] ){
  8327. col[providedType] = defaultTemplate;
  8328. } else {
  8329. col[providedType] = colDef[templateType];
  8330. }
  8331. var templatePromise = gridUtil.getTemplate(col[providedType])
  8332. .then(
  8333. function (template) {
  8334. if ( angular.isFunction(template) ) { template = template(); }
  8335. var tooltipCall = ( tooltipType === 'cellTooltip' ) ? 'col.cellTooltip(row,col)' : 'col.headerTooltip(col)';
  8336. if ( tooltipType && col[tooltipType] === false ){
  8337. template = template.replace(uiGridConstants.TOOLTIP, '');
  8338. } else if ( tooltipType && col[tooltipType] ){
  8339. template = template.replace(uiGridConstants.TOOLTIP, 'title="{{' + tooltipCall + ' CUSTOM_FILTERS }}"');
  8340. }
  8341. if ( filterType ){
  8342. col[templateType] = template.replace(uiGridConstants.CUSTOM_FILTERS, function() {
  8343. return col[filterType] ? "|" + col[filterType] : "";
  8344. });
  8345. } else {
  8346. col[templateType] = template;
  8347. }
  8348. },
  8349. function (res) {
  8350. throw new Error("Couldn't fetch/use colDef." + templateType + " '" + colDef[templateType] + "'");
  8351. }).catch(angular.noop);
  8352. templateGetPromises.push(templatePromise);
  8353. return templatePromise;
  8354. };
  8355. /**
  8356. * @ngdoc property
  8357. * @name cellTemplate
  8358. * @propertyOf ui.grid.class:GridOptions.columnDef
  8359. * @description a custom template for each cell in this column. The default
  8360. * is ui-grid/uiGridCell. If you are using the cellNav feature, this template
  8361. * must contain a div that can receive focus.
  8362. *
  8363. */
  8364. col.cellTemplatePromise = processTemplate( 'cellTemplate', 'providedCellTemplate', 'ui-grid/uiGridCell', 'cellFilter', 'cellTooltip' );
  8365. /**
  8366. * @ngdoc property
  8367. * @name headerCellTemplate
  8368. * @propertyOf ui.grid.class:GridOptions.columnDef
  8369. * @description a custom template for the header for this column. The default
  8370. * is ui-grid/uiGridHeaderCell
  8371. *
  8372. */
  8373. col.headerCellTemplatePromise = processTemplate( 'headerCellTemplate', 'providedHeaderCellTemplate', 'ui-grid/uiGridHeaderCell', 'headerCellFilter', 'headerTooltip' );
  8374. /**
  8375. * @ngdoc property
  8376. * @name footerCellTemplate
  8377. * @propertyOf ui.grid.class:GridOptions.columnDef
  8378. * @description a custom template for the footer for this column. The default
  8379. * is ui-grid/uiGridFooterCell
  8380. *
  8381. */
  8382. col.footerCellTemplatePromise = processTemplate( 'footerCellTemplate', 'providedFooterCellTemplate', 'ui-grid/uiGridFooterCell', 'footerCellFilter' );
  8383. /**
  8384. * @ngdoc property
  8385. * @name filterHeaderTemplate
  8386. * @propertyOf ui.grid.class:GridOptions.columnDef
  8387. * @description a custom template for the filter input. The default is ui-grid/ui-grid-filter
  8388. *
  8389. */
  8390. col.filterHeaderTemplatePromise = processTemplate( 'filterHeaderTemplate', 'providedFilterHeaderTemplate', 'ui-grid/ui-grid-filter' );
  8391. // Create a promise for the compiled element function
  8392. col.compiledElementFnDefer = $q.defer();
  8393. return $q.all(templateGetPromises);
  8394. },
  8395. rowTemplateAssigner: function rowTemplateAssigner(row) {
  8396. var grid = this;
  8397. // Row has no template assigned to it
  8398. if (!row.rowTemplate) {
  8399. // Use the default row template from the grid
  8400. row.rowTemplate = grid.options.rowTemplate;
  8401. // Use the grid's function for fetching the compiled row template function
  8402. row.getRowTemplateFn = grid.getRowTemplateFn;
  8403. }
  8404. // Row has its own template assigned
  8405. else {
  8406. // Create a promise for the compiled row template function
  8407. var perRowTemplateFnPromise = $q.defer();
  8408. row.getRowTemplateFn = perRowTemplateFnPromise.promise;
  8409. // Get the row template
  8410. gridUtil.getTemplate(row.rowTemplate)
  8411. .then(function (template) {
  8412. // Compile the template
  8413. var rowTemplateFn = $compile(template);
  8414. // Resolve the compiled template function promise
  8415. perRowTemplateFnPromise.resolve(rowTemplateFn);
  8416. },
  8417. function (res) {
  8418. // Todo handle response error here?
  8419. throw new Error("Couldn't fetch/use row template '" + row.rowTemplate + "'");
  8420. });
  8421. }
  8422. return row.getRowTemplateFn;
  8423. }
  8424. };
  8425. //class definitions (moved to separate factories)
  8426. return service;
  8427. }]);
  8428. })();
  8429. (function() {
  8430. var module = angular.module('ui.grid');
  8431. function escapeRegExp(str) {
  8432. return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
  8433. }
  8434. /**
  8435. * @ngdoc service
  8436. * @name ui.grid.service:rowSearcher
  8437. *
  8438. * @description Service for searching/filtering rows based on column value conditions.
  8439. */
  8440. module.service('rowSearcher', ['gridUtil', 'uiGridConstants', function (gridUtil, uiGridConstants) {
  8441. var defaultCondition = uiGridConstants.filter.CONTAINS;
  8442. var rowSearcher = {};
  8443. /**
  8444. * @ngdoc function
  8445. * @name getTerm
  8446. * @methodOf ui.grid.service:rowSearcher
  8447. * @description Get the term from a filter
  8448. * Trims leading and trailing whitespace
  8449. * @param {object} filter object to use
  8450. * @returns {object} Parsed term
  8451. */
  8452. rowSearcher.getTerm = function getTerm(filter) {
  8453. if (typeof(filter.term) === 'undefined') { return filter.term; }
  8454. var term = filter.term;
  8455. // Strip leading and trailing whitespace if the term is a string
  8456. if (typeof(term) === 'string') {
  8457. term = term.trim();
  8458. }
  8459. return term;
  8460. };
  8461. /**
  8462. * @ngdoc function
  8463. * @name stripTerm
  8464. * @methodOf ui.grid.service:rowSearcher
  8465. * @description Remove leading and trailing asterisk (*) from the filter's term
  8466. * @param {object} filter object to use
  8467. * @returns {uiGridConstants.filter<int>} Value representing the condition constant value
  8468. */
  8469. rowSearcher.stripTerm = function stripTerm(filter) {
  8470. var term = rowSearcher.getTerm(filter);
  8471. if (typeof(term) === 'string') {
  8472. return escapeRegExp(term.replace(/(^\*|\*$)/g, ''));
  8473. }
  8474. else {
  8475. return term;
  8476. }
  8477. };
  8478. /**
  8479. * @ngdoc function
  8480. * @name guessCondition
  8481. * @methodOf ui.grid.service:rowSearcher
  8482. * @description Guess the condition for a filter based on its term
  8483. * <br>
  8484. * Defaults to STARTS_WITH. Uses CONTAINS for strings beginning and ending with *s (*bob*).
  8485. * Uses STARTS_WITH for strings ending with * (bo*). Uses ENDS_WITH for strings starting with * (*ob).
  8486. * @param {object} filter object to use
  8487. * @returns {uiGridConstants.filter<int>} Value representing the condition constant value
  8488. */
  8489. rowSearcher.guessCondition = function guessCondition(filter) {
  8490. if (typeof(filter.term) === 'undefined' || !filter.term) {
  8491. return defaultCondition;
  8492. }
  8493. var term = rowSearcher.getTerm(filter);
  8494. if (/\*/.test(term)) {
  8495. var regexpFlags = '';
  8496. if (!filter.flags || !filter.flags.caseSensitive) {
  8497. regexpFlags += 'i';
  8498. }
  8499. var reText = term.replace(/(\\)?\*/g, function ($0, $1) { return $1 ? $0 : '[\\s\\S]*?'; });
  8500. return new RegExp('^' + reText + '$', regexpFlags);
  8501. }
  8502. // Otherwise default to default condition
  8503. else {
  8504. return defaultCondition;
  8505. }
  8506. };
  8507. /**
  8508. * @ngdoc function
  8509. * @name setupFilters
  8510. * @methodOf ui.grid.service:rowSearcher
  8511. * @description For a given columns filters (either col.filters, or [col.filter] can be passed in),
  8512. * do all the parsing and pre-processing and store that data into a new filters object. The object
  8513. * has the condition, the flags, the stripped term, and a parsed reg exp if there was one.
  8514. *
  8515. * We could use a forEach in here, since it's much less performance sensitive, but since we're using
  8516. * for loops everywhere else in this module...
  8517. *
  8518. * @param {array} filters the filters from the column (col.filters or [col.filter])
  8519. * @returns {array} An array of parsed/preprocessed filters
  8520. */
  8521. rowSearcher.setupFilters = function setupFilters( filters ){
  8522. var newFilters = [];
  8523. var filtersLength = filters.length;
  8524. for ( var i = 0; i < filtersLength; i++ ){
  8525. var filter = filters[i];
  8526. if ( filter.noTerm || !gridUtil.isNullOrUndefined(filter.term) ){
  8527. var newFilter = {};
  8528. var regexpFlags = '';
  8529. if (!filter.flags || !filter.flags.caseSensitive) {
  8530. regexpFlags += 'i';
  8531. }
  8532. if ( !gridUtil.isNullOrUndefined(filter.term) ){
  8533. // it is possible to have noTerm.
  8534. if ( filter.rawTerm ){
  8535. newFilter.term = filter.term;
  8536. } else {
  8537. newFilter.term = rowSearcher.stripTerm(filter);
  8538. }
  8539. }
  8540. newFilter.noTerm = filter.noTerm;
  8541. if ( filter.condition ){
  8542. newFilter.condition = filter.condition;
  8543. } else {
  8544. newFilter.condition = rowSearcher.guessCondition(filter);
  8545. }
  8546. newFilter.flags = angular.extend( { caseSensitive: false, date: false }, filter.flags );
  8547. if (newFilter.condition === uiGridConstants.filter.STARTS_WITH) {
  8548. newFilter.startswithRE = new RegExp('^' + newFilter.term, regexpFlags);
  8549. }
  8550. if (newFilter.condition === uiGridConstants.filter.ENDS_WITH) {
  8551. newFilter.endswithRE = new RegExp(newFilter.term + '$', regexpFlags);
  8552. }
  8553. if (newFilter.condition === uiGridConstants.filter.CONTAINS) {
  8554. newFilter.containsRE = new RegExp(newFilter.term, regexpFlags);
  8555. }
  8556. if (newFilter.condition === uiGridConstants.filter.EXACT) {
  8557. newFilter.exactRE = new RegExp('^' + newFilter.term + '$', regexpFlags);
  8558. }
  8559. newFilters.push(newFilter);
  8560. }
  8561. }
  8562. return newFilters;
  8563. };
  8564. /**
  8565. * @ngdoc function
  8566. * @name runColumnFilter
  8567. * @methodOf ui.grid.service:rowSearcher
  8568. * @description Runs a single pre-parsed filter against a cell, returning true
  8569. * if the cell matches that one filter.
  8570. *
  8571. * @param {Grid} grid the grid we're working against
  8572. * @param {GridRow} row the row we're matching against
  8573. * @param {GridColumn} column the column that we're working against
  8574. * @param {object} filter the specific, preparsed, filter that we want to test
  8575. * @returns {boolean} true if we match (row stays visible)
  8576. */
  8577. rowSearcher.runColumnFilter = function runColumnFilter(grid, row, column, filter) {
  8578. // Cache typeof condition
  8579. var conditionType = typeof(filter.condition);
  8580. // Term to search for.
  8581. var term = filter.term;
  8582. // Get the column value for this row
  8583. var value;
  8584. if ( column.filterCellFiltered ){
  8585. value = grid.getCellDisplayValue(row, column);
  8586. } else {
  8587. value = grid.getCellValue(row, column);
  8588. }
  8589. // If the filter's condition is a RegExp, then use it
  8590. if (filter.condition instanceof RegExp) {
  8591. return filter.condition.test(value);
  8592. }
  8593. // If the filter's condition is a function, run it
  8594. if (conditionType === 'function') {
  8595. return filter.condition(term, value, row, column);
  8596. }
  8597. if (filter.startswithRE) {
  8598. return filter.startswithRE.test(value);
  8599. }
  8600. if (filter.endswithRE) {
  8601. return filter.endswithRE.test(value);
  8602. }
  8603. if (filter.containsRE) {
  8604. return filter.containsRE.test(value);
  8605. }
  8606. if (filter.exactRE) {
  8607. return filter.exactRE.test(value);
  8608. }
  8609. if (filter.condition === uiGridConstants.filter.NOT_EQUAL) {
  8610. var regex = new RegExp('^' + term + '$');
  8611. return !regex.exec(value);
  8612. }
  8613. if (typeof(value) === 'number' && typeof(term) === 'string' ){
  8614. // if the term has a decimal in it, it comes through as '9\.4', we need to take out the \
  8615. // the same for negative numbers
  8616. // TODO: I suspect the right answer is to look at escapeRegExp at the top of this code file, maybe it's not needed?
  8617. var tempFloat = parseFloat(term.replace(/\\\./,'.').replace(/\\\-/,'-'));
  8618. if (!isNaN(tempFloat)) {
  8619. term = tempFloat;
  8620. }
  8621. }
  8622. if (filter.flags.date === true) {
  8623. value = new Date(value);
  8624. // If the term has a dash in it, it comes through as '\-' -- we need to take out the '\'.
  8625. term = new Date(term.replace(/\\/g, ''));
  8626. }
  8627. if (filter.condition === uiGridConstants.filter.GREATER_THAN) {
  8628. return (value > term);
  8629. }
  8630. if (filter.condition === uiGridConstants.filter.GREATER_THAN_OR_EQUAL) {
  8631. return (value >= term);
  8632. }
  8633. if (filter.condition === uiGridConstants.filter.LESS_THAN) {
  8634. return (value < term);
  8635. }
  8636. if (filter.condition === uiGridConstants.filter.LESS_THAN_OR_EQUAL) {
  8637. return (value <= term);
  8638. }
  8639. return true;
  8640. };
  8641. /**
  8642. * @ngdoc boolean
  8643. * @name useExternalFiltering
  8644. * @propertyOf ui.grid.class:GridOptions
  8645. * @description False by default. When enabled, this setting suppresses the internal filtering.
  8646. * All UI logic will still operate, allowing filter conditions to be set and modified.
  8647. *
  8648. * The external filter logic can listen for the `filterChange` event, which fires whenever
  8649. * a filter has been adjusted.
  8650. */
  8651. /**
  8652. * @ngdoc function
  8653. * @name searchColumn
  8654. * @methodOf ui.grid.service:rowSearcher
  8655. * @description Process provided filters on provided column against a given row. If the row meets
  8656. * the conditions on all the filters, return true.
  8657. * @param {Grid} grid Grid to search in
  8658. * @param {GridRow} row Row to search on
  8659. * @param {GridColumn} column Column with the filters to use
  8660. * @param {array} filters array of pre-parsed/preprocessed filters to apply
  8661. * @returns {boolean} Whether the column matches or not.
  8662. */
  8663. rowSearcher.searchColumn = function searchColumn(grid, row, column, filters) {
  8664. if (grid.options.useExternalFiltering) {
  8665. return true;
  8666. }
  8667. var filtersLength = filters.length;
  8668. for (var i = 0; i < filtersLength; i++) {
  8669. var filter = filters[i];
  8670. if ( !gridUtil.isNullOrUndefined(filter.term) && filter.term !== '' || filter.noTerm ){
  8671. var ret = rowSearcher.runColumnFilter(grid, row, column, filter);
  8672. if (!ret) {
  8673. return false;
  8674. }
  8675. }
  8676. }
  8677. return true;
  8678. };
  8679. /**
  8680. * @ngdoc function
  8681. * @name search
  8682. * @methodOf ui.grid.service:rowSearcher
  8683. * @description Run a search across the given rows and columns, marking any rows that don't
  8684. * match the stored col.filters or col.filter as invisible.
  8685. * @param {Grid} grid Grid instance to search inside
  8686. * @param {Array[GridRow]} rows GridRows to filter
  8687. * @param {Array[GridColumn]} columns GridColumns with filters to process
  8688. */
  8689. rowSearcher.search = function search(grid, rows, columns) {
  8690. /*
  8691. * Added performance optimisations into this code base, as this logic creates deeply nested
  8692. * loops and is therefore very performance sensitive. In particular, avoiding forEach as
  8693. * this impacts some browser optimisers (particularly Chrome), using iterators instead
  8694. */
  8695. // Don't do anything if we weren't passed any rows
  8696. if (!rows) {
  8697. return;
  8698. }
  8699. // don't filter if filtering currently disabled
  8700. if (!grid.options.enableFiltering){
  8701. return rows;
  8702. }
  8703. // Build list of filters to apply
  8704. var filterData = [];
  8705. var colsLength = columns.length;
  8706. var hasTerm = function( filters ) {
  8707. var hasTerm = false;
  8708. filters.forEach( function (filter) {
  8709. if ( !gridUtil.isNullOrUndefined(filter.term) && filter.term !== '' || filter.noTerm ){
  8710. hasTerm = true;
  8711. }
  8712. });
  8713. return hasTerm;
  8714. };
  8715. for (var i = 0; i < colsLength; i++) {
  8716. var col = columns[i];
  8717. if (typeof(col.filters) !== 'undefined' && hasTerm(col.filters) ) {
  8718. filterData.push( { col: col, filters: rowSearcher.setupFilters(col.filters) } );
  8719. }
  8720. }
  8721. if (filterData.length > 0) {
  8722. // define functions outside the loop, performance optimisation
  8723. var foreachRow = function(grid, row, col, filters){
  8724. if ( row.visible && !rowSearcher.searchColumn(grid, row, col, filters) ) {
  8725. row.visible = false;
  8726. }
  8727. };
  8728. var foreachFilterCol = function(grid, filterData){
  8729. var rowsLength = rows.length;
  8730. for ( var i = 0; i < rowsLength; i++){
  8731. foreachRow(grid, rows[i], filterData.col, filterData.filters);
  8732. }
  8733. };
  8734. // nested loop itself - foreachFilterCol, which in turn calls foreachRow
  8735. var filterDataLength = filterData.length;
  8736. for ( var j = 0; j < filterDataLength; j++){
  8737. foreachFilterCol( grid, filterData[j] );
  8738. }
  8739. if (grid.api.core.raise.rowsVisibleChanged) {
  8740. grid.api.core.raise.rowsVisibleChanged();
  8741. }
  8742. // drop any invisible rows
  8743. // 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
  8744. // rows = rows.filter(function(row){ return row.visible; });
  8745. }
  8746. return rows;
  8747. };
  8748. return rowSearcher;
  8749. }]);
  8750. })();
  8751. (function() {
  8752. var module = angular.module('ui.grid');
  8753. /**
  8754. * @ngdoc object
  8755. * @name ui.grid.class:rowSorter
  8756. * @description rowSorter provides the default sorting mechanisms,
  8757. * including guessing column types and applying appropriate sort
  8758. * algorithms
  8759. *
  8760. */
  8761. module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGridConstants) {
  8762. var currencyRegexStr =
  8763. '(' +
  8764. uiGridConstants.CURRENCY_SYMBOLS
  8765. .map(function (a) { return '\\' + a; }) // Escape all the currency symbols ($ at least will jack up this regex)
  8766. .join('|') + // Join all the symbols together with |s
  8767. ')?';
  8768. // /^[-+]?[£$¤¥]?[\d,.]+%?$/
  8769. var numberStrRegex = new RegExp('^[-+]?' + currencyRegexStr + '[\\d,.]+' + currencyRegexStr + '%?$');
  8770. var rowSorter = {
  8771. // Cache of sorting functions. Once we create them, we don't want to keep re-doing it
  8772. // this takes a piece of data from the cell and tries to determine its type and what sorting
  8773. // function to use for it
  8774. colSortFnCache: {}
  8775. };
  8776. /**
  8777. * @ngdoc method
  8778. * @methodOf ui.grid.class:rowSorter
  8779. * @name guessSortFn
  8780. * @description Assigns a sort function to use based on the itemType in the column
  8781. * @param {string} itemType one of 'number', 'boolean', 'string', 'date', 'object'. And
  8782. * error will be thrown for any other type.
  8783. * @returns {function} a sort function that will sort that type
  8784. */
  8785. rowSorter.guessSortFn = function guessSortFn(itemType) {
  8786. switch (itemType) {
  8787. case "number":
  8788. return rowSorter.sortNumber;
  8789. case "numberStr":
  8790. return rowSorter.sortNumberStr;
  8791. case "boolean":
  8792. return rowSorter.sortBool;
  8793. case "string":
  8794. return rowSorter.sortAlpha;
  8795. case "date":
  8796. return rowSorter.sortDate;
  8797. case "object":
  8798. return rowSorter.basicSort;
  8799. default:
  8800. throw new Error('No sorting function found for type:' + itemType);
  8801. }
  8802. };
  8803. /**
  8804. * @ngdoc method
  8805. * @methodOf ui.grid.class:rowSorter
  8806. * @name handleNulls
  8807. * @description Sorts nulls and undefined to the bottom (top when
  8808. * descending). Called by each of the internal sorters before
  8809. * attempting to sort. Note that this method is available on the core api
  8810. * via gridApi.core.sortHandleNulls
  8811. * @param {object} a sort value a
  8812. * @param {object} b sort value b
  8813. * @returns {number} null if there were no nulls/undefineds, otherwise returns
  8814. * a sort value that should be passed back from the sort function
  8815. */
  8816. rowSorter.handleNulls = function handleNulls(a, b) {
  8817. // We want to allow zero values and false values to be evaluated in the sort function
  8818. if ((!a && a !== 0 && a !== false) || (!b && b !== 0 && b !== false)) {
  8819. // We want to force nulls and such to the bottom when we sort... which effectively is "greater than"
  8820. if ((!a && a !== 0 && a !== false) && (!b && b !== 0 && b !== false)) {
  8821. return 0;
  8822. }
  8823. else if (!a && a !== 0 && a !== false) {
  8824. return 1;
  8825. }
  8826. else if (!b && b !== 0 && b !== false) {
  8827. return -1;
  8828. }
  8829. }
  8830. return null;
  8831. };
  8832. /**
  8833. * @ngdoc method
  8834. * @methodOf ui.grid.class:rowSorter
  8835. * @name basicSort
  8836. * @description Sorts any values that provide the < method, including strings
  8837. * or numbers. Handles nulls and undefined through calling handleNulls
  8838. * @param {object} a sort value a
  8839. * @param {object} b sort value b
  8840. * @returns {number} normal sort function, returns -ve, 0, +ve
  8841. */
  8842. rowSorter.basicSort = function basicSort(a, b) {
  8843. var nulls = rowSorter.handleNulls(a, b);
  8844. if ( nulls !== null ){
  8845. return nulls;
  8846. } else {
  8847. if (a === b) {
  8848. return 0;
  8849. }
  8850. if (a < b) {
  8851. return -1;
  8852. }
  8853. return 1;
  8854. }
  8855. };
  8856. /**
  8857. * @ngdoc method
  8858. * @methodOf ui.grid.class:rowSorter
  8859. * @name sortNumber
  8860. * @description Sorts numerical values. Handles nulls and undefined through calling handleNulls
  8861. * @param {object} a sort value a
  8862. * @param {object} b sort value b
  8863. * @returns {number} normal sort function, returns -ve, 0, +ve
  8864. */
  8865. rowSorter.sortNumber = function sortNumber(a, b) {
  8866. var nulls = rowSorter.handleNulls(a, b);
  8867. if ( nulls !== null ){
  8868. return nulls;
  8869. } else {
  8870. return a - b;
  8871. }
  8872. };
  8873. /**
  8874. * @ngdoc method
  8875. * @methodOf ui.grid.class:rowSorter
  8876. * @name sortNumberStr
  8877. * @description Sorts numerical values that are stored in a string (i.e. parses them to numbers first).
  8878. * Handles nulls and undefined through calling handleNulls
  8879. * @param {object} a sort value a
  8880. * @param {object} b sort value b
  8881. * @returns {number} normal sort function, returns -ve, 0, +ve
  8882. */
  8883. rowSorter.sortNumberStr = function sortNumberStr(a, b) {
  8884. var nulls = rowSorter.handleNulls(a, b);
  8885. if ( nulls !== null ){
  8886. return nulls;
  8887. } else {
  8888. var numA, // The parsed number form of 'a'
  8889. numB, // The parsed number form of 'b'
  8890. badA = false,
  8891. badB = false;
  8892. // Try to parse 'a' to a float
  8893. numA = parseFloat(a.replace(/[^0-9.-]/g, ''));
  8894. // If 'a' couldn't be parsed to float, flag it as bad
  8895. if (isNaN(numA)) {
  8896. badA = true;
  8897. }
  8898. // Try to parse 'b' to a float
  8899. numB = parseFloat(b.replace(/[^0-9.-]/g, ''));
  8900. // If 'b' couldn't be parsed to float, flag it as bad
  8901. if (isNaN(numB)) {
  8902. badB = true;
  8903. }
  8904. // We want bad ones to get pushed to the bottom... which effectively is "greater than"
  8905. if (badA && badB) {
  8906. return 0;
  8907. }
  8908. if (badA) {
  8909. return 1;
  8910. }
  8911. if (badB) {
  8912. return -1;
  8913. }
  8914. return numA - numB;
  8915. }
  8916. };
  8917. /**
  8918. * @ngdoc method
  8919. * @methodOf ui.grid.class:rowSorter
  8920. * @name sortAlpha
  8921. * @description Sorts string values. Handles nulls and undefined through calling handleNulls
  8922. * @param {object} a sort value a
  8923. * @param {object} b sort value b
  8924. * @returns {number} normal sort function, returns -ve, 0, +ve
  8925. */
  8926. rowSorter.sortAlpha = function sortAlpha(a, b) {
  8927. var nulls = rowSorter.handleNulls(a, b);
  8928. if ( nulls !== null ){
  8929. return nulls;
  8930. } else {
  8931. var strA = a.toString().toLowerCase(),
  8932. strB = b.toString().toLowerCase();
  8933. return strA === strB ? 0 : strA.localeCompare(strB);
  8934. }
  8935. };
  8936. /**
  8937. * @ngdoc method
  8938. * @methodOf ui.grid.class:rowSorter
  8939. * @name sortDate
  8940. * @description Sorts date values. Handles nulls and undefined through calling handleNulls.
  8941. * Handles date strings by converting to Date object if not already an instance of Date
  8942. * @param {object} a sort value a
  8943. * @param {object} b sort value b
  8944. * @returns {number} normal sort function, returns -ve, 0, +ve
  8945. */
  8946. rowSorter.sortDate = function sortDate(a, b) {
  8947. var nulls = rowSorter.handleNulls(a, b);
  8948. if ( nulls !== null ){
  8949. return nulls;
  8950. } else {
  8951. if (!(a instanceof Date)) {
  8952. a = new Date(a);
  8953. }
  8954. if (!(b instanceof Date)){
  8955. b = new Date(b);
  8956. }
  8957. var timeA = a.getTime(),
  8958. timeB = b.getTime();
  8959. return timeA === timeB ? 0 : (timeA < timeB ? -1 : 1);
  8960. }
  8961. };
  8962. /**
  8963. * @ngdoc method
  8964. * @methodOf ui.grid.class:rowSorter
  8965. * @name sortBool
  8966. * @description Sorts boolean values, true is considered larger than false.
  8967. * Handles nulls and undefined through calling handleNulls
  8968. * @param {object} a sort value a
  8969. * @param {object} b sort value b
  8970. * @returns {number} normal sort function, returns -ve, 0, +ve
  8971. */
  8972. rowSorter.sortBool = function sortBool(a, b) {
  8973. var nulls = rowSorter.handleNulls(a, b);
  8974. if ( nulls !== null ){
  8975. return nulls;
  8976. } else {
  8977. if (a && b) {
  8978. return 0;
  8979. }
  8980. if (!a && !b) {
  8981. return 0;
  8982. }
  8983. else {
  8984. return a ? 1 : -1;
  8985. }
  8986. }
  8987. };
  8988. /**
  8989. * @ngdoc method
  8990. * @methodOf ui.grid.class:rowSorter
  8991. * @name getSortFn
  8992. * @description Get the sort function for the column. Looks first in
  8993. * rowSorter.colSortFnCache using the column name, failing that it
  8994. * looks at col.sortingAlgorithm (and puts it in the cache), failing that
  8995. * it guesses the sort algorithm based on the data type.
  8996. *
  8997. * The cache currently seems a bit pointless, as none of the work we do is
  8998. * processor intensive enough to need caching. Presumably in future we might
  8999. * inspect the row data itself to guess the sort function, and in that case
  9000. * it would make sense to have a cache, the infrastructure is in place to allow
  9001. * that.
  9002. *
  9003. * @param {Grid} grid the grid to consider
  9004. * @param {GridColumn} col the column to find a function for
  9005. * @param {array} rows an array of grid rows. Currently unused, but presumably in future
  9006. * we might inspect the rows themselves to decide what sort of data might be there
  9007. * @returns {function} the sort function chosen for the column
  9008. */
  9009. rowSorter.getSortFn = function getSortFn(grid, col, rows) {
  9010. var sortFn, item;
  9011. // See if we already figured out what to use to sort the column and have it in the cache
  9012. if (rowSorter.colSortFnCache[col.colDef.name]) {
  9013. sortFn = rowSorter.colSortFnCache[col.colDef.name];
  9014. }
  9015. // If the column has its OWN sorting algorithm, use that
  9016. else if (col.sortingAlgorithm !== undefined) {
  9017. sortFn = col.sortingAlgorithm;
  9018. rowSorter.colSortFnCache[col.colDef.name] = col.sortingAlgorithm;
  9019. }
  9020. // Always default to sortAlpha when sorting after a cellFilter
  9021. else if ( col.sortCellFiltered && col.cellFilter ){
  9022. sortFn = rowSorter.sortAlpha;
  9023. rowSorter.colSortFnCache[col.colDef.name] = sortFn;
  9024. }
  9025. // Try and guess what sort function to use
  9026. else {
  9027. // Guess the sort function
  9028. sortFn = rowSorter.guessSortFn(col.colDef.type);
  9029. // If we found a sort function, cache it
  9030. if (sortFn) {
  9031. rowSorter.colSortFnCache[col.colDef.name] = sortFn;
  9032. }
  9033. else {
  9034. // We assign the alpha sort because anything that is null/undefined will never get passed to
  9035. // the actual sorting function. It will get caught in our null check and returned to be sorted
  9036. // down to the bottom
  9037. sortFn = rowSorter.sortAlpha;
  9038. }
  9039. }
  9040. return sortFn;
  9041. };
  9042. /**
  9043. * @ngdoc method
  9044. * @methodOf ui.grid.class:rowSorter
  9045. * @name prioritySort
  9046. * @description Used where multiple columns are present in the sort criteria,
  9047. * we determine which column should take precedence in the sort by sorting
  9048. * the columns based on their sort.priority
  9049. *
  9050. * @param {gridColumn} a column a
  9051. * @param {gridColumn} b column b
  9052. * @returns {number} normal sort function, returns -ve, 0, +ve
  9053. */
  9054. rowSorter.prioritySort = function (a, b) {
  9055. // Both columns have a sort priority
  9056. if (a.sort.priority !== undefined && b.sort.priority !== undefined) {
  9057. // A is higher priority
  9058. if (a.sort.priority < b.sort.priority) {
  9059. return -1;
  9060. }
  9061. // Equal
  9062. else if (a.sort.priority === b.sort.priority) {
  9063. return 0;
  9064. }
  9065. // B is higher
  9066. else {
  9067. return 1;
  9068. }
  9069. }
  9070. // Only A has a priority
  9071. else if (a.sort.priority !== undefined) {
  9072. return -1;
  9073. }
  9074. // Only B has a priority
  9075. else if (b.sort.priority !== undefined) {
  9076. return 1;
  9077. }
  9078. // Neither has a priority
  9079. else {
  9080. return 0;
  9081. }
  9082. };
  9083. /**
  9084. * @ngdoc object
  9085. * @name useExternalSorting
  9086. * @propertyOf ui.grid.class:GridOptions
  9087. * @description Prevents the internal sorting from executing. Events will
  9088. * still be fired when the sort changes, and the sort information on
  9089. * the columns will be updated, allowing an external sorter (for example,
  9090. * server sorting) to be implemented. Defaults to false.
  9091. *
  9092. */
  9093. /**
  9094. * @ngdoc method
  9095. * @methodOf ui.grid.class:rowSorter
  9096. * @name sort
  9097. * @description sorts the grid
  9098. * @param {Object} grid the grid itself
  9099. * @param {array} rows the rows to be sorted
  9100. * @param {array} columns the columns in which to look
  9101. * for sort criteria
  9102. * @returns {array} sorted rows
  9103. */
  9104. rowSorter.sort = function rowSorterSort(grid, rows, columns) {
  9105. // first make sure we are even supposed to do work
  9106. if (!rows) {
  9107. return;
  9108. }
  9109. if (grid.options.useExternalSorting){
  9110. return rows;
  9111. }
  9112. // Build the list of columns to sort by
  9113. var sortCols = [];
  9114. var defaultSortCols = [];
  9115. columns.forEach(function (col) {
  9116. if (col.sort && !col.sort.ignoreSort && col.sort.direction && (col.sort.direction === uiGridConstants.ASC || col.sort.direction === uiGridConstants.DESC)) {
  9117. sortCols.push({
  9118. col: col,
  9119. sort: col.sort
  9120. });
  9121. } else if ( col.defaultSort && col.defaultSort.direction && (col.defaultSort.direction === uiGridConstants.ASC || col.defaultSort.direction === uiGridConstants.DESC) ) {
  9122. defaultSortCols.push({
  9123. col: col,
  9124. sort: col.defaultSort
  9125. });
  9126. }
  9127. });
  9128. // Sort the "sort columns" by their sort priority
  9129. sortCols = sortCols.sort(rowSorter.prioritySort);
  9130. defaultSortCols = defaultSortCols.sort(rowSorter.prioritySort);
  9131. sortCols = sortCols.concat(defaultSortCols);
  9132. // Now rows to sort by, maintain original order
  9133. if (sortCols.length === 0) {
  9134. return rows;
  9135. }
  9136. // Re-usable variables
  9137. var col, direction;
  9138. // put a custom index field on each row, used to make a stable sort out of unstable sorts (e.g. Chrome)
  9139. var setIndex = function( row, idx ){
  9140. row.entity.$$uiGridIndex = idx;
  9141. };
  9142. rows.forEach(setIndex);
  9143. // IE9-11 HACK.... the 'rows' variable would be empty where we call rowSorter.getSortFn(...) below. We have to use a separate reference
  9144. // var d = data.slice(0);
  9145. var r = rows.slice(0);
  9146. // Now actually sort the data
  9147. var rowSortFn = function (rowA, rowB) {
  9148. var tem = 0,
  9149. idx = 0,
  9150. sortFn;
  9151. while (tem === 0 && idx < sortCols.length) {
  9152. // grab the metadata for the rest of the logic
  9153. col = sortCols[idx].col;
  9154. direction = sortCols[idx].sort.direction;
  9155. sortFn = rowSorter.getSortFn(grid, col, r);
  9156. var propA, propB;
  9157. if ( col.sortCellFiltered ){
  9158. propA = grid.getCellDisplayValue(rowA, col);
  9159. propB = grid.getCellDisplayValue(rowB, col);
  9160. } else {
  9161. propA = grid.getCellValue(rowA, col);
  9162. propB = grid.getCellValue(rowB, col);
  9163. }
  9164. tem = sortFn(propA, propB, rowA, rowB, direction, col);
  9165. idx++;
  9166. }
  9167. // Chrome doesn't implement a stable sort function. If our sort returns 0
  9168. // (i.e. the items are equal), and we're at the last sort column in the list,
  9169. // then return the previous order using our custom
  9170. // index variable
  9171. if (tem === 0 ) {
  9172. return rowA.entity.$$uiGridIndex - rowB.entity.$$uiGridIndex;
  9173. }
  9174. // Made it this far, we don't have to worry about null & undefined
  9175. if (direction === uiGridConstants.ASC) {
  9176. return tem;
  9177. } else {
  9178. return 0 - tem;
  9179. }
  9180. };
  9181. var newRows = rows.sort(rowSortFn);
  9182. // remove the custom index field on each row, used to make a stable sort out of unstable sorts (e.g. Chrome)
  9183. var clearIndex = function( row, idx ){
  9184. delete row.entity.$$uiGridIndex;
  9185. };
  9186. rows.forEach(clearIndex);
  9187. return newRows;
  9188. };
  9189. return rowSorter;
  9190. }]);
  9191. })();
  9192. (function() {
  9193. var module = angular.module('ui.grid');
  9194. var bindPolyfill;
  9195. if (typeof Function.prototype.bind !== "function") {
  9196. bindPolyfill = function() {
  9197. var slice = Array.prototype.slice;
  9198. return function(context) {
  9199. var fn = this,
  9200. args = slice.call(arguments, 1);
  9201. if (args.length) {
  9202. return function() {
  9203. return arguments.length ? fn.apply(context, args.concat(slice.call(arguments))) : fn.apply(context, args);
  9204. };
  9205. }
  9206. return function() {
  9207. return arguments.length ? fn.apply(context, arguments) : fn.call(context);
  9208. };
  9209. };
  9210. };
  9211. }
  9212. function getStyles (elem) {
  9213. var e = elem;
  9214. if (typeof(e.length) !== 'undefined' && e.length) {
  9215. e = elem[0];
  9216. }
  9217. return e.ownerDocument.defaultView.getComputedStyle(e, null);
  9218. }
  9219. var rnumnonpx = new RegExp( "^(" + (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source + ")(?!px)[a-z%]+$", "i" ),
  9220. // swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
  9221. // see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
  9222. rdisplayswap = /^(block|none|table(?!-c[ea]).+)/,
  9223. cssShow = { position: "absolute", visibility: "hidden", display: "block" };
  9224. function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
  9225. var i = extra === ( isBorderBox ? 'border' : 'content' ) ?
  9226. // If we already have the right measurement, avoid augmentation
  9227. 4 :
  9228. // Otherwise initialize for horizontal or vertical properties
  9229. name === 'width' ? 1 : 0,
  9230. val = 0;
  9231. var sides = ['Top', 'Right', 'Bottom', 'Left'];
  9232. for ( ; i < 4; i += 2 ) {
  9233. var side = sides[i];
  9234. // dump('side', side);
  9235. // both box models exclude margin, so add it if we want it
  9236. if ( extra === 'margin' ) {
  9237. var marg = parseFloat(styles[extra + side]);
  9238. if (!isNaN(marg)) {
  9239. val += marg;
  9240. }
  9241. }
  9242. // dump('val1', val);
  9243. if ( isBorderBox ) {
  9244. // border-box includes padding, so remove it if we want content
  9245. if ( extra === 'content' ) {
  9246. var padd = parseFloat(styles['padding' + side]);
  9247. if (!isNaN(padd)) {
  9248. val -= padd;
  9249. // dump('val2', val);
  9250. }
  9251. }
  9252. // at this point, extra isn't border nor margin, so remove border
  9253. if ( extra !== 'margin' ) {
  9254. var bordermarg = parseFloat(styles['border' + side + 'Width']);
  9255. if (!isNaN(bordermarg)) {
  9256. val -= bordermarg;
  9257. // dump('val3', val);
  9258. }
  9259. }
  9260. }
  9261. else {
  9262. // at this point, extra isn't content, so add padding
  9263. var nocontentPad = parseFloat(styles['padding' + side]);
  9264. if (!isNaN(nocontentPad)) {
  9265. val += nocontentPad;
  9266. // dump('val4', val);
  9267. }
  9268. // at this point, extra isn't content nor padding, so add border
  9269. if ( extra !== 'padding') {
  9270. var nocontentnopad = parseFloat(styles['border' + side + 'Width']);
  9271. if (!isNaN(nocontentnopad)) {
  9272. val += nocontentnopad;
  9273. // dump('val5', val);
  9274. }
  9275. }
  9276. }
  9277. }
  9278. // dump('augVal', val);
  9279. return val;
  9280. }
  9281. function getWidthOrHeight( elem, name, extra ) {
  9282. // Start with offset property, which is equivalent to the border-box value
  9283. var valueIsBorderBox = true,
  9284. val, // = name === 'width' ? elem.offsetWidth : elem.offsetHeight,
  9285. styles = getStyles(elem),
  9286. isBorderBox = styles['boxSizing'] === 'border-box';
  9287. // some non-html elements return undefined for offsetWidth, so check for null/undefined
  9288. // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
  9289. // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
  9290. if ( val <= 0 || val == null ) {
  9291. // Fall back to computed then uncomputed css if necessary
  9292. val = styles[name];
  9293. if ( val < 0 || val == null ) {
  9294. val = elem.style[ name ];
  9295. }
  9296. // Computed unit is not pixels. Stop here and return.
  9297. if ( rnumnonpx.test(val) ) {
  9298. return val;
  9299. }
  9300. // we need the check for style in case a browser which returns unreliable values
  9301. // for getComputedStyle silently falls back to the reliable elem.style
  9302. valueIsBorderBox = isBorderBox &&
  9303. ( true || val === elem.style[ name ] ); // use 'true' instead of 'support.boxSizingReliable()'
  9304. // Normalize "", auto, and prepare for extra
  9305. val = parseFloat( val ) || 0;
  9306. }
  9307. // use the active box-sizing model to add/subtract irrelevant styles
  9308. var ret = ( val +
  9309. augmentWidthOrHeight(
  9310. elem,
  9311. name,
  9312. extra || ( isBorderBox ? "border" : "content" ),
  9313. valueIsBorderBox,
  9314. styles
  9315. )
  9316. );
  9317. // dump('ret', ret, val);
  9318. return ret;
  9319. }
  9320. function getLineHeight(elm) {
  9321. elm = angular.element(elm)[0];
  9322. var parent = elm.parentElement;
  9323. if (!parent) {
  9324. parent = document.getElementsByTagName('body')[0];
  9325. }
  9326. return parseInt( getStyles(parent).fontSize ) || parseInt( getStyles(elm).fontSize ) || 16;
  9327. }
  9328. var uid = ['0', '0', '0', '0'];
  9329. var uidPrefix = 'uiGrid-';
  9330. /**
  9331. * @ngdoc service
  9332. * @name ui.grid.service:GridUtil
  9333. *
  9334. * @description Grid utility functions
  9335. */
  9336. module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateCache', '$timeout', '$interval', '$injector', '$q', '$interpolate', 'uiGridConstants',
  9337. function ($log, $window, $document, $http, $templateCache, $timeout, $interval, $injector, $q, $interpolate, uiGridConstants) {
  9338. var s = {
  9339. augmentWidthOrHeight: augmentWidthOrHeight,
  9340. getStyles: getStyles,
  9341. /**
  9342. * @ngdoc method
  9343. * @name createBoundedWrapper
  9344. * @methodOf ui.grid.service:GridUtil
  9345. *
  9346. * @param {object} Object to bind 'this' to
  9347. * @param {method} Method to bind
  9348. * @returns {Function} The wrapper that performs the binding
  9349. *
  9350. * @description
  9351. * Binds given method to given object.
  9352. *
  9353. * By means of a wrapper, ensures that ``method`` is always bound to
  9354. * ``object`` regardless of its calling environment.
  9355. * Iow, inside ``method``, ``this`` always points to ``object``.
  9356. *
  9357. * See http://alistapart.com/article/getoutbindingsituations
  9358. *
  9359. */
  9360. createBoundedWrapper: function(object, method) {
  9361. return function() {
  9362. return method.apply(object, arguments);
  9363. };
  9364. },
  9365. /**
  9366. * @ngdoc method
  9367. * @name readableColumnName
  9368. * @methodOf ui.grid.service:GridUtil
  9369. *
  9370. * @param {string} columnName Column name as a string
  9371. * @returns {string} Column name appropriately capitalized and split apart
  9372. *
  9373. @example
  9374. <example module="app">
  9375. <file name="app.js">
  9376. var app = angular.module('app', ['ui.grid']);
  9377. app.controller('MainCtrl', ['$scope', 'gridUtil', function ($scope, gridUtil) {
  9378. $scope.name = 'firstName';
  9379. $scope.columnName = function(name) {
  9380. return gridUtil.readableColumnName(name);
  9381. };
  9382. }]);
  9383. </file>
  9384. <file name="index.html">
  9385. <div ng-controller="MainCtrl">
  9386. <strong>Column name:</strong> <input ng-model="name" />
  9387. <br>
  9388. <strong>Output:</strong> <span ng-bind="columnName(name)"></span>
  9389. </div>
  9390. </file>
  9391. </example>
  9392. */
  9393. readableColumnName: function (columnName) {
  9394. // Convert underscores to spaces
  9395. if (typeof(columnName) === 'undefined' || columnName === undefined || columnName === null) { return columnName; }
  9396. if (typeof(columnName) !== 'string') {
  9397. columnName = String(columnName);
  9398. }
  9399. return columnName.replace(/_+/g, ' ')
  9400. // Replace a completely all-capsed word with a first-letter-capitalized version
  9401. .replace(/^[A-Z]+$/, function (match) {
  9402. return angular.lowercase(angular.uppercase(match.charAt(0)) + match.slice(1));
  9403. })
  9404. // Capitalize the first letter of words
  9405. .replace(/([\w\u00C0-\u017F]+)/g, function (match) {
  9406. return angular.uppercase(match.charAt(0)) + match.slice(1);
  9407. })
  9408. // Put a space in between words that have partial capilizations (i.e. 'firstName' becomes 'First Name')
  9409. // .replace(/([A-Z]|[A-Z]\w+)([A-Z])/g, "$1 $2");
  9410. // .replace(/(\w+?|\w)([A-Z])/g, "$1 $2");
  9411. .replace(/(\w+?(?=[A-Z]))/g, '$1 ');
  9412. },
  9413. /**
  9414. * @ngdoc method
  9415. * @name getColumnsFromData
  9416. * @methodOf ui.grid.service:GridUtil
  9417. * @description Return a list of column names, given a data set
  9418. *
  9419. * @param {string} data Data array for grid
  9420. * @returns {Object} Column definitions with field accessor and column name
  9421. *
  9422. * @example
  9423. <pre>
  9424. var data = [
  9425. { firstName: 'Bob', lastName: 'Jones' },
  9426. { firstName: 'Frank', lastName: 'Smith' }
  9427. ];
  9428. var columnDefs = GridUtil.getColumnsFromData(data, excludeProperties);
  9429. columnDefs == [
  9430. {
  9431. field: 'firstName',
  9432. name: 'First Name'
  9433. },
  9434. {
  9435. field: 'lastName',
  9436. name: 'Last Name'
  9437. }
  9438. ];
  9439. </pre>
  9440. */
  9441. getColumnsFromData: function (data, excludeProperties) {
  9442. var columnDefs = [];
  9443. if (!data || typeof(data[0]) === 'undefined' || data[0] === undefined) { return []; }
  9444. if (angular.isUndefined(excludeProperties)) { excludeProperties = []; }
  9445. var item = data[0];
  9446. angular.forEach(item,function (prop, propName) {
  9447. if ( excludeProperties.indexOf(propName) === -1){
  9448. columnDefs.push({
  9449. name: propName
  9450. });
  9451. }
  9452. });
  9453. return columnDefs;
  9454. },
  9455. /**
  9456. * @ngdoc method
  9457. * @name newId
  9458. * @methodOf ui.grid.service:GridUtil
  9459. * @description Return a unique ID string
  9460. *
  9461. * @returns {string} Unique string
  9462. *
  9463. * @example
  9464. <pre>
  9465. var id = GridUtil.newId();
  9466. # 1387305700482;
  9467. </pre>
  9468. */
  9469. newId: (function() {
  9470. var seedId = new Date().getTime();
  9471. return function() {
  9472. return seedId += 1;
  9473. };
  9474. })(),
  9475. /**
  9476. * @ngdoc method
  9477. * @name getTemplate
  9478. * @methodOf ui.grid.service:GridUtil
  9479. * @description Get's template from cache / element / url
  9480. *
  9481. * @param {string|element|promise} Either a string representing the template id, a string representing the template url,
  9482. * an jQuery/Angualr element, or a promise that returns the template contents to use.
  9483. * @returns {object} a promise resolving to template contents
  9484. *
  9485. * @example
  9486. <pre>
  9487. GridUtil.getTemplate(url).then(function (contents) {
  9488. alert(contents);
  9489. })
  9490. </pre>
  9491. */
  9492. getTemplate: function (template) {
  9493. // Try to fetch the template out of the templateCache
  9494. if ($templateCache.get(template)) {
  9495. return s.postProcessTemplate($templateCache.get(template));
  9496. }
  9497. // See if the template is itself a promise
  9498. if (angular.isFunction(template.then)) {
  9499. return template.then(s.postProcessTemplate).catch(angular.noop);
  9500. }
  9501. // If the template is an element, return the element
  9502. try {
  9503. if (angular.element(template).length > 0) {
  9504. return $q.when(template).then(s.postProcessTemplate).catch(angular.noop);
  9505. }
  9506. }
  9507. catch (err){
  9508. //do nothing; not valid html
  9509. }
  9510. // s.logDebug('fetching url', template);
  9511. // Default to trying to fetch the template as a url with $http
  9512. return $http({ method: 'GET', url: template})
  9513. .then(
  9514. function (result) {
  9515. var templateHtml = result.data.trim();
  9516. //put in templateCache for next call
  9517. $templateCache.put(template, templateHtml);
  9518. return templateHtml;
  9519. },
  9520. function (err) {
  9521. throw new Error("Could not get template " + template + ": " + err);
  9522. }
  9523. )
  9524. .then(s.postProcessTemplate).catch(angular.noop);
  9525. },
  9526. //
  9527. postProcessTemplate: function (template) {
  9528. var startSym = $interpolate.startSymbol(),
  9529. endSym = $interpolate.endSymbol();
  9530. // If either of the interpolation symbols have been changed, we need to alter this template
  9531. if (startSym !== '{{' || endSym !== '}}') {
  9532. template = template.replace(/\{\{/g, startSym);
  9533. template = template.replace(/\}\}/g, endSym);
  9534. }
  9535. return $q.when(template);
  9536. },
  9537. /**
  9538. * @ngdoc method
  9539. * @name guessType
  9540. * @methodOf ui.grid.service:GridUtil
  9541. * @description guesses the type of an argument
  9542. *
  9543. * @param {string/number/bool/object} item variable to examine
  9544. * @returns {string} one of the following
  9545. * - 'string'
  9546. * - 'boolean'
  9547. * - 'number'
  9548. * - 'date'
  9549. * - 'object'
  9550. */
  9551. guessType : function (item) {
  9552. var itemType = typeof(item);
  9553. // Check for numbers and booleans
  9554. switch (itemType) {
  9555. case "number":
  9556. case "boolean":
  9557. case "string":
  9558. return itemType;
  9559. default:
  9560. if (angular.isDate(item)) {
  9561. return "date";
  9562. }
  9563. return "object";
  9564. }
  9565. },
  9566. /**
  9567. * @ngdoc method
  9568. * @name elementWidth
  9569. * @methodOf ui.grid.service:GridUtil
  9570. *
  9571. * @param {element} element DOM element
  9572. * @param {string} [extra] Optional modifier for calculation. Use 'margin' to account for margins on element
  9573. *
  9574. * @returns {number} Element width in pixels, accounting for any borders, etc.
  9575. */
  9576. elementWidth: function (elem) {
  9577. },
  9578. /**
  9579. * @ngdoc method
  9580. * @name elementHeight
  9581. * @methodOf ui.grid.service:GridUtil
  9582. *
  9583. * @param {element} element DOM element
  9584. * @param {string} [extra] Optional modifier for calculation. Use 'margin' to account for margins on element
  9585. *
  9586. * @returns {number} Element height in pixels, accounting for any borders, etc.
  9587. */
  9588. elementHeight: function (elem) {
  9589. },
  9590. // Thanks to http://stackoverflow.com/a/13382873/888165
  9591. getScrollbarWidth: function() {
  9592. var outer = document.createElement("div");
  9593. outer.style.visibility = "hidden";
  9594. outer.style.width = "100px";
  9595. outer.style.msOverflowStyle = "scrollbar"; // needed for WinJS apps
  9596. document.body.appendChild(outer);
  9597. var widthNoScroll = outer.offsetWidth;
  9598. // force scrollbars
  9599. outer.style.overflow = "scroll";
  9600. // add innerdiv
  9601. var inner = document.createElement("div");
  9602. inner.style.width = "100%";
  9603. outer.appendChild(inner);
  9604. var widthWithScroll = inner.offsetWidth;
  9605. // remove divs
  9606. outer.parentNode.removeChild(outer);
  9607. return widthNoScroll - widthWithScroll;
  9608. },
  9609. swap: function( elem, options, callback, args ) {
  9610. var ret, name,
  9611. old = {};
  9612. // Remember the old values, and insert the new ones
  9613. for ( name in options ) {
  9614. old[ name ] = elem.style[ name ];
  9615. elem.style[ name ] = options[ name ];
  9616. }
  9617. ret = callback.apply( elem, args || [] );
  9618. // Revert the old values
  9619. for ( name in options ) {
  9620. elem.style[ name ] = old[ name ];
  9621. }
  9622. return ret;
  9623. },
  9624. fakeElement: function( elem, options, callback, args ) {
  9625. var ret, name,
  9626. newElement = angular.element(elem).clone()[0];
  9627. for ( name in options ) {
  9628. newElement.style[ name ] = options[ name ];
  9629. }
  9630. angular.element(document.body).append(newElement);
  9631. ret = callback.call( newElement, newElement );
  9632. angular.element(newElement).remove();
  9633. return ret;
  9634. },
  9635. /**
  9636. * @ngdoc method
  9637. * @name normalizeWheelEvent
  9638. * @methodOf ui.grid.service:GridUtil
  9639. *
  9640. * @param {event} event A mouse wheel event
  9641. *
  9642. * @returns {event} A normalized event
  9643. *
  9644. * @description
  9645. * Given an event from this list:
  9646. *
  9647. * `wheel, mousewheel, DomMouseScroll, MozMousePixelScroll`
  9648. *
  9649. * "normalize" it
  9650. * so that it stays consistent no matter what browser it comes from (i.e. scale it correctly and make sure the direction is right.)
  9651. */
  9652. normalizeWheelEvent: function (event) {
  9653. // var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'];
  9654. // var toBind = 'onwheel' in document || document.documentMode >= 9 ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'];
  9655. var lowestDelta, lowestDeltaXY;
  9656. var orgEvent = event || window.event,
  9657. args = [].slice.call(arguments, 1),
  9658. delta = 0,
  9659. deltaX = 0,
  9660. deltaY = 0,
  9661. absDelta = 0,
  9662. absDeltaXY = 0,
  9663. fn;
  9664. // event = $.event.fix(orgEvent);
  9665. // event.type = 'mousewheel';
  9666. // NOTE: jQuery masks the event and stores it in the event as originalEvent
  9667. if (orgEvent.originalEvent) {
  9668. orgEvent = orgEvent.originalEvent;
  9669. }
  9670. // Old school scrollwheel delta
  9671. if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta; }
  9672. if ( orgEvent.detail ) { delta = orgEvent.detail * -1; }
  9673. // At a minimum, setup the deltaY to be delta
  9674. deltaY = delta;
  9675. // Firefox < 17 related to DOMMouseScroll event
  9676. if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
  9677. deltaY = 0;
  9678. deltaX = delta * -1;
  9679. }
  9680. // New school wheel delta (wheel event)
  9681. if ( orgEvent.deltaY ) {
  9682. deltaY = orgEvent.deltaY * -1;
  9683. delta = deltaY;
  9684. }
  9685. if ( orgEvent.deltaX ) {
  9686. deltaX = orgEvent.deltaX;
  9687. delta = deltaX * -1;
  9688. }
  9689. // Webkit
  9690. if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY; }
  9691. if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = orgEvent.wheelDeltaX; }
  9692. // Look for lowest delta to normalize the delta values
  9693. absDelta = Math.abs(delta);
  9694. if ( !lowestDelta || absDelta < lowestDelta ) { lowestDelta = absDelta; }
  9695. absDeltaXY = Math.max(Math.abs(deltaY), Math.abs(deltaX));
  9696. if ( !lowestDeltaXY || absDeltaXY < lowestDeltaXY ) { lowestDeltaXY = absDeltaXY; }
  9697. // Get a whole value for the deltas
  9698. fn = delta > 0 ? 'floor' : 'ceil';
  9699. delta = Math[fn](delta / lowestDelta);
  9700. deltaX = Math[fn](deltaX / lowestDeltaXY);
  9701. deltaY = Math[fn](deltaY / lowestDeltaXY);
  9702. return {
  9703. delta: delta,
  9704. deltaX: deltaX,
  9705. deltaY: deltaY
  9706. };
  9707. },
  9708. // Stolen from Modernizr
  9709. // TODO: make this, and everythign that flows from it, robust
  9710. //http://www.stucox.com/blog/you-cant-detect-a-touchscreen/
  9711. isTouchEnabled: function() {
  9712. var bool;
  9713. if (('ontouchstart' in $window) || $window.DocumentTouch && $document instanceof DocumentTouch) {
  9714. bool = true;
  9715. }
  9716. return bool;
  9717. },
  9718. isNullOrUndefined: function(obj) {
  9719. return (obj === undefined || obj === null);
  9720. },
  9721. endsWith: function(str, suffix) {
  9722. if (!str || !suffix || typeof str !== "string") {
  9723. return false;
  9724. }
  9725. return str.indexOf(suffix, str.length - suffix.length) !== -1;
  9726. },
  9727. arrayContainsObjectWithProperty: function(array, propertyName, propertyValue) {
  9728. var found = false;
  9729. angular.forEach(array, function (object) {
  9730. if (object[propertyName] === propertyValue) {
  9731. found = true;
  9732. }
  9733. });
  9734. return found;
  9735. },
  9736. //// Shim requestAnimationFrame
  9737. //requestAnimationFrame: $window.requestAnimationFrame && $window.requestAnimationFrame.bind($window) ||
  9738. // $window.webkitRequestAnimationFrame && $window.webkitRequestAnimationFrame.bind($window) ||
  9739. // function(fn) {
  9740. // return $timeout(fn, 10, false);
  9741. // },
  9742. numericAndNullSort: function (a, b) {
  9743. if (a === null) { return 1; }
  9744. if (b === null) { return -1; }
  9745. if (a === null && b === null) { return 0; }
  9746. return a - b;
  9747. },
  9748. // Disable ngAnimate animations on an element
  9749. disableAnimations: function (element) {
  9750. var $animate;
  9751. try {
  9752. $animate = $injector.get('$animate');
  9753. // See: http://brianhann.com/angular-1-4-breaking-changes-to-be-aware-of/#animate
  9754. if (angular.version.major > 1 || (angular.version.major === 1 && angular.version.minor >= 4)) {
  9755. $animate.enabled(element, false);
  9756. } else {
  9757. $animate.enabled(false, element);
  9758. }
  9759. }
  9760. catch (e) {}
  9761. },
  9762. enableAnimations: function (element) {
  9763. var $animate;
  9764. try {
  9765. $animate = $injector.get('$animate');
  9766. // See: http://brianhann.com/angular-1-4-breaking-changes-to-be-aware-of/#animate
  9767. if (angular.version.major > 1 || (angular.version.major === 1 && angular.version.minor >= 4)) {
  9768. $animate.enabled(element, true);
  9769. } else {
  9770. $animate.enabled(true, element);
  9771. }
  9772. return $animate;
  9773. }
  9774. catch (e) {}
  9775. },
  9776. // Blatantly stolen from Angular as it isn't exposed (yet)
  9777. nextUid: function nextUid() {
  9778. var index = uid.length;
  9779. var digit;
  9780. while (index) {
  9781. index--;
  9782. digit = uid[index].charCodeAt(0);
  9783. if (digit === 57 /*'9'*/) {
  9784. uid[index] = 'A';
  9785. return uidPrefix + uid.join('');
  9786. }
  9787. if (digit === 90 /*'Z'*/) {
  9788. uid[index] = '0';
  9789. } else {
  9790. uid[index] = String.fromCharCode(digit + 1);
  9791. return uidPrefix + uid.join('');
  9792. }
  9793. }
  9794. uid.unshift('0');
  9795. return uidPrefix + uid.join('');
  9796. },
  9797. // Blatantly stolen from Angular as it isn't exposed (yet)
  9798. hashKey: function hashKey(obj) {
  9799. var objType = typeof obj,
  9800. key;
  9801. if (objType === 'object' && obj !== null) {
  9802. if (typeof (key = obj.$$hashKey) === 'function') {
  9803. // must invoke on object to keep the right this
  9804. key = obj.$$hashKey();
  9805. }
  9806. else if (typeof(obj.$$hashKey) !== 'undefined' && obj.$$hashKey) {
  9807. key = obj.$$hashKey;
  9808. }
  9809. else if (key === undefined) {
  9810. key = obj.$$hashKey = s.nextUid();
  9811. }
  9812. }
  9813. else {
  9814. key = obj;
  9815. }
  9816. return objType + ':' + key;
  9817. },
  9818. resetUids: function () {
  9819. uid = ['0', '0', '0'];
  9820. },
  9821. /**
  9822. * @ngdoc method
  9823. * @methodOf ui.grid.service:GridUtil
  9824. * @name logError
  9825. * @description wraps the $log method, allowing us to choose different
  9826. * treatment within ui-grid if we so desired. At present we only log
  9827. * error messages if uiGridConstants.LOG_ERROR_MESSAGES is set to true
  9828. * @param {string} logMessage message to be logged to the console
  9829. *
  9830. */
  9831. logError: function( logMessage ){
  9832. if ( uiGridConstants.LOG_ERROR_MESSAGES ){
  9833. $log.error( logMessage );
  9834. }
  9835. },
  9836. /**
  9837. * @ngdoc method
  9838. * @methodOf ui.grid.service:GridUtil
  9839. * @name logWarn
  9840. * @description wraps the $log method, allowing us to choose different
  9841. * treatment within ui-grid if we so desired. At present we only log
  9842. * warning messages if uiGridConstants.LOG_WARN_MESSAGES is set to true
  9843. * @param {string} logMessage message to be logged to the console
  9844. *
  9845. */
  9846. logWarn: function( logMessage ){
  9847. if ( uiGridConstants.LOG_WARN_MESSAGES ){
  9848. $log.warn( logMessage );
  9849. }
  9850. },
  9851. /**
  9852. * @ngdoc method
  9853. * @methodOf ui.grid.service:GridUtil
  9854. * @name logDebug
  9855. * @description wraps the $log method, allowing us to choose different
  9856. * treatment within ui-grid if we so desired. At present we only log
  9857. * debug messages if uiGridConstants.LOG_DEBUG_MESSAGES is set to true
  9858. *
  9859. */
  9860. logDebug: function() {
  9861. if ( uiGridConstants.LOG_DEBUG_MESSAGES ){
  9862. $log.debug.apply($log, arguments);
  9863. }
  9864. }
  9865. };
  9866. /**
  9867. * @ngdoc object
  9868. * @name focus
  9869. * @propertyOf ui.grid.service:GridUtil
  9870. * @description Provies a set of methods to set the document focus inside the grid.
  9871. * See {@link ui.grid.service:GridUtil.focus} for more information.
  9872. */
  9873. /**
  9874. * @ngdoc object
  9875. * @name ui.grid.service:GridUtil.focus
  9876. * @description Provies a set of methods to set the document focus inside the grid.
  9877. * Timeouts are utilized to ensure that the focus is invoked after any other event has been triggered.
  9878. * e.g. click events that need to run before the focus or
  9879. * inputs elements that are in a disabled state but are enabled when those events
  9880. * are triggered.
  9881. */
  9882. s.focus = {
  9883. queue: [],
  9884. //http://stackoverflow.com/questions/25596399/set-element-focus-in-angular-way
  9885. /**
  9886. * @ngdoc method
  9887. * @methodOf ui.grid.service:GridUtil.focus
  9888. * @name byId
  9889. * @description Sets the focus of the document to the given id value.
  9890. * If provided with the grid object it will automatically append the grid id.
  9891. * This is done to encourage unique dom id's as it allows for multiple grids on a
  9892. * page.
  9893. * @param {String} id the id of the dom element to set the focus on
  9894. * @param {Object=} Grid the grid object for this grid instance. See: {@link ui.grid.class:Grid}
  9895. * @param {Number} Grid.id the unique id for this grid. Already set on an initialized grid object.
  9896. * @returns {Promise} The `$timeout` promise that will be resolved once focus is set. If another focus is requested before this request is evaluated.
  9897. * then the promise will fail with the `'canceled'` reason.
  9898. */
  9899. byId: function (id, Grid) {
  9900. this._purgeQueue();
  9901. var promise = $timeout(function() {
  9902. var elementID = (Grid && Grid.id ? Grid.id + '-' : '') + id;
  9903. var element = $window.document.getElementById(elementID);
  9904. if (element) {
  9905. element.focus();
  9906. } else {
  9907. s.logWarn('[focus.byId] Element id ' + elementID + ' was not found.');
  9908. }
  9909. }, 0, false);
  9910. this.queue.push(promise);
  9911. return promise;
  9912. },
  9913. /**
  9914. * @ngdoc method
  9915. * @methodOf ui.grid.service:GridUtil.focus
  9916. * @name byElement
  9917. * @description Sets the focus of the document to the given dom element.
  9918. * @param {(element|angular.element)} element the DOM element to set the focus on
  9919. * @returns {Promise} The `$timeout` promise that will be resolved once focus is set. If another focus is requested before this request is evaluated.
  9920. * then the promise will fail with the `'canceled'` reason.
  9921. */
  9922. byElement: function(element){
  9923. if (!angular.isElement(element)){
  9924. s.logWarn("Trying to focus on an element that isn\'t an element.");
  9925. return $q.reject('not-element');
  9926. }
  9927. element = angular.element(element);
  9928. this._purgeQueue();
  9929. var promise = $timeout(function(){
  9930. if (element){
  9931. element[0].focus();
  9932. }
  9933. }, 0, false);
  9934. this.queue.push(promise);
  9935. return promise;
  9936. },
  9937. /**
  9938. * @ngdoc method
  9939. * @methodOf ui.grid.service:GridUtil.focus
  9940. * @name bySelector
  9941. * @description Sets the focus of the document to the given dom element.
  9942. * @param {(element|angular.element)} parentElement the parent/ancestor of the dom element that you are selecting using the query selector
  9943. * @param {String} querySelector finds the dom element using the {@link http://www.w3schools.com/jsref/met_document_queryselector.asp querySelector}
  9944. * @param {boolean} [aSync=false] If true then the selector will be querried inside of a timeout. Otherwise the selector will be querried imidately
  9945. * then the focus will be called.
  9946. * @returns {Promise} The `$timeout` promise that will be resolved once focus is set. If another focus is requested before this request is evaluated.
  9947. * then the promise will fail with the `'canceled'` reason.
  9948. */
  9949. bySelector: function(parentElement, querySelector, aSync){
  9950. var self = this;
  9951. if (!angular.isElement(parentElement)){
  9952. throw new Error("The parent element is not an element.");
  9953. }
  9954. // Ensure that this is an angular element.
  9955. // It is fine if this is already an angular element.
  9956. parentElement = angular.element(parentElement);
  9957. var focusBySelector = function(){
  9958. var element = parentElement[0].querySelector(querySelector);
  9959. return self.byElement(element);
  9960. };
  9961. this._purgeQueue();
  9962. if (aSync){ //Do this asynchronysly
  9963. var promise = $timeout(focusBySelector, 0, false);
  9964. this.queue.push(promise);
  9965. return promise;
  9966. } else {
  9967. return focusBySelector();
  9968. }
  9969. },
  9970. _purgeQueue: function(){
  9971. this.queue.forEach(function(element){
  9972. $timeout.cancel(element);
  9973. });
  9974. this.queue = [];
  9975. }
  9976. };
  9977. ['width', 'height'].forEach(function (name) {
  9978. var capsName = angular.uppercase(name.charAt(0)) + name.substr(1);
  9979. s['element' + capsName] = function (elem, extra) {
  9980. var e = elem;
  9981. if (e && typeof(e.length) !== 'undefined' && e.length) {
  9982. e = elem[0];
  9983. }
  9984. if (e && e !== null) {
  9985. var styles = getStyles(e);
  9986. return e.offsetWidth === 0 && rdisplayswap.test(styles.display) ?
  9987. s.swap(e, cssShow, function() {
  9988. return getWidthOrHeight(e, name, extra );
  9989. }) :
  9990. getWidthOrHeight( e, name, extra );
  9991. }
  9992. else {
  9993. return null;
  9994. }
  9995. };
  9996. s['outerElement' + capsName] = function (elem, margin) {
  9997. return elem ? s['element' + capsName].call(this, elem, margin ? 'margin' : 'border') : null;
  9998. };
  9999. });
  10000. // http://stackoverflow.com/a/24107550/888165
  10001. s.closestElm = function closestElm(el, selector) {
  10002. if (typeof(el.length) !== 'undefined' && el.length) {
  10003. el = el[0];
  10004. }
  10005. var matchesFn;
  10006. // find vendor prefix
  10007. ['matches','webkitMatchesSelector','mozMatchesSelector','msMatchesSelector','oMatchesSelector'].some(function(fn) {
  10008. if (typeof document.body[fn] === 'function') {
  10009. matchesFn = fn;
  10010. return true;
  10011. }
  10012. return false;
  10013. });
  10014. // traverse parents
  10015. var parent;
  10016. while (el !== null) {
  10017. parent = el.parentElement;
  10018. if (parent !== null && parent[matchesFn](selector)) {
  10019. return parent;
  10020. }
  10021. el = parent;
  10022. }
  10023. return null;
  10024. };
  10025. s.type = function (obj) {
  10026. var text = Function.prototype.toString.call(obj.constructor);
  10027. return text.match(/function (.*?)\(/)[1];
  10028. };
  10029. s.getBorderSize = function getBorderSize(elem, borderType) {
  10030. if (typeof(elem.length) !== 'undefined' && elem.length) {
  10031. elem = elem[0];
  10032. }
  10033. var styles = getStyles(elem);
  10034. // If a specific border is supplied, like 'top', read the 'borderTop' style property
  10035. if (borderType) {
  10036. borderType = 'border' + borderType.charAt(0).toUpperCase() + borderType.slice(1);
  10037. }
  10038. else {
  10039. borderType = 'border';
  10040. }
  10041. borderType += 'Width';
  10042. var val = parseInt(styles[borderType], 10);
  10043. if (isNaN(val)) {
  10044. return 0;
  10045. }
  10046. else {
  10047. return val;
  10048. }
  10049. };
  10050. // http://stackoverflow.com/a/22948274/888165
  10051. // TODO: Opera? Mobile?
  10052. s.detectBrowser = function detectBrowser() {
  10053. var userAgent = $window.navigator.userAgent;
  10054. var browsers = {chrome: /chrome/i, safari: /safari/i, firefox: /firefox/i, ie: /internet explorer|trident\//i};
  10055. for (var key in browsers) {
  10056. if (browsers[key].test(userAgent)) {
  10057. return key;
  10058. }
  10059. }
  10060. return 'unknown';
  10061. };
  10062. // Borrowed from https://github.com/othree/jquery.rtl-scroll-type
  10063. // Determine the scroll "type" this browser is using for RTL
  10064. s.rtlScrollType = function rtlScrollType() {
  10065. if (rtlScrollType.type) {
  10066. return rtlScrollType.type;
  10067. }
  10068. var definer = angular.element('<div dir="rtl" style="font-size: 14px; width: 1px; height: 1px; position: absolute; top: -1000px; overflow: scroll">A</div>')[0],
  10069. type = 'reverse';
  10070. document.body.appendChild(definer);
  10071. if (definer.scrollLeft > 0) {
  10072. type = 'default';
  10073. }
  10074. else {
  10075. definer.scrollLeft = 1;
  10076. if (definer.scrollLeft === 0) {
  10077. type = 'negative';
  10078. }
  10079. }
  10080. angular.element(definer).remove();
  10081. rtlScrollType.type = type;
  10082. return type;
  10083. };
  10084. /**
  10085. * @ngdoc method
  10086. * @name normalizeScrollLeft
  10087. * @methodOf ui.grid.service:GridUtil
  10088. *
  10089. * @param {element} element The element to get the `scrollLeft` from.
  10090. * @param {grid} grid - grid used to normalize (uses the rtl property)
  10091. *
  10092. * @returns {number} A normalized scrollLeft value for the current browser.
  10093. *
  10094. * @description
  10095. * Browsers currently handle RTL in different ways, resulting in inconsistent scrollLeft values. This method normalizes them
  10096. */
  10097. s.normalizeScrollLeft = function normalizeScrollLeft(element, grid) {
  10098. if (typeof(element.length) !== 'undefined' && element.length) {
  10099. element = element[0];
  10100. }
  10101. var scrollLeft = element.scrollLeft;
  10102. if (grid.isRTL()) {
  10103. switch (s.rtlScrollType()) {
  10104. case 'default':
  10105. return element.scrollWidth - scrollLeft - element.clientWidth;
  10106. case 'negative':
  10107. return Math.abs(scrollLeft);
  10108. case 'reverse':
  10109. return scrollLeft;
  10110. }
  10111. }
  10112. return scrollLeft;
  10113. };
  10114. /**
  10115. * @ngdoc method
  10116. * @name denormalizeScrollLeft
  10117. * @methodOf ui.grid.service:GridUtil
  10118. *
  10119. * @param {element} element The element to normalize the `scrollLeft` value for
  10120. * @param {number} scrollLeft The `scrollLeft` value to denormalize.
  10121. * @param {grid} grid The grid that owns the scroll event.
  10122. *
  10123. * @returns {number} A normalized scrollLeft value for the current browser.
  10124. *
  10125. * @description
  10126. * Browsers currently handle RTL in different ways, resulting in inconsistent scrollLeft values. This method denormalizes a value for the current browser.
  10127. */
  10128. s.denormalizeScrollLeft = function denormalizeScrollLeft(element, scrollLeft, grid) {
  10129. if (typeof(element.length) !== 'undefined' && element.length) {
  10130. element = element[0];
  10131. }
  10132. if (grid.isRTL()) {
  10133. switch (s.rtlScrollType()) {
  10134. case 'default':
  10135. // Get the max scroll for the element
  10136. var maxScrollLeft = element.scrollWidth - element.clientWidth;
  10137. // Subtract the current scroll amount from the max scroll
  10138. return maxScrollLeft - scrollLeft;
  10139. case 'negative':
  10140. return scrollLeft * -1;
  10141. case 'reverse':
  10142. return scrollLeft;
  10143. }
  10144. }
  10145. return scrollLeft;
  10146. };
  10147. /**
  10148. * @ngdoc method
  10149. * @name preEval
  10150. * @methodOf ui.grid.service:GridUtil
  10151. *
  10152. * @param {string} path Path to evaluate
  10153. *
  10154. * @returns {string} A path that is normalized.
  10155. *
  10156. * @description
  10157. * Takes a field path and converts it to bracket notation to allow for special characters in path
  10158. * @example
  10159. * <pre>
  10160. * gridUtil.preEval('property') == 'property'
  10161. * gridUtil.preEval('nested.deep.prop-erty') = "nested['deep']['prop-erty']"
  10162. * </pre>
  10163. */
  10164. s.preEval = function (path) {
  10165. var m = uiGridConstants.BRACKET_REGEXP.exec(path);
  10166. if (m) {
  10167. return (m[1] ? s.preEval(m[1]) : m[1]) + m[2] + (m[3] ? s.preEval(m[3]) : m[3]);
  10168. } else {
  10169. path = path.replace(uiGridConstants.APOS_REGEXP, '\\\'');
  10170. var parts = path.split(uiGridConstants.DOT_REGEXP);
  10171. var preparsed = [parts.shift()]; // first item must be var notation, thus skip
  10172. angular.forEach(parts, function (part) {
  10173. preparsed.push(part.replace(uiGridConstants.FUNC_REGEXP, '\']$1'));
  10174. });
  10175. return preparsed.join('[\'');
  10176. }
  10177. };
  10178. /**
  10179. * @ngdoc method
  10180. * @name debounce
  10181. * @methodOf ui.grid.service:GridUtil
  10182. *
  10183. * @param {function} func function to debounce
  10184. * @param {number} wait milliseconds to delay
  10185. * @param {boolean} immediate execute before delay
  10186. *
  10187. * @returns {function} A function that can be executed as debounced function
  10188. *
  10189. * @description
  10190. * Copied from https://github.com/shahata/angular-debounce
  10191. * Takes a function, decorates it to execute only 1 time after multiple calls, and returns the decorated function
  10192. * @example
  10193. * <pre>
  10194. * var debouncedFunc = gridUtil.debounce(function(){alert('debounced');}, 500);
  10195. * debouncedFunc();
  10196. * debouncedFunc();
  10197. * debouncedFunc();
  10198. * </pre>
  10199. */
  10200. s.debounce = function (func, wait, immediate) {
  10201. var timeout, args, context, result;
  10202. function debounce() {
  10203. /* jshint validthis:true */
  10204. context = this;
  10205. args = arguments;
  10206. var later = function () {
  10207. timeout = null;
  10208. if (!immediate) {
  10209. result = func.apply(context, args);
  10210. }
  10211. };
  10212. var callNow = immediate && !timeout;
  10213. if (timeout) {
  10214. $timeout.cancel(timeout);
  10215. }
  10216. timeout = $timeout(later, wait, false);
  10217. if (callNow) {
  10218. result = func.apply(context, args);
  10219. }
  10220. return result;
  10221. }
  10222. debounce.cancel = function () {
  10223. $timeout.cancel(timeout);
  10224. timeout = null;
  10225. };
  10226. return debounce;
  10227. };
  10228. /**
  10229. * @ngdoc method
  10230. * @name throttle
  10231. * @methodOf ui.grid.service:GridUtil
  10232. *
  10233. * @param {function} func function to throttle
  10234. * @param {number} wait milliseconds to delay after first trigger
  10235. * @param {Object} params to use in throttle.
  10236. *
  10237. * @returns {function} A function that can be executed as throttled function
  10238. *
  10239. * @description
  10240. * Adapted from debounce function (above)
  10241. * Potential keys for Params Object are:
  10242. * trailing (bool) - whether to trigger after throttle time ends if called multiple times
  10243. * Updated to use $interval rather than $timeout, as protractor (e2e tests) is able to work with $interval,
  10244. * but not with $timeout
  10245. *
  10246. * Note that when using throttle, you need to use throttle to create a new function upfront, then use the function
  10247. * return from that call each time you need to call throttle. If you call throttle itself repeatedly, the lastCall
  10248. * variable will get overwritten and the throttling won't work
  10249. *
  10250. * @example
  10251. * <pre>
  10252. * var throttledFunc = gridUtil.throttle(function(){console.log('throttled');}, 500, {trailing: true});
  10253. * throttledFunc(); //=> logs throttled
  10254. * throttledFunc(); //=> queues attempt to log throttled for ~500ms (since trailing param is truthy)
  10255. * throttledFunc(); //=> updates arguments to keep most-recent request, but does not do anything else.
  10256. * </pre>
  10257. */
  10258. s.throttle = function(func, wait, options){
  10259. options = options || {};
  10260. var lastCall = 0, queued = null, context, args;
  10261. function runFunc(endDate){
  10262. lastCall = +new Date();
  10263. func.apply(context, args);
  10264. $interval(function(){queued = null; }, 0, 1, false);
  10265. }
  10266. return function(){
  10267. /* jshint validthis:true */
  10268. context = this;
  10269. args = arguments;
  10270. if (queued === null){
  10271. var sinceLast = +new Date() - lastCall;
  10272. if (sinceLast > wait){
  10273. runFunc();
  10274. }
  10275. else if (options.trailing){
  10276. queued = $interval(runFunc, wait - sinceLast, 1, false);
  10277. }
  10278. }
  10279. };
  10280. };
  10281. s.on = {};
  10282. s.off = {};
  10283. s._events = {};
  10284. s.addOff = function (eventName) {
  10285. s.off[eventName] = function (elm, fn) {
  10286. var idx = s._events[eventName].indexOf(fn);
  10287. if (idx > 0) {
  10288. s._events[eventName].removeAt(idx);
  10289. }
  10290. };
  10291. };
  10292. var mouseWheeltoBind = ( 'onwheel' in document || document.documentMode >= 9 ) ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
  10293. nullLowestDeltaTimeout,
  10294. lowestDelta;
  10295. s.on.mousewheel = function (elm, fn) {
  10296. if (!elm || !fn) { return; }
  10297. var $elm = angular.element(elm);
  10298. // Store the line height and page height for this particular element
  10299. $elm.data('mousewheel-line-height', getLineHeight($elm));
  10300. $elm.data('mousewheel-page-height', s.elementHeight($elm));
  10301. if (!$elm.data('mousewheel-callbacks')) { $elm.data('mousewheel-callbacks', {}); }
  10302. var cbs = $elm.data('mousewheel-callbacks');
  10303. cbs[fn] = (Function.prototype.bind || bindPolyfill).call(mousewheelHandler, $elm[0], fn);
  10304. // Bind all the mousew heel events
  10305. for ( var i = mouseWheeltoBind.length; i; ) {
  10306. $elm.on(mouseWheeltoBind[--i], cbs[fn]);
  10307. }
  10308. $elm.on('$destroy', function unbindEvents() {
  10309. for ( var i = mouseWheeltoBind.length; i; ) {
  10310. $elm.off(mouseWheeltoBind[--i], cbs[fn]);
  10311. }
  10312. });
  10313. };
  10314. s.off.mousewheel = function (elm, fn) {
  10315. var $elm = angular.element(elm);
  10316. var cbs = $elm.data('mousewheel-callbacks');
  10317. var handler = cbs[fn];
  10318. if (handler) {
  10319. for ( var i = mouseWheeltoBind.length; i; ) {
  10320. $elm.off(mouseWheeltoBind[--i], handler);
  10321. }
  10322. }
  10323. delete cbs[fn];
  10324. if (Object.keys(cbs).length === 0) {
  10325. $elm.removeData('mousewheel-line-height');
  10326. $elm.removeData('mousewheel-page-height');
  10327. $elm.removeData('mousewheel-callbacks');
  10328. }
  10329. };
  10330. function mousewheelHandler(fn, event) {
  10331. var $elm = angular.element(this);
  10332. var delta = 0,
  10333. deltaX = 0,
  10334. deltaY = 0,
  10335. absDelta = 0,
  10336. offsetX = 0,
  10337. offsetY = 0;
  10338. // jQuery masks events
  10339. if (event.originalEvent) { event = event.originalEvent; }
  10340. if ( 'detail' in event ) { deltaY = event.detail * -1; }
  10341. if ( 'wheelDelta' in event ) { deltaY = event.wheelDelta; }
  10342. if ( 'wheelDeltaY' in event ) { deltaY = event.wheelDeltaY; }
  10343. if ( 'wheelDeltaX' in event ) { deltaX = event.wheelDeltaX * -1; }
  10344. // Firefox < 17 horizontal scrolling related to DOMMouseScroll event
  10345. if ( 'axis' in event && event.axis === event.HORIZONTAL_AXIS ) {
  10346. deltaX = deltaY * -1;
  10347. deltaY = 0;
  10348. }
  10349. // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy
  10350. delta = deltaY === 0 ? deltaX : deltaY;
  10351. // New school wheel delta (wheel event)
  10352. if ( 'deltaY' in event ) {
  10353. deltaY = event.deltaY * -1;
  10354. delta = deltaY;
  10355. }
  10356. if ( 'deltaX' in event ) {
  10357. deltaX = event.deltaX;
  10358. if ( deltaY === 0 ) { delta = deltaX * -1; }
  10359. }
  10360. // No change actually happened, no reason to go any further
  10361. if ( deltaY === 0 && deltaX === 0 ) { return; }
  10362. // Need to convert lines and pages to pixels if we aren't already in pixels
  10363. // There are three delta modes:
  10364. // * deltaMode 0 is by pixels, nothing to do
  10365. // * deltaMode 1 is by lines
  10366. // * deltaMode 2 is by pages
  10367. if ( event.deltaMode === 1 ) {
  10368. var lineHeight = $elm.data('mousewheel-line-height');
  10369. delta *= lineHeight;
  10370. deltaY *= lineHeight;
  10371. deltaX *= lineHeight;
  10372. }
  10373. else if ( event.deltaMode === 2 ) {
  10374. var pageHeight = $elm.data('mousewheel-page-height');
  10375. delta *= pageHeight;
  10376. deltaY *= pageHeight;
  10377. deltaX *= pageHeight;
  10378. }
  10379. // Store lowest absolute delta to normalize the delta values
  10380. absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
  10381. if ( !lowestDelta || absDelta < lowestDelta ) {
  10382. lowestDelta = absDelta;
  10383. // Adjust older deltas if necessary
  10384. if ( shouldAdjustOldDeltas(event, absDelta) ) {
  10385. lowestDelta /= 40;
  10386. }
  10387. }
  10388. // Get a whole, normalized value for the deltas
  10389. delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
  10390. deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
  10391. deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
  10392. // Normalise offsetX and offsetY properties
  10393. // if ($elm[0].getBoundingClientRect ) {
  10394. // var boundingRect = $(elm)[0].getBoundingClientRect();
  10395. // offsetX = event.clientX - boundingRect.left;
  10396. // offsetY = event.clientY - boundingRect.top;
  10397. // }
  10398. // event.deltaX = deltaX;
  10399. // event.deltaY = deltaY;
  10400. // event.deltaFactor = lowestDelta;
  10401. var newEvent = {
  10402. originalEvent: event,
  10403. deltaX: deltaX,
  10404. deltaY: deltaY,
  10405. deltaFactor: lowestDelta,
  10406. preventDefault: function () { event.preventDefault(); },
  10407. stopPropagation: function () { event.stopPropagation(); }
  10408. };
  10409. // Clearout lowestDelta after sometime to better
  10410. // handle multiple device types that give
  10411. // a different lowestDelta
  10412. // Ex: trackpad = 3 and mouse wheel = 120
  10413. if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
  10414. nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
  10415. fn.call($elm[0], newEvent);
  10416. }
  10417. function nullLowestDelta() {
  10418. lowestDelta = null;
  10419. }
  10420. function shouldAdjustOldDeltas(orgEvent, absDelta) {
  10421. // If this is an older event and the delta is divisable by 120,
  10422. // then we are assuming that the browser is treating this as an
  10423. // older mouse wheel event and that we should divide the deltas
  10424. // by 40 to try and get a more usable deltaFactor.
  10425. // Side note, this actually impacts the reported scroll distance
  10426. // in older browsers and can cause scrolling to be slower than native.
  10427. // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.
  10428. return orgEvent.type === 'mousewheel' && absDelta % 120 === 0;
  10429. }
  10430. return s;
  10431. }]);
  10432. // Add 'px' to the end of a number string if it doesn't have it already
  10433. module.filter('px', function() {
  10434. return function(str) {
  10435. if (str.match(/^[\d\.]+$/)) {
  10436. return str + 'px';
  10437. }
  10438. else {
  10439. return str;
  10440. }
  10441. };
  10442. });
  10443. })();
  10444. (function () {
  10445. angular.module('ui.grid').config(['$provide', function($provide) {
  10446. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10447. $delegate.add('ar', {
  10448. "headerCell": {
  10449. "aria": {
  10450. "defaultFilterLabel": "التصفيه بالعمود",
  10451. "removeFilter": "محو التصفيه",
  10452. "columnMenuButtonLabel": "قاءمه الاعمده"
  10453. },
  10454. "priority": "أولويه : ",
  10455. "filterLabel": "تصفيه بالاعمده :"
  10456. },
  10457. "aggregate": {
  10458. "label": "العناصر"
  10459. },
  10460. "groupPanel": {
  10461. "description": "اسحب رأس العمود هنا وأسقطه لإنشاء مجموعه"
  10462. },
  10463. "search": {
  10464. "placeholder": "بحث ...",
  10465. "showingItems": "العناصر الظاهره :",
  10466. "selectedItems": "العناصر المحدده :",
  10467. "totalItems": "عدد العناصر :",
  10468. "size": "حجم الصفحه :",
  10469. "first": "اول صفحه",
  10470. "next": "الصفحه التاليه",
  10471. "previous": "الصفحه الصابقه",
  10472. "last": "الصفحه الاخيره"
  10473. },
  10474. "menu": {
  10475. "text": "اختيار العمود :"
  10476. },
  10477. "sort": {
  10478. "ascending": "ترتيب تصاعدى",
  10479. "descending": "ترتيب تنازلى",
  10480. "none": "عدم التحديد",
  10481. "remove": "حذف الترتيب"
  10482. },
  10483. "column": {
  10484. "hide": "إخفاء عمود"
  10485. },
  10486. "aggregation": {
  10487. "count": "عدد الصفوف: ",
  10488. "sum": "جمع: ",
  10489. "avg": "المتوسط الحسابى: ",
  10490. "min": "الادنى: ",
  10491. "max": "الاقصى: "
  10492. },
  10493. "pinning": {
  10494. "pinLeft": "تثبيت لليسار",
  10495. "pinRight": "تثبيت لليمين",
  10496. "unpin": "فك التثبيت"
  10497. },
  10498. "columnMenu": {
  10499. "close": "غلق"
  10500. },
  10501. "gridMenu": {
  10502. "aria": {
  10503. "buttonLabel": "قائمه الجدول"
  10504. },
  10505. "columns": "الاعمده:",
  10506. "importerTitle": "إدخال ملف",
  10507. "exporterAllAsCsv": "إخراج كل البيانات ك(csv)",
  10508. "exporterVisibleAsCsv": "إخراج كل البيانات الواضحه ك (csv)",
  10509. "exporterSelectedAsCsv": "إخراج كل البيانات المحدده ك (csv)",
  10510. "exporterAllAsPdf": "إخراج كل البيانات ك(pdf)",
  10511. "exporterVisibleAsPdf": "إخراج كل البيانات الواضحه ك (pdf)",
  10512. "exporterSelectedAsPdf": "إخراج كل البيانات المحدده ك (pdf)",
  10513. "clearAllFilters": "محو كل الترشيح"
  10514. },
  10515. "importer": {
  10516. "noHeaders": "اسماء هؤلاء الاعمده غير واضحه، هل يوجد رأس للملف؟",
  10517. "noObjects": "Objects were not able to be derived, was there data in the file other than headers?",
  10518. "invalidCsv": "الملف غير قادر على الاتمام ، هل ال (CSV) صحيح؟",
  10519. "invalidJson": "الملف غير قادر على الاتمام ، هل ال (JSON) صحيح؟",
  10520. "jsonNotArray": "Imported json file must contain an array, aborting."
  10521. },
  10522. "pagination": {
  10523. "aria": {
  10524. "pageToFirst": "الصفحه الاولى",
  10525. "pageBack": "الصفه السابقه",
  10526. "pageSelected": "الصفحه المحدده",
  10527. "pageForward": "الصفحه التاليه",
  10528. "pageToLast": "الصفحه الاخيره"
  10529. },
  10530. "sizes": "عدد العناصر فى الصفحه",
  10531. "totalItems": "عناصر",
  10532. "through": "إلى",
  10533. "of": "من"
  10534. },
  10535. "grouping": {
  10536. "group": "جمع",
  10537. "ungroup": "فك الجمع",
  10538. "aggregate_count": "جمله : العدد",
  10539. "aggregate_sum": "جمله : الحاصل",
  10540. "aggregate_max": "جمله : الاقصى",
  10541. "aggregate_min": "جمله : الاقل",
  10542. "aggregate_avg": "جمله :المتوسط ",
  10543. "aggregate_remove": "جمله : حذف"
  10544. },
  10545. "validate": {
  10546. "error": "خطأ :",
  10547. "minLength": "القيمه لابد ان لا تقل عن THRESHOLD حرف.",
  10548. "maxLength": "القيمه لابد ان لا تزيد عن THRESHOLD حرف.",
  10549. "required": "مطلوب قيمه"
  10550. }
  10551. });
  10552. return $delegate;
  10553. }]);
  10554. }]);
  10555. })();
  10556. (function () {
  10557. angular.module('ui.grid').config(['$provide', function($provide) {
  10558. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10559. $delegate.add('bg', {
  10560. headerCell: {
  10561. aria: {
  10562. defaultFilterLabel: 'Филттър за колоната',
  10563. removeFilter: 'Премахни филтър',
  10564. columnMenuButtonLabel: 'Меню на колоната'
  10565. },
  10566. priority: 'Приоритет:',
  10567. filterLabel: "Филтър за колоната: "
  10568. },
  10569. aggregate: {
  10570. label: 'обекти'
  10571. },
  10572. search: {
  10573. placeholder: 'Търсене...',
  10574. showingItems: 'Показани обекти:',
  10575. selectedItems: 'избрани обекти:',
  10576. totalItems: 'Общо:',
  10577. size: 'Размер на страницата:',
  10578. first: 'Първа страница',
  10579. next: 'Следваща страница',
  10580. previous: 'Предишна страница',
  10581. last: 'Последна страница'
  10582. },
  10583. menu: {
  10584. text: 'Избери колони:'
  10585. },
  10586. sort: {
  10587. ascending: 'Сортиране по възходящ ред',
  10588. descending: 'Сортиране по низходящ ред',
  10589. none: 'Без сортиране',
  10590. remove: 'Премахни сортирането'
  10591. },
  10592. column: {
  10593. hide: 'Скрий колоната'
  10594. },
  10595. aggregation: {
  10596. count: 'Общо редове: ',
  10597. sum: 'общо: ',
  10598. avg: 'средно: ',
  10599. min: 'най-малко: ',
  10600. max: 'най-много: '
  10601. },
  10602. pinning: {
  10603. pinLeft: 'Прикрепи вляво',
  10604. pinRight: 'Прикрепи вдясно',
  10605. unpin: 'Премахване'
  10606. },
  10607. columnMenu: {
  10608. close: 'Затвори'
  10609. },
  10610. gridMenu: {
  10611. aria: {
  10612. buttonLabel: 'Меню на таблицата'
  10613. },
  10614. columns: 'Колони:',
  10615. importerTitle: 'Импортиране на файл',
  10616. exporterAllAsCsv: 'Експортиране на данните като csv',
  10617. exporterVisibleAsCsv: 'Експортиране на видимите данни като csv',
  10618. exporterSelectedAsCsv: 'Експортиране на избраните данни като csv',
  10619. exporterAllAsPdf: 'Експортиране на данните като pdf',
  10620. exporterVisibleAsPdf: 'Експортиране на видимите данни като pdf',
  10621. exporterSelectedAsPdf: 'Експортиране на избраните данни като pdf',
  10622. clearAllFilters: 'Премахни всички филтри'
  10623. },
  10624. importer: {
  10625. noHeaders: 'Имената на колоните не успяха да бъдат извлечени, файлът има ли хедър?',
  10626. noObjects: 'Обектите не успяха да бъдат извлечени, файлът съдържа ли данни, различни от хедър?',
  10627. invalidCsv: 'Файлът не може да бъде обработеб, уверете се, че е валиден CSV файл',
  10628. invalidJson: 'Файлът не може да бъде обработеб, уверете се, че е валиден JSON файл',
  10629. jsonNotArray: 'Импортираният JSON файл трябва да съдържа масив, прекратяване.'
  10630. },
  10631. pagination: {
  10632. aria: {
  10633. pageToFirst: 'Към първа страница',
  10634. pageBack: 'Страница назад',
  10635. pageSelected: 'Избрана страница',
  10636. pageForward: 'Страница напред',
  10637. pageToLast: 'Към последна страница'
  10638. },
  10639. sizes: 'обекта на страница',
  10640. totalItems: 'обекта',
  10641. through: 'до',
  10642. of: 'от'
  10643. },
  10644. grouping: {
  10645. group: 'Групиране',
  10646. ungroup: 'Премахване на групирането',
  10647. aggregate_count: 'Сбор: Брой',
  10648. aggregate_sum: 'Сбор: Сума',
  10649. aggregate_max: 'Сбор: Максимум',
  10650. aggregate_min: 'Сбор: Минимум',
  10651. aggregate_avg: 'Сбор: Средно',
  10652. aggregate_remove: 'Сбор: Премахване'
  10653. },
  10654. validate: {
  10655. error: 'Грешка:',
  10656. minLength: 'Стойността трябва да съдържа поне THRESHOLD символа.',
  10657. maxLength: 'Стойността не трябва да съдържа повече от THRESHOLD символа.',
  10658. required: 'Необходима е стойност.'
  10659. }
  10660. });
  10661. return $delegate;
  10662. }]);
  10663. }]);
  10664. })();
  10665. (function () {
  10666. angular.module('ui.grid').config(['$provide', function($provide) {
  10667. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10668. var lang = {
  10669. aggregate: {
  10670. label: 'položky'
  10671. },
  10672. groupPanel: {
  10673. description: 'Přesuňte záhlaví zde pro vytvoření skupiny dle sloupce.'
  10674. },
  10675. search: {
  10676. placeholder: 'Hledat...',
  10677. showingItems: 'Zobrazuji položky:',
  10678. selectedItems: 'Vybrané položky:',
  10679. totalItems: 'Celkem položek:',
  10680. size: 'Velikost strany:',
  10681. first: 'První strana',
  10682. next: 'Další strana',
  10683. previous: 'Předchozí strana',
  10684. last: 'Poslední strana'
  10685. },
  10686. menu: {
  10687. text: 'Vyberte sloupec:'
  10688. },
  10689. sort: {
  10690. ascending: 'Seřadit od A-Z',
  10691. descending: 'Seřadit od Z-A',
  10692. remove: 'Odebrat seřazení'
  10693. },
  10694. column: {
  10695. hide: 'Schovat sloupec'
  10696. },
  10697. aggregation: {
  10698. count: 'celkem řádků: ',
  10699. sum: 'celkem: ',
  10700. avg: 'avg: ',
  10701. min: 'min.: ',
  10702. max: 'max.: '
  10703. },
  10704. pinning: {
  10705. pinLeft: 'Zamknout vlevo',
  10706. pinRight: 'Zamknout vpravo',
  10707. unpin: 'Odemknout'
  10708. },
  10709. gridMenu: {
  10710. columns: 'Sloupce:',
  10711. importerTitle: 'Importovat soubor',
  10712. exporterAllAsCsv: 'Exportovat všechna data do csv',
  10713. exporterVisibleAsCsv: 'Exportovat viditelná data do csv',
  10714. exporterSelectedAsCsv: 'Exportovat vybraná data do csv',
  10715. exporterAllAsPdf: 'Exportovat všechna data do pdf',
  10716. exporterVisibleAsPdf: 'Exportovat viditelná data do pdf',
  10717. exporterSelectedAsPdf: 'Exportovat vybraná data do pdf',
  10718. exporterAllAsExcel: 'Exportovat všechna data do excel',
  10719. exporterVisibleAsExcel: 'Exportovat viditelná data do excel',
  10720. exporterSelectedAsExcel: 'Exportovat vybraná data do excel',
  10721. clearAllFilters: 'Odstranit všechny filtry'
  10722. },
  10723. importer: {
  10724. noHeaders: 'Názvy sloupců se nepodařilo získat, obsahuje soubor záhlaví?',
  10725. noObjects: 'Data se nepodařilo zpracovat, obsahuje soubor řádky mimo záhlaví?',
  10726. invalidCsv: 'Soubor nelze zpracovat, jedná se o CSV?',
  10727. invalidJson: 'Soubor nelze zpracovat, je to JSON?',
  10728. jsonNotArray: 'Soubor musí obsahovat json. Ukončuji..'
  10729. },
  10730. pagination: {
  10731. sizes: 'položek na stránku',
  10732. totalItems: 'položek'
  10733. },
  10734. grouping: {
  10735. group: 'Seskupit',
  10736. ungroup: 'Odebrat seskupení',
  10737. aggregate_count: 'Agregace: Count',
  10738. aggregate_sum: 'Agregace: Sum',
  10739. aggregate_max: 'Agregace: Max',
  10740. aggregate_min: 'Agregace: Min',
  10741. aggregate_avg: 'Agregace: Avg',
  10742. aggregate_remove: 'Agregace: Odebrat'
  10743. }
  10744. };
  10745. // support varianty of different czech keys.
  10746. $delegate.add('cs', lang);
  10747. $delegate.add('cz', lang);
  10748. $delegate.add('cs-cz', lang);
  10749. $delegate.add('cs-CZ', lang);
  10750. return $delegate;
  10751. }]);
  10752. }]);
  10753. })();
  10754. (function(){
  10755. angular.module('ui.grid').config(['$provide', function($provide) {
  10756. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10757. $delegate.add('da', {
  10758. aggregate:{
  10759. label: 'artikler'
  10760. },
  10761. groupPanel:{
  10762. description: 'Grupér rækker udfra en kolonne ved at trække dens overskift hertil.'
  10763. },
  10764. search:{
  10765. placeholder: 'Søg...',
  10766. showingItems: 'Viste rækker:',
  10767. selectedItems: 'Valgte rækker:',
  10768. totalItems: 'Rækker totalt:',
  10769. size: 'Side størrelse:',
  10770. first: 'Første side',
  10771. next: 'Næste side',
  10772. previous: 'Forrige side',
  10773. last: 'Sidste side'
  10774. },
  10775. menu:{
  10776. text: 'Vælg kolonner:'
  10777. },
  10778. sort: {
  10779. ascending: 'Sorter stigende',
  10780. descending: 'Sorter faldende',
  10781. none: 'Sorter ingen',
  10782. remove: 'Fjern sortering'
  10783. },
  10784. column: {
  10785. hide: 'Skjul kolonne'
  10786. },
  10787. aggregation: {
  10788. count: 'antal rækker: ',
  10789. sum: 'sum: ',
  10790. avg: 'gns: ',
  10791. min: 'min: ',
  10792. max: 'max: '
  10793. },
  10794. gridMenu: {
  10795. columns: 'Kolonner:',
  10796. importerTitle: 'Importer fil',
  10797. exporterAllAsCsv: 'Eksporter alle data som csv',
  10798. exporterVisibleAsCsv: 'Eksporter synlige data som csv',
  10799. exporterSelectedAsCsv: 'Eksporter markerede data som csv',
  10800. exporterAllAsPdf: 'Eksporter alle data som pdf',
  10801. exporterVisibleAsPdf: 'Eksporter synlige data som pdf',
  10802. exporterSelectedAsPdf: 'Eksporter markerede data som pdf',
  10803. exporterAllAsExcel: 'Eksporter alle data som excel',
  10804. exporterVisibleAsExcel: 'Eksporter synlige data som excel',
  10805. exporterSelectedAsExcel: 'Eksporter markerede data som excel',
  10806. clearAllFilters: 'Clear all filters'
  10807. },
  10808. importer: {
  10809. noHeaders: 'Column names were unable to be derived, does the file have a header?',
  10810. noObjects: 'Objects were not able to be derived, was there data in the file other than headers?',
  10811. invalidCsv: 'File was unable to be processed, is it valid CSV?',
  10812. invalidJson: 'File was unable to be processed, is it valid Json?',
  10813. jsonNotArray: 'Imported json file must contain an array, aborting.'
  10814. },
  10815. pagination: {
  10816. aria: {
  10817. pageToFirst: 'Gå til første',
  10818. pageBack: 'Gå tilbage',
  10819. pageSelected: 'Valgte side',
  10820. pageForward: 'Gå frem',
  10821. pageToLast: 'Gå til sidste'
  10822. },
  10823. sizes: 'genstande per side',
  10824. totalItems: 'genstande',
  10825. through: 'gennem',
  10826. of: 'af'
  10827. }
  10828. });
  10829. return $delegate;
  10830. }]);
  10831. }]);
  10832. })();
  10833. (function () {
  10834. angular.module('ui.grid').config(['$provide', function ($provide) {
  10835. $provide.decorator('i18nService', ['$delegate', function ($delegate) {
  10836. $delegate.add('de', {
  10837. headerCell: {
  10838. aria: {
  10839. defaultFilterLabel: 'Filter für Spalte',
  10840. removeFilter: 'Filter löschen',
  10841. columnMenuButtonLabel: 'Spaltenmenü',
  10842. column: 'Spalte'
  10843. },
  10844. priority: 'Priorität:',
  10845. filterLabel: "Filter für Spalte: "
  10846. },
  10847. aggregate: {
  10848. label: 'Eintrag'
  10849. },
  10850. groupPanel: {
  10851. description: 'Ziehen Sie eine Spaltenüberschrift hierhin, um nach dieser Spalte zu gruppieren.'
  10852. },
  10853. search: {
  10854. aria: {
  10855. selected: 'Zeile markiert',
  10856. notSelected: 'Zeile nicht markiert'
  10857. },
  10858. placeholder: 'Suche...',
  10859. showingItems: 'Zeige Einträge:',
  10860. selectedItems: 'Ausgewählte Einträge:',
  10861. totalItems: 'Einträge gesamt:',
  10862. size: 'Einträge pro Seite:',
  10863. first: 'Erste Seite',
  10864. next: 'Nächste Seite',
  10865. previous: 'Vorherige Seite',
  10866. last: 'Letzte Seite'
  10867. },
  10868. menu: {
  10869. text: 'Spalten auswählen:'
  10870. },
  10871. sort: {
  10872. ascending: 'aufsteigend sortieren',
  10873. descending: 'absteigend sortieren',
  10874. none: 'keine Sortierung',
  10875. remove: 'Sortierung zurücksetzen'
  10876. },
  10877. column: {
  10878. hide: 'Spalte ausblenden'
  10879. },
  10880. aggregation: {
  10881. count: 'Zeilen insgesamt: ',
  10882. sum: 'gesamt: ',
  10883. avg: 'Durchschnitt: ',
  10884. min: 'min: ',
  10885. max: 'max: '
  10886. },
  10887. pinning: {
  10888. pinLeft: 'Links anheften',
  10889. pinRight: 'Rechts anheften',
  10890. unpin: 'Lösen'
  10891. },
  10892. columnMenu: {
  10893. close: 'Schließen'
  10894. },
  10895. gridMenu: {
  10896. aria: {
  10897. buttonLabel: 'Tabellenmenü'
  10898. },
  10899. columns: 'Spalten:',
  10900. importerTitle: 'Datei importieren',
  10901. exporterAllAsCsv: 'Alle Daten als CSV exportieren',
  10902. exporterVisibleAsCsv: 'Sichtbare Daten als CSV exportieren',
  10903. exporterSelectedAsCsv: 'Markierte Daten als CSV exportieren',
  10904. exporterAllAsPdf: 'Alle Daten als PDF exportieren',
  10905. exporterVisibleAsPdf: 'Sichtbare Daten als PDF exportieren',
  10906. exporterSelectedAsPdf: 'Markierte Daten als PDF exportieren',
  10907. exporterAllAsExcel: 'Alle Daten als Excel exportieren',
  10908. exporterVisibleAsExcel: 'Sichtbare Daten als Excel exportieren',
  10909. exporterSelectedAsExcel: 'Markierte Daten als Excel exportieren',
  10910. clearAllFilters: 'Alle Filter zurücksetzen'
  10911. },
  10912. importer: {
  10913. noHeaders: 'Es konnten keine Spaltennamen ermittelt werden. Sind in der Datei Spaltendefinitionen enthalten?',
  10914. noObjects: 'Es konnten keine Zeileninformationen gelesen werden, Sind in der Datei außer den Spaltendefinitionen auch Daten enthalten?',
  10915. invalidCsv: 'Die Datei konnte nicht eingelesen werden, ist es eine gültige CSV-Datei?',
  10916. invalidJson: 'Die Datei konnte nicht eingelesen werden. Enthält sie gültiges JSON?',
  10917. jsonNotArray: 'Die importierte JSON-Datei muß ein Array enthalten. Breche Import ab.'
  10918. },
  10919. pagination: {
  10920. aria: {
  10921. pageToFirst: 'Zum Anfang',
  10922. pageBack: 'Seite zurück',
  10923. pageSelected: 'Ausgewählte Seite',
  10924. pageForward: 'Seite vor',
  10925. pageToLast: 'Zum Ende'
  10926. },
  10927. sizes: 'Einträge pro Seite',
  10928. totalItems: 'Einträgen',
  10929. through: 'bis',
  10930. of: 'von'
  10931. },
  10932. grouping: {
  10933. group: 'Gruppieren',
  10934. ungroup: 'Gruppierung aufheben',
  10935. aggregate_count: 'Agg: Anzahl',
  10936. aggregate_sum: 'Agg: Summe',
  10937. aggregate_max: 'Agg: Maximum',
  10938. aggregate_min: 'Agg: Minimum',
  10939. aggregate_avg: 'Agg: Mittelwert',
  10940. aggregate_remove: 'Aggregation entfernen'
  10941. }
  10942. });
  10943. return $delegate;
  10944. }]);
  10945. }]);
  10946. })();
  10947. (function () {
  10948. angular.module('ui.grid').config(['$provide', function($provide) {
  10949. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  10950. $delegate.add('en', {
  10951. headerCell: {
  10952. aria: {
  10953. defaultFilterLabel: 'Filter for column',
  10954. removeFilter: 'Remove Filter',
  10955. columnMenuButtonLabel: 'Column Menu',
  10956. column: 'Column'
  10957. },
  10958. priority: 'Priority:',
  10959. filterLabel: "Filter for column: "
  10960. },
  10961. aggregate: {
  10962. label: 'items'
  10963. },
  10964. groupPanel: {
  10965. description: 'Drag a column header here and drop it to group by that column.'
  10966. },
  10967. search: {
  10968. aria: {
  10969. selected: 'Row selected',
  10970. notSelected: 'Row not selected'
  10971. },
  10972. placeholder: 'Search...',
  10973. showingItems: 'Showing Items:',
  10974. selectedItems: 'Selected Items:',
  10975. totalItems: 'Total Items:',
  10976. size: 'Page Size:',
  10977. first: 'First Page',
  10978. next: 'Next Page',
  10979. previous: 'Previous Page',
  10980. last: 'Last Page'
  10981. },
  10982. menu: {
  10983. text: 'Choose Columns:'
  10984. },
  10985. sort: {
  10986. ascending: 'Sort Ascending',
  10987. descending: 'Sort Descending',
  10988. none: 'Sort None',
  10989. remove: 'Remove Sort'
  10990. },
  10991. column: {
  10992. hide: 'Hide Column'
  10993. },
  10994. aggregation: {
  10995. count: 'total rows: ',
  10996. sum: 'total: ',
  10997. avg: 'avg: ',
  10998. min: 'min: ',
  10999. max: 'max: '
  11000. },
  11001. pinning: {
  11002. pinLeft: 'Pin Left',
  11003. pinRight: 'Pin Right',
  11004. unpin: 'Unpin'
  11005. },
  11006. columnMenu: {
  11007. close: 'Close'
  11008. },
  11009. gridMenu: {
  11010. aria: {
  11011. buttonLabel: 'Grid Menu'
  11012. },
  11013. columns: 'Columns:',
  11014. importerTitle: 'Import file',
  11015. exporterAllAsCsv: 'Export all data as csv',
  11016. exporterVisibleAsCsv: 'Export visible data as csv',
  11017. exporterSelectedAsCsv: 'Export selected data as csv',
  11018. exporterAllAsPdf: 'Export all data as pdf',
  11019. exporterVisibleAsPdf: 'Export visible data as pdf',
  11020. exporterSelectedAsPdf: 'Export selected data as pdf',
  11021. exporterAllAsExcel: 'Export all data as excel',
  11022. exporterVisibleAsExcel: 'Export visible data as excel',
  11023. exporterSelectedAsExcel: 'Export selected data as excel',
  11024. clearAllFilters: 'Clear all filters'
  11025. },
  11026. importer: {
  11027. noHeaders: 'Column names were unable to be derived, does the file have a header?',
  11028. noObjects: 'Objects were not able to be derived, was there data in the file other than headers?',
  11029. invalidCsv: 'File was unable to be processed, is it valid CSV?',
  11030. invalidJson: 'File was unable to be processed, is it valid Json?',
  11031. jsonNotArray: 'Imported json file must contain an array, aborting.'
  11032. },
  11033. pagination: {
  11034. aria: {
  11035. pageToFirst: 'Page to first',
  11036. pageBack: 'Page back',
  11037. pageSelected: 'Selected page',
  11038. pageForward: 'Page forward',
  11039. pageToLast: 'Page to last'
  11040. },
  11041. sizes: 'items per page',
  11042. totalItems: 'items',
  11043. through: 'through',
  11044. of: 'of'
  11045. },
  11046. grouping: {
  11047. group: 'Group',
  11048. ungroup: 'Ungroup',
  11049. aggregate_count: 'Agg: Count',
  11050. aggregate_sum: 'Agg: Sum',
  11051. aggregate_max: 'Agg: Max',
  11052. aggregate_min: 'Agg: Min',
  11053. aggregate_avg: 'Agg: Avg',
  11054. aggregate_remove: 'Agg: Remove'
  11055. },
  11056. validate: {
  11057. error: 'Error:',
  11058. minLength: 'Value should be at least THRESHOLD characters long.',
  11059. maxLength: 'Value should be at most THRESHOLD characters long.',
  11060. required: 'A value is needed.'
  11061. }
  11062. });
  11063. return $delegate;
  11064. }]);
  11065. }]);
  11066. })();
  11067. (function () {
  11068. angular.module('ui.grid').config(['$provide', function($provide) {
  11069. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11070. $delegate.add('es', {
  11071. aggregate: {
  11072. label: 'Artículos'
  11073. },
  11074. groupPanel: {
  11075. description: 'Arrastre un encabezado de columna aquí y suéltelo para agrupar por esa columna.'
  11076. },
  11077. search: {
  11078. placeholder: 'Buscar...',
  11079. showingItems: 'Artículos Mostrados:',
  11080. selectedItems: 'Artículos Seleccionados:',
  11081. totalItems: 'Artículos Totales:',
  11082. size: 'Tamaño de Página:',
  11083. first: 'Primera Página',
  11084. next: 'Página Siguiente',
  11085. previous: 'Página Anterior',
  11086. last: 'Última Página'
  11087. },
  11088. menu: {
  11089. text: 'Elegir columnas:'
  11090. },
  11091. sort: {
  11092. ascending: 'Orden Ascendente',
  11093. descending: 'Orden Descendente',
  11094. remove: 'Sin Ordenar'
  11095. },
  11096. column: {
  11097. hide: 'Ocultar la columna'
  11098. },
  11099. aggregation: {
  11100. count: 'filas totales: ',
  11101. sum: 'total: ',
  11102. avg: 'media: ',
  11103. min: 'min: ',
  11104. max: 'max: '
  11105. },
  11106. pinning: {
  11107. pinLeft: 'Fijar a la Izquierda',
  11108. pinRight: 'Fijar a la Derecha',
  11109. unpin: 'Quitar Fijación'
  11110. },
  11111. gridMenu: {
  11112. columns: 'Columnas:',
  11113. importerTitle: 'Importar archivo',
  11114. exporterAllAsCsv: 'Exportar todo como csv',
  11115. exporterVisibleAsCsv: 'Exportar vista como csv',
  11116. exporterSelectedAsCsv: 'Exportar selección como csv',
  11117. exporterAllAsPdf: 'Exportar todo como pdf',
  11118. exporterVisibleAsPdf: 'Exportar vista como pdf',
  11119. exporterSelectedAsPdf: 'Exportar selección como pdf',
  11120. exporterAllAsExcel: 'Exportar todo como excel',
  11121. exporterVisibleAsExcel: 'Exportar vista como excel',
  11122. exporterSelectedAsExcel: 'Exportar selección como excel',
  11123. clearAllFilters: 'Limpiar todos los filtros'
  11124. },
  11125. importer: {
  11126. noHeaders: 'No fue posible derivar los nombres de las columnas, ¿tiene encabezados el archivo?',
  11127. noObjects: 'No fue posible obtener registros, ¿contiene datos el archivo, aparte de los encabezados?',
  11128. invalidCsv: 'No fue posible procesar el archivo, ¿es un CSV válido?',
  11129. invalidJson: 'No fue posible procesar el archivo, ¿es un Json válido?',
  11130. jsonNotArray: 'El archivo json importado debe contener un array, abortando.'
  11131. },
  11132. pagination: {
  11133. sizes: 'registros por página',
  11134. totalItems: 'registros',
  11135. of: 'de'
  11136. },
  11137. grouping: {
  11138. group: 'Agrupar',
  11139. ungroup: 'Desagrupar',
  11140. aggregate_count: 'Agr: Cont',
  11141. aggregate_sum: 'Agr: Sum',
  11142. aggregate_max: 'Agr: Máx',
  11143. aggregate_min: 'Agr: Min',
  11144. aggregate_avg: 'Agr: Prom',
  11145. aggregate_remove: 'Agr: Quitar'
  11146. }
  11147. });
  11148. return $delegate;
  11149. }]);
  11150. }]);
  11151. })();
  11152. /**
  11153. * Translated by: R. Salarmehr
  11154. * M. Hosseynzade
  11155. * Using Vajje.com online dictionary.
  11156. */
  11157. (function () {
  11158. angular.module('ui.grid').config(['$provide', function ($provide) {
  11159. $provide.decorator('i18nService', ['$delegate', function ($delegate) {
  11160. $delegate.add('fa', {
  11161. aggregate: {
  11162. label: 'قلم'
  11163. },
  11164. groupPanel: {
  11165. description: 'عنوان یک ستون را بگیر و به گروهی از آن ستون رها کن.'
  11166. },
  11167. search: {
  11168. placeholder: 'جستجو...',
  11169. showingItems: 'نمایش اقلام:',
  11170. selectedItems: 'قلم\u200cهای انتخاب شده:',
  11171. totalItems: 'مجموع اقلام:',
  11172. size: 'اندازه\u200cی صفحه:',
  11173. first: 'اولین صفحه',
  11174. next: 'صفحه\u200cی\u200cبعدی',
  11175. previous: 'صفحه\u200cی\u200c قبلی',
  11176. last: 'آخرین صفحه'
  11177. },
  11178. menu: {
  11179. text: 'ستون\u200cهای انتخابی:'
  11180. },
  11181. sort: {
  11182. ascending: 'ترتیب صعودی',
  11183. descending: 'ترتیب نزولی',
  11184. remove: 'حذف مرتب کردن'
  11185. },
  11186. column: {
  11187. hide: 'پنهان\u200cکردن ستون'
  11188. },
  11189. aggregation: {
  11190. count: 'تعداد: ',
  11191. sum: 'مجموع: ',
  11192. avg: 'میانگین: ',
  11193. min: 'کمترین: ',
  11194. max: 'بیشترین: '
  11195. },
  11196. pinning: {
  11197. pinLeft: 'پین کردن سمت چپ',
  11198. pinRight: 'پین کردن سمت راست',
  11199. unpin: 'حذف پین'
  11200. },
  11201. gridMenu: {
  11202. columns: 'ستون\u200cها:',
  11203. importerTitle: 'وارد کردن فایل',
  11204. exporterAllAsCsv: 'خروجی تمام داده\u200cها در فایل csv',
  11205. exporterVisibleAsCsv: 'خروجی داده\u200cهای قابل مشاهده در فایل csv',
  11206. exporterSelectedAsCsv: 'خروجی داده\u200cهای انتخاب\u200cشده در فایل csv',
  11207. exporterAllAsPdf: 'خروجی تمام داده\u200cها در فایل pdf',
  11208. exporterVisibleAsPdf: 'خروجی داده\u200cهای قابل مشاهده در فایل pdf',
  11209. exporterSelectedAsPdf: 'خروجی داده\u200cهای انتخاب\u200cشده در فایل pdf',
  11210. clearAllFilters: 'پاک کردن تمام فیلتر'
  11211. },
  11212. importer: {
  11213. noHeaders: 'نام ستون قابل استخراج نیست. آیا فایل عنوان دارد؟',
  11214. noObjects: 'اشیا قابل استخراج نیستند. آیا به جز عنوان\u200cها در فایل داده وجود دارد؟',
  11215. invalidCsv: 'فایل قابل پردازش نیست. آیا فرمت csv معتبر است؟',
  11216. invalidJson: 'فایل قابل پردازش نیست. آیا فرمت json معتبر است؟',
  11217. jsonNotArray: 'فایل json وارد شده باید حاوی آرایه باشد. عملیات ساقط شد.'
  11218. },
  11219. pagination: {
  11220. sizes: 'اقلام در هر صفحه',
  11221. totalItems: 'اقلام',
  11222. of: 'از'
  11223. },
  11224. grouping: {
  11225. group: 'گروه\u200cبندی',
  11226. ungroup: 'حذف گروه\u200cبندی',
  11227. aggregate_count: 'Agg: تعداد',
  11228. aggregate_sum: 'Agg: جمع',
  11229. aggregate_max: 'Agg: بیشینه',
  11230. aggregate_min: 'Agg: کمینه',
  11231. aggregate_avg: 'Agg: میانگین',
  11232. aggregate_remove: 'Agg: حذف'
  11233. }
  11234. });
  11235. return $delegate;
  11236. }]);
  11237. }]);
  11238. })();
  11239. (function () {
  11240. angular.module('ui.grid').config(['$provide', function($provide) {
  11241. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11242. $delegate.add('fi', {
  11243. aggregate: {
  11244. label: 'rivit'
  11245. },
  11246. groupPanel: {
  11247. description: 'Raahaa ja pudota otsikko tähän ryhmittääksesi sarakkeen mukaan.'
  11248. },
  11249. search: {
  11250. placeholder: 'Hae...',
  11251. showingItems: 'Näytetään rivejä:',
  11252. selectedItems: 'Valitut rivit:',
  11253. totalItems: 'Rivejä yht.:',
  11254. size: 'Näytä:',
  11255. first: 'Ensimmäinen sivu',
  11256. next: 'Seuraava sivu',
  11257. previous: 'Edellinen sivu',
  11258. last: 'Viimeinen sivu'
  11259. },
  11260. menu: {
  11261. text: 'Valitse sarakkeet:'
  11262. },
  11263. sort: {
  11264. ascending: 'Järjestä nouseva',
  11265. descending: 'Järjestä laskeva',
  11266. remove: 'Poista järjestys'
  11267. },
  11268. column: {
  11269. hide: 'Piilota sarake'
  11270. },
  11271. aggregation: {
  11272. count: 'Rivejä yht.: ',
  11273. sum: 'Summa: ',
  11274. avg: 'K.a.: ',
  11275. min: 'Min: ',
  11276. max: 'Max: '
  11277. },
  11278. pinning: {
  11279. pinLeft: 'Lukitse vasemmalle',
  11280. pinRight: 'Lukitse oikealle',
  11281. unpin: 'Poista lukitus'
  11282. },
  11283. gridMenu: {
  11284. columns: 'Sarakkeet:',
  11285. importerTitle: 'Tuo tiedosto',
  11286. exporterAllAsCsv: 'Vie tiedot csv-muodossa',
  11287. exporterVisibleAsCsv: 'Vie näkyvä tieto csv-muodossa',
  11288. exporterSelectedAsCsv: 'Vie valittu tieto csv-muodossa',
  11289. exporterAllAsPdf: 'Vie tiedot pdf-muodossa',
  11290. exporterVisibleAsPdf: 'Vie näkyvä tieto pdf-muodossa',
  11291. exporterSelectedAsPdf: 'Vie valittu tieto pdf-muodossa',
  11292. exporterAllAsExcel: 'Vie tiedot excel-muodossa',
  11293. exporterVisibleAsExcel: 'Vie näkyvä tieto excel-muodossa',
  11294. exporterSelectedAsExcel: 'Vie valittu tieto excel-muodossa',
  11295. clearAllFilters: 'Puhdista kaikki suodattimet'
  11296. },
  11297. importer: {
  11298. noHeaders: 'Sarakkeen nimiä ei voitu päätellä, onko tiedostossa otsikkoriviä?',
  11299. noObjects: 'Tietoja ei voitu lukea, onko tiedostossa muuta kuin otsikkot?',
  11300. invalidCsv: 'Tiedostoa ei voitu käsitellä, oliko se CSV-muodossa?',
  11301. invalidJson: 'Tiedostoa ei voitu käsitellä, oliko se JSON-muodossa?',
  11302. jsonNotArray: 'Tiedosto ei sisältänyt taulukkoa, lopetetaan.'
  11303. }
  11304. });
  11305. return $delegate;
  11306. }]);
  11307. }]);
  11308. })();
  11309. (function () {
  11310. angular.module('ui.grid').config(['$provide', function($provide) {
  11311. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11312. $delegate.add('fr', {
  11313. headerCell: {
  11314. aria: {
  11315. defaultFilterLabel: 'Filtre de la colonne',
  11316. removeFilter: 'Supprimer le filtre',
  11317. columnMenuButtonLabel: 'Menu de la colonne'
  11318. },
  11319. priority: 'Priorité:',
  11320. filterLabel: "Filtre de la colonne: "
  11321. },
  11322. aggregate: {
  11323. label: 'éléments'
  11324. },
  11325. groupPanel: {
  11326. description: 'Faites glisser une en-tête de colonne ici pour créer un groupe de colonnes.'
  11327. },
  11328. search: {
  11329. placeholder: 'Recherche...',
  11330. showingItems: 'Affichage des éléments :',
  11331. selectedItems: 'Éléments sélectionnés :',
  11332. totalItems: 'Nombre total d\'éléments:',
  11333. size: 'Taille de page:',
  11334. first: 'Première page',
  11335. next: 'Page Suivante',
  11336. previous: 'Page précédente',
  11337. last: 'Dernière page'
  11338. },
  11339. menu: {
  11340. text: 'Choisir des colonnes :'
  11341. },
  11342. sort: {
  11343. ascending: 'Trier par ordre croissant',
  11344. descending: 'Trier par ordre décroissant',
  11345. none: 'Aucun tri',
  11346. remove: 'Enlever le tri'
  11347. },
  11348. column: {
  11349. hide: 'Cacher la colonne'
  11350. },
  11351. aggregation: {
  11352. count: 'lignes totales: ',
  11353. sum: 'total: ',
  11354. avg: 'moy: ',
  11355. min: 'min: ',
  11356. max: 'max: '
  11357. },
  11358. pinning: {
  11359. pinLeft: 'Épingler à gauche',
  11360. pinRight: 'Épingler à droite',
  11361. unpin: 'Détacher'
  11362. },
  11363. columnMenu: {
  11364. close: 'Fermer'
  11365. },
  11366. gridMenu: {
  11367. aria: {
  11368. buttonLabel: 'Menu du tableau'
  11369. },
  11370. columns: 'Colonnes:',
  11371. importerTitle: 'Importer un fichier',
  11372. exporterAllAsCsv: 'Exporter toutes les données en CSV',
  11373. exporterVisibleAsCsv: 'Exporter les données visibles en CSV',
  11374. exporterSelectedAsCsv: 'Exporter les données sélectionnées en CSV',
  11375. exporterAllAsPdf: 'Exporter toutes les données en PDF',
  11376. exporterVisibleAsPdf: 'Exporter les données visibles en PDF',
  11377. exporterSelectedAsPdf: 'Exporter les données sélectionnées en PDF',
  11378. exporterAllAsExcel: 'Exporter toutes les données en Excel',
  11379. exporterVisibleAsExcel: 'Exporter les données visibles en Excel',
  11380. exporterSelectedAsExcel: 'Exporter les données sélectionnées en Excel',
  11381. clearAllFilters: 'Nettoyez tous les filtres'
  11382. },
  11383. importer: {
  11384. noHeaders: 'Impossible de déterminer le nom des colonnes, le fichier possède-t-il une en-tête ?',
  11385. noObjects: 'Aucun objet trouvé, le fichier possède-t-il des données autres que l\'en-tête ?',
  11386. invalidCsv: 'Le fichier n\'a pas pu être traité, le CSV est-il valide ?',
  11387. invalidJson: 'Le fichier n\'a pas pu être traité, le JSON est-il valide ?',
  11388. jsonNotArray: 'Le fichier JSON importé doit contenir un tableau, abandon.'
  11389. },
  11390. pagination: {
  11391. aria: {
  11392. pageToFirst: 'Aller à la première page',
  11393. pageBack: 'Page précédente',
  11394. pageSelected: 'Page sélectionnée',
  11395. pageForward: 'Page suivante',
  11396. pageToLast: 'Aller à la dernière page'
  11397. },
  11398. sizes: 'éléments par page',
  11399. totalItems: 'éléments',
  11400. through: 'à',
  11401. of: 'sur'
  11402. },
  11403. grouping: {
  11404. group: 'Grouper',
  11405. ungroup: 'Dégrouper',
  11406. aggregate_count: 'Agg: Compter',
  11407. aggregate_sum: 'Agg: Somme',
  11408. aggregate_max: 'Agg: Max',
  11409. aggregate_min: 'Agg: Min',
  11410. aggregate_avg: 'Agg: Moy',
  11411. aggregate_remove: 'Agg: Retirer'
  11412. },
  11413. validate: {
  11414. error: 'Erreur:',
  11415. minLength: 'La valeur doit être supérieure ou égale à THRESHOLD caractères.',
  11416. maxLength: 'La valeur doit être inférieure ou égale à THRESHOLD caractères.',
  11417. required: 'Une valeur est nécéssaire.'
  11418. }
  11419. });
  11420. return $delegate;
  11421. }]);
  11422. }]);
  11423. })();
  11424. (function () {
  11425. angular.module('ui.grid').config(['$provide', function ($provide) {
  11426. $provide.decorator('i18nService', ['$delegate', function ($delegate) {
  11427. $delegate.add('he', {
  11428. aggregate: {
  11429. label: 'items'
  11430. },
  11431. groupPanel: {
  11432. description: 'גרור עמודה לכאן ושחרר בכדי לקבץ עמודה זו.'
  11433. },
  11434. search: {
  11435. placeholder: 'חפש...',
  11436. showingItems: 'מציג:',
  11437. selectedItems: 'סה"כ נבחרו:',
  11438. totalItems: 'סה"כ רשומות:',
  11439. size: 'תוצאות בדף:',
  11440. first: 'דף ראשון',
  11441. next: 'דף הבא',
  11442. previous: 'דף קודם',
  11443. last: 'דף אחרון'
  11444. },
  11445. menu: {
  11446. text: 'בחר עמודות:'
  11447. },
  11448. sort: {
  11449. ascending: 'סדר עולה',
  11450. descending: 'סדר יורד',
  11451. remove: 'בטל'
  11452. },
  11453. column: {
  11454. hide: 'טור הסתר'
  11455. },
  11456. aggregation: {
  11457. count: 'total rows: ',
  11458. sum: 'total: ',
  11459. avg: 'avg: ',
  11460. min: 'min: ',
  11461. max: 'max: '
  11462. },
  11463. gridMenu: {
  11464. columns: 'Columns:',
  11465. importerTitle: 'Import file',
  11466. exporterAllAsCsv: 'Export all data as csv',
  11467. exporterVisibleAsCsv: 'Export visible data as csv',
  11468. exporterSelectedAsCsv: 'Export selected data as csv',
  11469. exporterAllAsPdf: 'Export all data as pdf',
  11470. exporterVisibleAsPdf: 'Export visible data as pdf',
  11471. exporterSelectedAsPdf: 'Export selected data as pdf',
  11472. exporterAllAsExcel: 'Export all data as excel',
  11473. exporterVisibleAsExcel: 'Export visible data as excel',
  11474. exporterSelectedAsExcel: 'Export selected data as excel',
  11475. clearAllFilters: 'Clean all filters'
  11476. },
  11477. importer: {
  11478. noHeaders: 'Column names were unable to be derived, does the file have a header?',
  11479. noObjects: 'Objects were not able to be derived, was there data in the file other than headers?',
  11480. invalidCsv: 'File was unable to be processed, is it valid CSV?',
  11481. invalidJson: 'File was unable to be processed, is it valid Json?',
  11482. jsonNotArray: 'Imported json file must contain an array, aborting.'
  11483. }
  11484. });
  11485. return $delegate;
  11486. }]);
  11487. }]);
  11488. })();
  11489. (function () {
  11490. angular.module('ui.grid').config(['$provide', function($provide) {
  11491. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11492. $delegate.add('hy', {
  11493. aggregate: {
  11494. label: 'տվյալներ'
  11495. },
  11496. groupPanel: {
  11497. description: 'Ըստ սյան խմբավորելու համար քաշեք և գցեք վերնագիրն այստեղ։'
  11498. },
  11499. search: {
  11500. placeholder: 'Փնտրում...',
  11501. showingItems: 'Ցուցադրված տվյալներ՝',
  11502. selectedItems: 'Ընտրված:',
  11503. totalItems: 'Ընդամենը՝',
  11504. size: 'Տողերի քանակը էջում՝',
  11505. first: 'Առաջին էջ',
  11506. next: 'Հաջորդ էջ',
  11507. previous: 'Նախորդ էջ',
  11508. last: 'Վերջին էջ'
  11509. },
  11510. menu: {
  11511. text: 'Ընտրել սյուները:'
  11512. },
  11513. sort: {
  11514. ascending: 'Աճման կարգով',
  11515. descending: 'Նվազման կարգով',
  11516. remove: 'Հանել '
  11517. },
  11518. column: {
  11519. hide: 'Թաքցնել սյունը'
  11520. },
  11521. aggregation: {
  11522. count: 'ընդամենը տող՝ ',
  11523. sum: 'ընդամենը՝ ',
  11524. avg: 'միջին՝ ',
  11525. min: 'մին՝ ',
  11526. max: 'մաքս՝ '
  11527. },
  11528. pinning: {
  11529. pinLeft: 'Կպցնել ձախ կողմում',
  11530. pinRight: 'Կպցնել աջ կողմում',
  11531. unpin: 'Արձակել'
  11532. },
  11533. gridMenu: {
  11534. columns: 'Սյուներ:',
  11535. importerTitle: 'Ներմուծել ֆայլ',
  11536. exporterAllAsCsv: 'Արտահանել ամբողջը CSV',
  11537. exporterVisibleAsCsv: 'Արտահանել երևացող տվյալները CSV',
  11538. exporterSelectedAsCsv: 'Արտահանել ընտրված տվյալները CSV',
  11539. exporterAllAsPdf: 'Արտահանել PDF',
  11540. exporterVisibleAsPdf: 'Արտահանել երևացող տվյալները PDF',
  11541. exporterSelectedAsPdf: 'Արտահանել ընտրված տվյալները PDF',
  11542. exporterAllAsExcel: 'Արտահանել excel',
  11543. exporterVisibleAsExcel: 'Արտահանել երևացող տվյալները excel',
  11544. exporterSelectedAsExcel: 'Արտահանել ընտրված տվյալները excel',
  11545. clearAllFilters: 'Մաքրել բոլոր ֆիլտրերը'
  11546. },
  11547. importer: {
  11548. noHeaders: 'Հնարավոր չեղավ որոշել սյան վերնագրերը։ Արդյո՞ք ֆայլը ունի վերնագրեր։',
  11549. noObjects: 'Հնարավոր չեղավ կարդալ տվյալները։ Արդյո՞ք ֆայլում կան տվյալներ։',
  11550. invalidCsv: 'Հնարավոր չեղավ մշակել ֆայլը։ Արդյո՞ք այն վավեր CSV է։',
  11551. invalidJson: 'Հնարավոր չեղավ մշակել ֆայլը։ Արդյո՞ք այն վավեր Json է։',
  11552. jsonNotArray: 'Ներմուծված json ֆայլը պետք է պարունակի զանգված, կասեցվում է։'
  11553. }
  11554. });
  11555. return $delegate;
  11556. }]);
  11557. }]);
  11558. })();
  11559. (function () {
  11560. angular.module('ui.grid').config(['$provide', function($provide) {
  11561. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11562. $delegate.add('is', {
  11563. headerCell: {
  11564. aria: {
  11565. defaultFilterLabel: 'Sía fyrir dálk',
  11566. removeFilter: 'Fjarlægja síu',
  11567. columnMenuButtonLabel: 'Dálkavalmynd'
  11568. },
  11569. priority: 'Forgangsröðun:',
  11570. filterLabel: "Sía fyrir dálka: "
  11571. },
  11572. aggregate: {
  11573. label: 'hlutir'
  11574. },
  11575. groupPanel: {
  11576. description: 'Dragðu dálkhaus hingað til að flokka saman eftir þeim dálki.'
  11577. },
  11578. search: {
  11579. placeholder: 'Leita...',
  11580. showingItems: 'Sýni hluti:',
  11581. selectedItems: 'Valdir hlutir:',
  11582. totalItems: 'Hlutir alls:',
  11583. size: 'Stærð síðu:',
  11584. first: 'Fyrsta síða',
  11585. next: 'Næsta síða',
  11586. previous: 'Fyrri síða',
  11587. last: 'Síðasta síða'
  11588. },
  11589. menu: {
  11590. text: 'Veldu dálka:'
  11591. },
  11592. sort: {
  11593. ascending: 'Raða hækkandi',
  11594. descending: 'Raða lækkandi',
  11595. none: 'Engin röðun',
  11596. remove: 'Fjarlægja röðun'
  11597. },
  11598. column: {
  11599. hide: 'Fela dálk'
  11600. },
  11601. aggregation: {
  11602. count: 'fjöldi raða: ',
  11603. sum: 'summa: ',
  11604. avg: 'meðaltal: ',
  11605. min: 'lágmark: ',
  11606. max: 'hámark: '
  11607. },
  11608. pinning: {
  11609. pinLeft: 'Festa til vinstri',
  11610. pinRight: 'Festa til hægri',
  11611. unpin: 'Losa'
  11612. },
  11613. columnMenu: {
  11614. close: 'Loka'
  11615. },
  11616. gridMenu: {
  11617. aria: {
  11618. buttonLabel: 'Töflu valmynd'
  11619. },
  11620. columns: 'Dálkar:',
  11621. importerTitle: 'Flytja inn skjal',
  11622. exporterAllAsCsv: 'Flytja út gögn sem csv',
  11623. exporterVisibleAsCsv: 'Flytja út sýnileg gögn sem csv',
  11624. exporterSelectedAsCsv: 'Flytja út valin gögn sem csv',
  11625. exporterAllAsPdf: 'Flytja út öll gögn sem pdf',
  11626. exporterVisibleAsPdf: 'Flytja út sýnileg gögn sem pdf',
  11627. exporterSelectedAsPdf: 'Flytja út valin gögn sem pdf',
  11628. clearAllFilters: 'Hreinsa allar síur'
  11629. },
  11630. importer: {
  11631. noHeaders: 'Ekki hægt að vinna dálkanöfn úr skjalinu, er skjalið örugglega með haus?',
  11632. noObjects: 'Ekki hægt að vinna hluti úr skjalinu, voru örugglega gögn í skjalinu önnur en hausinn?',
  11633. invalidCsv: 'Tókst ekki að vinna skjal, er það örggulega gilt CSV?',
  11634. invalidJson: 'Tókst ekki að vinna skjal, er það örugglega gilt Json?',
  11635. jsonNotArray: 'Innflutt json skjal verður að innihalda fylki, hætti við.'
  11636. },
  11637. pagination: {
  11638. aria: {
  11639. pageToFirst: 'Fletta að fyrstu',
  11640. pageBack: 'Fletta til baka',
  11641. pageSelected: 'Valin síða',
  11642. pageForward: 'Fletta áfram',
  11643. pageToLast: 'Fletta að síðustu'
  11644. },
  11645. sizes: 'hlutir á síðu',
  11646. totalItems: 'hlutir',
  11647. through: 'gegnum',
  11648. of: 'af'
  11649. },
  11650. grouping: {
  11651. group: 'Flokka',
  11652. ungroup: 'Sundurliða',
  11653. aggregate_count: 'Fjöldi: ',
  11654. aggregate_sum: 'Summa: ',
  11655. aggregate_max: 'Hámark: ',
  11656. aggregate_min: 'Lágmark: ',
  11657. aggregate_avg: 'Meðaltal: ',
  11658. aggregate_remove: 'Fjarlægja: '
  11659. },
  11660. validate: {
  11661. error: 'Villa:',
  11662. minLength: 'Gildi ætti að vera a.m.k. THRESHOLD stafa langt.',
  11663. maxLength: 'Gildi ætti að vera í mesta lagi THRESHOLD stafa langt.',
  11664. required: 'Þarf að hafa gildi.'
  11665. }
  11666. });
  11667. return $delegate;
  11668. }]);
  11669. }]);
  11670. })();
  11671. (function () {
  11672. angular.module('ui.grid').config(['$provide', function($provide) {
  11673. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11674. $delegate.add('it', {
  11675. aggregate: {
  11676. label: 'elementi'
  11677. },
  11678. groupPanel: {
  11679. description: 'Trascina un\'intestazione all\'interno del gruppo della colonna.'
  11680. },
  11681. search: {
  11682. placeholder: 'Ricerca...',
  11683. showingItems: 'Mostra:',
  11684. selectedItems: 'Selezionati:',
  11685. totalItems: 'Totali:',
  11686. size: 'Tot Pagine:',
  11687. first: 'Prima',
  11688. next: 'Prossima',
  11689. previous: 'Precedente',
  11690. last: 'Ultima'
  11691. },
  11692. menu: {
  11693. text: 'Scegli le colonne:'
  11694. },
  11695. sort: {
  11696. ascending: 'Asc.',
  11697. descending: 'Desc.',
  11698. remove: 'Annulla ordinamento'
  11699. },
  11700. column: {
  11701. hide: 'Nascondi'
  11702. },
  11703. aggregation: {
  11704. count: 'righe totali: ',
  11705. sum: 'tot: ',
  11706. avg: 'media: ',
  11707. min: 'minimo: ',
  11708. max: 'massimo: '
  11709. },
  11710. pinning: {
  11711. pinLeft: 'Blocca a sx',
  11712. pinRight: 'Blocca a dx',
  11713. unpin: 'Blocca in alto'
  11714. },
  11715. gridMenu: {
  11716. columns: 'Colonne:',
  11717. importerTitle: 'Importa',
  11718. exporterAllAsCsv: 'Esporta tutti i dati in CSV',
  11719. exporterVisibleAsCsv: 'Esporta i dati visibili in CSV',
  11720. exporterSelectedAsCsv: 'Esporta i dati selezionati in CSV',
  11721. exporterAllAsPdf: 'Esporta tutti i dati in PDF',
  11722. exporterVisibleAsPdf: 'Esporta i dati visibili in PDF',
  11723. exporterSelectedAsPdf: 'Esporta i dati selezionati in PDF',
  11724. exporterAllAsExcel: 'Esporta tutti i dati in excel',
  11725. exporterVisibleAsExcel: 'Esporta i dati visibili in excel',
  11726. exporterSelectedAsExcel: 'Esporta i dati selezionati in excel',
  11727. clearAllFilters: 'Pulire tutti i filtri'
  11728. },
  11729. importer: {
  11730. noHeaders: 'Impossibile reperire i nomi delle colonne, sicuro che siano indicati all\'interno del file?',
  11731. noObjects: 'Impossibile reperire gli oggetti, sicuro che siano indicati all\'interno del file?',
  11732. invalidCsv: 'Impossibile elaborare il file, sicuro che sia un CSV?',
  11733. invalidJson: 'Impossibile elaborare il file, sicuro che sia un JSON valido?',
  11734. jsonNotArray: 'Errore! Il file JSON da importare deve contenere un array.'
  11735. },
  11736. pagination: {
  11737. aria: {
  11738. pageToFirst: 'Prima',
  11739. pageBack: 'Indietro',
  11740. pageSelected: 'Pagina selezionata',
  11741. pageForward: 'Avanti',
  11742. pageToLast: 'Ultima'
  11743. },
  11744. sizes: 'elementi per pagina',
  11745. totalItems: 'elementi',
  11746. through: 'a',
  11747. of: 'di'
  11748. },
  11749. grouping: {
  11750. group: 'Raggruppa',
  11751. ungroup: 'Separa',
  11752. aggregate_count: 'Agg: N. Elem.',
  11753. aggregate_sum: 'Agg: Somma',
  11754. aggregate_max: 'Agg: Massimo',
  11755. aggregate_min: 'Agg: Minimo',
  11756. aggregate_avg: 'Agg: Media',
  11757. aggregate_remove: 'Agg: Rimuovi'
  11758. },
  11759. validate: {
  11760. error: 'Errore:',
  11761. minLength: 'Lunghezza minima pari a THRESHOLD caratteri.',
  11762. maxLength: 'Lunghezza massima pari a THRESHOLD caratteri.',
  11763. required: 'Necessario inserire un valore.'
  11764. }
  11765. });
  11766. return $delegate;
  11767. }]);
  11768. }]);
  11769. })();
  11770. (function() {
  11771. angular.module('ui.grid').config(['$provide', function($provide) {
  11772. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11773. $delegate.add('ja', {
  11774. headerCell: {
  11775. aria: {
  11776. defaultFilterLabel: '列のフィルター',
  11777. removeFilter: 'フィルターの解除',
  11778. columnMenuButtonLabel: '列のメニュー'
  11779. },
  11780. priority: '優先度:',
  11781. filterLabel: "列フィルター: "
  11782. },
  11783. aggregate: {
  11784. label: '項目'
  11785. },
  11786. groupPanel: {
  11787. description: 'ここに列ヘッダをドラッグアンドドロップして、その列でグループ化します。'
  11788. },
  11789. search: {
  11790. placeholder: '検索...',
  11791. showingItems: '表示中の項目:',
  11792. selectedItems: '選択した項目:',
  11793. totalItems: '項目の総数:',
  11794. size: 'ページサイズ:',
  11795. first: '最初のページ',
  11796. next: '次のページ',
  11797. previous: '前のページ',
  11798. last: '前のページ'
  11799. },
  11800. menu: {
  11801. text: '列の選択:'
  11802. },
  11803. sort: {
  11804. ascending: '昇順に並べ替え',
  11805. descending: '降順に並べ替え',
  11806. none: '並べ替え無し',
  11807. remove: '並べ替えの解除'
  11808. },
  11809. column: {
  11810. hide: '列の非表示'
  11811. },
  11812. aggregation: {
  11813. count: '行数: ',
  11814. sum: '合計: ',
  11815. avg: '平均: ',
  11816. min: '最小: ',
  11817. max: '最大: '
  11818. },
  11819. pinning: {
  11820. pinLeft: '左に固定',
  11821. pinRight: '右に固定',
  11822. unpin: '固定解除'
  11823. },
  11824. columnMenu: {
  11825. close: '閉じる'
  11826. },
  11827. gridMenu: {
  11828. aria: {
  11829. buttonLabel: 'グリッドメニュー'
  11830. },
  11831. columns: '列の表示/非表示:',
  11832. importerTitle: 'ファイルのインポート',
  11833. exporterAllAsCsv: 'すべてのデータをCSV形式でエクスポート',
  11834. exporterVisibleAsCsv: '表示中のデータをCSV形式でエクスポート',
  11835. exporterSelectedAsCsv: '選択したデータをCSV形式でエクスポート',
  11836. exporterAllAsPdf: 'すべてのデータをPDF形式でエクスポート',
  11837. exporterVisibleAsPdf: '表示中のデータをPDF形式でエクスポート',
  11838. exporterSelectedAsPdf: '選択したデータをPDF形式でエクスポート',
  11839. clearAllFilters: 'すべてのフィルタをクリア'
  11840. },
  11841. importer: {
  11842. noHeaders: '列名を取得できません。ファイルにヘッダが含まれていることを確認してください。',
  11843. noObjects: 'オブジェクトを取得できません。ファイルにヘッダ以外のデータが含まれていることを確認してください。',
  11844. invalidCsv: 'ファイルを処理できません。ファイルが有効なCSV形式であることを確認してください。',
  11845. invalidJson: 'ファイルを処理できません。ファイルが有効なJSON形式であることを確認してください。',
  11846. jsonNotArray: 'インポートしたJSONファイルには配列が含まれている必要があります。処理を中止します。'
  11847. },
  11848. pagination: {
  11849. aria: {
  11850. pageToFirst: '最初のページ',
  11851. pageBack: '前のページ',
  11852. pageSelected: '現在のページ',
  11853. pageForward: '次のページ',
  11854. pageToLast: '最後のページ'
  11855. },
  11856. sizes: '項目/ページ',
  11857. totalItems: '項目',
  11858. through: 'から',
  11859. of: '項目/全'
  11860. },
  11861. grouping: {
  11862. group: 'グループ化',
  11863. ungroup: 'グループ化の解除',
  11864. aggregate_count: '集計表示: 行数',
  11865. aggregate_sum: '集計表示: 合計',
  11866. aggregate_max: '集計表示: 最大',
  11867. aggregate_min: '集計表示: 最小',
  11868. aggregate_avg: '集計表示: 平均',
  11869. aggregate_remove: '集計表示: 解除'
  11870. },
  11871. validate: {
  11872. error: 'Error:',
  11873. minLength: 'THRESHOLD 文字以上で入力してください。',
  11874. maxLength: 'THRESHOLD 文字以下で入力してください。',
  11875. required: '値が必要です。'
  11876. }
  11877. });
  11878. return $delegate;
  11879. }]);
  11880. }]);
  11881. })();
  11882. (function () {
  11883. angular.module('ui.grid').config(['$provide', function($provide) {
  11884. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11885. $delegate.add('ko', {
  11886. aggregate: {
  11887. label: '아이템'
  11888. },
  11889. groupPanel: {
  11890. description: '컬럼으로 그룹핑하기 위해서는 컬럼 헤더를 끌어 떨어뜨려 주세요.'
  11891. },
  11892. search: {
  11893. placeholder: '검색...',
  11894. showingItems: '항목 보여주기:',
  11895. selectedItems: '선택 항목:',
  11896. totalItems: '전체 항목:',
  11897. size: '페이지 크기:',
  11898. first: '첫번째 페이지',
  11899. next: '다음 페이지',
  11900. previous: '이전 페이지',
  11901. last: '마지막 페이지'
  11902. },
  11903. menu: {
  11904. text: '컬럼을 선택하세요:'
  11905. },
  11906. sort: {
  11907. ascending: '오름차순 정렬',
  11908. descending: '내림차순 정렬',
  11909. remove: '소팅 제거'
  11910. },
  11911. column: {
  11912. hide: '컬럼 제거'
  11913. },
  11914. aggregation: {
  11915. count: '전체 갯수: ',
  11916. sum: '전체: ',
  11917. avg: '평균: ',
  11918. min: '최소: ',
  11919. max: '최대: '
  11920. },
  11921. pinning: {
  11922. pinLeft: '왼쪽 핀',
  11923. pinRight: '오른쪽 핀',
  11924. unpin: '핀 제거'
  11925. },
  11926. gridMenu: {
  11927. columns: '컬럼:',
  11928. importerTitle: '파일 가져오기',
  11929. exporterAllAsCsv: 'csv로 모든 데이터 내보내기',
  11930. exporterVisibleAsCsv: 'csv로 보이는 데이터 내보내기',
  11931. exporterSelectedAsCsv: 'csv로 선택된 데이터 내보내기',
  11932. exporterAllAsPdf: 'pdf로 모든 데이터 내보내기',
  11933. exporterVisibleAsPdf: 'pdf로 보이는 데이터 내보내기',
  11934. exporterSelectedAsPdf: 'pdf로 선택 데이터 내보내기',
  11935. clearAllFilters: '모든 필터를 청소'
  11936. },
  11937. importer: {
  11938. noHeaders: '컬럼명이 지정되어 있지 않습니다. 파일에 헤더가 명시되어 있는지 확인해 주세요.',
  11939. noObjects: '데이터가 지정되어 있지 않습니다. 데이터가 파일에 있는지 확인해 주세요.',
  11940. invalidCsv: '파일을 처리할 수 없습니다. 올바른 csv인지 확인해 주세요.',
  11941. invalidJson: '파일을 처리할 수 없습니다. 올바른 json인지 확인해 주세요.',
  11942. jsonNotArray: 'json 파일은 배열을 포함해야 합니다.'
  11943. },
  11944. pagination: {
  11945. sizes: '페이지당 항목',
  11946. totalItems: '전체 항목'
  11947. }
  11948. });
  11949. return $delegate;
  11950. }]);
  11951. }]);
  11952. })();
  11953. (function () {
  11954. angular.module('ui.grid').config(['$provide', function($provide) {
  11955. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  11956. $delegate.add('nl', {
  11957. aggregate: {
  11958. label: 'items'
  11959. },
  11960. groupPanel: {
  11961. description: 'Sleep hier een kolomnaam heen om op te groeperen.'
  11962. },
  11963. search: {
  11964. placeholder: 'Zoeken...',
  11965. showingItems: 'Getoonde items:',
  11966. selectedItems: 'Geselecteerde items:',
  11967. totalItems: 'Totaal aantal items:',
  11968. size: 'Items per pagina:',
  11969. first: 'Eerste pagina',
  11970. next: 'Volgende pagina',
  11971. previous: 'Vorige pagina',
  11972. last: 'Laatste pagina'
  11973. },
  11974. menu: {
  11975. text: 'Kies kolommen:'
  11976. },
  11977. sort: {
  11978. ascending: 'Sorteer oplopend',
  11979. descending: 'Sorteer aflopend',
  11980. remove: 'Verwijder sortering'
  11981. },
  11982. column: {
  11983. hide: 'Verberg kolom'
  11984. },
  11985. aggregation: {
  11986. count: 'Aantal rijen: ',
  11987. sum: 'Som: ',
  11988. avg: 'Gemiddelde: ',
  11989. min: 'Min: ',
  11990. max: 'Max: '
  11991. },
  11992. pinning: {
  11993. pinLeft: 'Zet links vast',
  11994. pinRight: 'Zet rechts vast',
  11995. unpin: 'Maak los'
  11996. },
  11997. gridMenu: {
  11998. columns: 'Kolommen:',
  11999. importerTitle: 'Importeer bestand',
  12000. exporterAllAsCsv: 'Exporteer alle data als csv',
  12001. exporterVisibleAsCsv: 'Exporteer zichtbare data als csv',
  12002. exporterSelectedAsCsv: 'Exporteer geselecteerde data als csv',
  12003. exporterAllAsPdf: 'Exporteer alle data als pdf',
  12004. exporterVisibleAsPdf: 'Exporteer zichtbare data als pdf',
  12005. exporterSelectedAsPdf: 'Exporteer geselecteerde data als pdf',
  12006. exporterAllAsExcel: 'Exporteer alle data als excel',
  12007. exporterVisibleAsExcel: 'Exporteer zichtbare data als excel',
  12008. exporterSelectedAsExcel: 'Exporteer alle data als excel',
  12009. clearAllFilters: 'Reinig alle filters'
  12010. },
  12011. importer: {
  12012. noHeaders: 'Kolomnamen kunnen niet worden afgeleid. Heeft het bestand een header?',
  12013. noObjects: 'Objecten kunnen niet worden afgeleid. Bevat het bestand data naast de headers?',
  12014. invalidCsv: 'Het bestand kan niet verwerkt worden. Is het een valide csv bestand?',
  12015. invalidJson: 'Het bestand kan niet verwerkt worden. Is het valide json?',
  12016. jsonNotArray: 'Het json bestand moet een array bevatten. De actie wordt geannuleerd.'
  12017. },
  12018. pagination: {
  12019. sizes: 'items per pagina',
  12020. totalItems: 'items',
  12021. of: 'van de'
  12022. },
  12023. grouping: {
  12024. group: 'Groepeer',
  12025. ungroup: 'Groepering opheffen',
  12026. aggregate_count: 'Agg: Aantal',
  12027. aggregate_sum: 'Agg: Som',
  12028. aggregate_max: 'Agg: Max',
  12029. aggregate_min: 'Agg: Min',
  12030. aggregate_avg: 'Agg: Gem',
  12031. aggregate_remove: 'Agg: Verwijder'
  12032. }
  12033. });
  12034. return $delegate;
  12035. }]);
  12036. }]);
  12037. })();
  12038. (function () {
  12039. angular.module('ui.grid').config(['$provide', function($provide) {
  12040. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  12041. $delegate.add('no', {
  12042. headerCell: {
  12043. aria: {
  12044. defaultFilterLabel: 'Filter for kolonne',
  12045. removeFilter: 'Fjern filter',
  12046. columnMenuButtonLabel: 'Kolonnemeny'
  12047. },
  12048. priority: 'Prioritet:',
  12049. filterLabel: "Filter for kolonne: "
  12050. },
  12051. aggregate: {
  12052. label: 'elementer'
  12053. },
  12054. groupPanel: {
  12055. description: 'Trekk en kolonneoverskrift hit og slipp den for å gruppere etter den kolonnen.'
  12056. },
  12057. search: {
  12058. placeholder: 'Søk...',
  12059. showingItems: 'Viste elementer:',
  12060. selectedItems: 'Valgte elementer:',
  12061. totalItems: 'Antall elementer:',
  12062. size: 'Sidestørrelse:',
  12063. first: 'Første side',
  12064. next: 'Neste side',
  12065. previous: 'Forrige side',
  12066. last: 'Siste side'
  12067. },
  12068. menu: {
  12069. text: 'Velg kolonner:'
  12070. },
  12071. sort: {
  12072. ascending: 'Sortere stigende',
  12073. descending: 'Sortere fallende',
  12074. none: 'Ingen sortering',
  12075. remove: 'Fjern sortering'
  12076. },
  12077. column: {
  12078. hide: 'Skjul kolonne'
  12079. },
  12080. aggregation: {
  12081. count: 'antall rader: ',
  12082. sum: 'total: ',
  12083. avg: 'gjennomsnitt: ',
  12084. min: 'minimum: ',
  12085. max: 'maksimum: '
  12086. },
  12087. pinning: {
  12088. pinLeft: 'Fest til venstre',
  12089. pinRight: 'Fest til høyre',
  12090. unpin: 'Løsne'
  12091. },
  12092. columnMenu: {
  12093. close: 'Lukk'
  12094. },
  12095. gridMenu: {
  12096. aria: {
  12097. buttonLabel: 'Grid Menu'
  12098. },
  12099. columns: 'Kolonner:',
  12100. importerTitle: 'Importer fil',
  12101. exporterAllAsCsv: 'Eksporter alle data som csv',
  12102. exporterVisibleAsCsv: 'Eksporter synlige data som csv',
  12103. exporterSelectedAsCsv: 'Eksporter utvalgte data som csv',
  12104. exporterAllAsPdf: 'Eksporter alle data som pdf',
  12105. exporterVisibleAsPdf: 'Eksporter synlige data som pdf',
  12106. exporterSelectedAsPdf: 'Eksporter utvalgte data som pdf',
  12107. exporterAllAsExcel: 'Eksporter alle data som excel',
  12108. exporterVisibleAsExcel: 'Eksporter synlige data som excel',
  12109. exporterSelectedAsExcel: 'Eksporter utvalgte data som excel',
  12110. clearAllFilters: 'Clear all filters'
  12111. },
  12112. importer: {
  12113. noHeaders: 'Kolonnenavn kunne ikke avledes. Har filen en overskrift?',
  12114. noObjects: 'Objekter kunne ikke avledes. Er der andre data i filen enn overskriften?',
  12115. invalidCsv: 'Filen kunne ikke behandles. Er den gyldig CSV?',
  12116. invalidJson: 'Filen kunne ikke behandles. Er den gyldig JSON?',
  12117. jsonNotArray: 'Importert JSON-fil må inneholde en liste. Avbryter.'
  12118. },
  12119. pagination: {
  12120. aria: {
  12121. pageToFirst: 'Gå til første side',
  12122. pageBack: 'Gå til forrige side',
  12123. pageSelected: 'Valgte side',
  12124. pageForward: 'Gå til neste side',
  12125. pageToLast: 'Gå til siste side'
  12126. },
  12127. sizes: 'elementer per side',
  12128. totalItems: 'elementer',
  12129. through: 'til',
  12130. of: 'av'
  12131. },
  12132. grouping: {
  12133. group: 'Gruppere',
  12134. ungroup: 'Fjerne gruppering',
  12135. aggregate_count: 'Agr: Antall',
  12136. aggregate_sum: 'Agr: Sum',
  12137. aggregate_max: 'Agr: Maksimum',
  12138. aggregate_min: 'Agr: Minimum',
  12139. aggregate_avg: 'Agr: Gjennomsnitt',
  12140. aggregate_remove: 'Agr: Fjern'
  12141. }
  12142. });
  12143. return $delegate;
  12144. }]);
  12145. }]);
  12146. })();
  12147. (function () {
  12148. angular.module('ui.grid').config(['$provide', function($provide) {
  12149. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  12150. $delegate.add('pl', {
  12151. headerCell: {
  12152. aria: {
  12153. defaultFilterLabel: 'Filtr dla kolumny',
  12154. removeFilter: 'Usuń filtr',
  12155. columnMenuButtonLabel: 'Opcje kolumny',
  12156. column: 'Kolumna'
  12157. },
  12158. priority: 'Priorytet:',
  12159. filterLabel: "Filtr dla kolumny: "
  12160. },
  12161. aggregate: {
  12162. label: 'pozycji'
  12163. },
  12164. groupPanel: {
  12165. description: 'Przeciągnij nagłówek kolumny tutaj, aby pogrupować według niej.'
  12166. },
  12167. search: {
  12168. aria: {
  12169. selected: 'Wiersz zaznaczony',
  12170. notSelected: 'Wiersz niezaznaczony'
  12171. },
  12172. placeholder: 'Szukaj...',
  12173. showingItems: 'Widoczne pozycje:',
  12174. selectedItems: 'Zaznaczone pozycje:',
  12175. totalItems: 'Wszystkich pozycji:',
  12176. size: 'Rozmiar strony:',
  12177. first: 'Pierwsza strona',
  12178. next: 'Następna strona',
  12179. previous: 'Poprzednia strona',
  12180. last: 'Ostatnia strona'
  12181. },
  12182. menu: {
  12183. text: 'Wybierz kolumny:'
  12184. },
  12185. sort: {
  12186. ascending: 'Sortuj rosnąco',
  12187. descending: 'Sortuj malejąco',
  12188. none: 'Brak sortowania',
  12189. remove: 'Wyłącz sortowanie'
  12190. },
  12191. column: {
  12192. hide: 'Ukryj kolumnę'
  12193. },
  12194. aggregation: {
  12195. count: 'Razem pozycji: ',
  12196. sum: 'Razem: ',
  12197. avg: 'Średnia: ',
  12198. min: 'Min: ',
  12199. max: 'Max: '
  12200. },
  12201. pinning: {
  12202. pinLeft: 'Przypnij do lewej',
  12203. pinRight: 'Przypnij do prawej',
  12204. unpin: 'Odepnij'
  12205. },
  12206. columnMenu: {
  12207. close: 'Zamknij'
  12208. },
  12209. gridMenu: {
  12210. aria: {
  12211. buttonLabel: 'Opcje tabeli'
  12212. },
  12213. columns: 'Kolumny:',
  12214. importerTitle: 'Importuj plik',
  12215. exporterAllAsCsv: 'Eksportuj wszystkie dane do csv',
  12216. exporterVisibleAsCsv: 'Eksportuj widoczne dane do csv',
  12217. exporterSelectedAsCsv: 'Eksportuj zaznaczone dane do csv',
  12218. exporterAllAsPdf: 'Eksportuj wszystkie dane do pdf',
  12219. exporterVisibleAsPdf: 'Eksportuj widoczne dane do pdf',
  12220. exporterSelectedAsPdf: 'Eksportuj zaznaczone dane do pdf',
  12221. exporterAllAsExcel: 'Eksportuj wszystkie dane do excel',
  12222. exporterVisibleAsExcel: 'Eksportuj widoczne dane do excel',
  12223. exporterSelectedAsExcel: 'Eksportuj zaznaczone dane do excel',
  12224. clearAllFilters: 'Wyczyść filtry'
  12225. },
  12226. importer: {
  12227. noHeaders: 'Nie udało się wczytać nazw kolumn. Czy plik posiada nagłówek?',
  12228. noObjects: 'Nie udalo się wczytać pozycji. Czy plik zawiera dane?',
  12229. invalidCsv: 'Nie udało się przetworzyć pliku. Czy to prawidłowy plik CSV?',
  12230. invalidJson: 'Nie udało się przetworzyć pliku. Czy to prawidłowy plik JSON?',
  12231. jsonNotArray: 'Importowany plik JSON musi zawierać tablicę. Importowanie przerwane.'
  12232. },
  12233. pagination: {
  12234. aria: {
  12235. pageToFirst: 'Pierwsza strona',
  12236. pageBack: 'Poprzednia strona',
  12237. pageSelected: 'Wybrana strona',
  12238. pageForward: 'Następna strona',
  12239. pageToLast: 'Ostatnia strona'
  12240. },
  12241. sizes: 'pozycji na stronę',
  12242. totalItems: 'pozycji',
  12243. through: 'do',
  12244. of: 'z'
  12245. },
  12246. grouping: {
  12247. group: 'Grupuj',
  12248. ungroup: 'Rozgrupuj',
  12249. aggregate_count: 'Zbiorczo: Razem',
  12250. aggregate_sum: 'Zbiorczo: Suma',
  12251. aggregate_max: 'Zbiorczo: Max',
  12252. aggregate_min: 'Zbiorczo: Min',
  12253. aggregate_avg: 'Zbiorczo: Średnia',
  12254. aggregate_remove: 'Zbiorczo: Usuń'
  12255. },
  12256. validate: {
  12257. error: 'Błąd:',
  12258. minLength: 'Wartość powinna składać się z co najmniej THRESHOLD znaków.',
  12259. maxLength: 'Wartość powinna składać się z przynajmniej THRESHOLD znaków.',
  12260. required: 'Wartość jest wymagana.'
  12261. }
  12262. });
  12263. return $delegate;
  12264. }]);
  12265. }]);
  12266. })();
  12267. (function () {
  12268. angular.module('ui.grid').config(['$provide', function($provide) {
  12269. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  12270. $delegate.add('pt-br', {
  12271. headerCell: {
  12272. aria: {
  12273. defaultFilterLabel: 'Filtro por coluna',
  12274. removeFilter: 'Remover filtro',
  12275. columnMenuButtonLabel: 'Menu coluna'
  12276. },
  12277. priority: 'Prioridade:',
  12278. filterLabel: "Filtro por coluna: "
  12279. },
  12280. aggregate: {
  12281. label: 'itens'
  12282. },
  12283. groupPanel: {
  12284. description: 'Arraste e solte uma coluna aqui para agrupar por essa coluna'
  12285. },
  12286. search: {
  12287. placeholder: 'Procurar...',
  12288. showingItems: 'Mostrando os Itens:',
  12289. selectedItems: 'Items Selecionados:',
  12290. totalItems: 'Total de Itens:',
  12291. size: 'Tamanho da Página:',
  12292. first: 'Primeira Página',
  12293. next: 'Próxima Página',
  12294. previous: 'Página Anterior',
  12295. last: 'Última Página'
  12296. },
  12297. menu: {
  12298. text: 'Selecione as colunas:'
  12299. },
  12300. sort: {
  12301. ascending: 'Ordenar Ascendente',
  12302. descending: 'Ordenar Descendente',
  12303. none: 'Nenhuma Ordem',
  12304. remove: 'Remover Ordenação'
  12305. },
  12306. column: {
  12307. hide: 'Esconder coluna'
  12308. },
  12309. aggregation: {
  12310. count: 'total de linhas: ',
  12311. sum: 'total: ',
  12312. avg: 'med: ',
  12313. min: 'min: ',
  12314. max: 'max: '
  12315. },
  12316. pinning: {
  12317. pinLeft: 'Fixar Esquerda',
  12318. pinRight: 'Fixar Direita',
  12319. unpin: 'Desprender'
  12320. },
  12321. columnMenu: {
  12322. close: 'Fechar'
  12323. },
  12324. gridMenu: {
  12325. aria: {
  12326. buttonLabel: 'Menu Grid'
  12327. },
  12328. columns: 'Colunas:',
  12329. importerTitle: 'Importar arquivo',
  12330. exporterAllAsCsv: 'Exportar todos os dados como csv',
  12331. exporterVisibleAsCsv: 'Exportar dados visíveis como csv',
  12332. exporterSelectedAsCsv: 'Exportar dados selecionados como csv',
  12333. exporterAllAsPdf: 'Exportar todos os dados como pdf',
  12334. exporterVisibleAsPdf: 'Exportar dados visíveis como pdf',
  12335. exporterSelectedAsPdf: 'Exportar dados selecionados como pdf',
  12336. exporterAllAsExcel: 'Exportar todos os dados como excel',
  12337. exporterVisibleAsExcel: 'Exportar dados visíveis como excel',
  12338. clearAllFilters: 'Limpar todos os filtros'
  12339. },
  12340. importer: {
  12341. noHeaders: 'Nomes de colunas não puderam ser derivados. O arquivo tem um cabeçalho?',
  12342. noObjects: 'Objetos não puderam ser derivados. Havia dados no arquivo, além dos cabeçalhos?',
  12343. invalidCsv: 'Arquivo não pode ser processado. É um CSV válido?',
  12344. invalidJson: 'Arquivo não pode ser processado. É um Json válido?',
  12345. jsonNotArray: 'Arquivo json importado tem que conter um array. Abortando.'
  12346. },
  12347. pagination: {
  12348. aria: {
  12349. pageToFirst: 'Primeira página',
  12350. pageBack: 'Página anterior',
  12351. pageSelected: 'Página Selecionada',
  12352. pageForward: 'Proxima',
  12353. pageToLast: 'Anterior'
  12354. },
  12355. sizes: 'itens por página',
  12356. totalItems: 'itens',
  12357. through: 'através dos',
  12358. of: 'de'
  12359. },
  12360. grouping: {
  12361. group: 'Agrupar',
  12362. ungroup: 'Desagrupar',
  12363. aggregate_count: 'Agr: Contar',
  12364. aggregate_sum: 'Agr: Soma',
  12365. aggregate_max: 'Agr: Max',
  12366. aggregate_min: 'Agr: Min',
  12367. aggregate_avg: 'Agr: Med',
  12368. aggregate_remove: 'Agr: Remover'
  12369. }
  12370. });
  12371. return $delegate;
  12372. }]);
  12373. }]);
  12374. })();
  12375. (function () {
  12376. angular.module('ui.grid').config(['$provide', function($provide) {
  12377. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  12378. $delegate.add('pt', {
  12379. headerCell: {
  12380. aria: {
  12381. defaultFilterLabel: 'Filtro por coluna',
  12382. removeFilter: 'Remover filtro',
  12383. columnMenuButtonLabel: 'Menu coluna'
  12384. },
  12385. priority: 'Prioridade:',
  12386. filterLabel: "Filtro por coluna: "
  12387. },
  12388. aggregate: {
  12389. label: 'itens'
  12390. },
  12391. groupPanel: {
  12392. description: 'Arraste e solte uma coluna aqui para agrupar por essa coluna'
  12393. },
  12394. search: {
  12395. placeholder: 'Procurar...',
  12396. showingItems: 'Mostrando os Itens:',
  12397. selectedItems: 'Itens Selecionados:',
  12398. totalItems: 'Total de Itens:',
  12399. size: 'Tamanho da Página:',
  12400. first: 'Primeira Página',
  12401. next: 'Próxima Página',
  12402. previous: 'Página Anterior',
  12403. last: 'Última Página'
  12404. },
  12405. menu: {
  12406. text: 'Selecione as colunas:'
  12407. },
  12408. sort: {
  12409. ascending: 'Ordenar Ascendente',
  12410. descending: 'Ordenar Descendente',
  12411. none: 'Nenhuma Ordem',
  12412. remove: 'Remover Ordenação'
  12413. },
  12414. column: {
  12415. hide: 'Esconder coluna'
  12416. },
  12417. aggregation: {
  12418. count: 'total de linhas: ',
  12419. sum: 'total: ',
  12420. avg: 'med: ',
  12421. min: 'min: ',
  12422. max: 'max: '
  12423. },
  12424. pinning: {
  12425. pinLeft: 'Fixar Esquerda',
  12426. pinRight: 'Fixar Direita',
  12427. unpin: 'Desprender'
  12428. },
  12429. columnMenu: {
  12430. close: 'Fechar'
  12431. },
  12432. gridMenu: {
  12433. aria: {
  12434. buttonLabel: 'Menu Grid'
  12435. },
  12436. columns: 'Colunas:',
  12437. importerTitle: 'Importar ficheiro',
  12438. exporterAllAsCsv: 'Exportar todos os dados como csv',
  12439. exporterVisibleAsCsv: 'Exportar dados visíveis como csv',
  12440. exporterSelectedAsCsv: 'Exportar dados selecionados como csv',
  12441. exporterAllAsPdf: 'Exportar todos os dados como pdf',
  12442. exporterVisibleAsPdf: 'Exportar dados visíveis como pdf',
  12443. exporterSelectedAsPdf: 'Exportar dados selecionados como pdf',
  12444. clearAllFilters: 'Limpar todos os filtros'
  12445. },
  12446. importer: {
  12447. noHeaders: 'Nomes de colunas não puderam ser derivados. O ficheiro tem um cabeçalho?',
  12448. noObjects: 'Objetos não puderam ser derivados. Havia dados no ficheiro, além dos cabeçalhos?',
  12449. invalidCsv: 'Ficheiro não pode ser processado. É um CSV válido?',
  12450. invalidJson: 'Ficheiro não pode ser processado. É um Json válido?',
  12451. jsonNotArray: 'Ficheiro json importado tem que conter um array. Interrompendo.'
  12452. },
  12453. pagination: {
  12454. aria: {
  12455. pageToFirst: 'Primeira página',
  12456. pageBack: 'Página anterior',
  12457. pageSelected: 'Página Selecionada',
  12458. pageForward: 'Próxima',
  12459. pageToLast: 'Anterior'
  12460. },
  12461. sizes: 'itens por página',
  12462. totalItems: 'itens',
  12463. through: 'a',
  12464. of: 'de'
  12465. },
  12466. grouping: {
  12467. group: 'Agrupar',
  12468. ungroup: 'Desagrupar',
  12469. aggregate_count: 'Agr: Contar',
  12470. aggregate_sum: 'Agr: Soma',
  12471. aggregate_max: 'Agr: Max',
  12472. aggregate_min: 'Agr: Min',
  12473. aggregate_avg: 'Agr: Med',
  12474. aggregate_remove: 'Agr: Remover'
  12475. }
  12476. });
  12477. return $delegate;
  12478. }]);
  12479. }]);
  12480. })();
  12481. (function () {
  12482. angular.module('ui.grid').config(['$provide', function($provide) {
  12483. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  12484. $delegate.add('ro', {
  12485. headerCell: {
  12486. aria: {
  12487. defaultFilterLabel: 'Filtru pentru coloana',
  12488. removeFilter: 'Sterge filtru',
  12489. columnMenuButtonLabel: 'Column Menu'
  12490. },
  12491. priority: 'Prioritate:',
  12492. filterLabel: "Filtru pentru coloana:"
  12493. },
  12494. aggregate: {
  12495. label: 'Elemente'
  12496. },
  12497. groupPanel: {
  12498. description: 'Trage un cap de coloana aici pentru a grupa elementele dupa coloana respectiva'
  12499. },
  12500. search: {
  12501. placeholder: 'Cauta...',
  12502. showingItems: 'Arata elementele:',
  12503. selectedItems: 'Elementele selectate:',
  12504. totalItems: 'Total elemente:',
  12505. size: 'Marime pagina:',
  12506. first: 'Prima pagina',
  12507. next: 'Pagina urmatoare',
  12508. previous: 'Pagina anterioara',
  12509. last: 'Ultima pagina'
  12510. },
  12511. menu: {
  12512. text: 'Alege coloane:'
  12513. },
  12514. sort: {
  12515. ascending: 'Ordoneaza crescator',
  12516. descending: 'Ordoneaza descrescator',
  12517. none: 'Fara ordonare',
  12518. remove: 'Sterge ordonarea'
  12519. },
  12520. column: {
  12521. hide: 'Ascunde coloana'
  12522. },
  12523. aggregation: {
  12524. count: 'total linii: ',
  12525. sum: 'total: ',
  12526. avg: 'medie: ',
  12527. min: 'min: ',
  12528. max: 'max: '
  12529. },
  12530. pinning: {
  12531. pinLeft: 'Pin la stanga',
  12532. pinRight: 'Pin la dreapta',
  12533. unpin: 'Sterge pinul'
  12534. },
  12535. columnMenu: {
  12536. close: 'Inchide'
  12537. },
  12538. gridMenu: {
  12539. aria: {
  12540. buttonLabel: 'Grid Menu'
  12541. },
  12542. columns: 'Coloane:',
  12543. importerTitle: 'Incarca fisier',
  12544. exporterAllAsCsv: 'Exporta toate datele ca csv',
  12545. exporterVisibleAsCsv: 'Exporta datele vizibile ca csv',
  12546. exporterSelectedAsCsv: 'Exporta datele selectate ca csv',
  12547. exporterAllAsPdf: 'Exporta toate datele ca pdf',
  12548. exporterVisibleAsPdf: 'Exporta datele vizibile ca pdf',
  12549. exporterSelectedAsPdf: 'Exporta datele selectate ca csv pdf',
  12550. clearAllFilters: 'Sterge toate filtrele'
  12551. },
  12552. importer: {
  12553. noHeaders: 'Numele coloanelor nu a putut fi incarcat, acest fisier are un header?',
  12554. noObjects: 'Datele nu au putut fi incarcate, exista date in fisier in afara numelor de coloane?',
  12555. invalidCsv: 'Fisierul nu a putut fi procesat, ati incarcat un CSV valid ?',
  12556. invalidJson: 'Fisierul nu a putut fi procesat, ati incarcat un Json valid?',
  12557. jsonNotArray: 'Json-ul incarcat trebuie sa contina un array, inchidere.'
  12558. },
  12559. pagination: {
  12560. aria: {
  12561. pageToFirst: 'Prima pagina',
  12562. pageBack: 'O pagina inapoi',
  12563. pageSelected: 'Pagina selectata',
  12564. pageForward: 'O pagina inainte',
  12565. pageToLast: 'Ultima pagina'
  12566. },
  12567. sizes: 'Elemente per pagina',
  12568. totalItems: 'elemente',
  12569. through: 'prin',
  12570. of: 'of'
  12571. },
  12572. grouping: {
  12573. group: 'Grupeaza',
  12574. ungroup: 'Opreste gruparea',
  12575. aggregate_count: 'Agg: Count',
  12576. aggregate_sum: 'Agg: Sum',
  12577. aggregate_max: 'Agg: Max',
  12578. aggregate_min: 'Agg: Min',
  12579. aggregate_avg: 'Agg: Avg',
  12580. aggregate_remove: 'Agg: Remove'
  12581. }
  12582. });
  12583. return $delegate;
  12584. }]);
  12585. }]);
  12586. })();
  12587. (function () {
  12588. angular.module('ui.grid').config(['$provide', function($provide) {
  12589. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  12590. $delegate.add('ru', {
  12591. headerCell: {
  12592. aria: {
  12593. defaultFilterLabel: 'Фильтр столбца',
  12594. removeFilter: 'Удалить фильтр',
  12595. columnMenuButtonLabel: 'Меню столбца'
  12596. },
  12597. priority: 'Приоритет:',
  12598. filterLabel: "Фильтр столбца: "
  12599. },
  12600. aggregate: {
  12601. label: 'элементы'
  12602. },
  12603. groupPanel: {
  12604. description: 'Для группировки по столбцу перетащите сюда его название.'
  12605. },
  12606. search: {
  12607. placeholder: 'Поиск...',
  12608. showingItems: 'Показать элементы:',
  12609. selectedItems: 'Выбранные элементы:',
  12610. totalItems: 'Всего элементов:',
  12611. size: 'Размер страницы:',
  12612. first: 'Первая страница',
  12613. next: 'Следующая страница',
  12614. previous: 'Предыдущая страница',
  12615. last: 'Последняя страница'
  12616. },
  12617. menu: {
  12618. text: 'Выбрать столбцы:'
  12619. },
  12620. sort: {
  12621. ascending: 'По возрастанию',
  12622. descending: 'По убыванию',
  12623. none: 'Без сортировки',
  12624. remove: 'Убрать сортировку'
  12625. },
  12626. column: {
  12627. hide: 'Спрятать столбец'
  12628. },
  12629. aggregation: {
  12630. count: 'всего строк: ',
  12631. sum: 'итого: ',
  12632. avg: 'среднее: ',
  12633. min: 'мин: ',
  12634. max: 'макс: '
  12635. },
  12636. pinning: {
  12637. pinLeft: 'Закрепить слева',
  12638. pinRight: 'Закрепить справа',
  12639. unpin: 'Открепить'
  12640. },
  12641. columnMenu: {
  12642. close: 'Закрыть'
  12643. },
  12644. gridMenu: {
  12645. aria: {
  12646. buttonLabel: 'Меню'
  12647. },
  12648. columns: 'Столбцы:',
  12649. importerTitle: 'Импортировать файл',
  12650. exporterAllAsCsv: 'Экспортировать всё в CSV',
  12651. exporterVisibleAsCsv: 'Экспортировать видимые данные в CSV',
  12652. exporterSelectedAsCsv: 'Экспортировать выбранные данные в CSV',
  12653. exporterAllAsPdf: 'Экспортировать всё в PDF',
  12654. exporterVisibleAsPdf: 'Экспортировать видимые данные в PDF',
  12655. exporterSelectedAsPdf: 'Экспортировать выбранные данные в PDF',
  12656. clearAllFilters: 'Очистите все фильтры'
  12657. },
  12658. importer: {
  12659. noHeaders: 'Не удалось получить названия столбцов, есть ли в файле заголовок?',
  12660. noObjects: 'Не удалось получить данные, есть ли в файле строки кроме заголовка?',
  12661. invalidCsv: 'Не удалось обработать файл, это правильный CSV-файл?',
  12662. invalidJson: 'Не удалось обработать файл, это правильный JSON?',
  12663. jsonNotArray: 'Импортируемый JSON-файл должен содержать массив, операция отменена.'
  12664. },
  12665. pagination: {
  12666. aria: {
  12667. pageToFirst: 'Первая страница',
  12668. pageBack: 'Предыдущая страница',
  12669. pageSelected: 'Выбранная страница',
  12670. pageForward: 'Следующая страница',
  12671. pageToLast: 'Последняя страница'
  12672. },
  12673. sizes: 'строк на страницу',
  12674. totalItems: 'строк',
  12675. through: 'по',
  12676. of: 'из'
  12677. },
  12678. grouping: {
  12679. group: 'Группировать',
  12680. ungroup: 'Разгруппировать',
  12681. aggregate_count: 'Группировать: Count',
  12682. aggregate_sum: 'Для группы: Сумма',
  12683. aggregate_max: 'Для группы: Максимум',
  12684. aggregate_min: 'Для группы: Минимум',
  12685. aggregate_avg: 'Для группы: Среднее',
  12686. aggregate_remove: 'Для группы: Пусто'
  12687. }
  12688. });
  12689. return $delegate;
  12690. }]);
  12691. }]);
  12692. })();
  12693. (function () {
  12694. angular.module('ui.grid').config(['$provide', function($provide) {
  12695. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  12696. $delegate.add('sk', {
  12697. aggregate: {
  12698. label: 'items'
  12699. },
  12700. groupPanel: {
  12701. description: 'Pretiahni sem názov stĺpca pre zoskupenie podľa toho stĺpca.'
  12702. },
  12703. search: {
  12704. placeholder: 'Hľadaj...',
  12705. showingItems: 'Zobrazujem položky:',
  12706. selectedItems: 'Vybraté položky:',
  12707. totalItems: 'Počet položiek:',
  12708. size: 'Počet:',
  12709. first: 'Prvá strana',
  12710. next: 'Ďalšia strana',
  12711. previous: 'Predchádzajúca strana',
  12712. last: 'Posledná strana'
  12713. },
  12714. menu: {
  12715. text: 'Vyberte stĺpce:'
  12716. },
  12717. sort: {
  12718. ascending: 'Zotriediť vzostupne',
  12719. descending: 'Zotriediť zostupne',
  12720. remove: 'Vymazať triedenie'
  12721. },
  12722. aggregation: {
  12723. count: 'total rows: ',
  12724. sum: 'total: ',
  12725. avg: 'avg: ',
  12726. min: 'min: ',
  12727. max: 'max: '
  12728. },
  12729. gridMenu: {
  12730. columns: 'Columns:',
  12731. importerTitle: 'Import file',
  12732. exporterAllAsCsv: 'Export all data as csv',
  12733. exporterVisibleAsCsv: 'Export visible data as csv',
  12734. exporterSelectedAsCsv: 'Export selected data as csv',
  12735. exporterAllAsPdf: 'Export all data as pdf',
  12736. exporterVisibleAsPdf: 'Export visible data as pdf',
  12737. exporterSelectedAsPdf: 'Export selected data as pdf',
  12738. exporterAllAsExcel: 'Export all data as excel',
  12739. exporterVisibleAsExcel: 'Export visible data as excel',
  12740. exporterSelectedAsExcel: 'Export selected data as excel',
  12741. clearAllFilters: 'Clear all filters'
  12742. },
  12743. importer: {
  12744. noHeaders: 'Column names were unable to be derived, does the file have a header?',
  12745. noObjects: 'Objects were not able to be derived, was there data in the file other than headers?',
  12746. invalidCsv: 'File was unable to be processed, is it valid CSV?',
  12747. invalidJson: 'File was unable to be processed, is it valid Json?',
  12748. jsonNotArray: 'Imported json file must contain an array, aborting.'
  12749. }
  12750. });
  12751. return $delegate;
  12752. }]);
  12753. }]);
  12754. })();
  12755. (function () {
  12756. angular.module('ui.grid').config(['$provide', function($provide) {
  12757. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  12758. $delegate.add('sv', {
  12759. aggregate: {
  12760. label: 'Artiklar'
  12761. },
  12762. groupPanel: {
  12763. description: 'Dra en kolumnrubrik hit och släpp den för att gruppera efter den kolumnen.'
  12764. },
  12765. search: {
  12766. placeholder: 'Sök...',
  12767. showingItems: 'Visar artiklar:',
  12768. selectedItems: 'Valda artiklar:',
  12769. totalItems: 'Antal artiklar:',
  12770. size: 'Sidstorlek:',
  12771. first: 'Första sidan',
  12772. next: 'Nästa sida',
  12773. previous: 'Föregående sida',
  12774. last: 'Sista sidan'
  12775. },
  12776. menu: {
  12777. text: 'Välj kolumner:'
  12778. },
  12779. sort: {
  12780. ascending: 'Sortera stigande',
  12781. descending: 'Sortera fallande',
  12782. remove: 'Inaktivera sortering'
  12783. },
  12784. column: {
  12785. hide: 'Göm kolumn'
  12786. },
  12787. aggregation: {
  12788. count: 'Antal rader: ',
  12789. sum: 'Summa: ',
  12790. avg: 'Genomsnitt: ',
  12791. min: 'Min: ',
  12792. max: 'Max: '
  12793. },
  12794. pinning: {
  12795. pinLeft: 'Fäst vänster',
  12796. pinRight: 'Fäst höger',
  12797. unpin: 'Lösgör'
  12798. },
  12799. gridMenu: {
  12800. columns: 'Kolumner:',
  12801. importerTitle: 'Importera fil',
  12802. exporterAllAsCsv: 'Exportera all data som CSV',
  12803. exporterVisibleAsCsv: 'Exportera synlig data som CSV',
  12804. exporterSelectedAsCsv: 'Exportera markerad data som CSV',
  12805. exporterAllAsPdf: 'Exportera all data som PDF',
  12806. exporterVisibleAsPdf: 'Exportera synlig data som PDF',
  12807. exporterSelectedAsPdf: 'Exportera markerad data som PDF',
  12808. clearAllFilters: 'Rengör alla filter'
  12809. },
  12810. importer: {
  12811. noHeaders: 'Kolumnnamn kunde inte härledas. Har filen ett sidhuvud?',
  12812. noObjects: 'Objekt kunde inte härledas. Har filen data undantaget sidhuvud?',
  12813. invalidCsv: 'Filen kunde inte behandlas, är den en giltig CSV?',
  12814. invalidJson: 'Filen kunde inte behandlas, är den en giltig JSON?',
  12815. jsonNotArray: 'Importerad JSON-fil måste innehålla ett fält. Import avbruten.'
  12816. },
  12817. pagination: {
  12818. sizes: 'Artiklar per sida',
  12819. totalItems: 'Artiklar'
  12820. }
  12821. });
  12822. return $delegate;
  12823. }]);
  12824. }]);
  12825. })();
  12826. (function () {
  12827. angular.module('ui.grid').config(['$provide', function($provide) {
  12828. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  12829. $delegate.add('ta', {
  12830. aggregate: {
  12831. label: 'உருப்படிகள்'
  12832. },
  12833. groupPanel: {
  12834. description: 'ஒரு பத்தியை குழுவாக அமைக்க அப்பத்தியின் தலைப்பை இங்கே இழுத்து வரவும் '
  12835. },
  12836. search: {
  12837. placeholder: 'தேடல் ...',
  12838. showingItems: 'உருப்படிகளை காண்பித்தல்:',
  12839. selectedItems: 'தேர்ந்தெடுக்கப்பட்ட உருப்படிகள்:',
  12840. totalItems: 'மொத்த உருப்படிகள்:',
  12841. size: 'பக்க அளவு: ',
  12842. first: 'முதல் பக்கம்',
  12843. next: 'அடுத்த பக்கம்',
  12844. previous: 'முந்தைய பக்கம் ',
  12845. last: 'இறுதி பக்கம்'
  12846. },
  12847. menu: {
  12848. text: 'பத்திகளை தேர்ந்தெடு:'
  12849. },
  12850. sort: {
  12851. ascending: 'மேலிருந்து கீழாக',
  12852. descending: 'கீழிருந்து மேலாக',
  12853. remove: 'வரிசையை நீக்கு'
  12854. },
  12855. column: {
  12856. hide: 'பத்தியை மறைத்து வை '
  12857. },
  12858. aggregation: {
  12859. count: 'மொத்த வரிகள்:',
  12860. sum: 'மொத்தம்: ',
  12861. avg: 'சராசரி: ',
  12862. min: 'குறைந்தபட்ச: ',
  12863. max: 'அதிகபட்ச: '
  12864. },
  12865. pinning: {
  12866. pinLeft: 'இடதுபுறமாக தைக்க ',
  12867. pinRight: 'வலதுபுறமாக தைக்க',
  12868. unpin: 'பிரி'
  12869. },
  12870. gridMenu: {
  12871. columns: 'பத்திகள்:',
  12872. importerTitle: 'கோப்பு : படித்தல்',
  12873. exporterAllAsCsv: 'எல்லா தரவுகளையும் கோப்பாக்கு: csv',
  12874. exporterVisibleAsCsv: 'இருக்கும் தரவுகளை கோப்பாக்கு: csv',
  12875. exporterSelectedAsCsv: 'தேர்ந்தெடுத்த தரவுகளை கோப்பாக்கு: csv',
  12876. exporterAllAsPdf: 'எல்லா தரவுகளையும் கோப்பாக்கு: pdf',
  12877. exporterVisibleAsPdf: 'இருக்கும் தரவுகளை கோப்பாக்கு: pdf',
  12878. exporterSelectedAsPdf: 'தேர்ந்தெடுத்த தரவுகளை கோப்பாக்கு: pdf',
  12879. clearAllFilters: 'Clear all filters'
  12880. },
  12881. importer: {
  12882. noHeaders: 'பத்தியின் தலைப்புகளை பெற இயலவில்லை, கோப்பிற்கு தலைப்பு உள்ளதா?',
  12883. noObjects: 'இலக்குகளை உருவாக்க முடியவில்லை, கோப்பில் தலைப்புகளை தவிர தரவு ஏதேனும் உள்ளதா? ',
  12884. invalidCsv: 'சரிவர நடைமுறை படுத்த இயலவில்லை, கோப்பு சரிதானா? - csv',
  12885. invalidJson: 'சரிவர நடைமுறை படுத்த இயலவில்லை, கோப்பு சரிதானா? - json',
  12886. jsonNotArray: 'படித்த கோப்பில் வரிசைகள் உள்ளது, நடைமுறை ரத்து செய் : json'
  12887. },
  12888. pagination: {
  12889. sizes : 'உருப்படிகள் / பக்கம்',
  12890. totalItems : 'உருப்படிகள் '
  12891. },
  12892. grouping: {
  12893. group : 'குழு',
  12894. ungroup : 'பிரி',
  12895. aggregate_count : 'மதிப்பீட்டு : எண்ணு',
  12896. aggregate_sum : 'மதிப்பீட்டு : கூட்டல்',
  12897. aggregate_max : 'மதிப்பீட்டு : அதிகபட்சம்',
  12898. aggregate_min : 'மதிப்பீட்டு : குறைந்தபட்சம்',
  12899. aggregate_avg : 'மதிப்பீட்டு : சராசரி',
  12900. aggregate_remove : 'மதிப்பீட்டு : நீக்கு'
  12901. }
  12902. });
  12903. return $delegate;
  12904. }]);
  12905. }]);
  12906. })();
  12907. (function () {
  12908. angular.module('ui.grid').config(['$provide', function($provide) {
  12909. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  12910. $delegate.add('tr', {
  12911. headerCell: {
  12912. aria: {
  12913. defaultFilterLabel: 'Sütun için filtre',
  12914. removeFilter: 'Filtreyi Kaldır',
  12915. columnMenuButtonLabel: 'Sütun Menüsü'
  12916. },
  12917. priority: 'Öncelik:',
  12918. filterLabel: "Sütun için filtre: "
  12919. },
  12920. aggregate: {
  12921. label: 'kayıtlar'
  12922. },
  12923. groupPanel: {
  12924. description: 'Sütuna göre gruplamak için sütun başlığını buraya sürükleyin ve bırakın.'
  12925. },
  12926. search: {
  12927. placeholder: 'Arama...',
  12928. showingItems: 'Gösterilen Kayıt:',
  12929. selectedItems: 'Seçili Kayıt:',
  12930. totalItems: 'Toplam Kayıt:',
  12931. size: 'Sayfa Boyutu:',
  12932. first: 'İlk Sayfa',
  12933. next: 'Sonraki Sayfa',
  12934. previous: 'Önceki Sayfa',
  12935. last: 'Son Sayfa'
  12936. },
  12937. menu: {
  12938. text: 'Sütunları Seç:'
  12939. },
  12940. sort: {
  12941. ascending: 'Artan Sırada Sırala',
  12942. descending: 'Azalan Sırada Sırala',
  12943. none: 'Sıralama Yapma',
  12944. remove: 'Sıralamayı Kaldır'
  12945. },
  12946. column: {
  12947. hide: 'Sütunu Gizle'
  12948. },
  12949. aggregation: {
  12950. count: 'toplam satır: ',
  12951. sum: 'toplam: ',
  12952. avg: 'ort: ',
  12953. min: 'min: ',
  12954. max: 'maks: '
  12955. },
  12956. pinning: {
  12957. pinLeft: 'Sola Sabitle',
  12958. pinRight: 'Sağa Sabitle',
  12959. unpin: 'Sabitlemeyi Kaldır'
  12960. },
  12961. columnMenu: {
  12962. close: 'Kapat'
  12963. },
  12964. gridMenu: {
  12965. aria: {
  12966. buttonLabel: 'Tablo Menü'
  12967. },
  12968. columns: 'Sütunlar:',
  12969. importerTitle: 'Dosya içeri aktar',
  12970. exporterAllAsCsv: 'Bütün veriyi CSV olarak dışarı aktar',
  12971. exporterVisibleAsCsv: 'Görünen veriyi CSV olarak dışarı aktar',
  12972. exporterSelectedAsCsv: 'Seçili veriyi CSV olarak dışarı aktar',
  12973. exporterAllAsPdf: 'Bütün veriyi PDF olarak dışarı aktar',
  12974. exporterVisibleAsPdf: 'Görünen veriyi PDF olarak dışarı aktar',
  12975. exporterSelectedAsPdf: 'Seçili veriyi PDF olarak dışarı aktar',
  12976. clearAllFilters: 'Bütün filtreleri kaldır'
  12977. },
  12978. importer: {
  12979. noHeaders: 'Sütun isimleri üretilemiyor, dosyanın bir başlığı var mı?',
  12980. noObjects: 'Nesneler üretilemiyor, dosyada başlıktan başka bir veri var mı?',
  12981. invalidCsv: 'Dosya işlenemedi, geçerli bir CSV dosyası mı?',
  12982. invalidJson: 'Dosya işlenemedi, geçerli bir Json dosyası mı?',
  12983. jsonNotArray: 'Alınan Json dosyasında bir dizi bulunmalıdır, işlem iptal ediliyor.'
  12984. },
  12985. pagination: {
  12986. aria: {
  12987. pageToFirst: 'İlk sayfaya',
  12988. pageBack: 'Geri git',
  12989. pageSelected: 'Seçili sayfa',
  12990. pageForward: 'İleri git',
  12991. pageToLast: 'Sona git'
  12992. },
  12993. sizes: 'Sayfadaki nesne sayısı',
  12994. totalItems: 'kayıtlar',
  12995. through: '', //note(fsw) : turkish dont have this preposition
  12996. of: '' //note(fsw) : turkish dont have this preposition
  12997. },
  12998. grouping: {
  12999. group: 'Grupla',
  13000. ungroup: 'Gruplama',
  13001. aggregate_count: 'Yekun: Sayı',
  13002. aggregate_sum: 'Yekun: Toplam',
  13003. aggregate_max: 'Yekun: Maks',
  13004. aggregate_min: 'Yekun: Min',
  13005. aggregate_avg: 'Yekun: Ort',
  13006. aggregate_remove: 'Yekun: Sil'
  13007. }
  13008. });
  13009. return $delegate;
  13010. }]);
  13011. }]);
  13012. })();
  13013. (function () {
  13014. angular.module('ui.grid').config(['$provide', function($provide) {
  13015. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  13016. $delegate.add('ua', {
  13017. headerCell: {
  13018. aria: {
  13019. defaultFilterLabel: 'Фільтр стовпчика',
  13020. removeFilter: 'Видалити фільтр',
  13021. columnMenuButtonLabel: 'Меню ствпчика'
  13022. },
  13023. priority: 'Пріоритет:',
  13024. filterLabel: "Фільтр стовпчика: "
  13025. },
  13026. aggregate: {
  13027. label: 'елементи'
  13028. },
  13029. groupPanel: {
  13030. description: 'Для групування за стовпчиком перетягніть сюди його назву.'
  13031. },
  13032. search: {
  13033. placeholder: 'Пошук...',
  13034. showingItems: 'Показати елементи:',
  13035. selectedItems: 'Обрані елементи:',
  13036. totalItems: 'Усього елементів:',
  13037. size: 'Розмір сторінки:',
  13038. first: 'Перша сторінка',
  13039. next: 'Наступна сторінка',
  13040. previous: 'Попередня сторінка',
  13041. last: 'Остання сторінка'
  13042. },
  13043. menu: {
  13044. text: 'Обрати ствпчики:'
  13045. },
  13046. sort: {
  13047. ascending: 'За зростанням',
  13048. descending: 'За спаданням',
  13049. none: 'Без сортування',
  13050. remove: 'Прибрати сортування'
  13051. },
  13052. column: {
  13053. hide: 'Приховати стовпчик'
  13054. },
  13055. aggregation: {
  13056. count: 'усього рядків: ',
  13057. sum: 'ітого: ',
  13058. avg: 'середнє: ',
  13059. min: 'мін: ',
  13060. max: 'макс: '
  13061. },
  13062. pinning: {
  13063. pinLeft: 'Закріпити ліворуч',
  13064. pinRight: 'Закріпити праворуч',
  13065. unpin: 'Відкріпити'
  13066. },
  13067. columnMenu: {
  13068. close: 'Закрити'
  13069. },
  13070. gridMenu: {
  13071. aria: {
  13072. buttonLabel: 'Меню'
  13073. },
  13074. columns: 'Стовпчики:',
  13075. importerTitle: 'Імпортувати файл',
  13076. exporterAllAsCsv: 'Експортувати все в CSV',
  13077. exporterVisibleAsCsv: 'Експортувати видимі дані в CSV',
  13078. exporterSelectedAsCsv: 'Експортувати обрані дані в CSV',
  13079. exporterAllAsPdf: 'Експортувати все в PDF',
  13080. exporterVisibleAsPdf: 'Експортувати видимі дані в PDF',
  13081. exporterSelectedAsPdf: 'Експортувати обрані дані в PDF',
  13082. clearAllFilters: 'Очистити всі фільтри'
  13083. },
  13084. importer: {
  13085. noHeaders: 'Не вдалося отримати назви стовпчиків, чи є в файлі заголовок?',
  13086. noObjects: 'Не вдалося отримати дані, чи є в файлі рядки окрім заголовка?',
  13087. invalidCsv: 'Не вдалося обробити файл, чи це коректний CSV-файл?',
  13088. invalidJson: 'Не вдалося обробити файл, чи це коректний JSON?',
  13089. jsonNotArray: 'JSON-файл що імпортується повинен містити масив, операцію скасовано.'
  13090. },
  13091. pagination: {
  13092. aria: {
  13093. pageToFirst: 'Перша сторінка',
  13094. pageBack: 'Попередня сторінка',
  13095. pageSelected: 'Обрана сторінка',
  13096. pageForward: 'Наступна сторінка',
  13097. pageToLast: 'Остання сторінка'
  13098. },
  13099. sizes: 'рядків на сторінку',
  13100. totalItems: 'рядків',
  13101. through: 'по',
  13102. of: 'з'
  13103. },
  13104. grouping: {
  13105. group: 'Групувати',
  13106. ungroup: 'Розгрупувати',
  13107. aggregate_count: 'Групувати: Кількість',
  13108. aggregate_sum: 'Для групи: Сума',
  13109. aggregate_max: 'Для групи: Максимум',
  13110. aggregate_min: 'Для групи: Мінімум',
  13111. aggregate_avg: 'Для групи: Серднє',
  13112. aggregate_remove: 'Для групи: Пусто'
  13113. }
  13114. });
  13115. return $delegate;
  13116. }]);
  13117. }]);
  13118. })();
  13119. /**
  13120. * @ngdoc overview
  13121. * @name ui.grid.i18n
  13122. * @description
  13123. *
  13124. * # ui.grid.i18n
  13125. * This module provides i18n functions to ui.grid and any application that wants to use it
  13126. *
  13127. * <div doc-module-components="ui.grid.i18n"></div>
  13128. */
  13129. (function () {
  13130. var DIRECTIVE_ALIASES = ['uiT', 'uiTranslate'];
  13131. var FILTER_ALIASES = ['t', 'uiTranslate'];
  13132. var module = angular.module('ui.grid.i18n');
  13133. /**
  13134. * @ngdoc object
  13135. * @name ui.grid.i18n.constant:i18nConstants
  13136. *
  13137. * @description constants available in i18n module
  13138. */
  13139. module.constant('i18nConstants', {
  13140. MISSING: '[MISSING]',
  13141. UPDATE_EVENT: '$uiI18n',
  13142. LOCALE_DIRECTIVE_ALIAS: 'uiI18n',
  13143. // default to english
  13144. DEFAULT_LANG: 'en'
  13145. });
  13146. // module.config(['$provide', function($provide) {
  13147. // $provide.decorator('i18nService', ['$delegate', function($delegate) {}])}]);
  13148. /**
  13149. * @ngdoc service
  13150. * @name ui.grid.i18n.service:i18nService
  13151. *
  13152. * @description Services for i18n
  13153. */
  13154. module.service('i18nService', ['$log', 'i18nConstants', '$rootScope',
  13155. function ($log, i18nConstants, $rootScope) {
  13156. var langCache = {
  13157. _langs: {},
  13158. current: null,
  13159. get: function (lang) {
  13160. return this._langs[lang.toLowerCase()];
  13161. },
  13162. add: function (lang, strings) {
  13163. var lower = lang.toLowerCase();
  13164. if (!this._langs[lower]) {
  13165. this._langs[lower] = {};
  13166. }
  13167. angular.extend(this._langs[lower], strings);
  13168. },
  13169. getAllLangs: function () {
  13170. var langs = [];
  13171. if (!this._langs) {
  13172. return langs;
  13173. }
  13174. for (var key in this._langs) {
  13175. langs.push(key);
  13176. }
  13177. return langs;
  13178. },
  13179. setCurrent: function (lang) {
  13180. this.current = lang.toLowerCase();
  13181. },
  13182. getCurrentLang: function () {
  13183. return this.current;
  13184. }
  13185. };
  13186. var service = {
  13187. /**
  13188. * @ngdoc service
  13189. * @name add
  13190. * @methodOf ui.grid.i18n.service:i18nService
  13191. * @description Adds the languages and strings to the cache. Decorate this service to
  13192. * add more translation strings
  13193. * @param {string} lang language to add
  13194. * @param {object} stringMaps of strings to add grouped by property names
  13195. * @example
  13196. * <pre>
  13197. * i18nService.add('en', {
  13198. * aggregate: {
  13199. * label1: 'items',
  13200. * label2: 'some more items'
  13201. * }
  13202. * },
  13203. * groupPanel: {
  13204. * description: 'Drag a column header here and drop it to group by that column.'
  13205. * }
  13206. * }
  13207. * </pre>
  13208. */
  13209. add: function (langs, stringMaps) {
  13210. if (typeof(langs) === 'object') {
  13211. angular.forEach(langs, function (lang) {
  13212. if (lang) {
  13213. langCache.add(lang, stringMaps);
  13214. }
  13215. });
  13216. } else {
  13217. langCache.add(langs, stringMaps);
  13218. }
  13219. },
  13220. /**
  13221. * @ngdoc service
  13222. * @name getAllLangs
  13223. * @methodOf ui.grid.i18n.service:i18nService
  13224. * @description return all currently loaded languages
  13225. * @returns {array} string
  13226. */
  13227. getAllLangs: function () {
  13228. return langCache.getAllLangs();
  13229. },
  13230. /**
  13231. * @ngdoc service
  13232. * @name get
  13233. * @methodOf ui.grid.i18n.service:i18nService
  13234. * @description return all currently loaded languages
  13235. * @param {string} lang to return. If not specified, returns current language
  13236. * @returns {object} the translation string maps for the language
  13237. */
  13238. get: function (lang) {
  13239. var language = lang ? lang : service.getCurrentLang();
  13240. return langCache.get(language);
  13241. },
  13242. /**
  13243. * @ngdoc service
  13244. * @name getSafeText
  13245. * @methodOf ui.grid.i18n.service:i18nService
  13246. * @description returns the text specified in the path or a Missing text if text is not found
  13247. * @param {String} path property path to use for retrieving text from string map
  13248. * @param {String} [lang] to return. If not specified, returns current language
  13249. * @returns {object} the translation for the path
  13250. * @example
  13251. * <pre>
  13252. * i18nService.getSafeText('sort.ascending')
  13253. * </pre>
  13254. */
  13255. getSafeText: function (path, lang) {
  13256. var language = lang || service.getCurrentLang();
  13257. var trans = langCache.get(language);
  13258. if (!trans) {
  13259. return i18nConstants.MISSING;
  13260. }
  13261. var paths = path.split('.');
  13262. var current = trans;
  13263. for (var i = 0; i < paths.length; ++i) {
  13264. if (current[paths[i]] === undefined || current[paths[i]] === null) {
  13265. return i18nConstants.MISSING;
  13266. } else {
  13267. current = current[paths[i]];
  13268. }
  13269. }
  13270. return current;
  13271. },
  13272. /**
  13273. * @ngdoc service
  13274. * @name setCurrentLang
  13275. * @methodOf ui.grid.i18n.service:i18nService
  13276. * @description sets the current language to use in the application
  13277. * $broadcasts the i18nConstants.UPDATE_EVENT on the $rootScope
  13278. * @param {string} lang to set
  13279. * @example
  13280. * <pre>
  13281. * i18nService.setCurrentLang('fr');
  13282. * </pre>
  13283. */
  13284. setCurrentLang: function (lang) {
  13285. if (lang) {
  13286. langCache.setCurrent(lang);
  13287. $rootScope.$broadcast(i18nConstants.UPDATE_EVENT);
  13288. }
  13289. },
  13290. /**
  13291. * @ngdoc service
  13292. * @name getCurrentLang
  13293. * @methodOf ui.grid.i18n.service:i18nService
  13294. * @description returns the current language used in the application
  13295. */
  13296. getCurrentLang: function () {
  13297. var lang = langCache.getCurrentLang();
  13298. if (!lang) {
  13299. lang = i18nConstants.DEFAULT_LANG;
  13300. langCache.setCurrent(lang);
  13301. }
  13302. return lang;
  13303. }
  13304. };
  13305. return service;
  13306. }]);
  13307. var localeDirective = function (i18nService, i18nConstants) {
  13308. return {
  13309. compile: function () {
  13310. return {
  13311. pre: function ($scope, $elm, $attrs) {
  13312. var alias = i18nConstants.LOCALE_DIRECTIVE_ALIAS;
  13313. // check for watchable property
  13314. var lang = $scope.$eval($attrs[alias]);
  13315. if (lang) {
  13316. $scope.$watch($attrs[alias], function () {
  13317. i18nService.setCurrentLang(lang);
  13318. });
  13319. } else if ($attrs.$$observers) {
  13320. $attrs.$observe(alias, function () {
  13321. i18nService.setCurrentLang($attrs[alias] || i18nConstants.DEFAULT_LANG);
  13322. });
  13323. }
  13324. }
  13325. };
  13326. }
  13327. };
  13328. };
  13329. module.directive('uiI18n', ['i18nService', 'i18nConstants', localeDirective]);
  13330. // directive syntax
  13331. var uitDirective = function ($parse, i18nService, i18nConstants) {
  13332. return {
  13333. restrict: 'EA',
  13334. compile: function () {
  13335. return {
  13336. pre: function ($scope, $elm, $attrs) {
  13337. var alias1 = DIRECTIVE_ALIASES[0],
  13338. alias2 = DIRECTIVE_ALIASES[1];
  13339. var token = $attrs[alias1] || $attrs[alias2] || $elm.html();
  13340. var missing = i18nConstants.MISSING + token;
  13341. var observer;
  13342. if ($attrs.$$observers) {
  13343. var prop = $attrs[alias1] ? alias1 : alias2;
  13344. observer = $attrs.$observe(prop, function (result) {
  13345. if (result) {
  13346. $elm.html($parse(result)(i18nService.getCurrentLang()) || missing);
  13347. }
  13348. });
  13349. }
  13350. var getter = $parse(token);
  13351. var listener = $scope.$on(i18nConstants.UPDATE_EVENT, function (evt) {
  13352. if (observer) {
  13353. observer($attrs[alias1] || $attrs[alias2]);
  13354. } else {
  13355. // set text based on i18n current language
  13356. $elm.html(getter(i18nService.get()) || missing);
  13357. }
  13358. });
  13359. $scope.$on('$destroy', listener);
  13360. $elm.html(getter(i18nService.get()) || missing);
  13361. }
  13362. };
  13363. }
  13364. };
  13365. };
  13366. angular.forEach( DIRECTIVE_ALIASES, function ( alias ) {
  13367. module.directive( alias, ['$parse', 'i18nService', 'i18nConstants', uitDirective] );
  13368. } );
  13369. // optional filter syntax
  13370. var uitFilter = function ($parse, i18nService, i18nConstants) {
  13371. return function (data) {
  13372. var getter = $parse(data);
  13373. // set text based on i18n current language
  13374. return getter(i18nService.get()) || i18nConstants.MISSING + data;
  13375. };
  13376. };
  13377. angular.forEach( FILTER_ALIASES, function ( alias ) {
  13378. module.filter( alias, ['$parse', 'i18nService', 'i18nConstants', uitFilter] );
  13379. } );
  13380. })();
  13381. (function() {
  13382. angular.module('ui.grid').config(['$provide', function($provide) {
  13383. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  13384. $delegate.add('zh-cn', {
  13385. headerCell: {
  13386. aria: {
  13387. defaultFilterLabel: '列过滤器',
  13388. removeFilter: '移除过滤器',
  13389. columnMenuButtonLabel: '列菜单'
  13390. },
  13391. priority: '优先级:',
  13392. filterLabel: "列过滤器: "
  13393. },
  13394. aggregate: {
  13395. label: '行'
  13396. },
  13397. groupPanel: {
  13398. description: '拖曳表头到此处进行分组'
  13399. },
  13400. search: {
  13401. placeholder: '查找',
  13402. showingItems: '已显示行数:',
  13403. selectedItems: '已选择行数:',
  13404. totalItems: '总行数:',
  13405. size: '每页显示行数:',
  13406. first: '首页',
  13407. next: '下一页',
  13408. previous: '上一页',
  13409. last: '末页'
  13410. },
  13411. menu: {
  13412. text: '选择列:'
  13413. },
  13414. sort: {
  13415. ascending: '升序',
  13416. descending: '降序',
  13417. none: '无序',
  13418. remove: '取消排序'
  13419. },
  13420. column: {
  13421. hide: '隐藏列'
  13422. },
  13423. aggregation: {
  13424. count: '计数:',
  13425. sum: '求和:',
  13426. avg: '均值:',
  13427. min: '最小值:',
  13428. max: '最大值:'
  13429. },
  13430. pinning: {
  13431. pinLeft: '左侧固定',
  13432. pinRight: '右侧固定',
  13433. unpin: '取消固定'
  13434. },
  13435. columnMenu: {
  13436. close: '关闭'
  13437. },
  13438. gridMenu: {
  13439. aria: {
  13440. buttonLabel: '表格菜单'
  13441. },
  13442. columns: '列:',
  13443. importerTitle: '导入文件',
  13444. exporterAllAsCsv: '导出全部数据到CSV',
  13445. exporterVisibleAsCsv: '导出可见数据到CSV',
  13446. exporterSelectedAsCsv: '导出已选数据到CSV',
  13447. exporterAllAsPdf: '导出全部数据到PDF',
  13448. exporterVisibleAsPdf: '导出可见数据到PDF',
  13449. exporterSelectedAsPdf: '导出已选数据到PDF',
  13450. clearAllFilters: '清除所有过滤器'
  13451. },
  13452. importer: {
  13453. noHeaders: '无法获取列名,确定文件包含表头?',
  13454. noObjects: '无法获取数据,确定文件包含数据?',
  13455. invalidCsv: '无法处理文件,确定是合法的CSV文件?',
  13456. invalidJson: '无法处理文件,确定是合法的JSON文件?',
  13457. jsonNotArray: '导入的文件不是JSON数组!'
  13458. },
  13459. pagination: {
  13460. aria: {
  13461. pageToFirst: '第一页',
  13462. pageBack: '上一页',
  13463. pageSelected: '当前页',
  13464. pageForward: '下一页',
  13465. pageToLast: '最后一页'
  13466. },
  13467. sizes: '行每页',
  13468. totalItems: '行',
  13469. through: '至',
  13470. of: '共'
  13471. },
  13472. grouping: {
  13473. group: '分组',
  13474. ungroup: '取消分组',
  13475. aggregate_count: '合计: 计数',
  13476. aggregate_sum: '合计: 求和',
  13477. aggregate_max: '合计: 最大',
  13478. aggregate_min: '合计: 最小',
  13479. aggregate_avg: '合计: 平均',
  13480. aggregate_remove: '合计: 移除'
  13481. }
  13482. });
  13483. return $delegate;
  13484. }]);
  13485. }]);
  13486. })();
  13487. (function() {
  13488. angular.module('ui.grid').config(['$provide', function($provide) {
  13489. $provide.decorator('i18nService', ['$delegate', function($delegate) {
  13490. $delegate.add('zh-tw', {
  13491. aggregate: {
  13492. label: '行'
  13493. },
  13494. groupPanel: {
  13495. description: '拖曳表頭到此處進行分組'
  13496. },
  13497. search: {
  13498. placeholder: '查找',
  13499. showingItems: '已顯示行數:',
  13500. selectedItems: '已選擇行數:',
  13501. totalItems: '總行數:',
  13502. size: '每頁顯示行數:',
  13503. first: '首頁',
  13504. next: '下壹頁',
  13505. previous: '上壹頁',
  13506. last: '末頁'
  13507. },
  13508. menu: {
  13509. text: '選擇列:'
  13510. },
  13511. sort: {
  13512. ascending: '升序',
  13513. descending: '降序',
  13514. remove: '取消排序'
  13515. },
  13516. column: {
  13517. hide: '隱藏列'
  13518. },
  13519. aggregation: {
  13520. count: '計數:',
  13521. sum: '求和:',
  13522. avg: '均值:',
  13523. min: '最小值:',
  13524. max: '最大值:'
  13525. },
  13526. pinning: {
  13527. pinLeft: '左側固定',
  13528. pinRight: '右側固定',
  13529. unpin: '取消固定'
  13530. },
  13531. gridMenu: {
  13532. columns: '列:',
  13533. importerTitle: '導入文件',
  13534. exporterAllAsCsv: '導出全部數據到CSV',
  13535. exporterVisibleAsCsv: '導出可見數據到CSV',
  13536. exporterSelectedAsCsv: '導出已選數據到CSV',
  13537. exporterAllAsPdf: '導出全部數據到PDF',
  13538. exporterVisibleAsPdf: '導出可見數據到PDF',
  13539. exporterSelectedAsPdf: '導出已選數據到PDF',
  13540. clearAllFilters: '清除所有过滤器'
  13541. },
  13542. importer: {
  13543. noHeaders: '無法獲取列名,確定文件包含表頭?',
  13544. noObjects: '無法獲取數據,確定文件包含數據?',
  13545. invalidCsv: '無法處理文件,確定是合法的CSV文件?',
  13546. invalidJson: '無法處理文件,確定是合法的JSON文件?',
  13547. jsonNotArray: '導入的文件不是JSON數組!'
  13548. },
  13549. pagination: {
  13550. sizes: '行每頁',
  13551. totalItems: '行'
  13552. }
  13553. });
  13554. return $delegate;
  13555. }]);
  13556. }]);
  13557. })();
  13558. (function() {
  13559. 'use strict';
  13560. /**
  13561. * @ngdoc overview
  13562. * @name ui.grid.autoResize
  13563. *
  13564. * @description
  13565. *
  13566. * #ui.grid.autoResize
  13567. *
  13568. * <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>
  13569. *
  13570. * This module provides auto-resizing functionality to UI-Grid.
  13571. */
  13572. var module = angular.module('ui.grid.autoResize', ['ui.grid']);
  13573. module.directive('uiGridAutoResize', ['gridUtil', function(gridUtil) {
  13574. return {
  13575. require: 'uiGrid',
  13576. scope: false,
  13577. link: function($scope, $elm, $attrs, uiGridCtrl) {
  13578. var elementWidth,
  13579. elementHeight;
  13580. var updateWidth = gridUtil.throttle(function() {
  13581. elementWidth = gridUtil.elementWidth($elm);
  13582. }, 200);
  13583. var updateHeight = gridUtil.throttle(function() {
  13584. elementHeight = gridUtil.elementHeight($elm);
  13585. }, 200);
  13586. var refresh = gridUtil.throttle(function(width, height) {
  13587. uiGridCtrl.grid.gridWidth = width;
  13588. uiGridCtrl.grid.gridHeight = height;
  13589. uiGridCtrl.grid.refresh();
  13590. }, 300);
  13591. $scope.$watchGroup([
  13592. function() {
  13593. updateWidth();
  13594. return elementWidth;
  13595. },
  13596. function() {
  13597. updateHeight();
  13598. return elementHeight;
  13599. }
  13600. ], function(newValues, oldValues, scope) {
  13601. if (!angular.equals(newValues, oldValues)) {
  13602. refresh(newValues[0], newValues[1]);
  13603. }
  13604. });
  13605. }
  13606. };
  13607. }]);
  13608. })();
  13609. (function () {
  13610. 'use strict';
  13611. /**
  13612. * @ngdoc overview
  13613. * @name ui.grid.cellNav
  13614. *
  13615. * @description
  13616. #ui.grid.cellNav
  13617. <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>
  13618. This module provides cell navigation functionality to UI-Grid.
  13619. */
  13620. var module = angular.module('ui.grid.cellNav', ['ui.grid']);
  13621. /**
  13622. * @ngdoc object
  13623. * @name ui.grid.cellNav.constant:uiGridCellNavConstants
  13624. *
  13625. * @description constants available in cellNav
  13626. */
  13627. module.constant('uiGridCellNavConstants', {
  13628. FEATURE_NAME: 'gridCellNav',
  13629. CELL_NAV_EVENT: 'cellNav',
  13630. direction: {LEFT: 0, RIGHT: 1, UP: 2, DOWN: 3, PG_UP: 4, PG_DOWN: 5},
  13631. EVENT_TYPE: {
  13632. KEYDOWN: 0,
  13633. CLICK: 1,
  13634. CLEAR: 2
  13635. }
  13636. });
  13637. module.factory('uiGridCellNavFactory', ['gridUtil', 'uiGridConstants', 'uiGridCellNavConstants', 'GridRowColumn', '$q',
  13638. function (gridUtil, uiGridConstants, uiGridCellNavConstants, GridRowColumn, $q) {
  13639. /**
  13640. * @ngdoc object
  13641. * @name ui.grid.cellNav.object:CellNav
  13642. * @description returns a CellNav prototype function
  13643. * @param {object} rowContainer container for rows
  13644. * @param {object} colContainer parent column container
  13645. * @param {object} leftColContainer column container to the left of parent
  13646. * @param {object} rightColContainer column container to the right of parent
  13647. */
  13648. var UiGridCellNav = function UiGridCellNav(rowContainer, colContainer, leftColContainer, rightColContainer) {
  13649. this.rows = rowContainer.visibleRowCache;
  13650. this.columns = colContainer.visibleColumnCache;
  13651. this.leftColumns = leftColContainer ? leftColContainer.visibleColumnCache : [];
  13652. this.rightColumns = rightColContainer ? rightColContainer.visibleColumnCache : [];
  13653. this.bodyContainer = rowContainer;
  13654. };
  13655. /** returns focusable columns of all containers */
  13656. UiGridCellNav.prototype.getFocusableCols = function () {
  13657. var allColumns = this.leftColumns.concat(this.columns, this.rightColumns);
  13658. return allColumns.filter(function (col) {
  13659. return col.colDef.allowCellFocus;
  13660. });
  13661. };
  13662. /**
  13663. * @ngdoc object
  13664. * @name ui.grid.cellNav.api:GridRow
  13665. *
  13666. * @description GridRow settings for cellNav feature, these are available to be
  13667. * set only internally (for example, by other features)
  13668. */
  13669. /**
  13670. * @ngdoc object
  13671. * @name allowCellFocus
  13672. * @propertyOf ui.grid.cellNav.api:GridRow
  13673. * @description Enable focus on a cell within this row. If set to false then no cells
  13674. * in this row can be focused - group header rows as an example would set this to false.
  13675. * <br/>Defaults to true
  13676. */
  13677. /** returns focusable rows */
  13678. UiGridCellNav.prototype.getFocusableRows = function () {
  13679. return this.rows.filter(function(row) {
  13680. return row.allowCellFocus !== false;
  13681. });
  13682. };
  13683. UiGridCellNav.prototype.getNextRowCol = function (direction, curRow, curCol) {
  13684. switch (direction) {
  13685. case uiGridCellNavConstants.direction.LEFT:
  13686. return this.getRowColLeft(curRow, curCol);
  13687. case uiGridCellNavConstants.direction.RIGHT:
  13688. return this.getRowColRight(curRow, curCol);
  13689. case uiGridCellNavConstants.direction.UP:
  13690. return this.getRowColUp(curRow, curCol);
  13691. case uiGridCellNavConstants.direction.DOWN:
  13692. return this.getRowColDown(curRow, curCol);
  13693. case uiGridCellNavConstants.direction.PG_UP:
  13694. return this.getRowColPageUp(curRow, curCol);
  13695. case uiGridCellNavConstants.direction.PG_DOWN:
  13696. return this.getRowColPageDown(curRow, curCol);
  13697. }
  13698. };
  13699. UiGridCellNav.prototype.initializeSelection = function () {
  13700. var focusableCols = this.getFocusableCols();
  13701. var focusableRows = this.getFocusableRows();
  13702. if (focusableCols.length === 0 || focusableRows.length === 0) {
  13703. return null;
  13704. }
  13705. var curRowIndex = 0;
  13706. var curColIndex = 0;
  13707. return new GridRowColumn(focusableRows[0], focusableCols[0]); //return same row
  13708. };
  13709. UiGridCellNav.prototype.getRowColLeft = function (curRow, curCol) {
  13710. var focusableCols = this.getFocusableCols();
  13711. var focusableRows = this.getFocusableRows();
  13712. var curColIndex = focusableCols.indexOf(curCol);
  13713. var curRowIndex = focusableRows.indexOf(curRow);
  13714. //could not find column in focusable Columns so set it to 1
  13715. if (curColIndex === -1) {
  13716. curColIndex = 1;
  13717. }
  13718. var nextColIndex = curColIndex === 0 ? focusableCols.length - 1 : curColIndex - 1;
  13719. //get column to left
  13720. if (nextColIndex >= curColIndex) {
  13721. // On the first row
  13722. // if (curRowIndex === 0 && curColIndex === 0) {
  13723. // return null;
  13724. // }
  13725. if (curRowIndex === 0) {
  13726. return new GridRowColumn(curRow, focusableCols[nextColIndex]); //return same row
  13727. }
  13728. else {
  13729. //up one row and far right column
  13730. return new GridRowColumn(focusableRows[curRowIndex - 1], focusableCols[nextColIndex]);
  13731. }
  13732. }
  13733. else {
  13734. return new GridRowColumn(curRow, focusableCols[nextColIndex]);
  13735. }
  13736. };
  13737. UiGridCellNav.prototype.getRowColRight = function (curRow, curCol) {
  13738. var focusableCols = this.getFocusableCols();
  13739. var focusableRows = this.getFocusableRows();
  13740. var curColIndex = focusableCols.indexOf(curCol);
  13741. var curRowIndex = focusableRows.indexOf(curRow);
  13742. //could not find column in focusable Columns so set it to 0
  13743. if (curColIndex === -1) {
  13744. curColIndex = 0;
  13745. }
  13746. var nextColIndex = curColIndex === focusableCols.length - 1 ? 0 : curColIndex + 1;
  13747. if (nextColIndex <= curColIndex) {
  13748. if (curRowIndex === focusableRows.length - 1) {
  13749. return new GridRowColumn(curRow, focusableCols[nextColIndex]); //return same row
  13750. }
  13751. else {
  13752. //down one row and far left column
  13753. return new GridRowColumn(focusableRows[curRowIndex + 1], focusableCols[nextColIndex]);
  13754. }
  13755. }
  13756. else {
  13757. return new GridRowColumn(curRow, focusableCols[nextColIndex]);
  13758. }
  13759. };
  13760. UiGridCellNav.prototype.getRowColDown = function (curRow, curCol) {
  13761. var focusableCols = this.getFocusableCols();
  13762. var focusableRows = this.getFocusableRows();
  13763. var curColIndex = focusableCols.indexOf(curCol);
  13764. var curRowIndex = focusableRows.indexOf(curRow);
  13765. //could not find column in focusable Columns so set it to 0
  13766. if (curColIndex === -1) {
  13767. curColIndex = 0;
  13768. }
  13769. if (curRowIndex === focusableRows.length - 1) {
  13770. return new GridRowColumn(curRow, focusableCols[curColIndex]); //return same row
  13771. }
  13772. else {
  13773. //down one row
  13774. return new GridRowColumn(focusableRows[curRowIndex + 1], focusableCols[curColIndex]);
  13775. }
  13776. };
  13777. UiGridCellNav.prototype.getRowColPageDown = function (curRow, curCol) {
  13778. var focusableCols = this.getFocusableCols();
  13779. var focusableRows = this.getFocusableRows();
  13780. var curColIndex = focusableCols.indexOf(curCol);
  13781. var curRowIndex = focusableRows.indexOf(curRow);
  13782. //could not find column in focusable Columns so set it to 0
  13783. if (curColIndex === -1) {
  13784. curColIndex = 0;
  13785. }
  13786. var pageSize = this.bodyContainer.minRowsToRender();
  13787. if (curRowIndex >= focusableRows.length - pageSize) {
  13788. return new GridRowColumn(focusableRows[focusableRows.length - 1], focusableCols[curColIndex]); //return last row
  13789. }
  13790. else {
  13791. //down one page
  13792. return new GridRowColumn(focusableRows[curRowIndex + pageSize], focusableCols[curColIndex]);
  13793. }
  13794. };
  13795. UiGridCellNav.prototype.getRowColUp = function (curRow, curCol) {
  13796. var focusableCols = this.getFocusableCols();
  13797. var focusableRows = this.getFocusableRows();
  13798. var curColIndex = focusableCols.indexOf(curCol);
  13799. var curRowIndex = focusableRows.indexOf(curRow);
  13800. //could not find column in focusable Columns so set it to 0
  13801. if (curColIndex === -1) {
  13802. curColIndex = 0;
  13803. }
  13804. if (curRowIndex === 0) {
  13805. return new GridRowColumn(curRow, focusableCols[curColIndex]); //return same row
  13806. }
  13807. else {
  13808. //up one row
  13809. return new GridRowColumn(focusableRows[curRowIndex - 1], focusableCols[curColIndex]);
  13810. }
  13811. };
  13812. UiGridCellNav.prototype.getRowColPageUp = function (curRow, curCol) {
  13813. var focusableCols = this.getFocusableCols();
  13814. var focusableRows = this.getFocusableRows();
  13815. var curColIndex = focusableCols.indexOf(curCol);
  13816. var curRowIndex = focusableRows.indexOf(curRow);
  13817. //could not find column in focusable Columns so set it to 0
  13818. if (curColIndex === -1) {
  13819. curColIndex = 0;
  13820. }
  13821. var pageSize = this.bodyContainer.minRowsToRender();
  13822. if (curRowIndex - pageSize < 0) {
  13823. return new GridRowColumn(focusableRows[0], focusableCols[curColIndex]); //return first row
  13824. }
  13825. else {
  13826. //up one page
  13827. return new GridRowColumn(focusableRows[curRowIndex - pageSize], focusableCols[curColIndex]);
  13828. }
  13829. };
  13830. return UiGridCellNav;
  13831. }]);
  13832. /**
  13833. * @ngdoc service
  13834. * @name ui.grid.cellNav.service:uiGridCellNavService
  13835. *
  13836. * @description Services for cell navigation features. If you don't like the key maps we use,
  13837. * or the direction cells navigation, override with a service decorator (see angular docs)
  13838. */
  13839. module.service('uiGridCellNavService', ['gridUtil', 'uiGridConstants', 'uiGridCellNavConstants', '$q', 'uiGridCellNavFactory', 'GridRowColumn', 'ScrollEvent',
  13840. function (gridUtil, uiGridConstants, uiGridCellNavConstants, $q, UiGridCellNav, GridRowColumn, ScrollEvent) {
  13841. var service = {
  13842. initializeGrid: function (grid) {
  13843. grid.registerColumnBuilder(service.cellNavColumnBuilder);
  13844. /**
  13845. * @ngdoc object
  13846. * @name ui.grid.cellNav:Grid.cellNav
  13847. * @description cellNav properties added to grid class
  13848. */
  13849. grid.cellNav = {};
  13850. grid.cellNav.lastRowCol = null;
  13851. grid.cellNav.focusedCells = [];
  13852. service.defaultGridOptions(grid.options);
  13853. /**
  13854. * @ngdoc object
  13855. * @name ui.grid.cellNav.api:PublicApi
  13856. *
  13857. * @description Public Api for cellNav feature
  13858. */
  13859. var publicApi = {
  13860. events: {
  13861. cellNav: {
  13862. /**
  13863. * @ngdoc event
  13864. * @name navigate
  13865. * @eventOf ui.grid.cellNav.api:PublicApi
  13866. * @description raised when the active cell is changed
  13867. * <pre>
  13868. * gridApi.cellNav.on.navigate(scope,function(newRowcol, oldRowCol){})
  13869. * </pre>
  13870. * @param {object} newRowCol new position
  13871. * @param {object} oldRowCol old position
  13872. */
  13873. navigate: function (newRowCol, oldRowCol) {},
  13874. /**
  13875. * @ngdoc event
  13876. * @name viewPortKeyDown
  13877. * @eventOf ui.grid.cellNav.api:PublicApi
  13878. * @description is raised when the viewPort receives a keyDown event. Cells never get focus in uiGrid
  13879. * due to the difficulties of setting focus on a cell that is not visible in the viewport. Use this
  13880. * event whenever you need a keydown event on a cell
  13881. * <br/>
  13882. * @param {object} event keydown event
  13883. * @param {object} rowCol current rowCol position
  13884. */
  13885. viewPortKeyDown: function (event, rowCol) {},
  13886. /**
  13887. * @ngdoc event
  13888. * @name viewPortKeyPress
  13889. * @eventOf ui.grid.cellNav.api:PublicApi
  13890. * @description is raised when the viewPort receives a keyPress event. Cells never get focus in uiGrid
  13891. * due to the difficulties of setting focus on a cell that is not visible in the viewport. Use this
  13892. * event whenever you need a keypress event on a cell
  13893. * <br/>
  13894. * @param {object} event keypress event
  13895. * @param {object} rowCol current rowCol position
  13896. */
  13897. viewPortKeyPress: function (event, rowCol) {}
  13898. }
  13899. },
  13900. methods: {
  13901. cellNav: {
  13902. /**
  13903. * @ngdoc function
  13904. * @name scrollToFocus
  13905. * @methodOf ui.grid.cellNav.api:PublicApi
  13906. * @description brings the specified row and column into view, and sets focus
  13907. * to that cell
  13908. * @param {object} rowEntity gridOptions.data[] array instance to make visible and set focus
  13909. * @param {object} colDef to make visible and set focus
  13910. * @returns {promise} a promise that is resolved after any scrolling is finished
  13911. */
  13912. scrollToFocus: function (rowEntity, colDef) {
  13913. return service.scrollToFocus(grid, rowEntity, colDef);
  13914. },
  13915. /**
  13916. * @ngdoc function
  13917. * @name getFocusedCell
  13918. * @methodOf ui.grid.cellNav.api:PublicApi
  13919. * @description returns the current (or last if Grid does not have focus) focused row and column
  13920. * <br> value is null if no selection has occurred
  13921. */
  13922. getFocusedCell: function () {
  13923. return grid.cellNav.lastRowCol;
  13924. },
  13925. /**
  13926. * @ngdoc function
  13927. * @name getCurrentSelection
  13928. * @methodOf ui.grid.cellNav.api:PublicApi
  13929. * @description returns an array containing the current selection
  13930. * <br> array is empty if no selection has occurred
  13931. */
  13932. getCurrentSelection: function () {
  13933. return grid.cellNav.focusedCells;
  13934. },
  13935. /**
  13936. * @ngdoc function
  13937. * @name rowColSelectIndex
  13938. * @methodOf ui.grid.cellNav.api:PublicApi
  13939. * @description returns the index in the order in which the GridRowColumn was selected, returns -1 if the GridRowColumn
  13940. * isn't selected
  13941. * @param {object} rowCol the rowCol to evaluate
  13942. */
  13943. rowColSelectIndex: function (rowCol) {
  13944. //return gridUtil.arrayContainsObjectWithProperty(grid.cellNav.focusedCells, 'col.uid', rowCol.col.uid) &&
  13945. var index = -1;
  13946. for (var i = 0; i < grid.cellNav.focusedCells.length; i++) {
  13947. if (grid.cellNav.focusedCells[i].col.uid === rowCol.col.uid &&
  13948. grid.cellNav.focusedCells[i].row.uid === rowCol.row.uid) {
  13949. index = i;
  13950. break;
  13951. }
  13952. }
  13953. return index;
  13954. }
  13955. }
  13956. }
  13957. };
  13958. grid.api.registerEventsFromObject(publicApi.events);
  13959. grid.api.registerMethodsFromObject(publicApi.methods);
  13960. },
  13961. defaultGridOptions: function (gridOptions) {
  13962. /**
  13963. * @ngdoc object
  13964. * @name ui.grid.cellNav.api:GridOptions
  13965. *
  13966. * @description GridOptions for cellNav feature, these are available to be
  13967. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  13968. */
  13969. /**
  13970. * @ngdoc object
  13971. * @name modifierKeysToMultiSelectCells
  13972. * @propertyOf ui.grid.cellNav.api:GridOptions
  13973. * @description Enable multiple cell selection only when using the ctrlKey or shiftKey.
  13974. * <br/>Defaults to false
  13975. */
  13976. gridOptions.modifierKeysToMultiSelectCells = gridOptions.modifierKeysToMultiSelectCells === true;
  13977. /**
  13978. * @ngdoc array
  13979. * @name keyDownOverrides
  13980. * @propertyOf ui.grid.cellNav.api:GridOptions
  13981. * @description An array of event objects to override on keydown. If an event is overridden, the viewPortKeyDown event will
  13982. * be raised with the overridden events, allowing custom keydown behavior.
  13983. * <br/>Defaults to []
  13984. */
  13985. gridOptions.keyDownOverrides = gridOptions.keyDownOverrides || [];
  13986. },
  13987. /**
  13988. * @ngdoc service
  13989. * @name decorateRenderContainers
  13990. * @methodOf ui.grid.cellNav.service:uiGridCellNavService
  13991. * @description decorates grid renderContainers with cellNav functions
  13992. */
  13993. decorateRenderContainers: function (grid) {
  13994. var rightContainer = grid.hasRightContainer() ? grid.renderContainers.right : null;
  13995. var leftContainer = grid.hasLeftContainer() ? grid.renderContainers.left : null;
  13996. if (leftContainer !== null) {
  13997. grid.renderContainers.left.cellNav = new UiGridCellNav(grid.renderContainers.body, leftContainer, rightContainer, grid.renderContainers.body);
  13998. }
  13999. if (rightContainer !== null) {
  14000. grid.renderContainers.right.cellNav = new UiGridCellNav(grid.renderContainers.body, rightContainer, grid.renderContainers.body, leftContainer);
  14001. }
  14002. grid.renderContainers.body.cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, leftContainer, rightContainer);
  14003. },
  14004. /**
  14005. * @ngdoc service
  14006. * @name getDirection
  14007. * @methodOf ui.grid.cellNav.service:uiGridCellNavService
  14008. * @description determines which direction to for a given keyDown event
  14009. * @returns {uiGridCellNavConstants.direction} direction
  14010. */
  14011. getDirection: function (evt) {
  14012. if (evt.keyCode === uiGridConstants.keymap.LEFT ||
  14013. (evt.keyCode === uiGridConstants.keymap.TAB && evt.shiftKey)) {
  14014. return uiGridCellNavConstants.direction.LEFT;
  14015. }
  14016. if (evt.keyCode === uiGridConstants.keymap.RIGHT ||
  14017. evt.keyCode === uiGridConstants.keymap.TAB) {
  14018. return uiGridCellNavConstants.direction.RIGHT;
  14019. }
  14020. if (evt.keyCode === uiGridConstants.keymap.UP ||
  14021. (evt.keyCode === uiGridConstants.keymap.ENTER && evt.shiftKey) ) {
  14022. return uiGridCellNavConstants.direction.UP;
  14023. }
  14024. if (evt.keyCode === uiGridConstants.keymap.PG_UP){
  14025. return uiGridCellNavConstants.direction.PG_UP;
  14026. }
  14027. if (evt.keyCode === uiGridConstants.keymap.DOWN ||
  14028. evt.keyCode === uiGridConstants.keymap.ENTER && !(evt.ctrlKey || evt.altKey)) {
  14029. return uiGridCellNavConstants.direction.DOWN;
  14030. }
  14031. if (evt.keyCode === uiGridConstants.keymap.PG_DOWN){
  14032. return uiGridCellNavConstants.direction.PG_DOWN;
  14033. }
  14034. return null;
  14035. },
  14036. /**
  14037. * @ngdoc service
  14038. * @name cellNavColumnBuilder
  14039. * @methodOf ui.grid.cellNav.service:uiGridCellNavService
  14040. * @description columnBuilder function that adds cell navigation properties to grid column
  14041. * @returns {promise} promise that will load any needed templates when resolved
  14042. */
  14043. cellNavColumnBuilder: function (colDef, col, gridOptions) {
  14044. var promises = [];
  14045. /**
  14046. * @ngdoc object
  14047. * @name ui.grid.cellNav.api:ColumnDef
  14048. *
  14049. * @description Column Definitions for cellNav feature, these are available to be
  14050. * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs}
  14051. */
  14052. /**
  14053. * @ngdoc object
  14054. * @name allowCellFocus
  14055. * @propertyOf ui.grid.cellNav.api:ColumnDef
  14056. * @description Enable focus on a cell within this column.
  14057. * <br/>Defaults to true
  14058. */
  14059. colDef.allowCellFocus = colDef.allowCellFocus === undefined ? true : colDef.allowCellFocus;
  14060. return $q.all(promises);
  14061. },
  14062. /**
  14063. * @ngdoc method
  14064. * @methodOf ui.grid.cellNav.service:uiGridCellNavService
  14065. * @name scrollToFocus
  14066. * @description Scroll the grid such that the specified
  14067. * row and column is in view, and set focus to the cell in that row and column
  14068. * @param {Grid} grid the grid you'd like to act upon, usually available
  14069. * from gridApi.grid
  14070. * @param {object} rowEntity gridOptions.data[] array instance to make visible and set focus to
  14071. * @param {object} colDef to make visible and set focus to
  14072. * @returns {promise} a promise that is resolved after any scrolling is finished
  14073. */
  14074. scrollToFocus: function (grid, rowEntity, colDef) {
  14075. var gridRow = null, gridCol = null;
  14076. if (typeof(rowEntity) !== 'undefined' && rowEntity !== null) {
  14077. gridRow = grid.getRow(rowEntity);
  14078. }
  14079. if (typeof(colDef) !== 'undefined' && colDef !== null) {
  14080. gridCol = grid.getColumn(colDef.name ? colDef.name : colDef.field);
  14081. }
  14082. return grid.api.core.scrollToIfNecessary(gridRow, gridCol).then(function () {
  14083. var rowCol = { row: gridRow, col: gridCol };
  14084. // Broadcast the navigation
  14085. if (gridRow !== null && gridCol !== null) {
  14086. grid.cellNav.broadcastCellNav(rowCol);
  14087. }
  14088. });
  14089. },
  14090. /**
  14091. * @ngdoc method
  14092. * @methodOf ui.grid.cellNav.service:uiGridCellNavService
  14093. * @name getLeftWidth
  14094. * @description Get the current drawn width of the columns in the
  14095. * grid up to the numbered column, and add an apportionment for the
  14096. * column that we're on. So if we are on column 0, we want to scroll
  14097. * 0% (i.e. exclude this column from calc). If we're on the last column
  14098. * we want to scroll to 100% (i.e. include this column in the calc). So
  14099. * we include (thisColIndex / totalNumberCols) % of this column width
  14100. * @param {Grid} grid the grid you'd like to act upon, usually available
  14101. * from gridApi.grid
  14102. * @param {GridColumn} upToCol the column to total up to and including
  14103. */
  14104. getLeftWidth: function (grid, upToCol) {
  14105. var width = 0;
  14106. if (!upToCol) {
  14107. return width;
  14108. }
  14109. var lastIndex = grid.renderContainers.body.visibleColumnCache.indexOf( upToCol );
  14110. // total column widths up-to but not including the passed in column
  14111. grid.renderContainers.body.visibleColumnCache.forEach( function( col, index ) {
  14112. if ( index < lastIndex ){
  14113. width += col.drawnWidth;
  14114. }
  14115. });
  14116. // pro-rata the final column based on % of total columns.
  14117. var percentage = lastIndex === 0 ? 0 : (lastIndex + 1) / grid.renderContainers.body.visibleColumnCache.length;
  14118. width += upToCol.drawnWidth * percentage;
  14119. return width;
  14120. }
  14121. };
  14122. return service;
  14123. }]);
  14124. /**
  14125. * @ngdoc directive
  14126. * @name ui.grid.cellNav.directive:uiCellNav
  14127. * @element div
  14128. * @restrict EA
  14129. *
  14130. * @description Adds cell navigation features to the grid columns
  14131. *
  14132. * @example
  14133. <example module="app">
  14134. <file name="app.js">
  14135. var app = angular.module('app', ['ui.grid', 'ui.grid.cellNav']);
  14136. app.controller('MainCtrl', ['$scope', function ($scope) {
  14137. $scope.data = [
  14138. { name: 'Bob', title: 'CEO' },
  14139. { name: 'Frank', title: 'Lowly Developer' }
  14140. ];
  14141. $scope.columnDefs = [
  14142. {name: 'name'},
  14143. {name: 'title'}
  14144. ];
  14145. }]);
  14146. </file>
  14147. <file name="index.html">
  14148. <div ng-controller="MainCtrl">
  14149. <div ui-grid="{ data: data, columnDefs: columnDefs }" ui-grid-cellnav></div>
  14150. </div>
  14151. </file>
  14152. </example>
  14153. */
  14154. module.directive('uiGridCellnav', ['gridUtil', 'uiGridCellNavService', 'uiGridCellNavConstants', 'uiGridConstants', 'GridRowColumn', '$timeout', '$compile', 'i18nService',
  14155. function (gridUtil, uiGridCellNavService, uiGridCellNavConstants, uiGridConstants, GridRowColumn, $timeout, $compile, i18nService) {
  14156. return {
  14157. replace: true,
  14158. priority: -150,
  14159. require: '^uiGrid',
  14160. scope: false,
  14161. controller: function () {},
  14162. compile: function () {
  14163. return {
  14164. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  14165. var _scope = $scope;
  14166. var grid = uiGridCtrl.grid;
  14167. uiGridCellNavService.initializeGrid(grid);
  14168. uiGridCtrl.cellNav = {};
  14169. //Ensure that the object has all of the methods we expect it to
  14170. uiGridCtrl.cellNav.makeRowCol = function (obj) {
  14171. if (!(obj instanceof GridRowColumn)) {
  14172. obj = new GridRowColumn(obj.row, obj.col);
  14173. }
  14174. return obj;
  14175. };
  14176. uiGridCtrl.cellNav.getActiveCell = function () {
  14177. var elms = $elm[0].getElementsByClassName('ui-grid-cell-focus');
  14178. if (elms.length > 0){
  14179. return elms[0];
  14180. }
  14181. return undefined;
  14182. };
  14183. uiGridCtrl.cellNav.broadcastCellNav = grid.cellNav.broadcastCellNav = function (newRowCol, modifierDown, originEvt) {
  14184. modifierDown = !(modifierDown === undefined || !modifierDown);
  14185. newRowCol = uiGridCtrl.cellNav.makeRowCol(newRowCol);
  14186. uiGridCtrl.cellNav.broadcastFocus(newRowCol, modifierDown, originEvt);
  14187. _scope.$broadcast(uiGridCellNavConstants.CELL_NAV_EVENT, newRowCol, modifierDown, originEvt);
  14188. };
  14189. uiGridCtrl.cellNav.clearFocus = grid.cellNav.clearFocus = function () {
  14190. grid.cellNav.focusedCells = [];
  14191. _scope.$broadcast(uiGridCellNavConstants.CELL_NAV_EVENT);
  14192. };
  14193. uiGridCtrl.cellNav.broadcastFocus = function (rowCol, modifierDown, originEvt) {
  14194. modifierDown = !(modifierDown === undefined || !modifierDown);
  14195. rowCol = uiGridCtrl.cellNav.makeRowCol(rowCol);
  14196. var row = rowCol.row,
  14197. col = rowCol.col;
  14198. var rowColSelectIndex = uiGridCtrl.grid.api.cellNav.rowColSelectIndex(rowCol);
  14199. if (grid.cellNav.lastRowCol === null || rowColSelectIndex === -1 || (grid.cellNav.lastRowCol.col === col && grid.cellNav.lastRowCol.row === row)) {
  14200. var newRowCol = new GridRowColumn(row, col);
  14201. if (grid.cellNav.lastRowCol === null || grid.cellNav.lastRowCol.row !== newRowCol.row || grid.cellNav.lastRowCol.col !== newRowCol.col || grid.options.enableCellEditOnFocus){
  14202. grid.api.cellNav.raise.navigate(newRowCol, grid.cellNav.lastRowCol, originEvt);
  14203. grid.cellNav.lastRowCol = newRowCol;
  14204. }
  14205. if (uiGridCtrl.grid.options.modifierKeysToMultiSelectCells && modifierDown) {
  14206. grid.cellNav.focusedCells.push(rowCol);
  14207. } else {
  14208. grid.cellNav.focusedCells = [rowCol];
  14209. }
  14210. } else if (grid.options.modifierKeysToMultiSelectCells && modifierDown &&
  14211. rowColSelectIndex >= 0) {
  14212. grid.cellNav.focusedCells.splice(rowColSelectIndex, 1);
  14213. }
  14214. };
  14215. uiGridCtrl.cellNav.handleKeyDown = function (evt) {
  14216. var direction = uiGridCellNavService.getDirection(evt);
  14217. if (direction === null) {
  14218. return null;
  14219. }
  14220. var containerId = 'body';
  14221. if (evt.uiGridTargetRenderContainerId) {
  14222. containerId = evt.uiGridTargetRenderContainerId;
  14223. }
  14224. // Get the last-focused row+col combo
  14225. var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
  14226. if (lastRowCol) {
  14227. // Figure out which new row+combo we're navigating to
  14228. var rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(direction, lastRowCol.row, lastRowCol.col);
  14229. var focusableCols = uiGridCtrl.grid.renderContainers[containerId].cellNav.getFocusableCols();
  14230. var rowColSelectIndex = uiGridCtrl.grid.api.cellNav.rowColSelectIndex(rowCol);
  14231. // Shift+tab on top-left cell should exit cellnav on render container
  14232. if (
  14233. // Navigating left
  14234. direction === uiGridCellNavConstants.direction.LEFT &&
  14235. // New col is last col (i.e. wrap around)
  14236. rowCol.col === focusableCols[focusableCols.length - 1] &&
  14237. // Staying on same row, which means we're at first row
  14238. rowCol.row === lastRowCol.row &&
  14239. evt.keyCode === uiGridConstants.keymap.TAB &&
  14240. evt.shiftKey
  14241. ) {
  14242. grid.cellNav.focusedCells.splice(rowColSelectIndex, 1);
  14243. uiGridCtrl.cellNav.clearFocus();
  14244. return true;
  14245. }
  14246. // Tab on bottom-right cell should exit cellnav on render container
  14247. else if (
  14248. direction === uiGridCellNavConstants.direction.RIGHT &&
  14249. // New col is first col (i.e. wrap around)
  14250. rowCol.col === focusableCols[0] &&
  14251. // Staying on same row, which means we're at first row
  14252. rowCol.row === lastRowCol.row &&
  14253. evt.keyCode === uiGridConstants.keymap.TAB &&
  14254. !evt.shiftKey
  14255. ) {
  14256. grid.cellNav.focusedCells.splice(rowColSelectIndex, 1);
  14257. uiGridCtrl.cellNav.clearFocus();
  14258. return true;
  14259. }
  14260. // Scroll to the new cell, if it's not completely visible within the render container's viewport
  14261. grid.scrollToIfNecessary(rowCol.row, rowCol.col).then(function () {
  14262. uiGridCtrl.cellNav.broadcastCellNav(rowCol, null, evt);
  14263. });
  14264. evt.stopPropagation();
  14265. evt.preventDefault();
  14266. return false;
  14267. }
  14268. };
  14269. },
  14270. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  14271. var _scope = $scope;
  14272. var grid = uiGridCtrl.grid;
  14273. var usesAria = true;
  14274. // Detect whether we are using ngAria
  14275. // (if ngAria module is not used then the stuff inside addAriaLiveRegion
  14276. // is not used and provides extra fluff)
  14277. try {
  14278. angular.module('ngAria');
  14279. }
  14280. catch (err) {
  14281. usesAria = false;
  14282. }
  14283. function addAriaLiveRegion(){
  14284. // Thanks to google docs for the inspiration behind how to do this
  14285. // XXX: Why is this entire mess nessasary?
  14286. // Because browsers take a lot of coercing to get them to read out live regions
  14287. //http://www.paciellogroup.com/blog/2012/06/html5-accessibility-chops-aria-rolealert-browser-support/
  14288. var ariaNotifierDomElt = '<div ' +
  14289. 'id="' + grid.id +'-aria-speakable" ' +
  14290. 'class="ui-grid-a11y-ariascreenreader-speakable ui-grid-offscreen" ' +
  14291. 'aria-live="assertive" ' +
  14292. 'role="alert" ' +
  14293. 'aria-atomic="true" ' +
  14294. 'aria-hidden="false" ' +
  14295. 'aria-relevant="additions" ' +
  14296. '>' +
  14297. '&nbsp;' +
  14298. '</div>';
  14299. var ariaNotifier = $compile(ariaNotifierDomElt)($scope);
  14300. $elm.prepend(ariaNotifier);
  14301. $scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, function (evt, rowCol, modifierDown, originEvt) {
  14302. /*
  14303. * If the cell nav event was because of a focus event then we don't want to
  14304. * change the notifier text.
  14305. * Reasoning: Voice Over fires a focus events when moving arround the grid.
  14306. * If the screen reader is handing the grid nav properly then we don't need to
  14307. * use the alert to notify the user of the movement.
  14308. * In all other cases we do want a notification event.
  14309. */
  14310. if (originEvt && originEvt.type === 'focus'){return;}
  14311. function setNotifyText(text){
  14312. if (text === ariaNotifier.text().trim()){return;}
  14313. ariaNotifier[0].style.clip = 'rect(0px,0px,0px,0px)';
  14314. /*
  14315. * This is how google docs handles clearing the div. Seems to work better than setting the text of the div to ''
  14316. */
  14317. ariaNotifier[0].innerHTML = "";
  14318. ariaNotifier[0].style.visibility = 'hidden';
  14319. ariaNotifier[0].style.visibility = 'visible';
  14320. if (text !== ''){
  14321. ariaNotifier[0].style.clip = 'auto';
  14322. /*
  14323. * The space after the text is something that google docs does.
  14324. */
  14325. ariaNotifier[0].appendChild(document.createTextNode(text + " "));
  14326. ariaNotifier[0].style.visibility = 'hidden';
  14327. ariaNotifier[0].style.visibility = 'visible';
  14328. }
  14329. }
  14330. function getAppendedColumnHeaderText(col) {
  14331. return ', ' + i18nService.getSafeText('headerCell.aria.column') + ' ' + col.displayName;
  14332. }
  14333. function getCellDisplayValue(currentRowColumn) {
  14334. if (currentRowColumn.col.field === 'selectionRowHeaderCol') {
  14335. // This is the case when the 'selection' feature is used in the grid and the user has moved
  14336. // to or inside of the left grid container which holds the checkboxes for selecting rows.
  14337. // This is necessary for Accessibility. Without this a screen reader cannot determine if the row
  14338. // is or is not currently selected.
  14339. return currentRowColumn.row.isSelected ? i18nService.getSafeText('search.aria.selected') : i18nService.getSafeText('search.aria.notSelected');
  14340. } else {
  14341. return grid.getCellDisplayValue(currentRowColumn.row, currentRowColumn.col);
  14342. }
  14343. }
  14344. var values = [];
  14345. var currentSelection = grid.api.cellNav.getCurrentSelection();
  14346. for (var i = 0; i < currentSelection.length; i++) {
  14347. var cellDisplayValue = getCellDisplayValue(currentSelection[i]) + getAppendedColumnHeaderText(currentSelection[i].col);
  14348. values.push(cellDisplayValue);
  14349. }
  14350. var cellText = values.toString();
  14351. setNotifyText(cellText);
  14352. });
  14353. }
  14354. // Only add the ngAria stuff it will be used
  14355. if (usesAria) {
  14356. addAriaLiveRegion();
  14357. }
  14358. }
  14359. };
  14360. }
  14361. };
  14362. }]);
  14363. module.directive('uiGridRenderContainer', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', '$compile','uiGridCellNavConstants',
  14364. function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, $compile, uiGridCellNavConstants) {
  14365. return {
  14366. replace: true,
  14367. priority: -99999, //this needs to run very last
  14368. require: ['^uiGrid', 'uiGridRenderContainer', '?^uiGridCellnav'],
  14369. scope: false,
  14370. compile: function () {
  14371. return {
  14372. post: function ($scope, $elm, $attrs, controllers) {
  14373. var uiGridCtrl = controllers[0],
  14374. renderContainerCtrl = controllers[1],
  14375. uiGridCellnavCtrl = controllers[2];
  14376. // Skip attaching cell-nav specific logic if the directive is not attached above us
  14377. if (!uiGridCtrl.grid.api.cellNav) { return; }
  14378. var containerId = renderContainerCtrl.containerId;
  14379. var grid = uiGridCtrl.grid;
  14380. //run each time a render container is created
  14381. uiGridCellNavService.decorateRenderContainers(grid);
  14382. // focusser only created for body
  14383. if (containerId !== 'body') {
  14384. return;
  14385. }
  14386. if (uiGridCtrl.grid.options.modifierKeysToMultiSelectCells){
  14387. $elm.attr('aria-multiselectable', true);
  14388. } else {
  14389. $elm.attr('aria-multiselectable', false);
  14390. }
  14391. //add an element with no dimensions that can be used to set focus and capture keystrokes
  14392. 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);
  14393. $elm.append(focuser);
  14394. focuser.on('focus', function (evt) {
  14395. evt.uiGridTargetRenderContainerId = containerId;
  14396. var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
  14397. if (rowCol === null) {
  14398. rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(uiGridCellNavConstants.direction.DOWN, null, null);
  14399. if (rowCol.row && rowCol.col) {
  14400. uiGridCtrl.cellNav.broadcastCellNav(rowCol);
  14401. }
  14402. }
  14403. });
  14404. uiGridCellnavCtrl.setAriaActivedescendant = function(id){
  14405. $elm.attr('aria-activedescendant', id);
  14406. };
  14407. uiGridCellnavCtrl.removeAriaActivedescendant = function(id){
  14408. if ($elm.attr('aria-activedescendant') === id){
  14409. $elm.attr('aria-activedescendant', '');
  14410. }
  14411. };
  14412. uiGridCtrl.focus = function () {
  14413. gridUtil.focus.byElement(focuser[0]);
  14414. //allow for first time grid focus
  14415. };
  14416. var viewPortKeyDownWasRaisedForRowCol = null;
  14417. // Bind to keydown events in the render container
  14418. focuser.on('keydown', function (evt) {
  14419. evt.uiGridTargetRenderContainerId = containerId;
  14420. var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
  14421. var raiseViewPortKeyDown = uiGridCtrl.grid.options.keyDownOverrides.some(function (override) {
  14422. return Object.keys(override).every( function (property) {
  14423. return override[property] === evt[property];
  14424. });
  14425. });
  14426. var result = raiseViewPortKeyDown ? null : uiGridCtrl.cellNav.handleKeyDown(evt);
  14427. if (result === null) {
  14428. uiGridCtrl.grid.api.cellNav.raise.viewPortKeyDown(evt, rowCol, uiGridCtrl.cellNav.handleKeyDown);
  14429. viewPortKeyDownWasRaisedForRowCol = rowCol;
  14430. }
  14431. });
  14432. //Bind to keypress events in the render container
  14433. //keypress events are needed by edit function so the key press
  14434. //that initiated an edit is not lost
  14435. //must fire the event in a timeout so the editor can
  14436. //initialize and subscribe to the event on another event loop
  14437. focuser.on('keypress', function (evt) {
  14438. if (viewPortKeyDownWasRaisedForRowCol) {
  14439. $timeout(function () {
  14440. uiGridCtrl.grid.api.cellNav.raise.viewPortKeyPress(evt, viewPortKeyDownWasRaisedForRowCol);
  14441. },4);
  14442. viewPortKeyDownWasRaisedForRowCol = null;
  14443. }
  14444. });
  14445. $scope.$on('$destroy', function(){
  14446. //Remove all event handlers associated with this focuser.
  14447. focuser.off();
  14448. });
  14449. }
  14450. };
  14451. }
  14452. };
  14453. }]);
  14454. module.directive('uiGridViewport', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', 'uiGridCellNavConstants','$log','$compile',
  14455. function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, uiGridCellNavConstants, $log, $compile) {
  14456. return {
  14457. replace: true,
  14458. priority: -99999, //this needs to run very last
  14459. require: ['^uiGrid', '^uiGridRenderContainer', '?^uiGridCellnav'],
  14460. scope: false,
  14461. compile: function () {
  14462. return {
  14463. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  14464. },
  14465. post: function ($scope, $elm, $attrs, controllers) {
  14466. var uiGridCtrl = controllers[0],
  14467. renderContainerCtrl = controllers[1];
  14468. // Skip attaching cell-nav specific logic if the directive is not attached above us
  14469. if (!uiGridCtrl.grid.api.cellNav) { return; }
  14470. var containerId = renderContainerCtrl.containerId;
  14471. //no need to process for other containers
  14472. if (containerId !== 'body') {
  14473. return;
  14474. }
  14475. var grid = uiGridCtrl.grid;
  14476. grid.api.core.on.scrollBegin($scope, function (args) {
  14477. // Skip if there's no currently-focused cell
  14478. var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
  14479. if (lastRowCol === null) {
  14480. return;
  14481. }
  14482. //if not in my container, move on
  14483. //todo: worry about horiz scroll
  14484. if (!renderContainerCtrl.colContainer.containsColumn(lastRowCol.col)) {
  14485. return;
  14486. }
  14487. uiGridCtrl.cellNav.clearFocus();
  14488. });
  14489. grid.api.core.on.scrollEnd($scope, function (args) {
  14490. // Skip if there's no currently-focused cell
  14491. var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
  14492. if (lastRowCol === null) {
  14493. return;
  14494. }
  14495. //if not in my container, move on
  14496. //todo: worry about horiz scroll
  14497. if (!renderContainerCtrl.colContainer.containsColumn(lastRowCol.col)) {
  14498. return;
  14499. }
  14500. uiGridCtrl.cellNav.broadcastCellNav(lastRowCol);
  14501. });
  14502. grid.api.cellNav.on.navigate($scope, function () {
  14503. //focus again because it can be lost
  14504. uiGridCtrl.focus();
  14505. });
  14506. }
  14507. };
  14508. }
  14509. };
  14510. }]);
  14511. /**
  14512. * @ngdoc directive
  14513. * @name ui.grid.cellNav.directive:uiGridCell
  14514. * @element div
  14515. * @restrict A
  14516. * @description Stacks on top of ui.grid.uiGridCell to provide cell navigation
  14517. */
  14518. module.directive('uiGridCell', ['$timeout', '$document', 'uiGridCellNavService', 'gridUtil', 'uiGridCellNavConstants', 'uiGridConstants', 'GridRowColumn',
  14519. function ($timeout, $document, uiGridCellNavService, gridUtil, uiGridCellNavConstants, uiGridConstants, GridRowColumn) {
  14520. return {
  14521. priority: -150, // run after default uiGridCell directive and ui.grid.edit uiGridCell
  14522. restrict: 'A',
  14523. require: ['^uiGrid', '?^uiGridCellnav'],
  14524. scope: false,
  14525. link: function ($scope, $elm, $attrs, controllers) {
  14526. var uiGridCtrl = controllers[0],
  14527. uiGridCellnavCtrl = controllers[1];
  14528. // Skip attaching cell-nav specific logic if the directive is not attached above us
  14529. if (!uiGridCtrl.grid.api.cellNav) { return; }
  14530. if (!$scope.col.colDef.allowCellFocus) {
  14531. return;
  14532. }
  14533. //Convinience local variables
  14534. var grid = uiGridCtrl.grid;
  14535. $scope.focused = false;
  14536. // Make this cell focusable but only with javascript/a mouse click
  14537. $elm.attr('tabindex', -1);
  14538. // When a cell is clicked, broadcast a cellNav event saying that this row+col combo is now focused
  14539. $elm.find('div').on('click', function (evt) {
  14540. uiGridCtrl.cellNav.broadcastCellNav(new GridRowColumn($scope.row, $scope.col), evt.ctrlKey || evt.metaKey, evt);
  14541. evt.stopPropagation();
  14542. $scope.$apply();
  14543. });
  14544. /*
  14545. * XXX Hack for screen readers.
  14546. * This allows the grid to focus using only the screen reader cursor.
  14547. * Since the focus event doesn't include key press information we can't use it
  14548. * as our primary source of the event.
  14549. */
  14550. $elm.on('mousedown', preventMouseDown);
  14551. //turn on and off for edit events
  14552. if (uiGridCtrl.grid.api.edit) {
  14553. uiGridCtrl.grid.api.edit.on.beginCellEdit($scope, function () {
  14554. $elm.off('mousedown', preventMouseDown);
  14555. });
  14556. uiGridCtrl.grid.api.edit.on.afterCellEdit($scope, function () {
  14557. $elm.on('mousedown', preventMouseDown);
  14558. });
  14559. uiGridCtrl.grid.api.edit.on.cancelCellEdit($scope, function () {
  14560. $elm.on('mousedown', preventMouseDown);
  14561. });
  14562. }
  14563. // In case we created a new row, and we are the new created row by ngRepeat
  14564. // then this cell content might have been selected previously
  14565. refreshCellFocus();
  14566. function preventMouseDown(evt) {
  14567. //Prevents the foucus event from firing if the click event is already going to fire.
  14568. //If both events fire it will cause bouncing behavior.
  14569. evt.preventDefault();
  14570. }
  14571. //You can only focus on elements with a tabindex value
  14572. $elm.on('focus', function (evt) {
  14573. uiGridCtrl.cellNav.broadcastCellNav(new GridRowColumn($scope.row, $scope.col), false, evt);
  14574. evt.stopPropagation();
  14575. $scope.$apply();
  14576. });
  14577. // This event is fired for all cells. If the cell matches, then focus is set
  14578. $scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, refreshCellFocus);
  14579. // Refresh cell focus when a new row id added to the grid
  14580. var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback(function (grid) {
  14581. // Clear the focus if it's set to avoid the wrong cell getting focused during
  14582. // a short period of time (from now until $timeout function executed)
  14583. clearFocus();
  14584. $scope.$applyAsync(refreshCellFocus);
  14585. }, [uiGridConstants.dataChange.ROW]);
  14586. function refreshCellFocus() {
  14587. var isFocused = grid.cellNav.focusedCells.some(function (focusedRowCol, index) {
  14588. return (focusedRowCol.row === $scope.row && focusedRowCol.col === $scope.col);
  14589. });
  14590. if (isFocused) {
  14591. setFocused();
  14592. } else {
  14593. clearFocus();
  14594. }
  14595. }
  14596. function setFocused() {
  14597. if (!$scope.focused){
  14598. var div = $elm.find('div');
  14599. div.addClass('ui-grid-cell-focus');
  14600. $elm.attr('aria-selected', true);
  14601. uiGridCellnavCtrl.setAriaActivedescendant($elm.attr('id'));
  14602. $scope.focused = true;
  14603. }
  14604. }
  14605. function clearFocus() {
  14606. if ($scope.focused){
  14607. var div = $elm.find('div');
  14608. div.removeClass('ui-grid-cell-focus');
  14609. $elm.attr('aria-selected', false);
  14610. uiGridCellnavCtrl.removeAriaActivedescendant($elm.attr('id'));
  14611. $scope.focused = false;
  14612. }
  14613. }
  14614. $scope.$on('$destroy', function () {
  14615. dataChangeDereg();
  14616. //.off withouth paramaters removes all handlers
  14617. $elm.find('div').off();
  14618. $elm.off();
  14619. });
  14620. }
  14621. };
  14622. }]);
  14623. })();
  14624. (function () {
  14625. 'use strict';
  14626. /**
  14627. * @ngdoc overview
  14628. * @name ui.grid.edit
  14629. * @description
  14630. *
  14631. * # ui.grid.edit
  14632. *
  14633. * <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>
  14634. *
  14635. * This module provides cell editing capability to ui.grid. The goal was to emulate keying data in a spreadsheet via
  14636. * a keyboard.
  14637. * <br/>
  14638. * <br/>
  14639. * To really get the full spreadsheet-like data entry, the ui.grid.cellNav module should be used. This will allow the
  14640. * user to key data and then tab, arrow, or enter to the cells beside or below.
  14641. *
  14642. * <div doc-module-components="ui.grid.edit"></div>
  14643. */
  14644. var module = angular.module('ui.grid.edit', ['ui.grid']);
  14645. /**
  14646. * @ngdoc object
  14647. * @name ui.grid.edit.constant:uiGridEditConstants
  14648. *
  14649. * @description constants available in edit module
  14650. */
  14651. module.constant('uiGridEditConstants', {
  14652. EDITABLE_CELL_TEMPLATE: /EDITABLE_CELL_TEMPLATE/g,
  14653. //must be lowercase because template bulder converts to lower
  14654. EDITABLE_CELL_DIRECTIVE: /editable_cell_directive/g,
  14655. events: {
  14656. BEGIN_CELL_EDIT: 'uiGridEventBeginCellEdit',
  14657. END_CELL_EDIT: 'uiGridEventEndCellEdit',
  14658. CANCEL_CELL_EDIT: 'uiGridEventCancelCellEdit'
  14659. }
  14660. });
  14661. /**
  14662. * @ngdoc service
  14663. * @name ui.grid.edit.service:uiGridEditService
  14664. *
  14665. * @description Services for editing features
  14666. */
  14667. module.service('uiGridEditService', ['$q', 'uiGridConstants', 'gridUtil',
  14668. function ($q, uiGridConstants, gridUtil) {
  14669. var service = {
  14670. initializeGrid: function (grid) {
  14671. service.defaultGridOptions(grid.options);
  14672. grid.registerColumnBuilder(service.editColumnBuilder);
  14673. grid.edit = {};
  14674. /**
  14675. * @ngdoc object
  14676. * @name ui.grid.edit.api:PublicApi
  14677. *
  14678. * @description Public Api for edit feature
  14679. */
  14680. var publicApi = {
  14681. events: {
  14682. edit: {
  14683. /**
  14684. * @ngdoc event
  14685. * @name afterCellEdit
  14686. * @eventOf ui.grid.edit.api:PublicApi
  14687. * @description raised when cell editing is complete
  14688. * <pre>
  14689. * gridApi.edit.on.afterCellEdit(scope,function(rowEntity, colDef){})
  14690. * </pre>
  14691. * @param {object} rowEntity the options.data element that was edited
  14692. * @param {object} colDef the column that was edited
  14693. * @param {object} newValue new value
  14694. * @param {object} oldValue old value
  14695. */
  14696. afterCellEdit: function (rowEntity, colDef, newValue, oldValue) {
  14697. },
  14698. /**
  14699. * @ngdoc event
  14700. * @name beginCellEdit
  14701. * @eventOf ui.grid.edit.api:PublicApi
  14702. * @description raised when cell editing starts on a cell
  14703. * <pre>
  14704. * gridApi.edit.on.beginCellEdit(scope,function(rowEntity, colDef){})
  14705. * </pre>
  14706. * @param {object} rowEntity the options.data element that was edited
  14707. * @param {object} colDef the column that was edited
  14708. * @param {object} triggerEvent the event that triggered the edit. Useful to prevent losing keystrokes on some
  14709. * complex editors
  14710. */
  14711. beginCellEdit: function (rowEntity, colDef, triggerEvent) {
  14712. },
  14713. /**
  14714. * @ngdoc event
  14715. * @name cancelCellEdit
  14716. * @eventOf ui.grid.edit.api:PublicApi
  14717. * @description raised when cell editing is cancelled on a cell
  14718. * <pre>
  14719. * gridApi.edit.on.cancelCellEdit(scope,function(rowEntity, colDef){})
  14720. * </pre>
  14721. * @param {object} rowEntity the options.data element that was edited
  14722. * @param {object} colDef the column that was edited
  14723. */
  14724. cancelCellEdit: function (rowEntity, colDef) {
  14725. }
  14726. }
  14727. },
  14728. methods: {
  14729. edit: { }
  14730. }
  14731. };
  14732. grid.api.registerEventsFromObject(publicApi.events);
  14733. //grid.api.registerMethodsFromObject(publicApi.methods);
  14734. },
  14735. defaultGridOptions: function (gridOptions) {
  14736. /**
  14737. * @ngdoc object
  14738. * @name ui.grid.edit.api:GridOptions
  14739. *
  14740. * @description Options for configuring the edit feature, these are available to be
  14741. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  14742. */
  14743. /**
  14744. * @ngdoc object
  14745. * @name enableCellEdit
  14746. * @propertyOf ui.grid.edit.api:GridOptions
  14747. * @description If defined, sets the default value for the editable flag on each individual colDefs
  14748. * if their individual enableCellEdit configuration is not defined. Defaults to undefined.
  14749. */
  14750. /**
  14751. * @ngdoc object
  14752. * @name cellEditableCondition
  14753. * @propertyOf ui.grid.edit.api:GridOptions
  14754. * @description If specified, either a value or function to be used by all columns before editing.
  14755. * If false, then editing of cell is not allowed.
  14756. * @example
  14757. * <pre>
  14758. * function($scope, triggerEvent){
  14759. * //use $scope.row.entity, $scope.col.colDef and triggerEvent to determine if editing is allowed
  14760. * return true;
  14761. * }
  14762. * </pre>
  14763. */
  14764. gridOptions.cellEditableCondition = gridOptions.cellEditableCondition === undefined ? true : gridOptions.cellEditableCondition;
  14765. /**
  14766. * @ngdoc object
  14767. * @name editableCellTemplate
  14768. * @propertyOf ui.grid.edit.api:GridOptions
  14769. * @description If specified, cellTemplate to use as the editor for all columns.
  14770. * <br/> defaults to 'ui-grid/cellTextEditor'
  14771. */
  14772. /**
  14773. * @ngdoc object
  14774. * @name enableCellEditOnFocus
  14775. * @propertyOf ui.grid.edit.api:GridOptions
  14776. * @description If true, then editor is invoked as soon as cell receives focus. Default false.
  14777. * <br/>_requires cellNav feature and the edit feature to be enabled_
  14778. */
  14779. //enableCellEditOnFocus can only be used if cellnav module is used
  14780. gridOptions.enableCellEditOnFocus = gridOptions.enableCellEditOnFocus === undefined ? false : gridOptions.enableCellEditOnFocus;
  14781. },
  14782. /**
  14783. * @ngdoc service
  14784. * @name editColumnBuilder
  14785. * @methodOf ui.grid.edit.service:uiGridEditService
  14786. * @description columnBuilder function that adds edit properties to grid column
  14787. * @returns {promise} promise that will load any needed templates when resolved
  14788. */
  14789. editColumnBuilder: function (colDef, col, gridOptions) {
  14790. var promises = [];
  14791. /**
  14792. * @ngdoc object
  14793. * @name ui.grid.edit.api:ColumnDef
  14794. *
  14795. * @description Column Definition for edit feature, these are available to be
  14796. * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs}
  14797. */
  14798. /**
  14799. * @ngdoc object
  14800. * @name enableCellEdit
  14801. * @propertyOf ui.grid.edit.api:ColumnDef
  14802. * @description enable editing on column
  14803. */
  14804. colDef.enableCellEdit = colDef.enableCellEdit === undefined ? (gridOptions.enableCellEdit === undefined ?
  14805. (colDef.type !== 'object') : gridOptions.enableCellEdit) : colDef.enableCellEdit;
  14806. /**
  14807. * @ngdoc object
  14808. * @name cellEditableCondition
  14809. * @propertyOf ui.grid.edit.api:ColumnDef
  14810. * @description If specified, either a value or function evaluated before editing cell. If falsy, then editing of cell is not allowed.
  14811. * @example
  14812. * <pre>
  14813. * function($scope, triggerEvent){
  14814. * //use $scope.row.entity, $scope.col.colDef and triggerEvent to determine if editing is allowed
  14815. * return true;
  14816. * }
  14817. * </pre>
  14818. */
  14819. colDef.cellEditableCondition = colDef.cellEditableCondition === undefined ? gridOptions.cellEditableCondition : colDef.cellEditableCondition;
  14820. /**
  14821. * @ngdoc object
  14822. * @name editableCellTemplate
  14823. * @propertyOf ui.grid.edit.api:ColumnDef
  14824. * @description cell template to be used when editing this column. Can be Url or text template
  14825. * <br/>Defaults to gridOptions.editableCellTemplate
  14826. */
  14827. if (colDef.enableCellEdit) {
  14828. colDef.editableCellTemplate = colDef.editableCellTemplate || gridOptions.editableCellTemplate || 'ui-grid/cellEditor';
  14829. promises.push(gridUtil.getTemplate(colDef.editableCellTemplate)
  14830. .then(
  14831. function (template) {
  14832. col.editableCellTemplate = template;
  14833. },
  14834. function (res) {
  14835. // Todo handle response error here?
  14836. throw new Error("Couldn't fetch/use colDef.editableCellTemplate '" + colDef.editableCellTemplate + "'");
  14837. }));
  14838. }
  14839. /**
  14840. * @ngdoc object
  14841. * @name enableCellEditOnFocus
  14842. * @propertyOf ui.grid.edit.api:ColumnDef
  14843. * @requires ui.grid.cellNav
  14844. * @description If true, then editor is invoked as soon as cell receives focus. Default false.
  14845. * <br>_requires both the cellNav feature and the edit feature to be enabled_
  14846. */
  14847. //enableCellEditOnFocus can only be used if cellnav module is used
  14848. colDef.enableCellEditOnFocus = colDef.enableCellEditOnFocus === undefined ? gridOptions.enableCellEditOnFocus : colDef.enableCellEditOnFocus;
  14849. /**
  14850. * @ngdoc string
  14851. * @name editModelField
  14852. * @propertyOf ui.grid.edit.api:ColumnDef
  14853. * @description a bindable string value that is used when binding to edit controls instead of colDef.field
  14854. * <br/> example: You have a complex property on and object like state:{abbrev:'MS',name:'Mississippi'}. The
  14855. * grid should display state.name in the cell and sort/filter based on the state.name property but the editor
  14856. * requires the full state object.
  14857. * <br/>colDef.field = 'state.name'
  14858. * <br/>colDef.editModelField = 'state'
  14859. */
  14860. //colDef.editModelField
  14861. return $q.all(promises);
  14862. },
  14863. /**
  14864. * @ngdoc service
  14865. * @name isStartEditKey
  14866. * @methodOf ui.grid.edit.service:uiGridEditService
  14867. * @description Determines if a keypress should start editing. Decorate this service to override with your
  14868. * own key events. See service decorator in angular docs.
  14869. * @param {Event} evt keydown event
  14870. * @returns {boolean} true if an edit should start
  14871. */
  14872. isStartEditKey: function (evt) {
  14873. if (evt.metaKey ||
  14874. evt.keyCode === uiGridConstants.keymap.ESC ||
  14875. evt.keyCode === uiGridConstants.keymap.SHIFT ||
  14876. evt.keyCode === uiGridConstants.keymap.CTRL ||
  14877. evt.keyCode === uiGridConstants.keymap.ALT ||
  14878. evt.keyCode === uiGridConstants.keymap.WIN ||
  14879. evt.keyCode === uiGridConstants.keymap.CAPSLOCK ||
  14880. evt.keyCode === uiGridConstants.keymap.LEFT ||
  14881. (evt.keyCode === uiGridConstants.keymap.TAB && evt.shiftKey) ||
  14882. evt.keyCode === uiGridConstants.keymap.RIGHT ||
  14883. evt.keyCode === uiGridConstants.keymap.TAB ||
  14884. evt.keyCode === uiGridConstants.keymap.UP ||
  14885. (evt.keyCode === uiGridConstants.keymap.ENTER && evt.shiftKey) ||
  14886. evt.keyCode === uiGridConstants.keymap.DOWN ||
  14887. evt.keyCode === uiGridConstants.keymap.ENTER) {
  14888. return false;
  14889. }
  14890. return true;
  14891. }
  14892. };
  14893. return service;
  14894. }]);
  14895. /**
  14896. * @ngdoc directive
  14897. * @name ui.grid.edit.directive:uiGridEdit
  14898. * @element div
  14899. * @restrict A
  14900. *
  14901. * @description Adds editing features to the ui-grid directive.
  14902. *
  14903. * @example
  14904. <example module="app">
  14905. <file name="app.js">
  14906. var app = angular.module('app', ['ui.grid', 'ui.grid.edit']);
  14907. app.controller('MainCtrl', ['$scope', function ($scope) {
  14908. $scope.data = [
  14909. { name: 'Bob', title: 'CEO' },
  14910. { name: 'Frank', title: 'Lowly Developer' }
  14911. ];
  14912. $scope.columnDefs = [
  14913. {name: 'name', enableCellEdit: true},
  14914. {name: 'title', enableCellEdit: true}
  14915. ];
  14916. }]);
  14917. </file>
  14918. <file name="index.html">
  14919. <div ng-controller="MainCtrl">
  14920. <div ui-grid="{ data: data, columnDefs: columnDefs }" ui-grid-edit></div>
  14921. </div>
  14922. </file>
  14923. </example>
  14924. */
  14925. module.directive('uiGridEdit', ['gridUtil', 'uiGridEditService', function (gridUtil, uiGridEditService) {
  14926. return {
  14927. replace: true,
  14928. priority: 0,
  14929. require: '^uiGrid',
  14930. scope: false,
  14931. compile: function () {
  14932. return {
  14933. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  14934. uiGridEditService.initializeGrid(uiGridCtrl.grid);
  14935. },
  14936. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  14937. }
  14938. };
  14939. }
  14940. };
  14941. }]);
  14942. /**
  14943. * @ngdoc directive
  14944. * @name ui.grid.edit.directive:uiGridRenderContainer
  14945. * @element div
  14946. * @restrict A
  14947. *
  14948. * @description Adds keydown listeners to renderContainer element so we can capture when to begin edits
  14949. *
  14950. */
  14951. module.directive('uiGridViewport', [ 'uiGridEditConstants',
  14952. function ( uiGridEditConstants) {
  14953. return {
  14954. replace: true,
  14955. priority: -99998, //run before cellNav
  14956. require: ['^uiGrid', '^uiGridRenderContainer'],
  14957. scope: false,
  14958. compile: function () {
  14959. return {
  14960. post: function ($scope, $elm, $attrs, controllers) {
  14961. var uiGridCtrl = controllers[0];
  14962. // Skip attaching if edit and cellNav is not enabled
  14963. if (!uiGridCtrl.grid.api.edit || !uiGridCtrl.grid.api.cellNav) { return; }
  14964. var containerId = controllers[1].containerId;
  14965. //no need to process for other containers
  14966. if (containerId !== 'body') {
  14967. return;
  14968. }
  14969. //refocus on the grid
  14970. $scope.$on(uiGridEditConstants.events.CANCEL_CELL_EDIT, function () {
  14971. uiGridCtrl.focus();
  14972. });
  14973. $scope.$on(uiGridEditConstants.events.END_CELL_EDIT, function () {
  14974. uiGridCtrl.focus();
  14975. });
  14976. }
  14977. };
  14978. }
  14979. };
  14980. }]);
  14981. /**
  14982. * @ngdoc directive
  14983. * @name ui.grid.edit.directive:uiGridCell
  14984. * @element div
  14985. * @restrict A
  14986. *
  14987. * @description Stacks on top of ui.grid.uiGridCell to provide in-line editing capabilities to the cell
  14988. * Editing Actions.
  14989. *
  14990. * Binds edit start events to the uiGridCell element. When the events fire, the gridCell element is appended
  14991. * with the columnDef.editableCellTemplate element ('cellEditor.html' by default).
  14992. *
  14993. * The editableCellTemplate should respond to uiGridEditConstants.events.BEGIN\_CELL\_EDIT angular event
  14994. * and do the initial steps needed to edit the cell (setfocus on input element, etc).
  14995. *
  14996. * When the editableCellTemplate recognizes that the editing is ended (blur event, Enter key, etc.)
  14997. * it should emit the uiGridEditConstants.events.END\_CELL\_EDIT event.
  14998. *
  14999. * If editableCellTemplate recognizes that the editing has been cancelled (esc key)
  15000. * it should emit the uiGridEditConstants.events.CANCEL\_CELL\_EDIT event. The original value
  15001. * will be set back on the model by the uiGridCell directive.
  15002. *
  15003. * Events that invoke editing:
  15004. * - dblclick
  15005. * - F2 keydown (when using cell selection)
  15006. *
  15007. * Events that end editing:
  15008. * - Dependent on the specific editableCellTemplate
  15009. * - Standards should be blur and enter keydown
  15010. *
  15011. * Events that cancel editing:
  15012. * - Dependent on the specific editableCellTemplate
  15013. * - Standards should be Esc keydown
  15014. *
  15015. * Grid Events that end editing:
  15016. * - uiGridConstants.events.GRID_SCROLL
  15017. *
  15018. */
  15019. /**
  15020. * @ngdoc object
  15021. * @name ui.grid.edit.api:GridRow
  15022. *
  15023. * @description GridRow options for edit feature, these are available to be
  15024. * set internally only, by other features
  15025. */
  15026. /**
  15027. * @ngdoc object
  15028. * @name enableCellEdit
  15029. * @propertyOf ui.grid.edit.api:GridRow
  15030. * @description enable editing on row, grouping for example might disable editing on group header rows
  15031. */
  15032. module.directive('uiGridCell',
  15033. ['$compile', '$injector', '$timeout', 'uiGridConstants', 'uiGridEditConstants', 'gridUtil', '$parse', 'uiGridEditService', '$rootScope', '$q',
  15034. function ($compile, $injector, $timeout, uiGridConstants, uiGridEditConstants, gridUtil, $parse, uiGridEditService, $rootScope, $q) {
  15035. var touchstartTimeout = 500;
  15036. if ($injector.has('uiGridCellNavService')) {
  15037. var uiGridCellNavService = $injector.get('uiGridCellNavService');
  15038. }
  15039. return {
  15040. priority: -100, // run after default uiGridCell directive
  15041. restrict: 'A',
  15042. scope: false,
  15043. require: '?^uiGrid',
  15044. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  15045. var html;
  15046. var origCellValue;
  15047. var inEdit = false;
  15048. var cellModel;
  15049. var cancelTouchstartTimeout;
  15050. var editCellScope;
  15051. if (!$scope.col.colDef.enableCellEdit) {
  15052. return;
  15053. }
  15054. var cellNavNavigateDereg = function() {};
  15055. var viewPortKeyDownDereg = function() {};
  15056. var setEditable = function() {
  15057. if ($scope.col.colDef.enableCellEdit && $scope.row.enableCellEdit !== false) {
  15058. if (!$scope.beginEditEventsWired) { //prevent multiple attachments
  15059. registerBeginEditEvents();
  15060. }
  15061. } else {
  15062. if ($scope.beginEditEventsWired) {
  15063. cancelBeginEditEvents();
  15064. }
  15065. }
  15066. };
  15067. setEditable();
  15068. var rowWatchDereg = $scope.$watch('row', function (n, o) {
  15069. if (n !== o) {
  15070. setEditable();
  15071. }
  15072. });
  15073. $scope.$on('$destroy', function destroyEvents() {
  15074. rowWatchDereg();
  15075. // unbind all jquery events in order to avoid memory leaks
  15076. $elm.off();
  15077. });
  15078. function registerBeginEditEvents() {
  15079. $elm.on('dblclick', beginEdit);
  15080. // Add touchstart handling. If the users starts a touch and it doesn't end after X milliseconds, then start the edit
  15081. $elm.on('touchstart', touchStart);
  15082. if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) {
  15083. viewPortKeyDownDereg = uiGridCtrl.grid.api.cellNav.on.viewPortKeyDown($scope, function (evt, rowCol) {
  15084. if (rowCol === null) {
  15085. return;
  15086. }
  15087. if (rowCol.row === $scope.row && rowCol.col === $scope.col && !$scope.col.colDef.enableCellEditOnFocus) {
  15088. //important to do this before scrollToIfNecessary
  15089. beginEditKeyDown(evt);
  15090. }
  15091. });
  15092. cellNavNavigateDereg = uiGridCtrl.grid.api.cellNav.on.navigate($scope, function (newRowCol, oldRowCol, evt) {
  15093. if ($scope.col.colDef.enableCellEditOnFocus) {
  15094. // Don't begin edit if the cell hasn't changed
  15095. if (newRowCol.row === $scope.row && newRowCol.col === $scope.col &&
  15096. (!evt || (evt && (evt.type === 'click' || evt.type === 'keydown')))) {
  15097. $timeout(function() {
  15098. beginEdit(evt);
  15099. });
  15100. }
  15101. }
  15102. });
  15103. }
  15104. $scope.beginEditEventsWired = true;
  15105. }
  15106. function touchStart(event) {
  15107. // jQuery masks events
  15108. if (typeof(event.originalEvent) !== 'undefined' && event.originalEvent !== undefined) {
  15109. event = event.originalEvent;
  15110. }
  15111. // Bind touchend handler
  15112. $elm.on('touchend', touchEnd);
  15113. // Start a timeout
  15114. cancelTouchstartTimeout = $timeout(function() { }, touchstartTimeout);
  15115. // Timeout's done! Start the edit
  15116. cancelTouchstartTimeout.then(function () {
  15117. // Use setTimeout to start the edit because beginEdit expects to be outside of $digest
  15118. setTimeout(beginEdit, 0);
  15119. // Undbind the touchend handler, we don't need it anymore
  15120. $elm.off('touchend', touchEnd);
  15121. });
  15122. }
  15123. // Cancel any touchstart timeout
  15124. function touchEnd(event) {
  15125. $timeout.cancel(cancelTouchstartTimeout);
  15126. $elm.off('touchend', touchEnd);
  15127. }
  15128. function cancelBeginEditEvents() {
  15129. $elm.off('dblclick', beginEdit);
  15130. $elm.off('keydown', beginEditKeyDown);
  15131. $elm.off('touchstart', touchStart);
  15132. cellNavNavigateDereg();
  15133. viewPortKeyDownDereg();
  15134. $scope.beginEditEventsWired = false;
  15135. }
  15136. function beginEditKeyDown(evt) {
  15137. if (uiGridEditService.isStartEditKey(evt)) {
  15138. beginEdit(evt);
  15139. }
  15140. }
  15141. function shouldEdit(col, row, triggerEvent) {
  15142. return !row.isSaving &&
  15143. ( angular.isFunction(col.colDef.cellEditableCondition) ?
  15144. col.colDef.cellEditableCondition($scope, triggerEvent) :
  15145. col.colDef.cellEditableCondition );
  15146. }
  15147. function beginEdit(triggerEvent) {
  15148. //we need to scroll the cell into focus before invoking the editor
  15149. $scope.grid.api.core.scrollToIfNecessary($scope.row, $scope.col)
  15150. .then(function () {
  15151. beginEditAfterScroll(triggerEvent);
  15152. });
  15153. }
  15154. /**
  15155. * @ngdoc property
  15156. * @name editDropdownOptionsArray
  15157. * @propertyOf ui.grid.edit.api:ColumnDef
  15158. * @description an array of values in the format
  15159. * [ {id: xxx, value: xxx} ], which is populated
  15160. * into the edit dropdown
  15161. *
  15162. */
  15163. /**
  15164. * @ngdoc property
  15165. * @name editDropdownIdLabel
  15166. * @propertyOf ui.grid.edit.api:ColumnDef
  15167. * @description the label for the "id" field
  15168. * in the editDropdownOptionsArray. Defaults
  15169. * to 'id'
  15170. * @example
  15171. * <pre>
  15172. * $scope.gridOptions = {
  15173. * columnDefs: [
  15174. * {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
  15175. * editDropdownOptionsArray: [{code: 1, status: 'active'}, {code: 2, status: 'inactive'}],
  15176. * editDropdownIdLabel: 'code', editDropdownValueLabel: 'status' }
  15177. * ],
  15178. * </pre>
  15179. *
  15180. */
  15181. /**
  15182. * @ngdoc property
  15183. * @name editDropdownRowEntityOptionsArrayPath
  15184. * @propertyOf ui.grid.edit.api:ColumnDef
  15185. * @description a path to a property on row.entity containing an
  15186. * array of values in the format
  15187. * [ {id: xxx, value: xxx} ], which will be used to populate
  15188. * the edit dropdown. This can be used when the dropdown values are dependent on
  15189. * the backing row entity.
  15190. * If this property is set then editDropdownOptionsArray will be ignored.
  15191. * @example
  15192. * <pre>
  15193. * $scope.gridOptions = {
  15194. * columnDefs: [
  15195. * {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
  15196. * editDropdownRowEntityOptionsArrayPath: 'foo.bars[0].baz',
  15197. * editDropdownIdLabel: 'code', editDropdownValueLabel: 'status' }
  15198. * ],
  15199. * </pre>
  15200. *
  15201. */
  15202. /**
  15203. * @ngdoc service
  15204. * @name editDropdownOptionsFunction
  15205. * @methodOf ui.grid.edit.api:ColumnDef
  15206. * @description a function returning an array of values in the format
  15207. * [ {id: xxx, value: xxx} ], which will be used to populate
  15208. * the edit dropdown. This can be used when the dropdown values are dependent on
  15209. * the backing row entity with some kind of algorithm.
  15210. * If this property is set then both editDropdownOptionsArray and
  15211. * editDropdownRowEntityOptionsArrayPath will be ignored.
  15212. * @param {object} rowEntity the options.data element that the returned array refers to
  15213. * @param {object} colDef the column that implements this dropdown
  15214. * @returns {object} an array of values in the format
  15215. * [ {id: xxx, value: xxx} ] used to populate the edit dropdown
  15216. * @example
  15217. * <pre>
  15218. * $scope.gridOptions = {
  15219. * columnDefs: [
  15220. * {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
  15221. * editDropdownOptionsFunction: function(rowEntity, colDef) {
  15222. * if (rowEntity.foo === 'bar') {
  15223. * return [{id: 'bar1', value: 'BAR 1'},
  15224. * {id: 'bar2', value: 'BAR 2'},
  15225. * {id: 'bar3', value: 'BAR 3'}];
  15226. * } else {
  15227. * return [{id: 'foo1', value: 'FOO 1'},
  15228. * {id: 'foo2', value: 'FOO 2'}];
  15229. * }
  15230. * },
  15231. * editDropdownIdLabel: 'code', editDropdownValueLabel: 'status' }
  15232. * ],
  15233. * </pre>
  15234. *
  15235. */
  15236. /**
  15237. * @ngdoc property
  15238. * @name editDropdownValueLabel
  15239. * @propertyOf ui.grid.edit.api:ColumnDef
  15240. * @description the label for the "value" field
  15241. * in the editDropdownOptionsArray. Defaults
  15242. * to 'value'
  15243. * @example
  15244. * <pre>
  15245. * $scope.gridOptions = {
  15246. * columnDefs: [
  15247. * {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
  15248. * editDropdownOptionsArray: [{code: 1, status: 'active'}, {code: 2, status: 'inactive'}],
  15249. * editDropdownIdLabel: 'code', editDropdownValueLabel: 'status' }
  15250. * ],
  15251. * </pre>
  15252. *
  15253. */
  15254. /**
  15255. * @ngdoc property
  15256. * @name editDropdownFilter
  15257. * @propertyOf ui.grid.edit.api:ColumnDef
  15258. * @description A filter that you would like to apply to the values in the options list
  15259. * of the dropdown. For example if you were using angular-translate you might set this
  15260. * to `'translate'`
  15261. * @example
  15262. * <pre>
  15263. * $scope.gridOptions = {
  15264. * columnDefs: [
  15265. * {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
  15266. * editDropdownOptionsArray: [{code: 1, status: 'active'}, {code: 2, status: 'inactive'}],
  15267. * editDropdownIdLabel: 'code', editDropdownValueLabel: 'status', editDropdownFilter: 'translate' }
  15268. * ],
  15269. * </pre>
  15270. *
  15271. */
  15272. function beginEditAfterScroll(triggerEvent) {
  15273. // If we are already editing, then just skip this so we don't try editing twice...
  15274. if (inEdit) {
  15275. return;
  15276. }
  15277. if (!shouldEdit($scope.col, $scope.row, triggerEvent)) {
  15278. return;
  15279. }
  15280. var modelField = $scope.row.getQualifiedColField($scope.col);
  15281. if ($scope.col.colDef.editModelField) {
  15282. modelField = gridUtil.preEval('row.entity.' + $scope.col.colDef.editModelField);
  15283. }
  15284. cellModel = $parse(modelField);
  15285. //get original value from the cell
  15286. origCellValue = cellModel($scope);
  15287. html = $scope.col.editableCellTemplate;
  15288. html = html.replace(uiGridConstants.MODEL_COL_FIELD, modelField);
  15289. html = html.replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)');
  15290. var optionFilter = $scope.col.colDef.editDropdownFilter ? '|' + $scope.col.colDef.editDropdownFilter : '';
  15291. html = html.replace(uiGridConstants.CUSTOM_FILTERS, optionFilter);
  15292. var inputType = 'text';
  15293. switch ($scope.col.colDef.type){
  15294. case 'boolean':
  15295. inputType = 'checkbox';
  15296. break;
  15297. case 'number':
  15298. inputType = 'number';
  15299. break;
  15300. case 'date':
  15301. inputType = 'date';
  15302. break;
  15303. }
  15304. html = html.replace('INPUT_TYPE', inputType);
  15305. // In order to fill dropdown options we use:
  15306. // - A function/promise or
  15307. // - An array inside of row entity if no function exists or
  15308. // - A single array for the whole column if none of the previous exists.
  15309. var editDropdownOptionsFunction = $scope.col.colDef.editDropdownOptionsFunction;
  15310. if (editDropdownOptionsFunction) {
  15311. $q.when(editDropdownOptionsFunction($scope.row.entity, $scope.col.colDef))
  15312. .then(function(result) {
  15313. $scope.editDropdownOptionsArray = result;
  15314. });
  15315. } else {
  15316. var editDropdownRowEntityOptionsArrayPath = $scope.col.colDef.editDropdownRowEntityOptionsArrayPath;
  15317. if (editDropdownRowEntityOptionsArrayPath) {
  15318. $scope.editDropdownOptionsArray = resolveObjectFromPath($scope.row.entity, editDropdownRowEntityOptionsArrayPath);
  15319. }
  15320. else {
  15321. $scope.editDropdownOptionsArray = $scope.col.colDef.editDropdownOptionsArray;
  15322. }
  15323. }
  15324. $scope.editDropdownIdLabel = $scope.col.colDef.editDropdownIdLabel ? $scope.col.colDef.editDropdownIdLabel : 'id';
  15325. $scope.editDropdownValueLabel = $scope.col.colDef.editDropdownValueLabel ? $scope.col.colDef.editDropdownValueLabel : 'value';
  15326. var cellElement;
  15327. var createEditor = function(){
  15328. inEdit = true;
  15329. cancelBeginEditEvents();
  15330. var cellElement = angular.element(html);
  15331. $elm.append(cellElement);
  15332. editCellScope = $scope.$new();
  15333. $compile(cellElement)(editCellScope);
  15334. var gridCellContentsEl = angular.element($elm.children()[0]);
  15335. gridCellContentsEl.addClass('ui-grid-cell-contents-hidden');
  15336. };
  15337. if (!$rootScope.$$phase) {
  15338. $scope.$apply(createEditor);
  15339. } else {
  15340. createEditor();
  15341. }
  15342. //stop editing when grid is scrolled
  15343. var deregOnGridScroll = $scope.col.grid.api.core.on.scrollBegin($scope, function () {
  15344. if ($scope.grid.disableScrolling) {
  15345. return;
  15346. }
  15347. endEdit();
  15348. $scope.grid.api.edit.raise.afterCellEdit($scope.row.entity, $scope.col.colDef, cellModel($scope), origCellValue);
  15349. deregOnGridScroll();
  15350. deregOnEndCellEdit();
  15351. deregOnCancelCellEdit();
  15352. });
  15353. //end editing
  15354. var deregOnEndCellEdit = $scope.$on(uiGridEditConstants.events.END_CELL_EDIT, function () {
  15355. endEdit();
  15356. $scope.grid.api.edit.raise.afterCellEdit($scope.row.entity, $scope.col.colDef, cellModel($scope), origCellValue);
  15357. deregOnEndCellEdit();
  15358. deregOnGridScroll();
  15359. deregOnCancelCellEdit();
  15360. });
  15361. //cancel editing
  15362. var deregOnCancelCellEdit = $scope.$on(uiGridEditConstants.events.CANCEL_CELL_EDIT, function () {
  15363. cancelEdit();
  15364. deregOnCancelCellEdit();
  15365. deregOnGridScroll();
  15366. deregOnEndCellEdit();
  15367. });
  15368. $scope.$broadcast(uiGridEditConstants.events.BEGIN_CELL_EDIT, triggerEvent);
  15369. $timeout(function () {
  15370. // execute in a timeout to give any complex editor templates a cycle to completely render
  15371. $scope.grid.api.edit.raise.beginCellEdit($scope.row.entity, $scope.col.colDef, triggerEvent);
  15372. });
  15373. }
  15374. function endEdit() {
  15375. $scope.grid.disableScrolling = false;
  15376. if (!inEdit) {
  15377. return;
  15378. }
  15379. //sometimes the events can't keep up with the keyboard and grid focus is lost, so always focus
  15380. //back to grid here. The focus call needs to be before the $destroy and removal of the control,
  15381. //otherwise ng-model-options of UpdateOn: 'blur' will not work.
  15382. if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) {
  15383. uiGridCtrl.focus();
  15384. }
  15385. var gridCellContentsEl = angular.element($elm.children()[0]);
  15386. //remove edit element
  15387. editCellScope.$destroy();
  15388. var children = $elm.children();
  15389. for (var i = 1; i < children.length; i++) {
  15390. angular.element(children[i]).remove();
  15391. }
  15392. gridCellContentsEl.removeClass('ui-grid-cell-contents-hidden');
  15393. inEdit = false;
  15394. registerBeginEditEvents();
  15395. $scope.grid.api.core.notifyDataChange( uiGridConstants.dataChange.EDIT );
  15396. }
  15397. function cancelEdit() {
  15398. $scope.grid.disableScrolling = false;
  15399. if (!inEdit) {
  15400. return;
  15401. }
  15402. cellModel.assign($scope, origCellValue);
  15403. $scope.$apply();
  15404. $scope.grid.api.edit.raise.cancelCellEdit($scope.row.entity, $scope.col.colDef);
  15405. endEdit();
  15406. }
  15407. // resolves a string path against the given object
  15408. // shamelessly borrowed from
  15409. // http://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key
  15410. function resolveObjectFromPath(object, path) {
  15411. path = path.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
  15412. path = path.replace(/^\./, ''); // strip a leading dot
  15413. var a = path.split('.');
  15414. while (a.length) {
  15415. var n = a.shift();
  15416. if (n in object) {
  15417. object = object[n];
  15418. } else {
  15419. return;
  15420. }
  15421. }
  15422. return object;
  15423. }
  15424. }
  15425. };
  15426. }]);
  15427. /**
  15428. * @ngdoc directive
  15429. * @name ui.grid.edit.directive:uiGridEditor
  15430. * @element div
  15431. * @restrict A
  15432. *
  15433. * @description input editor directive for editable fields.
  15434. * Provides EndEdit and CancelEdit events
  15435. *
  15436. * Events that end editing:
  15437. * blur and enter keydown
  15438. *
  15439. * Events that cancel editing:
  15440. * - Esc keydown
  15441. *
  15442. */
  15443. module.directive('uiGridEditor',
  15444. ['gridUtil', 'uiGridConstants', 'uiGridEditConstants','$timeout', 'uiGridEditService',
  15445. function (gridUtil, uiGridConstants, uiGridEditConstants, $timeout, uiGridEditService) {
  15446. return {
  15447. scope: true,
  15448. require: ['?^uiGrid', '?^uiGridRenderContainer', 'ngModel'],
  15449. compile: function () {
  15450. return {
  15451. pre: function ($scope, $elm, $attrs) {
  15452. },
  15453. post: function ($scope, $elm, $attrs, controllers) {
  15454. var uiGridCtrl, renderContainerCtrl, ngModel;
  15455. if (controllers[0]) { uiGridCtrl = controllers[0]; }
  15456. if (controllers[1]) { renderContainerCtrl = controllers[1]; }
  15457. if (controllers[2]) { ngModel = controllers[2]; }
  15458. //set focus at start of edit
  15459. $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function (evt,triggerEvent) {
  15460. // must be in a timeout since it requires a new digest cycle
  15461. $timeout(function () {
  15462. $elm[0].focus();
  15463. //only select text if it is not being replaced below in the cellNav viewPortKeyPress
  15464. if ($elm[0].select && ($scope.col.colDef.enableCellEditOnFocus || !(uiGridCtrl && uiGridCtrl.grid.api.cellNav))) {
  15465. $elm[0].select();
  15466. }
  15467. else {
  15468. //some browsers (Chrome) stupidly, imo, support the w3 standard that number, email, ...
  15469. //fields should not allow setSelectionRange. We ignore the error for those browsers
  15470. //https://www.w3.org/Bugs/Public/show_bug.cgi?id=24796
  15471. try {
  15472. $elm[0].setSelectionRange($elm[0].value.length, $elm[0].value.length);
  15473. }
  15474. catch (ex) {
  15475. //ignore
  15476. }
  15477. }
  15478. });
  15479. //set the keystroke that started the edit event
  15480. //we must do this because the BeginEdit is done in a different event loop than the intitial
  15481. //keydown event
  15482. //fire this event for the keypress that is received
  15483. if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) {
  15484. var viewPortKeyDownUnregister = uiGridCtrl.grid.api.cellNav.on.viewPortKeyPress($scope, function (evt, rowCol) {
  15485. if (uiGridEditService.isStartEditKey(evt)) {
  15486. var code = typeof evt.which === 'number' ? evt.which : evt.keyCode;
  15487. if (code > 0) {
  15488. ngModel.$setViewValue(String.fromCharCode(code), evt);
  15489. ngModel.$render();
  15490. }
  15491. }
  15492. viewPortKeyDownUnregister();
  15493. });
  15494. }
  15495. // macOS will blur the checkbox when clicked in Safari and Firefox,
  15496. // to get around this, we disable the blur handler on mousedown,
  15497. // and then focus the checkbox and re-enable the blur handler after $timeout
  15498. $elm.on('mousedown', function(evt) {
  15499. if ($elm[0].type === 'checkbox') {
  15500. $elm.off('blur', $scope.stopEdit);
  15501. $timeout(function() {
  15502. $elm[0].focus();
  15503. $elm.on('blur', $scope.stopEdit);
  15504. });
  15505. }
  15506. });
  15507. $elm.on('blur', $scope.stopEdit);
  15508. });
  15509. $scope.deepEdit = false;
  15510. $scope.stopEdit = function (evt) {
  15511. if ($scope.inputForm && !$scope.inputForm.$valid) {
  15512. evt.stopPropagation();
  15513. $scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
  15514. }
  15515. else {
  15516. $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
  15517. }
  15518. $scope.deepEdit = false;
  15519. };
  15520. $elm.on('click', function (evt) {
  15521. if ($elm[0].type !== 'checkbox') {
  15522. $scope.deepEdit = true;
  15523. $scope.$applyAsync(function () {
  15524. $scope.grid.disableScrolling = true;
  15525. });
  15526. }
  15527. });
  15528. $elm.on('keydown', function (evt) {
  15529. switch (evt.keyCode) {
  15530. case uiGridConstants.keymap.ESC:
  15531. evt.stopPropagation();
  15532. $scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
  15533. break;
  15534. }
  15535. if ($scope.deepEdit &&
  15536. (evt.keyCode === uiGridConstants.keymap.LEFT ||
  15537. evt.keyCode === uiGridConstants.keymap.RIGHT ||
  15538. evt.keyCode === uiGridConstants.keymap.UP ||
  15539. evt.keyCode === uiGridConstants.keymap.DOWN)) {
  15540. evt.stopPropagation();
  15541. }
  15542. // Pass the keydown event off to the cellNav service, if it exists
  15543. else if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) {
  15544. evt.uiGridTargetRenderContainerId = renderContainerCtrl.containerId;
  15545. if (uiGridCtrl.cellNav.handleKeyDown(evt) !== null) {
  15546. $scope.stopEdit(evt);
  15547. }
  15548. }
  15549. else {
  15550. //handle enter and tab for editing not using cellNav
  15551. switch (evt.keyCode) {
  15552. case uiGridConstants.keymap.ENTER: // Enter (Leave Field)
  15553. case uiGridConstants.keymap.TAB:
  15554. evt.stopPropagation();
  15555. evt.preventDefault();
  15556. $scope.stopEdit(evt);
  15557. break;
  15558. }
  15559. }
  15560. return true;
  15561. });
  15562. $scope.$on('$destroy', function unbindEvents() {
  15563. // unbind all jquery events in order to avoid memory leaks
  15564. $elm.off();
  15565. });
  15566. }
  15567. };
  15568. }
  15569. };
  15570. }]);
  15571. /**
  15572. * @ngdoc directive
  15573. * @name ui.grid.edit.directive:input
  15574. * @element input
  15575. * @restrict E
  15576. *
  15577. * @description directive to provide binding between input[date] value and ng-model for angular 1.2
  15578. * It is similar to input[date] directive of angular 1.3
  15579. *
  15580. * Supported date format for input is 'yyyy-MM-dd'
  15581. * The directive will set the $valid property of input element and the enclosing form to false if
  15582. * model is invalid date or value of input is entered wrong.
  15583. *
  15584. */
  15585. module.directive('uiGridEditor', ['$filter', function ($filter) {
  15586. function parseDateString(dateString) {
  15587. if (typeof(dateString) === 'undefined' || dateString === '') {
  15588. return null;
  15589. }
  15590. var parts = dateString.split('-');
  15591. if (parts.length !== 3) {
  15592. return null;
  15593. }
  15594. var year = parseInt(parts[0], 10);
  15595. var month = parseInt(parts[1], 10);
  15596. var day = parseInt(parts[2], 10);
  15597. if (month < 1 || year < 1 || day < 1) {
  15598. return null;
  15599. }
  15600. return new Date(year, (month - 1), day);
  15601. }
  15602. return {
  15603. priority: -100, // run after default uiGridEditor directive
  15604. require: '?ngModel',
  15605. link: function (scope, element, attrs, ngModel) {
  15606. if (angular.version.minor === 2 && attrs.type && attrs.type === 'date' && ngModel) {
  15607. ngModel.$formatters.push(function (modelValue) {
  15608. ngModel.$setValidity(null,(!modelValue || !isNaN(modelValue.getTime())));
  15609. return $filter('date')(modelValue, 'yyyy-MM-dd');
  15610. });
  15611. ngModel.$parsers.push(function (viewValue) {
  15612. if (viewValue && viewValue.length > 0) {
  15613. var dateValue = parseDateString(viewValue);
  15614. ngModel.$setValidity(null, (dateValue && !isNaN(dateValue.getTime())));
  15615. return dateValue;
  15616. }
  15617. else {
  15618. ngModel.$setValidity(null, true);
  15619. return null;
  15620. }
  15621. });
  15622. }
  15623. }
  15624. };
  15625. }]);
  15626. /**
  15627. * @ngdoc directive
  15628. * @name ui.grid.edit.directive:uiGridEditDropdown
  15629. * @element div
  15630. * @restrict A
  15631. *
  15632. * @description dropdown editor for editable fields.
  15633. * Provides EndEdit and CancelEdit events
  15634. *
  15635. * Events that end editing:
  15636. * blur and enter keydown, and any left/right nav
  15637. *
  15638. * Events that cancel editing:
  15639. * - Esc keydown
  15640. *
  15641. */
  15642. module.directive('uiGridEditDropdown',
  15643. ['uiGridConstants', 'uiGridEditConstants', '$timeout',
  15644. function (uiGridConstants, uiGridEditConstants, $timeout) {
  15645. return {
  15646. require: ['?^uiGrid', '?^uiGridRenderContainer'],
  15647. scope: true,
  15648. compile: function () {
  15649. return {
  15650. pre: function ($scope, $elm, $attrs) {
  15651. },
  15652. post: function ($scope, $elm, $attrs, controllers) {
  15653. var uiGridCtrl = controllers[0];
  15654. var renderContainerCtrl = controllers[1];
  15655. //set focus at start of edit
  15656. $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () {
  15657. $timeout(function(){
  15658. $elm[0].focus();
  15659. });
  15660. $elm[0].style.width = ($elm[0].parentElement.offsetWidth - 1) + 'px';
  15661. $elm.on('blur', function (evt) {
  15662. $scope.stopEdit(evt);
  15663. });
  15664. });
  15665. $scope.stopEdit = function (evt) {
  15666. // no need to validate a dropdown - invalid values shouldn't be
  15667. // available in the list
  15668. $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
  15669. };
  15670. $elm.on('keydown', function (evt) {
  15671. switch (evt.keyCode) {
  15672. case uiGridConstants.keymap.ESC:
  15673. evt.stopPropagation();
  15674. $scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
  15675. break;
  15676. }
  15677. if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) {
  15678. evt.uiGridTargetRenderContainerId = renderContainerCtrl.containerId;
  15679. if (uiGridCtrl.cellNav.handleKeyDown(evt) !== null) {
  15680. $scope.stopEdit(evt);
  15681. }
  15682. }
  15683. else {
  15684. //handle enter and tab for editing not using cellNav
  15685. switch (evt.keyCode) {
  15686. case uiGridConstants.keymap.ENTER: // Enter (Leave Field)
  15687. case uiGridConstants.keymap.TAB:
  15688. evt.stopPropagation();
  15689. evt.preventDefault();
  15690. $scope.stopEdit(evt);
  15691. break;
  15692. }
  15693. }
  15694. return true;
  15695. });
  15696. $scope.$on('$destroy', function unbindEvents() {
  15697. // unbind jquery events to prevent memory leaks
  15698. $elm.off();
  15699. });
  15700. }
  15701. };
  15702. }
  15703. };
  15704. }]);
  15705. /**
  15706. * @ngdoc directive
  15707. * @name ui.grid.edit.directive:uiGridEditFileChooser
  15708. * @element div
  15709. * @restrict A
  15710. *
  15711. * @description input editor directive for editable fields.
  15712. * Provides EndEdit and CancelEdit events
  15713. *
  15714. * Events that end editing:
  15715. * blur and enter keydown
  15716. *
  15717. * Events that cancel editing:
  15718. * - Esc keydown
  15719. *
  15720. */
  15721. module.directive('uiGridEditFileChooser',
  15722. ['gridUtil', 'uiGridConstants', 'uiGridEditConstants',
  15723. function (gridUtil, uiGridConstants, uiGridEditConstants) {
  15724. return {
  15725. scope: true,
  15726. require: ['?^uiGrid', '?^uiGridRenderContainer'],
  15727. compile: function () {
  15728. return {
  15729. pre: function ($scope, $elm, $attrs) {
  15730. },
  15731. post: function ($scope, $elm) {
  15732. function handleFileSelect(event) {
  15733. var target = event.srcElement || event.target;
  15734. if (target && target.files && target.files.length > 0) {
  15735. /**
  15736. * @ngdoc property
  15737. * @name editFileChooserCallback
  15738. * @propertyOf ui.grid.edit.api:ColumnDef
  15739. * @description A function that should be called when any files have been chosen
  15740. * by the user. You should use this to process the files appropriately for your
  15741. * application.
  15742. *
  15743. * It passes the gridCol, the gridRow (from which you can get gridRow.entity),
  15744. * and the files. The files are in the format as returned from the file chooser,
  15745. * an array of files, with each having useful information such as:
  15746. * - `files[0].lastModifiedDate`
  15747. * - `files[0].name`
  15748. * - `files[0].size` (appears to be in bytes)
  15749. * - `files[0].type` (MIME type by the looks)
  15750. *
  15751. * Typically you would do something with these files - most commonly you would
  15752. * use the filename or read the file itself in. The example function does both.
  15753. *
  15754. * @example
  15755. * <pre>
  15756. * editFileChooserCallBack: function(gridRow, gridCol, files ){
  15757. * // ignore all but the first file, it can only choose one anyway
  15758. * // set the filename into this column
  15759. * gridRow.entity.filename = file[0].name;
  15760. *
  15761. * // read the file and set it into a hidden column, which we may do stuff with later
  15762. * var setFile = function(fileContent){
  15763. * gridRow.entity.file = fileContent.currentTarget.result;
  15764. * };
  15765. * var reader = new FileReader();
  15766. * reader.onload = setFile;
  15767. * reader.readAsText( files[0] );
  15768. * }
  15769. * </pre>
  15770. */
  15771. if ( typeof($scope.col.colDef.editFileChooserCallback) === 'function' ) {
  15772. $scope.col.colDef.editFileChooserCallback($scope.row, $scope.col, target.files);
  15773. } else {
  15774. gridUtil.logError('You need to set colDef.editFileChooserCallback to use the file chooser');
  15775. }
  15776. target.form.reset();
  15777. $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
  15778. } else {
  15779. $scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
  15780. }
  15781. $elm[0].removeEventListener('change', handleFileSelect, false);
  15782. }
  15783. $elm[0].addEventListener('change', handleFileSelect, false);
  15784. $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () {
  15785. $elm[0].focus();
  15786. $elm[0].select();
  15787. $elm.on('blur', function () {
  15788. $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
  15789. $elm.off();
  15790. });
  15791. });
  15792. }
  15793. };
  15794. }
  15795. };
  15796. }]);
  15797. })();
  15798. (function () {
  15799. 'use strict';
  15800. /**
  15801. * @ngdoc overview
  15802. * @name ui.grid.emptyBaseLayer
  15803. * @description
  15804. *
  15805. * # ui.grid.emptyBaseLayer
  15806. *
  15807. * <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>
  15808. *
  15809. * This module provides the ability to have the background of the ui-grid be empty rows, this would be displayed in the case were
  15810. * the grid height is greater then the amount of rows displayed.
  15811. *
  15812. * <div doc-module-components="ui.grid.emptyBaseLayer"></div>
  15813. */
  15814. var module = angular.module('ui.grid.emptyBaseLayer', ['ui.grid']);
  15815. /**
  15816. * @ngdoc service
  15817. * @name ui.grid.emptyBaseLayer.service:uiGridBaseLayerService
  15818. *
  15819. * @description Services for the empty base layer grid
  15820. */
  15821. module.service('uiGridBaseLayerService', ['gridUtil', '$compile', function (gridUtil, $compile) {
  15822. var service = {
  15823. initializeGrid: function (grid, disableEmptyBaseLayer) {
  15824. /**
  15825. * @ngdoc object
  15826. * @name ui.grid.emptyBaseLayer.api:GridOptions
  15827. *
  15828. * @description GridOptions for emptyBaseLayer feature, these are available to be
  15829. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  15830. */
  15831. grid.baseLayer = {
  15832. emptyRows: []
  15833. };
  15834. /**
  15835. * @ngdoc object
  15836. * @name enableEmptyGridBaseLayer
  15837. * @propertyOf ui.grid.emptyBaseLayer.api:GridOptions
  15838. * @description Enable empty base layer, which shows empty rows as background on the entire grid
  15839. * <br/>Defaults to true, if the directive is used.
  15840. * <br/>Set to false either by setting this attribute or passing false to the directive.
  15841. */
  15842. //default option to true unless it was explicitly set to false
  15843. if (grid.options.enableEmptyGridBaseLayer !== false) {
  15844. grid.options.enableEmptyGridBaseLayer = !disableEmptyBaseLayer;
  15845. }
  15846. },
  15847. setNumberOfEmptyRows: function(viewportHeight, grid) {
  15848. var rowHeight = grid.options.rowHeight,
  15849. rows = Math.ceil(viewportHeight / rowHeight);
  15850. if (rows > 0) {
  15851. grid.baseLayer.emptyRows = [];
  15852. for (var i = 0; i < rows; i++) {
  15853. grid.baseLayer.emptyRows.push({});
  15854. }
  15855. }
  15856. }
  15857. };
  15858. return service;
  15859. }]);
  15860. /**
  15861. * @ngdoc object
  15862. * @name ui.grid.emptyBaseLayer.directive:uiGridEmptyBaseLayer
  15863. * @description Shows empty rows in the background of the ui-grid, these span
  15864. * the full height of the ui-grid, so that there won't be blank space below the shown rows.
  15865. * @example
  15866. * <pre>
  15867. * <div ui-grid="gridOptions" class="grid" ui-grid-empty-base-layer></div>
  15868. * </pre>
  15869. * Or you can enable/disable it dynamically by passing in true or false. It doesn't
  15870. * the value, so it would only be set on initial render.
  15871. * <pre>
  15872. * <div ui-grid="gridOptions" class="grid" ui-grid-empty-base-layer="false"></div>
  15873. * </pre>
  15874. */
  15875. module.directive('uiGridEmptyBaseLayer', ['gridUtil', 'uiGridBaseLayerService',
  15876. '$parse',
  15877. function (gridUtil, uiGridBaseLayerService, $parse) {
  15878. return {
  15879. require: '^uiGrid',
  15880. scope: false,
  15881. compile: function ($elm, $attrs) {
  15882. return {
  15883. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  15884. var disableEmptyBaseLayer = $parse($attrs.uiGridEmptyBaseLayer)($scope) === false;
  15885. uiGridBaseLayerService.initializeGrid(uiGridCtrl.grid, disableEmptyBaseLayer);
  15886. },
  15887. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  15888. if (!uiGridCtrl.grid.options.enableEmptyGridBaseLayer) {
  15889. return;
  15890. }
  15891. var renderBodyContainer = uiGridCtrl.grid.renderContainers.body,
  15892. viewportHeight = renderBodyContainer.getViewportHeight();
  15893. function heightHasChanged() {
  15894. var newViewPortHeight = renderBodyContainer.getViewportHeight();
  15895. if (newViewPortHeight !== viewportHeight) {
  15896. viewportHeight = newViewPortHeight;
  15897. return true;
  15898. }
  15899. return false;
  15900. }
  15901. function getEmptyBaseLayerCss(viewportHeight) {
  15902. // Set ui-grid-empty-base-layer height
  15903. return '.grid' + uiGridCtrl.grid.id +
  15904. ' .ui-grid-render-container ' +
  15905. '.ui-grid-empty-base-layer-container.ui-grid-canvas ' +
  15906. '{ height: ' + viewportHeight + 'px; }';
  15907. }
  15908. uiGridCtrl.grid.registerStyleComputation({
  15909. func: function() {
  15910. if (heightHasChanged()) {
  15911. uiGridBaseLayerService.setNumberOfEmptyRows(viewportHeight, uiGridCtrl.grid);
  15912. }
  15913. return getEmptyBaseLayerCss(viewportHeight);
  15914. }
  15915. });
  15916. }
  15917. };
  15918. }
  15919. };
  15920. }]);
  15921. /**
  15922. * @ngdoc directive
  15923. * @name ui.grid.emptyBaseLayer.directive:uiGridViewport
  15924. * @description stacks on the uiGridViewport directive to append the empty grid base layer html elements to the
  15925. * default gridRow template
  15926. */
  15927. module.directive('uiGridViewport',
  15928. ['$compile', 'gridUtil', '$templateCache',
  15929. function ($compile, gridUtil, $templateCache) {
  15930. return {
  15931. priority: -200,
  15932. scope: false,
  15933. compile: function ($elm, $attrs) {
  15934. var emptyBaseLayerContainer = $templateCache.get('ui-grid/emptyBaseLayerContainer');
  15935. $elm.prepend(emptyBaseLayerContainer);
  15936. return {
  15937. pre: function ($scope, $elm, $attrs, controllers) {
  15938. },
  15939. post: function ($scope, $elm, $attrs, controllers) {
  15940. }
  15941. };
  15942. }
  15943. };
  15944. }]);
  15945. })();
  15946. (function () {
  15947. 'use strict';
  15948. /**
  15949. * @ngdoc overview
  15950. * @name ui.grid.expandable
  15951. * @description
  15952. *
  15953. * # ui.grid.expandable
  15954. *
  15955. * <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>
  15956. *
  15957. * This module provides the ability to create subgrids with the ability to expand a row
  15958. * to show the subgrid.
  15959. *
  15960. * <div doc-module-components="ui.grid.expandable"></div>
  15961. */
  15962. var module = angular.module('ui.grid.expandable', ['ui.grid']);
  15963. /**
  15964. * @ngdoc service
  15965. * @name ui.grid.expandable.service:uiGridExpandableService
  15966. *
  15967. * @description Services for the expandable grid
  15968. */
  15969. module.service('uiGridExpandableService', ['gridUtil', '$compile', function (gridUtil, $compile) {
  15970. var service = {
  15971. initializeGrid: function (grid) {
  15972. grid.expandable = {};
  15973. grid.expandable.expandedAll = false;
  15974. /**
  15975. * @ngdoc object
  15976. * @name enableExpandable
  15977. * @propertyOf ui.grid.expandable.api:GridOptions
  15978. * @description Whether or not to use expandable feature, allows you to turn off expandable on specific grids
  15979. * within your application, or in specific modes on _this_ grid. Defaults to true.
  15980. * @example
  15981. * <pre>
  15982. * $scope.gridOptions = {
  15983. * enableExpandable: false
  15984. * }
  15985. * </pre>
  15986. */
  15987. grid.options.enableExpandable = grid.options.enableExpandable !== false;
  15988. /**
  15989. * @ngdoc object
  15990. * @name showExpandAllButton
  15991. * @propertyOf ui.grid.expandable.api:GridOptions
  15992. * @description Whether or not to display the expand all button, allows you to hide expand all button on specific grids
  15993. * within your application, or in specific modes on _this_ grid. Defaults to true.
  15994. * @example
  15995. * <pre>
  15996. * $scope.gridOptions = {
  15997. * showExpandAllButton: false
  15998. * }
  15999. * </pre>
  16000. */
  16001. grid.options.showExpandAllButton = grid.options.showExpandAllButton !== false;
  16002. /**
  16003. * @ngdoc object
  16004. * @name expandableRowHeight
  16005. * @propertyOf ui.grid.expandable.api:GridOptions
  16006. * @description Height in pixels of the expanded subgrid. Defaults to
  16007. * 150
  16008. * @example
  16009. * <pre>
  16010. * $scope.gridOptions = {
  16011. * expandableRowHeight: 150
  16012. * }
  16013. * </pre>
  16014. */
  16015. grid.options.expandableRowHeight = grid.options.expandableRowHeight || 150;
  16016. /**
  16017. * @ngdoc object
  16018. * @name expandableRowHeaderWidth
  16019. * @propertyOf ui.grid.expandable.api:GridOptions
  16020. * @description Width in pixels of the expandable column. Defaults to 40
  16021. * @example
  16022. * <pre>
  16023. * $scope.gridOptions = {
  16024. * expandableRowHeaderWidth: 40
  16025. * }
  16026. * </pre>
  16027. */
  16028. grid.options.expandableRowHeaderWidth = grid.options.expandableRowHeaderWidth || 40;
  16029. /**
  16030. * @ngdoc object
  16031. * @name expandableRowTemplate
  16032. * @propertyOf ui.grid.expandable.api:GridOptions
  16033. * @description Mandatory. The template for your expanded row
  16034. * @example
  16035. * <pre>
  16036. * $scope.gridOptions = {
  16037. * expandableRowTemplate: 'expandableRowTemplate.html'
  16038. * }
  16039. * </pre>
  16040. */
  16041. if ( grid.options.enableExpandable && !grid.options.expandableRowTemplate ){
  16042. gridUtil.logError( 'You have not set the expandableRowTemplate, disabling expandable module' );
  16043. grid.options.enableExpandable = false;
  16044. }
  16045. /**
  16046. * @ngdoc object
  16047. * @name ui.grid.expandable.api:PublicApi
  16048. *
  16049. * @description Public Api for expandable feature
  16050. */
  16051. /**
  16052. * @ngdoc object
  16053. * @name ui.grid.expandable.api:GridRow
  16054. *
  16055. * @description Additional properties added to GridRow when using the expandable module
  16056. */
  16057. /**
  16058. * @ngdoc object
  16059. * @name ui.grid.expandable.api:GridOptions
  16060. *
  16061. * @description Options for configuring the expandable feature, these are available to be
  16062. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  16063. */
  16064. var publicApi = {
  16065. events: {
  16066. expandable: {
  16067. /**
  16068. * @ngdoc event
  16069. * @name rowExpandedBeforeStateChanged
  16070. * @eventOf ui.grid.expandable.api:PublicApi
  16071. * @description raised when row is expanding or collapsing
  16072. * <pre>
  16073. * gridApi.expandable.on.rowExpandedBeforeStateChanged(scope,function(row){})
  16074. * </pre>
  16075. * @param {scope} scope the application scope
  16076. * @param {GridRow} row the row that was expanded
  16077. */
  16078. rowExpandedBeforeStateChanged: function(scope, row){
  16079. },
  16080. /**
  16081. * @ngdoc event
  16082. * @name rowExpandedStateChanged
  16083. * @eventOf ui.grid.expandable.api:PublicApi
  16084. * @description raised when row expanded or collapsed
  16085. * <pre>
  16086. * gridApi.expandable.on.rowExpandedStateChanged(scope,function(row){})
  16087. * </pre>
  16088. * @param {scope} scope the application scope
  16089. * @param {GridRow} row the row that was expanded
  16090. */
  16091. rowExpandedStateChanged: function (scope, row) {
  16092. }
  16093. }
  16094. },
  16095. methods: {
  16096. expandable: {
  16097. /**
  16098. * @ngdoc method
  16099. * @name toggleRowExpansion
  16100. * @methodOf ui.grid.expandable.api:PublicApi
  16101. * @description Toggle a specific row
  16102. * <pre>
  16103. * gridApi.expandable.toggleRowExpansion(rowEntity);
  16104. * </pre>
  16105. * @param {object} rowEntity the data entity for the row you want to expand
  16106. */
  16107. toggleRowExpansion: function (rowEntity) {
  16108. var row = grid.getRow(rowEntity);
  16109. if (row !== null) {
  16110. service.toggleRowExpansion(grid, row);
  16111. }
  16112. },
  16113. /**
  16114. * @ngdoc method
  16115. * @name expandAllRows
  16116. * @methodOf ui.grid.expandable.api:PublicApi
  16117. * @description Expand all subgrids.
  16118. * <pre>
  16119. * gridApi.expandable.expandAllRows();
  16120. * </pre>
  16121. */
  16122. expandAllRows: function() {
  16123. service.expandAllRows(grid);
  16124. },
  16125. /**
  16126. * @ngdoc method
  16127. * @name collapseAllRows
  16128. * @methodOf ui.grid.expandable.api:PublicApi
  16129. * @description Collapse all subgrids.
  16130. * <pre>
  16131. * gridApi.expandable.collapseAllRows();
  16132. * </pre>
  16133. */
  16134. collapseAllRows: function() {
  16135. service.collapseAllRows(grid);
  16136. },
  16137. /**
  16138. * @ngdoc method
  16139. * @name toggleAllRows
  16140. * @methodOf ui.grid.expandable.api:PublicApi
  16141. * @description Toggle all subgrids.
  16142. * <pre>
  16143. * gridApi.expandable.toggleAllRows();
  16144. * </pre>
  16145. */
  16146. toggleAllRows: function() {
  16147. service.toggleAllRows(grid);
  16148. },
  16149. /**
  16150. * @ngdoc function
  16151. * @name expandRow
  16152. * @methodOf ui.grid.expandable.api:PublicApi
  16153. * @description Expand the data row
  16154. * @param {object} rowEntity gridOptions.data[] array instance
  16155. */
  16156. expandRow: function (rowEntity) {
  16157. var row = grid.getRow(rowEntity);
  16158. if (row !== null && !row.isExpanded) {
  16159. service.toggleRowExpansion(grid, row);
  16160. }
  16161. },
  16162. /**
  16163. * @ngdoc function
  16164. * @name collapseRow
  16165. * @methodOf ui.grid.expandable.api:PublicApi
  16166. * @description Collapse the data row
  16167. * @param {object} rowEntity gridOptions.data[] array instance
  16168. */
  16169. collapseRow: function (rowEntity) {
  16170. var row = grid.getRow(rowEntity);
  16171. if (row !== null && row.isExpanded) {
  16172. service.toggleRowExpansion(grid, row);
  16173. }
  16174. },
  16175. /**
  16176. * @ngdoc function
  16177. * @name getExpandedRows
  16178. * @methodOf ui.grid.expandable.api:PublicApi
  16179. * @description returns all expandedRow's entity references
  16180. */
  16181. getExpandedRows: function () {
  16182. return service.getExpandedRows(grid).map(function (gridRow) {
  16183. return gridRow.entity;
  16184. });
  16185. }
  16186. }
  16187. }
  16188. };
  16189. grid.api.registerEventsFromObject(publicApi.events);
  16190. grid.api.registerMethodsFromObject(publicApi.methods);
  16191. },
  16192. toggleRowExpansion: function (grid, row) {
  16193. // trigger the "before change" event. Can change row height dynamically this way.
  16194. grid.api.expandable.raise.rowExpandedBeforeStateChanged(row);
  16195. /**
  16196. * @ngdoc object
  16197. * @name isExpanded
  16198. * @propertyOf ui.grid.expandable.api:GridRow
  16199. * @description Whether or not the row is currently expanded.
  16200. * @example
  16201. * <pre>
  16202. * $scope.api.expandable.on.rowExpandedStateChanged($scope, function (row) {
  16203. * if (row.isExpanded) {
  16204. * //...
  16205. * }
  16206. * });
  16207. * </pre>
  16208. */
  16209. row.isExpanded = !row.isExpanded;
  16210. if (angular.isUndefined(row.expandedRowHeight)){
  16211. row.expandedRowHeight = grid.options.expandableRowHeight;
  16212. }
  16213. if (row.isExpanded) {
  16214. row.height = row.grid.options.rowHeight + row.expandedRowHeight;
  16215. grid.expandable.expandedAll = service.getExpandedRows(grid).length === grid.rows.length;
  16216. } else {
  16217. row.height = row.grid.options.rowHeight;
  16218. grid.expandable.expandedAll = false;
  16219. }
  16220. grid.api.expandable.raise.rowExpandedStateChanged(row);
  16221. },
  16222. expandAllRows: function(grid) {
  16223. grid.renderContainers.body.visibleRowCache.forEach( function(row) {
  16224. if (!row.isExpanded && !(row.entity.subGridOptions && row.entity.subGridOptions.disableRowExpandable)) {
  16225. service.toggleRowExpansion(grid, row);
  16226. }
  16227. });
  16228. grid.expandable.expandedAll = true;
  16229. grid.queueGridRefresh();
  16230. },
  16231. collapseAllRows: function(grid) {
  16232. grid.renderContainers.body.visibleRowCache.forEach( function(row) {
  16233. if (row.isExpanded) {
  16234. service.toggleRowExpansion(grid, row);
  16235. }
  16236. });
  16237. grid.expandable.expandedAll = false;
  16238. grid.queueGridRefresh();
  16239. },
  16240. toggleAllRows: function(grid) {
  16241. if (grid.expandable.expandedAll) {
  16242. service.collapseAllRows(grid);
  16243. }
  16244. else {
  16245. service.expandAllRows(grid);
  16246. }
  16247. },
  16248. getExpandedRows: function (grid) {
  16249. return grid.rows.filter(function (row) {
  16250. return row.isExpanded;
  16251. });
  16252. }
  16253. };
  16254. return service;
  16255. }]);
  16256. /**
  16257. * @ngdoc object
  16258. * @name enableExpandableRowHeader
  16259. * @propertyOf ui.grid.expandable.api:GridOptions
  16260. * @description Show a rowHeader to provide the expandable buttons. If set to false then implies
  16261. * you're going to use a custom method for expanding and collapsing the subgrids. Defaults to true.
  16262. * @example
  16263. * <pre>
  16264. * $scope.gridOptions = {
  16265. * enableExpandableRowHeader: false
  16266. * }
  16267. * </pre>
  16268. */
  16269. module.directive('uiGridExpandable', ['uiGridExpandableService', '$templateCache',
  16270. function (uiGridExpandableService, $templateCache) {
  16271. return {
  16272. replace: true,
  16273. priority: 0,
  16274. require: '^uiGrid',
  16275. scope: false,
  16276. compile: function () {
  16277. return {
  16278. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  16279. uiGridExpandableService.initializeGrid(uiGridCtrl.grid);
  16280. if (!uiGridCtrl.grid.options.enableExpandable) {
  16281. return;
  16282. }
  16283. if (uiGridCtrl.grid.options.enableExpandableRowHeader !== false ) {
  16284. var expandableRowHeaderColDef = {
  16285. name: 'expandableButtons',
  16286. displayName: '',
  16287. exporterSuppressExport: true,
  16288. enableColumnResizing: false,
  16289. enableColumnMenu: false,
  16290. width: uiGridCtrl.grid.options.expandableRowHeaderWidth || 40
  16291. };
  16292. expandableRowHeaderColDef.cellTemplate = $templateCache.get('ui-grid/expandableRowHeader');
  16293. expandableRowHeaderColDef.headerCellTemplate = $templateCache.get('ui-grid/expandableTopRowHeader');
  16294. uiGridCtrl.grid.addRowHeaderColumn(expandableRowHeaderColDef, -90);
  16295. }
  16296. },
  16297. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  16298. }
  16299. };
  16300. }
  16301. };
  16302. }]);
  16303. /**
  16304. * @ngdoc directive
  16305. * @name ui.grid.expandable.directive:uiGrid
  16306. * @description stacks on the uiGrid directive to register child grid with parent row when child is created
  16307. */
  16308. module.directive('uiGrid', ['uiGridExpandableService', '$templateCache',
  16309. function (uiGridExpandableService, $templateCache) {
  16310. return {
  16311. replace: true,
  16312. priority: 599,
  16313. require: '^uiGrid',
  16314. scope: false,
  16315. compile: function () {
  16316. return {
  16317. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  16318. uiGridCtrl.grid.api.core.on.renderingComplete($scope, function() {
  16319. //if a parent grid row is on the scope, then add the parentRow property to this childGrid
  16320. if ($scope.row && $scope.row.grid && $scope.row.grid.options && $scope.row.grid.options.enableExpandable) {
  16321. /**
  16322. * @ngdoc directive
  16323. * @name ui.grid.expandable.class:Grid
  16324. * @description Additional Grid properties added by expandable module
  16325. */
  16326. /**
  16327. * @ngdoc object
  16328. * @name parentRow
  16329. * @propertyOf ui.grid.expandable.class:Grid
  16330. * @description reference to the expanded parent row that owns this grid
  16331. */
  16332. uiGridCtrl.grid.parentRow = $scope.row;
  16333. //todo: adjust height on parent row when child grid height changes. we need some sort of gridHeightChanged event
  16334. // uiGridCtrl.grid.core.on.canvasHeightChanged($scope, function(oldHeight, newHeight) {
  16335. // uiGridCtrl.grid.parentRow = newHeight;
  16336. // });
  16337. }
  16338. });
  16339. },
  16340. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  16341. }
  16342. };
  16343. }
  16344. };
  16345. }]);
  16346. /**
  16347. * @ngdoc directive
  16348. * @name ui.grid.expandable.directive:uiGridExpandableRow
  16349. * @description directive to render the expandable row template
  16350. */
  16351. module.directive('uiGridExpandableRow',
  16352. ['uiGridExpandableService', '$timeout', '$compile', 'uiGridConstants','gridUtil','$interval', '$log',
  16353. function (uiGridExpandableService, $timeout, $compile, uiGridConstants, gridUtil, $interval, $log) {
  16354. return {
  16355. replace: false,
  16356. priority: 0,
  16357. scope: false,
  16358. compile: function () {
  16359. return {
  16360. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  16361. gridUtil.getTemplate($scope.grid.options.expandableRowTemplate).then(
  16362. function (template) {
  16363. if ($scope.grid.options.expandableRowScope) {
  16364. /**
  16365. * @ngdoc object
  16366. * @name expandableRowScope
  16367. * @propertyOf ui.grid.expandable.api:GridOptions
  16368. * @description Variables of object expandableScope will be available in the scope of the expanded subgrid
  16369. * @example
  16370. * <pre>
  16371. * $scope.gridOptions = {
  16372. * expandableRowScope: expandableScope
  16373. * }
  16374. * </pre>
  16375. */
  16376. var expandableRowScope = $scope.grid.options.expandableRowScope;
  16377. for (var property in expandableRowScope) {
  16378. if (expandableRowScope.hasOwnProperty(property)) {
  16379. $scope[property] = expandableRowScope[property];
  16380. }
  16381. }
  16382. }
  16383. var expandedRowElement = angular.element(template);
  16384. $elm.append(expandedRowElement);
  16385. expandedRowElement = $compile(expandedRowElement)($scope);
  16386. $scope.row.expandedRendered = true;
  16387. });
  16388. },
  16389. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  16390. $scope.$on('$destroy', function() {
  16391. $scope.row.expandedRendered = false;
  16392. });
  16393. }
  16394. };
  16395. }
  16396. };
  16397. }]);
  16398. /**
  16399. * @ngdoc directive
  16400. * @name ui.grid.expandable.directive:uiGridRow
  16401. * @description stacks on the uiGridRow directive to add support for expandable rows
  16402. */
  16403. module.directive('uiGridRow',
  16404. ['$compile', 'gridUtil', '$templateCache',
  16405. function ($compile, gridUtil, $templateCache) {
  16406. return {
  16407. priority: -200,
  16408. scope: false,
  16409. compile: function ($elm, $attrs) {
  16410. return {
  16411. pre: function ($scope, $elm, $attrs, controllers) {
  16412. if (!$scope.grid.options.enableExpandable) {
  16413. return;
  16414. }
  16415. $scope.expandableRow = {};
  16416. $scope.expandableRow.shouldRenderExpand = function () {
  16417. var ret = $scope.colContainer.name === 'body' && $scope.grid.options.enableExpandable !== false && $scope.row.isExpanded && (!$scope.grid.isScrollingVertically || $scope.row.expandedRendered);
  16418. return ret;
  16419. };
  16420. $scope.expandableRow.shouldRenderFiller = function () {
  16421. var ret = $scope.row.isExpanded && ( $scope.colContainer.name !== 'body' || ($scope.grid.isScrollingVertically && !$scope.row.expandedRendered));
  16422. return ret;
  16423. };
  16424. /*
  16425. * Commented out @PaulL1. This has no purpose that I can see, and causes #2964. If this code needs to be reinstated for some
  16426. * reason it needs to use drawnWidth, not width, and needs to check column visibility. It should really use render container
  16427. * visible column cache also instead of checking column.renderContainer.
  16428. function updateRowContainerWidth() {
  16429. var grid = $scope.grid;
  16430. var colWidth = 0;
  16431. grid.columns.forEach( function (column) {
  16432. if (column.renderContainer === 'left') {
  16433. colWidth += column.width;
  16434. }
  16435. });
  16436. colWidth = Math.floor(colWidth);
  16437. return '.grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.colContainer.name + ', .grid' + grid.id +
  16438. ' .ui-grid-pinned-container-' + $scope.colContainer.name + ' .ui-grid-render-container-' + $scope.colContainer.name +
  16439. ' .ui-grid-viewport .ui-grid-canvas .ui-grid-row { width: ' + colWidth + 'px; }';
  16440. }
  16441. if ($scope.colContainer.name === 'left') {
  16442. $scope.grid.registerStyleComputation({
  16443. priority: 15,
  16444. func: updateRowContainerWidth
  16445. });
  16446. }*/
  16447. },
  16448. post: function ($scope, $elm, $attrs, controllers) {
  16449. }
  16450. };
  16451. }
  16452. };
  16453. }]);
  16454. /**
  16455. * @ngdoc directive
  16456. * @name ui.grid.expandable.directive:uiGridViewport
  16457. * @description stacks on the uiGridViewport directive to append the expandable row html elements to the
  16458. * default gridRow template
  16459. */
  16460. module.directive('uiGridViewport',
  16461. ['$compile', 'gridUtil', '$templateCache',
  16462. function ($compile, gridUtil, $templateCache) {
  16463. return {
  16464. priority: -200,
  16465. scope: false,
  16466. compile: function ($elm, $attrs) {
  16467. //todo: this adds ng-if watchers to each row even if the grid is not using expandable directive
  16468. // or options.enableExpandable == false
  16469. // The alternative is to compile the template and append to each row in a uiGridRow directive
  16470. var rowRepeatDiv = angular.element($elm.children().children()[0]);
  16471. var expandedRowFillerElement = $templateCache.get('ui-grid/expandableScrollFiller');
  16472. var expandedRowElement = $templateCache.get('ui-grid/expandableRow');
  16473. rowRepeatDiv.append(expandedRowElement);
  16474. rowRepeatDiv.append(expandedRowFillerElement);
  16475. return {
  16476. pre: function ($scope, $elm, $attrs, controllers) {
  16477. },
  16478. post: function ($scope, $elm, $attrs, controllers) {
  16479. }
  16480. };
  16481. }
  16482. };
  16483. }]);
  16484. })();
  16485. /* global ExcelBuilder */
  16486. /* global console */
  16487. (function () {
  16488. 'use strict';
  16489. /**
  16490. * @ngdoc overview
  16491. * @name ui.grid.exporter
  16492. * @description
  16493. *
  16494. * # ui.grid.exporter
  16495. *
  16496. * <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>
  16497. *
  16498. * This module provides the ability to export data from the grid.
  16499. *
  16500. * Data can be exported in a range of formats, and all data, visible
  16501. * data, or selected rows can be exported, with all columns or visible
  16502. * columns.
  16503. *
  16504. * No UI is provided, the caller should provide their own UI/buttons
  16505. * as appropriate, or enable the gridMenu
  16506. *
  16507. * <br/>
  16508. * <br/>
  16509. *
  16510. * <div doc-module-components="ui.grid.exporter"></div>
  16511. */
  16512. var module = angular.module('ui.grid.exporter', ['ui.grid']);
  16513. /**
  16514. * @ngdoc object
  16515. * @name ui.grid.exporter.constant:uiGridExporterConstants
  16516. *
  16517. * @description constants available in exporter module
  16518. */
  16519. /**
  16520. * @ngdoc property
  16521. * @propertyOf ui.grid.exporter.constant:uiGridExporterConstants
  16522. * @name ALL
  16523. * @description export all data, including data not visible. Can
  16524. * be set for either rowTypes or colTypes
  16525. */
  16526. /**
  16527. * @ngdoc property
  16528. * @propertyOf ui.grid.exporter.constant:uiGridExporterConstants
  16529. * @name VISIBLE
  16530. * @description export only visible data, including data not visible. Can
  16531. * be set for either rowTypes or colTypes
  16532. */
  16533. /**
  16534. * @ngdoc property
  16535. * @propertyOf ui.grid.exporter.constant:uiGridExporterConstants
  16536. * @name SELECTED
  16537. * @description export all data, including data not visible. Can
  16538. * be set only for rowTypes, selection of only some columns is
  16539. * not supported
  16540. */
  16541. module.constant('uiGridExporterConstants', {
  16542. featureName: 'exporter',
  16543. ALL: 'all',
  16544. VISIBLE: 'visible',
  16545. SELECTED: 'selected',
  16546. CSV_CONTENT: 'CSV_CONTENT',
  16547. BUTTON_LABEL: 'BUTTON_LABEL',
  16548. FILE_NAME: 'FILE_NAME'
  16549. });
  16550. /**
  16551. * @ngdoc service
  16552. * @name ui.grid.exporter.service:uiGridExporterService
  16553. *
  16554. * @description Services for exporter feature
  16555. */
  16556. module.service('uiGridExporterService', ['$filter', '$q', 'uiGridExporterConstants', 'gridUtil', '$compile', '$interval', 'i18nService',
  16557. function ($filter, $q, uiGridExporterConstants, gridUtil, $compile, $interval, i18nService) {
  16558. var service = {
  16559. delay: 100,
  16560. initializeGrid: function (grid) {
  16561. //add feature namespace and any properties to grid for needed state
  16562. grid.exporter = {};
  16563. this.defaultGridOptions(grid.options);
  16564. /**
  16565. * @ngdoc object
  16566. * @name ui.grid.exporter.api:PublicApi
  16567. *
  16568. * @description Public Api for exporter feature
  16569. */
  16570. var publicApi = {
  16571. events: {
  16572. exporter: {
  16573. }
  16574. },
  16575. methods: {
  16576. exporter: {
  16577. /**
  16578. * @ngdoc function
  16579. * @name csvExport
  16580. * @methodOf ui.grid.exporter.api:PublicApi
  16581. * @description Exports rows from the grid in csv format,
  16582. * the data exported is selected based on the provided options
  16583. * @param {string} rowTypes which rows to export, valid values are
  16584. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  16585. * uiGridExporterConstants.SELECTED
  16586. * @param {string} colTypes which columns to export, valid values are
  16587. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE
  16588. */
  16589. csvExport: function (rowTypes, colTypes) {
  16590. service.csvExport(grid, rowTypes, colTypes);
  16591. },
  16592. /**
  16593. * @ngdoc function
  16594. * @name pdfExport
  16595. * @methodOf ui.grid.exporter.api:PublicApi
  16596. * @description Exports rows from the grid in pdf format,
  16597. * the data exported is selected based on the provided options
  16598. * Note that this function has a dependency on pdfMake, all
  16599. * going well this has been installed for you.
  16600. * The resulting pdf opens in a new browser window.
  16601. * @param {string} rowTypes which rows to export, valid values are
  16602. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  16603. * uiGridExporterConstants.SELECTED
  16604. * @param {string} colTypes which columns to export, valid values are
  16605. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE
  16606. */
  16607. pdfExport: function (rowTypes, colTypes) {
  16608. service.pdfExport(grid, rowTypes, colTypes);
  16609. },
  16610. /**
  16611. * @ngdoc function
  16612. * @name excelExport
  16613. * @methodOf ui.grid.exporter.api:PublicApi
  16614. * @description Exports rows from the grid in excel format,
  16615. * the data exported is selected based on the provided options
  16616. * @param {string} rowTypes which rows to export, valid values are
  16617. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  16618. * uiGridExporterConstants.SELECTED
  16619. * @param {string} colTypes which columns to export, valid values are
  16620. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE
  16621. */
  16622. excelExport: function (rowTypes, colTypes) {
  16623. service.excelExport(grid, rowTypes, colTypes);
  16624. }
  16625. }
  16626. }
  16627. };
  16628. grid.api.registerEventsFromObject(publicApi.events);
  16629. grid.api.registerMethodsFromObject(publicApi.methods);
  16630. if (grid.api.core.addToGridMenu){
  16631. service.addToMenu( grid );
  16632. } else {
  16633. // order of registration is not guaranteed, register in a little while
  16634. $interval( function() {
  16635. if (grid.api.core.addToGridMenu){
  16636. service.addToMenu( grid );
  16637. }
  16638. }, this.delay, 1);
  16639. }
  16640. },
  16641. defaultGridOptions: function (gridOptions) {
  16642. //default option to true unless it was explicitly set to false
  16643. /**
  16644. * @ngdoc object
  16645. * @name ui.grid.exporter.api:GridOptions
  16646. *
  16647. * @description GridOptions for exporter feature, these are available to be
  16648. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  16649. */
  16650. /**
  16651. * @ngdoc object
  16652. * @name ui.grid.exporter.api:ColumnDef
  16653. * @description ColumnDef settings for exporter
  16654. */
  16655. /**
  16656. * @ngdoc object
  16657. * @name exporterSuppressMenu
  16658. * @propertyOf ui.grid.exporter.api:GridOptions
  16659. * @description Don't show the export menu button, implying the user
  16660. * will roll their own UI for calling the exporter
  16661. * <br/>Defaults to false
  16662. */
  16663. gridOptions.exporterSuppressMenu = gridOptions.exporterSuppressMenu === true;
  16664. /**
  16665. * @ngdoc object
  16666. * @name exporterMenuLabel
  16667. * @propertyOf ui.grid.exporter.api:GridOptions
  16668. * @description The text to show on the exporter menu button
  16669. * link
  16670. * <br/>Defaults to 'Export'
  16671. */
  16672. gridOptions.exporterMenuLabel = gridOptions.exporterMenuLabel ? gridOptions.exporterMenuLabel : 'Export';
  16673. /**
  16674. * @ngdoc object
  16675. * @name exporterSuppressColumns
  16676. * @propertyOf ui.grid.exporter.api:GridOptions
  16677. * @description Columns that should not be exported. The selectionRowHeader is already automatically
  16678. * suppressed, but if you had a button column or some other "system" column that shouldn't be shown in the
  16679. * output then add it in this list. You should provide an array of column names.
  16680. * <br/>Defaults to: []
  16681. * <pre>
  16682. * gridOptions.exporterSuppressColumns = [ 'buttons' ];
  16683. * </pre>
  16684. */
  16685. gridOptions.exporterSuppressColumns = gridOptions.exporterSuppressColumns ? gridOptions.exporterSuppressColumns : [];
  16686. /**
  16687. * @ngdoc object
  16688. * @name exporterCsvColumnSeparator
  16689. * @propertyOf ui.grid.exporter.api:GridOptions
  16690. * @description The character to use as column separator
  16691. * link
  16692. * <br/>Defaults to ','
  16693. */
  16694. gridOptions.exporterCsvColumnSeparator = gridOptions.exporterCsvColumnSeparator ? gridOptions.exporterCsvColumnSeparator : ',';
  16695. /**
  16696. * @ngdoc object
  16697. * @name exporterCsvFilename
  16698. * @propertyOf ui.grid.exporter.api:GridOptions
  16699. * @description The default filename to use when saving the downloaded csv.
  16700. * This will only work in some browsers.
  16701. * <br/>Defaults to 'download.csv'
  16702. */
  16703. gridOptions.exporterCsvFilename = gridOptions.exporterCsvFilename ? gridOptions.exporterCsvFilename : 'download.csv';
  16704. /**
  16705. * @ngdoc object
  16706. * @name exporterPdfFilename
  16707. * @propertyOf ui.grid.exporter.api:GridOptions
  16708. * @description The default filename to use when saving the downloaded pdf, only used in IE (other browsers open pdfs in a new window)
  16709. * <br/>Defaults to 'download.pdf'
  16710. */
  16711. gridOptions.exporterPdfFilename = gridOptions.exporterPdfFilename ? gridOptions.exporterPdfFilename : 'download.pdf';
  16712. /**
  16713. * @ngdoc object
  16714. * @name exporterOlderExcelCompatibility
  16715. * @propertyOf ui.grid.exporter.api:GridOptions
  16716. * @description Some versions of excel don't like the utf-16 BOM on the front, and it comes
  16717. * through as  in the first column header. Setting this option to false will suppress this, at the
  16718. * expense of proper utf-16 handling in applications that do recognise the BOM
  16719. * <br/>Defaults to false
  16720. */
  16721. gridOptions.exporterOlderExcelCompatibility = gridOptions.exporterOlderExcelCompatibility === true;
  16722. /**
  16723. * @ngdoc object
  16724. * @name exporterIsExcelCompatible
  16725. * @propertyOf ui.grid.exporter.api:GridOptions
  16726. * @description Separator header, used to set a custom column separator in a csv file, only works on MS Excel.
  16727. * Used it on other programs will make csv content display unproperly. Setting this option to false won't add this header.
  16728. * <br/>Defaults to false
  16729. */
  16730. gridOptions.exporterIsExcelCompatible = gridOptions.exporterIsExcelCompatible === true;
  16731. /**
  16732. * @ngdoc object
  16733. * @name exporterMenuItemOrder
  16734. * @propertyOf ui.grid.exporter.api:GridOptions
  16735. * @description An option to determine the starting point for the menu items created by the exporter
  16736. * <br/>Defaults to 200
  16737. */
  16738. gridOptions.exporterMenuItemOrder = gridOptions.exporterMenuItemOrder ? gridOptions.exporterMenuItemOrder : 200;
  16739. /**
  16740. * @ngdoc object
  16741. * @name exporterPdfDefaultStyle
  16742. * @propertyOf ui.grid.exporter.api:GridOptions
  16743. * @description The default style in pdfMake format
  16744. * <br/>Defaults to:
  16745. * <pre>
  16746. * {
  16747. * fontSize: 11
  16748. * }
  16749. * </pre>
  16750. */
  16751. gridOptions.exporterPdfDefaultStyle = gridOptions.exporterPdfDefaultStyle ? gridOptions.exporterPdfDefaultStyle : { fontSize: 11 };
  16752. /**
  16753. * @ngdoc object
  16754. * @name exporterPdfTableStyle
  16755. * @propertyOf ui.grid.exporter.api:GridOptions
  16756. * @description The table style in pdfMake format
  16757. * <br/>Defaults to:
  16758. * <pre>
  16759. * {
  16760. * margin: [0, 5, 0, 15]
  16761. * }
  16762. * </pre>
  16763. */
  16764. gridOptions.exporterPdfTableStyle = gridOptions.exporterPdfTableStyle ? gridOptions.exporterPdfTableStyle : { margin: [0, 5, 0, 15] };
  16765. /**
  16766. * @ngdoc object
  16767. * @name exporterPdfTableHeaderStyle
  16768. * @propertyOf ui.grid.exporter.api:GridOptions
  16769. * @description The tableHeader style in pdfMake format
  16770. * <br/>Defaults to:
  16771. * <pre>
  16772. * {
  16773. * bold: true,
  16774. * fontSize: 12,
  16775. * color: 'black'
  16776. * }
  16777. * </pre>
  16778. */
  16779. gridOptions.exporterPdfTableHeaderStyle = gridOptions.exporterPdfTableHeaderStyle ? gridOptions.exporterPdfTableHeaderStyle : { bold: true, fontSize: 12, color: 'black' };
  16780. /**
  16781. * @ngdoc object
  16782. * @name exporterPdfHeader
  16783. * @propertyOf ui.grid.exporter.api:GridOptions
  16784. * @description The header section for pdf exports. Can be
  16785. * simple text:
  16786. * <pre>
  16787. * gridOptions.exporterPdfHeader = 'My Header';
  16788. * </pre>
  16789. * Can be a more complex object in pdfMake format:
  16790. * <pre>
  16791. * gridOptions.exporterPdfHeader = {
  16792. * columns: [
  16793. * 'Left part',
  16794. * { text: 'Right part', alignment: 'right' }
  16795. * ]
  16796. * };
  16797. * </pre>
  16798. * Or can be a function, allowing page numbers and the like
  16799. * <pre>
  16800. * gridOptions.exporterPdfHeader: function(currentPage, pageCount) { return currentPage.toString() + ' of ' + pageCount; };
  16801. * </pre>
  16802. */
  16803. gridOptions.exporterPdfHeader = gridOptions.exporterPdfHeader ? gridOptions.exporterPdfHeader : null;
  16804. /**
  16805. * @ngdoc object
  16806. * @name exporterPdfFooter
  16807. * @propertyOf ui.grid.exporter.api:GridOptions
  16808. * @description The header section for pdf exports. Can be
  16809. * simple text:
  16810. * <pre>
  16811. * gridOptions.exporterPdfFooter = 'My Footer';
  16812. * </pre>
  16813. * Can be a more complex object in pdfMake format:
  16814. * <pre>
  16815. * gridOptions.exporterPdfFooter = {
  16816. * columns: [
  16817. * 'Left part',
  16818. * { text: 'Right part', alignment: 'right' }
  16819. * ]
  16820. * };
  16821. * </pre>
  16822. * Or can be a function, allowing page numbers and the like
  16823. * <pre>
  16824. * gridOptions.exporterPdfFooter: function(currentPage, pageCount) { return currentPage.toString() + ' of ' + pageCount; };
  16825. * </pre>
  16826. */
  16827. gridOptions.exporterPdfFooter = gridOptions.exporterPdfFooter ? gridOptions.exporterPdfFooter : null;
  16828. /**
  16829. * @ngdoc object
  16830. * @name exporterPdfOrientation
  16831. * @propertyOf ui.grid.exporter.api:GridOptions
  16832. * @description The orientation, should be a valid pdfMake value,
  16833. * 'landscape' or 'portrait'
  16834. * <br/>Defaults to landscape
  16835. */
  16836. gridOptions.exporterPdfOrientation = gridOptions.exporterPdfOrientation ? gridOptions.exporterPdfOrientation : 'landscape';
  16837. /**
  16838. * @ngdoc object
  16839. * @name exporterPdfPageSize
  16840. * @propertyOf ui.grid.exporter.api:GridOptions
  16841. * @description The orientation, should be a valid pdfMake
  16842. * paper size, usually 'A4' or 'LETTER'
  16843. * {@link https://github.com/bpampuch/pdfmake/blob/master/src/standardPageSizes.js pdfMake page sizes}
  16844. * <br/>Defaults to A4
  16845. */
  16846. gridOptions.exporterPdfPageSize = gridOptions.exporterPdfPageSize ? gridOptions.exporterPdfPageSize : 'A4';
  16847. /**
  16848. * @ngdoc object
  16849. * @name exporterPdfMaxGridWidth
  16850. * @propertyOf ui.grid.exporter.api:GridOptions
  16851. * @description The maxium grid width - the current grid width
  16852. * will be scaled to match this, with any fixed width columns
  16853. * being adjusted accordingly.
  16854. * <br/>Defaults to 720 (for A4 landscape), use 670 for LETTER
  16855. */
  16856. gridOptions.exporterPdfMaxGridWidth = gridOptions.exporterPdfMaxGridWidth ? gridOptions.exporterPdfMaxGridWidth : 720;
  16857. /**
  16858. * @ngdoc object
  16859. * @name exporterPdfTableLayout
  16860. * @propertyOf ui.grid.exporter.api:GridOptions
  16861. * @description A tableLayout in pdfMake format,
  16862. * controls gridlines and the like. We use the default
  16863. * layout usually.
  16864. * <br/>Defaults to null, which means no layout
  16865. */
  16866. /**
  16867. * @ngdoc object
  16868. * @name exporterMenuAllData
  16869. * @porpertyOf ui.grid.exporter.api:GridOptions
  16870. * @description Add export all data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true.
  16871. */
  16872. gridOptions.exporterMenuAllData = gridOptions.exporterMenuAllData !== undefined ? gridOptions.exporterMenuAllData : true;
  16873. /**
  16874. * @ngdoc object
  16875. * @name exporterMenuVisibleData
  16876. * @porpertyOf ui.grid.exporter.api:GridOptions
  16877. * @description Add export visible data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true.
  16878. */
  16879. gridOptions.exporterMenuVisibleData = gridOptions.exporterMenuVisibleData !== undefined ? gridOptions.exporterMenuVisibleData : true;
  16880. /**
  16881. * @ngdoc object
  16882. * @name exporterMenuSelectedData
  16883. * @porpertyOf ui.grid.exporter.api:GridOptions
  16884. * @description Add export selected data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true.
  16885. */
  16886. gridOptions.exporterMenuSelectedData = gridOptions.exporterMenuSelectedData !== undefined ? gridOptions.exporterMenuSelectedData : true;
  16887. /**
  16888. * @ngdoc object
  16889. * @name exporterMenuCsv
  16890. * @propertyOf ui.grid.exporter.api:GridOptions
  16891. * @description Add csv export menu items to the ui-grid grid menu, if it's present. Defaults to true.
  16892. */
  16893. gridOptions.exporterMenuCsv = gridOptions.exporterMenuCsv !== undefined ? gridOptions.exporterMenuCsv : true;
  16894. /**
  16895. * @ngdoc object
  16896. * @name exporterMenuPdf
  16897. * @propertyOf ui.grid.exporter.api:GridOptions
  16898. * @description Add pdf export menu items to the ui-grid grid menu, if it's present. Defaults to true.
  16899. */
  16900. gridOptions.exporterMenuPdf = gridOptions.exporterMenuPdf !== undefined ? gridOptions.exporterMenuPdf : true;
  16901. /**
  16902. * @ngdoc object
  16903. * @name exporterMenuExcel
  16904. * @propertyOf ui.grid.exporter.api:GridOptions
  16905. * @description Add excel export menu items to the ui-grid grid menu, if it's present. Defaults to true.
  16906. */
  16907. gridOptions.exporterMenuExcel = gridOptions.exporterMenuExcel !== undefined ? gridOptions.exporterMenuExcel : true;
  16908. /**
  16909. * @ngdoc object
  16910. * @name exporterPdfCustomFormatter
  16911. * @propertyOf ui.grid.exporter.api:GridOptions
  16912. * @description A custom callback routine that changes the pdf document, adding any
  16913. * custom styling or content that is supported by pdfMake. Takes in the complete docDefinition, and
  16914. * must return an updated docDefinition ready for pdfMake.
  16915. * @example
  16916. * In this example we add a style to the style array, so that we can use it in our
  16917. * footer definition.
  16918. * <pre>
  16919. * gridOptions.exporterPdfCustomFormatter = function ( docDefinition ) {
  16920. * docDefinition.styles.footerStyle = { bold: true, fontSize: 10 };
  16921. * return docDefinition;
  16922. * }
  16923. *
  16924. * gridOptions.exporterPdfFooter = { text: 'My footer', style: 'footerStyle' }
  16925. * </pre>
  16926. */
  16927. gridOptions.exporterPdfCustomFormatter = ( gridOptions.exporterPdfCustomFormatter && typeof( gridOptions.exporterPdfCustomFormatter ) === 'function' ) ? gridOptions.exporterPdfCustomFormatter : function ( docDef ) { return docDef; };
  16928. /**
  16929. * @ngdoc object
  16930. * @name exporterHeaderFilterUseName
  16931. * @propertyOf ui.grid.exporter.api:GridOptions
  16932. * @description Defaults to false, which leads to `displayName` being passed into the headerFilter.
  16933. * If set to true, then will pass `name` instead.
  16934. *
  16935. *
  16936. * @example
  16937. * <pre>
  16938. * gridOptions.exporterHeaderFilterUseName = true;
  16939. * </pre>
  16940. */
  16941. gridOptions.exporterHeaderFilterUseName = gridOptions.exporterHeaderFilterUseName === true;
  16942. /**
  16943. * @ngdoc object
  16944. * @name exporterHeaderFilter
  16945. * @propertyOf ui.grid.exporter.api:GridOptions
  16946. * @description A function to apply to the header displayNames before exporting. Useful for internationalisation,
  16947. * for example if you were using angular-translate you'd set this to `$translate.instant`. Note that this
  16948. * call must be synchronous, it cannot be a call that returns a promise.
  16949. *
  16950. * Behaviour can be changed to pass in `name` instead of `displayName` through use of `exporterHeaderFilterUseName: true`.
  16951. *
  16952. * @example
  16953. * <pre>
  16954. * gridOptions.exporterHeaderFilter = function( displayName ){ return 'col: ' + name; };
  16955. * </pre>
  16956. * OR
  16957. * <pre>
  16958. * gridOptions.exporterHeaderFilter = $translate.instant;
  16959. * </pre>
  16960. */
  16961. /**
  16962. * @ngdoc function
  16963. * @name exporterFieldCallback
  16964. * @propertyOf ui.grid.exporter.api:GridOptions
  16965. * @description A function to call for each field before exporting it. Allows
  16966. * massaging of raw data into a display format, for example if you have applied
  16967. * filters to convert codes into decodes, or you require
  16968. * a specific date format in the exported content.
  16969. *
  16970. * The method is called once for each field exported, and provides the grid, the
  16971. * gridCol and the GridRow for you to use as context in massaging the data.
  16972. *
  16973. * @param {Grid} grid provides the grid in case you have need of it
  16974. * @param {GridRow} row the row from which the data comes
  16975. * @param {GridColumn} col the column from which the data comes
  16976. * @param {object} value the value for your massaging
  16977. * @returns {object} you must return the massaged value ready for exporting
  16978. *
  16979. * @example
  16980. * <pre>
  16981. * gridOptions.exporterFieldCallback = function ( grid, row, col, value ){
  16982. * if ( col.name === 'status' ){
  16983. * value = decodeStatus( value );
  16984. * }
  16985. * return value;
  16986. * }
  16987. * </pre>
  16988. */
  16989. gridOptions.exporterFieldCallback = gridOptions.exporterFieldCallback ? gridOptions.exporterFieldCallback : defaultExporterFieldCallback;
  16990. /**
  16991. * @ngdoc function
  16992. * @name exporterFieldFormatCallback
  16993. * @propertyOf ui.grid.exporter.api:GridOptions
  16994. * @description A function to call for each field before exporting it. Allows
  16995. * general object to be return to modify the format of a cell in the case of
  16996. * excel exports
  16997. *
  16998. * The method is called once for each field exported, and provides the grid, the
  16999. * gridCol and the GridRow for you to use as context in massaging the data.
  17000. *
  17001. * @param {Grid} grid provides the grid in case you have need of it
  17002. * @param {GridRow} row the row from which the data comes
  17003. * @param {GridColumn} col the column from which the data comes
  17004. * @param {object} value the value for your massaging
  17005. * @returns {object} you must return the massaged value ready for exporting
  17006. *
  17007. * @example
  17008. * <pre>
  17009. * gridOptions.exporterFieldCallback = function ( grid, row, col, value ){
  17010. * if ( col.name === 'status' ){
  17011. * value = decodeStatus( value );
  17012. * }
  17013. * return value;
  17014. * }
  17015. * </pre>
  17016. */
  17017. gridOptions.exporterFieldFormatCallback = gridOptions.exporterFieldFormatCallback ? gridOptions.exporterFieldFormatCallback : function( grid, row, col, value ) { return null; };
  17018. /**
  17019. * @ngdoc object
  17020. * @name exporterFieldApplyFilters
  17021. * @propertyOf ui.grid.exporter.api:GridOptions
  17022. * @description Defaults to false, which leads to filters being evaluated on export *
  17023. *
  17024. * @example
  17025. * <pre>
  17026. * gridOptions.exporterFieldApplyFilters = true;
  17027. * </pre>
  17028. */
  17029. gridOptions.exporterFieldApplyFilters = gridOptions.exporterFieldApplyFilters === true;
  17030. /**
  17031. * @ngdoc function
  17032. * @name exporterAllDataFn
  17033. * @propertyOf ui.grid.exporter.api:GridOptions
  17034. * @description This promise is needed when exporting all rows,
  17035. * and the data need to be provided by server side. Default is null.
  17036. * @returns {Promise} a promise to load all data from server
  17037. *
  17038. * @example
  17039. * <pre>
  17040. * gridOptions.exporterAllDataFn = function () {
  17041. * return $http.get('/data/100.json')
  17042. * }
  17043. * </pre>
  17044. */
  17045. gridOptions.exporterAllDataFn = gridOptions.exporterAllDataFn ? gridOptions.exporterAllDataFn : null;
  17046. /**
  17047. * @ngdoc function
  17048. * @name exporterAllDataPromise
  17049. * @propertyOf ui.grid.exporter.api:GridOptions
  17050. * @description DEPRECATED - exporterAllDataFn used to be
  17051. * called this, but it wasn't a promise, it was a function that returned
  17052. * a promise. Deprecated, but supported for backward compatibility, use
  17053. * exporterAllDataFn instead.
  17054. * @returns {Promise} a promise to load all data from server
  17055. *
  17056. * @example
  17057. * <pre>
  17058. * gridOptions.exporterAllDataFn = function () {
  17059. * return $http.get('/data/100.json')
  17060. * }
  17061. * </pre>
  17062. */
  17063. if ( gridOptions.exporterAllDataFn === null && gridOptions.exporterAllDataPromise ) {
  17064. gridOptions.exporterAllDataFn = gridOptions.exporterAllDataPromise;
  17065. }
  17066. },
  17067. /**
  17068. * @ngdoc function
  17069. * @name addToMenu
  17070. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17071. * @description Adds export items to the grid menu,
  17072. * allowing the user to select export options
  17073. * @param {Grid} grid the grid from which data should be exported
  17074. */
  17075. addToMenu: function ( grid ) {
  17076. grid.api.core.addToGridMenu( grid, [
  17077. {
  17078. title: i18nService.getSafeText('gridMenu.exporterAllAsCsv'),
  17079. action: function ($event) {
  17080. grid.api.exporter.csvExport( uiGridExporterConstants.ALL, uiGridExporterConstants.ALL );
  17081. },
  17082. shown: function() {
  17083. return grid.options.exporterMenuCsv && grid.options.exporterMenuAllData;
  17084. },
  17085. order: grid.options.exporterMenuItemOrder
  17086. },
  17087. {
  17088. title: i18nService.getSafeText('gridMenu.exporterVisibleAsCsv'),
  17089. action: function ($event) {
  17090. grid.api.exporter.csvExport( uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE );
  17091. },
  17092. shown: function() {
  17093. return grid.options.exporterMenuCsv && grid.options.exporterMenuVisibleData;
  17094. },
  17095. order: grid.options.exporterMenuItemOrder + 1
  17096. },
  17097. {
  17098. title: i18nService.getSafeText('gridMenu.exporterSelectedAsCsv'),
  17099. action: function ($event) {
  17100. grid.api.exporter.csvExport( uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE );
  17101. },
  17102. shown: function() {
  17103. return grid.options.exporterMenuCsv && grid.options.exporterMenuSelectedData &&
  17104. ( grid.api.selection && grid.api.selection.getSelectedRows().length > 0 );
  17105. },
  17106. order: grid.options.exporterMenuItemOrder + 2
  17107. },
  17108. {
  17109. title: i18nService.getSafeText('gridMenu.exporterAllAsPdf'),
  17110. action: function ($event) {
  17111. grid.api.exporter.pdfExport( uiGridExporterConstants.ALL, uiGridExporterConstants.ALL );
  17112. },
  17113. shown: function() {
  17114. return grid.options.exporterMenuPdf && grid.options.exporterMenuAllData;
  17115. },
  17116. order: grid.options.exporterMenuItemOrder + 3
  17117. },
  17118. {
  17119. title: i18nService.getSafeText('gridMenu.exporterVisibleAsPdf'),
  17120. action: function ($event) {
  17121. grid.api.exporter.pdfExport( uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE );
  17122. },
  17123. shown: function() {
  17124. return grid.options.exporterMenuPdf && grid.options.exporterMenuVisibleData;
  17125. },
  17126. order: grid.options.exporterMenuItemOrder + 4
  17127. },
  17128. {
  17129. title: i18nService.getSafeText('gridMenu.exporterSelectedAsPdf'),
  17130. action: function ($event) {
  17131. grid.api.exporter.pdfExport( uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE );
  17132. },
  17133. shown: function() {
  17134. return grid.options.exporterMenuPdf && grid.options.exporterMenuSelectedData &&
  17135. ( grid.api.selection && grid.api.selection.getSelectedRows().length > 0 );
  17136. },
  17137. order: grid.options.exporterMenuItemOrder + 5
  17138. },
  17139. {
  17140. title: i18nService.getSafeText('gridMenu.exporterAllAsExcel'),
  17141. action: function ($event) {
  17142. grid.api.exporter.excelExport( uiGridExporterConstants.ALL, uiGridExporterConstants.ALL );
  17143. },
  17144. shown: function() {
  17145. return grid.options.exporterMenuExcel && grid.options.exporterMenuAllData;
  17146. },
  17147. order: grid.options.exporterMenuItemOrder + 6
  17148. },
  17149. {
  17150. title: i18nService.getSafeText('gridMenu.exporterVisibleAsExcel'),
  17151. action: function ($event) {
  17152. grid.api.exporter.excelExport( uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE );
  17153. },
  17154. shown: function() {
  17155. return grid.options.exporterMenuExcel && grid.options.exporterMenuVisibleData;
  17156. },
  17157. order: grid.options.exporterMenuItemOrder + 7
  17158. },
  17159. {
  17160. title: i18nService.getSafeText('gridMenu.exporterSelectedAsExcel'),
  17161. action: function ($event) {
  17162. grid.api.exporter.excelExport( uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE );
  17163. },
  17164. shown: function() {
  17165. return grid.options.exporterMenuExcel && grid.options.exporterMenuSelectedData &&
  17166. ( grid.api.selection && grid.api.selection.getSelectedRows().length > 0 );
  17167. },
  17168. order: grid.options.exporterMenuItemOrder + 8
  17169. }
  17170. ]);
  17171. },
  17172. /**
  17173. * @ngdoc function
  17174. * @name csvExport
  17175. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17176. * @description Exports rows from the grid in csv format,
  17177. * the data exported is selected based on the provided options
  17178. * @param {Grid} grid the grid from which data should be exported
  17179. * @param {string} rowTypes which rows to export, valid values are
  17180. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  17181. * uiGridExporterConstants.SELECTED
  17182. * @param {string} colTypes which columns to export, valid values are
  17183. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  17184. * uiGridExporterConstants.SELECTED
  17185. */
  17186. csvExport: function (grid, rowTypes, colTypes) {
  17187. var self = this;
  17188. this.loadAllDataIfNeeded(grid, rowTypes, colTypes).then(function() {
  17189. var exportColumnHeaders = grid.options.showHeader ? self.getColumnHeaders(grid, colTypes) : [];
  17190. var exportData = self.getData(grid, rowTypes, colTypes);
  17191. var csvContent = self.formatAsCsv(exportColumnHeaders, exportData, grid.options.exporterCsvColumnSeparator);
  17192. self.downloadFile (grid.options.exporterCsvFilename, csvContent, grid.options.exporterCsvColumnSeparator, grid.options.exporterOlderExcelCompatibility, grid.options.exporterIsExcelCompatible);
  17193. });
  17194. },
  17195. /**
  17196. * @ngdoc function
  17197. * @name loadAllDataIfNeeded
  17198. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17199. * @description When using server side pagination, use exporterAllDataFn to
  17200. * load all data before continuing processing.
  17201. * When using client side pagination, return a resolved promise so processing
  17202. * continues immediately
  17203. * @param {Grid} grid the grid from which data should be exported
  17204. * @param {string} rowTypes which rows to export, valid values are
  17205. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  17206. * uiGridExporterConstants.SELECTED
  17207. * @param {string} colTypes which columns to export, valid values are
  17208. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  17209. * uiGridExporterConstants.SELECTED
  17210. */
  17211. loadAllDataIfNeeded: function (grid, rowTypes, colTypes) {
  17212. if ( rowTypes === uiGridExporterConstants.ALL && grid.rows.length !== grid.options.totalItems && grid.options.exporterAllDataFn) {
  17213. return grid.options.exporterAllDataFn()
  17214. .then(function(allData) {
  17215. grid.modifyRows(allData);
  17216. });
  17217. } else {
  17218. var deferred = $q.defer();
  17219. deferred.resolve();
  17220. return deferred.promise;
  17221. }
  17222. },
  17223. /**
  17224. * @ngdoc property
  17225. * @propertyOf ui.grid.exporter.api:ColumnDef
  17226. * @name exporterSuppressExport
  17227. * @description Suppresses export for this column. Used by selection and expandable.
  17228. */
  17229. /**
  17230. * @ngdoc function
  17231. * @name getColumnHeaders
  17232. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17233. * @description Gets the column headers from the grid to use
  17234. * as a title row for the exported file, all headers have
  17235. * headerCellFilters applied as appropriate.
  17236. *
  17237. * Column headers are an array of objects, each object has
  17238. * name, displayName, width and align attributes. Only name is
  17239. * used for csv, all attributes are used for pdf.
  17240. *
  17241. * @param {Grid} grid the grid from which data should be exported
  17242. * @param {string} colTypes which columns to export, valid values are
  17243. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  17244. * uiGridExporterConstants.SELECTED
  17245. */
  17246. getColumnHeaders: function (grid, colTypes) {
  17247. var headers = [];
  17248. var columns;
  17249. if ( colTypes === uiGridExporterConstants.ALL ){
  17250. columns = grid.columns;
  17251. } else {
  17252. var leftColumns = grid.renderContainers.left ? grid.renderContainers.left.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
  17253. var bodyColumns = grid.renderContainers.body ? grid.renderContainers.body.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
  17254. var rightColumns = grid.renderContainers.right ? grid.renderContainers.right.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
  17255. columns = leftColumns.concat(bodyColumns,rightColumns);
  17256. }
  17257. columns.forEach( function( gridCol ) {
  17258. // $$hashKey check since when grouping and sorting pragmatically this ends up in export. Filtering it out
  17259. if ( gridCol.colDef.exporterSuppressExport !== true && gridCol.field !== '$$hashKey' &&
  17260. grid.options.exporterSuppressColumns.indexOf( gridCol.name ) === -1 ){
  17261. var headerEntry = {
  17262. name: gridCol.field,
  17263. displayName: getDisplayName(grid, gridCol),
  17264. width: gridCol.drawnWidth ? gridCol.drawnWidth : gridCol.width,
  17265. align: gridCol.colDef.align ? gridCol.colDef.align : (gridCol.colDef.type === 'number' ? 'right' : 'left')
  17266. };
  17267. headers.push(headerEntry);
  17268. }
  17269. });
  17270. return headers;
  17271. },
  17272. /**
  17273. * @ngdoc property
  17274. * @propertyOf ui.grid.exporter.api:ColumnDef
  17275. * @name exporterPdfAlign
  17276. * @description the alignment you'd like for this specific column when
  17277. * exported into a pdf. Can be 'left', 'right', 'center' or any other
  17278. * valid pdfMake alignment option.
  17279. */
  17280. /**
  17281. * @ngdoc object
  17282. * @name ui.grid.exporter.api:GridRow
  17283. * @description GridRow settings for exporter
  17284. */
  17285. /**
  17286. * @ngdoc object
  17287. * @name exporterEnableExporting
  17288. * @propertyOf ui.grid.exporter.api:GridRow
  17289. * @description If set to false, then don't export this row, notwithstanding visible or
  17290. * other settings
  17291. * <br/>Defaults to true
  17292. */
  17293. /**
  17294. * @ngdoc function
  17295. * @name getRowsFromNode
  17296. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17297. * @description Gets rows from a node. If the node is grouped it will
  17298. * recurse down into the children to get to the raw data element
  17299. * which is a row without children (a leaf).
  17300. * @param {Node} aNode the tree node on the grid
  17301. * @returns {Array} an array of leaf nodes
  17302. */
  17303. getRowsFromNode: function(aNode) {
  17304. var rows = [];
  17305. for (var i = 0; i<aNode.children.length; i++) {
  17306. if (aNode.children[i].children && aNode.children[i].children.length === 0) {
  17307. rows.push(aNode.children[i]);
  17308. } else {
  17309. var nodeRows = this.getRowsFromNode(aNode.children[i]);
  17310. rows = rows.concat(nodeRows);
  17311. }
  17312. }
  17313. return rows;
  17314. },
  17315. /**
  17316. * @ngdoc function
  17317. * @name getDataSorted
  17318. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17319. * @description Gets rows from a node. If the node is grouped it will
  17320. * recurse down into the children to get to the raw data element
  17321. * which is a row without children (a leaf). If the grid is not
  17322. * grouped this will return just the raw rows
  17323. * @param {Grid} grid the grid from which data should be exported
  17324. * @param {string} rowTypes which rows to export, valid values are
  17325. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  17326. * uiGridExporterConstants.SELECTED
  17327. * @param {string} colTypes which columns to export, valid values are
  17328. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  17329. * uiGridExporterConstants.SELECTED
  17330. * @param {boolean} applyCellFilters whether or not to get the display value or the raw value of the data
  17331. * @returns {Array} an array of leaf nodes
  17332. */
  17333. getDataSorted: function (grid, rowTypes, colTypes, applyCellFilters) {
  17334. if (!grid.treeBase || grid.treeBase.numberLevels === 0) {
  17335. return grid.rows;
  17336. }
  17337. var rows = [];
  17338. for (var i = 0; i< grid.treeBase.tree.length; i++) {
  17339. var nodeRows = this.getRowsFromNode(grid.treeBase.tree[i]);
  17340. for (var j = 0; j<nodeRows.length; j++) {
  17341. rows.push(nodeRows[j].row);
  17342. }
  17343. }
  17344. return rows;
  17345. },
  17346. /**
  17347. * @ngdoc function
  17348. * @name getData
  17349. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17350. * @description Gets data from the grid based on the provided options,
  17351. * all cells have cellFilters applied as appropriate. Any rows marked
  17352. * `exporterEnableExporting: false` will not be exported
  17353. * @param {Grid} grid the grid from which data should be exported
  17354. * @param {string} rowTypes which rows to export, valid values are
  17355. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  17356. * uiGridExporterConstants.SELECTED
  17357. * @param {string} colTypes which columns to export, valid values are
  17358. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  17359. * uiGridExporterConstants.SELECTED
  17360. * @param {boolean} applyCellFilters whether or not to get the display value or the raw value of the data
  17361. */
  17362. getData: function (grid, rowTypes, colTypes, applyCellFilters) {
  17363. var data = [];
  17364. var rows;
  17365. var columns;
  17366. switch ( rowTypes ) {
  17367. case uiGridExporterConstants.ALL:
  17368. rows = this.getDataSorted(grid, rowTypes, colTypes, applyCellFilters);
  17369. break;
  17370. case uiGridExporterConstants.VISIBLE:
  17371. rows = grid.getVisibleRows();
  17372. break;
  17373. case uiGridExporterConstants.SELECTED:
  17374. if ( grid.api.selection ){
  17375. rows = grid.api.selection.getSelectedGridRows();
  17376. } else {
  17377. gridUtil.logError('selection feature must be enabled to allow selected rows to be exported');
  17378. }
  17379. break;
  17380. }
  17381. if ( colTypes === uiGridExporterConstants.ALL ){
  17382. columns = grid.columns;
  17383. } else {
  17384. var leftColumns = grid.renderContainers.left ? grid.renderContainers.left.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
  17385. var bodyColumns = grid.renderContainers.body ? grid.renderContainers.body.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
  17386. var rightColumns = grid.renderContainers.right ? grid.renderContainers.right.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
  17387. columns = leftColumns.concat(bodyColumns,rightColumns);
  17388. }
  17389. rows.forEach( function( row, index ) {
  17390. if (row.exporterEnableExporting !== false) {
  17391. var extractedRow = [];
  17392. columns.forEach( function( gridCol, index ) {
  17393. // $$hashKey check since when grouping and sorting programmatically this ends up in export. Filtering it out
  17394. if ( (gridCol.visible || colTypes === uiGridExporterConstants.ALL ) &&
  17395. gridCol.colDef.exporterSuppressExport !== true && gridCol.field !== '$$hashKey' &&
  17396. grid.options.exporterSuppressColumns.indexOf( gridCol.name ) === -1 ){
  17397. var cellValue = applyCellFilters ? grid.getCellDisplayValue( row, gridCol ) : grid.getCellValue( row, gridCol );
  17398. var extractedField = { value: grid.options.exporterFieldCallback( grid, row, gridCol, cellValue ) };
  17399. var extension = grid.options.exporterFieldFormatCallback( grid, row, gridCol, cellValue );
  17400. if (extension) {
  17401. Object.assign(extractedField, extension);
  17402. }
  17403. if ( gridCol.colDef.exporterPdfAlign ) {
  17404. extractedField.alignment = gridCol.colDef.exporterPdfAlign;
  17405. }
  17406. extractedRow.push(extractedField);
  17407. }
  17408. });
  17409. data.push(extractedRow);
  17410. }
  17411. });
  17412. return data;
  17413. },
  17414. /**
  17415. * @ngdoc function
  17416. * @name formatAsCsv
  17417. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17418. * @description Formats the column headers and data as a CSV,
  17419. * and sends that data to the user
  17420. * @param {array} exportColumnHeaders an array of column headers,
  17421. * where each header is an object with name, width and maybe alignment
  17422. * @param {array} exportData an array of rows, where each row is
  17423. * an array of column data
  17424. * @param {string} separator a string that represents the separator to be used in the csv file
  17425. * @returns {string} csv the formatted csv as a string
  17426. */
  17427. formatAsCsv: function (exportColumnHeaders, exportData, separator) {
  17428. var self = this;
  17429. var bareHeaders = exportColumnHeaders.map(function(header){return { value: header.displayName };});
  17430. var csv = bareHeaders.length > 0 ? (self.formatRowAsCsv(this, separator)(bareHeaders) + '\n') : '';
  17431. csv += exportData.map(this.formatRowAsCsv(this, separator)).join('\n');
  17432. return csv;
  17433. },
  17434. /**
  17435. * @ngdoc function
  17436. * @name formatRowAsCsv
  17437. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17438. * @description Renders a single field as a csv field, including
  17439. * quotes around the value
  17440. * @param {exporterService} exporter pass in exporter
  17441. * @param {array} row the row to be turned into a csv string
  17442. * @returns {string} a csv-ified version of the row
  17443. */
  17444. formatRowAsCsv: function (exporter, separator) {
  17445. return function (row) {
  17446. return row.map(exporter.formatFieldAsCsv).join(separator);
  17447. };
  17448. },
  17449. /**
  17450. * @ngdoc function
  17451. * @name formatFieldAsCsv
  17452. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17453. * @description Renders a single field as a csv field, including
  17454. * quotes around the value
  17455. * @param {field} field the field to be turned into a csv string,
  17456. * may be of any type
  17457. * @returns {string} a csv-ified version of the field
  17458. */
  17459. formatFieldAsCsv: function (field) {
  17460. if (field.value == null) { // we want to catch anything null-ish, hence just == not ===
  17461. return '';
  17462. }
  17463. if (typeof(field.value) === 'number') {
  17464. return field.value;
  17465. }
  17466. if (typeof(field.value) === 'boolean') {
  17467. return (field.value ? 'TRUE' : 'FALSE') ;
  17468. }
  17469. if (typeof(field.value) === 'string') {
  17470. return '"' + field.value.replace(/"/g,'""') + '"';
  17471. }
  17472. return JSON.stringify(field.value);
  17473. },
  17474. /**
  17475. * @ngdoc function
  17476. * @name isIE
  17477. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17478. * @description Checks whether current browser is IE and returns it's version if it is
  17479. */
  17480. isIE: function () {
  17481. var match = navigator.userAgent.search(/(?:Edge|MSIE|Trident\/.*; rv:)/);
  17482. var isIE = false;
  17483. if (match !== -1) {
  17484. isIE = true;
  17485. }
  17486. return isIE;
  17487. },
  17488. /**
  17489. * @ngdoc function
  17490. * @name downloadFile
  17491. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17492. * @description Triggers download of a csv file. Logic provided
  17493. * by @cssensei (from his colleagues at https://github.com/ifeelgoods) in issue #2391
  17494. * @param {string} fileName the filename we'd like our file to be
  17495. * given
  17496. * @param {string} csvContent the csv content that we'd like to
  17497. * download as a file
  17498. * @param {boolean} exporterOlderExcelCompatibility whether or not we put a utf-16 BOM on the from (\uFEFF)
  17499. * @param {boolean} exporterIsExcelCompatible whether or not we add separator header ('sep=X')
  17500. */
  17501. downloadFile: function (fileName, csvContent, columnSeparator, exporterOlderExcelCompatibility, exporterIsExcelCompatible) {
  17502. var D = document;
  17503. var a = D.createElement('a');
  17504. var strMimeType = 'application/octet-stream;charset=utf-8';
  17505. var rawFile;
  17506. var ieVersion = this.isIE();
  17507. if (exporterIsExcelCompatible) {
  17508. csvContent = 'sep=' + columnSeparator + '\r\n' + csvContent;
  17509. }
  17510. // IE10+
  17511. if (navigator.msSaveBlob) {
  17512. return navigator.msSaveOrOpenBlob(
  17513. new Blob(
  17514. [exporterOlderExcelCompatibility ? "\uFEFF" : '', csvContent],
  17515. { type: strMimeType } ),
  17516. fileName
  17517. );
  17518. }
  17519. if (ieVersion) {
  17520. var frame = D.createElement('iframe');
  17521. document.body.appendChild(frame);
  17522. frame.contentWindow.document.open('text/html', 'replace');
  17523. frame.contentWindow.document.write(csvContent);
  17524. frame.contentWindow.document.close();
  17525. frame.contentWindow.focus();
  17526. frame.contentWindow.document.execCommand('SaveAs', true, fileName);
  17527. document.body.removeChild(frame);
  17528. return true;
  17529. }
  17530. //html5 A[download]
  17531. if ('download' in a) {
  17532. var blob = new Blob(
  17533. [exporterOlderExcelCompatibility ? "\uFEFF" : '', csvContent],
  17534. { type: strMimeType }
  17535. );
  17536. rawFile = URL.createObjectURL(blob);
  17537. a.setAttribute('download', fileName);
  17538. } else {
  17539. rawFile = 'data:' + strMimeType + ',' + encodeURIComponent(csvContent);
  17540. a.setAttribute('target', '_blank');
  17541. }
  17542. a.href = rawFile;
  17543. a.setAttribute('style', 'display:none;');
  17544. D.body.appendChild(a);
  17545. setTimeout(function() {
  17546. if (a.click) {
  17547. a.click();
  17548. // Workaround for Safari 5
  17549. } else if (document.createEvent) {
  17550. var eventObj = document.createEvent('MouseEvents');
  17551. eventObj.initEvent('click', true, true);
  17552. a.dispatchEvent(eventObj);
  17553. }
  17554. D.body.removeChild(a);
  17555. }, this.delay);
  17556. },
  17557. /**
  17558. * @ngdoc function
  17559. * @name pdfExport
  17560. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17561. * @description Exports rows from the grid in pdf format,
  17562. * the data exported is selected based on the provided options.
  17563. * Note that this function has a dependency on pdfMake, which must
  17564. * be installed. The resulting pdf opens in a new
  17565. * browser window.
  17566. * @param {Grid} grid the grid from which data should be exported
  17567. * @param {string} rowTypes which rows to export, valid values are
  17568. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  17569. * uiGridExporterConstants.SELECTED
  17570. * @param {string} colTypes which columns to export, valid values are
  17571. * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
  17572. * uiGridExporterConstants.SELECTED
  17573. */
  17574. pdfExport: function (grid, rowTypes, colTypes) {
  17575. var self = this;
  17576. this.loadAllDataIfNeeded(grid, rowTypes, colTypes).then(function () {
  17577. var exportColumnHeaders = self.getColumnHeaders(grid, colTypes);
  17578. var exportData = self.getData(grid, rowTypes, colTypes);
  17579. var docDefinition = self.prepareAsPdf(grid, exportColumnHeaders, exportData);
  17580. if (self.isIE() || navigator.appVersion.indexOf("Edge") !== -1) {
  17581. self.downloadPDF(grid.options.exporterPdfFilename, docDefinition);
  17582. } else {
  17583. pdfMake.createPdf(docDefinition).open();
  17584. }
  17585. });
  17586. },
  17587. /**
  17588. * @ngdoc function
  17589. * @name downloadPdf
  17590. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17591. * @description Generates and retrieves the pdf as a blob, then downloads
  17592. * it as a file. Only used in IE, in all other browsers we use the native
  17593. * pdfMake.open function to just open the PDF
  17594. * @param {string} fileName the filename to give to the pdf, can be set
  17595. * through exporterPdfFilename
  17596. * @param {object} docDefinition a pdf docDefinition that we can generate
  17597. * and get a blob from
  17598. */
  17599. downloadPDF: function (fileName, docDefinition) {
  17600. var D = document;
  17601. var a = D.createElement('a');
  17602. var strMimeType = 'application/octet-stream;charset=utf-8';
  17603. var rawFile;
  17604. var ieVersion;
  17605. ieVersion = this.isIE(); // This is now a boolean value
  17606. var doc = pdfMake.createPdf(docDefinition);
  17607. var blob;
  17608. doc.getBuffer( function (buffer) {
  17609. blob = new Blob([buffer]);
  17610. // IE10+
  17611. if (navigator.msSaveBlob) {
  17612. return navigator.msSaveBlob(
  17613. blob, fileName
  17614. );
  17615. }
  17616. // Previously: && ieVersion < 10
  17617. // ieVersion now returns a boolean for the
  17618. // sake of sanity. We just check `msSaveBlob` first.
  17619. if (ieVersion) {
  17620. var frame = D.createElement('iframe');
  17621. document.body.appendChild(frame);
  17622. frame.contentWindow.document.open("text/html", "replace");
  17623. frame.contentWindow.document.write(blob);
  17624. frame.contentWindow.document.close();
  17625. frame.contentWindow.focus();
  17626. frame.contentWindow.document.execCommand('SaveAs', true, fileName);
  17627. document.body.removeChild(frame);
  17628. return true;
  17629. }
  17630. });
  17631. },
  17632. /**
  17633. * @ngdoc function
  17634. * @name renderAsPdf
  17635. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17636. * @description Renders the data into a pdf, and opens that pdf.
  17637. *
  17638. * @param {Grid} grid the grid from which data should be exported
  17639. * @param {array} exportColumnHeaders an array of column headers,
  17640. * where each header is an object with name, width and maybe alignment
  17641. * @param {array} exportData an array of rows, where each row is
  17642. * an array of column data
  17643. * @returns {object} a pdfMake format document definition, ready
  17644. * for generation
  17645. */
  17646. prepareAsPdf: function(grid, exportColumnHeaders, exportData) {
  17647. var headerWidths = this.calculatePdfHeaderWidths( grid, exportColumnHeaders );
  17648. var headerColumns = exportColumnHeaders.map( function( header ) {
  17649. return { text: header.displayName, style: 'tableHeader' };
  17650. });
  17651. var stringData = exportData.map(this.formatRowAsPdf(this));
  17652. var allData = [headerColumns].concat(stringData);
  17653. var docDefinition = {
  17654. pageOrientation: grid.options.exporterPdfOrientation,
  17655. pageSize: grid.options.exporterPdfPageSize,
  17656. content: [{
  17657. style: 'tableStyle',
  17658. table: {
  17659. headerRows: 1,
  17660. widths: headerWidths,
  17661. body: allData
  17662. }
  17663. }],
  17664. styles: {
  17665. tableStyle: grid.options.exporterPdfTableStyle,
  17666. tableHeader: grid.options.exporterPdfTableHeaderStyle
  17667. },
  17668. defaultStyle: grid.options.exporterPdfDefaultStyle
  17669. };
  17670. if ( grid.options.exporterPdfLayout ){
  17671. docDefinition.layout = grid.options.exporterPdfLayout;
  17672. }
  17673. if ( grid.options.exporterPdfHeader ){
  17674. docDefinition.header = grid.options.exporterPdfHeader;
  17675. }
  17676. if ( grid.options.exporterPdfFooter ){
  17677. docDefinition.footer = grid.options.exporterPdfFooter;
  17678. }
  17679. if ( grid.options.exporterPdfCustomFormatter ){
  17680. docDefinition = grid.options.exporterPdfCustomFormatter( docDefinition );
  17681. }
  17682. return docDefinition;
  17683. },
  17684. /**
  17685. * @ngdoc function
  17686. * @name calculatePdfHeaderWidths
  17687. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17688. * @description Determines the column widths base on the
  17689. * widths we got from the grid. If the column is drawn
  17690. * then we have a drawnWidth. If the column is not visible
  17691. * then we have '*', 'x%' or a width. When columns are
  17692. * not visible they don't contribute to the overall gridWidth,
  17693. * so we need to adjust to allow for extra columns
  17694. *
  17695. * Our basic heuristic is to take the current gridWidth, plus
  17696. * numeric columns and call this the base gridwidth.
  17697. *
  17698. * To that we add 100 for any '*' column, and x% of the base gridWidth
  17699. * for any column that is a %
  17700. *
  17701. * @param {Grid} grid the grid from which data should be exported
  17702. * @param {array} exportHeaders array of header information
  17703. * @returns {object} an array of header widths
  17704. */
  17705. calculatePdfHeaderWidths: function ( grid, exportHeaders ) {
  17706. var baseGridWidth = 0;
  17707. exportHeaders.forEach( function(value){
  17708. if (typeof(value.width) === 'number'){
  17709. baseGridWidth += value.width;
  17710. }
  17711. });
  17712. var extraColumns = 0;
  17713. exportHeaders.forEach( function(value){
  17714. if (value.width === '*'){
  17715. extraColumns += 100;
  17716. }
  17717. if (typeof(value.width) === 'string' && value.width.match(/(\d)*%/)) {
  17718. var percent = parseInt(value.width.match(/(\d)*%/)[0]);
  17719. value.width = baseGridWidth * percent / 100;
  17720. extraColumns += value.width;
  17721. }
  17722. });
  17723. var gridWidth = baseGridWidth + extraColumns;
  17724. return exportHeaders.map(function( header ) {
  17725. return header.width === '*' ? header.width : header.width * grid.options.exporterPdfMaxGridWidth / gridWidth;
  17726. });
  17727. },
  17728. /**
  17729. * @ngdoc function
  17730. * @name formatRowAsPdf
  17731. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17732. * @description Renders a row in a format consumable by PDF,
  17733. * mainly meaning casting everything to a string
  17734. * @param {exporterService} exporter pass in exporter
  17735. * @param {array} row the row to be turned into a csv string
  17736. * @returns {string} a csv-ified version of the row
  17737. */
  17738. formatRowAsPdf: function ( exporter ) {
  17739. return function( row ) {
  17740. return row.map(exporter.formatFieldAsPdfString);
  17741. };
  17742. },
  17743. /**
  17744. * @ngdoc function
  17745. * @name formatFieldAsCsv
  17746. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17747. * @description Renders a single field as a pdf-able field, which
  17748. * is different from a csv field only in that strings don't have quotes
  17749. * around them
  17750. * @param {field} field the field to be turned into a pdf string,
  17751. * may be of any type
  17752. * @returns {string} a string-ified version of the field
  17753. */
  17754. formatFieldAsPdfString: function (field) {
  17755. var returnVal;
  17756. if (field.value == null) { // we want to catch anything null-ish, hence just == not ===
  17757. returnVal = '';
  17758. } else if (typeof(field.value) === 'number') {
  17759. returnVal = field.value.toString();
  17760. } else if (typeof(field.value) === 'boolean') {
  17761. returnVal = (field.value ? 'TRUE' : 'FALSE') ;
  17762. } else if (typeof(field.value) === 'string') {
  17763. returnVal = field.value.replace(/"/g,'""');
  17764. } else if (field.value instanceof Date) {
  17765. returnVal = JSON.stringify(field.value).replace(/^"/,'').replace(/"$/,'');
  17766. } else if (typeof(field.value) === 'object') {
  17767. returnVal = field.value;
  17768. } else {
  17769. returnVal = JSON.stringify(field.value).replace(/^"/,'').replace(/"$/,'');
  17770. }
  17771. if (field.alignment && typeof(field.alignment) === 'string' ){
  17772. returnVal = { text: returnVal, alignment: field.alignment };
  17773. }
  17774. return returnVal;
  17775. },
  17776. /**
  17777. * @ngdoc function
  17778. * @name formatAsExcel
  17779. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17780. * @description Formats the column headers and data as a excel,
  17781. * and sends that data to the user
  17782. * @param {array} exportColumnHeaders an array of column headers,
  17783. * where each header is an object with name, width and maybe alignment
  17784. * @param {array} exportData an array of rows, where each row is
  17785. * an array of column data
  17786. * @param {string} separator a string that represents the separator to be used in the csv file
  17787. * @returns {string} csv the formatted excel as a string
  17788. */
  17789. formatAsExcel: function (exportColumnHeaders, exportData, workbook, sheet, docDefinition) {
  17790. var self = this;
  17791. var bareHeaders = exportColumnHeaders.map(function(header){return { value: header.displayName };});
  17792. var sheetData = [];
  17793. var headerData = [];
  17794. for (var i = 0; i < bareHeaders.length; i++) {
  17795. // TODO - probably need callback to determine header value and header styling
  17796. var exportStyle = 'header';
  17797. switch (exportColumnHeaders[i].align) {
  17798. case 'center':
  17799. exportStyle = 'headerCenter';
  17800. break;
  17801. case 'right':
  17802. exportStyle = 'headerRight';
  17803. break;
  17804. }
  17805. var metadata = (docDefinition.styles && docDefinition.styles[exportStyle]) ? {style: docDefinition.styles[exportStyle].id} : null;
  17806. headerData.push({value: bareHeaders[i].value, metadata: metadata});
  17807. }
  17808. sheetData.push(headerData);
  17809. var result = exportData.map(this.formatRowAsExcel(this, workbook, sheet));
  17810. for (var j = 0; j<result.length; j++) {
  17811. sheetData.push(result[j]);
  17812. }
  17813. return sheetData;
  17814. },
  17815. /**
  17816. * @ngdoc function
  17817. * @name formatRowAsExcel
  17818. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17819. * @description Renders a single field as a csv field, including
  17820. * quotes around the value
  17821. * @param {exporterService} exporter pass in exporter
  17822. * @param {array} row the row to be turned into a excel string
  17823. * @returns {array} array of cell objects (i.e. {value: x, metadata: y})
  17824. */
  17825. formatRowAsExcel: function (exporter, workbook, sheet) {
  17826. return function (row) {
  17827. var values = [];
  17828. for (var i = 0; i<row.length; i++) {
  17829. var value = exporter.formatFieldAsExcel(row[i], workbook, sheet);
  17830. values.push({value: value, metadata: row[i].metadata});
  17831. }
  17832. return values;
  17833. };
  17834. },
  17835. /**
  17836. * @ngdoc function
  17837. * @name formatFieldAsExcel
  17838. * @methodOf ui.grid.exporter.service:uiGridExporterService
  17839. * @description Renders a single field as a csv field, including
  17840. * quotes around the value
  17841. * @param {field} field the field to be turned into a csv string,
  17842. * may be of any type
  17843. * @returns {string} a excel-ified version of the field
  17844. */
  17845. formatFieldAsExcel: function (field, workbook, sheet, formatters) {
  17846. if (field.value == null) { // we want to catch anything null-ish, hence just == not ===
  17847. return '';
  17848. }
  17849. if (typeof(field.value) === 'number') {
  17850. return field.value;
  17851. }
  17852. if (typeof(field.value) === 'boolean') {
  17853. return (field.value ? 'TRUE' : 'FALSE') ;
  17854. }
  17855. if (typeof(field.value) === 'string') {
  17856. return field.value.replace(/"/g,'""');
  17857. }
  17858. return JSON.stringify(field.value);
  17859. },
  17860. prepareAsExcel: function(grid, workbook, sheet) {
  17861. var docDefinition = {
  17862. styles: {
  17863. }
  17864. };
  17865. if ( grid.options.exporterExcelCustomFormatters ){
  17866. docDefinition = grid.options.exporterExcelCustomFormatters( grid, workbook, docDefinition );
  17867. }
  17868. if ( grid.options.exporterExcelHeader ) {
  17869. if (angular.isFunction( grid.options.exporterExcelHeader )) {
  17870. grid.options.exporterExcelHeader(grid, workbook, sheet, docDefinition);
  17871. } else {
  17872. var headerText = grid.options.exporterExcelHeader.text;
  17873. var style = grid.options.exporterExcelHeader.style;
  17874. sheet.data.push([{value: headerText, metadata: {style: docDefinition.styles[style].id}}]);
  17875. }
  17876. }
  17877. return docDefinition;
  17878. },
  17879. excelExport: function (grid, rowTypes, colTypes) {
  17880. var self = this;
  17881. this.loadAllDataIfNeeded(grid, rowTypes, colTypes).then(function() {
  17882. var exportColumnHeaders = grid.options.showHeader ? self.getColumnHeaders(grid, colTypes) : [];
  17883. var workbook = new ExcelBuilder.Workbook();
  17884. var aName = grid.options.exporterExcelSheetName ? grid.options.exporterExcelSheetName : 'Sheet1';
  17885. var sheet = new ExcelBuilder.Worksheet({name: aName});
  17886. workbook.addWorksheet(sheet);
  17887. var docDefinition = self.prepareAsExcel(grid, workbook, sheet);
  17888. // The standard column width in Microsoft Excel 2000 is 8.43 characters based on fixed-width Courier font
  17889. // Width of 10 in excel is 75 pixels
  17890. var colWidths = [];
  17891. var startDataIndex = grid.treeBase ? grid.treeBase.numberLevels : (grid.enableRowSelection !== false ? 1 : 0);
  17892. for (var i = startDataIndex; i < grid.columns.length; i++) {
  17893. colWidths.push({width: (grid.columns[i].drawnWidth / 75) * 10});
  17894. }
  17895. sheet.setColumns(colWidths);
  17896. var exportData = self.getData(grid, rowTypes, colTypes, grid.options.exporterFieldApplyFilters);
  17897. // set column widhths. See function called from prepareAsExcel method
  17898. //sheet.setColumns(docDefinition.columnWidths);
  17899. //for (var i=0; i< grid.treeBase.tree.length; i++) {
  17900. // console.log(grid.treeBase.tree[i]);
  17901. //}
  17902. var excelContent = self.formatAsExcel(exportColumnHeaders, exportData, workbook, sheet, docDefinition);
  17903. sheet.setData(sheet.data.concat(excelContent));
  17904. ExcelBuilder.Builder.createFile(workbook, {type:"blob"}).then(function(result) {
  17905. self.downloadFile (grid.options.exporterExcelFilename, result, grid.options.exporterCsvColumnSeparator, grid.options.exporterOlderExcelCompatibility);
  17906. });
  17907. });
  17908. }
  17909. };
  17910. function getDisplayName(grid, gridCol) {
  17911. if (grid.options.exporterHeaderFilter) {
  17912. return grid.options.exporterHeaderFilterUseName ?
  17913. grid.options.exporterHeaderFilter(gridCol.name) :
  17914. grid.options.exporterHeaderFilter(gridCol.displayName);
  17915. }
  17916. return gridCol.headerCellFilter ?
  17917. $filter(gridCol.headerCellFilter)(gridCol.displayName) :
  17918. gridCol.displayName;
  17919. }
  17920. function defaultExporterFieldCallback(grid, row, col, value) {
  17921. return col.cellFilter ? $filter(col.cellFilter)(value) : value;
  17922. }
  17923. return service;
  17924. }
  17925. ]);
  17926. /**
  17927. * @ngdoc directive
  17928. * @name ui.grid.exporter.directive:uiGridExporter
  17929. * @element div
  17930. * @restrict A
  17931. *
  17932. * @description Adds exporter features to grid
  17933. *
  17934. * @example
  17935. <example module="app">
  17936. <file name="app.js">
  17937. var app = angular.module('app', ['ui.grid', 'ui.grid.exporter']);
  17938. app.controller('MainCtrl', ['$scope', function ($scope) {
  17939. $scope.data = [
  17940. { name: 'Bob', title: 'CEO' },
  17941. { name: 'Frank', title: 'Lowly Developer' }
  17942. ];
  17943. $scope.gridOptions = {
  17944. enableGridMenu: true,
  17945. exporterMenuCsv: false,
  17946. columnDefs: [
  17947. {name: 'name', enableCellEdit: true},
  17948. {name: 'title', enableCellEdit: true}
  17949. ],
  17950. data: $scope.data
  17951. };
  17952. }]);
  17953. </file>
  17954. <file name="index.html">
  17955. <div ng-controller="MainCtrl">
  17956. <div ui-grid="gridOptions" ui-grid-exporter></div>
  17957. </div>
  17958. </file>
  17959. </example>
  17960. */
  17961. module.directive('uiGridExporter', ['uiGridExporterConstants', 'uiGridExporterService', 'gridUtil', '$compile',
  17962. function (uiGridExporterConstants, uiGridExporterService, gridUtil, $compile) {
  17963. return {
  17964. replace: true,
  17965. priority: 0,
  17966. require: '^uiGrid',
  17967. scope: false,
  17968. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  17969. uiGridExporterService.initializeGrid(uiGridCtrl.grid);
  17970. uiGridCtrl.grid.exporter.$scope = $scope;
  17971. }
  17972. };
  17973. }
  17974. ]);
  17975. })();
  17976. (function () {
  17977. 'use strict';
  17978. /**
  17979. * @ngdoc overview
  17980. * @name ui.grid.grouping
  17981. * @description
  17982. *
  17983. * # ui.grid.grouping
  17984. *
  17985. * <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>
  17986. *
  17987. * This module provides grouping of rows based on the data in them, similar
  17988. * in concept to excel grouping. You can group multiple columns, resulting in
  17989. * nested grouping.
  17990. *
  17991. * In concept this feature is similar to sorting + grid footer/aggregation, it
  17992. * sorts the data based on the grouped columns, then creates group rows that
  17993. * reflect a break in the data. Each of those group rows can have aggregations for
  17994. * the data within that group.
  17995. *
  17996. * This feature leverages treeBase to provide the tree functionality itself,
  17997. * the key thing this feature does therefore is to set treeLevels on the rows
  17998. * and insert the group headers.
  17999. *
  18000. * Design information:
  18001. * -------------------
  18002. *
  18003. * Each column will get new menu items - group by, and aggregate by. Group by
  18004. * will cause this column to be sorted (if not already), and will move this column
  18005. * to the front of the sorted columns (i.e. grouped columns take precedence over
  18006. * sorted columns). It will respect the sort order already set if there is one,
  18007. * and it will allow the sorting logic to change that sort order, it just forces
  18008. * the column to the front of the sorting. You can group by multiple columns, the
  18009. * logic will add this column to the sorting after any already grouped columns.
  18010. *
  18011. * Once a grouping is defined, grouping logic is added to the rowsProcessors. This
  18012. * will process the rows, identifying a break in the data value, and inserting a grouping row.
  18013. * Grouping rows have specific attributes on them:
  18014. *
  18015. * - internalRow = true: tells us that this isn't a real row, so we can ignore it
  18016. * from any processing that it looking at core data rows. This is used by the core
  18017. * logic (or will be one day), as it's not grouping specific
  18018. * - groupHeader = true: tells us this is a groupHeader. This is used by the grouping logic
  18019. * to know if this is a groupHeader row or not
  18020. *
  18021. * Since the logic is baked into the rowsProcessors, it should get triggered whenever
  18022. * row order or filtering or anything like that is changed. In order to avoid the row instantiation
  18023. * time, and to preserve state across invocations, we hold a cache of the rows that we created
  18024. * last time, and we use them again this time if we can.
  18025. *
  18026. * By default rows are collapsed, which means all data rows have their visible property
  18027. * set to false, and only level 0 group rows are set to visible.
  18028. *
  18029. * <br/>
  18030. * <br/>
  18031. *
  18032. * <div doc-module-components="ui.grid.grouping"></div>
  18033. */
  18034. var module = angular.module('ui.grid.grouping', ['ui.grid', 'ui.grid.treeBase']);
  18035. /**
  18036. * @ngdoc object
  18037. * @name ui.grid.grouping.constant:uiGridGroupingConstants
  18038. *
  18039. * @description constants available in grouping module, this includes
  18040. * all the constants declared in the treeBase module (these are manually copied
  18041. * as there isn't an easy way to include constants in another constants file, and
  18042. * we don't want to make users include treeBase)
  18043. *
  18044. */
  18045. module.constant('uiGridGroupingConstants', {
  18046. featureName: "grouping",
  18047. rowHeaderColName: 'treeBaseRowHeaderCol',
  18048. EXPANDED: 'expanded',
  18049. COLLAPSED: 'collapsed',
  18050. aggregation: {
  18051. COUNT: 'count',
  18052. SUM: 'sum',
  18053. MAX: 'max',
  18054. MIN: 'min',
  18055. AVG: 'avg'
  18056. }
  18057. });
  18058. /**
  18059. * @ngdoc service
  18060. * @name ui.grid.grouping.service:uiGridGroupingService
  18061. *
  18062. * @description Services for grouping features
  18063. */
  18064. module.service('uiGridGroupingService', ['$q', 'uiGridGroupingConstants', 'gridUtil', 'rowSorter', 'GridRow', 'gridClassFactory', 'i18nService', 'uiGridConstants', 'uiGridTreeBaseService',
  18065. function ($q, uiGridGroupingConstants, gridUtil, rowSorter, GridRow, gridClassFactory, i18nService, uiGridConstants, uiGridTreeBaseService) {
  18066. var service = {
  18067. initializeGrid: function (grid, $scope) {
  18068. uiGridTreeBaseService.initializeGrid( grid, $scope );
  18069. //add feature namespace and any properties to grid for needed
  18070. /**
  18071. * @ngdoc object
  18072. * @name ui.grid.grouping.grid:grouping
  18073. *
  18074. * @description Grid properties and functions added for grouping
  18075. */
  18076. grid.grouping = {};
  18077. /**
  18078. * @ngdoc property
  18079. * @propertyOf ui.grid.grouping.grid:grouping
  18080. * @name groupHeaderCache
  18081. *
  18082. * @description Cache that holds the group header rows we created last time, we'll
  18083. * reuse these next time, not least because they hold our expanded states.
  18084. *
  18085. * We need to take care with these that they don't become a memory leak, we
  18086. * create a new cache each time using the values from the old cache. This works
  18087. * so long as we're creating group rows for invisible rows as well.
  18088. *
  18089. * The cache is a nested hash, indexed on the value we grouped by. So if we
  18090. * grouped by gender then age, we'd maybe have something like:
  18091. * ```
  18092. * {
  18093. * male: {
  18094. * row: <pointer to the old row>,
  18095. * children: {
  18096. * 22: { row: <pointer to the old row> },
  18097. * 31: { row: <pointer to the old row> }
  18098. * },
  18099. * female: {
  18100. * row: <pointer to the old row>,
  18101. * children: {
  18102. * 28: { row: <pointer to the old row> },
  18103. * 55: { row: <pointer to the old row> }
  18104. * }
  18105. * }
  18106. * ```
  18107. *
  18108. * We create new rows for any missing rows, this means that they come in as collapsed.
  18109. *
  18110. */
  18111. grid.grouping.groupHeaderCache = {};
  18112. service.defaultGridOptions(grid.options);
  18113. grid.registerRowsProcessor(service.groupRows, 400);
  18114. grid.registerColumnBuilder( service.groupingColumnBuilder);
  18115. grid.registerColumnsProcessor(service.groupingColumnProcessor, 400);
  18116. /**
  18117. * @ngdoc object
  18118. * @name ui.grid.grouping.api:PublicApi
  18119. *
  18120. * @description Public Api for grouping feature
  18121. */
  18122. var publicApi = {
  18123. events: {
  18124. grouping: {
  18125. /**
  18126. * @ngdoc event
  18127. * @eventOf ui.grid.grouping.api:PublicApi
  18128. * @name aggregationChanged
  18129. * @description raised whenever aggregation is changed, added or removed from a column
  18130. *
  18131. * <pre>
  18132. * gridApi.grouping.on.aggregationChanged(scope,function(col){})
  18133. * </pre>
  18134. * @param {GridColumn} col the column which on which aggregation changed. The aggregation
  18135. * type is available as `col.treeAggregation.type`
  18136. */
  18137. aggregationChanged: {},
  18138. /**
  18139. * @ngdoc event
  18140. * @eventOf ui.grid.grouping.api:PublicApi
  18141. * @name groupingChanged
  18142. * @description raised whenever the grouped columns changes
  18143. *
  18144. * <pre>
  18145. * gridApi.grouping.on.groupingChanged(scope,function(col){})
  18146. * </pre>
  18147. * @param {GridColumn} col the column which on which grouping changed. The new grouping is
  18148. * available as `col.grouping`
  18149. */
  18150. groupingChanged: {}
  18151. }
  18152. },
  18153. methods: {
  18154. grouping: {
  18155. /**
  18156. * @ngdoc function
  18157. * @name getGrouping
  18158. * @methodOf ui.grid.grouping.api:PublicApi
  18159. * @description Get the grouping configuration for this grid,
  18160. * used by the saveState feature. Adds expandedState to the information
  18161. * provided by the internal getGrouping, and removes any aggregations that have a source
  18162. * of grouping (i.e. will be automatically reapplied when we regroup the column)
  18163. * Returned grouping is an object
  18164. * `{ grouping: groupArray, treeAggregations: aggregateArray, expandedState: hash }`
  18165. * where grouping contains an array of objects:
  18166. * `{ field: column.field, colName: column.name, groupPriority: column.grouping.groupPriority }`
  18167. * and aggregations contains an array of objects:
  18168. * `{ field: column.field, colName: column.name, aggregation: column.grouping.aggregation }`
  18169. * and expandedState is a hash of the currently expanded nodes
  18170. *
  18171. * The groupArray will be sorted by groupPriority.
  18172. *
  18173. * @param {boolean} getExpanded whether or not to return the expanded state
  18174. * @returns {object} grouping configuration
  18175. */
  18176. getGrouping: function ( getExpanded ) {
  18177. var grouping = service.getGrouping(grid);
  18178. grouping.grouping.forEach( function( group ) {
  18179. group.colName = group.col.name;
  18180. delete group.col;
  18181. });
  18182. grouping.aggregations.forEach( function( aggregation ) {
  18183. aggregation.colName = aggregation.col.name;
  18184. delete aggregation.col;
  18185. });
  18186. grouping.aggregations = grouping.aggregations.filter( function( aggregation ){
  18187. return !aggregation.aggregation.source || aggregation.aggregation.source !== 'grouping';
  18188. });
  18189. if ( getExpanded ){
  18190. grouping.rowExpandedStates = service.getRowExpandedStates( grid.grouping.groupingHeaderCache );
  18191. }
  18192. return grouping;
  18193. },
  18194. /**
  18195. * @ngdoc function
  18196. * @name setGrouping
  18197. * @methodOf ui.grid.grouping.api:PublicApi
  18198. * @description Set the grouping configuration for this grid,
  18199. * used by the saveState feature, but can also be used by any
  18200. * user to specify a combined grouping and aggregation configuration
  18201. * @param {object} config the config you want to apply, in the format
  18202. * provided out by getGrouping
  18203. */
  18204. setGrouping: function ( config ) {
  18205. service.setGrouping(grid, config);
  18206. },
  18207. /**
  18208. * @ngdoc function
  18209. * @name groupColumn
  18210. * @methodOf ui.grid.grouping.api:PublicApi
  18211. * @description Adds this column to the existing grouping, at the end of the priority order.
  18212. * If the column doesn't have a sort, adds one, by default ASC
  18213. *
  18214. * This column will move to the left of any non-group columns, the
  18215. * move is handled in a columnProcessor, so gets called as part of refresh
  18216. *
  18217. * @param {string} columnName the name of the column we want to group
  18218. */
  18219. groupColumn: function( columnName ) {
  18220. var column = grid.getColumn(columnName);
  18221. service.groupColumn(grid, column);
  18222. },
  18223. /**
  18224. * @ngdoc function
  18225. * @name ungroupColumn
  18226. * @methodOf ui.grid.grouping.api:PublicApi
  18227. * @description Removes the groupPriority from this column. If the
  18228. * column was previously aggregated the aggregation will come back.
  18229. * The sort will remain.
  18230. *
  18231. * This column will move to the right of any other group columns, the
  18232. * move is handled in a columnProcessor, so gets called as part of refresh
  18233. *
  18234. * @param {string} columnName the name of the column we want to ungroup
  18235. */
  18236. ungroupColumn: function( columnName ) {
  18237. var column = grid.getColumn(columnName);
  18238. service.ungroupColumn(grid, column);
  18239. },
  18240. /**
  18241. * @ngdoc function
  18242. * @name clearGrouping
  18243. * @methodOf ui.grid.grouping.api:PublicApi
  18244. * @description Clear any grouped columns and any aggregations. Doesn't remove sorting,
  18245. * as we don't know whether that sorting was added by grouping or was there beforehand
  18246. *
  18247. */
  18248. clearGrouping: function() {
  18249. service.clearGrouping(grid);
  18250. },
  18251. /**
  18252. * @ngdoc function
  18253. * @name aggregateColumn
  18254. * @methodOf ui.grid.grouping.api:PublicApi
  18255. * @description Sets the aggregation type on a column, if the
  18256. * column is currently grouped then it removes the grouping first.
  18257. * If the aggregationDef is null then will result in the aggregation
  18258. * being removed
  18259. *
  18260. * @param {string} columnName the column we want to aggregate
  18261. * @param {string} or {function} aggregationDef one of the recognised types
  18262. * from uiGridGroupingConstants or a custom aggregation function.
  18263. * @param {string} aggregationLabel (optional) The label to use for this aggregation.
  18264. */
  18265. aggregateColumn: function( columnName, aggregationDef, aggregationLabel){
  18266. var column = grid.getColumn(columnName);
  18267. service.aggregateColumn( grid, column, aggregationDef, aggregationLabel);
  18268. }
  18269. }
  18270. }
  18271. };
  18272. grid.api.registerEventsFromObject(publicApi.events);
  18273. grid.api.registerMethodsFromObject(publicApi.methods);
  18274. grid.api.core.on.sortChanged( $scope, service.tidyPriorities);
  18275. },
  18276. defaultGridOptions: function (gridOptions) {
  18277. //default option to true unless it was explicitly set to false
  18278. /**
  18279. * @ngdoc object
  18280. * @name ui.grid.grouping.api:GridOptions
  18281. *
  18282. * @description GridOptions for grouping feature, these are available to be
  18283. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  18284. */
  18285. /**
  18286. * @ngdoc object
  18287. * @name enableGrouping
  18288. * @propertyOf ui.grid.grouping.api:GridOptions
  18289. * @description Enable row grouping for entire grid.
  18290. * <br/>Defaults to true
  18291. */
  18292. gridOptions.enableGrouping = gridOptions.enableGrouping !== false;
  18293. /**
  18294. * @ngdoc object
  18295. * @name groupingShowCounts
  18296. * @propertyOf ui.grid.grouping.api:GridOptions
  18297. * @description shows counts on the groupHeader rows. Not that if you are using a cellFilter or a
  18298. * sortingAlgorithm which relies on a specific format or data type, showing counts may cause that
  18299. * to break, since the group header rows will always be a string with groupingShowCounts enabled.
  18300. * <br/>Defaults to true except on columns of types 'date' and 'object'
  18301. */
  18302. gridOptions.groupingShowCounts = gridOptions.groupingShowCounts !== false;
  18303. /**
  18304. * @ngdoc object
  18305. * @name groupingNullLabel
  18306. * @propertyOf ui.grid.grouping.api:GridOptions
  18307. * @description The string to use for the grouping header row label on rows which contain a null or undefined value in the grouped column.
  18308. * <br/>Defaults to "Null"
  18309. */
  18310. gridOptions.groupingNullLabel = typeof(gridOptions.groupingNullLabel) === 'undefined' ? 'Null' : gridOptions.groupingNullLabel;
  18311. /**
  18312. * @ngdoc object
  18313. * @name enableGroupHeaderSelection
  18314. * @propertyOf ui.grid.grouping.api:GridOptions
  18315. * @description Allows group header rows to be selected.
  18316. * <br/>Defaults to false
  18317. */
  18318. gridOptions.enableGroupHeaderSelection = gridOptions.enableGroupHeaderSelection === true;
  18319. },
  18320. /**
  18321. * @ngdoc function
  18322. * @name groupingColumnBuilder
  18323. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18324. * @description Sets the grouping defaults based on the columnDefs
  18325. *
  18326. * @param {object} colDef columnDef we're basing on
  18327. * @param {GridColumn} col the column we're to update
  18328. * @param {object} gridOptions the options we should use
  18329. * @returns {promise} promise for the builder - actually we do it all inline so it's immediately resolved
  18330. */
  18331. groupingColumnBuilder: function (colDef, col, gridOptions) {
  18332. /**
  18333. * @ngdoc object
  18334. * @name ui.grid.grouping.api:ColumnDef
  18335. *
  18336. * @description ColumnDef for grouping feature, these are available to be
  18337. * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs}
  18338. */
  18339. /**
  18340. * @ngdoc object
  18341. * @name enableGrouping
  18342. * @propertyOf ui.grid.grouping.api:ColumnDef
  18343. * @description Enable grouping on this column
  18344. * <br/>Defaults to true.
  18345. */
  18346. if (colDef.enableGrouping === false){
  18347. return;
  18348. }
  18349. /**
  18350. * @ngdoc object
  18351. * @name grouping
  18352. * @propertyOf ui.grid.grouping.api:ColumnDef
  18353. * @description Set the grouping for a column. Format is:
  18354. * ```
  18355. * {
  18356. * groupPriority: <number, starts at 0, if less than 0 or undefined then we're aggregating in this column>
  18357. * }
  18358. * ```
  18359. *
  18360. * **Note that aggregation used to be included in grouping, but is now separately set on the column via treeAggregation
  18361. * setting in treeBase**
  18362. *
  18363. * We group in the priority order given, this will also put these columns to the high order of the sort irrespective
  18364. * of the sort priority given them. If there is no sort defined then we sort ascending, if there is a sort defined then
  18365. * we use that sort.
  18366. *
  18367. * If the groupPriority is undefined or less than 0, then we expect to be aggregating, and we look at the
  18368. * aggregation types to determine what sort of aggregation we can do. Values are in the constants file, but
  18369. * include SUM, COUNT, MAX, MIN
  18370. *
  18371. * groupPriorities should generally be sequential, if they're not then the next time getGrouping is called
  18372. * we'll renumber them to be sequential.
  18373. * <br/>Defaults to undefined.
  18374. */
  18375. if ( typeof(col.grouping) === 'undefined' && typeof(colDef.grouping) !== 'undefined') {
  18376. col.grouping = angular.copy(colDef.grouping);
  18377. if ( typeof(col.grouping.groupPriority) !== 'undefined' && col.grouping.groupPriority > -1 ){
  18378. col.treeAggregationFn = uiGridTreeBaseService.nativeAggregations()[uiGridGroupingConstants.aggregation.COUNT].aggregationFn;
  18379. col.treeAggregationFinalizerFn = service.groupedFinalizerFn;
  18380. }
  18381. } else if (typeof(col.grouping) === 'undefined'){
  18382. col.grouping = {};
  18383. }
  18384. if (typeof(col.grouping) !== 'undefined' && typeof(col.grouping.groupPriority) !== 'undefined' && col.grouping.groupPriority >= 0){
  18385. col.suppressRemoveSort = true;
  18386. }
  18387. var groupColumn = {
  18388. name: 'ui.grid.grouping.group',
  18389. title: i18nService.get().grouping.group,
  18390. icon: 'ui-grid-icon-indent-right',
  18391. shown: function () {
  18392. return typeof(this.context.col.grouping) === 'undefined' ||
  18393. typeof(this.context.col.grouping.groupPriority) === 'undefined' ||
  18394. this.context.col.grouping.groupPriority < 0;
  18395. },
  18396. action: function () {
  18397. service.groupColumn( this.context.col.grid, this.context.col );
  18398. }
  18399. };
  18400. var ungroupColumn = {
  18401. name: 'ui.grid.grouping.ungroup',
  18402. title: i18nService.get().grouping.ungroup,
  18403. icon: 'ui-grid-icon-indent-left',
  18404. shown: function () {
  18405. return typeof(this.context.col.grouping) !== 'undefined' &&
  18406. typeof(this.context.col.grouping.groupPriority) !== 'undefined' &&
  18407. this.context.col.grouping.groupPriority >= 0;
  18408. },
  18409. action: function () {
  18410. service.ungroupColumn( this.context.col.grid, this.context.col );
  18411. }
  18412. };
  18413. var aggregateRemove = {
  18414. name: 'ui.grid.grouping.aggregateRemove',
  18415. title: i18nService.get().grouping.aggregate_remove,
  18416. shown: function () {
  18417. return typeof(this.context.col.treeAggregationFn) !== 'undefined';
  18418. },
  18419. action: function () {
  18420. service.aggregateColumn( this.context.col.grid, this.context.col, null);
  18421. }
  18422. };
  18423. // generic adder for the aggregation menus, which follow a pattern
  18424. var addAggregationMenu = function(type, title){
  18425. title = title || i18nService.get().grouping['aggregate_' + type] || type;
  18426. var menuItem = {
  18427. name: 'ui.grid.grouping.aggregate' + type,
  18428. title: title,
  18429. shown: function () {
  18430. return typeof(this.context.col.treeAggregation) === 'undefined' ||
  18431. typeof(this.context.col.treeAggregation.type) === 'undefined' ||
  18432. this.context.col.treeAggregation.type !== type;
  18433. },
  18434. action: function () {
  18435. service.aggregateColumn( this.context.col.grid, this.context.col, type);
  18436. }
  18437. };
  18438. if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.grouping.aggregate' + type)) {
  18439. col.menuItems.push(menuItem);
  18440. }
  18441. };
  18442. /**
  18443. * @ngdoc object
  18444. * @name groupingShowGroupingMenu
  18445. * @propertyOf ui.grid.grouping.api:ColumnDef
  18446. * @description Show the grouping (group and ungroup items) menu on this column
  18447. * <br/>Defaults to true.
  18448. */
  18449. if ( col.colDef.groupingShowGroupingMenu !== false ){
  18450. if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.grouping.group')) {
  18451. col.menuItems.push(groupColumn);
  18452. }
  18453. if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.grouping.ungroup')) {
  18454. col.menuItems.push(ungroupColumn);
  18455. }
  18456. }
  18457. /**
  18458. * @ngdoc object
  18459. * @name groupingShowAggregationMenu
  18460. * @propertyOf ui.grid.grouping.api:ColumnDef
  18461. * @description Show the aggregation menu on this column
  18462. * <br/>Defaults to true.
  18463. */
  18464. if ( col.colDef.groupingShowAggregationMenu !== false ){
  18465. angular.forEach(uiGridTreeBaseService.nativeAggregations(), function(aggregationDef, name){
  18466. addAggregationMenu(name);
  18467. });
  18468. angular.forEach(gridOptions.treeCustomAggregations, function(aggregationDef, name){
  18469. addAggregationMenu(name, aggregationDef.menuTitle);
  18470. });
  18471. if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.grouping.aggregateRemove')) {
  18472. col.menuItems.push(aggregateRemove);
  18473. }
  18474. }
  18475. },
  18476. /**
  18477. * @ngdoc function
  18478. * @name groupingColumnProcessor
  18479. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18480. * @description Moves the columns around based on which are grouped
  18481. *
  18482. * @param {array} columns the columns to consider rendering
  18483. * @param {array} rows the grid rows, which we don't use but are passed to us
  18484. * @returns {array} updated columns array
  18485. */
  18486. groupingColumnProcessor: function( columns, rows ) {
  18487. var grid = this;
  18488. columns = service.moveGroupColumns(this, columns, rows);
  18489. return columns;
  18490. },
  18491. /**
  18492. * @ngdoc function
  18493. * @name groupedFinalizerFn
  18494. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18495. * @description Used on group columns to display the rendered value and optionally
  18496. * display the count of rows.
  18497. *
  18498. * @param {aggregation} the aggregation entity for a grouped column
  18499. */
  18500. groupedFinalizerFn: function( aggregation ){
  18501. var col = this;
  18502. if ( typeof(aggregation.groupVal) !== 'undefined') {
  18503. aggregation.rendered = aggregation.groupVal;
  18504. if ( col.grid.options.groupingShowCounts && col.colDef.type !== 'date' && col.colDef.type !== 'object' ){
  18505. aggregation.rendered += (' (' + aggregation.value + ')');
  18506. }
  18507. } else {
  18508. aggregation.rendered = null;
  18509. }
  18510. },
  18511. /**
  18512. * @ngdoc function
  18513. * @name moveGroupColumns
  18514. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18515. * @description Moves the column order so that the grouped columns are lined up
  18516. * to the left (well, unless you're RTL, then it's the right). By doing this in
  18517. * the columnsProcessor, we make it transient - when the column is ungrouped it'll
  18518. * go back to where it was.
  18519. *
  18520. * Does nothing if the option `moveGroupColumns` is set to false.
  18521. *
  18522. * @param {Grid} grid grid object
  18523. * @param {array} columns the columns that we should process/move
  18524. * @param {array} rows the grid rows
  18525. * @returns {array} updated columns
  18526. */
  18527. moveGroupColumns: function( grid, columns, rows ){
  18528. if ( grid.options.moveGroupColumns === false){
  18529. return columns;
  18530. }
  18531. columns.forEach( function(column, index){
  18532. // position used to make stable sort in moveGroupColumns
  18533. column.groupingPosition = index;
  18534. });
  18535. columns.sort(function(a, b){
  18536. var a_group, b_group;
  18537. if (a.isRowHeader){
  18538. a_group = a.headerPriority;
  18539. }
  18540. else if ( typeof(a.grouping) === 'undefined' || typeof(a.grouping.groupPriority) === 'undefined' || a.grouping.groupPriority < 0){
  18541. a_group = null;
  18542. } else {
  18543. a_group = a.grouping.groupPriority;
  18544. }
  18545. if (b.isRowHeader){
  18546. b_group = b.headerPriority;
  18547. }
  18548. else if ( typeof(b.grouping) === 'undefined' || typeof(b.grouping.groupPriority) === 'undefined' || b.grouping.groupPriority < 0){
  18549. b_group = null;
  18550. } else {
  18551. b_group = b.grouping.groupPriority;
  18552. }
  18553. // groups get sorted to the top
  18554. if ( a_group !== null && b_group === null) { return -1; }
  18555. if ( b_group !== null && a_group === null) { return 1; }
  18556. if ( a_group !== null && b_group !== null) {return a_group - b_group; }
  18557. return a.groupingPosition - b.groupingPosition;
  18558. });
  18559. columns.forEach( function(column, index) {
  18560. delete column.groupingPosition;
  18561. });
  18562. return columns;
  18563. },
  18564. /**
  18565. * @ngdoc function
  18566. * @name groupColumn
  18567. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18568. * @description Adds this column to the existing grouping, at the end of the priority order.
  18569. * If the column doesn't have a sort, adds one, by default ASC
  18570. *
  18571. * This column will move to the left of any non-group columns, the
  18572. * move is handled in a columnProcessor, so gets called as part of refresh
  18573. *
  18574. * @param {Grid} grid grid object
  18575. * @param {GridColumn} column the column we want to group
  18576. */
  18577. groupColumn: function( grid, column){
  18578. if ( typeof(column.grouping) === 'undefined' ){
  18579. column.grouping = {};
  18580. }
  18581. // set the group priority to the next number in the hierarchy
  18582. var existingGrouping = service.getGrouping( grid );
  18583. column.grouping.groupPriority = existingGrouping.grouping.length;
  18584. // save sort in order to restore it when column is ungrouped
  18585. column.previousSort = angular.copy(column.sort);
  18586. // add sort if not present
  18587. if ( !column.sort ){
  18588. column.sort = { direction: uiGridConstants.ASC };
  18589. } else if ( typeof(column.sort.direction) === 'undefined' || column.sort.direction === null ){
  18590. column.sort.direction = uiGridConstants.ASC;
  18591. }
  18592. column.treeAggregation = { type: uiGridGroupingConstants.aggregation.COUNT, source: 'grouping' };
  18593. column.treeAggregationFn = uiGridTreeBaseService.nativeAggregations()[uiGridGroupingConstants.aggregation.COUNT].aggregationFn;
  18594. column.treeAggregationFinalizerFn = service.groupedFinalizerFn;
  18595. grid.api.grouping.raise.groupingChanged(column);
  18596. // This indirectly calls service.tidyPriorities( grid );
  18597. grid.api.core.raise.sortChanged(grid, grid.getColumnSorting());
  18598. grid.queueGridRefresh();
  18599. },
  18600. /**
  18601. * @ngdoc function
  18602. * @name ungroupColumn
  18603. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18604. * @description Removes the groupPriority from this column. If the
  18605. * column was previously aggregated the aggregation will come back.
  18606. * The sort will remain.
  18607. *
  18608. * This column will move to the right of any other group columns, the
  18609. * move is handled in a columnProcessor, so gets called as part of refresh
  18610. *
  18611. * @param {Grid} grid grid object
  18612. * @param {GridColumn} column the column we want to ungroup
  18613. */
  18614. ungroupColumn: function( grid, column){
  18615. if ( typeof(column.grouping) === 'undefined' ){
  18616. return;
  18617. }
  18618. delete column.grouping.groupPriority;
  18619. delete column.treeAggregation;
  18620. delete column.customTreeAggregationFinalizer;
  18621. if (column.previousSort) {
  18622. column.sort = column.previousSort;
  18623. delete column.previousSort;
  18624. }
  18625. service.tidyPriorities( grid );
  18626. grid.api.grouping.raise.groupingChanged(column);
  18627. grid.api.core.raise.sortChanged(grid, grid.getColumnSorting());
  18628. grid.queueGridRefresh();
  18629. },
  18630. /**
  18631. * @ngdoc function
  18632. * @name aggregateColumn
  18633. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18634. * @description Sets the aggregation type on a column, if the
  18635. * column is currently grouped then it removes the grouping first.
  18636. *
  18637. * @param {Grid} grid grid object
  18638. * @param {GridColumn} column the column we want to aggregate
  18639. * @param {string} aggregationType of the recognised types from uiGridGroupingConstants or one of the custom aggregations from gridOptions
  18640. */
  18641. aggregateColumn: function( grid, column, aggregationType){
  18642. if (typeof(column.grouping) !== 'undefined' && typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0){
  18643. service.ungroupColumn( grid, column );
  18644. }
  18645. var aggregationDef = {};
  18646. if ( typeof(grid.options.treeCustomAggregations[aggregationType]) !== 'undefined' ){
  18647. aggregationDef = grid.options.treeCustomAggregations[aggregationType];
  18648. } else if ( typeof(uiGridTreeBaseService.nativeAggregations()[aggregationType]) !== 'undefined' ){
  18649. aggregationDef = uiGridTreeBaseService.nativeAggregations()[aggregationType];
  18650. }
  18651. column.treeAggregation = { type: aggregationType, label: i18nService.get().aggregation[aggregationDef.label] || aggregationDef.label };
  18652. column.treeAggregationFn = aggregationDef.aggregationFn;
  18653. column.treeAggregationFinalizerFn = aggregationDef.finalizerFn;
  18654. grid.api.grouping.raise.aggregationChanged(column);
  18655. grid.queueGridRefresh();
  18656. },
  18657. /**
  18658. * @ngdoc function
  18659. * @name setGrouping
  18660. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18661. * @description Set the grouping based on a config object, used by the save state feature
  18662. * (more specifically, by the restore function in that feature )
  18663. *
  18664. * @param {Grid} grid grid object
  18665. * @param {object} config the config we want to set, same format as that returned by getGrouping
  18666. */
  18667. setGrouping: function ( grid, config ){
  18668. if ( typeof(config) === 'undefined' ){
  18669. return;
  18670. }
  18671. // first remove any existing grouping
  18672. service.clearGrouping(grid);
  18673. if ( config.grouping && config.grouping.length && config.grouping.length > 0 ){
  18674. config.grouping.forEach( function( group ) {
  18675. var col = grid.getColumn(group.colName);
  18676. if ( col ) {
  18677. service.groupColumn( grid, col );
  18678. }
  18679. });
  18680. }
  18681. if ( config.aggregations && config.aggregations.length ){
  18682. config.aggregations.forEach( function( aggregation ) {
  18683. var col = grid.getColumn(aggregation.colName);
  18684. if ( col ) {
  18685. service.aggregateColumn( grid, col, aggregation.aggregation.type );
  18686. }
  18687. });
  18688. }
  18689. if ( config.rowExpandedStates ){
  18690. service.applyRowExpandedStates( grid.grouping.groupingHeaderCache, config.rowExpandedStates );
  18691. }
  18692. },
  18693. /**
  18694. * @ngdoc function
  18695. * @name clearGrouping
  18696. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18697. * @description Clear any grouped columns and any aggregations. Doesn't remove sorting,
  18698. * as we don't know whether that sorting was added by grouping or was there beforehand
  18699. *
  18700. * @param {Grid} grid grid object
  18701. */
  18702. clearGrouping: function( grid ) {
  18703. var currentGrouping = service.getGrouping(grid);
  18704. if ( currentGrouping.grouping.length > 0 ){
  18705. currentGrouping.grouping.forEach( function( group ) {
  18706. if (!group.col){
  18707. // should have a group.colName if there's no col
  18708. group.col = grid.getColumn(group.colName);
  18709. }
  18710. service.ungroupColumn(grid, group.col);
  18711. });
  18712. }
  18713. if ( currentGrouping.aggregations.length > 0 ){
  18714. currentGrouping.aggregations.forEach( function( aggregation ){
  18715. if (!aggregation.col){
  18716. // should have a group.colName if there's no col
  18717. aggregation.col = grid.getColumn(aggregation.colName);
  18718. }
  18719. service.aggregateColumn(grid, aggregation.col, null);
  18720. });
  18721. }
  18722. },
  18723. /**
  18724. * @ngdoc function
  18725. * @name tidyPriorities
  18726. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18727. * @description Renumbers groupPriority and sortPriority such that
  18728. * groupPriority is contiguous, and sortPriority either matches
  18729. * groupPriority (for group columns), and otherwise is contiguous and
  18730. * higher than groupPriority.
  18731. *
  18732. * @param {Grid} grid grid object
  18733. */
  18734. tidyPriorities: function( grid ){
  18735. // if we're called from sortChanged, grid is in this, not passed as param, the param can be a column or undefined
  18736. if ( ( typeof(grid) === 'undefined' || typeof(grid.grid) !== 'undefined' ) && typeof(this.grid) !== 'undefined' ) {
  18737. grid = this.grid;
  18738. }
  18739. var groupArray = [];
  18740. var sortArray = [];
  18741. grid.columns.forEach( function(column, index){
  18742. if ( typeof(column.grouping) !== 'undefined' && typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0){
  18743. groupArray.push(column);
  18744. } else if ( typeof(column.sort) !== 'undefined' && typeof(column.sort.priority) !== 'undefined' && column.sort.priority >= 0){
  18745. sortArray.push(column);
  18746. }
  18747. });
  18748. groupArray.sort(function(a, b){ return a.grouping.groupPriority - b.grouping.groupPriority; });
  18749. groupArray.forEach( function(column, index){
  18750. column.grouping.groupPriority = index;
  18751. column.suppressRemoveSort = true;
  18752. if ( typeof(column.sort) === 'undefined'){
  18753. column.sort = {};
  18754. }
  18755. column.sort.priority = index;
  18756. });
  18757. var i = groupArray.length;
  18758. sortArray.sort(function(a, b){ return a.sort.priority - b.sort.priority; });
  18759. sortArray.forEach( function(column, index){
  18760. column.sort.priority = i;
  18761. column.suppressRemoveSort = column.colDef.suppressRemoveSort;
  18762. i++;
  18763. });
  18764. },
  18765. /**
  18766. * @ngdoc function
  18767. * @name groupRows
  18768. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18769. * @description The rowProcessor that creates the groupHeaders (i.e. does
  18770. * the actual grouping).
  18771. *
  18772. * Assumes it is always called after the sorting processor, guaranteed by the priority setting
  18773. *
  18774. * Processes all the rows in order, inserting a groupHeader row whenever there is a change
  18775. * in value of a grouped row, based on the sortAlgorithm used for the column. The group header row
  18776. * is looked up in the groupHeaderCache, and used from there if there is one. The entity is reset
  18777. * to {} if one is found.
  18778. *
  18779. * As it processes it maintains a `processingState` array. This records, for each level of grouping we're
  18780. * working with, the following information:
  18781. * ```
  18782. * {
  18783. * fieldName: name,
  18784. * col: col,
  18785. * initialised: boolean,
  18786. * currentValue: value,
  18787. * currentRow: gridRow,
  18788. * }
  18789. * ```
  18790. * We look for changes in the currentValue at any of the levels. Where we find a change we:
  18791. *
  18792. * - create a new groupHeader row in the array
  18793. *
  18794. * @param {array} renderableRows the rows we want to process, usually the output from the previous rowProcessor
  18795. * @returns {array} the updated rows, including our new group rows
  18796. */
  18797. groupRows: function( renderableRows ) {
  18798. if (renderableRows.length === 0){
  18799. return renderableRows;
  18800. }
  18801. var grid = this;
  18802. grid.grouping.oldGroupingHeaderCache = grid.grouping.groupingHeaderCache || {};
  18803. grid.grouping.groupingHeaderCache = {};
  18804. var processingState = service.initialiseProcessingState( grid );
  18805. // processes each of the fields we are grouping by, checks if the value has changed and inserts a groupHeader
  18806. // Broken out as shouldn't create functions in a loop.
  18807. var updateProcessingState = function( groupFieldState, stateIndex ) {
  18808. var fieldValue = grid.getCellValue(row, groupFieldState.col);
  18809. // look for change of value - and insert a header
  18810. if ( !groupFieldState.initialised || rowSorter.getSortFn(grid, groupFieldState.col, renderableRows)(fieldValue, groupFieldState.currentValue) !== 0 ){
  18811. service.insertGroupHeader( grid, renderableRows, i, processingState, stateIndex );
  18812. i++;
  18813. }
  18814. };
  18815. // use a for loop because it's tolerant of the array length changing whilst we go - we can
  18816. // manipulate the iterator when we insert groupHeader rows
  18817. for (var i = 0; i < renderableRows.length; i++ ){
  18818. var row = renderableRows[i];
  18819. if ( row.visible ){
  18820. processingState.forEach( updateProcessingState );
  18821. }
  18822. }
  18823. delete grid.grouping.oldGroupingHeaderCache;
  18824. return renderableRows;
  18825. },
  18826. /**
  18827. * @ngdoc function
  18828. * @name initialiseProcessingState
  18829. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18830. * @description Creates the processing state array that is used
  18831. * for groupRows.
  18832. *
  18833. * @param {Grid} grid grid object
  18834. * @returns {array} an array in the format described in the groupRows method,
  18835. * initialised with blank values
  18836. */
  18837. initialiseProcessingState: function( grid ){
  18838. var processingState = [];
  18839. var columnSettings = service.getGrouping( grid );
  18840. columnSettings.grouping.forEach( function( groupItem, index){
  18841. processingState.push({
  18842. fieldName: groupItem.field,
  18843. col: groupItem.col,
  18844. initialised: false,
  18845. currentValue: null,
  18846. currentRow: null
  18847. });
  18848. });
  18849. return processingState;
  18850. },
  18851. /**
  18852. * @ngdoc function
  18853. * @name getGrouping
  18854. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18855. * @description Get the grouping settings from the columns. As a side effect
  18856. * this always renumbers the grouping starting at 0
  18857. * @param {Grid} grid grid object
  18858. * @returns {array} an array of the group fields, in order of priority
  18859. */
  18860. getGrouping: function( grid ){
  18861. var groupArray = [];
  18862. var aggregateArray = [];
  18863. // get all the grouping
  18864. grid.columns.forEach( function(column, columnIndex){
  18865. if ( column.grouping ){
  18866. if ( typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0){
  18867. groupArray.push({ field: column.field, col: column, groupPriority: column.grouping.groupPriority, grouping: column.grouping });
  18868. }
  18869. }
  18870. if ( column.treeAggregation && column.treeAggregation.type ){
  18871. aggregateArray.push({ field: column.field, col: column, aggregation: column.treeAggregation });
  18872. }
  18873. });
  18874. // sort grouping into priority order
  18875. groupArray.sort( function(a, b){
  18876. return a.groupPriority - b.groupPriority;
  18877. });
  18878. // renumber the priority in case it was somewhat messed up, then remove the grouping reference
  18879. groupArray.forEach( function( group, index) {
  18880. group.grouping.groupPriority = index;
  18881. group.groupPriority = index;
  18882. delete group.grouping;
  18883. });
  18884. return { grouping: groupArray, aggregations: aggregateArray };
  18885. },
  18886. /**
  18887. * @ngdoc function
  18888. * @name insertGroupHeader
  18889. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18890. * @description Create a group header row, and link it to the various configuration
  18891. * items that we use.
  18892. *
  18893. * Look for the row in the oldGroupingHeaderCache, write the row into the new groupingHeaderCache.
  18894. *
  18895. * @param {Grid} grid grid object
  18896. * @param {array} renderableRows the rows that we are processing
  18897. * @param {number} rowIndex the row we were up to processing
  18898. * @param {array} processingState the current processing state
  18899. * @param {number} stateIndex the processing state item that we were on when we triggered a new group header -
  18900. * i.e. the column that we want to create a header for
  18901. */
  18902. insertGroupHeader: function( grid, renderableRows, rowIndex, processingState, stateIndex ) {
  18903. // set the value that caused the end of a group into the header row and the processing state
  18904. var fieldName = processingState[stateIndex].fieldName;
  18905. var col = processingState[stateIndex].col;
  18906. var newValue = grid.getCellValue(renderableRows[rowIndex], col);
  18907. var newDisplayValue = newValue;
  18908. if ( typeof(newValue) === 'undefined' || newValue === null ) {
  18909. newDisplayValue = grid.options.groupingNullLabel;
  18910. }
  18911. var getKeyAsValueForCacheMap = function(key) {
  18912. if (angular.isObject(key)) {
  18913. return JSON.stringify(key);
  18914. } else {
  18915. return key;
  18916. }
  18917. };
  18918. var cacheItem = grid.grouping.oldGroupingHeaderCache;
  18919. for ( var i = 0; i < stateIndex; i++ ){
  18920. if ( cacheItem && cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)] ){
  18921. cacheItem = cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)].children;
  18922. }
  18923. }
  18924. var headerRow;
  18925. if ( cacheItem && cacheItem[getKeyAsValueForCacheMap(newValue)]){
  18926. headerRow = cacheItem[getKeyAsValueForCacheMap(newValue)].row;
  18927. headerRow.entity = {};
  18928. } else {
  18929. headerRow = new GridRow( {}, null, grid );
  18930. gridClassFactory.rowTemplateAssigner.call(grid, headerRow);
  18931. }
  18932. headerRow.entity['$$' + processingState[stateIndex].col.uid] = { groupVal: newDisplayValue };
  18933. headerRow.treeLevel = stateIndex;
  18934. headerRow.groupHeader = true;
  18935. headerRow.internalRow = true;
  18936. headerRow.enableCellEdit = false;
  18937. headerRow.enableSelection = grid.options.enableGroupHeaderSelection;
  18938. processingState[stateIndex].initialised = true;
  18939. processingState[stateIndex].currentValue = newValue;
  18940. processingState[stateIndex].currentRow = headerRow;
  18941. // set all processing states below this one to not be initialised - change of this state
  18942. // means all those need to start again
  18943. service.finaliseProcessingState( processingState, stateIndex + 1);
  18944. // insert our new header row
  18945. renderableRows.splice(rowIndex, 0, headerRow);
  18946. // add our new header row to the cache
  18947. cacheItem = grid.grouping.groupingHeaderCache;
  18948. for ( i = 0; i < stateIndex; i++ ){
  18949. cacheItem = cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)].children;
  18950. }
  18951. cacheItem[getKeyAsValueForCacheMap(newValue)] = { row: headerRow, children: {} };
  18952. },
  18953. /**
  18954. * @ngdoc function
  18955. * @name finaliseProcessingState
  18956. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18957. * @description Set all processing states lower than the one that had a break in value to
  18958. * no longer be initialised. Render the counts into the entity ready for display.
  18959. *
  18960. * @param {array} processingState the current processing state
  18961. * @param {number} stateIndex the processing state item that we were on when we triggered a new group header, all
  18962. * processing states after this need to be finalised
  18963. */
  18964. finaliseProcessingState: function( processingState, stateIndex ){
  18965. for ( var i = stateIndex; i < processingState.length; i++){
  18966. processingState[i].initialised = false;
  18967. processingState[i].currentRow = null;
  18968. processingState[i].currentValue = null;
  18969. }
  18970. },
  18971. /**
  18972. * @ngdoc function
  18973. * @name getRowExpandedStates
  18974. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  18975. * @description Extract the groupHeaderCache hash, pulling out only the states.
  18976. *
  18977. * The example below shows a grid that is grouped by gender then age
  18978. *
  18979. * <pre>
  18980. * {
  18981. * male: {
  18982. * state: 'expanded',
  18983. * children: {
  18984. * 22: { state: 'expanded' },
  18985. * 30: { state: 'collapsed' }
  18986. * }
  18987. * },
  18988. * female: {
  18989. * state: 'expanded',
  18990. * children: {
  18991. * 28: { state: 'expanded' },
  18992. * 55: { state: 'collapsed' }
  18993. * }
  18994. * }
  18995. * }
  18996. * </pre>
  18997. *
  18998. * @param {object} treeChildren The tree children elements object
  18999. * @returns {object} the expanded states as an object
  19000. */
  19001. getRowExpandedStates: function(treeChildren){
  19002. if ( typeof(treeChildren) === 'undefined' ){
  19003. return {};
  19004. }
  19005. var newChildren = {};
  19006. angular.forEach( treeChildren, function( value, key ){
  19007. newChildren[key] = { state: value.row.treeNode.state };
  19008. if ( value.children ){
  19009. newChildren[key].children = service.getRowExpandedStates( value.children );
  19010. } else {
  19011. newChildren[key].children = {};
  19012. }
  19013. });
  19014. return newChildren;
  19015. },
  19016. /**
  19017. * @ngdoc function
  19018. * @name applyRowExpandedStates
  19019. * @methodOf ui.grid.grouping.service:uiGridGroupingService
  19020. * @description Take a hash in the format as created by getRowExpandedStates,
  19021. * and apply it to the grid.grouping.groupHeaderCache.
  19022. *
  19023. * Takes a treeSubset, and applies to a treeSubset - so can be called
  19024. * recursively.
  19025. *
  19026. * @param {object} currentNode can be grid.grouping.groupHeaderCache, or any of
  19027. * the children of that hash
  19028. * @param {object} expandedStates can be the full expanded states, or children
  19029. * of that expanded states (which hopefully matches the subset of the groupHeaderCache)
  19030. */
  19031. applyRowExpandedStates: function( currentNode, expandedStates ){
  19032. if ( typeof(expandedStates) === 'undefined' ){
  19033. return;
  19034. }
  19035. angular.forEach(expandedStates, function( value, key ) {
  19036. if ( currentNode[key] ){
  19037. currentNode[key].row.treeNode.state = value.state;
  19038. if (value.children && currentNode[key].children){
  19039. service.applyRowExpandedStates( currentNode[key].children, value.children );
  19040. }
  19041. }
  19042. });
  19043. }
  19044. };
  19045. return service;
  19046. }]);
  19047. /**
  19048. * @ngdoc directive
  19049. * @name ui.grid.grouping.directive:uiGridGrouping
  19050. * @element div
  19051. * @restrict A
  19052. *
  19053. * @description Adds grouping features to grid
  19054. *
  19055. * @example
  19056. <example module="app">
  19057. <file name="app.js">
  19058. var app = angular.module('app', ['ui.grid', 'ui.grid.grouping']);
  19059. app.controller('MainCtrl', ['$scope', function ($scope) {
  19060. $scope.data = [
  19061. { name: 'Bob', title: 'CEO' },
  19062. { name: 'Frank', title: 'Lowly Developer' }
  19063. ];
  19064. $scope.columnDefs = [
  19065. {name: 'name', enableCellEdit: true},
  19066. {name: 'title', enableCellEdit: true}
  19067. ];
  19068. $scope.gridOptions = { columnDefs: $scope.columnDefs, data: $scope.data };
  19069. }]);
  19070. </file>
  19071. <file name="index.html">
  19072. <div ng-controller="MainCtrl">
  19073. <div ui-grid="gridOptions" ui-grid-grouping></div>
  19074. </div>
  19075. </file>
  19076. </example>
  19077. */
  19078. module.directive('uiGridGrouping', ['uiGridGroupingConstants', 'uiGridGroupingService',
  19079. function (uiGridGroupingConstants, uiGridGroupingService) {
  19080. return {
  19081. replace: true,
  19082. priority: 0,
  19083. require: '^uiGrid',
  19084. scope: false,
  19085. compile: function () {
  19086. return {
  19087. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  19088. if (uiGridCtrl.grid.options.enableGrouping !== false){
  19089. uiGridGroupingService.initializeGrid(uiGridCtrl.grid, $scope);
  19090. }
  19091. },
  19092. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  19093. }
  19094. };
  19095. }
  19096. };
  19097. }]);
  19098. })();
  19099. (function () {
  19100. 'use strict';
  19101. /**
  19102. * @ngdoc overview
  19103. * @name ui.grid.importer
  19104. * @description
  19105. *
  19106. * # ui.grid.importer
  19107. *
  19108. * <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>
  19109. *
  19110. * This module provides the ability to import data into the grid. It
  19111. * uses the column defs to work out which data belongs in which column,
  19112. * and creates entities from a configured class (typically a $resource).
  19113. *
  19114. * If the rowEdit feature is enabled, it also calls save on those newly
  19115. * created objects, and then displays any errors in the imported data.
  19116. *
  19117. * Currently the importer imports only CSV and json files, although provision has been
  19118. * made to process other file formats, and these can be added over time.
  19119. *
  19120. * For json files, the properties within each object in the json must match the column names
  19121. * (to put it another way, the importer doesn't process the json, it just copies the objects
  19122. * within the json into a new instance of the specified object type)
  19123. *
  19124. * For CSV import, the default column identification relies on each column in the
  19125. * header row matching a column.name or column.displayName. Optionally, a column identification
  19126. * callback can be used. This allows matching using other attributes, which is particularly
  19127. * useful if your application has internationalised column headings (i.e. the headings that
  19128. * the user sees don't match the column names).
  19129. *
  19130. * The importer makes use of the grid menu as the UI for requesting an
  19131. * import.
  19132. *
  19133. * <div ui-grid-importer></div>
  19134. */
  19135. var module = angular.module('ui.grid.importer', ['ui.grid']);
  19136. /**
  19137. * @ngdoc object
  19138. * @name ui.grid.importer.constant:uiGridImporterConstants
  19139. *
  19140. * @description constants available in importer module
  19141. */
  19142. module.constant('uiGridImporterConstants', {
  19143. featureName: 'importer'
  19144. });
  19145. /**
  19146. * @ngdoc service
  19147. * @name ui.grid.importer.service:uiGridImporterService
  19148. *
  19149. * @description Services for importer feature
  19150. */
  19151. module.service('uiGridImporterService', ['$q', 'uiGridConstants', 'uiGridImporterConstants', 'gridUtil', '$compile', '$interval', 'i18nService', '$window',
  19152. function ($q, uiGridConstants, uiGridImporterConstants, gridUtil, $compile, $interval, i18nService, $window) {
  19153. var service = {
  19154. initializeGrid: function ($scope, grid) {
  19155. //add feature namespace and any properties to grid for needed state
  19156. grid.importer = {
  19157. $scope: $scope
  19158. };
  19159. this.defaultGridOptions(grid.options);
  19160. /**
  19161. * @ngdoc object
  19162. * @name ui.grid.importer.api:PublicApi
  19163. *
  19164. * @description Public Api for importer feature
  19165. */
  19166. var publicApi = {
  19167. events: {
  19168. importer: {
  19169. }
  19170. },
  19171. methods: {
  19172. importer: {
  19173. /**
  19174. * @ngdoc function
  19175. * @name importFile
  19176. * @methodOf ui.grid.importer.api:PublicApi
  19177. * @description Imports a file into the grid using the file object
  19178. * provided. Bypasses the grid menu
  19179. * @param {File} fileObject the file we want to import, as a javascript
  19180. * File object
  19181. */
  19182. importFile: function ( fileObject ) {
  19183. service.importThisFile( grid, fileObject );
  19184. }
  19185. }
  19186. }
  19187. };
  19188. grid.api.registerEventsFromObject(publicApi.events);
  19189. grid.api.registerMethodsFromObject(publicApi.methods);
  19190. if ( grid.options.enableImporter && grid.options.importerShowMenu ){
  19191. if ( grid.api.core.addToGridMenu ){
  19192. service.addToMenu( grid );
  19193. } else {
  19194. // order of registration is not guaranteed, register in a little while
  19195. $interval( function() {
  19196. if (grid.api.core.addToGridMenu){
  19197. service.addToMenu( grid );
  19198. }
  19199. }, 100, 1);
  19200. }
  19201. }
  19202. },
  19203. defaultGridOptions: function (gridOptions) {
  19204. //default option to true unless it was explicitly set to false
  19205. /**
  19206. * @ngdoc object
  19207. * @name ui.grid.importer.api:GridOptions
  19208. *
  19209. * @description GridOptions for importer feature, these are available to be
  19210. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  19211. */
  19212. /**
  19213. * @ngdoc property
  19214. * @propertyOf ui.grid.importer.api:GridOptions
  19215. * @name enableImporter
  19216. * @description Whether or not importer is enabled. Automatically set
  19217. * to false if the user's browser does not support the required fileApi.
  19218. * Otherwise defaults to true.
  19219. *
  19220. */
  19221. if (gridOptions.enableImporter || gridOptions.enableImporter === undefined) {
  19222. if ( !($window.hasOwnProperty('File') && $window.hasOwnProperty('FileReader') && $window.hasOwnProperty('FileList') && $window.hasOwnProperty('Blob')) ) {
  19223. gridUtil.logError('The File APIs are not fully supported in this browser, grid importer cannot be used.');
  19224. gridOptions.enableImporter = false;
  19225. } else {
  19226. gridOptions.enableImporter = true;
  19227. }
  19228. } else {
  19229. gridOptions.enableImporter = false;
  19230. }
  19231. /**
  19232. * @ngdoc method
  19233. * @name importerProcessHeaders
  19234. * @methodOf ui.grid.importer.api:GridOptions
  19235. * @description A callback function that will process headers using custom
  19236. * logic. Set this callback function if the headers that your user will provide in their
  19237. * import file don't necessarily match the grid header or field names. This might commonly
  19238. * occur where your application is internationalised, and therefore the field names
  19239. * that the user recognises are in a different language than the field names that
  19240. * ui-grid knows about.
  19241. *
  19242. * Defaults to the internal `processHeaders` method, which seeks to match using both
  19243. * displayName and column.name. Any non-matching columns are discarded.
  19244. *
  19245. * Your callback routine should respond by processing the header array, and returning an array
  19246. * of matching column names. A null value in any given position means "don't import this column"
  19247. *
  19248. * <pre>
  19249. * gridOptions.importerProcessHeaders: function( headerArray ) {
  19250. * var myHeaderColumns = [];
  19251. * var thisCol;
  19252. * headerArray.forEach( function( value, index ) {
  19253. * thisCol = mySpecialLookupFunction( value );
  19254. * myHeaderColumns.push( thisCol.name );
  19255. * });
  19256. *
  19257. * return myHeaderCols;
  19258. * })
  19259. * </pre>
  19260. * @param {Grid} grid the grid we're importing into
  19261. * @param {array} headerArray an array of the text from the first row of the csv file,
  19262. * which you need to match to column.names
  19263. * @returns {array} array of matching column names, in the same order as the headerArray
  19264. *
  19265. */
  19266. gridOptions.importerProcessHeaders = gridOptions.importerProcessHeaders || service.processHeaders;
  19267. /**
  19268. * @ngdoc method
  19269. * @name importerHeaderFilter
  19270. * @methodOf ui.grid.importer.api:GridOptions
  19271. * @description A callback function that will filter (usually translate) a single
  19272. * header. Used when you want to match the passed in column names to the column
  19273. * displayName after the header filter.
  19274. *
  19275. * Your callback routine needs to return the filtered header value.
  19276. * <pre>
  19277. * gridOptions.importerHeaderFilter: function( displayName ) {
  19278. * return $translate.instant( displayName );
  19279. * })
  19280. * </pre>
  19281. *
  19282. * or:
  19283. * <pre>
  19284. * gridOptions.importerHeaderFilter: $translate.instant
  19285. * </pre>
  19286. * @param {string} displayName the displayName that we'd like to translate
  19287. * @returns {string} the translated name
  19288. *
  19289. */
  19290. gridOptions.importerHeaderFilter = gridOptions.importerHeaderFilter || function( displayName ) { return displayName; };
  19291. /**
  19292. * @ngdoc method
  19293. * @name importerErrorCallback
  19294. * @methodOf ui.grid.importer.api:GridOptions
  19295. * @description A callback function that provides custom error handling, rather
  19296. * than the standard grid behaviour of an alert box and a console message. You
  19297. * might use this to internationalise the console log messages, or to write to a
  19298. * custom logging routine that returned errors to the server.
  19299. *
  19300. * <pre>
  19301. * gridOptions.importerErrorCallback: function( grid, errorKey, consoleMessage, context ) {
  19302. * myUserDisplayRoutine( errorKey );
  19303. * myLoggingRoutine( consoleMessage, context );
  19304. * })
  19305. * </pre>
  19306. * @param {Grid} grid the grid we're importing into, may be useful if you're positioning messages
  19307. * in some way
  19308. * @param {string} errorKey one of the i18n keys the importer can return - importer.noHeaders,
  19309. * importer.noObjects, importer.invalidCsv, importer.invalidJson, importer.jsonNotArray
  19310. * @param {string} consoleMessage the English console message that importer would have written
  19311. * @param {object} context the context data that importer would have appended to that console message,
  19312. * often the file content itself or the element that is in error
  19313. *
  19314. */
  19315. if ( !gridOptions.importerErrorCallback || typeof(gridOptions.importerErrorCallback) !== 'function' ){
  19316. delete gridOptions.importerErrorCallback;
  19317. }
  19318. /**
  19319. * @ngdoc method
  19320. * @name importerDataAddCallback
  19321. * @methodOf ui.grid.importer.api:GridOptions
  19322. * @description A mandatory callback function that adds data to the source data array. The grid
  19323. * generally doesn't add rows to the source data array, it is tidier to handle this through a user
  19324. * callback.
  19325. *
  19326. * <pre>
  19327. * gridOptions.importerDataAddCallback: function( grid, newObjects ) {
  19328. * $scope.myData = $scope.myData.concat( newObjects );
  19329. * })
  19330. * </pre>
  19331. * @param {Grid} grid the grid we're importing into, may be useful in some way
  19332. * @param {array} newObjects an array of new objects that you should add to your data
  19333. *
  19334. */
  19335. if ( gridOptions.enableImporter === true && !gridOptions.importerDataAddCallback ) {
  19336. gridUtil.logError("You have not set an importerDataAddCallback, importer is disabled");
  19337. gridOptions.enableImporter = false;
  19338. }
  19339. /**
  19340. * @ngdoc object
  19341. * @name importerNewObject
  19342. * @propertyOf ui.grid.importer.api:GridOptions
  19343. * @description An object on which we call `new` to create each new row before inserting it into
  19344. * the data array. Typically this would be a $resource entity, which means that if you're using
  19345. * the rowEdit feature, you can directly call save on this entity when the save event is triggered.
  19346. *
  19347. * Defaults to a vanilla javascript object
  19348. *
  19349. * @example
  19350. * <pre>
  19351. * gridOptions.importerNewObject = MyRes;
  19352. * </pre>
  19353. *
  19354. */
  19355. /**
  19356. * @ngdoc property
  19357. * @propertyOf ui.grid.importer.api:GridOptions
  19358. * @name importerShowMenu
  19359. * @description Whether or not to show an item in the grid menu. Defaults to true.
  19360. *
  19361. */
  19362. gridOptions.importerShowMenu = gridOptions.importerShowMenu !== false;
  19363. /**
  19364. * @ngdoc method
  19365. * @methodOf ui.grid.importer.api:GridOptions
  19366. * @name importerObjectCallback
  19367. * @description A callback that massages the data for each object. For example,
  19368. * you might have data stored as a code value, but display the decode. This callback
  19369. * can be used to change the decoded value back into a code. Defaults to doing nothing.
  19370. * @param {Grid} grid in case you need it
  19371. * @param {object} newObject the new object as importer has created it, modify it
  19372. * then return the modified version
  19373. * @returns {object} the modified object
  19374. * @example
  19375. * <pre>
  19376. * gridOptions.importerObjectCallback = function ( grid, newObject ) {
  19377. * switch newObject.status {
  19378. * case 'Active':
  19379. * newObject.status = 1;
  19380. * break;
  19381. * case 'Inactive':
  19382. * newObject.status = 2;
  19383. * break;
  19384. * }
  19385. * return newObject;
  19386. * };
  19387. * </pre>
  19388. */
  19389. gridOptions.importerObjectCallback = gridOptions.importerObjectCallback || function( grid, newObject ) { return newObject; };
  19390. },
  19391. /**
  19392. * @ngdoc function
  19393. * @name addToMenu
  19394. * @methodOf ui.grid.importer.service:uiGridImporterService
  19395. * @description Adds import menu item to the grid menu,
  19396. * allowing the user to request import of a file
  19397. * @param {Grid} grid the grid into which data should be imported
  19398. */
  19399. addToMenu: function ( grid ) {
  19400. grid.api.core.addToGridMenu( grid, [
  19401. {
  19402. title: i18nService.getSafeText('gridMenu.importerTitle'),
  19403. order: 150
  19404. },
  19405. {
  19406. templateUrl: 'ui-grid/importerMenuItemContainer',
  19407. action: function ($event) {
  19408. this.grid.api.importer.importAFile( grid );
  19409. },
  19410. order: 151
  19411. }
  19412. ]);
  19413. },
  19414. /**
  19415. * @ngdoc function
  19416. * @name importThisFile
  19417. * @methodOf ui.grid.importer.service:uiGridImporterService
  19418. * @description Imports the provided file into the grid using the file object
  19419. * provided. Bypasses the grid menu
  19420. * @param {Grid} grid the grid we're importing into
  19421. * @param {File} fileObject the file we want to import, as returned from the File
  19422. * javascript object
  19423. */
  19424. importThisFile: function ( grid, fileObject ) {
  19425. if (!fileObject){
  19426. gridUtil.logError( 'No file object provided to importThisFile, should be impossible, aborting');
  19427. return;
  19428. }
  19429. var reader = new FileReader();
  19430. switch ( fileObject.type ){
  19431. case 'application/json':
  19432. reader.onload = service.importJsonClosure( grid );
  19433. break;
  19434. default:
  19435. reader.onload = service.importCsvClosure( grid );
  19436. break;
  19437. }
  19438. reader.readAsText( fileObject );
  19439. },
  19440. /**
  19441. * @ngdoc function
  19442. * @name importJson
  19443. * @methodOf ui.grid.importer.service:uiGridImporterService
  19444. * @description Creates a function that imports a json file into the grid.
  19445. * The json data is imported into new objects of type `gridOptions.importerNewObject`,
  19446. * and if the rowEdit feature is enabled the rows are marked as dirty
  19447. * @param {Grid} grid the grid we want to import into
  19448. * @param {FileObject} importFile the file that we want to import, as
  19449. * a FileObject
  19450. */
  19451. importJsonClosure: function( grid ) {
  19452. return function( importFile ){
  19453. var newObjects = [];
  19454. var newObject;
  19455. var importArray = service.parseJson( grid, importFile );
  19456. if (importArray === null){
  19457. return;
  19458. }
  19459. importArray.forEach( function( value, index ) {
  19460. newObject = service.newObject( grid );
  19461. angular.extend( newObject, value );
  19462. newObject = grid.options.importerObjectCallback( grid, newObject );
  19463. newObjects.push( newObject );
  19464. });
  19465. service.addObjects( grid, newObjects );
  19466. };
  19467. },
  19468. /**
  19469. * @ngdoc function
  19470. * @name parseJson
  19471. * @methodOf ui.grid.importer.service:uiGridImporterService
  19472. * @description Parses a json file, returns the parsed data.
  19473. * Displays an error if file doesn't parse
  19474. * @param {Grid} grid the grid that we want to import into
  19475. * @param {FileObject} importFile the file that we want to import, as
  19476. * a FileObject
  19477. * @returns {array} array of objects from the imported json
  19478. */
  19479. parseJson: function( grid, importFile ){
  19480. var loadedObjects;
  19481. try {
  19482. loadedObjects = JSON.parse( importFile.target.result );
  19483. } catch (e) {
  19484. service.alertError( grid, 'importer.invalidJson', 'File could not be processed, is it valid json? Content was: ', importFile.target.result );
  19485. return;
  19486. }
  19487. if ( !Array.isArray( loadedObjects ) ){
  19488. service.alertError( grid, 'importer.jsonNotarray', 'Import failed, file is not an array, file was: ', importFile.target.result );
  19489. return [];
  19490. } else {
  19491. return loadedObjects;
  19492. }
  19493. },
  19494. /**
  19495. * @ngdoc function
  19496. * @name importCsvClosure
  19497. * @methodOf ui.grid.importer.service:uiGridImporterService
  19498. * @description Creates a function that imports a csv file into the grid
  19499. * (allowing it to be used in the reader.onload event)
  19500. * @param {Grid} grid the grid that we want to import into
  19501. * @param {FileObject} importFile the file that we want to import, as
  19502. * a file object
  19503. */
  19504. importCsvClosure: function( grid ) {
  19505. return function( importFile ){
  19506. var importArray = service.parseCsv( importFile );
  19507. if ( !importArray || importArray.length < 1 ){
  19508. service.alertError( grid, 'importer.invalidCsv', 'File could not be processed, is it valid csv? Content was: ', importFile.target.result );
  19509. return;
  19510. }
  19511. var newObjects = service.createCsvObjects( grid, importArray );
  19512. if ( !newObjects || newObjects.length === 0 ){
  19513. service.alertError( grid, 'importer.noObjects', 'Objects were not able to be derived, content was: ', importFile.target.result );
  19514. return;
  19515. }
  19516. service.addObjects( grid, newObjects );
  19517. };
  19518. },
  19519. /**
  19520. * @ngdoc function
  19521. * @name parseCsv
  19522. * @methodOf ui.grid.importer.service:uiGridImporterService
  19523. * @description Parses a csv file into an array of arrays, with the first
  19524. * array being the headers, and the remaining arrays being the data.
  19525. * The logic for this comes from https://github.com/thetalecrafter/excel.js/blob/master/src/csv.js,
  19526. * which is noted as being under the MIT license. The code is modified to pass the jscs yoda condition
  19527. * checker
  19528. * @param {FileObject} importFile the file that we want to import, as a
  19529. * file object
  19530. */
  19531. parseCsv: function( importFile ) {
  19532. var csv = importFile.target.result;
  19533. // use the CSV-JS library to parse
  19534. return CSV.parse(csv);
  19535. },
  19536. /**
  19537. * @ngdoc function
  19538. * @name createCsvObjects
  19539. * @methodOf ui.grid.importer.service:uiGridImporterService
  19540. * @description Converts an array of arrays (representing the csv file)
  19541. * into a set of objects. Uses the provided `gridOptions.importerNewObject`
  19542. * to create the objects, and maps the header row into the individual columns
  19543. * using either `gridOptions.importerProcessHeaders`, or by using a native method
  19544. * of matching to either the displayName, column name or column field of
  19545. * the columns in the column defs. The resulting objects will have attributes
  19546. * that are named based on the column.field or column.name, in that order.
  19547. * @param {Grid} grid the grid that we want to import into
  19548. * @param {Array} importArray the data that we want to import, as an array
  19549. */
  19550. createCsvObjects: function( grid, importArray ){
  19551. // pull off header row and turn into headers
  19552. var headerMapping = grid.options.importerProcessHeaders( grid, importArray.shift() );
  19553. if ( !headerMapping || headerMapping.length === 0 ){
  19554. service.alertError( grid, 'importer.noHeaders', 'Column names could not be derived, content was: ', importArray );
  19555. return [];
  19556. }
  19557. var newObjects = [];
  19558. var newObject;
  19559. importArray.forEach( function( row, index ) {
  19560. newObject = service.newObject( grid );
  19561. if ( row !== null ){
  19562. row.forEach( function( field, index ){
  19563. if ( headerMapping[index] !== null ){
  19564. newObject[ headerMapping[index] ] = field;
  19565. }
  19566. });
  19567. }
  19568. newObject = grid.options.importerObjectCallback( grid, newObject );
  19569. newObjects.push( newObject );
  19570. });
  19571. return newObjects;
  19572. },
  19573. /**
  19574. * @ngdoc function
  19575. * @name processHeaders
  19576. * @methodOf ui.grid.importer.service:uiGridImporterService
  19577. * @description Determines the columns that the header row from
  19578. * a csv (or other) file represents.
  19579. * @param {Grid} grid the grid we're importing into
  19580. * @param {array} headerRow the header row that we wish to match against
  19581. * the column definitions
  19582. * @returns {array} an array of the attribute names that should be used
  19583. * for that column, based on matching the headers or creating the headers
  19584. *
  19585. */
  19586. processHeaders: function( grid, headerRow ) {
  19587. var headers = [];
  19588. if ( !grid.options.columnDefs || grid.options.columnDefs.length === 0 ){
  19589. // we are going to create new columnDefs for all these columns, so just remove
  19590. // spaces from the names to create fields
  19591. headerRow.forEach( function( value, index ) {
  19592. headers.push( value.replace( /[^0-9a-zA-Z\-_]/g, '_' ) );
  19593. });
  19594. return headers;
  19595. } else {
  19596. var lookupHash = service.flattenColumnDefs( grid, grid.options.columnDefs );
  19597. headerRow.forEach( function( value, index ) {
  19598. if ( lookupHash[value] ) {
  19599. headers.push( lookupHash[value] );
  19600. } else if ( lookupHash[ value.toLowerCase() ] ) {
  19601. headers.push( lookupHash[ value.toLowerCase() ] );
  19602. } else {
  19603. headers.push( null );
  19604. }
  19605. });
  19606. return headers;
  19607. }
  19608. },
  19609. /**
  19610. * @name flattenColumnDefs
  19611. * @methodOf ui.grid.importer.service:uiGridImporterService
  19612. * @description Runs through the column defs and creates a hash of
  19613. * the displayName, name and field, and of each of those values forced to lower case,
  19614. * with each pointing to the field or name
  19615. * (whichever is present). Used to lookup column headers and decide what
  19616. * attribute name to give to the resulting field.
  19617. * @param {Grid} grid the grid we're importing into
  19618. * @param {array} columnDefs the columnDefs that we should flatten
  19619. * @returns {hash} the flattened version of the column def information, allowing
  19620. * us to look up a value by `flattenedHash[ headerValue ]`
  19621. */
  19622. flattenColumnDefs: function( grid, columnDefs ){
  19623. var flattenedHash = {};
  19624. columnDefs.forEach( function( columnDef, index) {
  19625. if ( columnDef.name ){
  19626. flattenedHash[ columnDef.name ] = columnDef.field || columnDef.name;
  19627. flattenedHash[ columnDef.name.toLowerCase() ] = columnDef.field || columnDef.name;
  19628. }
  19629. if ( columnDef.field ){
  19630. flattenedHash[ columnDef.field ] = columnDef.field || columnDef.name;
  19631. flattenedHash[ columnDef.field.toLowerCase() ] = columnDef.field || columnDef.name;
  19632. }
  19633. if ( columnDef.displayName ){
  19634. flattenedHash[ columnDef.displayName ] = columnDef.field || columnDef.name;
  19635. flattenedHash[ columnDef.displayName.toLowerCase() ] = columnDef.field || columnDef.name;
  19636. }
  19637. if ( columnDef.displayName && grid.options.importerHeaderFilter ){
  19638. flattenedHash[ grid.options.importerHeaderFilter(columnDef.displayName) ] = columnDef.field || columnDef.name;
  19639. flattenedHash[ grid.options.importerHeaderFilter(columnDef.displayName).toLowerCase() ] = columnDef.field || columnDef.name;
  19640. }
  19641. });
  19642. return flattenedHash;
  19643. },
  19644. /**
  19645. * @ngdoc function
  19646. * @name addObjects
  19647. * @methodOf ui.grid.importer.service:uiGridImporterService
  19648. * @description Inserts our new objects into the grid data, and
  19649. * sets the rows to dirty if the rowEdit feature is being used
  19650. *
  19651. * Does this by registering a watch on dataChanges, which essentially
  19652. * is waiting on the result of the grid data watch, and downstream processing.
  19653. *
  19654. * When the callback is called, it deregisters itself - we don't want to run
  19655. * again next time data is added.
  19656. *
  19657. * If we never get called, we deregister on destroy.
  19658. *
  19659. * @param {Grid} grid the grid we're importing into
  19660. * @param {array} newObjects the objects we want to insert into the grid data
  19661. * @returns {object} the new object
  19662. */
  19663. addObjects: function( grid, newObjects, $scope ){
  19664. if ( grid.api.rowEdit ){
  19665. var dataChangeDereg = grid.registerDataChangeCallback( function() {
  19666. grid.api.rowEdit.setRowsDirty( newObjects );
  19667. dataChangeDereg();
  19668. }, [uiGridConstants.dataChange.ROW] );
  19669. grid.importer.$scope.$on( '$destroy', dataChangeDereg );
  19670. }
  19671. grid.importer.$scope.$apply( grid.options.importerDataAddCallback( grid, newObjects ) );
  19672. },
  19673. /**
  19674. * @ngdoc function
  19675. * @name newObject
  19676. * @methodOf ui.grid.importer.service:uiGridImporterService
  19677. * @description Makes a new object based on `gridOptions.importerNewObject`,
  19678. * or based on an empty object if not present
  19679. * @param {Grid} grid the grid we're importing into
  19680. * @returns {object} the new object
  19681. */
  19682. newObject: function( grid ){
  19683. if ( typeof(grid.options) !== "undefined" && typeof(grid.options.importerNewObject) !== "undefined" ){
  19684. return new grid.options.importerNewObject();
  19685. } else {
  19686. return {};
  19687. }
  19688. },
  19689. /**
  19690. * @ngdoc function
  19691. * @name alertError
  19692. * @methodOf ui.grid.importer.service:uiGridImporterService
  19693. * @description Provides an internationalised user alert for the failure,
  19694. * and logs a console message including diagnostic content.
  19695. * Optionally, if the the `gridOptions.importerErrorCallback` routine
  19696. * is defined, then calls that instead, allowing user specified error routines
  19697. * @param {Grid} grid the grid we're importing into
  19698. * @param {array} headerRow the header row that we wish to match against
  19699. * the column definitions
  19700. */
  19701. alertError: function( grid, alertI18nToken, consoleMessage, context ){
  19702. if ( grid.options.importerErrorCallback ){
  19703. grid.options.importerErrorCallback( grid, alertI18nToken, consoleMessage, context );
  19704. } else {
  19705. $window.alert(i18nService.getSafeText( alertI18nToken ));
  19706. gridUtil.logError(consoleMessage + context );
  19707. }
  19708. }
  19709. };
  19710. return service;
  19711. }
  19712. ]);
  19713. /**
  19714. * @ngdoc directive
  19715. * @name ui.grid.importer.directive:uiGridImporter
  19716. * @element div
  19717. * @restrict A
  19718. *
  19719. * @description Adds importer features to grid
  19720. *
  19721. */
  19722. module.directive('uiGridImporter', ['uiGridImporterConstants', 'uiGridImporterService', 'gridUtil', '$compile',
  19723. function (uiGridImporterConstants, uiGridImporterService, gridUtil, $compile) {
  19724. return {
  19725. replace: true,
  19726. priority: 0,
  19727. require: '^uiGrid',
  19728. scope: false,
  19729. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  19730. uiGridImporterService.initializeGrid($scope, uiGridCtrl.grid);
  19731. }
  19732. };
  19733. }
  19734. ]);
  19735. /**
  19736. * @ngdoc directive
  19737. * @name ui.grid.importer.directive:uiGridImporterMenuItem
  19738. * @element div
  19739. * @restrict A
  19740. *
  19741. * @description Handles the processing from the importer menu item - once a file is
  19742. * selected
  19743. *
  19744. */
  19745. module.directive('uiGridImporterMenuItem', ['uiGridImporterConstants', 'uiGridImporterService', 'gridUtil', '$compile',
  19746. function (uiGridImporterConstants, uiGridImporterService, gridUtil, $compile) {
  19747. return {
  19748. replace: true,
  19749. priority: 0,
  19750. require: '?^uiGrid',
  19751. scope: false,
  19752. templateUrl: 'ui-grid/importerMenuItem',
  19753. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  19754. var grid;
  19755. function handleFileSelect(event) {
  19756. var target = event.srcElement || event.target;
  19757. if (target && target.files && target.files.length === 1) {
  19758. var fileObject = target.files[0];
  19759. // Define grid if the uiGrid controller is present
  19760. if (typeof(uiGridCtrl) !== 'undefined' && uiGridCtrl) {
  19761. grid = uiGridCtrl.grid;
  19762. uiGridImporterService.importThisFile( grid, fileObject );
  19763. target.form.reset();
  19764. } else {
  19765. gridUtil.logError('Could not import file because UI Grid was not found.');
  19766. }
  19767. }
  19768. }
  19769. var fileChooser = $elm[0].querySelectorAll('.ui-grid-importer-file-chooser');
  19770. if ( fileChooser.length !== 1 ){
  19771. gridUtil.logError('Found > 1 or < 1 file choosers within the menu item, error, cannot continue');
  19772. } else {
  19773. fileChooser[0].addEventListener('change', handleFileSelect, false);
  19774. }
  19775. }
  19776. };
  19777. }
  19778. ]);
  19779. })();
  19780. (function() {
  19781. 'use strict';
  19782. /**
  19783. * @ngdoc overview
  19784. * @name ui.grid.infiniteScroll
  19785. *
  19786. * @description
  19787. *
  19788. * #ui.grid.infiniteScroll
  19789. *
  19790. * <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>
  19791. *
  19792. * This module provides infinite scroll functionality to ui-grid
  19793. *
  19794. */
  19795. var module = angular.module('ui.grid.infiniteScroll', ['ui.grid']);
  19796. /**
  19797. * @ngdoc service
  19798. * @name ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  19799. *
  19800. * @description Service for infinite scroll features
  19801. */
  19802. module.service('uiGridInfiniteScrollService', ['gridUtil', '$compile', '$rootScope', 'uiGridConstants', 'ScrollEvent', '$q', function (gridUtil, $compile, $rootScope, uiGridConstants, ScrollEvent, $q) {
  19803. var service = {
  19804. /**
  19805. * @ngdoc function
  19806. * @name initializeGrid
  19807. * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  19808. * @description This method register events and methods into grid public API
  19809. */
  19810. initializeGrid: function(grid, $scope) {
  19811. service.defaultGridOptions(grid.options);
  19812. if (!grid.options.enableInfiniteScroll){
  19813. return;
  19814. }
  19815. grid.infiniteScroll = { dataLoading: false };
  19816. service.setScrollDirections( grid, grid.options.infiniteScrollUp, grid.options.infiniteScrollDown );
  19817. grid.api.core.on.scrollEnd($scope, service.handleScroll);
  19818. /**
  19819. * @ngdoc object
  19820. * @name ui.grid.infiniteScroll.api:PublicAPI
  19821. *
  19822. * @description Public API for infinite scroll feature
  19823. */
  19824. var publicApi = {
  19825. events: {
  19826. infiniteScroll: {
  19827. /**
  19828. * @ngdoc event
  19829. * @name needLoadMoreData
  19830. * @eventOf ui.grid.infiniteScroll.api:PublicAPI
  19831. * @description This event fires when scroll reaches bottom percentage of grid
  19832. * and needs to load data
  19833. */
  19834. needLoadMoreData: function ($scope, fn) {
  19835. },
  19836. /**
  19837. * @ngdoc event
  19838. * @name needLoadMoreDataTop
  19839. * @eventOf ui.grid.infiniteScroll.api:PublicAPI
  19840. * @description This event fires when scroll reaches top percentage of grid
  19841. * and needs to load data
  19842. */
  19843. needLoadMoreDataTop: function ($scope, fn) {
  19844. }
  19845. }
  19846. },
  19847. methods: {
  19848. infiniteScroll: {
  19849. /**
  19850. * @ngdoc function
  19851. * @name dataLoaded
  19852. * @methodOf ui.grid.infiniteScroll.api:PublicAPI
  19853. * @description Call this function when you have loaded the additional data
  19854. * requested. You should set scrollUp and scrollDown to indicate
  19855. * whether there are still more pages in each direction.
  19856. *
  19857. * If you call dataLoaded without first calling `saveScrollPercentage` then we will
  19858. * scroll the user to the start of the newly loaded data, which usually gives a smooth scroll
  19859. * experience, but can give a jumpy experience with large `infiniteScrollRowsFromEnd` values, and
  19860. * on variable speed internet connections. Using `saveScrollPercentage` as demonstrated in the tutorial
  19861. * should give a smoother scrolling experience for users.
  19862. *
  19863. * See infinite_scroll tutorial for example of usage
  19864. * @param {boolean} scrollUp if set to false flags that there are no more pages upwards, so don't fire
  19865. * any more infinite scroll events upward
  19866. * @param {boolean} scrollDown if set to false flags that there are no more pages downwards, so don't
  19867. * fire any more infinite scroll events downward
  19868. * @returns {promise} a promise that is resolved when the grid scrolling is fully adjusted. If you're
  19869. * planning to remove pages, you should wait on this promise first, or you'll break the scroll positioning
  19870. */
  19871. dataLoaded: function( scrollUp, scrollDown ) {
  19872. service.setScrollDirections(grid, scrollUp, scrollDown);
  19873. var promise = service.adjustScroll(grid).then(function() {
  19874. grid.infiniteScroll.dataLoading = false;
  19875. });
  19876. return promise;
  19877. },
  19878. /**
  19879. * @ngdoc function
  19880. * @name resetScroll
  19881. * @methodOf ui.grid.infiniteScroll.api:PublicAPI
  19882. * @description Call this function when you have taken some action that makes the current
  19883. * scroll position invalid. For example, if you're using external sorting and you've resorted
  19884. * then you might reset the scroll, or if you've otherwise substantially changed the data, perhaps
  19885. * you've reused an existing grid for a new data set
  19886. *
  19887. * You must tell us whether there is data upwards or downwards after the reset
  19888. *
  19889. * @param {boolean} scrollUp flag that there are pages upwards, fire
  19890. * infinite scroll events upward
  19891. * @param {boolean} scrollDown flag that there are pages downwards, so
  19892. * fire infinite scroll events downward
  19893. */
  19894. resetScroll: function( scrollUp, scrollDown ) {
  19895. service.setScrollDirections( grid, scrollUp, scrollDown);
  19896. service.adjustInfiniteScrollPosition(grid, 0);
  19897. },
  19898. /**
  19899. * @ngdoc function
  19900. * @name saveScrollPercentage
  19901. * @methodOf ui.grid.infiniteScroll.api:PublicAPI
  19902. * @description Saves the scroll percentage and number of visible rows before you adjust the data,
  19903. * used if you're subsequently going to call `dataRemovedTop` or `dataRemovedBottom`
  19904. */
  19905. saveScrollPercentage: function() {
  19906. grid.infiniteScroll.prevScrollTop = grid.renderContainers.body.prevScrollTop;
  19907. grid.infiniteScroll.previousVisibleRows = grid.getVisibleRowCount();
  19908. },
  19909. /**
  19910. * @ngdoc function
  19911. * @name dataRemovedTop
  19912. * @methodOf ui.grid.infiniteScroll.api:PublicAPI
  19913. * @description Adjusts the scroll position after you've removed data at the top
  19914. * @param {boolean} scrollUp flag that there are pages upwards, fire
  19915. * infinite scroll events upward
  19916. * @param {boolean} scrollDown flag that there are pages downwards, so
  19917. * fire infinite scroll events downward
  19918. */
  19919. dataRemovedTop: function( scrollUp, scrollDown ) {
  19920. service.dataRemovedTop( grid, scrollUp, scrollDown );
  19921. },
  19922. /**
  19923. * @ngdoc function
  19924. * @name dataRemovedBottom
  19925. * @methodOf ui.grid.infiniteScroll.api:PublicAPI
  19926. * @description Adjusts the scroll position after you've removed data at the bottom
  19927. * @param {boolean} scrollUp flag that there are pages upwards, fire
  19928. * infinite scroll events upward
  19929. * @param {boolean} scrollDown flag that there are pages downwards, so
  19930. * fire infinite scroll events downward
  19931. */
  19932. dataRemovedBottom: function( scrollUp, scrollDown ) {
  19933. service.dataRemovedBottom( grid, scrollUp, scrollDown );
  19934. },
  19935. /**
  19936. * @ngdoc function
  19937. * @name setScrollDirections
  19938. * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  19939. * @description Sets the scrollUp and scrollDown flags, handling nulls and undefined,
  19940. * and also sets the grid.suppressParentScroll
  19941. * @param {boolean} scrollUp whether there are pages available up - defaults to false
  19942. * @param {boolean} scrollDown whether there are pages available down - defaults to true
  19943. */
  19944. setScrollDirections: function ( scrollUp, scrollDown ) {
  19945. service.setScrollDirections( grid, scrollUp, scrollDown );
  19946. }
  19947. }
  19948. }
  19949. };
  19950. grid.api.registerEventsFromObject(publicApi.events);
  19951. grid.api.registerMethodsFromObject(publicApi.methods);
  19952. },
  19953. defaultGridOptions: function (gridOptions) {
  19954. //default option to true unless it was explicitly set to false
  19955. /**
  19956. * @ngdoc object
  19957. * @name ui.grid.infiniteScroll.api:GridOptions
  19958. *
  19959. * @description GridOptions for infinite scroll feature, these are available to be
  19960. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  19961. */
  19962. /**
  19963. * @ngdoc object
  19964. * @name enableInfiniteScroll
  19965. * @propertyOf ui.grid.infiniteScroll.api:GridOptions
  19966. * @description Enable infinite scrolling for this grid
  19967. * <br/>Defaults to true
  19968. */
  19969. gridOptions.enableInfiniteScroll = gridOptions.enableInfiniteScroll !== false;
  19970. /**
  19971. * @ngdoc property
  19972. * @name infiniteScrollRowsFromEnd
  19973. * @propertyOf ui.grid.class:GridOptions
  19974. * @description This setting controls how close to the end of the dataset a user gets before
  19975. * more data is requested by the infinite scroll, whether scrolling up or down. This allows you to
  19976. * 'prefetch' rows before the user actually runs out of scrolling.
  19977. *
  19978. * Note that if you set this value too high it may give jumpy scrolling behaviour, if you're getting
  19979. * this behaviour you could use the `saveScrollPercentageMethod` right before loading your data, and we'll
  19980. * preserve that scroll position
  19981. *
  19982. * <br> Defaults to 20
  19983. */
  19984. gridOptions.infiniteScrollRowsFromEnd = gridOptions.infiniteScrollRowsFromEnd || 20;
  19985. /**
  19986. * @ngdoc property
  19987. * @name infiniteScrollUp
  19988. * @propertyOf ui.grid.class:GridOptions
  19989. * @description Whether you allow infinite scroll up, implying that the first page of data
  19990. * you have displayed is in the middle of your data set. If set to true then we trigger the
  19991. * needMoreDataTop event when the user hits the top of the scrollbar.
  19992. * <br> Defaults to false
  19993. */
  19994. gridOptions.infiniteScrollUp = gridOptions.infiniteScrollUp === true;
  19995. /**
  19996. * @ngdoc property
  19997. * @name infiniteScrollDown
  19998. * @propertyOf ui.grid.class:GridOptions
  19999. * @description Whether you allow infinite scroll down, implying that the first page of data
  20000. * you have displayed is in the middle of your data set. If set to true then we trigger the
  20001. * needMoreData event when the user hits the bottom of the scrollbar.
  20002. * <br> Defaults to true
  20003. */
  20004. gridOptions.infiniteScrollDown = gridOptions.infiniteScrollDown !== false;
  20005. },
  20006. /**
  20007. * @ngdoc function
  20008. * @name setScrollDirections
  20009. * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  20010. * @description Sets the scrollUp and scrollDown flags, handling nulls and undefined,
  20011. * and also sets the grid.suppressParentScroll
  20012. * @param {grid} grid the grid we're operating on
  20013. * @param {boolean} scrollUp whether there are pages available up - defaults to false
  20014. * @param {boolean} scrollDown whether there are pages available down - defaults to true
  20015. */
  20016. setScrollDirections: function ( grid, scrollUp, scrollDown ) {
  20017. grid.infiniteScroll.scrollUp = ( scrollUp === true );
  20018. grid.suppressParentScrollUp = ( scrollUp === true );
  20019. grid.infiniteScroll.scrollDown = ( scrollDown !== false);
  20020. grid.suppressParentScrollDown = ( scrollDown !== false);
  20021. },
  20022. /**
  20023. * @ngdoc function
  20024. * @name handleScroll
  20025. * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  20026. * @description Called whenever the grid scrolls, determines whether the scroll should
  20027. * trigger an infinite scroll request for more data
  20028. * @param {object} args the args from the event
  20029. */
  20030. handleScroll: function (args) {
  20031. // don't request data if already waiting for data, or if source is coming from ui.grid.adjustInfiniteScrollPosition() function
  20032. if ( args.grid.infiniteScroll && args.grid.infiniteScroll.dataLoading || args.source === 'ui.grid.adjustInfiniteScrollPosition' ){
  20033. return;
  20034. }
  20035. if (args.y) {
  20036. // If the user is scrolling very quickly all the way to the top/bottom, the scroll handler can get confused
  20037. // about the direction. First we check if they've gone all the way, and data always is loaded in this case.
  20038. if (args.y.percentage === 0) {
  20039. args.grid.scrollDirection = uiGridConstants.scrollDirection.UP;
  20040. service.loadData(args.grid);
  20041. } else if (args.y.percentage === 1) {
  20042. args.grid.scrollDirection = uiGridConstants.scrollDirection.DOWN;
  20043. service.loadData(args.grid);
  20044. } else { // Scroll position is somewhere in between top/bottom, so determine whether it's far enough to load more data.
  20045. var percentage;
  20046. var targetPercentage = args.grid.options.infiniteScrollRowsFromEnd / args.grid.renderContainers.body.visibleRowCache.length;
  20047. if (args.grid.scrollDirection === uiGridConstants.scrollDirection.UP ) {
  20048. percentage = args.y.percentage;
  20049. if (percentage <= targetPercentage){
  20050. service.loadData(args.grid);
  20051. }
  20052. } else if (args.grid.scrollDirection === uiGridConstants.scrollDirection.DOWN) {
  20053. percentage = 1 - args.y.percentage;
  20054. if (percentage <= targetPercentage){
  20055. service.loadData(args.grid);
  20056. }
  20057. }
  20058. }
  20059. }
  20060. },
  20061. /**
  20062. * @ngdoc function
  20063. * @name loadData
  20064. * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  20065. * @description This function fires 'needLoadMoreData' or 'needLoadMoreDataTop' event based on scrollDirection
  20066. * and whether there are more pages upwards or downwards. It also stores the number of rows that we had previously,
  20067. * and clears out any saved scroll position so that we know whether or not the user calls `saveScrollPercentage`
  20068. * @param {Grid} grid the grid we're working on
  20069. */
  20070. loadData: function (grid) {
  20071. // save number of currently visible rows to calculate new scroll position later - we know that we want
  20072. // to be at approximately the row we're currently at
  20073. grid.infiniteScroll.previousVisibleRows = grid.renderContainers.body.visibleRowCache.length;
  20074. grid.infiniteScroll.direction = grid.scrollDirection;
  20075. delete grid.infiniteScroll.prevScrollTop;
  20076. if (grid.scrollDirection === uiGridConstants.scrollDirection.UP && grid.infiniteScroll.scrollUp ) {
  20077. grid.infiniteScroll.dataLoading = true;
  20078. grid.api.infiniteScroll.raise.needLoadMoreDataTop();
  20079. } else if (grid.scrollDirection === uiGridConstants.scrollDirection.DOWN && grid.infiniteScroll.scrollDown ) {
  20080. grid.infiniteScroll.dataLoading = true;
  20081. grid.api.infiniteScroll.raise.needLoadMoreData();
  20082. }
  20083. },
  20084. /**
  20085. * @ngdoc function
  20086. * @name adjustScroll
  20087. * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  20088. * @description Once we are informed that data has been loaded, adjust the scroll position to account for that
  20089. * addition and to make things look clean.
  20090. *
  20091. * If we're scrolling up we scroll to the first row of the old data set -
  20092. * so we're assuming that you would have gotten to the top of the grid (from the 20% need more data trigger) by
  20093. * the time the data comes back. If we're scrolling down we scroll to the last row of the old data set - so we're
  20094. * assuming that you would have gotten to the bottom of the grid (from the 80% need more data trigger) by the time
  20095. * the data comes back.
  20096. *
  20097. * Neither of these are good assumptions, but making this a smoother experience really requires
  20098. * 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
  20099. * 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
  20100. * somewhere else in the mean-time, in which case they'll get a jump back to the new data. Anyway, this will do for
  20101. * now, until someone wants to do better.
  20102. * @param {Grid} grid the grid we're working on
  20103. * @returns {promise} a promise that is resolved when scrolling has finished
  20104. */
  20105. adjustScroll: function(grid){
  20106. var promise = $q.defer();
  20107. $rootScope.$applyAsync(function () {
  20108. var newPercentage, viewportHeight, rowHeight, newVisibleRows, oldTop, newTop;
  20109. viewportHeight = grid.getViewportHeight() + grid.headerHeight - grid.renderContainers.body.headerHeight - grid.scrollbarHeight;
  20110. rowHeight = grid.options.rowHeight;
  20111. if ( grid.infiniteScroll.direction === undefined ){
  20112. // called from initialize, tweak our scroll up a little
  20113. service.adjustInfiniteScrollPosition(grid, 0);
  20114. }
  20115. newVisibleRows = grid.getVisibleRowCount();
  20116. // in case not enough data is loaded to enable scroller - load more data
  20117. var canvasHeight = rowHeight * newVisibleRows;
  20118. if (grid.infiniteScroll.scrollDown && (viewportHeight > canvasHeight)) {
  20119. grid.api.infiniteScroll.raise.needLoadMoreData();
  20120. }
  20121. if ( grid.infiniteScroll.direction === uiGridConstants.scrollDirection.UP ){
  20122. oldTop = grid.infiniteScroll.prevScrollTop || 0;
  20123. newTop = oldTop + (newVisibleRows - grid.infiniteScroll.previousVisibleRows)*rowHeight;
  20124. service.adjustInfiniteScrollPosition(grid, newTop);
  20125. $rootScope.$applyAsync( function() {
  20126. promise.resolve();
  20127. });
  20128. }
  20129. if ( grid.infiniteScroll.direction === uiGridConstants.scrollDirection.DOWN ){
  20130. newTop = grid.infiniteScroll.prevScrollTop || (grid.infiniteScroll.previousVisibleRows*rowHeight - viewportHeight);
  20131. service.adjustInfiniteScrollPosition(grid, newTop);
  20132. $rootScope.$applyAsync( function() {
  20133. promise.resolve();
  20134. });
  20135. }
  20136. }, 0);
  20137. return promise.promise;
  20138. },
  20139. /**
  20140. * @ngdoc function
  20141. * @name adjustInfiniteScrollPosition
  20142. * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService
  20143. * @description This function fires 'needLoadMoreData' or 'needLoadMoreDataTop' event based on scrollDirection
  20144. * @param {Grid} grid the grid we're working on
  20145. * @param {number} scrollTop the position through the grid that we want to scroll to
  20146. */
  20147. adjustInfiniteScrollPosition: function (grid, scrollTop) {
  20148. var scrollEvent = new ScrollEvent(grid, null, null, 'ui.grid.adjustInfiniteScrollPosition'),
  20149. visibleRows = grid.getVisibleRowCount(),
  20150. viewportHeight = grid.getViewportHeight() + grid.headerHeight - grid.renderContainers.body.headerHeight - grid.scrollbarHeight,
  20151. rowHeight = grid.options.rowHeight,
  20152. scrollHeight = visibleRows*rowHeight-viewportHeight;
  20153. //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
  20154. if (scrollTop === 0 && grid.infiniteScroll.scrollUp) {
  20155. // using pixels results in a relative scroll, hence we have to use percentage
  20156. scrollEvent.y = {percentage: 1/scrollHeight};
  20157. }
  20158. else {
  20159. scrollEvent.y = {percentage: scrollTop/scrollHeight};
  20160. }
  20161. grid.scrollContainers('', scrollEvent);
  20162. },
  20163. /**
  20164. * @ngdoc function
  20165. * @name dataRemovedTop
  20166. * @methodOf ui.grid.infiniteScroll.api:PublicAPI
  20167. * @description Adjusts the scroll position after you've removed data at the top. You should
  20168. * have called `saveScrollPercentage` before you remove the data, and if you're doing this in
  20169. * response to a `needMoreData` you should wait until the promise from `loadData` has resolved
  20170. * before you start removing data
  20171. * @param {Grid} grid the grid we're working on
  20172. * @param {boolean} scrollUp flag that there are pages upwards, fire
  20173. * infinite scroll events upward
  20174. * @param {boolean} scrollDown flag that there are pages downwards, so
  20175. * fire infinite scroll events downward
  20176. */
  20177. dataRemovedTop: function( grid, scrollUp, scrollDown ) {
  20178. var newVisibleRows, oldTop, newTop, rowHeight;
  20179. service.setScrollDirections( grid, scrollUp, scrollDown );
  20180. newVisibleRows = grid.renderContainers.body.visibleRowCache.length;
  20181. oldTop = grid.infiniteScroll.prevScrollTop;
  20182. rowHeight = grid.options.rowHeight;
  20183. // since we removed from the top, our new scroll row will be the old scroll row less the number
  20184. // of rows removed
  20185. newTop = oldTop - ( grid.infiniteScroll.previousVisibleRows - newVisibleRows )*rowHeight;
  20186. service.adjustInfiniteScrollPosition( grid, newTop );
  20187. },
  20188. /**
  20189. * @ngdoc function
  20190. * @name dataRemovedBottom
  20191. * @methodOf ui.grid.infiniteScroll.api:PublicAPI
  20192. * @description Adjusts the scroll position after you've removed data at the bottom. You should
  20193. * have called `saveScrollPercentage` before you remove the data, and if you're doing this in
  20194. * response to a `needMoreData` you should wait until the promise from `loadData` has resolved
  20195. * before you start removing data
  20196. * @param {Grid} grid the grid we're working on
  20197. * @param {boolean} scrollUp flag that there are pages upwards, fire
  20198. * infinite scroll events upward
  20199. * @param {boolean} scrollDown flag that there are pages downwards, so
  20200. * fire infinite scroll events downward
  20201. */
  20202. dataRemovedBottom: function( grid, scrollUp, scrollDown ) {
  20203. var newTop;
  20204. service.setScrollDirections( grid, scrollUp, scrollDown );
  20205. newTop = grid.infiniteScroll.prevScrollTop;
  20206. service.adjustInfiniteScrollPosition( grid, newTop );
  20207. }
  20208. };
  20209. return service;
  20210. }]);
  20211. /**
  20212. * @ngdoc directive
  20213. * @name ui.grid.infiniteScroll.directive:uiGridInfiniteScroll
  20214. * @element div
  20215. * @restrict A
  20216. *
  20217. * @description Adds infinite scroll features to grid
  20218. *
  20219. * @example
  20220. <example module="app">
  20221. <file name="app.js">
  20222. var app = angular.module('app', ['ui.grid', 'ui.grid.infiniteScroll']);
  20223. app.controller('MainCtrl', ['$scope', function ($scope) {
  20224. $scope.data = [
  20225. { name: 'Alex', car: 'Toyota' },
  20226. { name: 'Sam', car: 'Lexus' }
  20227. ];
  20228. $scope.columnDefs = [
  20229. {name: 'name'},
  20230. {name: 'car'}
  20231. ];
  20232. }]);
  20233. </file>
  20234. <file name="index.html">
  20235. <div ng-controller="MainCtrl">
  20236. <div ui-grid="{ data: data, columnDefs: columnDefs }" ui-grid-infinite-scroll="20"></div>
  20237. </div>
  20238. </file>
  20239. </example>
  20240. */
  20241. module.directive('uiGridInfiniteScroll', ['uiGridInfiniteScrollService',
  20242. function (uiGridInfiniteScrollService) {
  20243. return {
  20244. priority: -200,
  20245. scope: false,
  20246. require: '^uiGrid',
  20247. compile: function($scope, $elm, $attr){
  20248. return {
  20249. pre: function($scope, $elm, $attr, uiGridCtrl) {
  20250. uiGridInfiniteScrollService.initializeGrid(uiGridCtrl.grid, $scope);
  20251. },
  20252. post: function($scope, $elm, $attr) {
  20253. }
  20254. };
  20255. }
  20256. };
  20257. }]);
  20258. })();
  20259. (function () {
  20260. 'use strict';
  20261. /**
  20262. * @ngdoc overview
  20263. * @name ui.grid.moveColumns
  20264. * @description
  20265. *
  20266. * # ui.grid.moveColumns
  20267. *
  20268. * <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>
  20269. *
  20270. * This module provides column moving capability to ui.grid. It enables to change the position of columns.
  20271. * <div doc-module-components="ui.grid.moveColumns"></div>
  20272. */
  20273. var module = angular.module('ui.grid.moveColumns', ['ui.grid']);
  20274. /**
  20275. * @ngdoc service
  20276. * @name ui.grid.moveColumns.service:uiGridMoveColumnService
  20277. * @description Service for column moving feature.
  20278. */
  20279. module.service('uiGridMoveColumnService', ['$q', '$rootScope', '$log', 'ScrollEvent', 'uiGridConstants', 'gridUtil', function ($q, $rootScope, $log, ScrollEvent, uiGridConstants, gridUtil) {
  20280. var service = {
  20281. initializeGrid: function (grid) {
  20282. var self = this;
  20283. this.registerPublicApi(grid);
  20284. this.defaultGridOptions(grid.options);
  20285. grid.moveColumns = {orderCache: []}; // Used to cache the order before columns are rebuilt
  20286. grid.registerColumnBuilder(self.movableColumnBuilder);
  20287. grid.registerDataChangeCallback(self.verifyColumnOrder, [uiGridConstants.dataChange.COLUMN]);
  20288. },
  20289. registerPublicApi: function (grid) {
  20290. var self = this;
  20291. /**
  20292. * @ngdoc object
  20293. * @name ui.grid.moveColumns.api:PublicApi
  20294. * @description Public Api for column moving feature.
  20295. */
  20296. var publicApi = {
  20297. events: {
  20298. /**
  20299. * @ngdoc event
  20300. * @name columnPositionChanged
  20301. * @eventOf ui.grid.moveColumns.api:PublicApi
  20302. * @description raised when column is moved
  20303. * <pre>
  20304. * gridApi.colMovable.on.columnPositionChanged(scope,function(colDef, originalPosition, newPosition){})
  20305. * </pre>
  20306. * @param {object} colDef the column that was moved
  20307. * @param {integer} originalPosition of the column
  20308. * @param {integer} finalPosition of the column
  20309. */
  20310. colMovable: {
  20311. columnPositionChanged: function (colDef, originalPosition, newPosition) {
  20312. }
  20313. }
  20314. },
  20315. methods: {
  20316. /**
  20317. * @ngdoc method
  20318. * @name moveColumn
  20319. * @methodOf ui.grid.moveColumns.api:PublicApi
  20320. * @description Method can be used to change column position.
  20321. * <pre>
  20322. * gridApi.colMovable.moveColumn(oldPosition, newPosition)
  20323. * </pre>
  20324. * @param {integer} originalPosition of the column
  20325. * @param {integer} finalPosition of the column
  20326. */
  20327. colMovable: {
  20328. moveColumn: function (originalPosition, finalPosition) {
  20329. var columns = grid.columns;
  20330. if (!angular.isNumber(originalPosition) || !angular.isNumber(finalPosition)) {
  20331. gridUtil.logError('MoveColumn: Please provide valid values for originalPosition and finalPosition');
  20332. return;
  20333. }
  20334. var nonMovableColumns = 0;
  20335. for (var i = 0; i < columns.length; i++) {
  20336. if ((angular.isDefined(columns[i].colDef.visible) && columns[i].colDef.visible === false) || columns[i].isRowHeader === true) {
  20337. nonMovableColumns++;
  20338. }
  20339. }
  20340. if (originalPosition >= (columns.length - nonMovableColumns) || finalPosition >= (columns.length - nonMovableColumns)) {
  20341. gridUtil.logError('MoveColumn: Invalid values for originalPosition, finalPosition');
  20342. return;
  20343. }
  20344. var findPositionForRenderIndex = function (index) {
  20345. var position = index;
  20346. for (var i = 0; i <= position; i++) {
  20347. if (angular.isDefined(columns[i]) && ((angular.isDefined(columns[i].colDef.visible) && columns[i].colDef.visible === false) || columns[i].isRowHeader === true)) {
  20348. position++;
  20349. }
  20350. }
  20351. return position;
  20352. };
  20353. self.redrawColumnAtPosition(grid, findPositionForRenderIndex(originalPosition), findPositionForRenderIndex(finalPosition));
  20354. }
  20355. }
  20356. }
  20357. };
  20358. grid.api.registerEventsFromObject(publicApi.events);
  20359. grid.api.registerMethodsFromObject(publicApi.methods);
  20360. },
  20361. defaultGridOptions: function (gridOptions) {
  20362. /**
  20363. * @ngdoc object
  20364. * @name ui.grid.moveColumns.api:GridOptions
  20365. *
  20366. * @description Options for configuring the move column feature, these are available to be
  20367. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  20368. */
  20369. /**
  20370. * @ngdoc object
  20371. * @name enableColumnMoving
  20372. * @propertyOf ui.grid.moveColumns.api:GridOptions
  20373. * @description If defined, sets the default value for the colMovable flag on each individual colDefs
  20374. * if their individual enableColumnMoving configuration is not defined. Defaults to true.
  20375. */
  20376. gridOptions.enableColumnMoving = gridOptions.enableColumnMoving !== false;
  20377. },
  20378. movableColumnBuilder: function (colDef, col, gridOptions) {
  20379. var promises = [];
  20380. /**
  20381. * @ngdoc object
  20382. * @name ui.grid.moveColumns.api:ColumnDef
  20383. *
  20384. * @description Column Definition for move column feature, these are available to be
  20385. * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs}
  20386. */
  20387. /**
  20388. * @ngdoc object
  20389. * @name enableColumnMoving
  20390. * @propertyOf ui.grid.moveColumns.api:ColumnDef
  20391. * @description Enable column moving for the column.
  20392. */
  20393. colDef.enableColumnMoving = colDef.enableColumnMoving === undefined ? gridOptions.enableColumnMoving
  20394. : colDef.enableColumnMoving;
  20395. return $q.all(promises);
  20396. },
  20397. /**
  20398. * @ngdoc method
  20399. * @name updateColumnCache
  20400. * @methodOf ui.grid.moveColumns
  20401. * @description Cache the current order of columns, so we can restore them after new columnDefs are defined
  20402. */
  20403. updateColumnCache: function(grid){
  20404. grid.moveColumns.orderCache = grid.getOnlyDataColumns();
  20405. },
  20406. /**
  20407. * @ngdoc method
  20408. * @name verifyColumnOrder
  20409. * @methodOf ui.grid.moveColumns
  20410. * @description dataChangeCallback which uses the cached column order to restore the column order
  20411. * when it is reset by altering the columnDefs array.
  20412. */
  20413. verifyColumnOrder: function(grid){
  20414. var headerRowOffset = grid.rowHeaderColumns.length;
  20415. var newIndex;
  20416. angular.forEach(grid.moveColumns.orderCache, function(cacheCol, cacheIndex){
  20417. newIndex = grid.columns.indexOf(cacheCol);
  20418. if ( newIndex !== -1 && newIndex - headerRowOffset !== cacheIndex ){
  20419. var column = grid.columns.splice(newIndex, 1)[0];
  20420. grid.columns.splice(cacheIndex + headerRowOffset, 0, column);
  20421. }
  20422. });
  20423. },
  20424. redrawColumnAtPosition: function (grid, originalPosition, newPosition) {
  20425. var columns = grid.columns;
  20426. if (originalPosition === newPosition) {
  20427. return;
  20428. }
  20429. //check columns in between move-range to make sure they are visible columns
  20430. var pos = (originalPosition < newPosition) ? originalPosition + 1 : originalPosition - 1;
  20431. var i0 = Math.min(pos, newPosition);
  20432. for (i0; i0 <= Math.max(pos, newPosition); i0++) {
  20433. if (columns[i0].visible) {
  20434. break;
  20435. }
  20436. }
  20437. if (i0 > Math.max(pos, newPosition)) {
  20438. //no visible column found, column did not visibly move
  20439. return;
  20440. }
  20441. var originalColumn = columns[originalPosition];
  20442. if (originalColumn.colDef.enableColumnMoving) {
  20443. if (originalPosition > newPosition) {
  20444. for (var i1 = originalPosition; i1 > newPosition; i1--) {
  20445. columns[i1] = columns[i1 - 1];
  20446. }
  20447. }
  20448. else if (newPosition > originalPosition) {
  20449. for (var i2 = originalPosition; i2 < newPosition; i2++) {
  20450. columns[i2] = columns[i2 + 1];
  20451. }
  20452. }
  20453. columns[newPosition] = originalColumn;
  20454. service.updateColumnCache(grid);
  20455. grid.queueGridRefresh();
  20456. $rootScope.$applyAsync(function () {
  20457. grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
  20458. grid.api.colMovable.raise.columnPositionChanged(originalColumn.colDef, originalPosition, newPosition);
  20459. });
  20460. }
  20461. }
  20462. };
  20463. return service;
  20464. }]);
  20465. /**
  20466. * @ngdoc directive
  20467. * @name ui.grid.moveColumns.directive:uiGridMoveColumns
  20468. * @element div
  20469. * @restrict A
  20470. * @description Adds column moving features to the ui-grid directive.
  20471. * @example
  20472. <example module="app">
  20473. <file name="app.js">
  20474. var app = angular.module('app', ['ui.grid', 'ui.grid.moveColumns']);
  20475. app.controller('MainCtrl', ['$scope', function ($scope) {
  20476. $scope.data = [
  20477. { name: 'Bob', title: 'CEO', age: 45 },
  20478. { name: 'Frank', title: 'Lowly Developer', age: 25 },
  20479. { name: 'Jenny', title: 'Highly Developer', age: 35 }
  20480. ];
  20481. $scope.columnDefs = [
  20482. {name: 'name'},
  20483. {name: 'title'},
  20484. {name: 'age'}
  20485. ];
  20486. }]);
  20487. </file>
  20488. <file name="main.css">
  20489. .grid {
  20490. width: 100%;
  20491. height: 150px;
  20492. }
  20493. </file>
  20494. <file name="index.html">
  20495. <div ng-controller="MainCtrl">
  20496. <div class="grid" ui-grid="{ data: data, columnDefs: columnDefs }" ui-grid-move-columns></div>
  20497. </div>
  20498. </file>
  20499. </example>
  20500. */
  20501. module.directive('uiGridMoveColumns', ['uiGridMoveColumnService', function (uiGridMoveColumnService) {
  20502. return {
  20503. replace: true,
  20504. priority: 0,
  20505. require: '^uiGrid',
  20506. scope: false,
  20507. compile: function () {
  20508. return {
  20509. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  20510. uiGridMoveColumnService.initializeGrid(uiGridCtrl.grid);
  20511. },
  20512. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  20513. }
  20514. };
  20515. }
  20516. };
  20517. }]);
  20518. /**
  20519. * @ngdoc directive
  20520. * @name ui.grid.moveColumns.directive:uiGridHeaderCell
  20521. * @element div
  20522. * @restrict A
  20523. *
  20524. * @description Stacks on top of ui.grid.uiGridHeaderCell to provide capability to be able to move it to reposition column.
  20525. *
  20526. * On receiving mouseDown event headerCell is cloned, now as the mouse moves the cloned header cell also moved in the grid.
  20527. * In case the moving cloned header cell reaches the left or right extreme of grid, grid scrolling is triggered (if horizontal scroll exists).
  20528. * On mouseUp event column is repositioned at position where mouse is released and cloned header cell is removed.
  20529. *
  20530. * Events that invoke cloning of header cell:
  20531. * - mousedown
  20532. *
  20533. * Events that invoke movement of cloned header cell:
  20534. * - mousemove
  20535. *
  20536. * Events that invoke repositioning of column:
  20537. * - mouseup
  20538. */
  20539. module.directive('uiGridHeaderCell', ['$q', 'gridUtil', 'uiGridMoveColumnService', '$document', '$log', 'uiGridConstants', 'ScrollEvent',
  20540. function ($q, gridUtil, uiGridMoveColumnService, $document, $log, uiGridConstants, ScrollEvent) {
  20541. return {
  20542. priority: -10,
  20543. require: '^uiGrid',
  20544. compile: function () {
  20545. return {
  20546. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  20547. if ($scope.col.colDef.enableColumnMoving) {
  20548. /*
  20549. * Our general approach to column move is that we listen to a touchstart or mousedown
  20550. * event over the column header. When we hear one, then we wait for a move of the same type
  20551. * - if we are a touchstart then we listen for a touchmove, if we are a mousedown we listen for
  20552. * a mousemove (i.e. a drag) before we decide that there's a move underway. If there's never a move,
  20553. * and we instead get a mouseup or a touchend, then we just drop out again and do nothing.
  20554. *
  20555. */
  20556. var $contentsElm = angular.element( $elm[0].querySelectorAll('.ui-grid-cell-contents') );
  20557. var gridLeft;
  20558. var previousMouseX;
  20559. var totalMouseMovement;
  20560. var rightMoveLimit;
  20561. var elmCloned = false;
  20562. var movingElm;
  20563. var reducedWidth;
  20564. var moveOccurred = false;
  20565. var downFn = function( event ){
  20566. //Setting some variables required for calculations.
  20567. gridLeft = $scope.grid.element[0].getBoundingClientRect().left;
  20568. if ( $scope.grid.hasLeftContainer() ){
  20569. gridLeft += $scope.grid.renderContainers.left.header[0].getBoundingClientRect().width;
  20570. }
  20571. previousMouseX = event.pageX || (event.originalEvent ? event.originalEvent.pageX : 0);
  20572. totalMouseMovement = 0;
  20573. rightMoveLimit = gridLeft + $scope.grid.getViewportWidth();
  20574. if ( event.type === 'mousedown' ){
  20575. $document.on('mousemove', moveFn);
  20576. $document.on('mouseup', upFn);
  20577. } else if ( event.type === 'touchstart' ){
  20578. $document.on('touchmove', moveFn);
  20579. $document.on('touchend', upFn);
  20580. }
  20581. };
  20582. var moveFn = function( event ) {
  20583. var pageX = event.pageX || (event.originalEvent ? event.originalEvent.pageX : 0);
  20584. var changeValue = pageX - previousMouseX;
  20585. if ( changeValue === 0 ){ return; }
  20586. //Disable text selection in Chrome during column move
  20587. document.onselectstart = function() { return false; };
  20588. moveOccurred = true;
  20589. if (!elmCloned) {
  20590. cloneElement();
  20591. }
  20592. else if (elmCloned) {
  20593. moveElement(changeValue);
  20594. previousMouseX = pageX;
  20595. }
  20596. };
  20597. var upFn = function( event ){
  20598. //Re-enable text selection after column move
  20599. document.onselectstart = null;
  20600. //Remove the cloned element on mouse up.
  20601. if (movingElm) {
  20602. movingElm.remove();
  20603. elmCloned = false;
  20604. }
  20605. offAllEvents();
  20606. onDownEvents();
  20607. if (!moveOccurred){
  20608. return;
  20609. }
  20610. var columns = $scope.grid.columns;
  20611. var columnIndex = 0;
  20612. for (var i = 0; i < columns.length; i++) {
  20613. if (columns[i].colDef.name !== $scope.col.colDef.name) {
  20614. columnIndex++;
  20615. }
  20616. else {
  20617. break;
  20618. }
  20619. }
  20620. var targetIndex;
  20621. //Case where column should be moved to a position on its left
  20622. if (totalMouseMovement < 0) {
  20623. var totalColumnsLeftWidth = 0;
  20624. var il;
  20625. if ( $scope.grid.isRTL() ){
  20626. for (il = columnIndex + 1; il < columns.length; il++) {
  20627. if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) {
  20628. totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width;
  20629. if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) {
  20630. uiGridMoveColumnService.redrawColumnAtPosition
  20631. ($scope.grid, columnIndex, il - 1);
  20632. break;
  20633. }
  20634. }
  20635. }
  20636. }
  20637. else {
  20638. for (il = columnIndex - 1; il >= 0; il--) {
  20639. if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) {
  20640. totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width;
  20641. if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) {
  20642. uiGridMoveColumnService.redrawColumnAtPosition
  20643. ($scope.grid, columnIndex, il + 1);
  20644. break;
  20645. }
  20646. }
  20647. }
  20648. }
  20649. //Case where column should be moved to beginning (or end in RTL) of the grid.
  20650. if (totalColumnsLeftWidth < Math.abs(totalMouseMovement)) {
  20651. targetIndex = 0;
  20652. if ( $scope.grid.isRTL() ){
  20653. targetIndex = columns.length - 1;
  20654. }
  20655. uiGridMoveColumnService.redrawColumnAtPosition
  20656. ($scope.grid, columnIndex, targetIndex);
  20657. }
  20658. }
  20659. //Case where column should be moved to a position on its right
  20660. else if (totalMouseMovement > 0) {
  20661. var totalColumnsRightWidth = 0;
  20662. var ir;
  20663. if ( $scope.grid.isRTL() ){
  20664. for (ir = columnIndex - 1; ir > 0; ir--) {
  20665. if (angular.isUndefined(columns[ir].colDef.visible) || columns[ir].colDef.visible === true) {
  20666. totalColumnsRightWidth += columns[ir].drawnWidth || columns[ir].width || columns[ir].colDef.width;
  20667. if (totalColumnsRightWidth > totalMouseMovement) {
  20668. uiGridMoveColumnService.redrawColumnAtPosition
  20669. ($scope.grid, columnIndex, ir);
  20670. break;
  20671. }
  20672. }
  20673. }
  20674. }
  20675. else {
  20676. for (ir = columnIndex + 1; ir < columns.length; ir++) {
  20677. if (angular.isUndefined(columns[ir].colDef.visible) || columns[ir].colDef.visible === true) {
  20678. totalColumnsRightWidth += columns[ir].drawnWidth || columns[ir].width || columns[ir].colDef.width;
  20679. if (totalColumnsRightWidth > totalMouseMovement) {
  20680. uiGridMoveColumnService.redrawColumnAtPosition
  20681. ($scope.grid, columnIndex, ir - 1);
  20682. break;
  20683. }
  20684. }
  20685. }
  20686. }
  20687. //Case where column should be moved to end (or beginning in RTL) of the grid.
  20688. if (totalColumnsRightWidth < totalMouseMovement) {
  20689. targetIndex = columns.length - 1;
  20690. if ( $scope.grid.isRTL() ){
  20691. targetIndex = 0;
  20692. }
  20693. uiGridMoveColumnService.redrawColumnAtPosition
  20694. ($scope.grid, columnIndex, targetIndex);
  20695. }
  20696. }
  20697. };
  20698. var onDownEvents = function(){
  20699. $contentsElm.on('touchstart', downFn);
  20700. $contentsElm.on('mousedown', downFn);
  20701. };
  20702. var offAllEvents = function() {
  20703. $contentsElm.off('touchstart', downFn);
  20704. $contentsElm.off('mousedown', downFn);
  20705. $document.off('mousemove', moveFn);
  20706. $document.off('touchmove', moveFn);
  20707. $document.off('mouseup', upFn);
  20708. $document.off('touchend', upFn);
  20709. };
  20710. onDownEvents();
  20711. var cloneElement = function () {
  20712. elmCloned = true;
  20713. //Cloning header cell and appending to current header cell.
  20714. movingElm = $elm.clone();
  20715. $elm.parent().append(movingElm);
  20716. //Left of cloned element should be aligned to original header cell.
  20717. movingElm.addClass('movingColumn');
  20718. var movingElementStyles = {};
  20719. movingElementStyles.left = $elm[0].offsetLeft + 'px';
  20720. var gridRight = $scope.grid.element[0].getBoundingClientRect().right;
  20721. var elmRight = $elm[0].getBoundingClientRect().right;
  20722. if (elmRight > gridRight) {
  20723. reducedWidth = $scope.col.drawnWidth + (gridRight - elmRight);
  20724. movingElementStyles.width = reducedWidth + 'px';
  20725. }
  20726. movingElm.css(movingElementStyles);
  20727. };
  20728. var moveElement = function (changeValue) {
  20729. //Calculate total column width
  20730. var columns = $scope.grid.columns;
  20731. var totalColumnWidth = 0;
  20732. for (var i = 0; i < columns.length; i++) {
  20733. if (angular.isUndefined(columns[i].colDef.visible) || columns[i].colDef.visible === true) {
  20734. totalColumnWidth += columns[i].drawnWidth || columns[i].width || columns[i].colDef.width;
  20735. }
  20736. }
  20737. //Calculate new position of left of column
  20738. var currentElmLeft = movingElm[0].getBoundingClientRect().left - 1;
  20739. var currentElmRight = movingElm[0].getBoundingClientRect().right;
  20740. var newElementLeft;
  20741. newElementLeft = currentElmLeft - gridLeft + changeValue;
  20742. newElementLeft = newElementLeft < rightMoveLimit ? newElementLeft : rightMoveLimit;
  20743. //Update css of moving column to adjust to new left value or fire scroll in case column has reached edge of grid
  20744. if ((currentElmLeft >= gridLeft || changeValue > 0) && (currentElmRight <= rightMoveLimit || changeValue < 0)) {
  20745. movingElm.css({visibility: 'visible', 'left': (movingElm[0].offsetLeft +
  20746. (newElementLeft < rightMoveLimit ? changeValue : (rightMoveLimit - currentElmLeft))) + 'px'});
  20747. }
  20748. else if (totalColumnWidth > Math.ceil(uiGridCtrl.grid.gridWidth)) {
  20749. changeValue *= 8;
  20750. var scrollEvent = new ScrollEvent($scope.col.grid, null, null, 'uiGridHeaderCell.moveElement');
  20751. scrollEvent.x = {pixels: changeValue};
  20752. scrollEvent.grid.scrollContainers('',scrollEvent);
  20753. }
  20754. //Calculate total width of columns on the left of the moving column and the mouse movement
  20755. var totalColumnsLeftWidth = 0;
  20756. for (var il = 0; il < columns.length; il++) {
  20757. if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) {
  20758. if (columns[il].colDef.name !== $scope.col.colDef.name) {
  20759. totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width;
  20760. }
  20761. else {
  20762. break;
  20763. }
  20764. }
  20765. }
  20766. if ($scope.newScrollLeft === undefined) {
  20767. totalMouseMovement += changeValue;
  20768. }
  20769. else {
  20770. totalMouseMovement = $scope.newScrollLeft + newElementLeft - totalColumnsLeftWidth;
  20771. }
  20772. //Increase width of moving column, in case the rightmost column was moved and its width was
  20773. //decreased because of overflow
  20774. if (reducedWidth < $scope.col.drawnWidth) {
  20775. reducedWidth += Math.abs(changeValue);
  20776. movingElm.css({'width': reducedWidth + 'px'});
  20777. }
  20778. };
  20779. $scope.$on('$destroy', offAllEvents);
  20780. }
  20781. }
  20782. };
  20783. }
  20784. };
  20785. }]);
  20786. })();
  20787. (function() {
  20788. 'use strict';
  20789. /**
  20790. * @ngdoc overview
  20791. * @name ui.grid.pagination
  20792. *
  20793. * @description
  20794. *
  20795. * # ui.grid.pagination
  20796. *
  20797. * <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>
  20798. *
  20799. * This module provides pagination support to ui-grid
  20800. */
  20801. var module = angular.module('ui.grid.pagination', ['ng', 'ui.grid']);
  20802. /**
  20803. * @ngdoc service
  20804. * @name ui.grid.pagination.service:uiGridPaginationService
  20805. *
  20806. * @description Service for the pagination feature
  20807. */
  20808. module.service('uiGridPaginationService', ['gridUtil',
  20809. function (gridUtil) {
  20810. var service = {
  20811. /**
  20812. * @ngdoc method
  20813. * @name initializeGrid
  20814. * @methodOf ui.grid.pagination.service:uiGridPaginationService
  20815. * @description Attaches the service to a certain grid
  20816. * @param {Grid} grid The grid we want to work with
  20817. */
  20818. initializeGrid: function (grid) {
  20819. service.defaultGridOptions(grid.options);
  20820. /**
  20821. * @ngdoc object
  20822. * @name ui.grid.pagination.api:PublicAPI
  20823. *
  20824. * @description Public API for the pagination feature
  20825. */
  20826. var publicApi = {
  20827. events: {
  20828. pagination: {
  20829. /**
  20830. * @ngdoc event
  20831. * @name paginationChanged
  20832. * @eventOf ui.grid.pagination.api:PublicAPI
  20833. * @description This event fires when the pageSize or currentPage changes
  20834. * @param {int} currentPage requested page number
  20835. * @param {int} pageSize requested page size
  20836. */
  20837. paginationChanged: function (currentPage, pageSize) { }
  20838. }
  20839. },
  20840. methods: {
  20841. pagination: {
  20842. /**
  20843. * @ngdoc method
  20844. * @name getPage
  20845. * @methodOf ui.grid.pagination.api:PublicAPI
  20846. * @description Returns the number of the current page
  20847. */
  20848. getPage: function () {
  20849. return grid.options.enablePagination ? grid.options.paginationCurrentPage : null;
  20850. },
  20851. /**
  20852. * @ngdoc method
  20853. * @name getFirstRowIndex
  20854. * @methodOf ui.grid.pagination.api:PublicAPI
  20855. * @description Returns the index of the first row of the current page.
  20856. */
  20857. getFirstRowIndex: function () {
  20858. if (grid.options.useCustomPagination) {
  20859. return grid.options.paginationPageSizes.reduce(function(result, size, index) {
  20860. return index < grid.options.paginationCurrentPage - 1 ? result + size : result;
  20861. }, 0);
  20862. }
  20863. return ((grid.options.paginationCurrentPage - 1) * grid.options.paginationPageSize);
  20864. },
  20865. /**
  20866. * @ngdoc method
  20867. * @name getLastRowIndex
  20868. * @methodOf ui.grid.pagination.api:PublicAPI
  20869. * @description Returns the index of the last row of the current page.
  20870. */
  20871. getLastRowIndex: function () {
  20872. if (grid.options.useCustomPagination) {
  20873. return publicApi.methods.pagination.getFirstRowIndex() + grid.options.paginationPageSizes[grid.options.paginationCurrentPage - 1] - 1;
  20874. }
  20875. return Math.min(grid.options.paginationCurrentPage * grid.options.paginationPageSize, grid.options.totalItems) - 1;
  20876. },
  20877. /**
  20878. * @ngdoc method
  20879. * @name getTotalPages
  20880. * @methodOf ui.grid.pagination.api:PublicAPI
  20881. * @description Returns the total number of pages
  20882. */
  20883. getTotalPages: function () {
  20884. if (!grid.options.enablePagination) {
  20885. return null;
  20886. }
  20887. if (grid.options.useCustomPagination) {
  20888. return grid.options.paginationPageSizes.length;
  20889. }
  20890. return (grid.options.totalItems === 0) ? 1 : Math.ceil(grid.options.totalItems / grid.options.paginationPageSize);
  20891. },
  20892. /**
  20893. * @ngdoc method
  20894. * @name nextPage
  20895. * @methodOf ui.grid.pagination.api:PublicAPI
  20896. * @description Moves to the next page, if possible
  20897. */
  20898. nextPage: function () {
  20899. if (!grid.options.enablePagination) {
  20900. return;
  20901. }
  20902. if (grid.options.totalItems > 0) {
  20903. grid.options.paginationCurrentPage = Math.min(
  20904. grid.options.paginationCurrentPage + 1,
  20905. publicApi.methods.pagination.getTotalPages()
  20906. );
  20907. } else {
  20908. grid.options.paginationCurrentPage++;
  20909. }
  20910. },
  20911. /**
  20912. * @ngdoc method
  20913. * @name previousPage
  20914. * @methodOf ui.grid.pagination.api:PublicAPI
  20915. * @description Moves to the previous page, if we're not on the first page
  20916. */
  20917. previousPage: function () {
  20918. if (!grid.options.enablePagination) {
  20919. return;
  20920. }
  20921. grid.options.paginationCurrentPage = Math.max(grid.options.paginationCurrentPage - 1, 1);
  20922. },
  20923. /**
  20924. * @ngdoc method
  20925. * @name seek
  20926. * @methodOf ui.grid.pagination.api:PublicAPI
  20927. * @description Moves to the requested page
  20928. * @param {int} page The number of the page that should be displayed
  20929. */
  20930. seek: function (page) {
  20931. if (!grid.options.enablePagination) {
  20932. return;
  20933. }
  20934. if (!angular.isNumber(page) || page < 1) {
  20935. throw 'Invalid page number: ' + page;
  20936. }
  20937. grid.options.paginationCurrentPage = Math.min(page, publicApi.methods.pagination.getTotalPages());
  20938. }
  20939. }
  20940. }
  20941. };
  20942. grid.api.registerEventsFromObject(publicApi.events);
  20943. grid.api.registerMethodsFromObject(publicApi.methods);
  20944. var processPagination = function( renderableRows ){
  20945. if (grid.options.useExternalPagination || !grid.options.enablePagination) {
  20946. return renderableRows;
  20947. }
  20948. //client side pagination
  20949. var pageSize = parseInt(grid.options.paginationPageSize, 10);
  20950. var currentPage = parseInt(grid.options.paginationCurrentPage, 10);
  20951. var visibleRows = renderableRows.filter(function (row) { return row.visible; });
  20952. grid.options.totalItems = visibleRows.length;
  20953. var firstRow = publicApi.methods.pagination.getFirstRowIndex();
  20954. var lastRow = publicApi.methods.pagination.getLastRowIndex();
  20955. if (firstRow > visibleRows.length) {
  20956. currentPage = grid.options.paginationCurrentPage = 1;
  20957. firstRow = (currentPage - 1) * pageSize;
  20958. }
  20959. return visibleRows.slice(firstRow, lastRow + 1);
  20960. };
  20961. grid.registerRowsProcessor(processPagination, 900 );
  20962. },
  20963. defaultGridOptions: function (gridOptions) {
  20964. /**
  20965. * @ngdoc object
  20966. * @name ui.grid.pagination.api:GridOptions
  20967. *
  20968. * @description GridOptions for the pagination feature, these are available to be
  20969. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  20970. */
  20971. /**
  20972. * @ngdoc property
  20973. * @name enablePagination
  20974. * @propertyOf ui.grid.pagination.api:GridOptions
  20975. * @description Enables pagination. Defaults to true.
  20976. */
  20977. gridOptions.enablePagination = gridOptions.enablePagination !== false;
  20978. /**
  20979. * @ngdoc property
  20980. * @name enablePaginationControls
  20981. * @propertyOf ui.grid.pagination.api:GridOptions
  20982. * @description Enables the paginator at the bottom of the grid. Turn this off if you want to implement your
  20983. * own controls outside the grid.
  20984. */
  20985. gridOptions.enablePaginationControls = gridOptions.enablePaginationControls !== false;
  20986. /**
  20987. * @ngdoc property
  20988. * @name useExternalPagination
  20989. * @propertyOf ui.grid.pagination.api:GridOptions
  20990. * @description Disables client side pagination. When true, handle the paginationChanged event and set data
  20991. * and totalItems. Defaults to `false`
  20992. */
  20993. gridOptions.useExternalPagination = gridOptions.useExternalPagination === true;
  20994. /**
  20995. * @ngdoc property
  20996. * @name useCustomPagination
  20997. * @propertyOf ui.grid.pagination.api:GridOptions
  20998. * @description Disables client-side pagination. When true, handle the `paginationChanged` event and set `data`,
  20999. * `firstRowIndex`, `lastRowIndex`, and `totalItems`. Defaults to `false`.
  21000. */
  21001. gridOptions.useCustomPagination = gridOptions.useCustomPagination === true;
  21002. /**
  21003. * @ngdoc property
  21004. * @name totalItems
  21005. * @propertyOf ui.grid.pagination.api:GridOptions
  21006. * @description Total number of items, set automatically when using client side pagination, but needs set by user
  21007. * for server side pagination
  21008. */
  21009. if (gridUtil.isNullOrUndefined(gridOptions.totalItems)) {
  21010. gridOptions.totalItems = 0;
  21011. }
  21012. /**
  21013. * @ngdoc property
  21014. * @name paginationPageSizes
  21015. * @propertyOf ui.grid.pagination.api:GridOptions
  21016. * @description Array of page sizes, defaults to `[250, 500, 1000]`
  21017. */
  21018. if (gridUtil.isNullOrUndefined(gridOptions.paginationPageSizes)) {
  21019. gridOptions.paginationPageSizes = [250, 500, 1000];
  21020. }
  21021. /**
  21022. * @ngdoc property
  21023. * @name paginationPageSize
  21024. * @propertyOf ui.grid.pagination.api:GridOptions
  21025. * @description Page size, defaults to the first item in paginationPageSizes, or 0 if paginationPageSizes is empty
  21026. */
  21027. if (gridUtil.isNullOrUndefined(gridOptions.paginationPageSize)) {
  21028. if (gridOptions.paginationPageSizes.length > 0) {
  21029. gridOptions.paginationPageSize = gridOptions.paginationPageSizes[0];
  21030. } else {
  21031. gridOptions.paginationPageSize = 0;
  21032. }
  21033. }
  21034. /**
  21035. * @ngdoc property
  21036. * @name paginationCurrentPage
  21037. * @propertyOf ui.grid.pagination.api:GridOptions
  21038. * @description Current page number, defaults to 1
  21039. */
  21040. if (gridUtil.isNullOrUndefined(gridOptions.paginationCurrentPage)) {
  21041. gridOptions.paginationCurrentPage = 1;
  21042. }
  21043. /**
  21044. * @ngdoc property
  21045. * @name paginationTemplate
  21046. * @propertyOf ui.grid.pagination.api:GridOptions
  21047. * @description A custom template for the pager, defaults to `ui-grid/pagination`
  21048. */
  21049. if (gridUtil.isNullOrUndefined(gridOptions.paginationTemplate)) {
  21050. gridOptions.paginationTemplate = 'ui-grid/pagination';
  21051. }
  21052. },
  21053. /**
  21054. * @ngdoc method
  21055. * @methodOf ui.grid.pagination.service:uiGridPaginationService
  21056. * @name uiGridPaginationService
  21057. * @description Raises paginationChanged and calls refresh for client side pagination
  21058. * @param {Grid} grid the grid for which the pagination changed
  21059. * @param {int} currentPage requested page number
  21060. * @param {int} pageSize requested page size
  21061. */
  21062. onPaginationChanged: function (grid, currentPage, pageSize) {
  21063. grid.api.pagination.raise.paginationChanged(currentPage, pageSize);
  21064. if (!grid.options.useExternalPagination) {
  21065. grid.queueGridRefresh(); //client side pagination
  21066. }
  21067. }
  21068. };
  21069. return service;
  21070. }
  21071. ]);
  21072. /**
  21073. * @ngdoc directive
  21074. * @name ui.grid.pagination.directive:uiGridPagination
  21075. * @element div
  21076. * @restrict A
  21077. *
  21078. * @description Adds pagination features to grid
  21079. * @example
  21080. <example module="app">
  21081. <file name="app.js">
  21082. var app = angular.module('app', ['ui.grid', 'ui.grid.pagination']);
  21083. app.controller('MainCtrl', ['$scope', function ($scope) {
  21084. $scope.data = [
  21085. { name: 'Alex', car: 'Toyota' },
  21086. { name: 'Sam', car: 'Lexus' },
  21087. { name: 'Joe', car: 'Dodge' },
  21088. { name: 'Bob', car: 'Buick' },
  21089. { name: 'Cindy', car: 'Ford' },
  21090. { name: 'Brian', car: 'Audi' },
  21091. { name: 'Malcom', car: 'Mercedes Benz' },
  21092. { name: 'Dave', car: 'Ford' },
  21093. { name: 'Stacey', car: 'Audi' },
  21094. { name: 'Amy', car: 'Acura' },
  21095. { name: 'Scott', car: 'Toyota' },
  21096. { name: 'Ryan', car: 'BMW' },
  21097. ];
  21098. $scope.gridOptions = {
  21099. data: 'data',
  21100. paginationPageSizes: [5, 10, 25],
  21101. paginationPageSize: 5,
  21102. columnDefs: [
  21103. {name: 'name'},
  21104. {name: 'car'}
  21105. ]
  21106. }
  21107. }]);
  21108. </file>
  21109. <file name="index.html">
  21110. <div ng-controller="MainCtrl">
  21111. <div ui-grid="gridOptions" ui-grid-pagination></div>
  21112. </div>
  21113. </file>
  21114. </example>
  21115. */
  21116. module.directive('uiGridPagination', ['gridUtil', 'uiGridPaginationService',
  21117. function (gridUtil, uiGridPaginationService) {
  21118. return {
  21119. priority: -200,
  21120. scope: false,
  21121. require: 'uiGrid',
  21122. link: {
  21123. pre: function ($scope, $elm, $attr, uiGridCtrl) {
  21124. uiGridPaginationService.initializeGrid(uiGridCtrl.grid);
  21125. gridUtil.getTemplate(uiGridCtrl.grid.options.paginationTemplate)
  21126. .then(function (contents) {
  21127. var template = angular.element(contents);
  21128. $elm.append(template);
  21129. uiGridCtrl.innerCompile(template);
  21130. });
  21131. }
  21132. }
  21133. };
  21134. }
  21135. ]);
  21136. /**
  21137. * @ngdoc directive
  21138. * @name ui.grid.pagination.directive:uiGridPager
  21139. * @element div
  21140. *
  21141. * @description Panel for handling pagination
  21142. */
  21143. module.directive('uiGridPager', ['uiGridPaginationService', 'uiGridConstants', 'gridUtil', 'i18nService', 'i18nConstants',
  21144. function (uiGridPaginationService, uiGridConstants, gridUtil, i18nService, i18nConstants) {
  21145. return {
  21146. priority: -200,
  21147. scope: true,
  21148. require: '^uiGrid',
  21149. link: function ($scope, $elm, $attr, uiGridCtrl) {
  21150. var defaultFocusElementSelector = '.ui-grid-pager-control-input';
  21151. $scope.aria = i18nService.getSafeText('pagination.aria'); //Returns an object with all of the aria labels
  21152. var updateLabels = function(){
  21153. $scope.paginationApi = uiGridCtrl.grid.api.pagination;
  21154. $scope.sizesLabel = i18nService.getSafeText('pagination.sizes');
  21155. $scope.totalItemsLabel = i18nService.getSafeText('pagination.totalItems');
  21156. $scope.paginationOf = i18nService.getSafeText('pagination.of');
  21157. $scope.paginationThrough = i18nService.getSafeText('pagination.through');
  21158. };
  21159. updateLabels();
  21160. $scope.$on(i18nConstants.UPDATE_EVENT, updateLabels);
  21161. var options = uiGridCtrl.grid.options;
  21162. uiGridCtrl.grid.renderContainers.body.registerViewportAdjuster(function (adjustment) {
  21163. if (options.enablePaginationControls) {
  21164. adjustment.height = adjustment.height - gridUtil.elementHeight($elm, "padding");
  21165. }
  21166. return adjustment;
  21167. });
  21168. var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback(function (grid) {
  21169. if (!grid.options.useExternalPagination) {
  21170. grid.options.totalItems = grid.rows.length;
  21171. }
  21172. }, [uiGridConstants.dataChange.ROW]);
  21173. $scope.$on('$destroy', dataChangeDereg);
  21174. var deregP = $scope.$watch('grid.options.paginationCurrentPage + grid.options.paginationPageSize', function (newValues, oldValues) {
  21175. if (newValues === oldValues || oldValues === undefined) {
  21176. return;
  21177. }
  21178. if (!angular.isNumber(options.paginationCurrentPage) || options.paginationCurrentPage < 1) {
  21179. options.paginationCurrentPage = 1;
  21180. return;
  21181. }
  21182. if (options.totalItems > 0 && options.paginationCurrentPage > $scope.paginationApi.getTotalPages()) {
  21183. options.paginationCurrentPage = $scope.paginationApi.getTotalPages();
  21184. return;
  21185. }
  21186. uiGridPaginationService.onPaginationChanged($scope.grid, options.paginationCurrentPage, options.paginationPageSize);
  21187. }
  21188. );
  21189. $scope.$on('$destroy', function() {
  21190. deregP();
  21191. });
  21192. $scope.cantPageForward = function () {
  21193. if ($scope.paginationApi.getTotalPages()) {
  21194. return $scope.cantPageToLast();
  21195. } else {
  21196. return options.data.length < 1;
  21197. }
  21198. };
  21199. $scope.cantPageToLast = function () {
  21200. var totalPages = $scope.paginationApi.getTotalPages();
  21201. return !totalPages || options.paginationCurrentPage >= totalPages;
  21202. };
  21203. $scope.cantPageBackward = function () {
  21204. return options.paginationCurrentPage <= 1;
  21205. };
  21206. var focusToInputIf = function(condition){
  21207. if (condition){
  21208. gridUtil.focus.bySelector($elm, defaultFocusElementSelector);
  21209. }
  21210. };
  21211. //Takes care of setting focus to the middle element when focus is lost
  21212. $scope.pageFirstPageClick = function () {
  21213. $scope.paginationApi.seek(1);
  21214. focusToInputIf($scope.cantPageBackward());
  21215. };
  21216. $scope.pagePreviousPageClick = function () {
  21217. $scope.paginationApi.previousPage();
  21218. focusToInputIf($scope.cantPageBackward());
  21219. };
  21220. $scope.pageNextPageClick = function () {
  21221. $scope.paginationApi.nextPage();
  21222. focusToInputIf($scope.cantPageForward());
  21223. };
  21224. $scope.pageLastPageClick = function () {
  21225. $scope.paginationApi.seek($scope.paginationApi.getTotalPages());
  21226. focusToInputIf($scope.cantPageToLast());
  21227. };
  21228. }
  21229. };
  21230. }
  21231. ]);
  21232. })();
  21233. (function () {
  21234. 'use strict';
  21235. /**
  21236. * @ngdoc overview
  21237. * @name ui.grid.pinning
  21238. * @description
  21239. *
  21240. * # ui.grid.pinning
  21241. *
  21242. * <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>
  21243. *
  21244. * This module provides column pinning to the end user via menu options in the column header
  21245. *
  21246. * <div doc-module-components="ui.grid.pinning"></div>
  21247. */
  21248. var module = angular.module('ui.grid.pinning', ['ui.grid']);
  21249. module.constant('uiGridPinningConstants', {
  21250. container: {
  21251. LEFT: 'left',
  21252. RIGHT: 'right',
  21253. NONE: ''
  21254. }
  21255. });
  21256. module.service('uiGridPinningService', ['gridUtil', 'GridRenderContainer', 'i18nService', 'uiGridPinningConstants', function (gridUtil, GridRenderContainer, i18nService, uiGridPinningConstants) {
  21257. var service = {
  21258. initializeGrid: function (grid) {
  21259. service.defaultGridOptions(grid.options);
  21260. // Register a column builder to add new menu items for pinning left and right
  21261. grid.registerColumnBuilder(service.pinningColumnBuilder);
  21262. /**
  21263. * @ngdoc object
  21264. * @name ui.grid.pinning.api:PublicApi
  21265. *
  21266. * @description Public Api for pinning feature
  21267. */
  21268. var publicApi = {
  21269. events: {
  21270. pinning: {
  21271. /**
  21272. * @ngdoc event
  21273. * @name columnPin
  21274. * @eventOf ui.grid.pinning.api:PublicApi
  21275. * @description raised when column pin state has changed
  21276. * <pre>
  21277. * gridApi.pinning.on.columnPinned(scope, function(colDef){})
  21278. * </pre>
  21279. * @param {object} colDef the column that was changed
  21280. * @param {string} container the render container the column is in ('left', 'right', '')
  21281. */
  21282. columnPinned: function(colDef, container) {
  21283. }
  21284. }
  21285. },
  21286. methods: {
  21287. pinning: {
  21288. /**
  21289. * @ngdoc function
  21290. * @name pinColumn
  21291. * @methodOf ui.grid.pinning.api:PublicApi
  21292. * @description pin column left, right, or none
  21293. * <pre>
  21294. * gridApi.pinning.pinColumn(col, uiGridPinningConstants.container.LEFT)
  21295. * </pre>
  21296. * @param {gridColumn} col the column being pinned
  21297. * @param {string} container one of the recognised types
  21298. * from uiGridPinningConstants
  21299. */
  21300. pinColumn: function(col, container) {
  21301. service.pinColumn(grid, col, container);
  21302. }
  21303. }
  21304. }
  21305. };
  21306. grid.api.registerEventsFromObject(publicApi.events);
  21307. grid.api.registerMethodsFromObject(publicApi.methods);
  21308. },
  21309. defaultGridOptions: function (gridOptions) {
  21310. //default option to true unless it was explicitly set to false
  21311. /**
  21312. * @ngdoc object
  21313. * @name ui.grid.pinning.api:GridOptions
  21314. *
  21315. * @description GridOptions for pinning feature, these are available to be
  21316. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  21317. */
  21318. /**
  21319. * @ngdoc object
  21320. * @name enablePinning
  21321. * @propertyOf ui.grid.pinning.api:GridOptions
  21322. * @description Enable pinning for the entire grid.
  21323. * <br/>Defaults to true
  21324. */
  21325. gridOptions.enablePinning = gridOptions.enablePinning !== false;
  21326. /**
  21327. * @ngdoc object
  21328. * @name hidePinLeft
  21329. * @propertyOf ui.grid.pinning.api:GridOptions
  21330. * @description Hide Pin Left for the entire grid.
  21331. * <br/>Defaults to false
  21332. */
  21333. gridOptions.hidePinLeft = gridOptions.enablePinning && gridOptions.hidePinLeft;
  21334. /**
  21335. * @ngdoc object
  21336. * @name hidePinRight
  21337. * @propertyOf ui.grid.pinning.api:GridOptions
  21338. * @description Hide Pin Right pinning for the entire grid.
  21339. * <br/>Defaults to false
  21340. */
  21341. gridOptions.hidePinRight = gridOptions.enablePinning && gridOptions.hidePinRight;
  21342. },
  21343. pinningColumnBuilder: function (colDef, col, gridOptions) {
  21344. //default to true unless gridOptions or colDef is explicitly false
  21345. /**
  21346. * @ngdoc object
  21347. * @name ui.grid.pinning.api:ColumnDef
  21348. *
  21349. * @description ColumnDef for pinning feature, these are available to be
  21350. * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs}
  21351. */
  21352. /**
  21353. * @ngdoc object
  21354. * @name enablePinning
  21355. * @propertyOf ui.grid.pinning.api:ColumnDef
  21356. * @description Enable pinning for the individual column.
  21357. * <br/>Defaults to true
  21358. */
  21359. colDef.enablePinning = colDef.enablePinning === undefined ? gridOptions.enablePinning : colDef.enablePinning;
  21360. /**
  21361. * @ngdoc object
  21362. * @name hidePinLeft
  21363. * @propertyOf ui.grid.pinning.api:ColumnDef
  21364. * @description Hide Pin Left for the individual column.
  21365. * <br/>Defaults to false
  21366. */
  21367. colDef.hidePinLeft = colDef.hidePinLeft === undefined ? gridOptions.hidePinLeft : colDef.hidePinLeft;
  21368. /**
  21369. * @ngdoc object
  21370. * @name hidePinRight
  21371. * @propertyOf ui.grid.pinning.api:ColumnDef
  21372. * @description Hide Pin Right for the individual column.
  21373. * <br/>Defaults to false
  21374. */
  21375. colDef.hidePinRight = colDef.hidePinRight === undefined ? gridOptions.hidePinRight : colDef.hidePinRight;
  21376. /**
  21377. * @ngdoc object
  21378. * @name pinnedLeft
  21379. * @propertyOf ui.grid.pinning.api:ColumnDef
  21380. * @description Column is pinned left when grid is rendered
  21381. * <br/>Defaults to false
  21382. */
  21383. /**
  21384. * @ngdoc object
  21385. * @name pinnedRight
  21386. * @propertyOf ui.grid.pinning.api:ColumnDef
  21387. * @description Column is pinned right when grid is rendered
  21388. * <br/>Defaults to false
  21389. */
  21390. if (colDef.pinnedLeft) {
  21391. col.renderContainer = 'left';
  21392. col.grid.createLeftContainer();
  21393. }
  21394. else if (colDef.pinnedRight) {
  21395. col.renderContainer = 'right';
  21396. col.grid.createRightContainer();
  21397. }
  21398. if (!colDef.enablePinning) {
  21399. return;
  21400. }
  21401. var pinColumnLeftAction = {
  21402. name: 'ui.grid.pinning.pinLeft',
  21403. title: i18nService.get().pinning.pinLeft,
  21404. icon: 'ui-grid-icon-left-open',
  21405. shown: function () {
  21406. return typeof(this.context.col.renderContainer) === 'undefined' || !this.context.col.renderContainer || this.context.col.renderContainer !== 'left';
  21407. },
  21408. action: function () {
  21409. service.pinColumn(this.context.col.grid, this.context.col, uiGridPinningConstants.container.LEFT);
  21410. }
  21411. };
  21412. var pinColumnRightAction = {
  21413. name: 'ui.grid.pinning.pinRight',
  21414. title: i18nService.get().pinning.pinRight,
  21415. icon: 'ui-grid-icon-right-open',
  21416. shown: function () {
  21417. return typeof(this.context.col.renderContainer) === 'undefined' || !this.context.col.renderContainer || this.context.col.renderContainer !== 'right';
  21418. },
  21419. action: function () {
  21420. service.pinColumn(this.context.col.grid, this.context.col, uiGridPinningConstants.container.RIGHT);
  21421. }
  21422. };
  21423. var removePinAction = {
  21424. name: 'ui.grid.pinning.unpin',
  21425. title: i18nService.get().pinning.unpin,
  21426. icon: 'ui-grid-icon-cancel',
  21427. shown: function () {
  21428. return typeof(this.context.col.renderContainer) !== 'undefined' && this.context.col.renderContainer !== null && this.context.col.renderContainer !== 'body';
  21429. },
  21430. action: function () {
  21431. service.pinColumn(this.context.col.grid, this.context.col, uiGridPinningConstants.container.NONE);
  21432. }
  21433. };
  21434. //// Skip from menu if hidePinLeft or hidePinRight is true
  21435. if (!colDef.hidePinLeft && !gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.pinning.pinLeft')) {
  21436. col.menuItems.push(pinColumnLeftAction);
  21437. }
  21438. if (!colDef.hidePinRight && !gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.pinning.pinRight')) {
  21439. col.menuItems.push(pinColumnRightAction);
  21440. }
  21441. if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.pinning.unpin')) {
  21442. col.menuItems.push(removePinAction);
  21443. }
  21444. },
  21445. pinColumn: function(grid, col, container) {
  21446. if (container === uiGridPinningConstants.container.NONE) {
  21447. col.renderContainer = null;
  21448. col.colDef.pinnedLeft = col.colDef.pinnedRight = false;
  21449. }
  21450. else {
  21451. col.renderContainer = container;
  21452. if (container === uiGridPinningConstants.container.LEFT) {
  21453. grid.createLeftContainer();
  21454. }
  21455. else if (container === uiGridPinningConstants.container.RIGHT) {
  21456. grid.createRightContainer();
  21457. }
  21458. }
  21459. grid.refresh()
  21460. .then(function() {
  21461. grid.api.pinning.raise.columnPinned( col.colDef, container );
  21462. });
  21463. }
  21464. };
  21465. return service;
  21466. }]);
  21467. module.directive('uiGridPinning', ['gridUtil', 'uiGridPinningService',
  21468. function (gridUtil, uiGridPinningService) {
  21469. return {
  21470. require: 'uiGrid',
  21471. scope: false,
  21472. compile: function () {
  21473. return {
  21474. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  21475. uiGridPinningService.initializeGrid(uiGridCtrl.grid);
  21476. },
  21477. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  21478. }
  21479. };
  21480. }
  21481. };
  21482. }]);
  21483. })();
  21484. (function(){
  21485. 'use strict';
  21486. /**
  21487. * @ngdoc overview
  21488. * @name ui.grid.resizeColumns
  21489. * @description
  21490. *
  21491. * # ui.grid.resizeColumns
  21492. *
  21493. * <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>
  21494. *
  21495. * This module allows columns to be resized.
  21496. */
  21497. var module = angular.module('ui.grid.resizeColumns', ['ui.grid']);
  21498. module.service('uiGridResizeColumnsService', ['gridUtil', '$q', '$rootScope',
  21499. function (gridUtil, $q, $rootScope) {
  21500. var service = {
  21501. defaultGridOptions: function(gridOptions){
  21502. //default option to true unless it was explicitly set to false
  21503. /**
  21504. * @ngdoc object
  21505. * @name ui.grid.resizeColumns.api:GridOptions
  21506. *
  21507. * @description GridOptions for resizeColumns feature, these are available to be
  21508. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  21509. */
  21510. /**
  21511. * @ngdoc object
  21512. * @name enableColumnResizing
  21513. * @propertyOf ui.grid.resizeColumns.api:GridOptions
  21514. * @description Enable column resizing on the entire grid
  21515. * <br/>Defaults to true
  21516. */
  21517. gridOptions.enableColumnResizing = gridOptions.enableColumnResizing !== false;
  21518. //legacy support
  21519. //use old name if it is explicitly false
  21520. if (gridOptions.enableColumnResize === false){
  21521. gridOptions.enableColumnResizing = false;
  21522. }
  21523. },
  21524. colResizerColumnBuilder: function (colDef, col, gridOptions) {
  21525. var promises = [];
  21526. /**
  21527. * @ngdoc object
  21528. * @name ui.grid.resizeColumns.api:ColumnDef
  21529. *
  21530. * @description ColumnDef for resizeColumns feature, these are available to be
  21531. * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs}
  21532. */
  21533. /**
  21534. * @ngdoc object
  21535. * @name enableColumnResizing
  21536. * @propertyOf ui.grid.resizeColumns.api:ColumnDef
  21537. * @description Enable column resizing on an individual column
  21538. * <br/>Defaults to GridOptions.enableColumnResizing
  21539. */
  21540. //default to true unless gridOptions or colDef is explicitly false
  21541. colDef.enableColumnResizing = colDef.enableColumnResizing === undefined ? gridOptions.enableColumnResizing : colDef.enableColumnResizing;
  21542. //legacy support of old option name
  21543. if (colDef.enableColumnResize === false){
  21544. colDef.enableColumnResizing = false;
  21545. }
  21546. return $q.all(promises);
  21547. },
  21548. registerPublicApi: function (grid) {
  21549. /**
  21550. * @ngdoc object
  21551. * @name ui.grid.resizeColumns.api:PublicApi
  21552. * @description Public Api for column resize feature.
  21553. */
  21554. var publicApi = {
  21555. events: {
  21556. /**
  21557. * @ngdoc event
  21558. * @name columnSizeChanged
  21559. * @eventOf ui.grid.resizeColumns.api:PublicApi
  21560. * @description raised when column is resized
  21561. * <pre>
  21562. * gridApi.colResizable.on.columnSizeChanged(scope,function(colDef, deltaChange){})
  21563. * </pre>
  21564. * @param {object} colDef the column that was resized
  21565. * @param {integer} delta of the column size change
  21566. */
  21567. colResizable: {
  21568. columnSizeChanged: function (colDef, deltaChange) {
  21569. }
  21570. }
  21571. }
  21572. };
  21573. grid.api.registerEventsFromObject(publicApi.events);
  21574. },
  21575. fireColumnSizeChanged: function (grid, colDef, deltaChange) {
  21576. $rootScope.$applyAsync(function () {
  21577. if ( grid.api.colResizable ){
  21578. grid.api.colResizable.raise.columnSizeChanged(colDef, deltaChange);
  21579. } else {
  21580. 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.");
  21581. }
  21582. });
  21583. },
  21584. // get either this column, or the column next to this column, to resize,
  21585. // returns the column we're going to resize
  21586. findTargetCol: function(col, position, rtlMultiplier){
  21587. var renderContainer = col.getRenderContainer();
  21588. if (position === 'left') {
  21589. // Get the column to the left of this one
  21590. var colIndex = renderContainer.visibleColumnCache.indexOf(col);
  21591. return renderContainer.visibleColumnCache[colIndex - 1 * rtlMultiplier];
  21592. } else {
  21593. return col;
  21594. }
  21595. }
  21596. };
  21597. return service;
  21598. }]);
  21599. /**
  21600. * @ngdoc directive
  21601. * @name ui.grid.resizeColumns.directive:uiGridResizeColumns
  21602. * @element div
  21603. * @restrict A
  21604. * @description
  21605. * 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
  21606. * option to false. This prevents resizing for the entire grid, regardless of individual columnDef options.
  21607. *
  21608. * @example
  21609. <doc:example module="app">
  21610. <doc:source>
  21611. <script>
  21612. var app = angular.module('app', ['ui.grid', 'ui.grid.resizeColumns']);
  21613. app.controller('MainCtrl', ['$scope', function ($scope) {
  21614. $scope.gridOpts = {
  21615. data: [
  21616. { "name": "Ethel Price", "gender": "female", "company": "Enersol" },
  21617. { "name": "Claudine Neal", "gender": "female", "company": "Sealoud" },
  21618. { "name": "Beryl Rice", "gender": "female", "company": "Velity" },
  21619. { "name": "Wilder Gonzales", "gender": "male", "company": "Geekko" }
  21620. ]
  21621. };
  21622. }]);
  21623. </script>
  21624. <div ng-controller="MainCtrl">
  21625. <div class="testGrid" ui-grid="gridOpts" ui-grid-resize-columns ></div>
  21626. </div>
  21627. </doc:source>
  21628. <doc:scenario>
  21629. </doc:scenario>
  21630. </doc:example>
  21631. */
  21632. module.directive('uiGridResizeColumns', ['gridUtil', 'uiGridResizeColumnsService', function (gridUtil, uiGridResizeColumnsService) {
  21633. return {
  21634. replace: true,
  21635. priority: 0,
  21636. require: '^uiGrid',
  21637. scope: false,
  21638. compile: function () {
  21639. return {
  21640. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  21641. uiGridResizeColumnsService.defaultGridOptions(uiGridCtrl.grid.options);
  21642. uiGridCtrl.grid.registerColumnBuilder( uiGridResizeColumnsService.colResizerColumnBuilder);
  21643. uiGridResizeColumnsService.registerPublicApi(uiGridCtrl.grid);
  21644. },
  21645. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  21646. }
  21647. };
  21648. }
  21649. };
  21650. }]);
  21651. // Extend the uiGridHeaderCell directive
  21652. module.directive('uiGridHeaderCell', ['gridUtil', '$templateCache', '$compile', '$q', 'uiGridResizeColumnsService', 'uiGridConstants', function (gridUtil, $templateCache, $compile, $q, uiGridResizeColumnsService, uiGridConstants) {
  21653. return {
  21654. // Run after the original uiGridHeaderCell
  21655. priority: -10,
  21656. require: '^uiGrid',
  21657. // scope: false,
  21658. compile: function() {
  21659. return {
  21660. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  21661. var grid = uiGridCtrl.grid;
  21662. if (grid.options.enableColumnResizing) {
  21663. var columnResizerElm = $templateCache.get('ui-grid/columnResizer');
  21664. var rtlMultiplier = 1;
  21665. //when in RTL mode reverse the direction using the rtlMultiplier and change the position to left
  21666. if (grid.isRTL()) {
  21667. $scope.position = 'left';
  21668. rtlMultiplier = -1;
  21669. }
  21670. var displayResizers = function(){
  21671. // remove any existing resizers.
  21672. var resizers = $elm[0].getElementsByClassName('ui-grid-column-resizer');
  21673. for ( var i = 0; i < resizers.length; i++ ){
  21674. angular.element(resizers[i]).remove();
  21675. }
  21676. // get the target column for the left resizer
  21677. var otherCol = uiGridResizeColumnsService.findTargetCol($scope.col, 'left', rtlMultiplier);
  21678. var renderContainer = $scope.col.getRenderContainer();
  21679. // Don't append the left resizer if this is the first column or the column to the left of this one has resizing disabled
  21680. if (otherCol && renderContainer.visibleColumnCache.indexOf($scope.col) !== 0 && otherCol.colDef.enableColumnResizing !== false) {
  21681. var resizerLeft = angular.element(columnResizerElm).clone();
  21682. resizerLeft.attr('position', 'left');
  21683. $elm.prepend(resizerLeft);
  21684. $compile(resizerLeft)($scope);
  21685. }
  21686. // Don't append the right resizer if this column has resizing disabled
  21687. if ($scope.col.colDef.enableColumnResizing !== false) {
  21688. var resizerRight = angular.element(columnResizerElm).clone();
  21689. resizerRight.attr('position', 'right');
  21690. $elm.append(resizerRight);
  21691. $compile(resizerRight)($scope);
  21692. }
  21693. };
  21694. displayResizers();
  21695. var waitDisplay = function() {
  21696. $scope.$applyAsync(displayResizers);
  21697. };
  21698. var dataChangeDereg = grid.registerDataChangeCallback( waitDisplay, [uiGridConstants.dataChange.COLUMN] );
  21699. $scope.$on( '$destroy', dataChangeDereg );
  21700. }
  21701. }
  21702. };
  21703. }
  21704. };
  21705. }]);
  21706. /**
  21707. * @ngdoc directive
  21708. * @name ui.grid.resizeColumns.directive:uiGridColumnResizer
  21709. * @element div
  21710. * @restrict A
  21711. *
  21712. * @description
  21713. * Draggable handle that controls column resizing.
  21714. *
  21715. * @example
  21716. <doc:example module="app">
  21717. <doc:source>
  21718. <script>
  21719. var app = angular.module('app', ['ui.grid', 'ui.grid.resizeColumns']);
  21720. app.controller('MainCtrl', ['$scope', function ($scope) {
  21721. $scope.gridOpts = {
  21722. enableColumnResizing: true,
  21723. data: [
  21724. { "name": "Ethel Price", "gender": "female", "company": "Enersol" },
  21725. { "name": "Claudine Neal", "gender": "female", "company": "Sealoud" },
  21726. { "name": "Beryl Rice", "gender": "female", "company": "Velity" },
  21727. { "name": "Wilder Gonzales", "gender": "male", "company": "Geekko" }
  21728. ]
  21729. };
  21730. }]);
  21731. </script>
  21732. <div ng-controller="MainCtrl">
  21733. <div class="testGrid" ui-grid="gridOpts"></div>
  21734. </div>
  21735. </doc:source>
  21736. <doc:scenario>
  21737. // TODO: e2e specs?
  21738. // TODO: post-resize a horizontal scroll event should be fired
  21739. </doc:scenario>
  21740. </doc:example>
  21741. */
  21742. module.directive('uiGridColumnResizer', ['$document', 'gridUtil', 'uiGridConstants', 'uiGridResizeColumnsService', function ($document, gridUtil, uiGridConstants, uiGridResizeColumnsService) {
  21743. var resizeOverlay = angular.element('<div class="ui-grid-resize-overlay"></div>');
  21744. var resizer = {
  21745. priority: 0,
  21746. scope: {
  21747. col: '=',
  21748. position: '@',
  21749. renderIndex: '='
  21750. },
  21751. require: '?^uiGrid',
  21752. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  21753. var startX = 0,
  21754. x = 0,
  21755. gridLeft = 0,
  21756. rtlMultiplier = 1;
  21757. //when in RTL mode reverse the direction using the rtlMultiplier and change the position to left
  21758. if (uiGridCtrl.grid.isRTL()) {
  21759. $scope.position = 'left';
  21760. rtlMultiplier = -1;
  21761. }
  21762. if ($scope.position === 'left') {
  21763. $elm.addClass('left');
  21764. }
  21765. else if ($scope.position === 'right') {
  21766. $elm.addClass('right');
  21767. }
  21768. // Refresh the grid canvas
  21769. // takes an argument representing the diff along the X-axis that the resize had
  21770. function refreshCanvas(xDiff) {
  21771. // Then refresh the grid canvas, rebuilding the styles so that the scrollbar updates its size
  21772. uiGridCtrl.grid.refreshCanvas(true).then( function() {
  21773. uiGridCtrl.grid.queueGridRefresh();
  21774. });
  21775. }
  21776. // Check that the requested width isn't wider than the maxWidth, or narrower than the minWidth
  21777. // Returns the new recommended with, after constraints applied
  21778. function constrainWidth(col, width){
  21779. var newWidth = width;
  21780. // If the new width would be less than the column's allowably minimum width, don't allow it
  21781. if (col.minWidth && newWidth < col.minWidth) {
  21782. newWidth = col.minWidth;
  21783. }
  21784. else if (col.maxWidth && newWidth > col.maxWidth) {
  21785. newWidth = col.maxWidth;
  21786. }
  21787. return newWidth;
  21788. }
  21789. /*
  21790. * Our approach to event handling aims to deal with both touch devices and mouse devices
  21791. * We register down handlers on both touch and mouse. When a touchstart or mousedown event
  21792. * occurs, we register the corresponding touchmove/touchend, or mousemove/mouseend events.
  21793. *
  21794. * This way we can listen for both without worrying about the fact many touch devices also emulate
  21795. * mouse events - basically whichever one we hear first is what we'll go with.
  21796. */
  21797. function moveFunction(event, args) {
  21798. if (event.originalEvent) { event = event.originalEvent; }
  21799. event.preventDefault();
  21800. x = (event.targetTouches ? event.targetTouches[0] : event).clientX - gridLeft;
  21801. if (x < 0) { x = 0; }
  21802. else if (x > uiGridCtrl.grid.gridWidth) { x = uiGridCtrl.grid.gridWidth; }
  21803. var col = uiGridResizeColumnsService.findTargetCol($scope.col, $scope.position, rtlMultiplier);
  21804. // Don't resize if it's disabled on this column
  21805. if (col.colDef.enableColumnResizing === false) {
  21806. return;
  21807. }
  21808. if (!uiGridCtrl.grid.element.hasClass('column-resizing')) {
  21809. uiGridCtrl.grid.element.addClass('column-resizing');
  21810. }
  21811. // Get the diff along the X axis
  21812. var xDiff = x - startX;
  21813. // Get the width that this mouse would give the column
  21814. var newWidth = parseInt(col.drawnWidth + xDiff * rtlMultiplier, 10);
  21815. // check we're not outside the allowable bounds for this column
  21816. x = x + ( constrainWidth(col, newWidth) - newWidth ) * rtlMultiplier;
  21817. resizeOverlay.css({ left: x + 'px' });
  21818. uiGridCtrl.fireEvent(uiGridConstants.events.ITEM_DRAGGING);
  21819. }
  21820. function upFunction(event, args) {
  21821. if (event.originalEvent) { event = event.originalEvent; }
  21822. event.preventDefault();
  21823. uiGridCtrl.grid.element.removeClass('column-resizing');
  21824. resizeOverlay.remove();
  21825. // Resize the column
  21826. x = (event.changedTouches ? event.changedTouches[0] : event).clientX - gridLeft;
  21827. var xDiff = x - startX;
  21828. if (xDiff === 0) {
  21829. // no movement, so just reset event handlers, including turning back on both
  21830. // down events - we turned one off when this event started
  21831. offAllEvents();
  21832. onDownEvents();
  21833. return;
  21834. }
  21835. var col = uiGridResizeColumnsService.findTargetCol($scope.col, $scope.position, rtlMultiplier);
  21836. // Don't resize if it's disabled on this column
  21837. if (col.colDef.enableColumnResizing === false) {
  21838. return;
  21839. }
  21840. // Get the new width
  21841. var newWidth = parseInt(col.drawnWidth + xDiff * rtlMultiplier, 10);
  21842. // check we're not outside the allowable bounds for this column
  21843. col.width = constrainWidth(col, newWidth);
  21844. col.hasCustomWidth = true;
  21845. refreshCanvas(xDiff);
  21846. uiGridResizeColumnsService.fireColumnSizeChanged(uiGridCtrl.grid, col.colDef, xDiff);
  21847. // stop listening of up and move events - wait for next down
  21848. // reset the down events - we will have turned one off when this event started
  21849. offAllEvents();
  21850. onDownEvents();
  21851. }
  21852. var downFunction = function(event, args) {
  21853. if (event.originalEvent) { event = event.originalEvent; }
  21854. event.stopPropagation();
  21855. // Get the left offset of the grid
  21856. // gridLeft = uiGridCtrl.grid.element[0].offsetLeft;
  21857. gridLeft = uiGridCtrl.grid.element[0].getBoundingClientRect().left;
  21858. // Get the starting X position, which is the X coordinate of the click minus the grid's offset
  21859. startX = (event.targetTouches ? event.targetTouches[0] : event).clientX - gridLeft;
  21860. // Append the resizer overlay
  21861. uiGridCtrl.grid.element.append(resizeOverlay);
  21862. // Place the resizer overlay at the start position
  21863. resizeOverlay.css({ left: startX });
  21864. // Add handlers for move and up events - if we were mousedown then we listen for mousemove and mouseup, if
  21865. // we were touchdown then we listen for touchmove and touchup. Also remove the handler for the equivalent
  21866. // down event - so if we're touchdown, then remove the mousedown handler until this event is over, if we're
  21867. // mousedown then remove the touchdown handler until this event is over, this avoids processing duplicate events
  21868. if ( event.type === 'touchstart' ){
  21869. $document.on('touchend', upFunction);
  21870. $document.on('touchmove', moveFunction);
  21871. $elm.off('mousedown', downFunction);
  21872. } else {
  21873. $document.on('mouseup', upFunction);
  21874. $document.on('mousemove', moveFunction);
  21875. $elm.off('touchstart', downFunction);
  21876. }
  21877. };
  21878. var onDownEvents = function() {
  21879. $elm.on('mousedown', downFunction);
  21880. $elm.on('touchstart', downFunction);
  21881. };
  21882. var offAllEvents = function() {
  21883. $document.off('mouseup', upFunction);
  21884. $document.off('touchend', upFunction);
  21885. $document.off('mousemove', moveFunction);
  21886. $document.off('touchmove', moveFunction);
  21887. $elm.off('mousedown', downFunction);
  21888. $elm.off('touchstart', downFunction);
  21889. };
  21890. onDownEvents();
  21891. // On doubleclick, resize to fit all rendered cells
  21892. var dblClickFn = function(event, args){
  21893. event.stopPropagation();
  21894. var col = uiGridResizeColumnsService.findTargetCol($scope.col, $scope.position, rtlMultiplier);
  21895. // Don't resize if it's disabled on this column
  21896. if (col.colDef.enableColumnResizing === false) {
  21897. return;
  21898. }
  21899. // Go through the rendered rows and find out the max size for the data in this column
  21900. var maxWidth = 0;
  21901. var xDiff = 0;
  21902. // Get the parent render container element
  21903. var renderContainerElm = gridUtil.closestElm($elm, '.ui-grid-render-container');
  21904. // 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
  21905. var cells = renderContainerElm.querySelectorAll('.' + uiGridConstants.COL_CLASS_PREFIX + col.uid + ' .ui-grid-cell-contents');
  21906. Array.prototype.forEach.call(cells, function (cell) {
  21907. // Get the cell width
  21908. // gridUtil.logDebug('width', gridUtil.elementWidth(cell));
  21909. // Account for the menu button if it exists
  21910. var menuButton;
  21911. if (angular.element(cell).parent().hasClass('ui-grid-header-cell')) {
  21912. menuButton = angular.element(cell).parent()[0].querySelectorAll('.ui-grid-column-menu-button');
  21913. }
  21914. gridUtil.fakeElement(cell, {}, function(newElm) {
  21915. // Make the element float since it's a div and can expand to fill its container
  21916. var e = angular.element(newElm);
  21917. e.attr('style', 'float: left');
  21918. var width = gridUtil.elementWidth(e);
  21919. if (menuButton) {
  21920. var menuButtonWidth = gridUtil.elementWidth(menuButton);
  21921. width = width + menuButtonWidth;
  21922. }
  21923. if (width > maxWidth) {
  21924. maxWidth = width;
  21925. }
  21926. });
  21927. });
  21928. // check we're not outside the allowable bounds for this column
  21929. var newWidth = constrainWidth(col, maxWidth);
  21930. xDiff = newWidth - col.drawnWidth;
  21931. col.width = newWidth;
  21932. col.hasCustomWidth = true;
  21933. refreshCanvas(xDiff);
  21934. uiGridResizeColumnsService.fireColumnSizeChanged(uiGridCtrl.grid, col.colDef, xDiff); };
  21935. $elm.on('dblclick', dblClickFn);
  21936. $elm.on('$destroy', function() {
  21937. $elm.off('dblclick', dblClickFn);
  21938. offAllEvents();
  21939. });
  21940. }
  21941. };
  21942. return resizer;
  21943. }]);
  21944. })();
  21945. (function () {
  21946. 'use strict';
  21947. /**
  21948. * @ngdoc overview
  21949. * @name ui.grid.rowEdit
  21950. * @description
  21951. *
  21952. * # ui.grid.rowEdit
  21953. *
  21954. * <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>
  21955. *
  21956. * This module extends the edit feature to provide tracking and saving of rows
  21957. * of data. The tutorial provides more information on how this feature is best
  21958. * used {@link tutorial/205_row_editable here}.
  21959. * <br/>
  21960. * This feature depends on usage of the ui-grid-edit feature, and also benefits
  21961. * from use of ui-grid-cellNav to provide the full spreadsheet-like editing
  21962. * experience
  21963. *
  21964. */
  21965. var module = angular.module('ui.grid.rowEdit', ['ui.grid', 'ui.grid.edit', 'ui.grid.cellNav']);
  21966. /**
  21967. * @ngdoc object
  21968. * @name ui.grid.rowEdit.constant:uiGridRowEditConstants
  21969. *
  21970. * @description constants available in row edit module
  21971. */
  21972. module.constant('uiGridRowEditConstants', {
  21973. });
  21974. /**
  21975. * @ngdoc service
  21976. * @name ui.grid.rowEdit.service:uiGridRowEditService
  21977. *
  21978. * @description Services for row editing features
  21979. */
  21980. module.service('uiGridRowEditService', ['$interval', '$q', 'uiGridConstants', 'uiGridRowEditConstants', 'gridUtil',
  21981. function ($interval, $q, uiGridConstants, uiGridRowEditConstants, gridUtil) {
  21982. var service = {
  21983. initializeGrid: function (scope, grid) {
  21984. /**
  21985. * @ngdoc object
  21986. * @name ui.grid.rowEdit.api:PublicApi
  21987. *
  21988. * @description Public Api for rowEdit feature
  21989. */
  21990. grid.rowEdit = {};
  21991. var publicApi = {
  21992. events: {
  21993. rowEdit: {
  21994. /**
  21995. * @ngdoc event
  21996. * @eventOf ui.grid.rowEdit.api:PublicApi
  21997. * @name saveRow
  21998. * @description raised when a row is ready for saving. Once your
  21999. * row has saved you may need to use angular.extend to update the
  22000. * data entity with any changed data from your save (for example,
  22001. * lock version information if you're using optimistic locking,
  22002. * or last update time/user information).
  22003. *
  22004. * Your method should call setSavePromise somewhere in the body before
  22005. * returning control. The feature will then wait, with the gridRow greyed out
  22006. * whilst this promise is being resolved.
  22007. *
  22008. * <pre>
  22009. * gridApi.rowEdit.on.saveRow(scope,function(rowEntity){})
  22010. * </pre>
  22011. * and somewhere within the event handler:
  22012. * <pre>
  22013. * gridApi.rowEdit.setSavePromise( rowEntity, savePromise)
  22014. * </pre>
  22015. * @param {object} rowEntity the options.data element that was edited
  22016. * @returns {promise} Your saveRow method should return a promise, the
  22017. * promise should either be resolved (implying successful save), or
  22018. * rejected (implying an error).
  22019. */
  22020. saveRow: function (rowEntity) {
  22021. }
  22022. }
  22023. },
  22024. methods: {
  22025. rowEdit: {
  22026. /**
  22027. * @ngdoc method
  22028. * @methodOf ui.grid.rowEdit.api:PublicApi
  22029. * @name setSavePromise
  22030. * @description Sets the promise associated with the row save, mandatory that
  22031. * the saveRow event handler calls this method somewhere before returning.
  22032. * <pre>
  22033. * gridApi.rowEdit.setSavePromise(rowEntity, savePromise)
  22034. * </pre>
  22035. * @param {object} rowEntity a data row from the grid for which a save has
  22036. * been initiated
  22037. * @param {promise} savePromise the promise that will be resolved when the
  22038. * save is successful, or rejected if the save fails
  22039. *
  22040. */
  22041. setSavePromise: function ( rowEntity, savePromise) {
  22042. service.setSavePromise(grid, rowEntity, savePromise);
  22043. },
  22044. /**
  22045. * @ngdoc method
  22046. * @methodOf ui.grid.rowEdit.api:PublicApi
  22047. * @name getDirtyRows
  22048. * @description Returns all currently dirty rows
  22049. * <pre>
  22050. * gridApi.rowEdit.getDirtyRows(grid)
  22051. * </pre>
  22052. * @returns {array} An array of gridRows that are currently dirty
  22053. *
  22054. */
  22055. getDirtyRows: function () {
  22056. return grid.rowEdit.dirtyRows ? grid.rowEdit.dirtyRows : [];
  22057. },
  22058. /**
  22059. * @ngdoc method
  22060. * @methodOf ui.grid.rowEdit.api:PublicApi
  22061. * @name getErrorRows
  22062. * @description Returns all currently errored rows
  22063. * <pre>
  22064. * gridApi.rowEdit.getErrorRows(grid)
  22065. * </pre>
  22066. * @returns {array} An array of gridRows that are currently in error
  22067. *
  22068. */
  22069. getErrorRows: function () {
  22070. return grid.rowEdit.errorRows ? grid.rowEdit.errorRows : [];
  22071. },
  22072. /**
  22073. * @ngdoc method
  22074. * @methodOf ui.grid.rowEdit.api:PublicApi
  22075. * @name flushDirtyRows
  22076. * @description Triggers a save event for all currently dirty rows, could
  22077. * be used where user presses a save button or navigates away from the page
  22078. * <pre>
  22079. * gridApi.rowEdit.flushDirtyRows(grid)
  22080. * </pre>
  22081. * @returns {promise} a promise that represents the aggregate of all
  22082. * of the individual save promises - i.e. it will be resolved when all
  22083. * the individual save promises have been resolved.
  22084. *
  22085. */
  22086. flushDirtyRows: function () {
  22087. return service.flushDirtyRows(grid);
  22088. },
  22089. /**
  22090. * @ngdoc method
  22091. * @methodOf ui.grid.rowEdit.api:PublicApi
  22092. * @name setRowsDirty
  22093. * @description Sets each of the rows passed in dataRows
  22094. * to be dirty. note that if you have only just inserted the
  22095. * rows into your data you will need to wait for a $digest cycle
  22096. * before the gridRows are present - so often you would wrap this
  22097. * call in a $interval or $timeout
  22098. * <pre>
  22099. * $interval( function() {
  22100. * gridApi.rowEdit.setRowsDirty(myDataRows);
  22101. * }, 0, 1);
  22102. * </pre>
  22103. * @param {array} dataRows the data entities for which the gridRows
  22104. * should be set dirty.
  22105. *
  22106. */
  22107. setRowsDirty: function ( dataRows) {
  22108. service.setRowsDirty(grid, dataRows);
  22109. },
  22110. /**
  22111. * @ngdoc method
  22112. * @methodOf ui.grid.rowEdit.api:PublicApi
  22113. * @name setRowsClean
  22114. * @description Sets each of the rows passed in dataRows
  22115. * to be clean, removing them from the dirty cache and the error cache,
  22116. * and clearing the error flag and the dirty flag
  22117. * <pre>
  22118. * var gridRows = $scope.gridApi.rowEdit.getDirtyRows();
  22119. * var dataRows = gridRows.map( function( gridRow ) { return gridRow.entity; });
  22120. * $scope.gridApi.rowEdit.setRowsClean( dataRows );
  22121. * </pre>
  22122. * @param {array} dataRows the data entities for which the gridRows
  22123. * should be set clean.
  22124. *
  22125. */
  22126. setRowsClean: function ( dataRows) {
  22127. service.setRowsClean(grid, dataRows);
  22128. }
  22129. }
  22130. }
  22131. };
  22132. grid.api.registerEventsFromObject(publicApi.events);
  22133. grid.api.registerMethodsFromObject(publicApi.methods);
  22134. grid.api.core.on.renderingComplete( scope, function ( gridApi ) {
  22135. grid.api.edit.on.afterCellEdit( scope, service.endEditCell );
  22136. grid.api.edit.on.beginCellEdit( scope, service.beginEditCell );
  22137. grid.api.edit.on.cancelCellEdit( scope, service.cancelEditCell );
  22138. if ( grid.api.cellNav ) {
  22139. grid.api.cellNav.on.navigate( scope, service.navigate );
  22140. }
  22141. });
  22142. },
  22143. defaultGridOptions: function (gridOptions) {
  22144. /**
  22145. * @ngdoc object
  22146. * @name ui.grid.rowEdit.api:GridOptions
  22147. *
  22148. * @description Options for configuring the rowEdit feature, these are available to be
  22149. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  22150. */
  22151. },
  22152. /**
  22153. * @ngdoc method
  22154. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22155. * @name saveRow
  22156. * @description Returns a function that saves the specified row from the grid,
  22157. * and returns a promise
  22158. * @param {object} grid the grid for which dirty rows should be flushed
  22159. * @param {GridRow} gridRow the row that should be saved
  22160. * @returns {function} the saveRow function returns a function. That function
  22161. * in turn, when called, returns a promise relating to the save callback
  22162. */
  22163. saveRow: function ( grid, gridRow ) {
  22164. var self = this;
  22165. return function() {
  22166. gridRow.isSaving = true;
  22167. if ( gridRow.rowEditSavePromise ){
  22168. // don't save the row again if it's already saving - that causes stale object exceptions
  22169. return gridRow.rowEditSavePromise;
  22170. }
  22171. var promise = grid.api.rowEdit.raise.saveRow( gridRow.entity );
  22172. if ( gridRow.rowEditSavePromise ){
  22173. gridRow.rowEditSavePromise.then( self.processSuccessPromise( grid, gridRow ), self.processErrorPromise( grid, gridRow ));
  22174. } else {
  22175. 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' );
  22176. }
  22177. return promise;
  22178. };
  22179. },
  22180. /**
  22181. * @ngdoc method
  22182. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22183. * @name setSavePromise
  22184. * @description Sets the promise associated with the row save, mandatory that
  22185. * the saveRow event handler calls this method somewhere before returning.
  22186. * <pre>
  22187. * gridApi.rowEdit.setSavePromise(grid, rowEntity)
  22188. * </pre>
  22189. * @param {object} grid the grid for which dirty rows should be returned
  22190. * @param {object} rowEntity a data row from the grid for which a save has
  22191. * been initiated
  22192. * @param {promise} savePromise the promise that will be resolved when the
  22193. * save is successful, or rejected if the save fails
  22194. *
  22195. */
  22196. setSavePromise: function (grid, rowEntity, savePromise) {
  22197. var gridRow = grid.getRow( rowEntity );
  22198. gridRow.rowEditSavePromise = savePromise;
  22199. },
  22200. /**
  22201. * @ngdoc method
  22202. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22203. * @name processSuccessPromise
  22204. * @description Returns a function that processes the successful
  22205. * resolution of a save promise
  22206. * @param {object} grid the grid for which the promise should be processed
  22207. * @param {GridRow} gridRow the row that has been saved
  22208. * @returns {function} the success handling function
  22209. */
  22210. processSuccessPromise: function ( grid, gridRow ) {
  22211. var self = this;
  22212. return function() {
  22213. delete gridRow.isSaving;
  22214. delete gridRow.isDirty;
  22215. delete gridRow.isError;
  22216. delete gridRow.rowEditSaveTimer;
  22217. delete gridRow.rowEditSavePromise;
  22218. self.removeRow( grid.rowEdit.errorRows, gridRow );
  22219. self.removeRow( grid.rowEdit.dirtyRows, gridRow );
  22220. };
  22221. },
  22222. /**
  22223. * @ngdoc method
  22224. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22225. * @name processErrorPromise
  22226. * @description Returns a function that processes the failed
  22227. * resolution of a save promise
  22228. * @param {object} grid the grid for which the promise should be processed
  22229. * @param {GridRow} gridRow the row that is now in error
  22230. * @returns {function} the error handling function
  22231. */
  22232. processErrorPromise: function ( grid, gridRow ) {
  22233. return function() {
  22234. delete gridRow.isSaving;
  22235. delete gridRow.rowEditSaveTimer;
  22236. delete gridRow.rowEditSavePromise;
  22237. gridRow.isError = true;
  22238. if (!grid.rowEdit.errorRows){
  22239. grid.rowEdit.errorRows = [];
  22240. }
  22241. if (!service.isRowPresent( grid.rowEdit.errorRows, gridRow ) ){
  22242. grid.rowEdit.errorRows.push( gridRow );
  22243. }
  22244. };
  22245. },
  22246. /**
  22247. * @ngdoc method
  22248. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22249. * @name removeRow
  22250. * @description Removes a row from a cache of rows - either
  22251. * grid.rowEdit.errorRows or grid.rowEdit.dirtyRows. If the row
  22252. * is not present silently does nothing.
  22253. * @param {array} rowArray the array from which to remove the row
  22254. * @param {GridRow} gridRow the row that should be removed
  22255. */
  22256. removeRow: function( rowArray, removeGridRow ){
  22257. if (typeof(rowArray) === 'undefined' || rowArray === null){
  22258. return;
  22259. }
  22260. rowArray.forEach( function( gridRow, index ){
  22261. if ( gridRow.uid === removeGridRow.uid ){
  22262. rowArray.splice( index, 1);
  22263. }
  22264. });
  22265. },
  22266. /**
  22267. * @ngdoc method
  22268. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22269. * @name isRowPresent
  22270. * @description Checks whether a row is already present
  22271. * in the given array
  22272. * @param {array} rowArray the array in which to look for the row
  22273. * @param {GridRow} gridRow the row that should be looked for
  22274. */
  22275. isRowPresent: function( rowArray, removeGridRow ){
  22276. var present = false;
  22277. rowArray.forEach( function( gridRow, index ){
  22278. if ( gridRow.uid === removeGridRow.uid ){
  22279. present = true;
  22280. }
  22281. });
  22282. return present;
  22283. },
  22284. /**
  22285. * @ngdoc method
  22286. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22287. * @name flushDirtyRows
  22288. * @description Triggers a save event for all currently dirty rows, could
  22289. * be used where user presses a save button or navigates away from the page
  22290. * <pre>
  22291. * gridApi.rowEdit.flushDirtyRows(grid)
  22292. * </pre>
  22293. * @param {object} grid the grid for which dirty rows should be flushed
  22294. * @returns {promise} a promise that represents the aggregate of all
  22295. * of the individual save promises - i.e. it will be resolved when all
  22296. * the individual save promises have been resolved.
  22297. *
  22298. */
  22299. flushDirtyRows: function(grid){
  22300. var promises = [];
  22301. grid.api.rowEdit.getDirtyRows().forEach( function( gridRow ){
  22302. service.cancelTimer( grid, gridRow );
  22303. service.saveRow( grid, gridRow )();
  22304. promises.push( gridRow.rowEditSavePromise );
  22305. });
  22306. return $q.all( promises );
  22307. },
  22308. /**
  22309. * @ngdoc method
  22310. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22311. * @name endEditCell
  22312. * @description Receives an afterCellEdit event from the edit function,
  22313. * and sets flags as appropriate. Only the rowEntity parameter
  22314. * is processed, although other params are available. Grid
  22315. * is automatically provided by the gridApi.
  22316. * @param {object} rowEntity the data entity for which the cell
  22317. * was edited
  22318. */
  22319. endEditCell: function( rowEntity, colDef, newValue, previousValue ){
  22320. var grid = this.grid;
  22321. var gridRow = grid.getRow( rowEntity );
  22322. if ( !gridRow ){ gridUtil.logError( 'Unable to find rowEntity in grid data, dirty flag cannot be set' ); return; }
  22323. if ( newValue !== previousValue || gridRow.isDirty ){
  22324. if ( !grid.rowEdit.dirtyRows ){
  22325. grid.rowEdit.dirtyRows = [];
  22326. }
  22327. if ( !gridRow.isDirty ){
  22328. gridRow.isDirty = true;
  22329. grid.rowEdit.dirtyRows.push( gridRow );
  22330. }
  22331. delete gridRow.isError;
  22332. service.considerSetTimer( grid, gridRow );
  22333. }
  22334. },
  22335. /**
  22336. * @ngdoc method
  22337. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22338. * @name beginEditCell
  22339. * @description Receives a beginCellEdit event from the edit function,
  22340. * and cancels any rowEditSaveTimers if present, as the user is still editing
  22341. * this row. Only the rowEntity parameter
  22342. * is processed, although other params are available. Grid
  22343. * is automatically provided by the gridApi.
  22344. * @param {object} rowEntity the data entity for which the cell
  22345. * editing has commenced
  22346. */
  22347. beginEditCell: function( rowEntity, colDef ){
  22348. var grid = this.grid;
  22349. var gridRow = grid.getRow( rowEntity );
  22350. if ( !gridRow ){ gridUtil.logError( 'Unable to find rowEntity in grid data, timer cannot be cancelled' ); return; }
  22351. service.cancelTimer( grid, gridRow );
  22352. },
  22353. /**
  22354. * @ngdoc method
  22355. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22356. * @name cancelEditCell
  22357. * @description Receives a cancelCellEdit event from the edit function,
  22358. * and if the row was already dirty, restarts the save timer. If the row
  22359. * was not already dirty, then it's not dirty now either and does nothing.
  22360. *
  22361. * Only the rowEntity parameter
  22362. * is processed, although other params are available. Grid
  22363. * is automatically provided by the gridApi.
  22364. *
  22365. * @param {object} rowEntity the data entity for which the cell
  22366. * editing was cancelled
  22367. */
  22368. cancelEditCell: function( rowEntity, colDef ){
  22369. var grid = this.grid;
  22370. var gridRow = grid.getRow( rowEntity );
  22371. if ( !gridRow ){ gridUtil.logError( 'Unable to find rowEntity in grid data, timer cannot be set' ); return; }
  22372. service.considerSetTimer( grid, gridRow );
  22373. },
  22374. /**
  22375. * @ngdoc method
  22376. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22377. * @name navigate
  22378. * @description cellNav tells us that the selected cell has changed. If
  22379. * the new row had a timer running, then stop it similar to in a beginCellEdit
  22380. * call. If the old row is dirty and not the same as the new row, then
  22381. * start a timer on it.
  22382. * @param {object} newRowCol the row and column that were selected
  22383. * @param {object} oldRowCol the row and column that was left
  22384. *
  22385. */
  22386. navigate: function( newRowCol, oldRowCol ){
  22387. var grid = this.grid;
  22388. if ( newRowCol.row.rowEditSaveTimer ){
  22389. service.cancelTimer( grid, newRowCol.row );
  22390. }
  22391. if ( oldRowCol && oldRowCol.row && oldRowCol.row !== newRowCol.row ){
  22392. service.considerSetTimer( grid, oldRowCol.row );
  22393. }
  22394. },
  22395. /**
  22396. * @ngdoc property
  22397. * @propertyOf ui.grid.rowEdit.api:GridOptions
  22398. * @name rowEditWaitInterval
  22399. * @description How long the grid should wait for another change on this row
  22400. * before triggering a save (in milliseconds). If set to -1, then saves are
  22401. * never triggered by timer (implying that the user will call flushDirtyRows()
  22402. * manually)
  22403. *
  22404. * @example
  22405. * Setting the wait interval to 4 seconds
  22406. * <pre>
  22407. * $scope.gridOptions = { rowEditWaitInterval: 4000 }
  22408. * </pre>
  22409. *
  22410. */
  22411. /**
  22412. * @ngdoc method
  22413. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22414. * @name considerSetTimer
  22415. * @description Consider setting a timer on this row (if it is dirty). if there is a timer running
  22416. * on the row and the row isn't currently saving, cancel it, using cancelTimer, then if the row is
  22417. * dirty and not currently saving then set a new timer
  22418. * @param {object} grid the grid for which we are processing
  22419. * @param {GridRow} gridRow the row for which the timer should be adjusted
  22420. *
  22421. */
  22422. considerSetTimer: function( grid, gridRow ){
  22423. service.cancelTimer( grid, gridRow );
  22424. if ( gridRow.isDirty && !gridRow.isSaving ){
  22425. if ( grid.options.rowEditWaitInterval !== -1 ){
  22426. var waitTime = grid.options.rowEditWaitInterval ? grid.options.rowEditWaitInterval : 2000;
  22427. gridRow.rowEditSaveTimer = $interval( service.saveRow( grid, gridRow ), waitTime, 1);
  22428. }
  22429. }
  22430. },
  22431. /**
  22432. * @ngdoc method
  22433. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22434. * @name cancelTimer
  22435. * @description cancel the $interval for any timer running on this row
  22436. * then delete the timer itself
  22437. * @param {object} grid the grid for which we are processing
  22438. * @param {GridRow} gridRow the row for which the timer should be adjusted
  22439. *
  22440. */
  22441. cancelTimer: function( grid, gridRow ){
  22442. if ( gridRow.rowEditSaveTimer && !gridRow.isSaving ){
  22443. $interval.cancel(gridRow.rowEditSaveTimer);
  22444. delete gridRow.rowEditSaveTimer;
  22445. }
  22446. },
  22447. /**
  22448. * @ngdoc method
  22449. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22450. * @name setRowsDirty
  22451. * @description Sets each of the rows passed in dataRows
  22452. * to be dirty. note that if you have only just inserted the
  22453. * rows into your data you will need to wait for a $digest cycle
  22454. * before the gridRows are present - so often you would wrap this
  22455. * call in a $interval or $timeout
  22456. * <pre>
  22457. * $interval( function() {
  22458. * gridApi.rowEdit.setRowsDirty( myDataRows);
  22459. * }, 0, 1);
  22460. * </pre>
  22461. * @param {object} grid the grid for which rows should be set dirty
  22462. * @param {array} dataRows the data entities for which the gridRows
  22463. * should be set dirty.
  22464. *
  22465. */
  22466. setRowsDirty: function( grid, myDataRows ) {
  22467. var gridRow;
  22468. myDataRows.forEach( function( value, index ){
  22469. gridRow = grid.getRow( value );
  22470. if ( gridRow ){
  22471. if ( !grid.rowEdit.dirtyRows ){
  22472. grid.rowEdit.dirtyRows = [];
  22473. }
  22474. if ( !gridRow.isDirty ){
  22475. gridRow.isDirty = true;
  22476. grid.rowEdit.dirtyRows.push( gridRow );
  22477. }
  22478. delete gridRow.isError;
  22479. service.considerSetTimer( grid, gridRow );
  22480. } else {
  22481. gridUtil.logError( "requested row not found in rowEdit.setRowsDirty, row was: " + value );
  22482. }
  22483. });
  22484. },
  22485. /**
  22486. * @ngdoc method
  22487. * @methodOf ui.grid.rowEdit.service:uiGridRowEditService
  22488. * @name setRowsClean
  22489. * @description Sets each of the rows passed in dataRows
  22490. * to be clean, clearing the dirty flag and the error flag, and removing
  22491. * the rows from the dirty and error caches.
  22492. * @param {object} grid the grid for which rows should be set clean
  22493. * @param {array} dataRows the data entities for which the gridRows
  22494. * should be set clean.
  22495. *
  22496. */
  22497. setRowsClean: function( grid, myDataRows ) {
  22498. var gridRow;
  22499. myDataRows.forEach( function( value, index ){
  22500. gridRow = grid.getRow( value );
  22501. if ( gridRow ){
  22502. delete gridRow.isDirty;
  22503. service.removeRow( grid.rowEdit.dirtyRows, gridRow );
  22504. service.cancelTimer( grid, gridRow );
  22505. delete gridRow.isError;
  22506. service.removeRow( grid.rowEdit.errorRows, gridRow );
  22507. } else {
  22508. gridUtil.logError( "requested row not found in rowEdit.setRowsClean, row was: " + value );
  22509. }
  22510. });
  22511. }
  22512. };
  22513. return service;
  22514. }]);
  22515. /**
  22516. * @ngdoc directive
  22517. * @name ui.grid.rowEdit.directive:uiGridEdit
  22518. * @element div
  22519. * @restrict A
  22520. *
  22521. * @description Adds row editing features to the ui-grid-edit directive.
  22522. *
  22523. */
  22524. module.directive('uiGridRowEdit', ['gridUtil', 'uiGridRowEditService', 'uiGridEditConstants',
  22525. function (gridUtil, uiGridRowEditService, uiGridEditConstants) {
  22526. return {
  22527. replace: true,
  22528. priority: 0,
  22529. require: '^uiGrid',
  22530. scope: false,
  22531. compile: function () {
  22532. return {
  22533. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  22534. uiGridRowEditService.initializeGrid($scope, uiGridCtrl.grid);
  22535. },
  22536. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  22537. }
  22538. };
  22539. }
  22540. };
  22541. }]);
  22542. /**
  22543. * @ngdoc directive
  22544. * @name ui.grid.rowEdit.directive:uiGridViewport
  22545. * @element div
  22546. *
  22547. * @description Stacks on top of ui.grid.uiGridViewport to alter the attributes used
  22548. * for the grid row to allow coloring of saving and error rows
  22549. */
  22550. module.directive('uiGridViewport',
  22551. ['$compile', 'uiGridConstants', 'gridUtil', '$parse',
  22552. function ($compile, uiGridConstants, gridUtil, $parse) {
  22553. return {
  22554. priority: -200, // run after default directive
  22555. scope: false,
  22556. compile: function ($elm, $attrs) {
  22557. var rowRepeatDiv = angular.element($elm.children().children()[0]);
  22558. var existingNgClass = rowRepeatDiv.attr("ng-class");
  22559. var newNgClass = '';
  22560. if ( existingNgClass ) {
  22561. newNgClass = existingNgClass.slice(0, -1) + ", 'ui-grid-row-dirty': row.isDirty, 'ui-grid-row-saving': row.isSaving, 'ui-grid-row-error': row.isError}";
  22562. } else {
  22563. newNgClass = "{'ui-grid-row-dirty': row.isDirty, 'ui-grid-row-saving': row.isSaving, 'ui-grid-row-error': row.isError}";
  22564. }
  22565. rowRepeatDiv.attr("ng-class", newNgClass);
  22566. return {
  22567. pre: function ($scope, $elm, $attrs, controllers) {
  22568. },
  22569. post: function ($scope, $elm, $attrs, controllers) {
  22570. }
  22571. };
  22572. }
  22573. };
  22574. }]);
  22575. })();
  22576. (function () {
  22577. 'use strict';
  22578. /**
  22579. * @ngdoc overview
  22580. * @name ui.grid.saveState
  22581. * @description
  22582. *
  22583. * # ui.grid.saveState
  22584. *
  22585. * <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>
  22586. *
  22587. * This module provides the ability to save the grid state, and restore
  22588. * it when the user returns to the page.
  22589. *
  22590. * No UI is provided, the caller should provide their own UI/buttons
  22591. * as appropriate. Usually the navigate events would be used to save
  22592. * the grid state and restore it.
  22593. *
  22594. * <br/>
  22595. * <br/>
  22596. *
  22597. * <div doc-module-components="ui.grid.save-state"></div>
  22598. */
  22599. var module = angular.module('ui.grid.saveState', ['ui.grid', 'ui.grid.selection', 'ui.grid.cellNav', 'ui.grid.grouping', 'ui.grid.pinning', 'ui.grid.treeView']);
  22600. /**
  22601. * @ngdoc object
  22602. * @name ui.grid.saveState.constant:uiGridSaveStateConstants
  22603. *
  22604. * @description constants available in save state module
  22605. */
  22606. module.constant('uiGridSaveStateConstants', {
  22607. featureName: 'saveState'
  22608. });
  22609. /**
  22610. * @ngdoc service
  22611. * @name ui.grid.saveState.service:uiGridSaveStateService
  22612. *
  22613. * @description Services for saveState feature
  22614. */
  22615. module.service('uiGridSaveStateService', ['$q', 'uiGridSaveStateConstants', 'gridUtil', '$compile', '$interval', 'uiGridConstants',
  22616. function ($q, uiGridSaveStateConstants, gridUtil, $compile, $interval, uiGridConstants ) {
  22617. var service = {
  22618. initializeGrid: function (grid) {
  22619. //add feature namespace and any properties to grid for needed state
  22620. grid.saveState = {};
  22621. this.defaultGridOptions(grid.options);
  22622. /**
  22623. * @ngdoc object
  22624. * @name ui.grid.saveState.api:PublicApi
  22625. *
  22626. * @description Public Api for saveState feature
  22627. */
  22628. var publicApi = {
  22629. events: {
  22630. saveState: {
  22631. }
  22632. },
  22633. methods: {
  22634. saveState: {
  22635. /**
  22636. * @ngdoc function
  22637. * @name save
  22638. * @methodOf ui.grid.saveState.api:PublicApi
  22639. * @description Packages the current state of the grid into
  22640. * an object, and provides it to the user for saving
  22641. * @returns {object} the state as a javascript object that can be saved
  22642. */
  22643. save: function () {
  22644. return service.save(grid);
  22645. },
  22646. /**
  22647. * @ngdoc function
  22648. * @name restore
  22649. * @methodOf ui.grid.saveState.api:PublicApi
  22650. * @description Restores the provided state into the grid
  22651. * @param {scope} $scope a scope that we can broadcast on
  22652. * @param {object} state the state that should be restored into the grid
  22653. * @returns {object} the promise created by refresh
  22654. */
  22655. restore: function ( $scope, state) {
  22656. return service.restore(grid, $scope, state);
  22657. }
  22658. }
  22659. }
  22660. };
  22661. grid.api.registerEventsFromObject(publicApi.events);
  22662. grid.api.registerMethodsFromObject(publicApi.methods);
  22663. },
  22664. defaultGridOptions: function (gridOptions) {
  22665. //default option to true unless it was explicitly set to false
  22666. /**
  22667. * @ngdoc object
  22668. * @name ui.grid.saveState.api:GridOptions
  22669. *
  22670. * @description GridOptions for saveState feature, these are available to be
  22671. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  22672. */
  22673. /**
  22674. * @ngdoc object
  22675. * @name saveWidths
  22676. * @propertyOf ui.grid.saveState.api:GridOptions
  22677. * @description Save the current column widths. Note that unless
  22678. * you've provided the user with some way to resize their columns (say
  22679. * the resize columns feature), then this makes little sense.
  22680. * <br/>Defaults to true
  22681. */
  22682. gridOptions.saveWidths = gridOptions.saveWidths !== false;
  22683. /**
  22684. * @ngdoc object
  22685. * @name saveOrder
  22686. * @propertyOf ui.grid.saveState.api:GridOptions
  22687. * @description Restore the current column order. Note that unless
  22688. * you've provided the user with some way to reorder their columns (for
  22689. * example the move columns feature), this makes little sense.
  22690. * <br/>Defaults to true
  22691. */
  22692. gridOptions.saveOrder = gridOptions.saveOrder !== false;
  22693. /**
  22694. * @ngdoc object
  22695. * @name saveScroll
  22696. * @propertyOf ui.grid.saveState.api:GridOptions
  22697. * @description Save the current scroll position. Note that this
  22698. * is saved as the percentage of the grid scrolled - so if your
  22699. * user returns to a grid with a significantly different number of
  22700. * rows (perhaps some data has been deleted) then the scroll won't
  22701. * actually show the same rows as before. If you want to scroll to
  22702. * a specific row then you should instead use the saveFocus option, which
  22703. * is the default.
  22704. *
  22705. * Note that this element will only be saved if the cellNav feature is
  22706. * enabled
  22707. * <br/>Defaults to false
  22708. */
  22709. gridOptions.saveScroll = gridOptions.saveScroll === true;
  22710. /**
  22711. * @ngdoc object
  22712. * @name saveFocus
  22713. * @propertyOf ui.grid.saveState.api:GridOptions
  22714. * @description Save the current focused cell. On returning
  22715. * to this focused cell we'll also scroll. This option is
  22716. * preferred to the saveScroll option, so is set to true by
  22717. * default. If saveScroll is set to true then this option will
  22718. * be disabled.
  22719. *
  22720. * By default this option saves the current row number and column
  22721. * number, and returns to that row and column. However, if you define
  22722. * a saveRowIdentity function, then it will return you to the currently
  22723. * selected column within that row (in a business sense - so if some
  22724. * rows have been deleted, it will still find the same data, presuming it
  22725. * still exists in the list. If it isn't in the list then it will instead
  22726. * return to the same row number - i.e. scroll percentage)
  22727. *
  22728. * Note that this option will do nothing if the cellNav
  22729. * feature is not enabled.
  22730. *
  22731. * <br/>Defaults to true (unless saveScroll is true)
  22732. */
  22733. gridOptions.saveFocus = gridOptions.saveScroll !== true && gridOptions.saveFocus !== false;
  22734. /**
  22735. * @ngdoc object
  22736. * @name saveRowIdentity
  22737. * @propertyOf ui.grid.saveState.api:GridOptions
  22738. * @description A function that can be called, passing in a rowEntity,
  22739. * and that will return a unique id for that row. This might simply
  22740. * return the `id` field from that row (if you have one), or it might
  22741. * concatenate some fields within the row to make a unique value.
  22742. *
  22743. * This value will be used to find the same row again and set the focus
  22744. * to it, if it exists when we return.
  22745. *
  22746. * <br/>Defaults to undefined
  22747. */
  22748. /**
  22749. * @ngdoc object
  22750. * @name saveVisible
  22751. * @propertyOf ui.grid.saveState.api:GridOptions
  22752. * @description Save whether or not columns are visible.
  22753. *
  22754. * <br/>Defaults to true
  22755. */
  22756. gridOptions.saveVisible = gridOptions.saveVisible !== false;
  22757. /**
  22758. * @ngdoc object
  22759. * @name saveSort
  22760. * @propertyOf ui.grid.saveState.api:GridOptions
  22761. * @description Save the current sort state for each column
  22762. *
  22763. * <br/>Defaults to true
  22764. */
  22765. gridOptions.saveSort = gridOptions.saveSort !== false;
  22766. /**
  22767. * @ngdoc object
  22768. * @name saveFilter
  22769. * @propertyOf ui.grid.saveState.api:GridOptions
  22770. * @description Save the current filter state for each column
  22771. *
  22772. * <br/>Defaults to true
  22773. */
  22774. gridOptions.saveFilter = gridOptions.saveFilter !== false;
  22775. /**
  22776. * @ngdoc object
  22777. * @name saveSelection
  22778. * @propertyOf ui.grid.saveState.api:GridOptions
  22779. * @description Save the currently selected rows. If the `saveRowIdentity` callback
  22780. * is defined, then it will save the id of the row and select that. If not, then
  22781. * it will attempt to select the rows by row number, which will give the wrong results
  22782. * if the data set has changed in the mean-time.
  22783. *
  22784. * Note that this option only does anything
  22785. * if the selection feature is enabled.
  22786. *
  22787. * <br/>Defaults to true
  22788. */
  22789. gridOptions.saveSelection = gridOptions.saveSelection !== false;
  22790. /**
  22791. * @ngdoc object
  22792. * @name saveGrouping
  22793. * @propertyOf ui.grid.saveState.api:GridOptions
  22794. * @description Save the grouping configuration. If set to true and the
  22795. * grouping feature is not enabled then does nothing.
  22796. *
  22797. * <br/>Defaults to true
  22798. */
  22799. gridOptions.saveGrouping = gridOptions.saveGrouping !== false;
  22800. /**
  22801. * @ngdoc object
  22802. * @name saveGroupingExpandedStates
  22803. * @propertyOf ui.grid.saveState.api:GridOptions
  22804. * @description Save the grouping row expanded states. If set to true and the
  22805. * grouping feature is not enabled then does nothing.
  22806. *
  22807. * This can be quite a bit of data, in many cases you wouldn't want to save this
  22808. * information.
  22809. *
  22810. * <br/>Defaults to false
  22811. */
  22812. gridOptions.saveGroupingExpandedStates = gridOptions.saveGroupingExpandedStates === true;
  22813. /**
  22814. * @ngdoc object
  22815. * @name savePinning
  22816. * @propertyOf ui.grid.saveState.api:GridOptions
  22817. * @description Save pinning state for columns.
  22818. *
  22819. * <br/>Defaults to true
  22820. */
  22821. gridOptions.savePinning = gridOptions.savePinning !== false;
  22822. /**
  22823. * @ngdoc object
  22824. * @name saveTreeView
  22825. * @propertyOf ui.grid.saveState.api:GridOptions
  22826. * @description Save the treeView configuration. If set to true and the
  22827. * treeView feature is not enabled then does nothing.
  22828. *
  22829. * <br/>Defaults to true
  22830. */
  22831. gridOptions.saveTreeView = gridOptions.saveTreeView !== false;
  22832. },
  22833. /**
  22834. * @ngdoc function
  22835. * @name save
  22836. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  22837. * @description Saves the current grid state into an object, and
  22838. * passes that object back to the caller
  22839. * @param {Grid} grid the grid whose state we'd like to save
  22840. * @returns {object} the state ready to be saved
  22841. */
  22842. save: function (grid) {
  22843. var savedState = {};
  22844. savedState.columns = service.saveColumns( grid );
  22845. savedState.scrollFocus = service.saveScrollFocus( grid );
  22846. savedState.selection = service.saveSelection( grid );
  22847. savedState.grouping = service.saveGrouping( grid );
  22848. savedState.treeView = service.saveTreeView( grid );
  22849. savedState.pagination = service.savePagination( grid );
  22850. return savedState;
  22851. },
  22852. /**
  22853. * @ngdoc function
  22854. * @name restore
  22855. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  22856. * @description Applies the provided state to the grid
  22857. *
  22858. * @param {Grid} grid the grid whose state we'd like to restore
  22859. * @param {scope} $scope a scope that we can broadcast on
  22860. * @param {object} state the state we'd like to restore
  22861. * @returns {object} the promise created by refresh
  22862. */
  22863. restore: function( grid, $scope, state ){
  22864. if ( state.columns ) {
  22865. service.restoreColumns( grid, state.columns );
  22866. }
  22867. if ( state.scrollFocus ){
  22868. service.restoreScrollFocus( grid, $scope, state.scrollFocus );
  22869. }
  22870. if ( state.selection ){
  22871. service.restoreSelection( grid, state.selection );
  22872. }
  22873. if ( state.grouping ){
  22874. service.restoreGrouping( grid, state.grouping );
  22875. }
  22876. if ( state.treeView ){
  22877. service.restoreTreeView( grid, state.treeView );
  22878. }
  22879. if ( state.pagination ){
  22880. service.restorePagination( grid, state.pagination );
  22881. }
  22882. return grid.refresh();
  22883. },
  22884. /**
  22885. * @ngdoc function
  22886. * @name saveColumns
  22887. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  22888. * @description Saves the column setup, including sort, filters, ordering,
  22889. * pinning and column widths.
  22890. *
  22891. * Works through the current columns, storing them in order. Stores the
  22892. * column name, then the visible flag, width, sort and filters for each column.
  22893. *
  22894. * @param {Grid} grid the grid whose state we'd like to save
  22895. * @returns {array} the columns state ready to be saved
  22896. */
  22897. saveColumns: function( grid ) {
  22898. var columns = [];
  22899. grid.getOnlyDataColumns().forEach( function( column ) {
  22900. var savedColumn = {};
  22901. savedColumn.name = column.name;
  22902. if ( grid.options.saveVisible ){
  22903. savedColumn.visible = column.visible;
  22904. }
  22905. if ( grid.options.saveWidths ){
  22906. savedColumn.width = column.width;
  22907. }
  22908. // these two must be copied, not just pointed too - otherwise our saved state is pointing to the same object as current state
  22909. if ( grid.options.saveSort ){
  22910. savedColumn.sort = angular.copy( column.sort );
  22911. }
  22912. if ( grid.options.saveFilter ){
  22913. savedColumn.filters = [];
  22914. column.filters.forEach( function( filter ){
  22915. var copiedFilter = {};
  22916. angular.forEach( filter, function( value, key) {
  22917. if ( key !== 'condition' && key !== '$$hashKey' && key !== 'placeholder'){
  22918. copiedFilter[key] = value;
  22919. }
  22920. });
  22921. savedColumn.filters.push(copiedFilter);
  22922. });
  22923. }
  22924. if ( !!grid.api.pinning && grid.options.savePinning ){
  22925. savedColumn.pinned = column.renderContainer ? column.renderContainer : '';
  22926. }
  22927. columns.push( savedColumn );
  22928. });
  22929. return columns;
  22930. },
  22931. /**
  22932. * @ngdoc function
  22933. * @name saveScrollFocus
  22934. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  22935. * @description Saves the currently scroll or focus.
  22936. *
  22937. * If cellNav isn't present then does nothing - we can't return
  22938. * to the scroll position without cellNav anyway.
  22939. *
  22940. * If the cellNav module is present, and saveFocus is true, then
  22941. * it saves the currently focused cell. If rowIdentity is present
  22942. * then saves using rowIdentity, otherwise saves visibleRowNum.
  22943. *
  22944. * If the cellNav module is not present, and saveScroll is true, then
  22945. * it approximates the current scroll row and column, and saves that.
  22946. *
  22947. * @param {Grid} grid the grid whose state we'd like to save
  22948. * @returns {object} the selection state ready to be saved
  22949. */
  22950. saveScrollFocus: function( grid ){
  22951. if ( !grid.api.cellNav ){
  22952. return {};
  22953. }
  22954. var scrollFocus = {};
  22955. if ( grid.options.saveFocus ){
  22956. scrollFocus.focus = true;
  22957. var rowCol = grid.api.cellNav.getFocusedCell();
  22958. if ( rowCol !== null ) {
  22959. if ( rowCol.col !== null ){
  22960. scrollFocus.colName = rowCol.col.colDef.name;
  22961. }
  22962. if ( rowCol.row !== null ){
  22963. scrollFocus.rowVal = service.getRowVal( grid, rowCol.row );
  22964. }
  22965. }
  22966. }
  22967. if ( grid.options.saveScroll || grid.options.saveFocus && !scrollFocus.colName && !scrollFocus.rowVal ) {
  22968. scrollFocus.focus = false;
  22969. if ( grid.renderContainers.body.prevRowScrollIndex ){
  22970. scrollFocus.rowVal = service.getRowVal( grid, grid.renderContainers.body.visibleRowCache[ grid.renderContainers.body.prevRowScrollIndex ]);
  22971. }
  22972. if ( grid.renderContainers.body.prevColScrollIndex ){
  22973. scrollFocus.colName = grid.renderContainers.body.visibleColumnCache[ grid.renderContainers.body.prevColScrollIndex ].name;
  22974. }
  22975. }
  22976. return scrollFocus;
  22977. },
  22978. /**
  22979. * @ngdoc function
  22980. * @name saveSelection
  22981. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  22982. * @description Saves the currently selected rows, if the selection feature is enabled
  22983. * @param {Grid} grid the grid whose state we'd like to save
  22984. * @returns {array} the selection state ready to be saved
  22985. */
  22986. saveSelection: function( grid ){
  22987. if ( !grid.api.selection || !grid.options.saveSelection ){
  22988. return [];
  22989. }
  22990. var selection = grid.api.selection.getSelectedGridRows().map( function( gridRow ) {
  22991. return service.getRowVal( grid, gridRow );
  22992. });
  22993. return selection;
  22994. },
  22995. /**
  22996. * @ngdoc function
  22997. * @name saveGrouping
  22998. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  22999. * @description Saves the grouping state, if the grouping feature is enabled
  23000. * @param {Grid} grid the grid whose state we'd like to save
  23001. * @returns {object} the grouping state ready to be saved
  23002. */
  23003. saveGrouping: function( grid ){
  23004. if ( !grid.api.grouping || !grid.options.saveGrouping ){
  23005. return {};
  23006. }
  23007. return grid.api.grouping.getGrouping( grid.options.saveGroupingExpandedStates );
  23008. },
  23009. /**
  23010. * @ngdoc function
  23011. * @name savePagination
  23012. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  23013. * @description Saves the pagination state, if the pagination feature is enabled
  23014. * @param {Grid} grid the grid whose state we'd like to save
  23015. * @returns {object} the pagination state ready to be saved
  23016. */
  23017. savePagination: function( grid ) {
  23018. if ( !grid.api.pagination || !grid.options.paginationPageSize ){
  23019. return {};
  23020. }
  23021. return {
  23022. paginationCurrentPage: grid.options.paginationCurrentPage,
  23023. paginationPageSize: grid.options.paginationPageSize
  23024. };
  23025. },
  23026. /**
  23027. * @ngdoc function
  23028. * @name saveTreeView
  23029. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  23030. * @description Saves the tree view state, if the tree feature is enabled
  23031. * @param {Grid} grid the grid whose state we'd like to save
  23032. * @returns {object} the tree view state ready to be saved
  23033. */
  23034. saveTreeView: function( grid ){
  23035. if ( !grid.api.treeView || !grid.options.saveTreeView ){
  23036. return {};
  23037. }
  23038. return grid.api.treeView.getTreeView();
  23039. },
  23040. /**
  23041. * @ngdoc function
  23042. * @name getRowVal
  23043. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  23044. * @description Helper function that gets either the rowNum or
  23045. * the saveRowIdentity, given a gridRow
  23046. * @param {Grid} grid the grid the row is in
  23047. * @param {GridRow} gridRow the row we want the rowNum for
  23048. * @returns {object} an object containing { identity: true/false, row: rowNumber/rowIdentity }
  23049. *
  23050. */
  23051. getRowVal: function( grid, gridRow ){
  23052. if ( !gridRow ) {
  23053. return null;
  23054. }
  23055. var rowVal = {};
  23056. if ( grid.options.saveRowIdentity ){
  23057. rowVal.identity = true;
  23058. rowVal.row = grid.options.saveRowIdentity( gridRow.entity );
  23059. } else {
  23060. rowVal.identity = false;
  23061. rowVal.row = grid.renderContainers.body.visibleRowCache.indexOf( gridRow );
  23062. }
  23063. return rowVal;
  23064. },
  23065. /**
  23066. * @ngdoc function
  23067. * @name restoreColumns
  23068. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  23069. * @description Restores the columns, including order, visible, width,
  23070. * pinning, sort and filters.
  23071. *
  23072. * @param {Grid} grid the grid whose state we'd like to restore
  23073. * @param {object} columnsState the list of columns we had before, with their state
  23074. */
  23075. restoreColumns: function( grid, columnsState ){
  23076. var isSortChanged = false;
  23077. columnsState.forEach( function( columnState, index ) {
  23078. var currentCol = grid.getColumn( columnState.name );
  23079. if ( currentCol && !grid.isRowHeaderColumn(currentCol) ){
  23080. if ( grid.options.saveVisible &&
  23081. ( currentCol.visible !== columnState.visible ||
  23082. currentCol.colDef.visible !== columnState.visible ) ){
  23083. currentCol.visible = columnState.visible;
  23084. currentCol.colDef.visible = columnState.visible;
  23085. grid.api.core.raise.columnVisibilityChanged(currentCol);
  23086. }
  23087. if ( grid.options.saveWidths && currentCol.width !== columnState.width){
  23088. currentCol.width = columnState.width;
  23089. currentCol.hasCustomWidth = true;
  23090. }
  23091. if ( grid.options.saveSort &&
  23092. !angular.equals(currentCol.sort, columnState.sort) &&
  23093. !( currentCol.sort === undefined && angular.isEmpty(columnState.sort) ) ){
  23094. currentCol.sort = angular.copy( columnState.sort );
  23095. isSortChanged = true;
  23096. }
  23097. if ( grid.options.saveFilter &&
  23098. !angular.equals(currentCol.filters, columnState.filters ) ){
  23099. columnState.filters.forEach( function( filter, index ){
  23100. angular.extend( currentCol.filters[index], filter );
  23101. if ( typeof(filter.term) === 'undefined' || filter.term === null ){
  23102. delete currentCol.filters[index].term;
  23103. }
  23104. });
  23105. grid.api.core.raise.filterChanged();
  23106. }
  23107. if ( !!grid.api.pinning && grid.options.savePinning && currentCol.renderContainer !== columnState.pinned ){
  23108. grid.api.pinning.pinColumn(currentCol, columnState.pinned);
  23109. }
  23110. var currentIndex = grid.getOnlyDataColumns().indexOf( currentCol );
  23111. if (currentIndex !== -1) {
  23112. if (grid.options.saveOrder && currentIndex !== index) {
  23113. var column = grid.columns.splice(currentIndex + grid.rowHeaderColumns.length, 1)[0];
  23114. grid.columns.splice(index + grid.rowHeaderColumns.length, 0, column);
  23115. }
  23116. }
  23117. }
  23118. });
  23119. if ( isSortChanged ) {
  23120. grid.api.core.raise.sortChanged( grid, grid.getColumnSorting() );
  23121. }
  23122. },
  23123. /**
  23124. * @ngdoc function
  23125. * @name restoreScrollFocus
  23126. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  23127. * @description Scrolls to the position that was saved. If focus is true, then
  23128. * sets focus to the specified row/col. If focus is false, then scrolls to the
  23129. * specified row/col.
  23130. *
  23131. * @param {Grid} grid the grid whose state we'd like to restore
  23132. * @param {scope} $scope a scope that we can broadcast on
  23133. * @param {object} scrollFocusState the scroll/focus state ready to be restored
  23134. */
  23135. restoreScrollFocus: function( grid, $scope, scrollFocusState ){
  23136. if ( !grid.api.cellNav ){
  23137. return;
  23138. }
  23139. var colDef, row;
  23140. if ( scrollFocusState.colName ){
  23141. var colDefs = grid.options.columnDefs.filter( function( colDef ) { return colDef.name === scrollFocusState.colName; });
  23142. if ( colDefs.length > 0 ){
  23143. colDef = colDefs[0];
  23144. }
  23145. }
  23146. if ( scrollFocusState.rowVal && scrollFocusState.rowVal.row ){
  23147. if ( scrollFocusState.rowVal.identity ){
  23148. row = service.findRowByIdentity( grid, scrollFocusState.rowVal );
  23149. } else {
  23150. row = grid.renderContainers.body.visibleRowCache[ scrollFocusState.rowVal.row ];
  23151. }
  23152. }
  23153. var entity = row && row.entity ? row.entity : null ;
  23154. if ( colDef || entity ) {
  23155. if (scrollFocusState.focus ){
  23156. grid.api.cellNav.scrollToFocus( entity, colDef );
  23157. } else {
  23158. grid.scrollTo( entity, colDef );
  23159. }
  23160. }
  23161. },
  23162. /**
  23163. * @ngdoc function
  23164. * @name restoreSelection
  23165. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  23166. * @description Selects the rows that are provided in the selection
  23167. * state. If you are using `saveRowIdentity` and more than one row matches the identity
  23168. * function then only the first is selected.
  23169. * @param {Grid} grid the grid whose state we'd like to restore
  23170. * @param {object} selectionState the selection state ready to be restored
  23171. */
  23172. restoreSelection: function( grid, selectionState ){
  23173. if ( !grid.api.selection ){
  23174. return;
  23175. }
  23176. grid.api.selection.clearSelectedRows();
  23177. selectionState.forEach( function( rowVal ) {
  23178. if ( rowVal.identity ){
  23179. var foundRow = service.findRowByIdentity( grid, rowVal );
  23180. if ( foundRow ){
  23181. grid.api.selection.selectRow( foundRow.entity );
  23182. }
  23183. } else {
  23184. grid.api.selection.selectRowByVisibleIndex( rowVal.row );
  23185. }
  23186. });
  23187. },
  23188. /**
  23189. * @ngdoc function
  23190. * @name restoreGrouping
  23191. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  23192. * @description Restores the grouping configuration, if the grouping feature
  23193. * is enabled.
  23194. * @param {Grid} grid the grid whose state we'd like to restore
  23195. * @param {object} groupingState the grouping state ready to be restored
  23196. */
  23197. restoreGrouping: function( grid, groupingState ){
  23198. if ( !grid.api.grouping || typeof(groupingState) === 'undefined' || groupingState === null || angular.equals(groupingState, {}) ){
  23199. return;
  23200. }
  23201. grid.api.grouping.setGrouping( groupingState );
  23202. },
  23203. /**
  23204. * @ngdoc function
  23205. * @name restoreTreeView
  23206. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  23207. * @description Restores the tree view configuration, if the tree view feature
  23208. * is enabled.
  23209. * @param {Grid} grid the grid whose state we'd like to restore
  23210. * @param {object} treeViewState the tree view state ready to be restored
  23211. */
  23212. restoreTreeView: function( grid, treeViewState ){
  23213. if ( !grid.api.treeView || typeof(treeViewState) === 'undefined' || treeViewState === null || angular.equals(treeViewState, {}) ){
  23214. return;
  23215. }
  23216. grid.api.treeView.setTreeView( treeViewState );
  23217. },
  23218. /**
  23219. * @ngdoc function
  23220. * @name restorePagination
  23221. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  23222. * @description Restores the pagination information, if pagination is enabled.
  23223. * @param {Grid} grid the grid whose state we'd like to restore
  23224. * @param {object} pagination the pagination object to be restored
  23225. * @param {number} pagination.paginationCurrentPage the page number to restore
  23226. * @param {number} pagination.paginationPageSize the number of items displayed per page
  23227. */
  23228. restorePagination: function( grid, pagination ){
  23229. if ( !grid.api.pagination || !grid.options.paginationPageSize ){
  23230. return;
  23231. }
  23232. grid.options.paginationCurrentPage = pagination.paginationCurrentPage;
  23233. grid.options.paginationPageSize = pagination.paginationPageSize;
  23234. },
  23235. /**
  23236. * @ngdoc function
  23237. * @name findRowByIdentity
  23238. * @methodOf ui.grid.saveState.service:uiGridSaveStateService
  23239. * @description Finds a row given it's identity value, returns the first found row
  23240. * if any are found, otherwise returns null if no rows are found.
  23241. * @param {Grid} grid the grid whose state we'd like to restore
  23242. * @param {object} rowVal the row we'd like to find
  23243. * @returns {gridRow} the found row, or null if none found
  23244. */
  23245. findRowByIdentity: function( grid, rowVal ){
  23246. if ( !grid.options.saveRowIdentity ){
  23247. return null;
  23248. }
  23249. var filteredRows = grid.rows.filter( function( gridRow ) {
  23250. if ( grid.options.saveRowIdentity( gridRow.entity ) === rowVal.row ){
  23251. return true;
  23252. } else {
  23253. return false;
  23254. }
  23255. });
  23256. if ( filteredRows.length > 0 ){
  23257. return filteredRows[0];
  23258. } else {
  23259. return null;
  23260. }
  23261. }
  23262. };
  23263. return service;
  23264. }
  23265. ]);
  23266. /**
  23267. * @ngdoc directive
  23268. * @name ui.grid.saveState.directive:uiGridSaveState
  23269. * @element div
  23270. * @restrict A
  23271. *
  23272. * @description Adds saveState features to grid
  23273. *
  23274. * @example
  23275. <example module="app">
  23276. <file name="app.js">
  23277. var app = angular.module('app', ['ui.grid', 'ui.grid.saveState']);
  23278. app.controller('MainCtrl', ['$scope', function ($scope) {
  23279. $scope.data = [
  23280. { name: 'Bob', title: 'CEO' },
  23281. { name: 'Frank', title: 'Lowly Developer' }
  23282. ];
  23283. $scope.gridOptions = {
  23284. columnDefs: [
  23285. {name: 'name'},
  23286. {name: 'title', enableCellEdit: true}
  23287. ],
  23288. data: $scope.data
  23289. };
  23290. }]);
  23291. </file>
  23292. <file name="index.html">
  23293. <div ng-controller="MainCtrl">
  23294. <div ui-grid="gridOptions" ui-grid-save-state></div>
  23295. </div>
  23296. </file>
  23297. </example>
  23298. */
  23299. module.directive('uiGridSaveState', ['uiGridSaveStateConstants', 'uiGridSaveStateService', 'gridUtil', '$compile',
  23300. function (uiGridSaveStateConstants, uiGridSaveStateService, gridUtil, $compile) {
  23301. return {
  23302. replace: true,
  23303. priority: 0,
  23304. require: '^uiGrid',
  23305. scope: false,
  23306. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  23307. uiGridSaveStateService.initializeGrid(uiGridCtrl.grid);
  23308. }
  23309. };
  23310. }
  23311. ]);
  23312. })();
  23313. (function () {
  23314. 'use strict';
  23315. /**
  23316. * @ngdoc overview
  23317. * @name ui.grid.selection
  23318. * @description
  23319. *
  23320. * # ui.grid.selection
  23321. * This module provides row selection
  23322. *
  23323. * <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>
  23324. *
  23325. * <div doc-module-components="ui.grid.selection"></div>
  23326. */
  23327. var module = angular.module('ui.grid.selection', ['ui.grid']);
  23328. /**
  23329. * @ngdoc object
  23330. * @name ui.grid.selection.constant:uiGridSelectionConstants
  23331. *
  23332. * @description constants available in selection module
  23333. */
  23334. module.constant('uiGridSelectionConstants', {
  23335. featureName: "selection",
  23336. selectionRowHeaderColName: 'selectionRowHeaderCol'
  23337. });
  23338. //add methods to GridRow
  23339. angular.module('ui.grid').config(['$provide', function ($provide) {
  23340. $provide.decorator('GridRow', ['$delegate', function ($delegate) {
  23341. /**
  23342. * @ngdoc object
  23343. * @name ui.grid.selection.api:GridRow
  23344. *
  23345. * @description GridRow prototype functions added for selection
  23346. */
  23347. /**
  23348. * @ngdoc object
  23349. * @name enableSelection
  23350. * @propertyOf ui.grid.selection.api:GridRow
  23351. * @description Enable row selection for this row, only settable by internal code.
  23352. *
  23353. * The grouping feature, for example, might set group header rows to not be selectable.
  23354. * <br/>Defaults to true
  23355. */
  23356. /**
  23357. * @ngdoc object
  23358. * @name isSelected
  23359. * @propertyOf ui.grid.selection.api:GridRow
  23360. * @description Selected state of row. Should be readonly. Make any changes to selected state using setSelected().
  23361. * <br/>Defaults to false
  23362. */
  23363. /**
  23364. * @ngdoc function
  23365. * @name setSelected
  23366. * @methodOf ui.grid.selection.api:GridRow
  23367. * @description Sets the isSelected property and updates the selectedCount
  23368. * Changes to isSelected state should only be made via this function
  23369. * @param {bool} selected value to set
  23370. */
  23371. $delegate.prototype.setSelected = function (selected) {
  23372. if (selected !== this.isSelected) {
  23373. this.isSelected = selected;
  23374. this.grid.selection.selectedCount += selected ? 1 : -1;
  23375. }
  23376. };
  23377. return $delegate;
  23378. }]);
  23379. }]);
  23380. /**
  23381. * @ngdoc service
  23382. * @name ui.grid.selection.service:uiGridSelectionService
  23383. *
  23384. * @description Services for selection features
  23385. */
  23386. module.service('uiGridSelectionService', ['$q', '$templateCache', 'uiGridSelectionConstants', 'gridUtil',
  23387. function ($q, $templateCache, uiGridSelectionConstants, gridUtil) {
  23388. var service = {
  23389. initializeGrid: function (grid) {
  23390. //add feature namespace and any properties to grid for needed
  23391. /**
  23392. * @ngdoc object
  23393. * @name ui.grid.selection.grid:selection
  23394. *
  23395. * @description Grid properties and functions added for selection
  23396. */
  23397. grid.selection = {};
  23398. grid.selection.lastSelectedRow = null;
  23399. grid.selection.selectAll = false;
  23400. /**
  23401. * @ngdoc object
  23402. * @name selectedCount
  23403. * @propertyOf ui.grid.selection.grid:selection
  23404. * @description Current count of selected rows
  23405. * @example
  23406. * var count = grid.selection.selectedCount
  23407. */
  23408. grid.selection.selectedCount = 0;
  23409. service.defaultGridOptions(grid.options);
  23410. /**
  23411. * @ngdoc object
  23412. * @name ui.grid.selection.api:PublicApi
  23413. *
  23414. * @description Public Api for selection feature
  23415. */
  23416. var publicApi = {
  23417. events: {
  23418. selection: {
  23419. /**
  23420. * @ngdoc event
  23421. * @name rowSelectionChanged
  23422. * @eventOf ui.grid.selection.api:PublicApi
  23423. * @description is raised after the row.isSelected state is changed
  23424. * @param {object} scope the scope associated with the grid
  23425. * @param {GridRow} row the row that was selected/deselected
  23426. * @param {Event} evt object if raised from an event
  23427. */
  23428. rowSelectionChanged: function (scope, row, evt) {
  23429. },
  23430. /**
  23431. * @ngdoc event
  23432. * @name rowSelectionChangedBatch
  23433. * @eventOf ui.grid.selection.api:PublicApi
  23434. * @description is raised after the row.isSelected state is changed
  23435. * in bulk, if the `enableSelectionBatchEvent` option is set to true
  23436. * (which it is by default). This allows more efficient processing
  23437. * of bulk events.
  23438. * @param {object} scope the scope associated with the grid
  23439. * @param {array} rows the rows that were selected/deselected
  23440. * @param {Event} evt object if raised from an event
  23441. */
  23442. rowSelectionChangedBatch: function (scope, rows, evt) {
  23443. }
  23444. }
  23445. },
  23446. methods: {
  23447. selection: {
  23448. /**
  23449. * @ngdoc function
  23450. * @name toggleRowSelection
  23451. * @methodOf ui.grid.selection.api:PublicApi
  23452. * @description Toggles data row as selected or unselected
  23453. * @param {object} rowEntity gridOptions.data[] array instance
  23454. * @param {Event} evt object if raised from an event
  23455. */
  23456. toggleRowSelection: function (rowEntity, evt) {
  23457. var row = grid.getRow(rowEntity);
  23458. if (row !== null) {
  23459. service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect);
  23460. }
  23461. },
  23462. /**
  23463. * @ngdoc function
  23464. * @name selectRow
  23465. * @methodOf ui.grid.selection.api:PublicApi
  23466. * @description Select the data row
  23467. * @param {object} rowEntity gridOptions.data[] array instance
  23468. * @param {Event} evt object if raised from an event
  23469. */
  23470. selectRow: function (rowEntity, evt) {
  23471. var row = grid.getRow(rowEntity);
  23472. if (row !== null && !row.isSelected) {
  23473. service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect);
  23474. }
  23475. },
  23476. /**
  23477. * @ngdoc function
  23478. * @name selectRowByVisibleIndex
  23479. * @methodOf ui.grid.selection.api:PublicApi
  23480. * @description Select the specified row by visible index (i.e. if you
  23481. * specify row 0 you'll get the first visible row selected). In this context
  23482. * visible means of those rows that are theoretically visible (i.e. not filtered),
  23483. * rather than rows currently rendered on the screen.
  23484. * @param {number} rowNum index within the rowsVisible array
  23485. * @param {Event} evt object if raised from an event
  23486. */
  23487. selectRowByVisibleIndex: function (rowNum, evt) {
  23488. var row = grid.renderContainers.body.visibleRowCache[rowNum];
  23489. if (row !== null && typeof (row) !== 'undefined' && !row.isSelected) {
  23490. service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect);
  23491. }
  23492. },
  23493. /**
  23494. * @ngdoc function
  23495. * @name unSelectRow
  23496. * @methodOf ui.grid.selection.api:PublicApi
  23497. * @description UnSelect the data row
  23498. * @param {object} rowEntity gridOptions.data[] array instance
  23499. * @param {Event} evt object if raised from an event
  23500. */
  23501. unSelectRow: function (rowEntity, evt) {
  23502. var row = grid.getRow(rowEntity);
  23503. if (row !== null && row.isSelected) {
  23504. service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect);
  23505. }
  23506. },
  23507. /**
  23508. * @ngdoc function
  23509. * @name unSelectRowByVisibleIndex
  23510. * @methodOf ui.grid.selection.api:PublicApi
  23511. * @description Unselect the specified row by visible index (i.e. if you
  23512. * specify row 0 you'll get the first visible row unselected). In this context
  23513. * visible means of those rows that are theoretically visible (i.e. not filtered),
  23514. * rather than rows currently rendered on the screen.
  23515. * @param {number} rowNum index within the rowsVisible array
  23516. * @param {Event} evt object if raised from an event
  23517. */
  23518. unSelectRowByVisibleIndex: function (rowNum, evt) {
  23519. var row = grid.renderContainers.body.visibleRowCache[rowNum];
  23520. if (row !== null && typeof (row) !== 'undefined' && row.isSelected) {
  23521. service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect);
  23522. }
  23523. },
  23524. /**
  23525. * @ngdoc function
  23526. * @name selectAllRows
  23527. * @methodOf ui.grid.selection.api:PublicApi
  23528. * @description Selects all rows. Does nothing if multiSelect = false
  23529. * @param {Event} evt object if raised from an event
  23530. */
  23531. selectAllRows: function (evt) {
  23532. if (grid.options.multiSelect !== false) {
  23533. var changedRows = [];
  23534. grid.rows.forEach(function (row) {
  23535. if (!row.isSelected && row.enableSelection !== false && grid.options.isRowSelectable(row) !== false) {
  23536. row.setSelected(true);
  23537. service.decideRaiseSelectionEvent(grid, row, changedRows, evt);
  23538. }
  23539. });
  23540. service.decideRaiseSelectionBatchEvent(grid, changedRows, evt);
  23541. grid.selection.selectAll = true;
  23542. }
  23543. },
  23544. /**
  23545. * @ngdoc function
  23546. * @name selectAllVisibleRows
  23547. * @methodOf ui.grid.selection.api:PublicApi
  23548. * @description Selects all visible rows. Does nothing if multiSelect = false
  23549. * @param {Event} evt object if raised from an event
  23550. */
  23551. selectAllVisibleRows: function (evt) {
  23552. if (grid.options.multiSelect !== false) {
  23553. var changedRows = [];
  23554. grid.rows.forEach(function(row) {
  23555. if (row.visible) {
  23556. if (!row.isSelected && row.enableSelection !== false && grid.options.isRowSelectable(row) !== false) {
  23557. row.setSelected(true);
  23558. service.decideRaiseSelectionEvent(grid, row, changedRows, evt);
  23559. }
  23560. } else if (row.isSelected) {
  23561. row.setSelected(false);
  23562. service.decideRaiseSelectionEvent(grid, row, changedRows, evt);
  23563. }
  23564. });
  23565. service.decideRaiseSelectionBatchEvent(grid, changedRows, evt);
  23566. grid.selection.selectAll = true;
  23567. }
  23568. },
  23569. /**
  23570. * @ngdoc function
  23571. * @name clearSelectedRows
  23572. * @methodOf ui.grid.selection.api:PublicApi
  23573. * @description Unselects all rows
  23574. * @param {Event} evt object if raised from an event
  23575. */
  23576. clearSelectedRows: function (evt) {
  23577. service.clearSelectedRows(grid, evt);
  23578. },
  23579. /**
  23580. * @ngdoc function
  23581. * @name getSelectedRows
  23582. * @methodOf ui.grid.selection.api:PublicApi
  23583. * @description returns all selectedRow's entity references
  23584. */
  23585. getSelectedRows: function () {
  23586. return service.getSelectedRows(grid).map(function (gridRow) {
  23587. return gridRow.entity;
  23588. }).filter(function (entity) {
  23589. return entity.hasOwnProperty('$$hashKey');
  23590. });
  23591. },
  23592. /**
  23593. * @ngdoc function
  23594. * @name getSelectedGridRows
  23595. * @methodOf ui.grid.selection.api:PublicApi
  23596. * @description returns all selectedRow's as gridRows
  23597. */
  23598. getSelectedGridRows: function () {
  23599. return service.getSelectedRows(grid);
  23600. },
  23601. /**
  23602. * @ngdoc function
  23603. * @name getSelectedCount
  23604. * @methodOf ui.grid.selection.api:PublicApi
  23605. * @description returns the number of rows selected
  23606. */
  23607. getSelectedCount: function () {
  23608. return grid.selection.selectedCount;
  23609. },
  23610. /**
  23611. * @ngdoc function
  23612. * @name setMultiSelect
  23613. * @methodOf ui.grid.selection.api:PublicApi
  23614. * @description Sets the current gridOption.multiSelect to true or false
  23615. * @param {bool} multiSelect true to allow multiple rows
  23616. */
  23617. setMultiSelect: function (multiSelect) {
  23618. grid.options.multiSelect = multiSelect;
  23619. },
  23620. /**
  23621. * @ngdoc function
  23622. * @name setModifierKeysToMultiSelect
  23623. * @methodOf ui.grid.selection.api:PublicApi
  23624. * @description Sets the current gridOption.modifierKeysToMultiSelect to true or false
  23625. * @param {bool} modifierKeysToMultiSelect true to only allow multiple rows when using ctrlKey or shiftKey is used
  23626. */
  23627. setModifierKeysToMultiSelect: function (modifierKeysToMultiSelect) {
  23628. grid.options.modifierKeysToMultiSelect = modifierKeysToMultiSelect;
  23629. },
  23630. /**
  23631. * @ngdoc function
  23632. * @name getSelectAllState
  23633. * @methodOf ui.grid.selection.api:PublicApi
  23634. * @description Returns whether or not the selectAll checkbox is currently ticked. The
  23635. * grid doesn't automatically select rows when you add extra data - so when you add data
  23636. * you need to explicitly check whether the selectAll is set, and then call setVisible rows
  23637. * if it is
  23638. */
  23639. getSelectAllState: function () {
  23640. return grid.selection.selectAll;
  23641. }
  23642. }
  23643. }
  23644. };
  23645. grid.api.registerEventsFromObject(publicApi.events);
  23646. grid.api.registerMethodsFromObject(publicApi.methods);
  23647. },
  23648. defaultGridOptions: function (gridOptions) {
  23649. //default option to true unless it was explicitly set to false
  23650. /**
  23651. * @ngdoc object
  23652. * @name ui.grid.selection.api:GridOptions
  23653. *
  23654. * @description GridOptions for selection feature, these are available to be
  23655. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  23656. */
  23657. /**
  23658. * @ngdoc object
  23659. * @name enableRowSelection
  23660. * @propertyOf ui.grid.selection.api:GridOptions
  23661. * @description Enable row selection for entire grid.
  23662. * <br/>Defaults to true
  23663. */
  23664. gridOptions.enableRowSelection = gridOptions.enableRowSelection !== false;
  23665. /**
  23666. * @ngdoc object
  23667. * @name multiSelect
  23668. * @propertyOf ui.grid.selection.api:GridOptions
  23669. * @description Enable multiple row selection for entire grid
  23670. * <br/>Defaults to true
  23671. */
  23672. gridOptions.multiSelect = gridOptions.multiSelect !== false;
  23673. /**
  23674. * @ngdoc object
  23675. * @name noUnselect
  23676. * @propertyOf ui.grid.selection.api:GridOptions
  23677. * @description Prevent a row from being unselected. Works in conjunction
  23678. * with `multiselect = false` and `gridApi.selection.selectRow()` to allow
  23679. * you to create a single selection only grid - a row is always selected, you
  23680. * can only select different rows, you can't unselect the row.
  23681. * <br/>Defaults to false
  23682. */
  23683. gridOptions.noUnselect = gridOptions.noUnselect === true;
  23684. /**
  23685. * @ngdoc object
  23686. * @name modifierKeysToMultiSelect
  23687. * @propertyOf ui.grid.selection.api:GridOptions
  23688. * @description Enable multiple row selection only when using the ctrlKey or shiftKey. Requires multiSelect to be true.
  23689. * <br/>Defaults to false
  23690. */
  23691. gridOptions.modifierKeysToMultiSelect = gridOptions.modifierKeysToMultiSelect === true;
  23692. /**
  23693. * @ngdoc object
  23694. * @name enableRowHeaderSelection
  23695. * @propertyOf ui.grid.selection.api:GridOptions
  23696. * @description Enable a row header to be used for selection
  23697. * <br/>Defaults to true
  23698. */
  23699. gridOptions.enableRowHeaderSelection = gridOptions.enableRowHeaderSelection !== false;
  23700. /**
  23701. * @ngdoc object
  23702. * @name enableFullRowSelection
  23703. * @propertyOf ui.grid.selection.api:GridOptions
  23704. * @description Enable selection by clicking anywhere on the row. Defaults to
  23705. * false if `enableRowHeaderSelection` is true, otherwise defaults to false.
  23706. */
  23707. if (typeof (gridOptions.enableFullRowSelection) === 'undefined') {
  23708. gridOptions.enableFullRowSelection = !gridOptions.enableRowHeaderSelection;
  23709. }
  23710. /**
  23711. * @ngdoc object
  23712. * @name enableSelectAll
  23713. * @propertyOf ui.grid.selection.api:GridOptions
  23714. * @description Enable the select all checkbox at the top of the selectionRowHeader
  23715. * <br/>Defaults to true
  23716. */
  23717. gridOptions.enableSelectAll = gridOptions.enableSelectAll !== false;
  23718. /**
  23719. * @ngdoc object
  23720. * @name enableSelectionBatchEvent
  23721. * @propertyOf ui.grid.selection.api:GridOptions
  23722. * @description If selected rows are changed in bulk, either via the API or
  23723. * via the selectAll checkbox, then a separate event is fired. Setting this
  23724. * option to false will cause the rowSelectionChanged event to be called multiple times
  23725. * instead
  23726. * <br/>Defaults to true
  23727. */
  23728. gridOptions.enableSelectionBatchEvent = gridOptions.enableSelectionBatchEvent !== false;
  23729. /**
  23730. * @ngdoc object
  23731. * @name selectionRowHeaderWidth
  23732. * @propertyOf ui.grid.selection.api:GridOptions
  23733. * @description can be used to set a custom width for the row header selection column
  23734. * <br/>Defaults to 30px
  23735. */
  23736. gridOptions.selectionRowHeaderWidth = angular.isDefined(gridOptions.selectionRowHeaderWidth) ? gridOptions.selectionRowHeaderWidth : 30;
  23737. /**
  23738. * @ngdoc object
  23739. * @name enableFooterTotalSelected
  23740. * @propertyOf ui.grid.selection.api:GridOptions
  23741. * @description Shows the total number of selected items in footer if true.
  23742. * <br/>Defaults to true.
  23743. * <br/>GridOptions.showGridFooter must also be set to true.
  23744. */
  23745. gridOptions.enableFooterTotalSelected = gridOptions.enableFooterTotalSelected !== false;
  23746. /**
  23747. * @ngdoc object
  23748. * @name isRowSelectable
  23749. * @propertyOf ui.grid.selection.api:GridOptions
  23750. * @description Makes it possible to specify a method that evaluates for each row and sets its "enableSelection" property.
  23751. */
  23752. gridOptions.isRowSelectable = angular.isDefined(gridOptions.isRowSelectable) ? gridOptions.isRowSelectable : angular.noop;
  23753. },
  23754. /**
  23755. * @ngdoc function
  23756. * @name toggleRowSelection
  23757. * @methodOf ui.grid.selection.service:uiGridSelectionService
  23758. * @description Toggles row as selected or unselected
  23759. * @param {Grid} grid grid object
  23760. * @param {GridRow} row row to select or deselect
  23761. * @param {Event} evt object if resulting from event
  23762. * @param {bool} multiSelect if false, only one row at time can be selected
  23763. * @param {bool} noUnselect if true then rows cannot be unselected
  23764. */
  23765. toggleRowSelection: function (grid, row, evt, multiSelect, noUnselect) {
  23766. var selected = row.isSelected;
  23767. if (row.enableSelection === false) {
  23768. return;
  23769. }
  23770. var selectedRows;
  23771. if (!multiSelect && !selected) {
  23772. service.clearSelectedRows(grid, evt);
  23773. } else if (!multiSelect && selected) {
  23774. selectedRows = service.getSelectedRows(grid);
  23775. if (selectedRows.length > 1) {
  23776. selected = false; // Enable reselect of the row
  23777. service.clearSelectedRows(grid, evt);
  23778. }
  23779. }
  23780. if (selected && noUnselect) {
  23781. // don't deselect the row
  23782. } else {
  23783. row.setSelected(!selected);
  23784. if (row.isSelected === true) {
  23785. grid.selection.lastSelectedRow = row;
  23786. }
  23787. selectedRows = service.getSelectedRows(grid);
  23788. grid.selection.selectAll = grid.rows.length === selectedRows.length;
  23789. grid.api.selection.raise.rowSelectionChanged(row, evt);
  23790. }
  23791. },
  23792. /**
  23793. * @ngdoc function
  23794. * @name shiftSelect
  23795. * @methodOf ui.grid.selection.service:uiGridSelectionService
  23796. * @description selects a group of rows from the last selected row using the shift key
  23797. * @param {Grid} grid grid object
  23798. * @param {GridRow} row clicked row
  23799. * @param {Event} evt object if raised from an event
  23800. * @param {bool} multiSelect if false, does nothing this is for multiSelect only
  23801. */
  23802. shiftSelect: function (grid, row, evt, multiSelect) {
  23803. if (!multiSelect) {
  23804. return;
  23805. }
  23806. var selectedRows = service.getSelectedRows(grid);
  23807. var fromRow = selectedRows.length > 0 ? grid.renderContainers.body.visibleRowCache.indexOf(grid.selection.lastSelectedRow) : 0;
  23808. var toRow = grid.renderContainers.body.visibleRowCache.indexOf(row);
  23809. //reverse select direction
  23810. if (fromRow > toRow) {
  23811. var tmp = fromRow;
  23812. fromRow = toRow;
  23813. toRow = tmp;
  23814. }
  23815. var changedRows = [];
  23816. for (var i = fromRow; i <= toRow; i++) {
  23817. var rowToSelect = grid.renderContainers.body.visibleRowCache[i];
  23818. if (rowToSelect) {
  23819. if (!rowToSelect.isSelected && rowToSelect.enableSelection !== false) {
  23820. rowToSelect.setSelected(true);
  23821. grid.selection.lastSelectedRow = rowToSelect;
  23822. service.decideRaiseSelectionEvent(grid, rowToSelect, changedRows, evt);
  23823. }
  23824. }
  23825. }
  23826. service.decideRaiseSelectionBatchEvent(grid, changedRows, evt);
  23827. },
  23828. /**
  23829. * @ngdoc function
  23830. * @name getSelectedRows
  23831. * @methodOf ui.grid.selection.service:uiGridSelectionService
  23832. * @description Returns all the selected rows
  23833. * @param {Grid} grid grid object
  23834. */
  23835. getSelectedRows: function (grid) {
  23836. return grid.rows.filter(function (row) {
  23837. return row.isSelected;
  23838. });
  23839. },
  23840. /**
  23841. * @ngdoc function
  23842. * @name clearSelectedRows
  23843. * @methodOf ui.grid.selection.service:uiGridSelectionService
  23844. * @description Clears all selected rows
  23845. * @param {Grid} grid grid object
  23846. * @param {Event} evt object if raised from an event
  23847. */
  23848. clearSelectedRows: function (grid, evt) {
  23849. var changedRows = [];
  23850. service.getSelectedRows(grid).forEach(function (row) {
  23851. if (row.isSelected) {
  23852. row.setSelected(false);
  23853. service.decideRaiseSelectionEvent(grid, row, changedRows, evt);
  23854. }
  23855. });
  23856. service.decideRaiseSelectionBatchEvent(grid, changedRows, evt);
  23857. grid.selection.selectAll = false;
  23858. grid.selection.selectedCount = 0;
  23859. },
  23860. /**
  23861. * @ngdoc function
  23862. * @name decideRaiseSelectionEvent
  23863. * @methodOf ui.grid.selection.service:uiGridSelectionService
  23864. * @description Decides whether to raise a single event or a batch event
  23865. * @param {Grid} grid grid object
  23866. * @param {GridRow} row row that has changed
  23867. * @param {array} changedRows an array to which we can append the changed
  23868. * @param {Event} evt object if raised from an event
  23869. * row if we're doing batch events
  23870. */
  23871. decideRaiseSelectionEvent: function (grid, row, changedRows, evt) {
  23872. if (!grid.options.enableSelectionBatchEvent) {
  23873. grid.api.selection.raise.rowSelectionChanged(row, evt);
  23874. } else {
  23875. changedRows.push(row);
  23876. }
  23877. },
  23878. /**
  23879. * @ngdoc function
  23880. * @name raiseSelectionEvent
  23881. * @methodOf ui.grid.selection.service:uiGridSelectionService
  23882. * @description Decides whether we need to raise a batch event, and
  23883. * raises it if we do.
  23884. * @param {Grid} grid grid object
  23885. * @param {array} changedRows an array of changed rows, only populated
  23886. * @param {Event} evt object if raised from an event
  23887. * if we're doing batch events
  23888. */
  23889. decideRaiseSelectionBatchEvent: function (grid, changedRows, evt) {
  23890. if (changedRows.length > 0) {
  23891. grid.api.selection.raise.rowSelectionChangedBatch(changedRows, evt);
  23892. }
  23893. }
  23894. };
  23895. return service;
  23896. }]);
  23897. /**
  23898. * @ngdoc directive
  23899. * @name ui.grid.selection.directive:uiGridSelection
  23900. * @element div
  23901. * @restrict A
  23902. *
  23903. * @description Adds selection features to grid
  23904. *
  23905. * @example
  23906. <example module="app">
  23907. <file name="app.js">
  23908. var app = angular.module('app', ['ui.grid', 'ui.grid.selection']);
  23909. app.controller('MainCtrl', ['$scope', function ($scope) {
  23910. $scope.data = [
  23911. { name: 'Bob', title: 'CEO' },
  23912. { name: 'Frank', title: 'Lowly Developer' }
  23913. ];
  23914. $scope.columnDefs = [
  23915. {name: 'name', enableCellEdit: true},
  23916. {name: 'title', enableCellEdit: true}
  23917. ];
  23918. }]);
  23919. </file>
  23920. <file name="index.html">
  23921. <div ng-controller="MainCtrl">
  23922. <div ui-grid="{ data: data, columnDefs: columnDefs }" ui-grid-selection></div>
  23923. </div>
  23924. </file>
  23925. </example>
  23926. */
  23927. module.directive('uiGridSelection', ['uiGridSelectionConstants', 'uiGridSelectionService', '$templateCache', 'uiGridConstants',
  23928. function (uiGridSelectionConstants, uiGridSelectionService, $templateCache, uiGridConstants) {
  23929. return {
  23930. replace: true,
  23931. priority: 0,
  23932. require: '^uiGrid',
  23933. scope: false,
  23934. compile: function () {
  23935. return {
  23936. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  23937. uiGridSelectionService.initializeGrid(uiGridCtrl.grid);
  23938. if (uiGridCtrl.grid.options.enableRowHeaderSelection) {
  23939. var selectionRowHeaderDef = {
  23940. name: uiGridSelectionConstants.selectionRowHeaderColName,
  23941. displayName: '',
  23942. width: uiGridCtrl.grid.options.selectionRowHeaderWidth,
  23943. minWidth: 10,
  23944. cellTemplate: 'ui-grid/selectionRowHeader',
  23945. headerCellTemplate: 'ui-grid/selectionHeaderCell',
  23946. enableColumnResizing: false,
  23947. enableColumnMenu: false,
  23948. exporterSuppressExport: true,
  23949. allowCellFocus: true
  23950. };
  23951. uiGridCtrl.grid.addRowHeaderColumn(selectionRowHeaderDef, 0);
  23952. }
  23953. var processorSet = false;
  23954. var processSelectableRows = function (rows) {
  23955. rows.forEach(function (row) {
  23956. row.enableSelection = uiGridCtrl.grid.options.isRowSelectable(row);
  23957. });
  23958. return rows;
  23959. };
  23960. var updateOptions = function () {
  23961. if (uiGridCtrl.grid.options.isRowSelectable !== angular.noop && processorSet !== true) {
  23962. uiGridCtrl.grid.registerRowsProcessor(processSelectableRows, 500);
  23963. processorSet = true;
  23964. }
  23965. };
  23966. updateOptions();
  23967. var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback(updateOptions, [uiGridConstants.dataChange.OPTIONS]);
  23968. $scope.$on('$destroy', dataChangeDereg);
  23969. },
  23970. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  23971. }
  23972. };
  23973. }
  23974. };
  23975. }]);
  23976. module.directive('uiGridSelectionRowHeaderButtons', ['$templateCache', 'uiGridSelectionService', 'gridUtil',
  23977. function ($templateCache, uiGridSelectionService, gridUtil) {
  23978. return {
  23979. replace: true,
  23980. restrict: 'E',
  23981. template: $templateCache.get('ui-grid/selectionRowHeaderButtons'),
  23982. scope: true,
  23983. require: '^uiGrid',
  23984. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  23985. var self = uiGridCtrl.grid;
  23986. $scope.selectButtonClick = selectButtonClick;
  23987. $scope.selectButtonKeyDown = selectButtonKeyDown;
  23988. // On IE, prevent mousedowns on the select button from starting a selection.
  23989. // If this is not done and you shift+click on another row, the browser will select a big chunk of text
  23990. if (gridUtil.detectBrowser() === 'ie') {
  23991. $elm.on('mousedown', selectButtonMouseDown);
  23992. }
  23993. function selectButtonKeyDown(row, evt) {
  23994. if (evt.keyCode === 32) {
  23995. evt.preventDefault();
  23996. selectButtonClick(row, evt);
  23997. }
  23998. }
  23999. function selectButtonClick(row, evt) {
  24000. evt.stopPropagation();
  24001. if (evt.shiftKey) {
  24002. uiGridSelectionService.shiftSelect(self, row, evt, self.options.multiSelect);
  24003. }
  24004. else if (evt.ctrlKey || evt.metaKey) {
  24005. uiGridSelectionService.toggleRowSelection(self, row, evt, self.options.multiSelect, self.options.noUnselect);
  24006. }
  24007. else if (row.groupHeader) {
  24008. for (var i = 0; i < row.treeNode.children.length; i++) {
  24009. uiGridSelectionService.toggleRowSelection(self, row.treeNode.children[i].row, evt, self.options.multiSelect, self.options.noUnselect);
  24010. }
  24011. }
  24012. else {
  24013. uiGridSelectionService.toggleRowSelection(self, row, evt, (self.options.multiSelect && !self.options.modifierKeysToMultiSelect), self.options.noUnselect);
  24014. }
  24015. }
  24016. function selectButtonMouseDown(evt) {
  24017. if (evt.ctrlKey || evt.shiftKey) {
  24018. evt.target.onselectstart = function () { return false; };
  24019. window.setTimeout(function () { evt.target.onselectstart = null; }, 0);
  24020. }
  24021. }
  24022. $scope.$on('$destroy', function unbindEvents() {
  24023. $elm.off();
  24024. });
  24025. }
  24026. };
  24027. }]);
  24028. module.directive('uiGridSelectionSelectAllButtons', ['$templateCache', 'uiGridSelectionService',
  24029. function ($templateCache, uiGridSelectionService) {
  24030. return {
  24031. replace: true,
  24032. restrict: 'E',
  24033. template: $templateCache.get('ui-grid/selectionSelectAllButtons'),
  24034. scope: false,
  24035. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  24036. var self = $scope.col.grid;
  24037. $scope.headerButtonKeyDown = function (evt) {
  24038. if (evt.keyCode === 32 || evt.keyCode === 13) {
  24039. evt.preventDefault();
  24040. $scope.headerButtonClick(evt);
  24041. }
  24042. };
  24043. $scope.headerButtonClick = function (evt) {
  24044. if (self.selection.selectAll) {
  24045. uiGridSelectionService.clearSelectedRows(self, evt);
  24046. if (self.options.noUnselect) {
  24047. self.api.selection.selectRowByVisibleIndex(0, evt);
  24048. }
  24049. self.selection.selectAll = false;
  24050. } else if (self.options.multiSelect) {
  24051. self.api.selection.selectAllVisibleRows(evt);
  24052. self.selection.selectAll = true;
  24053. }
  24054. };
  24055. }
  24056. };
  24057. }]);
  24058. /**
  24059. * @ngdoc directive
  24060. * @name ui.grid.selection.directive:uiGridViewport
  24061. * @element div
  24062. *
  24063. * @description Stacks on top of ui.grid.uiGridViewport to alter the attributes used
  24064. * for the grid row
  24065. */
  24066. module.directive('uiGridViewport',
  24067. ['$compile', 'uiGridConstants', 'uiGridSelectionConstants', 'gridUtil', '$parse', 'uiGridSelectionService',
  24068. function ($compile, uiGridConstants, uiGridSelectionConstants, gridUtil, $parse, uiGridSelectionService) {
  24069. return {
  24070. priority: -200, // run after default directive
  24071. scope: false,
  24072. compile: function ($elm, $attrs) {
  24073. var rowRepeatDiv = angular.element($elm[0].querySelector('.ui-grid-canvas:not(.ui-grid-empty-base-layer-container)').children[0]);
  24074. var existingNgClass = rowRepeatDiv.attr("ng-class");
  24075. var newNgClass = '';
  24076. if (existingNgClass) {
  24077. newNgClass = existingNgClass.slice(0, -1) + ",'ui-grid-row-selected': row.isSelected}";
  24078. } else {
  24079. newNgClass = "{'ui-grid-row-selected': row.isSelected}";
  24080. }
  24081. rowRepeatDiv.attr("ng-class", newNgClass);
  24082. return {
  24083. pre: function ($scope, $elm, $attrs, controllers) {
  24084. },
  24085. post: function ($scope, $elm, $attrs, controllers) {
  24086. }
  24087. };
  24088. }
  24089. };
  24090. }]);
  24091. /**
  24092. * @ngdoc directive
  24093. * @name ui.grid.selection.directive:uiGridCell
  24094. * @element div
  24095. * @restrict A
  24096. *
  24097. * @description Stacks on top of ui.grid.uiGridCell to provide selection feature
  24098. */
  24099. module.directive('uiGridCell',
  24100. ['$compile', 'uiGridConstants', 'uiGridSelectionConstants', 'gridUtil', '$parse', 'uiGridSelectionService', '$timeout',
  24101. function ($compile, uiGridConstants, uiGridSelectionConstants, gridUtil, $parse, uiGridSelectionService, $timeout) {
  24102. return {
  24103. priority: -200, // run after default uiGridCell directive
  24104. restrict: 'A',
  24105. require: '?^uiGrid',
  24106. scope: false,
  24107. link: function ($scope, $elm, $attrs, uiGridCtrl) {
  24108. var touchStartTime = 0;
  24109. var touchTimeout = 300;
  24110. // Bind to keydown events in the render container
  24111. if (uiGridCtrl.grid.api.cellNav) {
  24112. uiGridCtrl.grid.api.cellNav.on.viewPortKeyDown($scope, function (evt, rowCol) {
  24113. if (rowCol === null ||
  24114. rowCol.row !== $scope.row ||
  24115. rowCol.col !== $scope.col) {
  24116. return;
  24117. }
  24118. if (evt.keyCode === 32 && $scope.col.colDef.name === "selectionRowHeaderCol") {
  24119. evt.preventDefault();
  24120. uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, ($scope.grid.options.multiSelect && !$scope.grid.options.modifierKeysToMultiSelect), $scope.grid.options.noUnselect);
  24121. $scope.$apply();
  24122. }
  24123. // uiGridCellNavService.scrollToIfNecessary(uiGridCtrl.grid, rowCol.row, rowCol.col);
  24124. });
  24125. }
  24126. //$elm.bind('keydown', function (evt) {
  24127. // if (evt.keyCode === 32 && $scope.col.colDef.name === "selectionRowHeaderCol") {
  24128. // uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, ($scope.grid.options.multiSelect && !$scope.grid.options.modifierKeysToMultiSelect), $scope.grid.options.noUnselect);
  24129. // $scope.$apply();
  24130. // }
  24131. //});
  24132. var selectCells = function (evt) {
  24133. // if you click on expandable icon doesn't trigger selection
  24134. if (evt.target.className === "ui-grid-icon-minus-squared" || evt.target.className === "ui-grid-icon-plus-squared") {
  24135. return;
  24136. }
  24137. // if we get a click, then stop listening for touchend
  24138. $elm.off('touchend', touchEnd);
  24139. if (evt.shiftKey) {
  24140. uiGridSelectionService.shiftSelect($scope.grid, $scope.row, evt, $scope.grid.options.multiSelect);
  24141. }
  24142. else if (evt.ctrlKey || evt.metaKey) {
  24143. uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, $scope.grid.options.multiSelect, $scope.grid.options.noUnselect);
  24144. }
  24145. else {
  24146. uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, ($scope.grid.options.multiSelect && !$scope.grid.options.modifierKeysToMultiSelect), $scope.grid.options.noUnselect);
  24147. }
  24148. $scope.$apply();
  24149. // don't re-enable the touchend handler for a little while - some devices generate both, and it will
  24150. // take a little while to move your hand from the mouse to the screen if you have both modes of input
  24151. $timeout(function () {
  24152. $elm.on('touchend', touchEnd);
  24153. }, touchTimeout);
  24154. };
  24155. var touchStart = function (evt) {
  24156. touchStartTime = (new Date()).getTime();
  24157. // if we get a touch event, then stop listening for click
  24158. $elm.off('click', selectCells);
  24159. };
  24160. var touchEnd = function (evt) {
  24161. var touchEndTime = (new Date()).getTime();
  24162. var touchTime = touchEndTime - touchStartTime;
  24163. if (touchTime < touchTimeout) {
  24164. // short touch
  24165. selectCells(evt);
  24166. }
  24167. // don't re-enable the click handler for a little while - some devices generate both, and it will
  24168. // take a little while to move your hand from the screen to the mouse if you have both modes of input
  24169. $timeout(function () {
  24170. $elm.on('click', selectCells);
  24171. }, touchTimeout);
  24172. };
  24173. function registerRowSelectionEvents() {
  24174. if ($scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection && !$elm.hasClass('ui-grid-row-header-cell')) {
  24175. $elm.addClass('ui-grid-disable-selection');
  24176. $elm.on('touchstart', touchStart);
  24177. $elm.on('touchend', touchEnd);
  24178. $elm.on('click', selectCells);
  24179. $scope.registered = true;
  24180. }
  24181. }
  24182. function deregisterRowSelectionEvents() {
  24183. if ($scope.registered) {
  24184. $elm.removeClass('ui-grid-disable-selection');
  24185. $elm.off('touchstart', touchStart);
  24186. $elm.off('touchend', touchEnd);
  24187. $elm.off('click', selectCells);
  24188. $scope.registered = false;
  24189. }
  24190. }
  24191. registerRowSelectionEvents();
  24192. // register a dataChange callback so that we can change the selection configuration dynamically
  24193. // if the user changes the options
  24194. var dataChangeDereg = $scope.grid.registerDataChangeCallback(function () {
  24195. if ($scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection &&
  24196. !$scope.registered) {
  24197. registerRowSelectionEvents();
  24198. } else if ((!$scope.grid.options.enableRowSelection || !$scope.grid.options.enableFullRowSelection) &&
  24199. $scope.registered) {
  24200. deregisterRowSelectionEvents();
  24201. }
  24202. }, [uiGridConstants.dataChange.OPTIONS]);
  24203. $elm.on('$destroy', dataChangeDereg);
  24204. }
  24205. };
  24206. }]);
  24207. module.directive('uiGridGridFooter', ['$compile', 'uiGridConstants', 'gridUtil', function ($compile, uiGridConstants, gridUtil) {
  24208. return {
  24209. restrict: 'EA',
  24210. replace: true,
  24211. priority: -1000,
  24212. require: '^uiGrid',
  24213. scope: true,
  24214. compile: function ($elm, $attrs) {
  24215. return {
  24216. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  24217. if (!uiGridCtrl.grid.options.showGridFooter) {
  24218. return;
  24219. }
  24220. gridUtil.getTemplate('ui-grid/gridFooterSelectedItems')
  24221. .then(function (contents) {
  24222. var template = angular.element(contents);
  24223. var newElm = $compile(template)($scope);
  24224. angular.element($elm[0].getElementsByClassName('ui-grid-grid-footer')[0]).append(newElm);
  24225. });
  24226. },
  24227. post: function ($scope, $elm, $attrs, controllers) {
  24228. }
  24229. };
  24230. }
  24231. };
  24232. }]);
  24233. })();
  24234. (function () {
  24235. 'use strict';
  24236. /**
  24237. * @ngdoc overview
  24238. * @name ui.grid.treeBase
  24239. * @description
  24240. *
  24241. * # ui.grid.treeBase
  24242. *
  24243. * <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>
  24244. *
  24245. * This module provides base tree handling functions that are shared by other features, notably grouping
  24246. * and treeView. It provides a tree view of the data, with nodes in that
  24247. * tree and leaves.
  24248. *
  24249. * Design information:
  24250. * -------------------
  24251. *
  24252. * The raw data that is provided must come with a $$treeLevel on any non-leaf node. Grouping will create
  24253. * these on all the group header rows, treeView will expect these to be set in the raw data by the user.
  24254. * TreeBase will run a rowsProcessor that:
  24255. * - builds `treeBase.tree` out of the provided rows
  24256. * - permits a recursive sort of the tree
  24257. * - maintains the expand/collapse state of each node
  24258. * - provides the expand/collapse all button and the expand/collapse buttons
  24259. * - maintains the count of children for each node
  24260. *
  24261. * Each row is updated with a link to the tree node that represents it. Refer {@link ui.grid.treeBase.grid:treeBase.tree tree documentation}
  24262. * for information.
  24263. *
  24264. * TreeBase adds information to the rows
  24265. * - treeLevel: if present and > -1 tells us the level (level 0 is the top level)
  24266. * - treeNode: pointer to the node in the grid.treeBase.tree that refers
  24267. * to this row, allowing us to manipulate the state
  24268. *
  24269. * Since the logic is baked into the rowsProcessors, it should get triggered whenever
  24270. * row order or filtering or anything like that is changed. We recall the expanded state
  24271. * across invocations of the rowsProcessors by the reference to the treeNode on the individual
  24272. * rows. We rebuild the tree itself quite frequently, when we do this we use the saved treeNodes to
  24273. * get the state, but we overwrite the other data in that treeNode.
  24274. *
  24275. * By default rows are collapsed, which means all data rows have their visible property
  24276. * set to false, and only level 0 group rows are set to visible.
  24277. *
  24278. * We rely on the rowsProcessors to do the actual expanding and collapsing, so we set the flags we want into
  24279. * grid.treeBase.tree, then call refresh. This is because we can't easily change the visible
  24280. * row cache without calling the processors, and once we've built the logic into the rowProcessors we may as
  24281. * well use it all the time.
  24282. *
  24283. * Tree base provides sorting (on non-grouped columns).
  24284. *
  24285. * Sorting works in two passes. The standard sorting is performed for any columns that are important to building
  24286. * the tree (for example, any grouped columns). Then after the tree is built, a recursive tree sort is performed
  24287. * for the remaining sort columns (including the original sort) - these columns are sorted within each tree level
  24288. * (so all the level 1 nodes are sorted, then all the level 2 nodes within each level 1 node etc).
  24289. *
  24290. * To achieve this we make use of the `ignoreSort` property on the sort configuration. The parent feature (treeView or grouping)
  24291. * must provide a rowsProcessor that runs with very low priority (typically in the 60-65 range), and that sets
  24292. * the `ignoreSort`on any sort that it wants to run on the tree. TreeBase will clear the ignoreSort on all sorts - so it
  24293. * will turn on any sorts that haven't run. It will then call a recursive sort on the tree.
  24294. *
  24295. * Tree base provides treeAggregation. It checks the treeAggregation configuration on each column, and aggregates based on
  24296. * the logic provided as it builds the tree. Footer aggregation from the uiGrid core should not be used with treeBase aggregation,
  24297. * since it operates on all visible rows, as opposed to to leaf nodes only. Setting `showColumnFooter: true` will show the
  24298. * treeAggregations in the column footer. Aggregation information will be collected in the format:
  24299. *
  24300. * ```
  24301. * {
  24302. * type: 'count',
  24303. * value: 4,
  24304. * label: 'count: ',
  24305. * rendered: 'count: 4'
  24306. * }
  24307. * ```
  24308. *
  24309. * A callback is provided to format the value once it is finalised (aka a valueFilter).
  24310. *
  24311. * <br/>
  24312. * <br/>
  24313. *
  24314. * <div doc-module-components="ui.grid.treeBase"></div>
  24315. */
  24316. var module = angular.module('ui.grid.treeBase', ['ui.grid']);
  24317. /**
  24318. * @ngdoc object
  24319. * @name ui.grid.treeBase.constant:uiGridTreeBaseConstants
  24320. *
  24321. * @description constants available in treeBase module.
  24322. *
  24323. * These constants are manually copied into grouping and treeView,
  24324. * as I haven't found a way to simply include them, and it's not worth
  24325. * investing time in for something that changes very infrequently.
  24326. *
  24327. */
  24328. module.constant('uiGridTreeBaseConstants', {
  24329. featureName: "treeBase",
  24330. rowHeaderColName: 'treeBaseRowHeaderCol',
  24331. EXPANDED: 'expanded',
  24332. COLLAPSED: 'collapsed',
  24333. aggregation: {
  24334. COUNT: 'count',
  24335. SUM: 'sum',
  24336. MAX: 'max',
  24337. MIN: 'min',
  24338. AVG: 'avg'
  24339. }
  24340. });
  24341. /**
  24342. * @ngdoc service
  24343. * @name ui.grid.treeBase.service:uiGridTreeBaseService
  24344. *
  24345. * @description Services for treeBase feature
  24346. */
  24347. /**
  24348. * @ngdoc object
  24349. * @name ui.grid.treeBase.api:ColumnDef
  24350. *
  24351. * @description ColumnDef for tree feature, these are available to be
  24352. * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs}
  24353. */
  24354. module.service('uiGridTreeBaseService', ['$q', 'uiGridTreeBaseConstants', 'gridUtil', 'GridRow', 'gridClassFactory', 'i18nService', 'uiGridConstants', 'rowSorter',
  24355. function ($q, uiGridTreeBaseConstants, gridUtil, GridRow, gridClassFactory, i18nService, uiGridConstants, rowSorter) {
  24356. var service = {
  24357. initializeGrid: function (grid, $scope) {
  24358. //add feature namespace and any properties to grid for needed
  24359. /**
  24360. * @ngdoc object
  24361. * @name ui.grid.treeBase.grid:treeBase
  24362. *
  24363. * @description Grid properties and functions added for treeBase
  24364. */
  24365. grid.treeBase = {};
  24366. /**
  24367. * @ngdoc property
  24368. * @propertyOf ui.grid.treeBase.grid:treeBase
  24369. * @name numberLevels
  24370. *
  24371. * @description Total number of tree levels currently used, calculated by the rowsProcessor by
  24372. * retaining the highest tree level it sees
  24373. */
  24374. grid.treeBase.numberLevels = 0;
  24375. /**
  24376. * @ngdoc property
  24377. * @propertyOf ui.grid.treeBase.grid:treeBase
  24378. * @name expandAll
  24379. *
  24380. * @description Whether or not the expandAll box is selected
  24381. */
  24382. grid.treeBase.expandAll = false;
  24383. /**
  24384. * @ngdoc property
  24385. * @propertyOf ui.grid.treeBase.grid:treeBase
  24386. * @name tree
  24387. *
  24388. * @description Tree represented as a nested array that holds the state of each node, along with a
  24389. * pointer to the row. The array order is material - we will display the children in the order
  24390. * they are stored in the array
  24391. *
  24392. * Each node stores:
  24393. *
  24394. * - the state of this node
  24395. * - an array of children of this node
  24396. * - a pointer to the parent of this node (reverse pointer, allowing us to walk up the tree)
  24397. * - the number of children of this node
  24398. * - aggregation information calculated from the nodes
  24399. *
  24400. * ```
  24401. * [{
  24402. * state: 'expanded',
  24403. * row: <reference to row>,
  24404. * parentRow: null,
  24405. * aggregations: [{
  24406. * type: 'count',
  24407. * col: <gridCol>,
  24408. * value: 2,
  24409. * label: 'count: ',
  24410. * rendered: 'count: 2'
  24411. * }],
  24412. * children: [
  24413. * {
  24414. * state: 'expanded',
  24415. * row: <reference to row>,
  24416. * parentRow: <reference to row>,
  24417. * aggregations: [{
  24418. * type: 'count',
  24419. * col: '<gridCol>,
  24420. * value: 4,
  24421. * label: 'count: ',
  24422. * rendered: 'count: 4'
  24423. * }],
  24424. * children: [
  24425. * { state: 'expanded', row: <reference to row>, parentRow: <reference to row> },
  24426. * { state: 'collapsed', row: <reference to row>, parentRow: <reference to row> },
  24427. * { state: 'expanded', row: <reference to row>, parentRow: <reference to row> },
  24428. * { state: 'collapsed', row: <reference to row>, parentRow: <reference to row> }
  24429. * ]
  24430. * },
  24431. * {
  24432. * state: 'collapsed',
  24433. * row: <reference to row>,
  24434. * parentRow: <reference to row>,
  24435. * aggregations: [{
  24436. * type: 'count',
  24437. * col: <gridCol>,
  24438. * value: 3,
  24439. * label: 'count: ',
  24440. * rendered: 'count: 3'
  24441. * }],
  24442. * children: [
  24443. * { state: 'expanded', row: <reference to row>, parentRow: <reference to row> },
  24444. * { state: 'collapsed', row: <reference to row>, parentRow: <reference to row> },
  24445. * { state: 'expanded', row: <reference to row>, parentRow: <reference to row> }
  24446. * ]
  24447. * }
  24448. * ]
  24449. * }, {<another level 0 node maybe>} ]
  24450. * ```
  24451. * Missing state values are false - meaning they aren't expanded.
  24452. *
  24453. * This is used because the rowProcessors run every time the grid is refreshed, so
  24454. * we'd lose the expanded state every time the grid was refreshed. This instead gives
  24455. * us a reliable lookup that persists across rowProcessors.
  24456. *
  24457. * This tree is rebuilt every time we run the rowsProcessors. Since each row holds a pointer
  24458. * to it's tree node we can persist expand/collapse state across calls to rowsProcessor, we discard
  24459. * all transient information on the tree (children, childCount) and recalculate it
  24460. *
  24461. */
  24462. grid.treeBase.tree = [];
  24463. service.defaultGridOptions(grid.options);
  24464. grid.registerRowsProcessor(service.treeRows, 410);
  24465. grid.registerColumnBuilder( service.treeBaseColumnBuilder );
  24466. service.createRowHeader( grid );
  24467. /**
  24468. * @ngdoc object
  24469. * @name ui.grid.treeBase.api:PublicApi
  24470. *
  24471. * @description Public Api for treeBase feature
  24472. */
  24473. var publicApi = {
  24474. events: {
  24475. treeBase: {
  24476. /**
  24477. * @ngdoc event
  24478. * @eventOf ui.grid.treeBase.api:PublicApi
  24479. * @name rowExpanded
  24480. * @description raised whenever a row is expanded. If you are dynamically
  24481. * rendering your tree you can listen to this event, and then retrieve
  24482. * the children of this row and load them into the grid data.
  24483. *
  24484. * When the data is loaded the grid will automatically refresh to show these new rows
  24485. *
  24486. * <pre>
  24487. * gridApi.treeBase.on.rowExpanded(scope,function(row){})
  24488. * </pre>
  24489. * @param {gridRow} row the row that was expanded. You can also
  24490. * retrieve the grid from this row with row.grid
  24491. */
  24492. rowExpanded: {},
  24493. /**
  24494. * @ngdoc event
  24495. * @eventOf ui.grid.treeBase.api:PublicApi
  24496. * @name rowCollapsed
  24497. * @description raised whenever a row is collapsed. Doesn't really have
  24498. * a purpose at the moment, included for symmetry
  24499. *
  24500. * <pre>
  24501. * gridApi.treeBase.on.rowCollapsed(scope,function(row){})
  24502. * </pre>
  24503. * @param {gridRow} row the row that was collapsed. You can also
  24504. * retrieve the grid from this row with row.grid
  24505. */
  24506. rowCollapsed: {}
  24507. }
  24508. },
  24509. methods: {
  24510. treeBase: {
  24511. /**
  24512. * @ngdoc function
  24513. * @name expandAllRows
  24514. * @methodOf ui.grid.treeBase.api:PublicApi
  24515. * @description Expands all tree rows
  24516. */
  24517. expandAllRows: function () {
  24518. service.expandAllRows(grid);
  24519. },
  24520. /**
  24521. * @ngdoc function
  24522. * @name collapseAllRows
  24523. * @methodOf ui.grid.treeBase.api:PublicApi
  24524. * @description collapse all tree rows
  24525. */
  24526. collapseAllRows: function () {
  24527. service.collapseAllRows(grid);
  24528. },
  24529. /**
  24530. * @ngdoc function
  24531. * @name toggleRowTreeState
  24532. * @methodOf ui.grid.treeBase.api:PublicApi
  24533. * @description call expand if the row is collapsed, collapse if it is expanded
  24534. * @param {gridRow} row the row you wish to toggle
  24535. */
  24536. toggleRowTreeState: function (row) {
  24537. service.toggleRowTreeState(grid, row);
  24538. },
  24539. /**
  24540. * @ngdoc function
  24541. * @name expandRow
  24542. * @methodOf ui.grid.treeBase.api:PublicApi
  24543. * @description expand the immediate children of the specified row
  24544. * @param {gridRow} row the row you wish to expand
  24545. * @param {boolean} recursive true if you wish to expand the row's ancients
  24546. */
  24547. expandRow: function (row, recursive) {
  24548. service.expandRow(grid, row, recursive);
  24549. },
  24550. /**
  24551. * @ngdoc function
  24552. * @name expandRowChildren
  24553. * @methodOf ui.grid.treeBase.api:PublicApi
  24554. * @description expand all children of the specified row
  24555. * @param {gridRow} row the row you wish to expand
  24556. */
  24557. expandRowChildren: function (row) {
  24558. service.expandRowChildren(grid, row);
  24559. },
  24560. /**
  24561. * @ngdoc function
  24562. * @name collapseRow
  24563. * @methodOf ui.grid.treeBase.api:PublicApi
  24564. * @description collapse the specified row. When
  24565. * you expand the row again, all grandchildren will retain their state
  24566. * @param {gridRow} row the row you wish to collapse
  24567. */
  24568. collapseRow: function ( row ) {
  24569. service.collapseRow(grid, row);
  24570. },
  24571. /**
  24572. * @ngdoc function
  24573. * @name collapseRowChildren
  24574. * @methodOf ui.grid.treeBase.api:PublicApi
  24575. * @description collapse all children of the specified row. When
  24576. * you expand the row again, all grandchildren will be collapsed
  24577. * @param {gridRow} row the row you wish to collapse children for
  24578. */
  24579. collapseRowChildren: function ( row ) {
  24580. service.collapseRowChildren(grid, row);
  24581. },
  24582. /**
  24583. * @ngdoc function
  24584. * @name getTreeState
  24585. * @methodOf ui.grid.treeBase.api:PublicApi
  24586. * @description Get the tree state for this grid,
  24587. * used by the saveState feature
  24588. * Returned treeState as an object
  24589. * `{ expandedState: { uid: 'expanded', uid: 'collapsed' } }`
  24590. * where expandedState is a hash of row uid and the current expanded state
  24591. *
  24592. * @returns {object} tree state
  24593. *
  24594. * TODO - this needs work - we need an identifier that persists across instantiations,
  24595. * not uid. This really means we need a row identity defined, but that won't work for
  24596. * grouping. Perhaps this needs to be moved up to treeView and grouping, rather than
  24597. * being in base.
  24598. */
  24599. getTreeExpandedState: function () {
  24600. return { expandedState: service.getTreeState(grid) };
  24601. },
  24602. /**
  24603. * @ngdoc function
  24604. * @name setTreeState
  24605. * @methodOf ui.grid.treeBase.api:PublicApi
  24606. * @description Set the expanded states of the tree
  24607. * @param {object} config the config you want to apply, in the format
  24608. * provided by getTreeState
  24609. */
  24610. setTreeState: function ( config ) {
  24611. service.setTreeState( grid, config );
  24612. },
  24613. /**
  24614. * @ngdoc function
  24615. * @name getRowChildren
  24616. * @methodOf ui.grid.treeBase.api:PublicApi
  24617. * @description Get the children of the specified row
  24618. * @param {GridRow} row the row you want the children of
  24619. * @returns {Array} array of children of this row, the children
  24620. * are all gridRows
  24621. */
  24622. getRowChildren: function ( row ){
  24623. return row.treeNode.children.map( function( childNode ){
  24624. return childNode.row;
  24625. });
  24626. }
  24627. }
  24628. }
  24629. };
  24630. grid.api.registerEventsFromObject(publicApi.events);
  24631. grid.api.registerMethodsFromObject(publicApi.methods);
  24632. },
  24633. defaultGridOptions: function (gridOptions) {
  24634. //default option to true unless it was explicitly set to false
  24635. /**
  24636. * @ngdoc object
  24637. * @name ui.grid.treeBase.api:GridOptions
  24638. *
  24639. * @description GridOptions for treeBase feature, these are available to be
  24640. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  24641. */
  24642. /**
  24643. * @ngdoc object
  24644. * @name treeRowHeaderBaseWidth
  24645. * @propertyOf ui.grid.treeBase.api:GridOptions
  24646. * @description Base width of the tree header, provides for a single level of tree. This
  24647. * is incremented by `treeIndent` for each extra level
  24648. * <br/>Defaults to 30
  24649. */
  24650. gridOptions.treeRowHeaderBaseWidth = gridOptions.treeRowHeaderBaseWidth || 30;
  24651. /**
  24652. * @ngdoc object
  24653. * @name treeIndent
  24654. * @propertyOf ui.grid.treeBase.api:GridOptions
  24655. * @description Number of pixels of indent for the icon at each tree level, wider indents are visually more pleasing,
  24656. * but will make the tree row header wider
  24657. * <br/>Defaults to 10
  24658. */
  24659. gridOptions.treeIndent = gridOptions.treeIndent || 10;
  24660. /**
  24661. * @ngdoc object
  24662. * @name showTreeRowHeader
  24663. * @propertyOf ui.grid.treeBase.api:GridOptions
  24664. * @description If set to false, don't create the row header. You'll need to programmatically control the expand
  24665. * states
  24666. * <br/>Defaults to true
  24667. */
  24668. gridOptions.showTreeRowHeader = gridOptions.showTreeRowHeader !== false;
  24669. /**
  24670. * @ngdoc object
  24671. * @name showTreeExpandNoChildren
  24672. * @propertyOf ui.grid.treeBase.api:GridOptions
  24673. * @description If set to true, show the expand/collapse button even if there are no
  24674. * children of a node. You'd use this if you're planning to dynamically load the children
  24675. *
  24676. * <br/>Defaults to true, grouping overrides to false
  24677. */
  24678. gridOptions.showTreeExpandNoChildren = gridOptions.showTreeExpandNoChildren !== false;
  24679. /**
  24680. * @ngdoc object
  24681. * @name treeRowHeaderAlwaysVisible
  24682. * @propertyOf ui.grid.treeBase.api:GridOptions
  24683. * @description If set to true, row header even if there are no tree nodes
  24684. *
  24685. * <br/>Defaults to true
  24686. */
  24687. gridOptions.treeRowHeaderAlwaysVisible = gridOptions.treeRowHeaderAlwaysVisible !== false;
  24688. /**
  24689. * @ngdoc object
  24690. * @name treeCustomAggregations
  24691. * @propertyOf ui.grid.treeBase.api:GridOptions
  24692. * @description Define custom aggregation functions. The properties of this object will be
  24693. * aggregation types available for use on columnDef with {@link ui.grid.treeBase.api:ColumnDef treeAggregationType} or through the column menu.
  24694. * If a function defined here uses the same name as one of the native aggregations, this one will take precedence.
  24695. * The object format is:
  24696. *
  24697. * <pre>
  24698. * {
  24699. * aggregationName: {
  24700. * label: (optional) string,
  24701. * aggregationFn: function( aggregation, fieldValue, numValue, row ){...},
  24702. * finalizerFn: (optional) function( aggregation ){...}
  24703. * },
  24704. * mean: {
  24705. * label: 'mean',
  24706. * aggregationFn: function( aggregation, fieldValue, numValue ){
  24707. * aggregation.count = (aggregation.count || 1) + 1;
  24708. * aggregation.sum = (aggregation.sum || 0) + numValue;
  24709. * },
  24710. * finalizerFn: function( aggregation ){
  24711. * aggregation.value = aggregation.sum / aggregation.count
  24712. * }
  24713. * }
  24714. * }
  24715. * </pre>
  24716. *
  24717. * <br/>The `finalizerFn` may be used to manipulate the value before rendering, or to
  24718. * apply a custom rendered value. If `aggregation.rendered` is left undefined, the value will be
  24719. * rendered. Note that the native aggregation functions use an `finalizerFn` to concatenate
  24720. * the label and the value.
  24721. *
  24722. * <br/>Defaults to {}
  24723. */
  24724. gridOptions.treeCustomAggregations = gridOptions.treeCustomAggregations || {};
  24725. /**
  24726. * @ngdoc object
  24727. * @name enableExpandAll
  24728. * @propertyOf ui.grid.treeBase.api:GridOptions
  24729. * @description Enable the expand all button at the top of the row header
  24730. *
  24731. * <br/>Defaults to true
  24732. */
  24733. gridOptions.enableExpandAll = gridOptions.enableExpandAll !== false;
  24734. },
  24735. /**
  24736. * @ngdoc function
  24737. * @name treeBaseColumnBuilder
  24738. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  24739. * @description Sets the tree defaults based on the columnDefs
  24740. *
  24741. * @param {object} colDef columnDef we're basing on
  24742. * @param {GridColumn} col the column we're to update
  24743. * @param {object} gridOptions the options we should use
  24744. * @returns {promise} promise for the builder - actually we do it all inline so it's immediately resolved
  24745. */
  24746. treeBaseColumnBuilder: function (colDef, col, gridOptions) {
  24747. /**
  24748. * @ngdoc object
  24749. * @name customTreeAggregationFn
  24750. * @propertyOf ui.grid.treeBase.api:ColumnDef
  24751. * @description A custom function that aggregates rows into some form of
  24752. * total. Aggregations run row-by-row, the function needs to be capable of
  24753. * creating a running total.
  24754. *
  24755. * The function will be provided the aggregation item (in which you can store running
  24756. * totals), the row value that is to be aggregated, and that same row value converted to
  24757. * a number (most aggregations work on numbers)
  24758. * @example
  24759. * <pre>
  24760. * customTreeAggregationFn = function ( aggregation, fieldValue, numValue, row ){
  24761. * // calculates the average of the squares of the values
  24762. * if ( typeof(aggregation.count) === 'undefined' ){
  24763. * aggregation.count = 0;
  24764. * }
  24765. * aggregation.count++;
  24766. *
  24767. * if ( !isNaN(numValue) ){
  24768. * if ( typeof(aggregation.total) === 'undefined' ){
  24769. * aggregation.total = 0;
  24770. * }
  24771. * aggregation.total = aggregation.total + numValue * numValue;
  24772. * }
  24773. *
  24774. * aggregation.value = aggregation.total / aggregation.count;
  24775. * }
  24776. * </pre>
  24777. * <br/>Defaults to undefined. May be overwritten by treeAggregationType, the two options should not be used together.
  24778. */
  24779. if ( typeof(colDef.customTreeAggregationFn) !== 'undefined' ){
  24780. col.treeAggregationFn = colDef.customTreeAggregationFn;
  24781. }
  24782. /**
  24783. * @ngdoc object
  24784. * @name treeAggregationType
  24785. * @propertyOf ui.grid.treeBase.api:ColumnDef
  24786. * @description Use one of the native or grid-level aggregation methods for calculating aggregations on this column.
  24787. * Native method are in the constants file and include: SUM, COUNT, MIN, MAX, AVG. This may also be the property the
  24788. * name of an aggregation function defined with {@link ui.grid.treeBase.api:GridOptions treeCustomAggregations}.
  24789. *
  24790. * <pre>
  24791. * treeAggregationType = uiGridTreeBaseConstants.aggregation.SUM,
  24792. * }
  24793. * </pre>
  24794. *
  24795. * If you are using aggregations you should either:
  24796. *
  24797. * - also use grouping, in which case the aggregations are displayed in the group header, OR
  24798. * - use treeView, in which case you can set `treeAggregationUpdateEntity: true` in the colDef, and
  24799. * treeBase will store the aggregation information in the entity, or you can set `treeAggregationUpdateEntity: false`
  24800. * in the colDef, and you need to manual retrieve the calculated aggregations from the row.treeNode.aggregations
  24801. *
  24802. * <br/>Takes precendence over a treeAggregationFn, the two options should not be used together.
  24803. * <br/>Defaults to undefined.
  24804. */
  24805. if ( typeof(colDef.treeAggregationType) !== 'undefined' ){
  24806. col.treeAggregation = { type: colDef.treeAggregationType };
  24807. if ( typeof(gridOptions.treeCustomAggregations[colDef.treeAggregationType]) !== 'undefined' ){
  24808. col.treeAggregationFn = gridOptions.treeCustomAggregations[colDef.treeAggregationType].aggregationFn;
  24809. col.treeAggregationFinalizerFn = gridOptions.treeCustomAggregations[colDef.treeAggregationType].finalizerFn;
  24810. col.treeAggregation.label = gridOptions.treeCustomAggregations[colDef.treeAggregationType].label;
  24811. } else if ( typeof(service.nativeAggregations()[colDef.treeAggregationType]) !== 'undefined' ){
  24812. col.treeAggregationFn = service.nativeAggregations()[colDef.treeAggregationType].aggregationFn;
  24813. col.treeAggregation.label = service.nativeAggregations()[colDef.treeAggregationType].label;
  24814. }
  24815. }
  24816. /**
  24817. * @ngdoc object
  24818. * @name treeAggregationLabel
  24819. * @propertyOf ui.grid.treeBase.api:ColumnDef
  24820. * @description A custom label to use for this aggregation. If provided we don't use native i18n.
  24821. */
  24822. if ( typeof(colDef.treeAggregationLabel) !== 'undefined' ){
  24823. if (typeof(col.treeAggregation) === 'undefined' ){
  24824. col.treeAggregation = {};
  24825. }
  24826. col.treeAggregation.label = colDef.treeAggregationLabel;
  24827. }
  24828. /**
  24829. * @ngdoc object
  24830. * @name treeAggregationUpdateEntity
  24831. * @propertyOf ui.grid.treeBase.api:ColumnDef
  24832. * @description Store calculated aggregations into the entity, allowing them
  24833. * to be displayed in the grid using a standard cellTemplate. This defaults to true,
  24834. * if you are using grouping then you shouldn't set it to false, as then the aggregations won't
  24835. * display.
  24836. *
  24837. * If you are using treeView in most cases you'll want to set this to true. This will result in
  24838. * getCellValue returning the aggregation rather than whatever was stored in the cell attribute on
  24839. * the entity. If you want to render the underlying entity value (and do something else with the aggregation)
  24840. * then you could use a custom cellTemplate to display `row.entity.myAttribute`, rather than using getCellValue.
  24841. *
  24842. * <br/>Defaults to true
  24843. *
  24844. * @example
  24845. * <pre>
  24846. * gridOptions.columns = [{
  24847. * name: 'myCol',
  24848. * treeAggregation: { type: uiGridTreeBaseConstants.aggregation.SUM },
  24849. * treeAggregationUpdateEntity: true
  24850. * cellTemplate: '<div>{{row.entity.myCol + " " + row.treeNode.aggregations[0].rendered}}</div>'
  24851. * }];
  24852. * </pre>
  24853. */
  24854. col.treeAggregationUpdateEntity = colDef.treeAggregationUpdateEntity !== false;
  24855. /**
  24856. * @ngdoc object
  24857. * @name customTreeAggregationFinalizerFn
  24858. * @propertyOf ui.grid.treeBase.api:ColumnDef
  24859. * @description A custom function that populates aggregation.rendered, this is called when
  24860. * a particular aggregation has been fully calculated, and we want to render the value.
  24861. *
  24862. * With the native aggregation options we just concatenate `aggregation.label` and
  24863. * `aggregation.value`, but if you wanted to apply a filter or otherwise manipulate the label
  24864. * or the value, you can do so with this function. This function will be called after the
  24865. * the default `finalizerFn`.
  24866. *
  24867. * @example
  24868. * <pre>
  24869. * customTreeAggregationFinalizerFn = function ( aggregation ){
  24870. * aggregation.rendered = aggregation.label + aggregation.value / 100 + '%';
  24871. * }
  24872. * </pre>
  24873. * <br/>Defaults to undefined.
  24874. */
  24875. if ( typeof(col.customTreeAggregationFinalizerFn) === 'undefined' ){
  24876. col.customTreeAggregationFinalizerFn = colDef.customTreeAggregationFinalizerFn;
  24877. }
  24878. },
  24879. /**
  24880. * @ngdoc function
  24881. * @name createRowHeader
  24882. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  24883. * @description Create the rowHeader. If treeRowHeaderAlwaysVisible then
  24884. * set it to visible, otherwise set it to invisible
  24885. *
  24886. * @param {Grid} grid grid object
  24887. */
  24888. createRowHeader: function( grid ){
  24889. var rowHeaderColumnDef = {
  24890. name: uiGridTreeBaseConstants.rowHeaderColName,
  24891. displayName: '',
  24892. width: grid.options.treeRowHeaderBaseWidth,
  24893. minWidth: 10,
  24894. cellTemplate: 'ui-grid/treeBaseRowHeader',
  24895. headerCellTemplate: 'ui-grid/treeBaseHeaderCell',
  24896. enableColumnResizing: false,
  24897. enableColumnMenu: false,
  24898. exporterSuppressExport: true,
  24899. allowCellFocus: true
  24900. };
  24901. rowHeaderColumnDef.visible = grid.options.treeRowHeaderAlwaysVisible;
  24902. grid.addRowHeaderColumn(rowHeaderColumnDef, -100);
  24903. },
  24904. /**
  24905. * @ngdoc function
  24906. * @name expandAllRows
  24907. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  24908. * @description Expands all nodes in the tree
  24909. *
  24910. * @param {Grid} grid grid object
  24911. */
  24912. expandAllRows: function (grid) {
  24913. grid.treeBase.tree.forEach( function( node ) {
  24914. service.setAllNodes( grid, node, uiGridTreeBaseConstants.EXPANDED);
  24915. });
  24916. grid.treeBase.expandAll = true;
  24917. grid.queueGridRefresh();
  24918. },
  24919. /**
  24920. * @ngdoc function
  24921. * @name collapseAllRows
  24922. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  24923. * @description Collapses all nodes in the tree
  24924. *
  24925. * @param {Grid} grid grid object
  24926. */
  24927. collapseAllRows: function (grid) {
  24928. grid.treeBase.tree.forEach( function( node ) {
  24929. service.setAllNodes( grid, node, uiGridTreeBaseConstants.COLLAPSED);
  24930. });
  24931. grid.treeBase.expandAll = false;
  24932. grid.queueGridRefresh();
  24933. },
  24934. /**
  24935. * @ngdoc function
  24936. * @name setAllNodes
  24937. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  24938. * @description Works through a subset of grid.treeBase.rowExpandedStates, setting
  24939. * all child nodes (and their descendents) of the provided node to the given state.
  24940. *
  24941. * Calls itself recursively on all nodes so as to achieve this.
  24942. *
  24943. * @param {Grid} grid the grid we're operating on (so we can raise events)
  24944. * @param {object} treeNode a node in the tree that we want to update
  24945. * @param {string} targetState the state we want to set it to
  24946. */
  24947. setAllNodes: function (grid, treeNode, targetState) {
  24948. if ( typeof(treeNode.state) !== 'undefined' && treeNode.state !== targetState ){
  24949. treeNode.state = targetState;
  24950. if ( targetState === uiGridTreeBaseConstants.EXPANDED ){
  24951. grid.api.treeBase.raise.rowExpanded(treeNode.row);
  24952. } else {
  24953. grid.api.treeBase.raise.rowCollapsed(treeNode.row);
  24954. }
  24955. }
  24956. // set all child nodes
  24957. if ( treeNode.children ){
  24958. treeNode.children.forEach(function( childNode ){
  24959. service.setAllNodes(grid, childNode, targetState);
  24960. });
  24961. }
  24962. },
  24963. /**
  24964. * @ngdoc function
  24965. * @name toggleRowTreeState
  24966. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  24967. * @description Toggles the expand or collapse state of this grouped row, if
  24968. * it's a parent row
  24969. *
  24970. * @param {Grid} grid grid object
  24971. * @param {GridRow} row the row we want to toggle
  24972. */
  24973. toggleRowTreeState: function ( grid, row ){
  24974. if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){
  24975. return;
  24976. }
  24977. if (row.treeNode.state === uiGridTreeBaseConstants.EXPANDED){
  24978. service.collapseRow(grid, row);
  24979. } else {
  24980. service.expandRow(grid, row, false);
  24981. }
  24982. grid.queueGridRefresh();
  24983. },
  24984. /**
  24985. * @ngdoc function
  24986. * @name expandRow
  24987. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  24988. * @description Expands this specific row, showing only immediate children.
  24989. *
  24990. * @param {Grid} grid grid object
  24991. * @param {GridRow} row the row we want to expand
  24992. * @param {boolean} recursive true if you wish to expand the row's ancients
  24993. */
  24994. expandRow: function ( grid, row, recursive ){
  24995. if ( recursive ){
  24996. var parents = [];
  24997. while ( row && typeof(row.treeLevel) !== 'undefined' && row.treeLevel !== null && row.treeLevel >= 0 && row.treeNode.state !== uiGridTreeBaseConstants.EXPANDED ){
  24998. parents.push(row);
  24999. row = row.treeNode.parentRow;
  25000. }
  25001. if ( parents.length > 0 ){
  25002. row = parents.pop();
  25003. while ( row ){
  25004. row.treeNode.state = uiGridTreeBaseConstants.EXPANDED;
  25005. grid.api.treeBase.raise.rowExpanded(row);
  25006. row = parents.pop();
  25007. }
  25008. grid.treeBase.expandAll = service.allExpanded(grid.treeBase.tree);
  25009. grid.queueGridRefresh();
  25010. }
  25011. } else {
  25012. if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){
  25013. return;
  25014. }
  25015. if ( row.treeNode.state !== uiGridTreeBaseConstants.EXPANDED ){
  25016. row.treeNode.state = uiGridTreeBaseConstants.EXPANDED;
  25017. grid.api.treeBase.raise.rowExpanded(row);
  25018. grid.treeBase.expandAll = service.allExpanded(grid.treeBase.tree);
  25019. grid.queueGridRefresh();
  25020. }
  25021. }
  25022. },
  25023. /**
  25024. * @ngdoc function
  25025. * @name expandRowChildren
  25026. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25027. * @description Expands this specific row, showing all children.
  25028. *
  25029. * @param {Grid} grid grid object
  25030. * @param {GridRow} row the row we want to expand
  25031. */
  25032. expandRowChildren: function ( grid, row ){
  25033. if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){
  25034. return;
  25035. }
  25036. service.setAllNodes(grid, row.treeNode, uiGridTreeBaseConstants.EXPANDED);
  25037. grid.treeBase.expandAll = service.allExpanded(grid.treeBase.tree);
  25038. grid.queueGridRefresh();
  25039. },
  25040. /**
  25041. * @ngdoc function
  25042. * @name collapseRow
  25043. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25044. * @description Collapses this specific row
  25045. *
  25046. * @param {Grid} grid grid object
  25047. * @param {GridRow} row the row we want to collapse
  25048. */
  25049. collapseRow: function( grid, row ){
  25050. if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){
  25051. return;
  25052. }
  25053. if ( row.treeNode.state !== uiGridTreeBaseConstants.COLLAPSED ){
  25054. row.treeNode.state = uiGridTreeBaseConstants.COLLAPSED;
  25055. grid.treeBase.expandAll = false;
  25056. grid.api.treeBase.raise.rowCollapsed(row);
  25057. grid.queueGridRefresh();
  25058. }
  25059. },
  25060. /**
  25061. * @ngdoc function
  25062. * @name collapseRowChildren
  25063. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25064. * @description Collapses this specific row and all children
  25065. *
  25066. * @param {Grid} grid grid object
  25067. * @param {GridRow} row the row we want to collapse
  25068. */
  25069. collapseRowChildren: function( grid, row ){
  25070. if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){
  25071. return;
  25072. }
  25073. service.setAllNodes(grid, row.treeNode, uiGridTreeBaseConstants.COLLAPSED);
  25074. grid.treeBase.expandAll = false;
  25075. grid.queueGridRefresh();
  25076. },
  25077. /**
  25078. * @ngdoc function
  25079. * @name allExpanded
  25080. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25081. * @description Returns true if all rows are expanded, false
  25082. * if they're not. Walks the tree to determine this. Used
  25083. * to set the expandAll state.
  25084. *
  25085. * If the node has no children, then return true (it's immaterial
  25086. * whether it is expanded). If the node has children, then return
  25087. * false if this node is collapsed, or if any child node is not all expanded
  25088. *
  25089. * @param {object} tree the grid to check
  25090. * @returns {boolean} whether or not the tree is all expanded
  25091. */
  25092. allExpanded: function( tree ){
  25093. var allExpanded = true;
  25094. tree.forEach( function( node ){
  25095. if ( !service.allExpandedInternal( node ) ){
  25096. allExpanded = false;
  25097. }
  25098. });
  25099. return allExpanded;
  25100. },
  25101. allExpandedInternal: function( treeNode ){
  25102. if ( treeNode.children && treeNode.children.length > 0 ){
  25103. if ( treeNode.state === uiGridTreeBaseConstants.COLLAPSED ){
  25104. return false;
  25105. }
  25106. var allExpanded = true;
  25107. treeNode.children.forEach( function( node ){
  25108. if ( !service.allExpandedInternal( node ) ){
  25109. allExpanded = false;
  25110. }
  25111. });
  25112. return allExpanded;
  25113. } else {
  25114. return true;
  25115. }
  25116. },
  25117. /**
  25118. * @ngdoc function
  25119. * @name treeRows
  25120. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25121. * @description The rowProcessor that adds the nodes to the tree, and sets the visible
  25122. * state of each row based on it's parent state
  25123. *
  25124. * Assumes it is always called after the sorting processor, and the grouping processor if there is one.
  25125. * Performs any tree sorts itself after having built the tree
  25126. *
  25127. * Processes all the rows in order, setting the group level based on the $$treeLevel in the associated
  25128. * entity, and setting the visible state based on the parent's state.
  25129. *
  25130. * Calculates the deepest level of tree whilst it goes, and updates that so that the header column can be correctly
  25131. * sized.
  25132. *
  25133. * Aggregates if necessary along the way.
  25134. *
  25135. * @param {array} renderableRows the rows we want to process, usually the output from the previous rowProcessor
  25136. * @returns {array} the updated rows
  25137. */
  25138. treeRows: function( renderableRows ) {
  25139. if (renderableRows.length === 0){
  25140. return renderableRows;
  25141. }
  25142. var grid = this;
  25143. grid.treeBase.tree = service.createTree( grid, renderableRows );
  25144. service.updateRowHeaderWidth( grid );
  25145. service.sortTree( grid );
  25146. service.fixFilter( grid );
  25147. return service.renderTree( grid.treeBase.tree );
  25148. },
  25149. /**
  25150. * @ngdoc function
  25151. * @name createOrUpdateRowHeaderWidth
  25152. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25153. * @description Calculates the rowHeader width.
  25154. *
  25155. * If rowHeader is always present, updates the width.
  25156. *
  25157. * If rowHeader is only sometimes present (`treeRowHeaderAlwaysVisible: false`), determines whether there
  25158. * should be one, then creates or removes it as appropriate, with the created rowHeader having the
  25159. * right width.
  25160. *
  25161. * If there's never a rowHeader then never creates one: `showTreeRowHeader: false`
  25162. *
  25163. * @param {Grid} grid the grid we want to set the row header on
  25164. */
  25165. updateRowHeaderWidth: function( grid ){
  25166. var rowHeader = grid.getColumn(uiGridTreeBaseConstants.rowHeaderColName);
  25167. var newWidth = grid.options.treeRowHeaderBaseWidth + grid.options.treeIndent * Math.max(grid.treeBase.numberLevels - 1, 0);
  25168. if ( rowHeader && newWidth !== rowHeader.width ){
  25169. rowHeader.width = newWidth;
  25170. grid.queueRefresh();
  25171. }
  25172. var newVisibility = true;
  25173. if ( grid.options.showTreeRowHeader === false ){
  25174. newVisibility = false;
  25175. }
  25176. if ( grid.options.treeRowHeaderAlwaysVisible === false && grid.treeBase.numberLevels <= 0 ){
  25177. newVisibility = false;
  25178. }
  25179. if ( rowHeader && rowHeader.visible !== newVisibility ) {
  25180. rowHeader.visible = newVisibility;
  25181. rowHeader.colDef.visible = newVisibility;
  25182. grid.queueGridRefresh();
  25183. }
  25184. },
  25185. /**
  25186. * @ngdoc function
  25187. * @name renderTree
  25188. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25189. * @description Creates an array of rows based on the tree, exporting only
  25190. * the visible nodes and leaves
  25191. *
  25192. * @param {array} nodeList The list of nodes - can be grid.treeBase.tree, or can be node.children when
  25193. * we're calling recursively
  25194. * @returns {array} renderable rows
  25195. */
  25196. renderTree: function( nodeList ){
  25197. var renderableRows = [];
  25198. nodeList.forEach( function ( node ){
  25199. if ( node.row.visible ){
  25200. renderableRows.push( node.row );
  25201. }
  25202. if ( node.state === uiGridTreeBaseConstants.EXPANDED && node.children && node.children.length > 0 ){
  25203. renderableRows = renderableRows.concat( service.renderTree( node.children ) );
  25204. }
  25205. });
  25206. return renderableRows;
  25207. },
  25208. /**
  25209. * @ngdoc function
  25210. * @name createTree
  25211. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25212. * @description Creates a tree from the renderableRows
  25213. *
  25214. * @param {Grid} grid The grid
  25215. * @param {array} renderableRows The rows we want to create a tree from
  25216. * @returns {object} The tree we've build
  25217. */
  25218. createTree: function( grid, renderableRows ) {
  25219. var currentLevel = -1;
  25220. var parents = [];
  25221. var currentState;
  25222. grid.treeBase.tree = [];
  25223. grid.treeBase.numberLevels = 0;
  25224. var aggregations = service.getAggregations( grid );
  25225. var createNode = function( row ){
  25226. if ( typeof(row.entity.$$treeLevel) !== 'undefined' && row.treeLevel !== row.entity.$$treeLevel ){
  25227. row.treeLevel = row.entity.$$treeLevel;
  25228. }
  25229. if ( row.treeLevel <= currentLevel ){
  25230. // pop any levels that aren't parents of this level, formatting the aggregation at the same time
  25231. while ( row.treeLevel <= currentLevel ){
  25232. var lastParent = parents.pop();
  25233. service.finaliseAggregations( lastParent );
  25234. currentLevel--;
  25235. }
  25236. // reset our current state based on the new parent, set to expanded if this is a level 0 node
  25237. if ( parents.length > 0 ){
  25238. currentState = service.setCurrentState(parents);
  25239. } else {
  25240. currentState = uiGridTreeBaseConstants.EXPANDED;
  25241. }
  25242. }
  25243. // aggregate if this is a leaf node
  25244. if ( ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) && row.visible ){
  25245. service.aggregate( grid, row, parents );
  25246. }
  25247. // add this node to the tree
  25248. service.addOrUseNode(grid, row, parents, aggregations);
  25249. if ( typeof(row.treeLevel) !== 'undefined' && row.treeLevel !== null && row.treeLevel >= 0 ){
  25250. parents.push(row);
  25251. currentLevel++;
  25252. currentState = service.setCurrentState(parents);
  25253. }
  25254. // update the tree number of levels, so we can set header width if we need to
  25255. if ( grid.treeBase.numberLevels < row.treeLevel + 1){
  25256. grid.treeBase.numberLevels = row.treeLevel + 1;
  25257. }
  25258. };
  25259. renderableRows.forEach( createNode );
  25260. // finalise remaining aggregations
  25261. while ( parents.length > 0 ){
  25262. var lastParent = parents.pop();
  25263. service.finaliseAggregations( lastParent );
  25264. }
  25265. return grid.treeBase.tree;
  25266. },
  25267. /**
  25268. * @ngdoc function
  25269. * @name addOrUseNode
  25270. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25271. * @description Creates a tree node for this row. If this row already has a treeNode
  25272. * recorded against it, preserves the state, but otherwise overwrites the data.
  25273. *
  25274. * @param {grid} grid The grid we're operating on
  25275. * @param {gridRow} row The row we want to set
  25276. * @param {array} parents An array of the parents this row should have
  25277. * @param {array} aggregationBase Empty aggregation information
  25278. * @returns {undefined} Updates the parents array, updates the row to have a treeNode, and updates the
  25279. * grid.treeBase.tree
  25280. */
  25281. addOrUseNode: function( grid, row, parents, aggregationBase ){
  25282. var newAggregations = [];
  25283. aggregationBase.forEach( function(aggregation){
  25284. newAggregations.push(service.buildAggregationObject(aggregation.col));
  25285. });
  25286. var newNode = { state: uiGridTreeBaseConstants.COLLAPSED, row: row, parentRow: null, aggregations: newAggregations, children: [] };
  25287. if ( row.treeNode ){
  25288. newNode.state = row.treeNode.state;
  25289. }
  25290. if ( parents.length > 0 ){
  25291. newNode.parentRow = parents[parents.length - 1];
  25292. }
  25293. row.treeNode = newNode;
  25294. if ( parents.length === 0 ){
  25295. grid.treeBase.tree.push( newNode );
  25296. } else {
  25297. parents[parents.length - 1].treeNode.children.push( newNode );
  25298. }
  25299. },
  25300. /**
  25301. * @ngdoc function
  25302. * @name setCurrentState
  25303. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25304. * @description Looks at the parents array to determine our current state.
  25305. * If any node in the hierarchy is collapsed, then return collapsed, otherwise return
  25306. * expanded.
  25307. *
  25308. * @param {array} parents An array of the parents this row should have
  25309. * @returns {string} The state we should be setting to any nodes we see
  25310. */
  25311. setCurrentState: function( parents ){
  25312. var currentState = uiGridTreeBaseConstants.EXPANDED;
  25313. parents.forEach( function(parent){
  25314. if ( parent.treeNode.state === uiGridTreeBaseConstants.COLLAPSED ){
  25315. currentState = uiGridTreeBaseConstants.COLLAPSED;
  25316. }
  25317. });
  25318. return currentState;
  25319. },
  25320. /**
  25321. * @ngdoc function
  25322. * @name sortTree
  25323. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25324. * @description Performs a recursive sort on the tree nodes, sorting the
  25325. * children of each node and putting them back into the children array.
  25326. *
  25327. * Before doing this it turns back on all the sortIgnore - things that were previously
  25328. * ignored we process now. Since we're sorting within the nodes, presumably anything
  25329. * that was already sorted is how we derived the nodes, we can keep those sorts too.
  25330. *
  25331. * We only sort tree nodes that are expanded - no point in wasting effort sorting collapsed
  25332. * nodes
  25333. *
  25334. * @param {Grid} grid The grid to get the aggregation information from
  25335. * @returns {array} The aggregation information
  25336. */
  25337. sortTree: function( grid ){
  25338. grid.columns.forEach( function( column ) {
  25339. if ( column.sort && column.sort.ignoreSort ){
  25340. delete column.sort.ignoreSort;
  25341. }
  25342. });
  25343. grid.treeBase.tree = service.sortInternal( grid, grid.treeBase.tree );
  25344. },
  25345. sortInternal: function( grid, treeList ){
  25346. var rows = treeList.map( function( node ){
  25347. return node.row;
  25348. });
  25349. rows = rowSorter.sort( grid, rows, grid.columns );
  25350. var treeNodes = rows.map( function( row ){
  25351. return row.treeNode;
  25352. });
  25353. treeNodes.forEach( function( node ){
  25354. if ( node.state === uiGridTreeBaseConstants.EXPANDED && node.children && node.children.length > 0 ){
  25355. node.children = service.sortInternal( grid, node.children );
  25356. }
  25357. });
  25358. return treeNodes;
  25359. },
  25360. /**
  25361. * @ngdoc function
  25362. * @name fixFilter
  25363. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25364. * @description After filtering has run, we need to go back through the tree
  25365. * and make sure the parent rows are always visible if any of the child rows
  25366. * are visible (filtering may make a child visible, but the parent may not
  25367. * match the filter criteria)
  25368. *
  25369. * This has a risk of being computationally expensive, we do it by walking
  25370. * the tree and remembering whether there are any invisible nodes on the
  25371. * way down.
  25372. *
  25373. * @param {Grid} grid the grid to fix filters on
  25374. */
  25375. fixFilter: function( grid ){
  25376. var parentsVisible;
  25377. grid.treeBase.tree.forEach( function( node ){
  25378. if ( node.children && node.children.length > 0 ){
  25379. parentsVisible = node.row.visible;
  25380. service.fixFilterInternal( node.children, parentsVisible );
  25381. }
  25382. });
  25383. },
  25384. fixFilterInternal: function( nodes, parentsVisible) {
  25385. nodes.forEach( function( node ){
  25386. if ( node.row.visible && !parentsVisible ){
  25387. service.setParentsVisible( node );
  25388. parentsVisible = true;
  25389. }
  25390. if ( node.children && node.children.length > 0 ){
  25391. if ( service.fixFilterInternal( node.children, ( parentsVisible && node.row.visible ) ) ) {
  25392. parentsVisible = true;
  25393. }
  25394. }
  25395. });
  25396. return parentsVisible;
  25397. },
  25398. setParentsVisible: function( node ){
  25399. while ( node.parentRow ){
  25400. node.parentRow.visible = true;
  25401. node = node.parentRow.treeNode;
  25402. }
  25403. },
  25404. /**
  25405. * @ngdoc function
  25406. * @name buildAggregationObject
  25407. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25408. * @description Build the object which is stored on the column for holding meta-data about the aggregation.
  25409. * This method should only be called with columns which have an aggregation.
  25410. *
  25411. * @param {GridColumn} column The column which this object relates to
  25412. * @returns {object} {col: GridColumn object, label: string, type: string (optional)}
  25413. */
  25414. buildAggregationObject: function( column ){
  25415. var newAggregation = { col: column };
  25416. if ( column.treeAggregation && column.treeAggregation.type ){
  25417. newAggregation.type = column.treeAggregation.type;
  25418. }
  25419. if ( column.treeAggregation && column.treeAggregation.label ){
  25420. newAggregation.label = column.treeAggregation.label;
  25421. }
  25422. return newAggregation;
  25423. },
  25424. /**
  25425. * @ngdoc function
  25426. * @name getAggregations
  25427. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25428. * @description Looks through the grid columns to find those with aggregations,
  25429. * and collates the aggregation information into an array, returns that array
  25430. *
  25431. * @param {Grid} grid the grid to get the aggregation information from
  25432. * @returns {array} the aggregation information
  25433. */
  25434. getAggregations: function( grid ){
  25435. var aggregateArray = [];
  25436. grid.columns.forEach( function(column){
  25437. if ( typeof(column.treeAggregationFn) !== 'undefined' ){
  25438. aggregateArray.push( service.buildAggregationObject(column) );
  25439. if ( grid.options.showColumnFooter && typeof(column.colDef.aggregationType) === 'undefined' && column.treeAggregation ){
  25440. // Add aggregation object for footer
  25441. column.treeFooterAggregation = service.buildAggregationObject(column);
  25442. column.aggregationType = service.treeFooterAggregationType;
  25443. }
  25444. }
  25445. });
  25446. return aggregateArray;
  25447. },
  25448. /**
  25449. * @ngdoc function
  25450. * @name aggregate
  25451. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25452. * @description Accumulate the data from this row onto the aggregations for each parent
  25453. *
  25454. * Iterate over the parents, then iterate over the aggregations for each of those parents,
  25455. * and perform the aggregation for each individual aggregation
  25456. *
  25457. * @param {Grid} grid grid object
  25458. * @param {GridRow} row the row we want to set grouping visibility on
  25459. * @param {array} parents the parents that we would want to aggregate onto
  25460. */
  25461. aggregate: function( grid, row, parents ){
  25462. if ( parents.length === 0 && row.treeNode && row.treeNode.aggregations ){
  25463. row.treeNode.aggregations.forEach(function(aggregation){
  25464. // Calculate aggregations for footer even if there are no grouped rows
  25465. if ( typeof(aggregation.col.treeFooterAggregation) !== 'undefined' ) {
  25466. var fieldValue = grid.getCellValue(row, aggregation.col);
  25467. var numValue = Number(fieldValue);
  25468. aggregation.col.treeAggregationFn(aggregation.col.treeFooterAggregation, fieldValue, numValue, row);
  25469. }
  25470. });
  25471. }
  25472. parents.forEach( function( parent, index ){
  25473. if ( parent.treeNode.aggregations ){
  25474. parent.treeNode.aggregations.forEach( function( aggregation ){
  25475. var fieldValue = grid.getCellValue(row, aggregation.col);
  25476. var numValue = Number(fieldValue);
  25477. aggregation.col.treeAggregationFn(aggregation, fieldValue, numValue, row);
  25478. if ( index === 0 && typeof(aggregation.col.treeFooterAggregation) !== 'undefined' ){
  25479. aggregation.col.treeAggregationFn(aggregation.col.treeFooterAggregation, fieldValue, numValue, row);
  25480. }
  25481. });
  25482. }
  25483. });
  25484. },
  25485. // Aggregation routines - no doco needed as self evident
  25486. nativeAggregations: function() {
  25487. var nativeAggregations = {
  25488. count: {
  25489. label: i18nService.get().aggregation.count,
  25490. menuTitle: i18nService.get().grouping.aggregate_count,
  25491. aggregationFn: function (aggregation, fieldValue, numValue) {
  25492. if (typeof(aggregation.value) === 'undefined') {
  25493. aggregation.value = 1;
  25494. } else {
  25495. aggregation.value++;
  25496. }
  25497. }
  25498. },
  25499. sum: {
  25500. label: i18nService.get().aggregation.sum,
  25501. menuTitle: i18nService.get().grouping.aggregate_sum,
  25502. aggregationFn: function( aggregation, fieldValue, numValue ) {
  25503. if (!isNaN(numValue)) {
  25504. if (typeof(aggregation.value) === 'undefined') {
  25505. aggregation.value = numValue;
  25506. } else {
  25507. aggregation.value += numValue;
  25508. }
  25509. }
  25510. }
  25511. },
  25512. min: {
  25513. label: i18nService.get().aggregation.min,
  25514. menuTitle: i18nService.get().grouping.aggregate_min,
  25515. aggregationFn: function( aggregation, fieldValue, numValue ) {
  25516. if (typeof(aggregation.value) === 'undefined') {
  25517. aggregation.value = fieldValue;
  25518. } else {
  25519. if (typeof(fieldValue) !== 'undefined' && fieldValue !== null && (fieldValue < aggregation.value || aggregation.value === null)) {
  25520. aggregation.value = fieldValue;
  25521. }
  25522. }
  25523. }
  25524. },
  25525. max: {
  25526. label: i18nService.get().aggregation.max,
  25527. menuTitle: i18nService.get().grouping.aggregate_max,
  25528. aggregationFn: function( aggregation, fieldValue, numValue ){
  25529. if ( typeof(aggregation.value) === 'undefined' ){
  25530. aggregation.value = fieldValue;
  25531. } else {
  25532. if ( typeof(fieldValue) !== 'undefined' && fieldValue !== null && (fieldValue > aggregation.value || aggregation.value === null)){
  25533. aggregation.value = fieldValue;
  25534. }
  25535. }
  25536. }
  25537. },
  25538. avg: {
  25539. label: i18nService.get().aggregation.avg,
  25540. menuTitle: i18nService.get().grouping.aggregate_avg,
  25541. aggregationFn: function( aggregation, fieldValue, numValue ){
  25542. if ( typeof(aggregation.count) === 'undefined' ){
  25543. aggregation.count = 1;
  25544. } else {
  25545. aggregation.count++;
  25546. }
  25547. if ( isNaN(numValue) ){
  25548. return;
  25549. }
  25550. if ( typeof(aggregation.value) === 'undefined' || typeof(aggregation.sum) === 'undefined' ){
  25551. aggregation.value = numValue;
  25552. aggregation.sum = numValue;
  25553. } else {
  25554. aggregation.sum += numValue;
  25555. aggregation.value = aggregation.sum / aggregation.count;
  25556. }
  25557. }
  25558. }
  25559. };
  25560. return nativeAggregations;
  25561. },
  25562. /**
  25563. * @ngdoc function
  25564. * @name finaliseAggregation
  25565. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25566. * @description Helper function used to finalize aggregation nodes and footer cells
  25567. *
  25568. * @param {gridRow} row The parent we're finalising
  25569. * @param {aggregation} aggregation The aggregation object manipulated by the aggregationFn
  25570. */
  25571. finaliseAggregation: function(row, aggregation){
  25572. if ( aggregation.col.treeAggregationUpdateEntity && typeof(row) !== 'undefined' && typeof(row.entity[ '$$' + aggregation.col.uid ]) !== 'undefined' ){
  25573. angular.extend( aggregation, row.entity[ '$$' + aggregation.col.uid ]);
  25574. }
  25575. if ( typeof(aggregation.col.treeAggregationFinalizerFn) === 'function' ){
  25576. aggregation.col.treeAggregationFinalizerFn( aggregation );
  25577. }
  25578. if ( typeof(aggregation.col.customTreeAggregationFinalizerFn) === 'function' ){
  25579. aggregation.col.customTreeAggregationFinalizerFn( aggregation );
  25580. }
  25581. if ( typeof(aggregation.rendered) === 'undefined' ){
  25582. aggregation.rendered = aggregation.label ? aggregation.label + aggregation.value : aggregation.value;
  25583. }
  25584. },
  25585. /**
  25586. * @ngdoc function
  25587. * @name finaliseAggregations
  25588. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25589. * @description Format the data from the aggregation into the rendered text
  25590. * e.g. if we had label: 'sum: ' and value: 25, we'd create 'sum: 25'.
  25591. *
  25592. * As part of this we call any formatting callback routines we've been provided.
  25593. *
  25594. * We write our aggregation out to the row.entity if treeAggregationUpdateEntity is
  25595. * set on the column - we don't overwrite any information that's already there, we append
  25596. * to it so that grouping can have set the groupVal beforehand without us overwriting it.
  25597. *
  25598. * We need to copy the data from the row.entity first before we finalise the aggregation,
  25599. * we need that information for the finaliserFn
  25600. *
  25601. * @param {gridRow} row the parent we're finalising
  25602. */
  25603. finaliseAggregations: function( row ){
  25604. if ( row == null || typeof(row.treeNode.aggregations) === 'undefined' ){
  25605. return;
  25606. }
  25607. row.treeNode.aggregations.forEach( function( aggregation ) {
  25608. service.finaliseAggregation(row, aggregation);
  25609. if ( aggregation.col.treeAggregationUpdateEntity ){
  25610. var aggregationCopy = {};
  25611. angular.forEach( aggregation, function( value, key ){
  25612. if ( aggregation.hasOwnProperty(key) && key !== 'col' ){
  25613. aggregationCopy[key] = value;
  25614. }
  25615. });
  25616. row.entity[ '$$' + aggregation.col.uid ] = aggregationCopy;
  25617. }
  25618. });
  25619. },
  25620. /**
  25621. * @ngdoc function
  25622. * @name treeFooterAggregationType
  25623. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25624. * @description Uses the tree aggregation functions and finalizers to set the
  25625. * column footer aggregations.
  25626. *
  25627. * @param {rows} rows The visible rows. not used, but accepted to match signature of GridColumn.aggregationType
  25628. * @param {GridColumn} column The column we are finalizing
  25629. */
  25630. treeFooterAggregationType: function( rows, column ) {
  25631. service.finaliseAggregation(undefined, column.treeFooterAggregation);
  25632. if ( typeof(column.treeFooterAggregation.value) === 'undefined' || column.treeFooterAggregation.rendered === null ){
  25633. // The was apparently no aggregation performed (perhaps this is a grouped column
  25634. return '';
  25635. }
  25636. return column.treeFooterAggregation.rendered;
  25637. }
  25638. };
  25639. return service;
  25640. }]);
  25641. /**
  25642. * @ngdoc directive
  25643. * @name ui.grid.treeBase.directive:uiGridTreeRowHeaderButtons
  25644. * @element div
  25645. *
  25646. * @description Provides the expand/collapse button on rows
  25647. */
  25648. module.directive('uiGridTreeBaseRowHeaderButtons', ['$templateCache', 'uiGridTreeBaseService',
  25649. function ($templateCache, uiGridTreeBaseService) {
  25650. return {
  25651. replace: true,
  25652. restrict: 'E',
  25653. template: $templateCache.get('ui-grid/treeBaseRowHeaderButtons'),
  25654. scope: true,
  25655. require: '^uiGrid',
  25656. link: function($scope, $elm, $attrs, uiGridCtrl) {
  25657. var self = uiGridCtrl.grid;
  25658. $scope.treeButtonClick = function(row, evt) {
  25659. evt.stopPropagation();
  25660. uiGridTreeBaseService.toggleRowTreeState(self, row, evt);
  25661. };
  25662. }
  25663. };
  25664. }]);
  25665. /**
  25666. * @ngdoc directive
  25667. * @name ui.grid.treeBase.directive:uiGridTreeBaseExpandAllButtons
  25668. * @element div
  25669. *
  25670. * @description Provides the expand/collapse all button
  25671. */
  25672. module.directive('uiGridTreeBaseExpandAllButtons', ['$templateCache', 'uiGridTreeBaseService',
  25673. function ($templateCache, uiGridTreeBaseService) {
  25674. return {
  25675. replace: true,
  25676. restrict: 'E',
  25677. template: $templateCache.get('ui-grid/treeBaseExpandAllButtons'),
  25678. scope: false,
  25679. link: function($scope, $elm, $attrs, uiGridCtrl) {
  25680. var self = $scope.col.grid;
  25681. $scope.headerButtonClick = function(row, evt) {
  25682. if ( self.treeBase.expandAll ){
  25683. uiGridTreeBaseService.collapseAllRows(self, evt);
  25684. } else {
  25685. uiGridTreeBaseService.expandAllRows(self, evt);
  25686. }
  25687. };
  25688. }
  25689. };
  25690. }]);
  25691. /**
  25692. * @ngdoc directive
  25693. * @name ui.grid.treeBase.directive:uiGridViewport
  25694. * @element div
  25695. *
  25696. * @description Stacks on top of ui.grid.uiGridViewport to set formatting on a tree header row
  25697. */
  25698. module.directive('uiGridViewport',
  25699. ['$compile', 'uiGridConstants', 'gridUtil', '$parse',
  25700. function ($compile, uiGridConstants, gridUtil, $parse) {
  25701. return {
  25702. priority: -200, // run after default directive
  25703. scope: false,
  25704. compile: function ($elm, $attrs) {
  25705. var rowRepeatDiv = angular.element($elm.children().children()[0]);
  25706. var existingNgClass = rowRepeatDiv.attr("ng-class");
  25707. var newNgClass = '';
  25708. if ( existingNgClass ) {
  25709. newNgClass = existingNgClass.slice(0, -1) + ",'ui-grid-tree-header-row': row.treeLevel > -1}";
  25710. } else {
  25711. newNgClass = "{'ui-grid-tree-header-row': row.treeLevel > -1}";
  25712. }
  25713. rowRepeatDiv.attr("ng-class", newNgClass);
  25714. return {
  25715. pre: function ($scope, $elm, $attrs, controllers) {
  25716. },
  25717. post: function ($scope, $elm, $attrs, controllers) {
  25718. }
  25719. };
  25720. }
  25721. };
  25722. }]);
  25723. })();
  25724. (function () {
  25725. 'use strict';
  25726. /**
  25727. * @ngdoc overview
  25728. * @name ui.grid.treeView
  25729. * @description
  25730. *
  25731. * # ui.grid.treeView
  25732. *
  25733. * <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>
  25734. *
  25735. * This module provides a tree view of the data that it is provided, with nodes in that
  25736. * tree and leaves. Unlike grouping, the tree is an inherent property of the data and must
  25737. * be provided with your data array.
  25738. *
  25739. * Design information:
  25740. * -------------------
  25741. *
  25742. * TreeView uses treeBase for the underlying functionality, and is a very thin wrapper around
  25743. * that logic. Most of the design information has now moved to treebase.
  25744. * <br/>
  25745. * <br/>
  25746. *
  25747. * <div doc-module-components="ui.grid.treeView"></div>
  25748. */
  25749. var module = angular.module('ui.grid.treeView', ['ui.grid', 'ui.grid.treeBase']);
  25750. /**
  25751. * @ngdoc object
  25752. * @name ui.grid.treeView.constant:uiGridTreeViewConstants
  25753. *
  25754. * @description constants available in treeView module, this includes
  25755. * all the constants declared in the treeBase module (these are manually copied
  25756. * as there isn't an easy way to include constants in another constants file, and
  25757. * we don't want to make users include treeBase)
  25758. *
  25759. */
  25760. module.constant('uiGridTreeViewConstants', {
  25761. featureName: "treeView",
  25762. rowHeaderColName: 'treeBaseRowHeaderCol',
  25763. EXPANDED: 'expanded',
  25764. COLLAPSED: 'collapsed',
  25765. aggregation: {
  25766. COUNT: 'count',
  25767. SUM: 'sum',
  25768. MAX: 'max',
  25769. MIN: 'min',
  25770. AVG: 'avg'
  25771. }
  25772. });
  25773. /**
  25774. * @ngdoc service
  25775. * @name ui.grid.treeView.service:uiGridTreeViewService
  25776. *
  25777. * @description Services for treeView features
  25778. */
  25779. module.service('uiGridTreeViewService', ['$q', 'uiGridTreeViewConstants', 'uiGridTreeBaseConstants', 'uiGridTreeBaseService', 'gridUtil', 'GridRow', 'gridClassFactory', 'i18nService', 'uiGridConstants',
  25780. function ($q, uiGridTreeViewConstants, uiGridTreeBaseConstants, uiGridTreeBaseService, gridUtil, GridRow, gridClassFactory, i18nService, uiGridConstants) {
  25781. var service = {
  25782. initializeGrid: function (grid, $scope) {
  25783. uiGridTreeBaseService.initializeGrid( grid, $scope );
  25784. /**
  25785. * @ngdoc object
  25786. * @name ui.grid.treeView.grid:treeView
  25787. *
  25788. * @description Grid properties and functions added for treeView
  25789. */
  25790. grid.treeView = {};
  25791. grid.registerRowsProcessor(service.adjustSorting, 60);
  25792. /**
  25793. * @ngdoc object
  25794. * @name ui.grid.treeView.api:PublicApi
  25795. *
  25796. * @description Public Api for treeView feature
  25797. */
  25798. var publicApi = {
  25799. events: {
  25800. treeView: {
  25801. }
  25802. },
  25803. methods: {
  25804. treeView: {
  25805. }
  25806. }
  25807. };
  25808. grid.api.registerEventsFromObject(publicApi.events);
  25809. grid.api.registerMethodsFromObject(publicApi.methods);
  25810. },
  25811. defaultGridOptions: function (gridOptions) {
  25812. //default option to true unless it was explicitly set to false
  25813. /**
  25814. * @ngdoc object
  25815. * @name ui.grid.treeView.api:GridOptions
  25816. *
  25817. * @description GridOptions for treeView feature, these are available to be
  25818. * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
  25819. *
  25820. * Many tree options are set on treeBase, make sure to look at that feature in
  25821. * conjunction with these options.
  25822. */
  25823. /**
  25824. * @ngdoc object
  25825. * @name enableTreeView
  25826. * @propertyOf ui.grid.treeView.api:GridOptions
  25827. * @description Enable row tree view for entire grid.
  25828. * <br/>Defaults to true
  25829. */
  25830. gridOptions.enableTreeView = gridOptions.enableTreeView !== false;
  25831. },
  25832. /**
  25833. * @ngdoc function
  25834. * @name adjustSorting
  25835. * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService
  25836. * @description Trees cannot be sorted the same as flat lists of rows -
  25837. * trees are sorted recursively within each level - so the children of each
  25838. * node are sorted, but not the full set of rows.
  25839. *
  25840. * To achieve this, we suppress the normal sorting by setting ignoreSort on
  25841. * each of the sort columns. When the treeBase rowsProcessor runs it will then
  25842. * unignore these, and will perform a recursive sort against the tree that it builds.
  25843. *
  25844. * @param {array} renderableRows the rows that we need to pass on through
  25845. * @returns {array} renderableRows that we passed on through
  25846. */
  25847. adjustSorting: function( renderableRows ) {
  25848. var grid = this;
  25849. grid.columns.forEach( function( column ){
  25850. if ( column.sort ){
  25851. column.sort.ignoreSort = true;
  25852. }
  25853. });
  25854. return renderableRows;
  25855. }
  25856. };
  25857. return service;
  25858. }]);
  25859. /**
  25860. * @ngdoc directive
  25861. * @name ui.grid.treeView.directive:uiGridTreeView
  25862. * @element div
  25863. * @restrict A
  25864. *
  25865. * @description Adds treeView features to grid
  25866. *
  25867. * @example
  25868. <example module="app">
  25869. <file name="app.js">
  25870. var app = angular.module('app', ['ui.grid', 'ui.grid.treeView']);
  25871. app.controller('MainCtrl', ['$scope', function ($scope) {
  25872. $scope.data = [
  25873. { name: 'Bob', title: 'CEO' },
  25874. { name: 'Frank', title: 'Lowly Developer' }
  25875. ];
  25876. $scope.columnDefs = [
  25877. {name: 'name', enableCellEdit: true},
  25878. {name: 'title', enableCellEdit: true}
  25879. ];
  25880. $scope.gridOptions = { columnDefs: $scope.columnDefs, data: $scope.data };
  25881. }]);
  25882. </file>
  25883. <file name="index.html">
  25884. <div ng-controller="MainCtrl">
  25885. <div ui-grid="gridOptions" ui-grid-tree-view></div>
  25886. </div>
  25887. </file>
  25888. </example>
  25889. */
  25890. module.directive('uiGridTreeView', ['uiGridTreeViewConstants', 'uiGridTreeViewService', '$templateCache',
  25891. function (uiGridTreeViewConstants, uiGridTreeViewService, $templateCache) {
  25892. return {
  25893. replace: true,
  25894. priority: 0,
  25895. require: '^uiGrid',
  25896. scope: false,
  25897. compile: function () {
  25898. return {
  25899. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  25900. if (uiGridCtrl.grid.options.enableTreeView !== false){
  25901. uiGridTreeViewService.initializeGrid(uiGridCtrl.grid, $scope);
  25902. }
  25903. },
  25904. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  25905. }
  25906. };
  25907. }
  25908. };
  25909. }]);
  25910. })();
  25911. (function () {
  25912. 'use strict';
  25913. /**
  25914. * @ngdoc overview
  25915. * @name ui.grid.validate
  25916. * @description
  25917. *
  25918. * # ui.grid.validate
  25919. *
  25920. * <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>
  25921. *
  25922. * This module provides the ability to validate cells upon change.
  25923. *
  25924. * Design information:
  25925. * -------------------
  25926. *
  25927. * Validation is not based on angularjs validation, since it would work only when editing the field.
  25928. *
  25929. * Instead it adds custom properties to any field considered as invalid.
  25930. *
  25931. * <br/>
  25932. * <br/>
  25933. *
  25934. * <div doc-module-components="ui.grid.expandable"></div>
  25935. */
  25936. var module = angular.module('ui.grid.validate', ['ui.grid']);
  25937. /**
  25938. * @ngdoc service
  25939. * @name ui.grid.validate.service:uiGridValidateService
  25940. *
  25941. * @description Services for validation features
  25942. */
  25943. module.service('uiGridValidateService', ['$sce', '$q', '$http', 'i18nService', 'uiGridConstants', function ($sce, $q, $http, i18nService, uiGridConstants) {
  25944. var service = {
  25945. /**
  25946. * @ngdoc object
  25947. * @name validatorFactories
  25948. * @propertyOf ui.grid.validate.service:uiGridValidateService
  25949. * @description object containing all the factories used to validate data.<br/>
  25950. * These factories will be in the form <br/>
  25951. * ```
  25952. * {
  25953. * validatorFactory: function(argument) {
  25954. * return function(newValue, oldValue, rowEntity, colDef) {
  25955. * return true || false || promise
  25956. * }
  25957. * },
  25958. * messageFunction: function(argument) {
  25959. * return string
  25960. * }
  25961. * }
  25962. * ```
  25963. *
  25964. * Promises should return true or false as result according to the result of validation.
  25965. */
  25966. validatorFactories: {},
  25967. /**
  25968. * @ngdoc service
  25969. * @name setExternalFactoryFunction
  25970. * @methodOf ui.grid.validate.service:uiGridValidateService
  25971. * @description Adds a way to retrieve validators from an external service
  25972. * <p>Validators from this external service have a higher priority than default
  25973. * ones
  25974. * @param {function} externalFactoryFunction a function that accepts name and argument to pass to a
  25975. * validator factory and that returns an object with the same properties as
  25976. * you can see in {@link ui.grid.validate.service:uiGridValidateService#properties_validatorFactories validatorFactories}
  25977. */
  25978. setExternalFactoryFunction: function(externalFactoryFunction) {
  25979. service.externalFactoryFunction = externalFactoryFunction;
  25980. },
  25981. /**
  25982. * @ngdoc service
  25983. * @name clearExternalFactory
  25984. * @methodOf ui.grid.validate.service:uiGridValidateService
  25985. * @description Removes any link to external factory from this service
  25986. */
  25987. clearExternalFactory: function() {
  25988. delete service.externalFactoryFunction;
  25989. },
  25990. /**
  25991. * @ngdoc service
  25992. * @name getValidatorFromExternalFactory
  25993. * @methodOf ui.grid.validate.service:uiGridValidateService
  25994. * @description Retrieves a validator by executing a validatorFactory
  25995. * stored in an external service.
  25996. * @param {string} name the name of the validator to retrieve
  25997. * @param {object} argument an argument to pass to the validator factory
  25998. */
  25999. getValidatorFromExternalFactory: function(name, argument) {
  26000. return service.externalFactoryFunction(name, argument).validatorFactory(argument);
  26001. },
  26002. /**
  26003. * @ngdoc service
  26004. * @name getMessageFromExternalFactory
  26005. * @methodOf ui.grid.validate.service:uiGridValidateService
  26006. * @description Retrieves a message stored in an external service.
  26007. * @param {string} name the name of the validator
  26008. * @param {object} argument an argument to pass to the message function
  26009. */
  26010. getMessageFromExternalFactory: function(name, argument) {
  26011. return service.externalFactoryFunction(name, argument).messageFunction(argument);
  26012. },
  26013. /**
  26014. * @ngdoc service
  26015. * @name setValidator
  26016. * @methodOf ui.grid.validate.service:uiGridValidateService
  26017. * @description Adds a new validator to the service
  26018. * @param {string} name the name of the validator, must be unique
  26019. * @param {function} validatorFactory a factory that return a validatorFunction
  26020. * @param {function} messageFunction a function that return the error message
  26021. */
  26022. setValidator: function(name, validatorFactory, messageFunction) {
  26023. service.validatorFactories[name] = {
  26024. validatorFactory: validatorFactory,
  26025. messageFunction: messageFunction
  26026. };
  26027. },
  26028. /**
  26029. * @ngdoc service
  26030. * @name getValidator
  26031. * @methodOf ui.grid.validate.service:uiGridValidateService
  26032. * @description Returns a validator registered to the service
  26033. * or retrieved from the external factory
  26034. * @param {string} name the name of the validator to retrieve
  26035. * @param {object} argument an argument to pass to the validator factory
  26036. * @returns {object} the validator function
  26037. */
  26038. getValidator: function(name, argument) {
  26039. if (service.externalFactoryFunction) {
  26040. var validator = service.getValidatorFromExternalFactory(name, argument);
  26041. if (validator) {
  26042. return validator;
  26043. }
  26044. }
  26045. if (!service.validatorFactories[name]) {
  26046. throw ("Invalid validator name: " + name);
  26047. }
  26048. return service.validatorFactories[name].validatorFactory(argument);
  26049. },
  26050. /**
  26051. * @ngdoc service
  26052. * @name getMessage
  26053. * @methodOf ui.grid.validate.service:uiGridValidateService
  26054. * @description Returns the error message related to the validator
  26055. * @param {string} name the name of the validator
  26056. * @param {object} argument an argument to pass to the message function
  26057. * @returns {string} the error message related to the validator
  26058. */
  26059. getMessage: function(name, argument) {
  26060. if (service.externalFactoryFunction) {
  26061. var message = service.getMessageFromExternalFactory(name, argument);
  26062. if (message) {
  26063. return message;
  26064. }
  26065. }
  26066. return service.validatorFactories[name].messageFunction(argument);
  26067. },
  26068. /**
  26069. * @ngdoc service
  26070. * @name isInvalid
  26071. * @methodOf ui.grid.validate.service:uiGridValidateService
  26072. * @description Returns true if the cell (identified by rowEntity, colDef) is invalid
  26073. * @param {object} rowEntity the row entity of the cell
  26074. * @param {object} colDef the colDef of the cell
  26075. * @returns {boolean} true if the cell is invalid
  26076. */
  26077. isInvalid: function (rowEntity, colDef) {
  26078. return rowEntity['$$invalid'+colDef.name];
  26079. },
  26080. /**
  26081. * @ngdoc service
  26082. * @name setInvalid
  26083. * @methodOf ui.grid.validate.service:uiGridValidateService
  26084. * @description Makes the cell invalid by adding the proper field to the entity
  26085. * @param {object} rowEntity the row entity of the cell
  26086. * @param {object} colDef the colDef of the cell
  26087. */
  26088. setInvalid: function (rowEntity, colDef) {
  26089. rowEntity['$$invalid'+colDef.name] = true;
  26090. },
  26091. /**
  26092. * @ngdoc service
  26093. * @name setValid
  26094. * @methodOf ui.grid.validate.service:uiGridValidateService
  26095. * @description Makes the cell valid by removing the proper error field from the entity
  26096. * @param {object} rowEntity the row entity of the cell
  26097. * @param {object} colDef the colDef of the cell
  26098. */
  26099. setValid: function (rowEntity, colDef) {
  26100. delete rowEntity['$$invalid'+colDef.name];
  26101. },
  26102. /**
  26103. * @ngdoc service
  26104. * @name setError
  26105. * @methodOf ui.grid.validate.service:uiGridValidateService
  26106. * @description Adds the proper error to the entity errors field
  26107. * @param {object} rowEntity the row entity of the cell
  26108. * @param {object} colDef the colDef of the cell
  26109. * @param {string} validatorName the name of the validator that is failing
  26110. */
  26111. setError: function(rowEntity, colDef, validatorName) {
  26112. if (!rowEntity['$$errors'+colDef.name]) {
  26113. rowEntity['$$errors'+colDef.name] = {};
  26114. }
  26115. rowEntity['$$errors'+colDef.name][validatorName] = true;
  26116. },
  26117. /**
  26118. * @ngdoc service
  26119. * @name clearError
  26120. * @methodOf ui.grid.validate.service:uiGridValidateService
  26121. * @description Removes the proper error from the entity errors field
  26122. * @param {object} rowEntity the row entity of the cell
  26123. * @param {object} colDef the colDef of the cell
  26124. * @param {string} validatorName the name of the validator that is failing
  26125. */
  26126. clearError: function(rowEntity, colDef, validatorName) {
  26127. if (!rowEntity['$$errors'+colDef.name]) {
  26128. return;
  26129. }
  26130. if (validatorName in rowEntity['$$errors'+colDef.name]) {
  26131. delete rowEntity['$$errors'+colDef.name][validatorName];
  26132. }
  26133. },
  26134. /**
  26135. * @ngdoc function
  26136. * @name getErrorMessages
  26137. * @methodOf ui.grid.validate.service:uiGridValidateService
  26138. * @description returns an array of i18n-ed error messages.
  26139. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for
  26140. * @param {object} colDef the column whose errors we are looking for
  26141. * @returns {array} An array of strings containing all the error messages for the cell
  26142. */
  26143. getErrorMessages: function(rowEntity, colDef) {
  26144. var errors = [];
  26145. if (!rowEntity['$$errors'+colDef.name] || Object.keys(rowEntity['$$errors'+colDef.name]).length === 0) {
  26146. return errors;
  26147. }
  26148. Object.keys(rowEntity['$$errors'+colDef.name]).sort().forEach(function(validatorName) {
  26149. errors.push(service.getMessage(validatorName, colDef.validators[validatorName]));
  26150. });
  26151. return errors;
  26152. },
  26153. /**
  26154. * @ngdoc function
  26155. * @name getFormattedErrors
  26156. * @methodOf ui.grid.validate.service:uiGridValidateService
  26157. * @description returns the error i18n-ed and formatted in html to be shown inside the page.
  26158. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for
  26159. * @param {object} colDef the column whose errors we are looking for
  26160. * @returns {object} An object that can be used in a template (like a cellTemplate) to display the
  26161. * message inside the page (i.e. inside a div)
  26162. */
  26163. getFormattedErrors: function(rowEntity, colDef) {
  26164. var msgString = "";
  26165. var errors = service.getErrorMessages(rowEntity, colDef);
  26166. if (!errors.length) {
  26167. return;
  26168. }
  26169. errors.forEach(function(errorMsg) {
  26170. msgString += errorMsg + "<br/>";
  26171. });
  26172. return $sce.trustAsHtml('<p><b>' + i18nService.getSafeText('validate.error') + '</b></p>' + msgString );
  26173. },
  26174. /**
  26175. * @ngdoc function
  26176. * @name getTitleFormattedErrors
  26177. * @methodOf ui.grid.validate.service:uiGridValidateService
  26178. * @description returns the error i18n-ed and formatted in javaScript to be shown inside an html
  26179. * title attribute.
  26180. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for
  26181. * @param {object} colDef the column whose errors we are looking for
  26182. * @returns {object} An object that can be used in a template (like a cellTemplate) to display the
  26183. * message inside an html title attribute
  26184. */
  26185. getTitleFormattedErrors: function(rowEntity, colDef) {
  26186. var newLine = "\n";
  26187. var msgString = "";
  26188. var errors = service.getErrorMessages(rowEntity, colDef);
  26189. if (!errors.length) {
  26190. return;
  26191. }
  26192. errors.forEach(function(errorMsg) {
  26193. msgString += errorMsg + newLine;
  26194. });
  26195. return $sce.trustAsHtml(i18nService.getSafeText('validate.error') + newLine + msgString);
  26196. },
  26197. /**
  26198. * @ngdoc function
  26199. * @name getTitleFormattedErrors
  26200. * @methodOf ui.grid.validate.service:uiGridValidateService
  26201. * @description Executes all validators on a cell (identified by row entity and column definition) and sets or clears errors
  26202. * @param {object} rowEntity the row entity of the cell we want to run the validators on
  26203. * @param {object} colDef the column definition of the cell we want to run the validators on
  26204. * @param {object} newValue the value the user just entered
  26205. * @param {object} oldValue the value the field had before
  26206. */
  26207. runValidators: function(rowEntity, colDef, newValue, oldValue, grid) {
  26208. if (newValue === oldValue) {
  26209. // If the value has not changed we perform no validation
  26210. return;
  26211. }
  26212. if (typeof(colDef.name) === 'undefined' || !colDef.name) {
  26213. throw new Error('colDef.name is required to perform validation');
  26214. }
  26215. service.setValid(rowEntity, colDef);
  26216. var validateClosureFactory = function(rowEntity, colDef, validatorName) {
  26217. return function(value) {
  26218. if (!value) {
  26219. service.setInvalid(rowEntity, colDef);
  26220. service.setError(rowEntity, colDef, validatorName);
  26221. if (grid) {
  26222. grid.api.validate.raise.validationFailed(rowEntity, colDef, newValue, oldValue);
  26223. }
  26224. }
  26225. };
  26226. };
  26227. var promises = [];
  26228. for (var validatorName in colDef.validators) {
  26229. service.clearError(rowEntity, colDef, validatorName);
  26230. var msg;
  26231. var validatorFunction = service.getValidator(validatorName, colDef.validators[validatorName]);
  26232. // We pass the arguments as oldValue, newValue so they are in the same order
  26233. // as ng-model validators (modelValue, viewValue)
  26234. var promise = $q
  26235. .when(validatorFunction(oldValue, newValue, rowEntity, colDef))
  26236. .then(validateClosureFactory(rowEntity, colDef, validatorName));
  26237. promises.push(promise);
  26238. }
  26239. return $q.all(promises);
  26240. },
  26241. /**
  26242. * @ngdoc function
  26243. * @name createDefaultValidators
  26244. * @methodOf ui.grid.validate.service:uiGridValidateService
  26245. * @description adds the basic validators to the list of service validators
  26246. */
  26247. createDefaultValidators: function() {
  26248. service.setValidator('minLength',
  26249. function (argument) {
  26250. return function (oldValue, newValue, rowEntity, colDef) {
  26251. if (newValue === undefined || newValue === null || newValue === '') {
  26252. return true;
  26253. }
  26254. return newValue.length >= argument;
  26255. };
  26256. },
  26257. function(argument) {
  26258. return i18nService.getSafeText('validate.minLength').replace('THRESHOLD', argument);
  26259. });
  26260. service.setValidator('maxLength',
  26261. function (argument) {
  26262. return function (oldValue, newValue, rowEntity, colDef) {
  26263. if (newValue === undefined || newValue === null || newValue === '') {
  26264. return true;
  26265. }
  26266. return newValue.length <= argument;
  26267. };
  26268. },
  26269. function(threshold) {
  26270. return i18nService.getSafeText('validate.maxLength').replace('THRESHOLD', threshold);
  26271. });
  26272. service.setValidator('required',
  26273. function (argument) {
  26274. return function (oldValue, newValue, rowEntity, colDef) {
  26275. if (argument) {
  26276. return !(newValue === undefined || newValue === null || newValue === '');
  26277. }
  26278. return true;
  26279. };
  26280. },
  26281. function(argument) {
  26282. return i18nService.getSafeText('validate.required');
  26283. });
  26284. },
  26285. initializeGrid: function (scope, grid) {
  26286. grid.validate = {
  26287. isInvalid: service.isInvalid,
  26288. getFormattedErrors: service.getFormattedErrors,
  26289. getTitleFormattedErrors: service.getTitleFormattedErrors,
  26290. runValidators: service.runValidators
  26291. };
  26292. /**
  26293. * @ngdoc object
  26294. * @name ui.grid.validate.api:PublicApi
  26295. *
  26296. * @description Public Api for validation feature
  26297. */
  26298. var publicApi = {
  26299. events: {
  26300. validate: {
  26301. /**
  26302. * @ngdoc event
  26303. * @name validationFailed
  26304. * @eventOf ui.grid.validate.api:PublicApi
  26305. * @description raised when one or more failure happened during validation
  26306. * <pre>
  26307. * gridApi.validate.on.validationFailed(scope, function(rowEntity, colDef, newValue, oldValue){...})
  26308. * </pre>
  26309. * @param {object} rowEntity the options.data element whose validation failed
  26310. * @param {object} colDef the column whose validation failed
  26311. * @param {object} newValue new value
  26312. * @param {object} oldValue old value
  26313. */
  26314. validationFailed: function (rowEntity, colDef, newValue, oldValue) {
  26315. }
  26316. }
  26317. },
  26318. methods: {
  26319. validate: {
  26320. /**
  26321. * @ngdoc function
  26322. * @name isInvalid
  26323. * @methodOf ui.grid.validate.api:PublicApi
  26324. * @description checks if a cell (identified by rowEntity, colDef) is invalid
  26325. * @param {object} rowEntity gridOptions.data[] array instance we want to check
  26326. * @param {object} colDef the column whose errors we want to check
  26327. * @returns {boolean} true if the cell value is not valid
  26328. */
  26329. isInvalid: function(rowEntity, colDef) {
  26330. return grid.validate.isInvalid(rowEntity, colDef);
  26331. },
  26332. /**
  26333. * @ngdoc function
  26334. * @name getErrorMessages
  26335. * @methodOf ui.grid.validate.api:PublicApi
  26336. * @description returns an array of i18n-ed error messages.
  26337. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for
  26338. * @param {object} colDef the column whose errors we are looking for
  26339. * @returns {array} An array of strings containing all the error messages for the cell
  26340. */
  26341. getErrorMessages: function (rowEntity, colDef) {
  26342. return grid.validate.getErrorMessages(rowEntity, colDef);
  26343. },
  26344. /**
  26345. * @ngdoc function
  26346. * @name getFormattedErrors
  26347. * @methodOf ui.grid.validate.api:PublicApi
  26348. * @description returns the error i18n-ed and formatted in html to be shown inside the page.
  26349. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for
  26350. * @param {object} colDef the column whose errors we are looking for
  26351. * @returns {object} An object that can be used in a template (like a cellTemplate) to display the
  26352. * message inside the page (i.e. inside a div)
  26353. */
  26354. getFormattedErrors: function (rowEntity, colDef) {
  26355. return grid.validate.getFormattedErrors(rowEntity, colDef);
  26356. },
  26357. /**
  26358. * @ngdoc function
  26359. * @name getTitleFormattedErrors
  26360. * @methodOf ui.grid.validate.api:PublicApi
  26361. * @description returns the error i18n-ed and formatted in javaScript to be shown inside an html
  26362. * title attribute.
  26363. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for
  26364. * @param {object} colDef the column whose errors we are looking for
  26365. * @returns {object} An object that can be used in a template (like a cellTemplate) to display the
  26366. * message inside an html title attribute
  26367. */
  26368. getTitleFormattedErrors: function (rowEntity, colDef) {
  26369. return grid.validate.getTitleFormattedErrors(rowEntity, colDef);
  26370. }
  26371. }
  26372. }
  26373. };
  26374. grid.api.registerEventsFromObject(publicApi.events);
  26375. grid.api.registerMethodsFromObject(publicApi.methods);
  26376. if (grid.edit) {
  26377. grid.api.edit.on.afterCellEdit(scope, function(rowEntity, colDef, newValue, oldValue) {
  26378. grid.validate.runValidators(rowEntity, colDef, newValue, oldValue, grid);
  26379. });
  26380. }
  26381. service.createDefaultValidators();
  26382. }
  26383. };
  26384. return service;
  26385. }]);
  26386. /**
  26387. * @ngdoc directive
  26388. * @name ui.grid.validate.directive:uiGridValidate
  26389. * @element div
  26390. * @restrict A
  26391. * @description Adds validating features to the ui-grid directive.
  26392. * @example
  26393. <example module="app">
  26394. <file name="app.js">
  26395. var app = angular.module('app', ['ui.grid', 'ui.grid.edit', 'ui.grid.validate']);
  26396. app.controller('MainCtrl', ['$scope', function ($scope) {
  26397. $scope.data = [
  26398. { name: 'Bob', title: 'CEO' },
  26399. { name: 'Frank', title: 'Lowly Developer' }
  26400. ];
  26401. $scope.columnDefs = [
  26402. {name: 'name', enableCellEdit: true, validators: {minLength: 3, maxLength: 9}, cellTemplate: 'ui-grid/cellTitleValidator'},
  26403. {name: 'title', enableCellEdit: true, validators: {required: true}, cellTemplate: 'ui-grid/cellTitleValidator'}
  26404. ];
  26405. }]);
  26406. </file>
  26407. <file name="index.html">
  26408. <div ng-controller="MainCtrl">
  26409. <div ui-grid="{ data: data, columnDefs: columnDefs }" ui-grid-edit ui-grid-validate></div>
  26410. </div>
  26411. </file>
  26412. </example>
  26413. */
  26414. module.directive('uiGridValidate', ['gridUtil', 'uiGridValidateService', function (gridUtil, uiGridValidateService) {
  26415. return {
  26416. priority: 0,
  26417. replace: true,
  26418. require: '^uiGrid',
  26419. scope: false,
  26420. compile: function () {
  26421. return {
  26422. pre: function ($scope, $elm, $attrs, uiGridCtrl) {
  26423. uiGridValidateService.initializeGrid($scope, uiGridCtrl.grid);
  26424. },
  26425. post: function ($scope, $elm, $attrs, uiGridCtrl) {
  26426. }
  26427. };
  26428. }
  26429. };
  26430. }]);
  26431. })();
  26432. angular.module('ui.grid').run(['$templateCache', function($templateCache) {
  26433. 'use strict';
  26434. $templateCache.put('ui-grid/ui-grid-filter',
  26435. "<div class=\"ui-grid-filter-container\" ng-style=\"col.extraStyle\" 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-show=\"colFilter.selectOptions.length > 0\" 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>"
  26436. );
  26437. $templateCache.put('ui-grid/ui-grid-footer',
  26438. "<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>"
  26439. );
  26440. $templateCache.put('ui-grid/ui-grid-grid-footer',
  26441. "<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>"
  26442. );
  26443. $templateCache.put('ui-grid/ui-grid-header',
  26444. "<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>"
  26445. );
  26446. $templateCache.put('ui-grid/ui-grid-menu-button',
  26447. "<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>"
  26448. );
  26449. $templateCache.put('ui-grid/ui-grid-no-header',
  26450. "<div class=\"ui-grid-top-panel\"></div>"
  26451. );
  26452. $templateCache.put('ui-grid/ui-grid-row',
  26453. "<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>"
  26454. );
  26455. $templateCache.put('ui-grid/ui-grid',
  26456. "<div ui-i18n=\"en\" class=\"ui-grid\"><!-- TODO (c0bra): add \"scoped\" attr here, eventually? --><style ui-grid-style>.grid{{ grid.id }} {\n" +
  26457. " /* Styles for the grid */\n" +
  26458. " }\n" +
  26459. "\n" +
  26460. " .grid{{ grid.id }} .ui-grid-row, .grid{{ grid.id }} .ui-grid-cell, .grid{{ grid.id }} .ui-grid-cell .ui-grid-vertical-bar {\n" +
  26461. " height: {{ grid.options.rowHeight }}px;\n" +
  26462. " }\n" +
  26463. "\n" +
  26464. " .grid{{ grid.id }} .ui-grid-row:last-child .ui-grid-cell {\n" +
  26465. " border-bottom-width: {{ (((grid.getVisibleRowCount() * grid.options.rowHeight) < grid.getViewportHeight()) && '1') || '0' }}px;\n" +
  26466. " }\n" +
  26467. "\n" +
  26468. " {{ grid.verticalScrollbarStyles }}\n" +
  26469. " {{ grid.horizontalScrollbarStyles }}\n" +
  26470. "\n" +
  26471. " /*\n" +
  26472. " .ui-grid[dir=rtl] .ui-grid-viewport {\n" +
  26473. " padding-left: {{ grid.verticalScrollbarWidth }}px;\n" +
  26474. " }\n" +
  26475. " */\n" +
  26476. "\n" +
  26477. " {{ grid.customStyles }}</style><div class=\"ui-grid-contents-wrapper\" role=\"grid\"><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>"
  26478. );
  26479. $templateCache.put('ui-grid/uiGridCell',
  26480. "<div class=\"ui-grid-cell-contents\" title=\"TOOLTIP\">{{COL_FIELD CUSTOM_FILTERS}}</div>"
  26481. );
  26482. $templateCache.put('ui-grid/uiGridColumnMenu',
  26483. "<div class=\"ui-grid-column-menu\"><div ui-grid-menu menu-items=\"menuItems\"><!-- <div class=\"ui-grid-column-menu\">\n" +
  26484. " <div class=\"inner\" ng-show=\"menuShown\">\n" +
  26485. " <ul>\n" +
  26486. " <div ng-show=\"grid.options.enableSorting\">\n" +
  26487. " <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" +
  26488. " <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" +
  26489. " <li ng-show=\"col.sort.direction\" ng-click=\"unsortColumn()\"><i class=\"ui-grid-icon-cancel\"></i> Remove Sort</li>\n" +
  26490. " </div>\n" +
  26491. " </ul>\n" +
  26492. " </div>\n" +
  26493. " </div> --></div></div>"
  26494. );
  26495. $templateCache.put('ui-grid/uiGridFooterCell',
  26496. "<div class=\"ui-grid-cell-contents\" col-index=\"renderIndex\"><div>{{ col.getAggregationText() + ( col.getAggregationValue() CUSTOM_FILTERS ) }}</div></div>"
  26497. );
  26498. $templateCache.put('ui-grid/uiGridHeaderCell',
  26499. "<div role=\"columnheader\" ng-class=\"{ 'sortable': sortable, 'ui-grid-header-cell-last-col': isLastCol }\" 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\" ng-keydown=\"handleKeyDown($event)\" 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-keydown=\"headerCellArrowKeyDown($event)\" 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>"
  26500. );
  26501. $templateCache.put('ui-grid/uiGridMenu',
  26502. "<div class=\"ui-grid-menu\" ng-show=\"shown\"><style ui-grid-style>{{dynamicStyles}}</style><div class=\"ui-grid-menu-mid\" ng-show=\"shownMid\"><div class=\"ui-grid-menu-inner\" ng-if=\"shown\"><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>"
  26503. );
  26504. $templateCache.put('ui-grid/uiGridMenuItem',
  26505. "<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> {{ label() }}</button>"
  26506. );
  26507. $templateCache.put('ui-grid/uiGridRenderContainer',
  26508. "<div role=\"presentation\" 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>"
  26509. );
  26510. $templateCache.put('ui-grid/uiGridViewport',
  26511. "<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>"
  26512. );
  26513. $templateCache.put('ui-grid/cellEditor',
  26514. "<div><form name=\"inputForm\"><input type=\"INPUT_TYPE\" ng-class=\"'colt' + col.uid\" ui-grid-editor ng-model=\"MODEL_COL_FIELD\"></form></div>"
  26515. );
  26516. $templateCache.put('ui-grid/dropdownEditor',
  26517. "<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>"
  26518. );
  26519. $templateCache.put('ui-grid/fileChooserEditor',
  26520. "<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>"
  26521. );
  26522. $templateCache.put('ui-grid/emptyBaseLayerContainer',
  26523. "<div class=\"ui-grid-empty-base-layer-container ui-grid-canvas\"><div class=\"ui-grid-row\" ng-repeat=\"(rowRenderIndex, row) in grid.baseLayer.emptyRows track by $index\" ng-style=\"Viewport.rowStyle(rowRenderIndex)\"><div><div><div ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name\" class=\"ui-grid-cell {{ col.getColClass(false) }}\"></div></div></div></div></div>"
  26524. );
  26525. $templateCache.put('ui-grid/expandableRow',
  26526. "<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>"
  26527. );
  26528. $templateCache.put('ui-grid/expandableRowHeader',
  26529. "<div class=\"ui-grid-row-header-cell ui-grid-expandable-buttons-cell\"><div class=\"ui-grid-cell-contents\"><i ng-if=\"!(row.groupHeader==true || row.entity.subGridOptions.disableRowExpandable)\" 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>"
  26530. );
  26531. $templateCache.put('ui-grid/expandableScrollFiller',
  26532. "<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>"
  26533. );
  26534. $templateCache.put('ui-grid/expandableTopRowHeader',
  26535. "<div class=\"ui-grid-row-header-cell ui-grid-expandable-buttons-cell\"><div class=\"ui-grid-cell-contents\"><span class=\"ui-grid-cell-empty\" ng-if=\"!grid.options.showExpandAllButton\"></span> <button type=\"button\" class=\"ui-grid-icon-button\" ng-if=\"grid.options.showExpandAllButton\" ng-class=\"{ 'ui-grid-icon-plus-squared' : !grid.expandable.expandedAll, 'ui-grid-icon-minus-squared' : grid.expandable.expandedAll }\" ng-click=\"grid.api.expandable.toggleAllRows()\"></button></div></div>"
  26536. );
  26537. $templateCache.put('ui-grid/csvLink',
  26538. "<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>"
  26539. );
  26540. $templateCache.put('ui-grid/importerMenuItem',
  26541. "<li class=\"ui-grid-menu-item\"><form><input class=\"ui-grid-importer-file-chooser\" type=\"file\" id=\"files\" name=\"files[]\"></form></li>"
  26542. );
  26543. $templateCache.put('ui-grid/importerMenuItemContainer',
  26544. "<div ui-grid-importer-menu-item></div>"
  26545. );
  26546. $templateCache.put('ui-grid/pagination',
  26547. "<div class=\"ui-grid-pager-panel\" ui-grid-pager ng-show=\"grid.options.enablePaginationControls\"><div role=\"navigation\" class=\"ui-grid-pager-container\"><div class=\"ui-grid-pager-control\"><button type=\"button\" 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\" 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() }}\" step=\"1\" 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\" 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\" 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 && !grid.options.useCustomPagination\"><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\">{{ 1 + paginationApi.getFirstRowIndex() }} <abbr ui-grid-one-bind-title=\"paginationThrough\">-</abbr> {{ 1 + paginationApi.getLastRowIndex() }} {{paginationOf}} {{grid.options.totalItems}} {{totalItemsLabel}}</span></div></div></div>"
  26548. );
  26549. $templateCache.put('ui-grid/columnResizer',
  26550. "<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>"
  26551. );
  26552. $templateCache.put('ui-grid/gridFooterSelectedItems',
  26553. "<span ng-if=\"grid.selection.selectedCount !== 0 && grid.options.enableFooterTotalSelected\">({{\"search.selectedItems\" | t}} {{grid.selection.selectedCount}})</span>"
  26554. );
  26555. $templateCache.put('ui-grid/selectionHeaderCell',
  26556. "<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\" role=\"checkbox\" ng-model=\"grid.selection.selectAll\"></ui-grid-selection-select-all-buttons></div></div>"
  26557. );
  26558. $templateCache.put('ui-grid/selectionRowHeader',
  26559. "<div class=\"ui-grid-cell-contents ui-grid-disable-selection\"><ui-grid-selection-row-header-buttons></ui-grid-selection-row-header-buttons></div>"
  26560. );
  26561. $templateCache.put('ui-grid/selectionRowHeaderButtons',
  26562. "<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)\" ng-keydown=\"selectButtonKeyDown(row, $event)\" role=\"checkbox\" ng-model=\"row.isSelected\">&nbsp;</div>"
  26563. );
  26564. $templateCache.put('ui-grid/selectionSelectAllButtons',
  26565. "<div role=\"button\" class=\"ui-grid-selection-row-header-buttons ui-grid-icon-ok\" ng-class=\"{'ui-grid-all-selected': grid.selection.selectAll}\" ng-click=\"headerButtonClick($event)\" ng-keydown=\"headerButtonKeyDown($event)\"></div>"
  26566. );
  26567. $templateCache.put('ui-grid/treeBaseExpandAllButtons',
  26568. "<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>"
  26569. );
  26570. $templateCache.put('ui-grid/treeBaseHeaderCell',
  26571. "<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>"
  26572. );
  26573. $templateCache.put('ui-grid/treeBaseRowHeader',
  26574. "<div class=\"ui-grid-cell-contents\"><ui-grid-tree-base-row-header-buttons></ui-grid-tree-base-row-header-buttons></div>"
  26575. );
  26576. $templateCache.put('ui-grid/treeBaseRowHeaderButtons',
  26577. "<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>"
  26578. );
  26579. $templateCache.put('ui-grid/cellTitleValidator',
  26580. "<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>"
  26581. );
  26582. $templateCache.put('ui-grid/cellTooltipValidator',
  26583. "<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>"
  26584. );
  26585. }]);