jquery.jqGrid.min.js 586 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505
  1. /**
  2. *
  3. * @license Guriddo jqGrid JS - v5.2.1 - 2017-05-01
  4. * Copyright(c) 2008, Tony Tomov, tony@trirand.com
  5. *
  6. * License: http://guriddo.net/?page_id=103334
  7. */
  8. (function( factory ) {
  9. "use strict";
  10. if ( typeof define === "function" && define.amd ) {
  11. // AMD. Register as an anonymous module.
  12. define([
  13. "jquery"
  14. ], factory );
  15. } else {
  16. // Browser globals
  17. factory( jQuery );
  18. }
  19. }(function( $ ) {
  20. "use strict";
  21. //module begin
  22. $.jgrid = $.jgrid || {};
  23. if(!$.jgrid.hasOwnProperty("defaults")) {
  24. $.jgrid.defaults = {};
  25. }
  26. $.extend($.jgrid,{
  27. version : "5.2.1",
  28. htmlDecode : function(value){
  29. if(value && (value===' ' || value===' ' || (value.length===1 && value.charCodeAt(0)===160))) { return "";}
  30. return !value ? value : String(value).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
  31. },
  32. htmlEncode : function (value){
  33. return !value ? value : String(value).replace(/&/g, "&amp;").replace(/\"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  34. },
  35. template : function(format){ //jqgformat
  36. var args = $.makeArray(arguments).slice(1), j, al = args.length;
  37. if(format==null) { format = ""; }
  38. return format.replace(/\{([\w\-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, function(m,i){
  39. if(!isNaN(parseInt(i,10))) {
  40. return args[parseInt(i,10)];
  41. }
  42. for(j=0; j < al;j++) {
  43. if($.isArray(args[j])) {
  44. var nmarr = args[ j ],
  45. k = nmarr.length;
  46. while(k--) {
  47. if(i===nmarr[k].nm) {
  48. return nmarr[k].v;
  49. }
  50. }
  51. }
  52. }
  53. });
  54. },
  55. msie : function () {
  56. return $.jgrid.msiever() > 0;
  57. },
  58. msiever : function () {
  59. var rv =0,
  60. sAgent = window.navigator.userAgent,
  61. Idx = sAgent.indexOf("MSIE");
  62. if (Idx > 0) {
  63. rv = parseInt(sAgent.substring(Idx+ 5, sAgent.indexOf(".", Idx)));
  64. } else if ( !!navigator.userAgent.match(/Trident\/7\./) ) {
  65. rv = 11;
  66. }
  67. return rv;
  68. },
  69. getCellIndex : function (cell) {
  70. var c = $(cell);
  71. if (c.is('tr')) { return -1; }
  72. c = (!c.is('td') && !c.is('th') ? c.closest("td,th") : c)[0];
  73. if ($.jgrid.msie()) { return $.inArray(c, c.parentNode.cells); }
  74. return c.cellIndex;
  75. },
  76. stripHtml : function(v) {
  77. v = String(v);
  78. var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
  79. if (v) {
  80. v = v.replace(regexp,"");
  81. return (v && v !== '&nbsp;' && v !== '&#160;') ? v.replace(/\"/g,"'") : "";
  82. }
  83. return v;
  84. },
  85. stripPref : function (pref, id) {
  86. var obj = $.type( pref );
  87. if( obj === "string" || obj === "number") {
  88. pref = String(pref);
  89. id = pref !== "" ? String(id).replace(String(pref), "") : id;
  90. }
  91. return id;
  92. },
  93. useJSON : true,
  94. parse : function(jsonString) {
  95. var js = jsonString;
  96. if (js.substr(0,9) === "while(1);") { js = js.substr(9); }
  97. if (js.substr(0,2) === "/*") { js = js.substr(2,js.length-4); }
  98. if(!js) { js = "{}"; }
  99. return ($.jgrid.useJSON===true && typeof JSON === 'object' && typeof JSON.parse === 'function') ?
  100. JSON.parse(js) :
  101. eval('(' + js + ')');
  102. },
  103. parseDate : function(format, date, newformat, opts) {
  104. var token = /\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g,
  105. timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
  106. timezoneClip = /[^-+\dA-Z]/g,
  107. msDateRegExp = new RegExp("^\/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)\/$"),
  108. msMatch = ((typeof date === 'string') ? date.match(msDateRegExp): null),
  109. pad = function (value, length) {
  110. value = String(value);
  111. length = parseInt(length,10) || 2;
  112. while (value.length < length) { value = '0' + value; }
  113. return value;
  114. },
  115. ts = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0},
  116. timestamp=0, dM, k,hl,
  117. h12to24 = function(ampm, h){
  118. if (ampm === 0){ if (h === 12) { h = 0;} }
  119. else { if (h !== 12) { h += 12; } }
  120. return h;
  121. },
  122. offset =0;
  123. if(opts === undefined) {
  124. opts = $.jgrid.getRegional(this, "formatter.date");//$.jgrid.formatter.date;
  125. }
  126. // old lang files
  127. if(opts.parseRe === undefined ) {
  128. opts.parseRe = /[#%\\\/:_;.,\t\s-]/;
  129. }
  130. if( opts.masks.hasOwnProperty(format) ) { format = opts.masks[format]; }
  131. if(date && date != null) {
  132. if( !isNaN( date - 0 ) && String(format).toLowerCase() === "u") {
  133. //Unix timestamp
  134. timestamp = new Date( parseFloat(date)*1000 );
  135. } else if(date.constructor === Date) {
  136. timestamp = date;
  137. // Microsoft date format support
  138. } else if( msMatch !== null ) {
  139. timestamp = new Date(parseInt(msMatch[1], 10));
  140. if (msMatch[3]) {
  141. offset = Number(msMatch[5]) * 60 + Number(msMatch[6]);
  142. offset *= ((msMatch[4] === '-') ? 1 : -1);
  143. offset -= timestamp.getTimezoneOffset();
  144. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  145. }
  146. } else {
  147. //Support ISO8601Long that have Z at the end to indicate UTC timezone
  148. if(opts.srcformat === 'ISO8601Long' && date.charAt(date.length - 1) === 'Z') {
  149. offset -= (new Date()).getTimezoneOffset();
  150. }
  151. date = String(date).replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe);
  152. format = format.replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe);
  153. // parsing for month names
  154. for(k=0,hl=format.length;k<hl;k++){
  155. switch ( format[k] ) {
  156. case 'M':
  157. dM = $.inArray(date[k],opts.monthNames);
  158. if(dM !== -1 && dM < 12){date[k] = dM+1; ts.m = date[k];}
  159. break;
  160. case 'F':
  161. dM = $.inArray(date[k],opts.monthNames,12);
  162. if(dM !== -1 && dM > 11){date[k] = dM+1-12; ts.m = date[k];}
  163. break;
  164. case 'n':
  165. format[k] = 'm';
  166. break;
  167. case 'j':
  168. format[k] = 'd';
  169. break;
  170. case 'a':
  171. dM = $.inArray(date[k],opts.AmPm);
  172. if(dM !== -1 && dM < 2 && date[k] === opts.AmPm[dM]){
  173. date[k] = dM;
  174. ts.h = h12to24(date[k], ts.h);
  175. }
  176. break;
  177. case 'A':
  178. dM = $.inArray(date[k],opts.AmPm);
  179. if(dM !== -1 && dM > 1 && date[k] === opts.AmPm[dM]){
  180. date[k] = dM-2;
  181. ts.h = h12to24(date[k], ts.h);
  182. }
  183. break;
  184. case 'g':
  185. ts.h = parseInt(date[k], 10);
  186. break;
  187. }
  188. if(date[k] !== undefined) {
  189. ts[format[k].toLowerCase()] = parseInt(date[k],10);
  190. }
  191. }
  192. if(ts.f) {ts.m = ts.f;}
  193. if( ts.m === 0 && ts.y === 0 && ts.d === 0) {
  194. return "&#160;" ;
  195. }
  196. ts.m = parseInt(ts.m,10)-1;
  197. var ty = ts.y;
  198. if (ty >= 70 && ty <= 99) {ts.y = 1900+ts.y;}
  199. else if (ty >=0 && ty <=69) {ts.y= 2000+ts.y;}
  200. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  201. //Apply offset to show date as local time.
  202. if(offset !== 0) {
  203. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  204. }
  205. }
  206. } else {
  207. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  208. }
  209. if(opts.userLocalTime && offset === 0) {
  210. offset -= (new Date()).getTimezoneOffset();
  211. if( offset !== 0 ) {
  212. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  213. }
  214. }
  215. if( newformat === undefined ) {
  216. return timestamp;
  217. }
  218. if( opts.masks.hasOwnProperty(newformat) ) {
  219. newformat = opts.masks[newformat];
  220. } else if ( !newformat ) {
  221. newformat = 'Y-m-d';
  222. }
  223. var
  224. G = timestamp.getHours(),
  225. i = timestamp.getMinutes(),
  226. j = timestamp.getDate(),
  227. n = timestamp.getMonth() + 1,
  228. o = timestamp.getTimezoneOffset(),
  229. s = timestamp.getSeconds(),
  230. u = timestamp.getMilliseconds(),
  231. w = timestamp.getDay(),
  232. Y = timestamp.getFullYear(),
  233. N = (w + 6) % 7 + 1,
  234. z = (new Date(Y, n - 1, j) - new Date(Y, 0, 1)) / 86400000,
  235. flags = {
  236. // Day
  237. d: pad(j),
  238. D: opts.dayNames[w],
  239. j: j,
  240. l: opts.dayNames[w + 7],
  241. N: N,
  242. S: opts.S(j),
  243. //j < 11 || j > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((j - 1) % 10, 3)] : 'th',
  244. w: w,
  245. z: z,
  246. // Week
  247. W: N < 5 ? Math.floor((z + N - 1) / 7) + 1 : Math.floor((z + N - 1) / 7) || ((new Date(Y - 1, 0, 1).getDay() + 6) % 7 < 4 ? 53 : 52),
  248. // Month
  249. F: opts.monthNames[n - 1 + 12],
  250. m: pad(n),
  251. M: opts.monthNames[n - 1],
  252. n: n,
  253. t: '?',
  254. // Year
  255. L: '?',
  256. o: '?',
  257. Y: Y,
  258. y: String(Y).substring(2),
  259. // Time
  260. a: G < 12 ? opts.AmPm[0] : opts.AmPm[1],
  261. A: G < 12 ? opts.AmPm[2] : opts.AmPm[3],
  262. B: '?',
  263. g: G % 12 || 12,
  264. G: G,
  265. h: pad(G % 12 || 12),
  266. H: pad(G),
  267. i: pad(i),
  268. s: pad(s),
  269. u: u,
  270. // Timezone
  271. e: '?',
  272. I: '?',
  273. O: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
  274. P: '?',
  275. T: (String(timestamp).match(timezone) || [""]).pop().replace(timezoneClip, ""),
  276. Z: '?',
  277. // Full Date/Time
  278. c: '?',
  279. r: '?',
  280. U: Math.floor(timestamp / 1000)
  281. };
  282. return newformat.replace(token, function ($0) {
  283. return flags.hasOwnProperty($0) ? flags[$0] : $0.substring(1);
  284. });
  285. },
  286. jqID : function(sid){
  287. return String(sid).replace(/[!"#$%&'()*+,.\/:; <=>?@\[\\\]\^`{|}~]/g,"\\$&");
  288. },
  289. guid : 1,
  290. uidPref: 'jqg',
  291. randId : function( prefix ) {
  292. return (prefix || $.jgrid.uidPref) + ($.jgrid.guid++);
  293. },
  294. getAccessor : function(obj, expr) {
  295. var ret,p,prm = [], i;
  296. if( typeof expr === 'function') { return expr(obj); }
  297. ret = obj[expr];
  298. if(ret===undefined) {
  299. try {
  300. if ( typeof expr === 'string' ) {
  301. prm = expr.split('.');
  302. }
  303. i = prm.length;
  304. if( i ) {
  305. ret = obj;
  306. while (ret && i--) {
  307. p = prm.shift();
  308. ret = ret[p];
  309. }
  310. }
  311. } catch (e) {}
  312. }
  313. return ret;
  314. },
  315. getXmlData: function (obj, expr, returnObj) {
  316. var ret, m = typeof expr === 'string' ? expr.match(/^(.*)\[(\w+)\]$/) : null;
  317. if (typeof expr === 'function') { return expr(obj); }
  318. if (m && m[2]) {
  319. // m[2] is the attribute selector
  320. // m[1] is an optional element selector
  321. // examples: "[id]", "rows[page]"
  322. return m[1] ? $(m[1], obj).attr(m[2]) : $(obj).attr(m[2]);
  323. }
  324. ret = $(expr, obj);
  325. if (returnObj) { return ret; }
  326. //$(expr, obj).filter(':last'); // we use ':last' to be more compatible with old version of jqGrid
  327. return ret.length > 0 ? $(ret).text() : undefined;
  328. },
  329. cellWidth : function () {
  330. var $testDiv = $("<div class='ui-jqgrid' style='left:10000px'><table class='ui-jqgrid-btable ui-common-table' style='width:5px;'><tr class='jqgrow'><td style='width:5px;display:block;'></td></tr></table></div>"),
  331. testCell = $testDiv.appendTo("body")
  332. .find("td")
  333. .width();
  334. $testDiv.remove();
  335. return Math.abs(testCell-5) > 0.1;
  336. },
  337. isLocalStorage : function () {
  338. try {
  339. return 'localStorage' in window && window.localStorage !== null;
  340. } catch (e) {
  341. return false;
  342. }
  343. },
  344. getRegional : function(inst, param, def_val) {
  345. var ret;
  346. if(def_val !== undefined) {
  347. return def_val;
  348. }
  349. if(inst.p && inst.p.regional && $.jgrid.regional) {
  350. ret = $.jgrid.getAccessor( $.jgrid.regional[inst.p.regional] || {}, param);
  351. }
  352. if(ret === undefined ) {
  353. ret = $.jgrid.getAccessor( $.jgrid, param);
  354. }
  355. return ret;
  356. },
  357. isMobile : function() {
  358. try {
  359. if(/Android|webOS|iPhone|iPad|iPod|pocket|psp|kindle|avantgo|blazer|midori|Tablet|Palm|maemo|plucker|phone|BlackBerry|symbian|IEMobile|mobile|ZuneWP7|Windows Phone|Opera Mini/i.test(navigator.userAgent)) {
  360. return true;
  361. }
  362. return false;
  363. } catch(e) {
  364. return false;
  365. }
  366. },
  367. cell_width : true,
  368. ajaxOptions: {},
  369. from : function(source){
  370. // Original Author Hugo Bonacci
  371. // License MIT http://jlinq.codeplex.com/license
  372. var $t = this,
  373. QueryObject=function(d,q){
  374. if(typeof d==="string"){
  375. d=$.data(d);
  376. }
  377. var self=this,
  378. _data=d,
  379. _usecase=true,
  380. _trim=false,
  381. _query=q,
  382. _stripNum = /[\$,%]/g,
  383. _lastCommand=null,
  384. _lastField=null,
  385. _orDepth=0,
  386. _negate=false,
  387. _queuedOperator="",
  388. _sorting=[],
  389. _useProperties=true;
  390. if(typeof d==="object"&&d.push) {
  391. if(d.length>0){
  392. if(typeof d[0]!=="object"){
  393. _useProperties=false;
  394. }else{
  395. _useProperties=true;
  396. }
  397. }
  398. }else{
  399. throw "data provides is not an array";
  400. }
  401. this._hasData=function(){
  402. return _data===null?false:_data.length===0?false:true;
  403. };
  404. this._getStr=function(s){
  405. var phrase=[];
  406. if(_trim){
  407. phrase.push("jQuery.trim(");
  408. }
  409. phrase.push("String("+s+")");
  410. if(_trim){
  411. phrase.push(")");
  412. }
  413. if(!_usecase){
  414. phrase.push(".toLowerCase()");
  415. }
  416. return phrase.join("");
  417. };
  418. this._strComp=function(val){
  419. if(typeof val==="string"){
  420. return".toString()";
  421. }
  422. return"";
  423. };
  424. this._group=function(f,u){
  425. return({field:f.toString(),unique:u,items:[]});
  426. };
  427. this._toStr=function(phrase){
  428. if(_trim){
  429. phrase=$.trim(phrase);
  430. }
  431. phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
  432. return _usecase ? phrase : phrase.toLowerCase();
  433. };
  434. this._funcLoop=function(func){
  435. var results=[];
  436. $.each(_data,function(i,v){
  437. results.push(func(v));
  438. });
  439. return results;
  440. };
  441. this._append=function(s){
  442. var i;
  443. if(_query===null){
  444. _query="";
  445. } else {
  446. _query+=_queuedOperator === "" ? " && " :_queuedOperator;
  447. }
  448. for (i=0;i<_orDepth;i++){
  449. _query+="(";
  450. }
  451. if(_negate){
  452. _query+="!";
  453. }
  454. _query+="("+s+")";
  455. _negate=false;
  456. _queuedOperator="";
  457. _orDepth=0;
  458. };
  459. this._setCommand=function(f,c){
  460. _lastCommand=f;
  461. _lastField=c;
  462. };
  463. this._resetNegate=function(){
  464. _negate=false;
  465. };
  466. this._repeatCommand=function(f,v){
  467. if(_lastCommand===null){
  468. return self;
  469. }
  470. if(f!==null&&v!==null){
  471. return _lastCommand(f,v);
  472. }
  473. if(_lastField===null){
  474. return _lastCommand(f);
  475. }
  476. if(!_useProperties){
  477. return _lastCommand(f);
  478. }
  479. return _lastCommand(_lastField,f);
  480. };
  481. this._equals=function(a,b){
  482. return(self._compare(a,b,1)===0);
  483. };
  484. this._compare=function(a,b,d){
  485. var toString = Object.prototype.toString;
  486. if( d === undefined) { d = 1; }
  487. if(a===undefined) { a = null; }
  488. if(b===undefined) { b = null; }
  489. if(a===null && b===null){
  490. return 0;
  491. }
  492. if(a===null&&b!==null){
  493. return 1;
  494. }
  495. if(a!==null&&b===null){
  496. return -1;
  497. }
  498. if (toString.call(a) === '[object Date]' && toString.call(b) === '[object Date]') {
  499. if (a < b) { return -d; }
  500. if (a > b) { return d; }
  501. return 0;
  502. }
  503. if(!_usecase && typeof a !== "number" && typeof b !== "number" ) {
  504. a=String(a);
  505. b=String(b);
  506. }
  507. if(a<b){return -d;}
  508. if(a>b){return d;}
  509. return 0;
  510. };
  511. this._performSort=function(){
  512. if(_sorting.length===0){return;}
  513. _data=self._doSort(_data,0);
  514. };
  515. this._doSort=function(d,q){
  516. var by=_sorting[q].by,
  517. dir=_sorting[q].dir,
  518. type = _sorting[q].type,
  519. dfmt = _sorting[q].datefmt,
  520. sfunc = _sorting[q].sfunc;
  521. if(q===_sorting.length-1){
  522. return self._getOrder(d, by, dir, type, dfmt, sfunc);
  523. }
  524. q++;
  525. var values=self._getGroup(d,by,dir,type,dfmt), results=[], i, j, sorted;
  526. for(i=0;i<values.length;i++){
  527. sorted=self._doSort(values[i].items,q);
  528. for(j=0;j<sorted.length;j++){
  529. results.push(sorted[j]);
  530. }
  531. }
  532. return results;
  533. };
  534. this._getOrder=function(data,by,dir,type, dfmt, sfunc){
  535. var sortData=[],_sortData=[], newDir = dir==="a" ? 1 : -1, i,ab,j,
  536. findSortKey;
  537. if(type === undefined ) { type = "text"; }
  538. if (type === 'float' || type=== 'number' || type=== 'currency' || type=== 'numeric') {
  539. findSortKey = function($cell) {
  540. var key = parseFloat( String($cell).replace(_stripNum, ''));
  541. return isNaN(key) ? Number.NEGATIVE_INFINITY : key;
  542. };
  543. } else if (type==='int' || type==='integer') {
  544. findSortKey = function($cell) {
  545. return $cell ? parseFloat(String($cell).replace(_stripNum, '')) : Number.NEGATIVE_INFINITY;
  546. };
  547. } else if(type === 'date' || type === 'datetime') {
  548. findSortKey = function($cell) {
  549. return $.jgrid.parseDate.call($t, dfmt, $cell).getTime();
  550. };
  551. } else if($.isFunction(type)) {
  552. findSortKey = type;
  553. } else {
  554. findSortKey = function($cell) {
  555. $cell = $cell ? $.trim(String($cell)) : "";
  556. return _usecase ? $cell : $cell.toLowerCase();
  557. };
  558. }
  559. $.each(data,function(i,v){
  560. ab = by!=="" ? $.jgrid.getAccessor(v,by) : v;
  561. if(ab === undefined) { ab = ""; }
  562. ab = findSortKey(ab, v);
  563. _sortData.push({ 'vSort': ab,'index':i});
  564. });
  565. if($.isFunction(sfunc)) {
  566. _sortData.sort(function(a,b){
  567. return sfunc.call(this,a.vSort, b.vSort, newDir, a, b);
  568. });
  569. } else {
  570. _sortData.sort(function(a,b){
  571. return self._compare(a.vSort, b.vSort,newDir);
  572. });
  573. }
  574. j=0;
  575. var nrec= data.length;
  576. // overhead, but we do not change the original data.
  577. while(j<nrec) {
  578. i = _sortData[j].index;
  579. sortData.push(data[i]);
  580. j++;
  581. }
  582. return sortData;
  583. };
  584. this._getGroup=function(data,by,dir,type, dfmt){
  585. var results=[],
  586. group=null,
  587. last=null, val;
  588. $.each(self._getOrder(data,by,dir,type, dfmt),function(i,v){
  589. val = $.jgrid.getAccessor(v, by);
  590. if(val == null) { val = ""; }
  591. if(!self._equals(last,val)){
  592. last=val;
  593. if(group !== null){
  594. results.push(group);
  595. }
  596. group=self._group(by,val);
  597. }
  598. group.items.push(v);
  599. });
  600. if(group !== null){
  601. results.push(group);
  602. }
  603. return results;
  604. };
  605. this.ignoreCase=function(){
  606. _usecase=false;
  607. return self;
  608. };
  609. this.useCase=function(){
  610. _usecase=true;
  611. return self;
  612. };
  613. this.trim=function(){
  614. _trim=true;
  615. return self;
  616. };
  617. this.noTrim=function(){
  618. _trim=false;
  619. return self;
  620. };
  621. this.execute=function(){
  622. var match=_query, results=[];
  623. if(match === null){
  624. return self;
  625. }
  626. $.each(_data,function(){
  627. if(eval(match)){results.push(this);}
  628. });
  629. _data=results;
  630. return self;
  631. };
  632. this.data=function(){
  633. return _data;
  634. };
  635. this.select=function(f){
  636. self._performSort();
  637. if(!self._hasData()){ return[]; }
  638. self.execute();
  639. if($.isFunction(f)){
  640. var results=[];
  641. $.each(_data,function(i,v){
  642. results.push(f(v));
  643. });
  644. return results;
  645. }
  646. return _data;
  647. };
  648. this.hasMatch=function(){
  649. if(!self._hasData()) { return false; }
  650. self.execute();
  651. return _data.length>0;
  652. };
  653. this.andNot=function(f,v,x){
  654. _negate=!_negate;
  655. return self.and(f,v,x);
  656. };
  657. this.orNot=function(f,v,x){
  658. _negate=!_negate;
  659. return self.or(f,v,x);
  660. };
  661. this.not=function(f,v,x){
  662. return self.andNot(f,v,x);
  663. };
  664. this.and=function(f,v,x){
  665. _queuedOperator=" && ";
  666. if(f===undefined){
  667. return self;
  668. }
  669. return self._repeatCommand(f,v,x);
  670. };
  671. this.or=function(f,v,x){
  672. _queuedOperator=" || ";
  673. if(f===undefined) { return self; }
  674. return self._repeatCommand(f,v,x);
  675. };
  676. this.orBegin=function(){
  677. _orDepth++;
  678. return self;
  679. };
  680. this.orEnd=function(){
  681. if (_query !== null){
  682. _query+=")";
  683. }
  684. return self;
  685. };
  686. this.isNot=function(f){
  687. _negate=!_negate;
  688. return self.is(f);
  689. };
  690. this.is=function(f){
  691. self._append('this.'+f);
  692. self._resetNegate();
  693. return self;
  694. };
  695. this._compareValues=function(func,f,v,how,t){
  696. var fld;
  697. if(_useProperties){
  698. fld='jQuery.jgrid.getAccessor(this,\''+f+'\')';
  699. }else{
  700. fld='this';
  701. }
  702. if(v===undefined) { v = null; }
  703. //var val=v===null?f:v,
  704. var val =v,
  705. swst = t.stype === undefined ? "text" : t.stype;
  706. if(v !== null) {
  707. switch(swst) {
  708. case 'int':
  709. case 'integer':
  710. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  711. fld = 'parseInt('+fld+',10)';
  712. val = 'parseInt('+val+',10)';
  713. break;
  714. case 'float':
  715. case 'number':
  716. case 'numeric':
  717. val = String(val).replace(_stripNum, '');
  718. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  719. fld = 'parseFloat('+fld+')';
  720. val = 'parseFloat('+val+')';
  721. break;
  722. case 'date':
  723. case 'datetime':
  724. val = String($.jgrid.parseDate.call($t, t.srcfmt || 'Y-m-d',val).getTime());
  725. fld = 'jQuery.jgrid.parseDate.call(jQuery("#'+$.jgrid.jqID($t.p.id)+'")[0],"'+t.srcfmt+'",'+fld+').getTime()';
  726. break;
  727. default :
  728. fld=self._getStr(fld);
  729. val=self._getStr('"'+self._toStr(val)+'"');
  730. }
  731. }
  732. self._append(fld+' '+how+' '+val);
  733. self._setCommand(func,f);
  734. self._resetNegate();
  735. return self;
  736. };
  737. this.equals=function(f,v,t){
  738. return self._compareValues(self.equals,f,v,"==",t);
  739. };
  740. this.notEquals=function(f,v,t){
  741. return self._compareValues(self.equals,f,v,"!==",t);
  742. };
  743. this.isNull = function(f,v,t){
  744. return self._compareValues(self.equals,f,null,"===",t);
  745. };
  746. this.greater=function(f,v,t){
  747. return self._compareValues(self.greater,f,v,">",t);
  748. };
  749. this.less=function(f,v,t){
  750. return self._compareValues(self.less,f,v,"<",t);
  751. };
  752. this.greaterOrEquals=function(f,v,t){
  753. return self._compareValues(self.greaterOrEquals,f,v,">=",t);
  754. };
  755. this.lessOrEquals=function(f,v,t){
  756. return self._compareValues(self.lessOrEquals,f,v,"<=",t);
  757. };
  758. this.startsWith=function(f,v){
  759. var val = (v==null) ? f: v,
  760. length=_trim ? $.trim(val.toString()).length : val.toString().length;
  761. if(_useProperties){
  762. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(v)+'"'));
  763. }else{
  764. if (v!=null) { length=_trim?$.trim(v.toString()).length:v.toString().length; }
  765. self._append(self._getStr('this')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(f)+'"'));
  766. }
  767. self._setCommand(self.startsWith,f);
  768. self._resetNegate();
  769. return self;
  770. };
  771. this.endsWith=function(f,v){
  772. var val = (v==null) ? f: v,
  773. length=_trim ? $.trim(val.toString()).length:val.toString().length;
  774. if(_useProperties){
  775. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr('+self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.length-'+length+','+length+') == "'+self._toStr(v)+'"');
  776. } else {
  777. self._append(self._getStr('this')+'.substr('+self._getStr('this')+'.length-"'+self._toStr(f)+'".length,"'+self._toStr(f)+'".length) == "'+self._toStr(f)+'"');
  778. }
  779. self._setCommand(self.endsWith,f);self._resetNegate();
  780. return self;
  781. };
  782. this.contains=function(f,v){
  783. if(_useProperties){
  784. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.indexOf("'+self._toStr(v)+'",0) > -1');
  785. }else{
  786. self._append(self._getStr('this')+'.indexOf("'+self._toStr(f)+'",0) > -1');
  787. }
  788. self._setCommand(self.contains,f);
  789. self._resetNegate();
  790. return self;
  791. };
  792. this.groupBy=function(by,dir,type, datefmt){
  793. if(!self._hasData()){
  794. return null;
  795. }
  796. return self._getGroup(_data,by,dir,type, datefmt);
  797. };
  798. this.orderBy=function(by,dir,stype, dfmt, sfunc){
  799. dir = dir == null ? "a" :$.trim(dir.toString().toLowerCase());
  800. if(stype == null) { stype = "text"; }
  801. if(dfmt == null) { dfmt = "Y-m-d"; }
  802. if(sfunc == null) { sfunc = false; }
  803. if(dir==="desc"||dir==="descending"){dir="d";}
  804. if(dir==="asc"||dir==="ascending"){dir="a";}
  805. _sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt, sfunc: sfunc});
  806. return self;
  807. };
  808. return self;
  809. };
  810. return new QueryObject(source,null);
  811. },
  812. getMethod: function (name) {
  813. return this.getAccessor($.fn.jqGrid, name);
  814. },
  815. extend : function(methods) {
  816. $.extend($.fn.jqGrid,methods);
  817. if (!this.no_legacy_api) {
  818. $.fn.extend(methods);
  819. }
  820. },
  821. clearBeforeUnload : function( jqGridId ) {
  822. var $t = $("#"+$.jgrid.jqID( jqGridId ))[0], grid;
  823. if(!$t.grid) { return;}
  824. grid = $t.grid;
  825. if ($.isFunction(grid.emptyRows)) {
  826. grid.emptyRows.call($t, true, true); // this work quick enough and reduce the size of memory leaks if we have someone
  827. }
  828. $(document).off("mouseup.jqGrid" + $t.p.id );
  829. $(grid.hDiv).off("mousemove"); // TODO add namespace
  830. $($t).off();
  831. var i, l = grid.headers.length,
  832. removevents = ['formatCol','sortData','updatepager','refreshIndex','setHeadCheckBox','constructTr','formatter','addXmlData','addJSONData','grid','p', 'addLocalData'];
  833. for (i = 0; i < l; i++) {
  834. grid.headers[i].el = null;
  835. }
  836. for( i in grid) {
  837. if( grid.hasOwnProperty(i)) {
  838. grid[i] = null;
  839. }
  840. }
  841. // experimental
  842. for( i in $t.p) {
  843. if($t.p.hasOwnProperty(i)) {
  844. $t.p[i] = $.isArray($t.p[i]) ? [] : null;
  845. }
  846. }
  847. l = removevents.length;
  848. for(i = 0; i < l; i++) {
  849. if($t.hasOwnProperty(removevents[i])) {
  850. $t[removevents[i]] = null;
  851. delete($t[removevents[i]]);
  852. }
  853. }
  854. },
  855. gridUnload : function ( jqGridId ) {
  856. if(!jqGridId) { return; }
  857. jqGridId = $.trim(jqGridId);
  858. if(jqGridId.indexOf("#") === 0) {
  859. jqGridId = jqGridId.substring(1);
  860. }
  861. var $t = $("#"+ $.jgrid.jqID(jqGridId))[0];
  862. if ( !$t.grid ) {return;}
  863. var defgrid = {id: $($t).attr('id'),cl: $($t).attr('class')};
  864. if ($t.p.pager) {
  865. $($t.p.pager).off().empty().removeClass("ui-state-default ui-jqgrid-pager ui-corner-bottom");
  866. }
  867. var newtable = document.createElement('table');
  868. newtable.className = defgrid.cl;
  869. var gid = $.jgrid.jqID($t.id);
  870. $(newtable).removeClass("ui-jqgrid-btable ui-common-table").insertBefore("#gbox_"+gid);
  871. if( $($t.p.pager).parents("#gbox_"+gid).length === 1 ) {
  872. $($t.p.pager).insertBefore("#gbox_"+gid);
  873. }
  874. $.jgrid.clearBeforeUnload( jqGridId );
  875. $("#gbox_"+gid).remove();
  876. $(newtable).attr({id:defgrid.id});
  877. $("#alertmod_"+$.jgrid.jqID(jqGridId)).remove();
  878. },
  879. gridDestroy : function ( jqGridId ) {
  880. if(!jqGridId) { return; }
  881. jqGridId = $.trim(jqGridId);
  882. if(jqGridId.indexOf("#") === 0) {
  883. jqGridId = jqGridId.substring(1);
  884. }
  885. var $t = $("#"+ $.jgrid.jqID(jqGridId))[0];
  886. if ( !$t.grid ) {return;}
  887. if ( $t.p.pager ) { // if not part of grid
  888. $($t.p.pager).remove();
  889. }
  890. try {
  891. $.jgrid.clearBeforeUnload( jqGridId );
  892. $("#gbox_"+$.jgrid.jqID(jqGridId)).remove();
  893. } catch (_) {}
  894. },
  895. styleUI : {
  896. jQueryUI : {
  897. common : {
  898. disabled: "ui-state-disabled",
  899. highlight : "ui-state-highlight",
  900. hover : "ui-state-hover",
  901. cornerall: "ui-corner-all",
  902. cornertop: "ui-corner-top",
  903. cornerbottom : "ui-corner-bottom",
  904. hidden : "ui-helper-hidden",
  905. icon_base : "ui-icon",
  906. overlay : "ui-widget-overlay",
  907. active : "ui-state-active",
  908. error : "ui-state-error",
  909. button : "ui-state-default ui-corner-all",
  910. content : "ui-widget-content"
  911. },
  912. base : {
  913. entrieBox : "ui-widget ui-widget-content ui-corner-all", // entrie div incl everthing
  914. viewBox : "", // view diw
  915. headerTable : "",
  916. headerBox : "ui-state-default",
  917. rowTable : "",
  918. rowBox : "ui-widget-content",
  919. stripedTable : "ui-jqgrid-table-striped",
  920. footerTable : "",
  921. footerBox : "ui-widget-content",
  922. headerDiv : "ui-state-default",
  923. gridtitleBox : "ui-widget-header ui-corner-top ui-helper-clearfix",
  924. customtoolbarBox : "ui-state-default",
  925. //overlayBox: "ui-widget-overlay",
  926. loadingBox : "ui-state-default ui-state-active",
  927. rownumBox : "ui-state-default",
  928. scrollBox : "ui-widget-content",
  929. multiBox : "",
  930. pagerBox : "ui-state-default ui-corner-bottom",
  931. pagerTable : "",
  932. toppagerBox : "ui-state-default",
  933. pgInput : "ui-corner-all",
  934. pgSelectBox : "ui-widget-content ui-corner-all",
  935. pgButtonBox : "ui-corner-all",
  936. icon_first : "ui-icon-seek-first",
  937. icon_prev : "ui-icon-seek-prev",
  938. icon_next: "ui-icon-seek-next",
  939. icon_end: "ui-icon-seek-end",
  940. icon_asc : "ui-icon-triangle-1-n",
  941. icon_desc : "ui-icon-triangle-1-s",
  942. icon_caption_open : "ui-icon-circle-triangle-n",
  943. icon_caption_close : "ui-icon-circle-triangle-s"
  944. },
  945. modal : {
  946. modal : "ui-widget ui-widget-content ui-corner-all ui-dialog",
  947. header : "ui-widget-header ui-corner-all ui-helper-clearfix",
  948. content :"ui-widget-content",
  949. resizable : "ui-resizable-handle ui-resizable-se",
  950. icon_close : "ui-icon-closethick",
  951. icon_resizable : "ui-icon-gripsmall-diagonal-se"
  952. },
  953. celledit : {
  954. inputClass : "ui-widget-content ui-corner-all"
  955. },
  956. inlinedit : {
  957. inputClass : "ui-widget-content ui-corner-all",
  958. icon_edit_nav : "ui-icon-pencil",
  959. icon_add_nav : "ui-icon-plus",
  960. icon_save_nav : "ui-icon-disk",
  961. icon_cancel_nav : "ui-icon-cancel"
  962. },
  963. formedit : {
  964. inputClass : "ui-widget-content ui-corner-all",
  965. icon_prev : "ui-icon-triangle-1-w",
  966. icon_next : "ui-icon-triangle-1-e",
  967. icon_save : "ui-icon-disk",
  968. icon_close : "ui-icon-close",
  969. icon_del : "ui-icon-scissors",
  970. icon_cancel : "ui-icon-cancel"
  971. },
  972. navigator : {
  973. icon_edit_nav : "ui-icon-pencil",
  974. icon_add_nav : "ui-icon-plus",
  975. icon_del_nav : "ui-icon-trash",
  976. icon_search_nav : "ui-icon-search",
  977. icon_refresh_nav : "ui-icon-refresh",
  978. icon_view_nav : "ui-icon-document",
  979. icon_newbutton_nav : "ui-icon-newwin"
  980. },
  981. grouping : {
  982. icon_plus : 'ui-icon-circlesmall-plus',
  983. icon_minus : 'ui-icon-circlesmall-minus'
  984. },
  985. filter : {
  986. table_widget : 'ui-widget ui-widget-content',
  987. srSelect : 'ui-widget-content ui-corner-all',
  988. srInput : 'ui-widget-content ui-corner-all',
  989. menu_widget : 'ui-widget ui-widget-content ui-corner-all',
  990. icon_search : 'ui-icon-search',
  991. icon_reset : 'ui-icon-arrowreturnthick-1-w',
  992. icon_query :'ui-icon-comment'
  993. },
  994. subgrid : {
  995. icon_plus : 'ui-icon-plus',
  996. icon_minus : 'ui-icon-minus',
  997. icon_open : 'ui-icon-carat-1-sw'
  998. },
  999. treegrid : {
  1000. icon_plus : 'ui-icon-triangle-1-',
  1001. icon_minus : 'ui-icon-triangle-1-s',
  1002. icon_leaf : 'ui-icon-radio-off'
  1003. },
  1004. fmatter : {
  1005. icon_edit : "ui-icon-pencil",
  1006. icon_add : "ui-icon-plus",
  1007. icon_save : "ui-icon-disk",
  1008. icon_cancel : "ui-icon-cancel",
  1009. icon_del : "ui-icon-trash"
  1010. },
  1011. colmenu : {
  1012. menu_widget : 'ui-widget ui-widget-content ui-corner-all',
  1013. input_checkbox : "ui-widget ui-widget-content",
  1014. filter_select: "ui-widget-content ui-corner-all",
  1015. filter_input : "ui-widget-content ui-corner-all",
  1016. icon_menu : "ui-icon-comment",
  1017. icon_sort_asc : "ui-icon-arrow-1-n",
  1018. icon_sort_desc : "ui-icon-arrow-1-s",
  1019. icon_columns : "ui-icon-extlink",
  1020. icon_filter : "ui-icon-calculator",
  1021. icon_group : "ui-icon-grip-solid-horizontal",
  1022. icon_freeze : "ui-icon-grip-solid-vertical",
  1023. icon_move: "ui-icon-arrow-4"
  1024. }
  1025. },
  1026. Bootstrap : {
  1027. common : {
  1028. disabled: "ui-disabled",
  1029. highlight : "success",
  1030. hover : "active",
  1031. cornerall: "",
  1032. cornertop: "",
  1033. cornerbottom : "",
  1034. hidden : "",
  1035. icon_base : "glyphicon",
  1036. overlay: "ui-overlay",
  1037. active : "active",
  1038. error : "bg-danger",
  1039. button : "btn btn-default",
  1040. content : ""
  1041. },
  1042. base : {
  1043. entrieBox : "",
  1044. viewBox : "table-responsive",
  1045. headerTable : "table table-bordered",
  1046. headerBox : "",
  1047. rowTable : "table table-bordered",
  1048. rowBox : "",
  1049. stripedTable : "table-striped",
  1050. footerTable : "table table-bordered",
  1051. footerBox : "",
  1052. headerDiv : "",
  1053. gridtitleBox : "",
  1054. customtoolbarBox : "",
  1055. //overlayBox: "ui-overlay",
  1056. loadingBox : "row",
  1057. rownumBox : "active",
  1058. scrollBox : "",
  1059. multiBox : "checkbox",
  1060. pagerBox : "",
  1061. pagerTable : "table",
  1062. toppagerBox : "",
  1063. pgInput : "form-control",
  1064. pgSelectBox : "form-control",
  1065. pgButtonBox : "",
  1066. icon_first : "glyphicon-step-backward",
  1067. icon_prev : "glyphicon-backward",
  1068. icon_next: "glyphicon-forward",
  1069. icon_end: "glyphicon-step-forward",
  1070. icon_asc : "glyphicon-triangle-top",
  1071. icon_desc : "glyphicon-triangle-bottom",
  1072. icon_caption_open : "glyphicon-circle-arrow-up",
  1073. icon_caption_close : "glyphicon-circle-arrow-down"
  1074. },
  1075. modal : {
  1076. modal : "modal-content",
  1077. header : "modal-header",
  1078. title : "modal-title",
  1079. content :"modal-body",
  1080. resizable : "ui-resizable-handle ui-resizable-se",
  1081. icon_close : "glyphicon-remove-circle",
  1082. icon_resizable : "glyphicon-import"
  1083. },
  1084. celledit : {
  1085. inputClass : 'form-control'
  1086. },
  1087. inlinedit : {
  1088. inputClass : 'form-control',
  1089. icon_edit_nav : "glyphicon-edit",
  1090. icon_add_nav : "glyphicon-plus",
  1091. icon_save_nav : "glyphicon-save",
  1092. icon_cancel_nav : "glyphicon-remove-circle"
  1093. },
  1094. formedit : {
  1095. inputClass : "form-control",
  1096. icon_prev : "glyphicon-step-backward",
  1097. icon_next : "glyphicon-step-forward",
  1098. icon_save : "glyphicon-save",
  1099. icon_close : "glyphicon-remove-circle",
  1100. icon_del : "glyphicon-trash",
  1101. icon_cancel : "glyphicon-remove-circle"
  1102. },
  1103. navigator : {
  1104. icon_edit_nav : "glyphicon-edit",
  1105. icon_add_nav : "glyphicon-plus",
  1106. icon_del_nav : "glyphicon-trash",
  1107. icon_search_nav : "glyphicon-search",
  1108. icon_refresh_nav : "glyphicon-refresh",
  1109. icon_view_nav : "glyphicon-info-sign",
  1110. icon_newbutton_nav : "glyphicon-new-window"
  1111. },
  1112. grouping : {
  1113. icon_plus : 'glyphicon-triangle-right',
  1114. icon_minus : 'glyphicon-triangle-bottom'
  1115. },
  1116. filter : {
  1117. table_widget : 'table table-condensed',
  1118. srSelect : 'form-control',
  1119. srInput : 'form-control',
  1120. menu_widget : '',
  1121. icon_search : 'glyphicon-search',
  1122. icon_reset : 'glyphicon-refresh',
  1123. icon_query :'glyphicon-comment'
  1124. },
  1125. subgrid : {
  1126. icon_plus : 'glyphicon-triangle-right',
  1127. icon_minus : 'glyphicon-triangle-bottom',
  1128. icon_open : 'glyphicon-indent-left'
  1129. },
  1130. treegrid : {
  1131. icon_plus : 'glyphicon-triangle-right',
  1132. icon_minus : 'glyphicon-triangle-bottom',
  1133. icon_leaf : 'glyphicon-unchecked'
  1134. },
  1135. fmatter : {
  1136. icon_edit : "glyphicon-edit",
  1137. icon_add : "glyphicon-plus",
  1138. icon_save : "glyphicon-save",
  1139. icon_cancel : "glyphicon-remove-circle",
  1140. icon_del : "glyphicon-trash"
  1141. },
  1142. colmenu : {
  1143. menu_widget : '',
  1144. input_checkbox : "",
  1145. filter_select: "form-control",
  1146. filter_input : "form-control",
  1147. icon_menu : "glyphicon-menu-hamburger",
  1148. icon_sort_asc : "glyphicon-sort-by-alphabet",
  1149. icon_sort_desc : "glyphicon-sort-by-alphabet-alt",
  1150. icon_columns : "glyphicon-list-alt",
  1151. icon_filter : "glyphicon-filter",
  1152. icon_group : "glyphicon-align-left",
  1153. icon_freeze : "glyphicon-object-align-horizontal",
  1154. icon_move: "glyphicon-move"
  1155. }
  1156. }
  1157. }
  1158. });
  1159. $.fn.jqGrid = function( pin ) {
  1160. if (typeof pin === 'string') {
  1161. var fn = $.jgrid.getMethod(pin);
  1162. if (!fn) {
  1163. throw ("jqGrid - No such method: " + pin);
  1164. }
  1165. var args = $.makeArray(arguments).slice(1);
  1166. return fn.apply(this,args);
  1167. }
  1168. return this.each( function() {
  1169. if(this.grid) {return;}
  1170. var localData;
  1171. if (pin != null && pin.data !== undefined) {
  1172. localData = pin.data;
  1173. pin.data = [];
  1174. }
  1175. var p = $.extend(true,{
  1176. url: "",
  1177. height: 150,
  1178. page: 1,
  1179. rowNum: 20,
  1180. rowTotal : null,
  1181. records: 0,
  1182. pager: "",
  1183. pgbuttons: true,
  1184. pginput: true,
  1185. colModel: [],
  1186. rowList: [],
  1187. colNames: [],
  1188. sortorder: "asc",
  1189. sortname: "",
  1190. datatype: "xml",
  1191. mtype: "GET",
  1192. altRows: false,
  1193. selarrrow: [],
  1194. savedRow: [],
  1195. shrinkToFit: true,
  1196. xmlReader: {},
  1197. jsonReader: {},
  1198. subGrid: false,
  1199. subGridModel :[],
  1200. reccount: 0,
  1201. lastpage: 0,
  1202. lastsort: 0,
  1203. selrow: null,
  1204. beforeSelectRow: null,
  1205. onSelectRow: null,
  1206. onSortCol: null,
  1207. ondblClickRow: null,
  1208. onRightClickRow: null,
  1209. onPaging: null,
  1210. onSelectAll: null,
  1211. onInitGrid : null,
  1212. loadComplete: null,
  1213. gridComplete: null,
  1214. loadError: null,
  1215. loadBeforeSend: null,
  1216. afterInsertRow: null,
  1217. beforeRequest: null,
  1218. beforeProcessing : null,
  1219. onHeaderClick: null,
  1220. viewrecords: false,
  1221. loadonce: false,
  1222. multiselect: false,
  1223. multikey: false,
  1224. multiboxonly : false,
  1225. multimail : false,
  1226. multiselectWidth: 30,
  1227. editurl: null,
  1228. search: false,
  1229. caption: "",
  1230. hidegrid: true,
  1231. hiddengrid: false,
  1232. postData: {},
  1233. userData: {},
  1234. treeGrid : false,
  1235. treeGridModel : 'nested',
  1236. treeReader : {},
  1237. treeANode : -1,
  1238. ExpandColumn: null,
  1239. tree_root_level : 0,
  1240. prmNames: {
  1241. page:"page",
  1242. rows:"rows",
  1243. sort: "sidx",
  1244. order: "sord",
  1245. search:"_search",
  1246. nd:"nd",
  1247. id:"id",
  1248. oper:"oper",
  1249. editoper:"edit",
  1250. addoper:"add",
  1251. deloper:"del",
  1252. subgridid:"id",
  1253. npage: null,
  1254. totalrows:"totalrows"
  1255. },
  1256. forceFit : false,
  1257. gridstate : "visible",
  1258. cellEdit: false,
  1259. cellsubmit: "remote",
  1260. nv:0,
  1261. loadui: "enable",
  1262. toolbar: [false,""],
  1263. scroll: false,
  1264. deselectAfterSort : true,
  1265. scrollrows : false,
  1266. autowidth: false,
  1267. scrollOffset : 18,
  1268. cellLayout: 5,
  1269. subGridWidth: 20,
  1270. gridview: true,
  1271. rownumWidth: 35,
  1272. rownumbers : false,
  1273. pagerpos: 'center',
  1274. recordpos: 'right',
  1275. footerrow : false,
  1276. userDataOnFooter : false,
  1277. hoverrows : true,
  1278. viewsortcols : [false,'vertical',true],
  1279. resizeclass : '',
  1280. autoencode : false,
  1281. remapColumns : [],
  1282. ajaxGridOptions :{},
  1283. direction : "ltr",
  1284. toppager: false,
  1285. headertitles: false,
  1286. scrollTimeout: 40,
  1287. data : [],
  1288. _index : {},
  1289. grouping : false,
  1290. groupingView : {
  1291. groupField:[],
  1292. groupOrder:[],
  1293. groupText:[],
  1294. groupColumnShow:[],
  1295. groupSummary:[],
  1296. showSummaryOnHide: false,
  1297. sortitems:[],
  1298. sortnames:[],
  1299. summary:[],
  1300. summaryval:[],
  1301. plusicon: '',
  1302. minusicon: '',
  1303. displayField: [],
  1304. groupSummaryPos:[],
  1305. formatDisplayField : [],
  1306. _locgr : false
  1307. },
  1308. ignoreCase : true,
  1309. cmTemplate : {},
  1310. idPrefix : "",
  1311. multiSort : false,
  1312. minColWidth : 33,
  1313. scrollPopUp : false,
  1314. scrollTopOffset: 0, // pixel
  1315. scrollLeftOffset : "100%", //percent
  1316. scrollMaxBuffer : 0,
  1317. storeNavOptions: false,
  1318. regional : "en",
  1319. styleUI : "jQueryUI",
  1320. responsive : false,
  1321. restoreCellonFail : true,
  1322. colFilters : {},
  1323. colMenu : false
  1324. }, $.jgrid.defaults , pin );
  1325. if (localData !== undefined) {
  1326. p.data = localData;
  1327. pin.data = localData;
  1328. }
  1329. var ts= this, grid={
  1330. headers:[],
  1331. cols:[],
  1332. footers: [],
  1333. dragStart: function(i,x,y) {
  1334. var gridLeftPos = $(this.bDiv).offset().left;
  1335. this.resizing = { idx: i, startX: x.pageX, sOL : x.pageX - gridLeftPos };
  1336. this.hDiv.style.cursor = "col-resize";
  1337. this.curGbox = $("#rs_m"+$.jgrid.jqID(p.id),"#gbox_"+$.jgrid.jqID(p.id));
  1338. this.curGbox.css({display:"block",left:x.pageX-gridLeftPos,top:y[1],height:y[2]});
  1339. $(ts).triggerHandler("jqGridResizeStart", [x, i]);
  1340. if($.isFunction(p.resizeStart)) { p.resizeStart.call(ts,x,i); }
  1341. document.onselectstart=function(){return false;};
  1342. },
  1343. dragMove: function(x) {
  1344. if(this.resizing) {
  1345. var diff = x.pageX-this.resizing.startX,
  1346. h = this.headers[this.resizing.idx],
  1347. newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn;
  1348. if(newWidth > 33) {
  1349. this.curGbox.css({left:this.resizing.sOL+diff});
  1350. if(p.forceFit===true ){
  1351. hn = this.headers[this.resizing.idx+p.nv];
  1352. nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff;
  1353. if(nWn > p.minColWidth ) {
  1354. h.newWidth = newWidth;
  1355. hn.newWidth = nWn;
  1356. }
  1357. } else {
  1358. this.newWidth = p.direction === "ltr" ? p.tblwidth+diff : p.tblwidth-diff;
  1359. h.newWidth = newWidth;
  1360. }
  1361. }
  1362. }
  1363. },
  1364. dragEnd: function( events ) {
  1365. this.hDiv.style.cursor = "default";
  1366. if(this.resizing) {
  1367. var idx = this.resizing.idx,
  1368. nw = this.headers[idx].newWidth || this.headers[idx].width;
  1369. nw = parseInt(nw,10);
  1370. this.resizing = false;
  1371. $("#rs_m"+$.jgrid.jqID(p.id)).css("display","none");
  1372. p.colModel[idx].width = nw;
  1373. this.headers[idx].width = nw;
  1374. this.headers[idx].el.style.width = nw + "px";
  1375. this.cols[idx].style.width = nw+"px";
  1376. if(this.footers.length>0) {this.footers[idx].style.width = nw+"px";}
  1377. if(p.forceFit===true){
  1378. nw = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width;
  1379. this.headers[idx+p.nv].width = nw;
  1380. this.headers[idx+p.nv].el.style.width = nw + "px";
  1381. this.cols[idx+p.nv].style.width = nw+"px";
  1382. if(this.footers.length>0) {this.footers[idx+p.nv].style.width = nw+"px";}
  1383. p.colModel[idx+p.nv].width = nw;
  1384. } else {
  1385. p.tblwidth = this.newWidth || p.tblwidth;
  1386. $('table:first',this.bDiv).css("width",p.tblwidth+"px");
  1387. $('table:first',this.hDiv).css("width",p.tblwidth+"px");
  1388. this.hDiv.scrollLeft = this.bDiv.scrollLeft;
  1389. if(p.footerrow) {
  1390. $('table:first',this.sDiv).css("width",p.tblwidth+"px");
  1391. this.sDiv.scrollLeft = this.bDiv.scrollLeft;
  1392. }
  1393. }
  1394. if(events) {
  1395. $(ts).triggerHandler("jqGridResizeStop", [nw, idx]);
  1396. if($.isFunction(p.resizeStop)) { p.resizeStop.call(ts,nw,idx); }
  1397. }
  1398. }
  1399. this.curGbox = null;
  1400. document.onselectstart=function(){return true;};
  1401. },
  1402. populateVisible: function() {
  1403. if (grid.timer) { clearTimeout(grid.timer); }
  1404. grid.timer = null;
  1405. var dh = $(grid.bDiv).height();
  1406. if (!dh) { return; }
  1407. var table = $("table:first", grid.bDiv);
  1408. var rows, rh;
  1409. if(table[0].rows.length) {
  1410. try {
  1411. rows = table[0].rows[1];
  1412. rh = rows ? $(rows).outerHeight() || grid.prevRowHeight : grid.prevRowHeight;
  1413. } catch (pv) {
  1414. rh = grid.prevRowHeight;
  1415. }
  1416. }
  1417. if (!rh) { return; }
  1418. grid.prevRowHeight = rh;
  1419. var rn = p.rowNum;
  1420. var scrollTop = grid.scrollTop = grid.bDiv.scrollTop;
  1421. var ttop = Math.round(table.position().top) - scrollTop;
  1422. var tbot = ttop + table.height();
  1423. var div = rh * rn;
  1424. var page, npage, empty;
  1425. if ( tbot < dh && ttop <= 0 &&
  1426. (p.lastpage===undefined||(parseInt((tbot + scrollTop + div - 1) / div,10) || 0) <= p.lastpage))
  1427. {
  1428. npage = parseInt((dh - tbot + div - 1) / div,10) || 1;
  1429. if (tbot >= 0 || npage < 2 || p.scroll === true) {
  1430. page = ( Math.round((tbot + scrollTop) / div) || 0) + 1;
  1431. ttop = -1;
  1432. } else {
  1433. ttop = 1;
  1434. }
  1435. }
  1436. if (ttop > 0) {
  1437. page = ( parseInt(scrollTop / div,10) || 0 ) + 1;
  1438. npage = (parseInt((scrollTop + dh) / div,10) || 0) + 2 - page;
  1439. empty = true;
  1440. }
  1441. if (npage) {
  1442. if (p.lastpage && (page > p.lastpage || p.lastpage===1 || (page === p.page && page===p.lastpage)) ) {
  1443. return;
  1444. }
  1445. if (grid.hDiv.loading) {
  1446. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  1447. } else {
  1448. p.page = page;
  1449. if( p.scrollMaxBuffer > 0 ) {
  1450. if( rn > 0 && p.scrollMaxBuffer < rn ) {
  1451. p.scrollMaxBuffer = rn + 1;
  1452. }
  1453. if(p.reccount > (p.scrollMaxBuffer - (rn > 0 ? rn : 0) ) ) {
  1454. empty = true;
  1455. }
  1456. }
  1457. if (empty) {
  1458. grid.selectionPreserver(table[0]);
  1459. grid.emptyRows.call(table[0], false, false);
  1460. }
  1461. grid.populate(npage);
  1462. }
  1463. if(p.scrollPopUp && p.lastpage != null) {
  1464. $("#scroll_g"+p.id).show().html( $.jgrid.template( $.jgrid.getRegional(ts, "defaults.pgtext", p.pgtext) , p.page, p.lastpage)).css({ "top": p.scrollTopOffset+scrollTop*((parseInt(p.height,10) - 45)/ (parseInt(rh,10)*parseInt(p.records,10))) +"px", "left" : p.scrollLeftOffset});
  1465. $(this).mouseout(function(){
  1466. $("#scroll_g"+p.id).hide();
  1467. });
  1468. }
  1469. }
  1470. },
  1471. scrollGrid: function( e ) {
  1472. if(p.scroll) {
  1473. var scrollTop = grid.bDiv.scrollTop;
  1474. if(grid.scrollTop === undefined) { grid.scrollTop = 0; }
  1475. if (scrollTop !== grid.scrollTop) {
  1476. grid.scrollTop = scrollTop;
  1477. if (grid.timer) { clearTimeout(grid.timer); }
  1478. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  1479. }
  1480. }
  1481. grid.hDiv.scrollLeft = grid.bDiv.scrollLeft;
  1482. if(p.footerrow) {
  1483. grid.sDiv.scrollLeft = grid.bDiv.scrollLeft;
  1484. }
  1485. if(p.frozenColumns) {
  1486. $(grid.fbDiv).scrollTop( grid.bDiv.scrollTop );
  1487. }
  1488. if( e ) { e.stopPropagation(); }
  1489. },
  1490. selectionPreserver : function(ts) {
  1491. var p = ts.p,
  1492. sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null,
  1493. left = ts.grid.bDiv.scrollLeft,
  1494. restoreSelection = function() {
  1495. var i;
  1496. p.selrow = null;
  1497. p.selarrrow = [];
  1498. if(p.multiselect && sra && sra.length>0) {
  1499. for(i=0;i<sra.length;i++){
  1500. if (sra[i] !== sr) {
  1501. $(ts).jqGrid("setSelection",sra[i],false, null);
  1502. }
  1503. }
  1504. }
  1505. if (sr) {
  1506. $(ts).jqGrid("setSelection",sr,false,null);
  1507. }
  1508. ts.grid.bDiv.scrollLeft = left;
  1509. $(ts).off('.selectionPreserver', restoreSelection);
  1510. };
  1511. $(ts).on('jqGridGridComplete.selectionPreserver', restoreSelection);
  1512. }
  1513. };
  1514. if(this.tagName.toUpperCase() !== 'TABLE' || this.id == null) {
  1515. alert("Element is not a table or has no id!");
  1516. return;
  1517. }
  1518. if(document.documentMode !== undefined ) { // IE only
  1519. if(document.documentMode <= 5) {
  1520. alert("Grid can not be used in this ('quirks') mode!");
  1521. return;
  1522. }
  1523. }
  1524. var i =0, lr, lk, dir;
  1525. for( lk in $.jgrid.regional ){
  1526. if($.jgrid.regional.hasOwnProperty(lk)) {
  1527. if(i===0) { lr = lk; }
  1528. i++;
  1529. }
  1530. }
  1531. if(i === 1 && lr !== p.regional) {
  1532. p.regional = lr;
  1533. }
  1534. $(this).empty().attr("tabindex","0");
  1535. this.p = p ;
  1536. this.p.useProp = !!$.fn.prop;
  1537. if(this.p.colNames.length === 0) {
  1538. for (i=0;i<this.p.colModel.length;i++){
  1539. this.p.colNames[i] = this.p.colModel[i].label || this.p.colModel[i].name;
  1540. }
  1541. }
  1542. if( this.p.colNames.length !== this.p.colModel.length ) {
  1543. alert($.jgrid.getRegional(this,"errors.model"));
  1544. return;
  1545. }
  1546. var getstyle = $.jgrid.getMethod("getStyleUI"),
  1547. stylemodule = ts.p.styleUI + ".common",
  1548. disabled = getstyle(stylemodule,'disabled', true),
  1549. highlight = getstyle(stylemodule,'highlight', true),
  1550. hover = getstyle(stylemodule,'hover', true),
  1551. cornerall = getstyle(stylemodule,'cornerall', true),
  1552. iconbase = getstyle(stylemodule,'icon_base', true),
  1553. colmenustyle = $.jgrid.styleUI[(ts.p.styleUI || 'jQueryUI')].colmenu,
  1554. isMSIE = $.jgrid.msie(),
  1555. gv, sortarr = [], sortord = [], sotmp=[];
  1556. stylemodule = ts.p.styleUI + ".base";
  1557. gv = $("<div "+getstyle(stylemodule, 'viewBox', false, 'ui-jqgrid-view')+" role='grid'></div>");
  1558. ts.p.direction = $.trim(ts.p.direction.toLowerCase());
  1559. ts.p._ald = false;
  1560. if($.inArray(ts.p.direction,["ltr","rtl"]) === -1) { ts.p.direction = "ltr"; }
  1561. dir = ts.p.direction;
  1562. $(gv).insertBefore(this);
  1563. $(this).appendTo(gv);
  1564. var eg = $("<div "+ getstyle(stylemodule, 'entrieBox', false, 'ui-jqgrid') +"></div>");
  1565. $(eg).attr({"id" : "gbox_"+this.id,"dir":dir}).insertBefore(gv);
  1566. $(gv).attr("id","gview_"+this.id).appendTo(eg);
  1567. $("<div "+getstyle(ts.p.styleUI+'.common','overlay', false, 'jqgrid-overlay')+ " id='lui_"+this.id+"'></div>").insertBefore(gv);
  1568. $("<div "+getstyle(stylemodule,'loadingBox', false, 'loading')+" id='load_"+this.id+"'>"+$.jgrid.getRegional(ts, "defaults.loadtext", this.p.loadtext)+"</div>").insertBefore(gv);
  1569. $(this).attr({role:"presentation","aria-multiselectable":!!this.p.multiselect,"aria-labelledby":"gbox_"+this.id});
  1570. var sortkeys = ["shiftKey","altKey","ctrlKey"],
  1571. intNum = function(val,defval) {
  1572. val = parseInt(val,10);
  1573. if (isNaN(val)) { return defval || 0;}
  1574. return val;
  1575. },
  1576. formatCol = function (pos, rowInd, tv, rawObject, rowId, rdata){
  1577. var cm = ts.p.colModel[pos], cellAttrFunc,
  1578. ral = cm.align, result="style=\"", clas = cm.classes, nm = cm.name, celp, acp=[];
  1579. if(ral) { result += "text-align:"+ral+";"; }
  1580. if(cm.hidden===true) { result += "display:none;"; }
  1581. if(rowInd===0) {
  1582. result += "width: "+grid.headers[pos].width+"px;";
  1583. } else if ($.isFunction(cm.cellattr) || (typeof cm.cellattr === "string" && $.jgrid.cellattr != null && $.isFunction($.jgrid.cellattr[cm.cellattr]))) {
  1584. cellAttrFunc = $.isFunction(cm.cellattr) ? cm.cellattr : $.jgrid.cellattr[cm.cellattr];
  1585. celp = cellAttrFunc.call(ts, rowId, tv, rawObject, cm, rdata);
  1586. if(celp && typeof celp === "string") {
  1587. celp = celp.replace(/style/i,'style').replace(/title/i,'title');
  1588. if(celp.indexOf('title') > -1) { cm.title=false;}
  1589. if(celp.indexOf('class') > -1) { clas = undefined;}
  1590. acp = celp.replace(/\-style/g,'-sti').split(/style/);
  1591. if(acp.length === 2 ) {
  1592. acp[1] = $.trim(acp[1].replace(/\-sti/g,'-style').replace("=",""));
  1593. if(acp[1].indexOf("'") === 0 || acp[1].indexOf('"') === 0) {
  1594. acp[1] = acp[1].substring(1);
  1595. }
  1596. result += acp[1].replace(/'/gi,'"');
  1597. } else {
  1598. result += "\"";
  1599. }
  1600. }
  1601. }
  1602. if(!acp.length) { acp[0] = ""; result += "\"";}
  1603. result += (clas !== undefined ? (" class=\""+clas+"\"") :"") + ((cm.title && tv) ? (" title=\""+$.jgrid.stripHtml(tv)+"\"") :"");
  1604. result += " aria-describedby=\""+ts.p.id+"_"+nm+"\"";
  1605. return result + acp[0];
  1606. },
  1607. cellVal = function (val) {
  1608. return val == null || val === "" ? "&#160;" : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : String(val));
  1609. },
  1610. formatter = function (rowId, cellval , colpos, rwdat, _act){
  1611. var cm = ts.p.colModel[colpos],v;
  1612. if(cm.formatter !== undefined) {
  1613. rowId = String(ts.p.idPrefix) !== "" ? $.jgrid.stripPref(ts.p.idPrefix, rowId) : rowId;
  1614. var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos, styleUI: ts.p.styleUI };
  1615. if($.isFunction( cm.formatter ) ) {
  1616. v = cm.formatter.call(ts,cellval,opts,rwdat,_act);
  1617. } else if($.fmatter){
  1618. v = $.fn.fmatter.call(ts,cm.formatter,cellval,opts,rwdat,_act);
  1619. } else {
  1620. v = cellVal(cellval);
  1621. }
  1622. } else {
  1623. v = cellVal(cellval);
  1624. }
  1625. return v;
  1626. },
  1627. addCell = function(rowId,cell,pos,irow, srvr, rdata) {
  1628. var v,prp;
  1629. v = formatter(rowId,cell,pos,srvr,'add');
  1630. prp = formatCol( pos,irow, v, srvr, rowId, rdata);
  1631. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  1632. },
  1633. addMulti = function(rowid, pos, irow, checked, uiclass){
  1634. var v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+ts.p.id+"_"+rowid+"\" "+uiclass+" name=\"jqg_"+ts.p.id+"_"+rowid+"\"" + (checked ? "checked=\"checked\"" : "")+"/>",
  1635. prp = formatCol( pos,irow,'',null, rowid, true);
  1636. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  1637. },
  1638. addRowNum = function (pos, irow, pG, rN, uiclass ) {
  1639. var v = (parseInt(pG,10)-1)*parseInt(rN,10)+1+irow,
  1640. prp = formatCol( pos,irow,v, null, irow, true);
  1641. return "<td role=\"gridcell\" "+uiclass+" "+prp+">"+v+"</td>";
  1642. },
  1643. reader = function (datatype) {
  1644. var field, f=[], j=0, i;
  1645. for(i =0; i<ts.p.colModel.length; i++){
  1646. field = ts.p.colModel[i];
  1647. if (field.name !== 'cb' && field.name !=='subgrid' && field.name !=='rn') {
  1648. f[j]= datatype === "local" ?
  1649. field.name :
  1650. ( (datatype==="xml" || datatype === "xmlstring") ? field.xmlmap || field.name : field.jsonmap || field.name );
  1651. if(ts.p.keyName !== false && field.key===true ) {
  1652. ts.p.keyName = f[j];
  1653. ts.p.keyIndex = j;
  1654. }
  1655. j++;
  1656. }
  1657. }
  1658. return f;
  1659. },
  1660. orderedCols = function (offset) {
  1661. var order = ts.p.remapColumns;
  1662. if (!order || !order.length) {
  1663. order = $.map(ts.p.colModel, function(v,i) { return i; });
  1664. }
  1665. if (offset) {
  1666. order = $.map(order, function(v) { return v<offset?null:v-offset; });
  1667. }
  1668. return order;
  1669. },
  1670. emptyRows = function (scroll, locdata) {
  1671. var firstrow;
  1672. if (this.p.deepempty) {
  1673. $(this.rows).slice(1).remove();
  1674. } else {
  1675. firstrow = this.rows.length > 0 ? this.rows[0] : null;
  1676. $(this.firstChild).empty().append(firstrow);
  1677. }
  1678. if (scroll && this.p.scroll) {
  1679. $(this.grid.bDiv.firstChild).css({height: "auto"});
  1680. $(this.grid.bDiv.firstChild.firstChild).css({height: "0px", display: "none"});
  1681. if (this.grid.bDiv.scrollTop !== 0) {
  1682. this.grid.bDiv.scrollTop = 0;
  1683. }
  1684. }
  1685. if(locdata === true && this.p.treeGrid && !this.p.loadonce ) {
  1686. this.p.data = []; this.p._index = {};
  1687. }
  1688. },
  1689. normalizeData = function() {
  1690. var p = ts.p, data = p.data, dataLength = data.length, i, j, cur, idn, idr, ccur, v, rd,
  1691. localReader = p.localReader,
  1692. colModel = p.colModel,
  1693. cellName = localReader.cell,
  1694. iOffset = (p.multiselect === true ? 1 : 0) + (p.subGrid === true ? 1 : 0) + (p.rownumbers === true ? 1 : 0),
  1695. br = p.scroll ? $.jgrid.randId() : 1,
  1696. arrayReader, objectReader, rowReader;
  1697. if (p.datatype !== "local" || localReader.repeatitems !== true) {
  1698. return; // nothing to do
  1699. }
  1700. arrayReader = orderedCols(iOffset);
  1701. objectReader = reader("local");
  1702. // read ALL input items and convert items to be read by
  1703. // $.jgrid.getAccessor with column name as the second parameter
  1704. idn = p.keyName === false ?
  1705. ($.isFunction(localReader.id) ? localReader.id.call(ts, data) : localReader.id) :
  1706. p.keyName;
  1707. for (i = 0; i < dataLength; i++) {
  1708. cur = data[i];
  1709. // read id in the same way like addJSONData do
  1710. // probably it would be better to start with "if (cellName) {...}"
  1711. // but the goal of the current implementation was just have THE SAME
  1712. // id values like in addJSONData ...
  1713. idr = $.jgrid.getAccessor(cur, idn);
  1714. if (idr === undefined) {
  1715. if (typeof idn === "number" && colModel[idn + iOffset] != null) {
  1716. // reread id by name
  1717. idr = $.jgrid.getAccessor(cur, colModel[idn + iOffset].name);
  1718. }
  1719. if (idr === undefined) {
  1720. idr = br + i;
  1721. if (cellName) {
  1722. ccur = $.jgrid.getAccessor(cur, cellName) || cur;
  1723. idr = ccur != null && ccur[idn] !== undefined ? ccur[idn] : idr;
  1724. ccur = null;
  1725. }
  1726. }
  1727. }
  1728. rd = { };
  1729. rd[localReader.id] = idr;
  1730. if (cellName) {
  1731. cur = $.jgrid.getAccessor(cur, cellName) || cur;
  1732. }
  1733. rowReader = $.isArray(cur) ? arrayReader : objectReader;
  1734. for (j = 0; j < rowReader.length; j++) {
  1735. v = $.jgrid.getAccessor(cur, rowReader[j]);
  1736. rd[colModel[j + iOffset].name] = v;
  1737. }
  1738. data[i] = rd;
  1739. //$.extend(true, data[i], rd);
  1740. }
  1741. },
  1742. refreshIndex = function() {
  1743. var datalen = ts.p.data.length, idname, i, val;
  1744. if(ts.p.keyName === false || ts.p.loadonce === true) {
  1745. idname = ts.p.localReader.id;
  1746. } else {
  1747. idname = ts.p.keyName;
  1748. }
  1749. ts.p._index = [];
  1750. for(i =0;i < datalen; i++) {
  1751. val = $.jgrid.getAccessor(ts.p.data[i],idname);
  1752. if (val === undefined) { val=String(i+1); }
  1753. ts.p._index[val] = i;
  1754. }
  1755. },
  1756. constructTr = function(id, hide, classes, rd, cur ) {
  1757. var tabindex = '-1', restAttr = '', attrName, style = hide ? 'display:none;' : '',
  1758. //classes = getstyle(stylemodule, 'rowBox', true) + ts.p.direction + (altClass ? ' ' + altClass : '') + (selected ? ' ' + highlight : ''),
  1759. rowAttrObj = $(ts).triggerHandler("jqGridRowAttr", [rd, cur, id]);
  1760. if( typeof rowAttrObj !== "object" ) {
  1761. rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur, id) :
  1762. (typeof ts.p.rowattr === "string" && $.jgrid.rowattr != null && $.isFunction($.jgrid.rowattr[ts.p.rowattr]) ?
  1763. $.jgrid.rowattr[ts.p.rowattr].call(ts, rd, cur, id) : {});
  1764. }
  1765. if(!$.isEmptyObject( rowAttrObj )) {
  1766. if (rowAttrObj.hasOwnProperty("id")) {
  1767. id = rowAttrObj.id;
  1768. delete rowAttrObj.id;
  1769. }
  1770. if (rowAttrObj.hasOwnProperty("tabindex")) {
  1771. tabindex = rowAttrObj.tabindex;
  1772. delete rowAttrObj.tabindex;
  1773. }
  1774. if (rowAttrObj.hasOwnProperty("style")) {
  1775. style += rowAttrObj.style;
  1776. delete rowAttrObj.style;
  1777. }
  1778. if (rowAttrObj.hasOwnProperty("class")) {
  1779. classes += ' ' + rowAttrObj['class'];
  1780. delete rowAttrObj['class'];
  1781. }
  1782. // dot't allow to change role attribute
  1783. try { delete rowAttrObj.role; } catch(ra){}
  1784. for (attrName in rowAttrObj) {
  1785. if (rowAttrObj.hasOwnProperty(attrName)) {
  1786. restAttr += ' ' + attrName + '=' + rowAttrObj[attrName];
  1787. }
  1788. }
  1789. }
  1790. return '<tr role="row" id="' + id + '" tabindex="' + tabindex + '" class="' + classes + '"' +
  1791. (style === '' ? '' : ' style="' + style + '"') + restAttr + '>';
  1792. },
  1793. addXmlData = function (xml, rcnt, more, adjust) {
  1794. var startReq = new Date(),
  1795. locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "xmlstring",
  1796. xmlid = "_id_", xmlRd = ts.p.xmlReader,
  1797. frd = ts.p.datatype === "local" ? "local" : "xml";
  1798. if(locdata) {
  1799. ts.p.data = [];
  1800. ts.p._index = {};
  1801. ts.p.localReader.id = xmlid;
  1802. }
  1803. ts.p.reccount = 0;
  1804. if($.isXMLDoc(xml)) {
  1805. if(ts.p.treeANode===-1 && !ts.p.scroll) {
  1806. emptyRows.call(ts, false, true);
  1807. rcnt=1;
  1808. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1809. } else { return; }
  1810. var self= $(ts), i,fpos,ir=0,v,gi=ts.p.multiselect===true?1:0,si=0,addSubGridCell,ni=ts.p.rownumbers===true?1:0,idn, getId,f=[],F,rd ={},
  1811. xmlr,rid, rowData=[], classes = getstyle(stylemodule, 'rowBox', true, 'jqgrow ui-row-'+ ts.p.direction);
  1812. if(ts.p.subGrid===true) {
  1813. si = 1;
  1814. addSubGridCell = $.jgrid.getMethod("addSubGridCell");
  1815. }
  1816. if(!xmlRd.repeatitems) {f = reader(frd);}
  1817. if( ts.p.keyName===false) {
  1818. idn = $.isFunction( xmlRd.id ) ? xmlRd.id.call(ts, xml) : xmlRd.id;
  1819. } else {
  1820. idn = ts.p.keyName;
  1821. }
  1822. if(xmlRd.repeatitems && ts.p.keyName && isNaN(idn)) {
  1823. idn = ts.p.keyIndex;
  1824. }
  1825. if( String(idn).indexOf("[") === -1 ) {
  1826. if (f.length) {
  1827. getId = function( trow, k) {return $(idn,trow).text() || k;};
  1828. } else {
  1829. getId = function( trow, k) {return $(xmlRd.cell,trow).eq(idn).text() || k;};
  1830. }
  1831. }
  1832. else {
  1833. getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};
  1834. }
  1835. ts.p.userData = {};
  1836. ts.p.page = intNum($.jgrid.getXmlData(xml, xmlRd.page), ts.p.page);
  1837. ts.p.lastpage = intNum($.jgrid.getXmlData(xml, xmlRd.total), 1);
  1838. ts.p.records = intNum($.jgrid.getXmlData(xml, xmlRd.records));
  1839. if($.isFunction(xmlRd.userdata)) {
  1840. ts.p.userData = xmlRd.userdata.call(ts, xml) || {};
  1841. } else {
  1842. $.jgrid.getXmlData(xml, xmlRd.userdata, true).each(function() {ts.p.userData[this.getAttribute("name")]= $(this).text();});
  1843. }
  1844. var gxml = $.jgrid.getXmlData( xml, xmlRd.root, true);
  1845. gxml = $.jgrid.getXmlData( gxml, xmlRd.row, true);
  1846. if (!gxml) { gxml = []; }
  1847. var gl = gxml.length, j=0, grpdata=[], rn = parseInt(ts.p.rowNum,10), br=ts.p.scroll?$.jgrid.randId():1,
  1848. tablebody = $(ts).find("tbody:first"),
  1849. hiderow=false, groupingPrepare;
  1850. if(ts.p.grouping) {
  1851. hiderow = ts.p.groupingView.groupCollapse === true;
  1852. groupingPrepare = $.jgrid.getMethod("groupingPrepare");
  1853. }
  1854. if (gl > 0 && ts.p.page <= 0) { ts.p.page = 1; }
  1855. if(gxml && gl){
  1856. if (adjust) { rn *= adjust+1; }
  1857. var afterInsRow = $.isFunction(ts.p.afterInsertRow),
  1858. rnc = ni ? getstyle(stylemodule, 'rownumBox', false, 'jqgrid-rownum') :"",
  1859. mlc = gi ? getstyle(stylemodule, 'multiBox', false, 'cbox'):"";
  1860. while (j<gl) {
  1861. xmlr = gxml[j];
  1862. rid = getId(xmlr,br+j);
  1863. rid = ts.p.idPrefix + rid;
  1864. var iStartTrTag = rowData.length;
  1865. rowData.push("");
  1866. if( ni ) {
  1867. rowData.push( addRowNum(0, j, ts.p.page, ts.p.rowNum, rnc ) );
  1868. }
  1869. if( gi ) {
  1870. rowData.push( addMulti(rid, ni, j, false, mlc) );
  1871. }
  1872. if( si ) {
  1873. rowData.push( addSubGridCell.call(self, gi+ni, j+rcnt) );
  1874. }
  1875. if(xmlRd.repeatitems){
  1876. if (!F) { F=orderedCols(gi+si+ni); }
  1877. var cells = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
  1878. $.each(F, function (k) {
  1879. var cell = cells[this];
  1880. if (!cell) { return false; }
  1881. v = cell.textContent || cell.text;
  1882. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1883. rowData.push( addCell(rid,v,k+gi+si+ni,j+rcnt,xmlr, rd) );
  1884. });
  1885. } else {
  1886. for(i = 0; i < f.length;i++) {
  1887. v = $.jgrid.getXmlData( xmlr, f[i]);
  1888. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1889. rowData.push( addCell(rid, v, i+gi+si+ni, j+rcnt, xmlr, rd) );
  1890. }
  1891. }
  1892. rowData[iStartTrTag] = constructTr(rid, hiderow, classes, rd, xmlr);
  1893. rowData.push("</tr>");
  1894. if(ts.p.grouping) {
  1895. grpdata.push( rowData );
  1896. if(!ts.p.groupingView._locgr) {
  1897. groupingPrepare.call(self , rd, j );
  1898. }
  1899. rowData = [];
  1900. }
  1901. if(locdata || (ts.p.treeGrid === true && !(ts.p._ald)) ) {
  1902. rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid);
  1903. ts.p.data.push(rd);
  1904. ts.p._index[rd[xmlid]] = ts.p.data.length-1;
  1905. }
  1906. if(ts.p.gridview === false ) {
  1907. tablebody.append(rowData.join(''));
  1908. self.triggerHandler("jqGridAfterInsertRow", [rid, rd, xmlr]);
  1909. if(afterInsRow) {ts.p.afterInsertRow.call(ts,rid,rd,xmlr);}
  1910. rowData=[];
  1911. }
  1912. rd={};
  1913. ir++;
  1914. j++;
  1915. if(ir===rn) {break;}
  1916. }
  1917. }
  1918. if(ts.p.gridview === true) {
  1919. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1920. if(ts.p.grouping) {
  1921. if(!locdata) {
  1922. self.jqGrid('groupingRender',grpdata,ts.p.colModel.length, ts.p.page, rn);
  1923. grpdata = null;
  1924. }
  1925. } else if(ts.p.treeGrid === true && fpos > 0) {
  1926. $(ts.rows[fpos]).after(rowData.join(''));
  1927. } else {
  1928. //$("tbody:first",t).append(rowData.join(''));
  1929. tablebody.append(rowData.join(''));
  1930. ts.grid.cols = ts.rows[0].cells; // update cached first row
  1931. }
  1932. }
  1933. ts.p.totaltime = new Date() - startReq;
  1934. rowData =null;
  1935. if(ts.p.subGrid === true ) {
  1936. try {self.jqGrid("addSubGrid",gi+ni);} catch (_){}
  1937. }
  1938. if(ir>0) { if(ts.p.records===0) { ts.p.records=gl;} }
  1939. if( ts.p.treeGrid === true) {
  1940. try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1941. }
  1942. //if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1943. ts.p.reccount=ir;
  1944. ts.p.treeANode = -1;
  1945. if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }
  1946. if(locdata) {
  1947. ts.p.records = gl;
  1948. ts.p.lastpage = Math.ceil(gl/ rn);
  1949. }
  1950. if (!more) { ts.updatepager(false,true); }
  1951. if(locdata) {
  1952. while (ir<gl) {
  1953. xmlr = gxml[ir];
  1954. rid = getId(xmlr,ir+br);
  1955. rid = ts.p.idPrefix + rid;
  1956. if(xmlRd.repeatitems){
  1957. if (!F) { F=orderedCols(gi+si+ni); }
  1958. var cells2 = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
  1959. $.each(F, function (k) {
  1960. var cell = cells2[this];
  1961. if (!cell) { return false; }
  1962. v = cell.textContent || cell.text;
  1963. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1964. });
  1965. } else {
  1966. for(i = 0; i < f.length;i++) {
  1967. v = $.jgrid.getXmlData( xmlr, f[i]);
  1968. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1969. }
  1970. }
  1971. rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid);
  1972. if( ts.p.grouping ) {
  1973. groupingPrepare.call(self, rd, ir );
  1974. }
  1975. ts.p.data.push(rd);
  1976. ts.p._index[rd[xmlid]] = ts.p.data.length-1;
  1977. rd = {};
  1978. ir++;
  1979. }
  1980. if(ts.p.grouping) {
  1981. ts.p.groupingView._locgr = true;
  1982. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  1983. grpdata = null;
  1984. }
  1985. }
  1986. },
  1987. addJSONData = function(data, rcnt, more, adjust) {
  1988. var startReq = new Date();
  1989. if(data) {
  1990. if(ts.p.treeANode === -1 && !ts.p.scroll) {
  1991. emptyRows.call(ts, false, true);
  1992. rcnt=1;
  1993. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1994. } else { return; }
  1995. var dReader, locid = "_id_", frd,
  1996. locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "jsonstring";
  1997. if(locdata) { ts.p.data = []; ts.p._index = {}; ts.p.localReader.id = locid;}
  1998. ts.p.reccount = 0;
  1999. if(ts.p.datatype === "local") {
  2000. dReader = ts.p.localReader;
  2001. frd= 'local';
  2002. } else {
  2003. dReader = ts.p.jsonReader;
  2004. frd='json';
  2005. }
  2006. var self = $(ts), ir=0,v,i,j,f=[],cur,gi=ts.p.multiselect?1:0,si=ts.p.subGrid===true?1:0,addSubGridCell,ni=ts.p.rownumbers===true?1:0,arrayReader=orderedCols(gi+si+ni),objectReader=reader(frd),rowReader,len,drows,idn,rd={}, fpos, idr,rowData=[],
  2007. classes = getstyle(stylemodule, 'rowBox', true, 'jqgrow ui-row-'+ ts.p.direction);
  2008. ts.p.page = intNum($.jgrid.getAccessor(data,dReader.page), ts.p.page);
  2009. ts.p.lastpage = intNum($.jgrid.getAccessor(data,dReader.total), 1);
  2010. ts.p.records = intNum($.jgrid.getAccessor(data,dReader.records));
  2011. ts.p.userData = $.jgrid.getAccessor(data,dReader.userdata) || {};
  2012. if(si) {
  2013. addSubGridCell = $.jgrid.getMethod("addSubGridCell");
  2014. }
  2015. if( ts.p.keyName===false ) {
  2016. idn = $.isFunction(dReader.id) ? dReader.id.call(ts, data) : dReader.id;
  2017. } else {
  2018. idn = ts.p.keyName;
  2019. }
  2020. if(dReader.repeatitems && ts.p.keyName && isNaN(idn)) {
  2021. idn = ts.p.keyIndex;
  2022. }
  2023. drows = $.jgrid.getAccessor(data,dReader.root);
  2024. if (drows == null && $.isArray(data)) { drows = data; }
  2025. if (!drows) { drows = []; }
  2026. len = drows.length; i=0;
  2027. if (len > 0 && ts.p.page <= 0) { ts.p.page = 1; }
  2028. var rn = parseInt(ts.p.rowNum,10),br=ts.p.scroll?$.jgrid.randId():1,selected=false, selr;
  2029. if (adjust) { rn *= adjust+1; }
  2030. if(ts.p.datatype === "local" && !ts.p.deselectAfterSort) {
  2031. selected = true;
  2032. }
  2033. var afterInsRow = $.isFunction(ts.p.afterInsertRow), grpdata=[],hiderow=false, groupingPrepare,
  2034. tablebody = $(ts).find("tbody:first"),
  2035. rnc = ni ? getstyle(stylemodule, 'rownumBox', false, 'jqgrid-rownum') :"",
  2036. mlc = gi ? getstyle(stylemodule, 'multiBox', false, 'cbox'):"";
  2037. if(ts.p.grouping) {
  2038. hiderow = ts.p.groupingView.groupCollapse === true;
  2039. groupingPrepare = $.jgrid.getMethod("groupingPrepare");
  2040. }
  2041. while (i<len) {
  2042. cur = drows[i];
  2043. idr = $.jgrid.getAccessor(cur,idn);
  2044. if(idr === undefined) {
  2045. if (typeof idn === "number" && ts.p.colModel[idn+gi+si+ni] != null) {
  2046. // reread id by name
  2047. idr = $.jgrid.getAccessor(cur,ts.p.colModel[idn+gi+si+ni].name);
  2048. }
  2049. if(idr === undefined) {
  2050. idr = br+i;
  2051. if(f.length===0){
  2052. if(dReader.cell){
  2053. var ccur = $.jgrid.getAccessor(cur,dReader.cell) || cur;
  2054. idr = ccur != null && ccur[idn] !== undefined ? ccur[idn] : idr;
  2055. ccur=null;
  2056. }
  2057. }
  2058. }
  2059. }
  2060. idr = ts.p.idPrefix + idr;
  2061. if( selected) {
  2062. if( ts.p.multiselect) {
  2063. selr = ($.inArray(idr, ts.p.selarrrow) !== -1);
  2064. } else {
  2065. selr = (idr === ts.p.selrow);
  2066. }
  2067. }
  2068. var iStartTrTag = rowData.length;
  2069. rowData.push("");
  2070. if( ni ) {
  2071. rowData.push( addRowNum(0, i, ts.p.page, ts.p.rowNum, rnc ) );
  2072. }
  2073. if( gi ){
  2074. rowData.push( addMulti(idr, ni, i, selr, mlc) );
  2075. }
  2076. if( si ) {
  2077. rowData.push( addSubGridCell.call(self ,gi+ni,i+rcnt) );
  2078. }
  2079. rowReader=objectReader;
  2080. if (dReader.repeatitems) {
  2081. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell) || cur;}
  2082. if ($.isArray(cur)) { rowReader=arrayReader; }
  2083. }
  2084. for (j=0;j<rowReader.length;j++) {
  2085. v = $.jgrid.getAccessor(cur,rowReader[j]);
  2086. rd[ts.p.colModel[j+gi+si+ni].name] = v;
  2087. rowData.push( addCell(idr,v,j+gi+si+ni,i+rcnt,cur, rd) );
  2088. }
  2089. rowData[iStartTrTag] = constructTr(idr, hiderow, (selr ? classes + ' ' + highlight : classes), rd, cur);
  2090. rowData.push( "</tr>" );
  2091. if(ts.p.grouping) {
  2092. grpdata.push( rowData );
  2093. if(!ts.p.groupingView._locgr) {
  2094. groupingPrepare.call(self , rd, i);
  2095. }
  2096. rowData = [];
  2097. }
  2098. if(locdata || (ts.p.treeGrid===true && !(ts.p._ald))) {
  2099. rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr);
  2100. ts.p.data.push(rd);
  2101. ts.p._index[rd[locid]] = ts.p.data.length-1;
  2102. }
  2103. if(ts.p.gridview === false ) {
  2104. tablebody.append(rowData.join(''));
  2105. self.triggerHandler("jqGridAfterInsertRow", [idr, rd, cur]);
  2106. if(afterInsRow) {ts.p.afterInsertRow.call(ts,idr,rd,cur);}
  2107. rowData=[];//ari=0;
  2108. }
  2109. rd={};
  2110. ir++;
  2111. i++;
  2112. if(ir===rn) { break; }
  2113. }
  2114. if(ts.p.gridview === true ) {
  2115. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  2116. if(ts.p.grouping) {
  2117. if(!locdata) {
  2118. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  2119. grpdata = null;
  2120. }
  2121. } else if(ts.p.treeGrid === true && fpos > 0) {
  2122. $(ts.rows[fpos]).after(rowData.join(''));
  2123. } else {
  2124. tablebody.append(rowData.join(''));
  2125. ts.grid.cols = ts.rows[0].cells;
  2126. }
  2127. }
  2128. ts.p.totaltime = new Date() - startReq;
  2129. rowData = null;
  2130. if(ts.p.subGrid === true ) {
  2131. try { self.jqGrid("addSubGrid",gi+ni);} catch (_){}
  2132. }
  2133. if(ir>0) {
  2134. if(ts.p.records===0) { ts.p.records=len; }
  2135. }
  2136. if( ts.p.treeGrid === true) {
  2137. try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  2138. }
  2139. //if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  2140. ts.p.reccount=ir;
  2141. ts.p.treeANode = -1;
  2142. if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }
  2143. if(locdata) {
  2144. ts.p.records = len;
  2145. ts.p.lastpage = Math.ceil(len/ rn);
  2146. }
  2147. if (!more) { ts.updatepager(false,true); }
  2148. if(locdata) {
  2149. while (ir<len && drows[ir]) {
  2150. cur = drows[ir];
  2151. idr = $.jgrid.getAccessor(cur,idn);
  2152. if(idr === undefined) {
  2153. if (typeof idn === "number" && ts.p.colModel[idn+gi+si+ni] != null) {
  2154. // reread id by name
  2155. idr = $.jgrid.getAccessor(cur,ts.p.colModel[idn+gi+si+ni].name);
  2156. }
  2157. if(idr === undefined) {
  2158. idr = br+ir;
  2159. if(f.length===0){
  2160. if(dReader.cell){
  2161. var ccur2 = $.jgrid.getAccessor(cur,dReader.cell) || cur;
  2162. idr = ccur2 != null && ccur2[idn] !== undefined ? ccur2[idn] : idr;
  2163. ccur2=null;
  2164. }
  2165. }
  2166. }
  2167. }
  2168. if(cur) {
  2169. idr = ts.p.idPrefix + idr;
  2170. rowReader=objectReader;
  2171. if (dReader.repeatitems) {
  2172. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell) || cur;}
  2173. if ($.isArray(cur)) { rowReader=arrayReader; }
  2174. }
  2175. for (j=0;j<rowReader.length;j++) {
  2176. rd[ts.p.colModel[j+gi+si+ni].name] = $.jgrid.getAccessor(cur,rowReader[j]);
  2177. }
  2178. rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr);
  2179. if(ts.p.grouping) {
  2180. groupingPrepare.call(self, rd, ir );
  2181. }
  2182. ts.p.data.push(rd);
  2183. ts.p._index[rd[locid]] = ts.p.data.length-1;
  2184. rd = {};
  2185. }
  2186. ir++;
  2187. }
  2188. if(ts.p.grouping) {
  2189. ts.p.groupingView._locgr = true;
  2190. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  2191. grpdata = null;
  2192. }
  2193. }
  2194. },
  2195. addLocalData = function( retAll ) {
  2196. var st = ts.p.multiSort ? [] : "", sto=[], fndsort=false, cmtypes={}, grtypes=[], grindexes=[], srcformat, sorttype, newformat, sfld;
  2197. if(!$.isArray(ts.p.data)) {
  2198. return;
  2199. }
  2200. var grpview = ts.p.grouping ? ts.p.groupingView : false, lengrp, gin, si;
  2201. $.each(ts.p.colModel,function(){
  2202. sorttype = this.sorttype || "text";
  2203. si = this.index || this.name;
  2204. if(sorttype === "date" || sorttype === "datetime") {
  2205. if(this.formatter && typeof this.formatter === 'string' && this.formatter === 'date') {
  2206. if(this.formatoptions && this.formatoptions.srcformat) {
  2207. srcformat = this.formatoptions.srcformat;
  2208. } else {
  2209. srcformat = $.jgrid.getRegional(ts, "formatter.date.srcformat");
  2210. }
  2211. if(this.formatoptions && this.formatoptions.newformat) {
  2212. newformat = this.formatoptions.newformat;
  2213. } else {
  2214. newformat = $.jgrid.getRegional(ts, "formatter.date.newformat");
  2215. }
  2216. } else {
  2217. srcformat = newformat = this.datefmt || "Y-m-d";
  2218. }
  2219. cmtypes[si] = {"stype": sorttype, "srcfmt": srcformat,"newfmt":newformat, "sfunc": this.sortfunc || null};
  2220. } else {
  2221. cmtypes[si] = {"stype": sorttype, "srcfmt":'',"newfmt":'', "sfunc": this.sortfunc || null};
  2222. }
  2223. if(ts.p.grouping ) {
  2224. for(gin =0, lengrp = grpview.groupField.length; gin< lengrp; gin++) {
  2225. if( this.name === grpview.groupField[gin]) {
  2226. grtypes[gin] = cmtypes[si];
  2227. grindexes[gin]= si;
  2228. }
  2229. }
  2230. }
  2231. if(!ts.p.multiSort) {
  2232. if(!fndsort && (si === ts.p.sortname)){
  2233. st = si;
  2234. fndsort = true;
  2235. }
  2236. }
  2237. });
  2238. if(ts.p.multiSort) {
  2239. st = sortarr;
  2240. sto = sortord;
  2241. }
  2242. if(ts.p.treeGrid && ts.p._sort) {
  2243. $(ts).jqGrid("SortTree", st, ts.p.sortorder, cmtypes[st].stype || 'text', cmtypes[st].srcfmt || '');
  2244. return;
  2245. }
  2246. var compareFnMap = {
  2247. 'eq':function(queryObj) {return queryObj.equals;},
  2248. 'ne':function(queryObj) {return queryObj.notEquals;},
  2249. 'lt':function(queryObj) {return queryObj.less;},
  2250. 'le':function(queryObj) {return queryObj.lessOrEquals;},
  2251. 'gt':function(queryObj) {return queryObj.greater;},
  2252. 'ge':function(queryObj) {return queryObj.greaterOrEquals;},
  2253. 'cn':function(queryObj) {return queryObj.contains;},
  2254. 'nc':function(queryObj,op) {return op === "OR" ? queryObj.orNot().contains : queryObj.andNot().contains;},
  2255. 'bw':function(queryObj) {return queryObj.startsWith;},
  2256. 'bn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().startsWith : queryObj.andNot().startsWith;},
  2257. 'en':function(queryObj,op) {return op === "OR" ? queryObj.orNot().endsWith : queryObj.andNot().endsWith;},
  2258. 'ew':function(queryObj) {return queryObj.endsWith;},
  2259. 'ni':function(queryObj,op) {return op === "OR" ? queryObj.orNot().equals : queryObj.andNot().equals;},
  2260. 'in':function(queryObj) {return queryObj.equals;},
  2261. 'nu':function(queryObj) {return queryObj.isNull;},
  2262. 'nn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().isNull : queryObj.andNot().isNull;}
  2263. },
  2264. query = $.jgrid.from.call(ts, ts.p.data);
  2265. if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  2266. function tojLinq ( group ) {
  2267. var s = 0, index, gor, ror, opr, rule, fld;
  2268. if (group.groups != null) {
  2269. gor = group.groups.length && group.groupOp.toString().toUpperCase() === "OR";
  2270. if (gor) {
  2271. query.orBegin();
  2272. }
  2273. for (index = 0; index < group.groups.length; index++) {
  2274. if (s > 0 && gor) {
  2275. query.or();
  2276. }
  2277. try {
  2278. tojLinq(group.groups[index]);
  2279. } catch (e) {alert(e);}
  2280. s++;
  2281. }
  2282. if (gor) {
  2283. query.orEnd();
  2284. }
  2285. }
  2286. if (group.rules != null) {
  2287. //if(s>0) {
  2288. // var result = query.select();
  2289. // query = $.jgrid.from( result);
  2290. // if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  2291. //}
  2292. try{
  2293. ror = group.rules.length && group.groupOp.toString().toUpperCase() === "OR";
  2294. if (ror) {
  2295. query.orBegin();
  2296. }
  2297. for (index = 0; index < group.rules.length; index++) {
  2298. rule = group.rules[index];
  2299. opr = group.groupOp.toString().toUpperCase();
  2300. if (compareFnMap[rule.op] && rule.field ) {
  2301. if(s > 0 && opr && opr === "OR") {
  2302. query = query.or();
  2303. }
  2304. fld = cmtypes[rule.field];
  2305. if(fld.stype === 'date') {
  2306. if(fld.srcfmt && fld.newfmt && fld.srcfmt !== fld.newfmt ) {
  2307. rule.data = $.jgrid.parseDate.call(ts, fld.newfmt, rule.data, fld.srcfmt);
  2308. }
  2309. }
  2310. query = compareFnMap[rule.op](query, opr)(rule.field, rule.data, cmtypes[rule.field]);
  2311. }
  2312. s++;
  2313. }
  2314. if (ror) {
  2315. query.orEnd();
  2316. }
  2317. } catch (g) {alert(g);}
  2318. }
  2319. }
  2320. if (ts.p.search === true) {
  2321. var srules = ts.p.postData.filters;
  2322. if(srules) {
  2323. if(typeof srules === "string") { srules = $.jgrid.parse(srules);}
  2324. tojLinq( srules );
  2325. } else {
  2326. try {
  2327. sfld = cmtypes[ts.p.postData.searchField];
  2328. if(sfld.stype === 'date') {
  2329. if(sfld.srcfmt && sfld.newfmt && sfld.srcfmt !== sfld.newfmt ) {
  2330. ts.p.postData.searchString = $.jgrid.parseDate.call(ts, sfld.newfmt, ts.p.postData.searchString, sfld.srcfmt);
  2331. }
  2332. }
  2333. query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString,cmtypes[ts.p.postData.searchField]);
  2334. } catch (se){}
  2335. }
  2336. } else {
  2337. if(ts.p.treeGrid && ts.p.treeGridModel === "nested") {
  2338. query.orderBy(ts.p.treeReader.left_field, 'asc', 'integer', '', null);
  2339. }
  2340. }
  2341. if(ts.p.treeGrid && ts.p.treeGridModel === "adjacency") {
  2342. lengrp =0;
  2343. st = null;
  2344. }
  2345. if(ts.p.grouping) {
  2346. for(gin=0; gin<lengrp;gin++) {
  2347. query.orderBy(grindexes[gin],grpview.groupOrder[gin],grtypes[gin].stype, grtypes[gin].srcfmt);
  2348. }
  2349. }
  2350. if(ts.p.multiSort) {
  2351. $.each(st,function(i){
  2352. query.orderBy(this, sto[i], cmtypes[this].stype, cmtypes[this].srcfmt, cmtypes[this].sfunc);
  2353. });
  2354. } else {
  2355. if (st && ts.p.sortorder && fndsort) {
  2356. // to be fixed in case sortname has more than one field
  2357. if(ts.p.sortorder.toUpperCase() === "DESC") {
  2358. query.orderBy(ts.p.sortname, "d", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc);
  2359. } else {
  2360. query.orderBy(ts.p.sortname, "a", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc);
  2361. }
  2362. }
  2363. }
  2364. var queryResults = query.select(),
  2365. recordsperpage = parseInt(ts.p.rowNum,10),
  2366. total = queryResults.length,
  2367. page = parseInt(ts.p.page,10),
  2368. totalpages = Math.ceil(total / recordsperpage),
  2369. retresult = {};
  2370. if((ts.p.search || ts.p.resetsearch) && ts.p.grouping && ts.p.groupingView._locgr) {
  2371. ts.p.groupingView.groups =[];
  2372. var j, grPrepare = $.jgrid.getMethod("groupingPrepare"), key, udc;
  2373. if(ts.p.footerrow && ts.p.userDataOnFooter) {
  2374. for (key in ts.p.userData) {
  2375. if(ts.p.userData.hasOwnProperty(key)) {
  2376. ts.p.userData[key] = 0;
  2377. }
  2378. }
  2379. udc = true;
  2380. }
  2381. for(j=0; j<total; j++) {
  2382. if(udc) {
  2383. for(key in ts.p.userData){
  2384. if( ts.p.userData.hasOwnProperty( key ) ) {
  2385. ts.p.userData[key] += parseFloat(queryResults[j][key] || 0);
  2386. }
  2387. }
  2388. }
  2389. grPrepare.call($(ts),queryResults[j],j, recordsperpage );
  2390. }
  2391. }
  2392. if( retAll ) {
  2393. return queryResults;
  2394. }
  2395. if(ts.p.treeGrid && ts.p.search) {
  2396. queryResults = $(ts).jqGrid("searchTree", queryResults);
  2397. } else {
  2398. queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage );
  2399. }
  2400. query = null;
  2401. cmtypes = null;
  2402. retresult[ts.p.localReader.total] = totalpages;
  2403. retresult[ts.p.localReader.page] = page;
  2404. retresult[ts.p.localReader.records] = total;
  2405. retresult[ts.p.localReader.root] = queryResults;
  2406. retresult[ts.p.localReader.userdata] = ts.p.userData;
  2407. queryResults = null;
  2408. return retresult;
  2409. },
  2410. updatepager = function(rn, dnd) {
  2411. var cp, last, base, from,to,tot,fmt, pgboxes = "", sppg,
  2412. pgid = ts.p.pager ? $.jgrid.jqID(ts.p.pager.substr(1)) : "",
  2413. tspg = pgid ? "_"+pgid : "",
  2414. tspg_t = ts.p.toppager ? "_"+ts.p.toppager.substr(1) : "";
  2415. base = parseInt(ts.p.page,10)-1;
  2416. if(base < 0) { base = 0; }
  2417. base = base*parseInt(ts.p.rowNum,10);
  2418. to = base + ts.p.reccount;
  2419. if (ts.p.scroll) {
  2420. var rows = $("tbody:first > tr:gt(0)", ts.grid.bDiv);
  2421. if(to > ts.p.records) {
  2422. to = ts.p.records;
  2423. }
  2424. base = to - rows.length;
  2425. ts.p.reccount = rows.length;
  2426. var rh = rows.outerHeight() || ts.grid.prevRowHeight;
  2427. if (rh) {
  2428. var top = base * rh;
  2429. var height = parseInt(ts.p.records,10) * rh;
  2430. $(">div:first",ts.grid.bDiv).css({height : height}).children("div:first").css({height:top,display:top?"":"none"});
  2431. if (ts.grid.bDiv.scrollTop === 0 && ts.p.page > 1) {
  2432. ts.grid.bDiv.scrollTop = ts.p.rowNum * (ts.p.page - 1) * rh;
  2433. }
  2434. }
  2435. ts.grid.bDiv.scrollLeft = ts.grid.hDiv.scrollLeft;
  2436. }
  2437. pgboxes = ts.p.pager || "";
  2438. pgboxes += ts.p.toppager ? (pgboxes ? "," + ts.p.toppager : ts.p.toppager) : "";
  2439. if(pgboxes) {
  2440. fmt = $.jgrid.getRegional(ts, "formatter.integer");
  2441. cp = intNum(ts.p.page);
  2442. last = intNum(ts.p.lastpage);
  2443. $(".selbox",pgboxes)[ this.p.useProp ? 'prop' : 'attr' ]("disabled",false);
  2444. if(ts.p.pginput===true) {
  2445. $("#input"+tspg).html($.jgrid.template($.jgrid.getRegional(ts, "defaults.pgtext", ts.p.pgtext) || "","<input "+getstyle(stylemodule, 'pgInput', false, 'ui-pg-input') + " type='text' size='2' maxlength='7' value='0' role='textbox'/>","<span id='sp_1_"+$.jgrid.jqID(pgid)+"'></span>"));
  2446. if(ts.p.toppager) {
  2447. $("#input_t"+tspg_t).html($.jgrid.template($.jgrid.getRegional(ts, "defaults.pgtext", ts.p.pgtext) || "","<input "+getstyle(stylemodule, 'pgInput', false, 'ui-pg-input') + " type='text' size='2' maxlength='7' value='0' role='textbox'/>","<span id='sp_1_"+$.jgrid.jqID(pgid)+"_toppager'></span>"));
  2448. }
  2449. $('.ui-pg-input',pgboxes).val(ts.p.page);
  2450. sppg = ts.p.toppager ? '#sp_1'+tspg+",#sp_1"+tspg+"_toppager" : '#sp_1'+tspg;
  2451. $(sppg).html($.fmatter ? $.fmatter.util.NumberFormat(ts.p.lastpage,fmt):ts.p.lastpage);
  2452. }
  2453. if (ts.p.viewrecords){
  2454. if(ts.p.reccount === 0) {
  2455. $(".ui-paging-info",pgboxes).html($.jgrid.getRegional(ts, "defaults.emptyrecords", ts.p.emptyrecords ));
  2456. } else {
  2457. from = base+1;
  2458. tot=ts.p.records;
  2459. if($.fmatter) {
  2460. from = $.fmatter.util.NumberFormat(from,fmt);
  2461. to = $.fmatter.util.NumberFormat(to,fmt);
  2462. tot = $.fmatter.util.NumberFormat(tot,fmt);
  2463. }
  2464. var rt = $.jgrid.getRegional(ts, "defaults.recordtext", ts.p.recordtext);
  2465. $(".ui-paging-info",pgboxes).html($.jgrid.template( rt ,from,to,tot));
  2466. }
  2467. }
  2468. if(ts.p.pgbuttons===true) {
  2469. if(cp<=0) {cp = last = 0;}
  2470. if(cp===1 || cp === 0) {
  2471. $("#first"+tspg+", #prev"+tspg).addClass( disabled ).removeClass( hover );
  2472. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).addClass( disabled ).removeClass( hover ); }
  2473. } else {
  2474. $("#first"+tspg+", #prev"+tspg).removeClass( disabled );
  2475. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).removeClass( disabled ); }
  2476. }
  2477. if(cp===last || cp === 0) {
  2478. $("#next"+tspg+", #last"+tspg).addClass( disabled ).removeClass( hover );
  2479. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).addClass( disabled ).removeClass( hover ); }
  2480. } else {
  2481. $("#next"+tspg+", #last"+tspg).removeClass( disabled );
  2482. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).removeClass( disabled ); }
  2483. }
  2484. }
  2485. }
  2486. if(rn===true && ts.p.rownumbers === true) {
  2487. $(">td.jqgrid-rownum",ts.rows).each(function(i){
  2488. $(this).html(base+1+i);
  2489. });
  2490. }
  2491. if(dnd && ts.p.jqgdnd) { $(ts).jqGrid('gridDnD','updateDnD');}
  2492. $(ts).triggerHandler("jqGridGridComplete");
  2493. if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete.call(ts);}
  2494. $(ts).triggerHandler("jqGridAfterGridComplete");
  2495. },
  2496. beginReq = function() {
  2497. ts.grid.hDiv.loading = true;
  2498. if(ts.p.hiddengrid) { return;}
  2499. $(ts).jqGrid("progressBar", {method:"show", loadtype : ts.p.loadui, htmlcontent: $.jgrid.getRegional(ts, "defaults.loadtext", ts.p.loadtext) });
  2500. },
  2501. endReq = function() {
  2502. ts.grid.hDiv.loading = false;
  2503. $(ts).jqGrid("progressBar", {method:"hide", loadtype : ts.p.loadui });
  2504. },
  2505. beforeprocess = function(data, st, xhr) {
  2506. var bfpcr = $(ts).triggerHandler("jqGridBeforeProcessing", [data,st,xhr]);
  2507. bfpcr = (bfpcr === undefined || typeof(bfpcr) !== 'boolean') ? true : bfpcr;
  2508. if ($.isFunction(ts.p.beforeProcessing)) {
  2509. if (ts.p.beforeProcessing.call(ts, data, st, xhr) === false) {
  2510. bfpcr = false;
  2511. }
  2512. }
  2513. return bfpcr;
  2514. },
  2515. afterprocess = function(dstr, lcf) {
  2516. $(ts).triggerHandler("jqGridLoadComplete", [dstr]);
  2517. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  2518. $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]);
  2519. ts.p.datatype = "local";
  2520. ts.p.datastr = null;
  2521. endReq();
  2522. },
  2523. populate = function (npage) {
  2524. if(!ts.grid.hDiv.loading) {
  2525. var pvis = ts.p.scroll && npage === false,
  2526. prm = {}, dt, dstr, pN=ts.p.prmNames;
  2527. if(ts.p.page <=0) { ts.p.page = Math.min(1,ts.p.lastpage); }
  2528. if(pN.search !== null) {prm[pN.search] = ts.p.search;} if(pN.nd !== null) {prm[pN.nd] = new Date().getTime();}
  2529. if(pN.rows !== null) {prm[pN.rows]= ts.p.rowNum;} if(pN.page !== null) {prm[pN.page]= ts.p.page;}
  2530. if(pN.sort !== null) {prm[pN.sort]= ts.p.sortname;} if(pN.order !== null) {prm[pN.order]= ts.p.sortorder;}
  2531. if(ts.p.rowTotal !== null && pN.totalrows !== null) { prm[pN.totalrows]= ts.p.rowTotal; }
  2532. var lcf = $.isFunction(ts.p.loadComplete), lc = lcf ? ts.p.loadComplete : null;
  2533. var adjust = 0;
  2534. npage = npage || 1;
  2535. if (npage > 1) {
  2536. if(pN.npage !== null) {
  2537. prm[pN.npage] = npage;
  2538. adjust = npage - 1;
  2539. npage = 1;
  2540. } else {
  2541. lc = function(req) {
  2542. ts.p.page++;
  2543. ts.grid.hDiv.loading = false;
  2544. if (lcf) {
  2545. ts.p.loadComplete.call(ts,req);
  2546. }
  2547. populate(npage-1);
  2548. };
  2549. }
  2550. } else if (pN.npage !== null) {
  2551. delete ts.p.postData[pN.npage];
  2552. }
  2553. if(ts.p.grouping) {
  2554. $(ts).jqGrid('groupingSetup');
  2555. var grp = ts.p.groupingView, gi, gs="";
  2556. for(gi=0;gi<grp.groupField.length;gi++) {
  2557. var index = grp.groupField[gi];
  2558. $.each(ts.p.colModel, function(cmIndex, cmValue) {
  2559. if (cmValue.name === index && cmValue.index){
  2560. index = cmValue.index;
  2561. }
  2562. } );
  2563. gs += index +" "+grp.groupOrder[gi]+", ";
  2564. }
  2565. prm[pN.sort] = gs + prm[pN.sort];
  2566. }
  2567. $.extend(ts.p.postData,prm);
  2568. var rcnt = !ts.p.scroll ? 1 : ts.rows.length-1;
  2569. if ($.isFunction(ts.p.datatype)) {
  2570. ts.p.datatype.call(ts,ts.p.postData,"load_"+ts.p.id, rcnt, npage, adjust);
  2571. return;
  2572. }
  2573. var bfr = $(ts).triggerHandler("jqGridBeforeRequest");
  2574. if (bfr === false || bfr === 'stop') { return; }
  2575. if ($.isFunction(ts.p.beforeRequest)) {
  2576. bfr = ts.p.beforeRequest.call(ts);
  2577. if (bfr === false || bfr === 'stop') { return; }
  2578. }
  2579. dt = ts.p.datatype.toLowerCase();
  2580. switch(dt)
  2581. {
  2582. case "json":
  2583. case "jsonp":
  2584. case "xml":
  2585. case "script":
  2586. $.ajax($.extend({
  2587. url:ts.p.url,
  2588. type:ts.p.mtype,
  2589. dataType: dt ,
  2590. data: $.isFunction(ts.p.serializeGridData)? ts.p.serializeGridData.call(ts,ts.p.postData) : ts.p.postData,
  2591. success:function(data,st, xhr) {
  2592. if(!beforeprocess(data, st,xhr)) {
  2593. endReq();
  2594. return;
  2595. }
  2596. if(dt === "xml") { addXmlData(data, rcnt,npage>1,adjust); }
  2597. else { addJSONData(data, rcnt, npage>1, adjust); }
  2598. $(ts).triggerHandler("jqGridLoadComplete", [data]);
  2599. if(lc) { lc.call(ts,data); }
  2600. $(ts).triggerHandler("jqGridAfterLoadComplete", [data]);
  2601. if (pvis) { ts.grid.populateVisible(); }
  2602. if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";}
  2603. data=null;
  2604. if (npage === 1) { endReq(); }
  2605. },
  2606. error:function(xhr,st,err){
  2607. $(ts).triggerHandler("jqGridLoadError", [xhr,st,err]);
  2608. if($.isFunction(ts.p.loadError)) { ts.p.loadError.call(ts,xhr,st,err); }
  2609. if (npage === 1) { endReq(); }
  2610. xhr=null;
  2611. },
  2612. beforeSend: function(xhr, settings ){
  2613. var gotoreq = true;
  2614. gotoreq = $(ts).triggerHandler("jqGridLoadBeforeSend", [xhr,settings]);
  2615. if($.isFunction(ts.p.loadBeforeSend)) {
  2616. gotoreq = ts.p.loadBeforeSend.call(ts,xhr, settings);
  2617. }
  2618. if(gotoreq === undefined) { gotoreq = true; }
  2619. if(gotoreq === false) {
  2620. return false;
  2621. }
  2622. beginReq();
  2623. }
  2624. },$.jgrid.ajaxOptions, ts.p.ajaxGridOptions));
  2625. break;
  2626. case "xmlstring":
  2627. beginReq();
  2628. dstr = typeof ts.p.datastr !== 'string' ? ts.p.datastr : $.parseXML(ts.p.datastr);
  2629. if(!beforeprocess(dstr, 200 , null)) {
  2630. endReq();
  2631. return;
  2632. }
  2633. addXmlData(dstr);
  2634. afterprocess(dstr, lcf);
  2635. break;
  2636. case "jsonstring":
  2637. beginReq();
  2638. if(typeof ts.p.datastr === 'string') { dstr = $.jgrid.parse(ts.p.datastr); }
  2639. else { dstr = ts.p.datastr; }
  2640. if(!beforeprocess(dstr, 200 , null)) {
  2641. endReq();
  2642. return;
  2643. }
  2644. addJSONData(dstr);
  2645. afterprocess(dstr, lcf);
  2646. break;
  2647. case "local":
  2648. case "clientside":
  2649. beginReq();
  2650. ts.p.datatype = "local";
  2651. ts.p._ald = true;
  2652. var req = addLocalData( false );
  2653. if(!beforeprocess(req, 200 , null)) {
  2654. endReq();
  2655. return;
  2656. }
  2657. addJSONData(req,rcnt,npage>1,adjust);
  2658. $(ts).triggerHandler("jqGridLoadComplete", [req]);
  2659. if(lc) { lc.call(ts,req); }
  2660. $(ts).triggerHandler("jqGridAfterLoadComplete", [req]);
  2661. if (pvis) { ts.grid.populateVisible(); }
  2662. endReq();
  2663. ts.p._ald = false;
  2664. break;
  2665. }
  2666. ts.p._sort = false;
  2667. }
  2668. },
  2669. setHeadCheckBox = function ( checked ) {
  2670. $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked);
  2671. var fid = ts.p.frozenColumns ? ts.p.id+"_frozen" : "";
  2672. if(fid) {
  2673. $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.fhDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked);
  2674. }
  2675. },
  2676. setPager = function (pgid, tp){
  2677. // TBD - consider escaping pgid with pgid = $.jgrid.jqID(pgid);
  2678. var sep = "<td class='ui-pg-button "+disabled+"'><span class='ui-separator'></span></td>",
  2679. pginp = "",
  2680. pgl="<table class='ui-pg-table ui-common-table ui-paging-pager'><tbody><tr>",
  2681. str="", pgcnt, lft, cent, rgt, twd, tdw, i,
  2682. clearVals = function(onpaging, thus){
  2683. var ret;
  2684. ret = $(ts).triggerHandler("jqGridPaging", [onpaging, thus]);
  2685. if(ret==='stop') {return false;}
  2686. if ($.isFunction(ts.p.onPaging) ) { ret = ts.p.onPaging.call(ts,onpaging, thus); }
  2687. if(ret==='stop') {return false;}
  2688. ts.p.selrow = null;
  2689. if(ts.p.multiselect) {ts.p.selarrrow =[]; setHeadCheckBox( false );}
  2690. ts.p.savedRow = [];
  2691. return true;
  2692. };
  2693. pgid = pgid.substr(1);
  2694. tp += "_" + pgid;
  2695. pgcnt = "pg_"+pgid;
  2696. lft = pgid+"_left"; cent = pgid+"_center"; rgt = pgid+"_right";
  2697. $("#"+$.jgrid.jqID(pgid) )
  2698. .append("<div id='"+pgcnt+"' class='ui-pager-control' role='group'><table " + getstyle(stylemodule, 'pagerTable', false, 'ui-pg-table ui-common-table ui-pager-table') + "><tbody><tr><td id='"+lft+"' align='left'></td><td id='"+cent+"' align='center' style='white-space:pre;'></td><td id='"+rgt+"' align='right'></td></tr></tbody></table></div>")
  2699. .attr("dir","ltr"); //explicit setting
  2700. if(ts.p.rowList.length >0){
  2701. str = "<td dir=\""+dir+"\">";
  2702. str +="<select "+getstyle(stylemodule, 'pgSelectBox', false, 'ui-pg-selbox')+" role=\"listbox\" title=\""+($.jgrid.getRegional(ts,"defaults.pgrecs",ts.p.pgrecs) || "")+ "\">";
  2703. var strnm;
  2704. for(i=0;i<ts.p.rowList.length;i++){
  2705. strnm = ts.p.rowList[i].toString().split(":");
  2706. if(strnm.length === 1) {
  2707. strnm[1] = strnm[0];
  2708. }
  2709. str +="<option role=\"option\" value=\""+strnm[0]+"\""+(( intNum(ts.p.rowNum,0) === intNum(strnm[0],0))?" selected=\"selected\"":"")+">"+strnm[1]+"</option>";
  2710. }
  2711. str +="</select></td>";
  2712. }
  2713. if(dir==="rtl") { pgl += str; }
  2714. if(ts.p.pginput===true) {
  2715. pginp= "<td id='input"+tp+"' dir='"+dir+"'>"+$.jgrid.template( $.jgrid.getRegional(ts, "defaults.pgtext", ts.p.pgtext) || "","<input class='ui-pg-input' type='text' size='2' maxlength='7' value='0' role='textbox'/>","<span id='sp_1_"+$.jgrid.jqID(pgid)+"'></span>")+"</td>";
  2716. }
  2717. if(ts.p.pgbuttons===true) {
  2718. var po=["first"+tp,"prev"+tp, "next"+tp,"last"+tp], btc=getstyle(stylemodule, 'pgButtonBox', true, 'ui-pg-button'),
  2719. pot = [($.jgrid.getRegional(ts,"defaults.pgfirst",ts.p.pgfirst) || ""),
  2720. ($.jgrid.getRegional(ts,"defaults.pgprev",ts.p.pgprev) || ""),
  2721. ($.jgrid.getRegional(ts,"defaults.pgnext",ts.p.pgnext) || ""),
  2722. ($.jgrid.getRegional(ts,"defaults.pglast",ts.p.pglast) || "")];
  2723. if(dir==="rtl") {
  2724. po.reverse();
  2725. pot.reverse();
  2726. }
  2727. pgl += "<td id='"+po[0]+"' class='"+btc+"' title='"+ pot[0] +"'" + "><span " + getstyle(stylemodule, 'icon_first', false, iconbase)+"></span></td>";
  2728. pgl += "<td id='"+po[1]+"' class='"+btc+"' title='"+ pot[1] +"'" +"><span " + getstyle(stylemodule, 'icon_prev', false, iconbase)+"></span></td>";
  2729. pgl += pginp !== "" ? sep+pginp+sep:"";
  2730. pgl += "<td id='"+po[2]+"' class='"+btc+"' title='"+ pot[2] +"'" +"><span " + getstyle(stylemodule, 'icon_next',false, iconbase)+"></span></td>";
  2731. pgl += "<td id='"+po[3]+"' class='"+btc+"' title='"+ pot[3] +"'" +"><span " + getstyle(stylemodule, 'icon_end',false, iconbase)+"></span></td>";
  2732. } else if (pginp !== "") {
  2733. pgl += pginp;
  2734. }
  2735. if(dir==="ltr") {
  2736. pgl += str;
  2737. }
  2738. pgl += "</tr></tbody></table>";
  2739. if(ts.p.viewrecords===true) {
  2740. $("td#"+pgid+"_"+ts.p.recordpos,"#"+pgcnt).append("<div dir='"+dir+"' style='text-align:"+ts.p.recordpos+"' class='ui-paging-info'></div>");
  2741. }
  2742. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).append(pgl);
  2743. tdw = $("#gbox_"+$.jgrid.jqID(ts.p.id)).css("font-size") || "11px";
  2744. $("#gbox_"+$.jgrid.jqID(ts.p.id)).append("<div id='testpg' "+getstyle(stylemodule, 'entrieBox', false, 'ui-jqgrid')+" style='font-size:"+tdw+";visibility:hidden;' ></div>");
  2745. twd = $(pgl).clone().appendTo("#testpg").width();
  2746. $("#testpg").remove();
  2747. if(twd > 0) {
  2748. if(pginp !== "") { twd += 50; } //should be param
  2749. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).width(twd);
  2750. }
  2751. ts.p._nvtd = [];
  2752. ts.p._nvtd[0] = twd ? Math.floor((ts.p.width - twd)/2) : Math.floor(ts.p.width/3);
  2753. ts.p._nvtd[1] = 0;
  2754. pgl=null;
  2755. $('.ui-pg-selbox',"#"+pgcnt).on('change',function() {
  2756. if(!clearVals('records', this)) { return false; }
  2757. ts.p.page = Math.round(ts.p.rowNum*(ts.p.page-1)/this.value-0.5)+1;
  2758. ts.p.rowNum = this.value;
  2759. if(ts.p.pager) { $('.ui-pg-selbox',ts.p.pager).val(this.value); }
  2760. if(ts.p.toppager) { $('.ui-pg-selbox',ts.p.toppager).val(this.value); }
  2761. populate();
  2762. return false;
  2763. });
  2764. if(ts.p.pgbuttons===true) {
  2765. $(".ui-pg-button","#"+pgcnt).hover(function(){
  2766. if($(this).hasClass(disabled)) {
  2767. this.style.cursor='default';
  2768. } else {
  2769. $(this).addClass(hover);
  2770. this.style.cursor='pointer';
  2771. }
  2772. },function() {
  2773. if(!$(this).hasClass(disabled)) {
  2774. $(this).removeClass(hover);
  2775. this.style.cursor= "default";
  2776. }
  2777. });
  2778. $("#first"+$.jgrid.jqID(tp)+", #prev"+$.jgrid.jqID(tp)+", #next"+$.jgrid.jqID(tp)+", #last"+$.jgrid.jqID(tp)).click( function() {
  2779. if ($(this).hasClass(disabled)) {
  2780. return false;
  2781. }
  2782. var cp = intNum(ts.p.page,1),
  2783. last = intNum(ts.p.lastpage,1), selclick = false,
  2784. fp=true, pp=true, np=true,lp=true;
  2785. if(last ===0 || last===1) {
  2786. fp=false;
  2787. pp=false;
  2788. np=false;
  2789. lp=false;
  2790. } else if( last>1 && cp >=1) {
  2791. if( cp === 1) {
  2792. fp=false;
  2793. pp=false;
  2794. } else if( cp===last){
  2795. np=false;
  2796. lp=false;
  2797. }
  2798. } else if( last>1 && cp===0 ) {
  2799. np=false;
  2800. lp=false;
  2801. cp=last-1;
  2802. }
  2803. if(!clearVals(this.id.split("_")[0], this)) { return false; }
  2804. if( this.id === 'first'+tp && fp ) { ts.p.page=1; selclick=true;}
  2805. if( this.id === 'prev'+tp && pp) { ts.p.page=(cp-1); selclick=true;}
  2806. if( this.id === 'next'+tp && np) { ts.p.page=(cp+1); selclick=true;}
  2807. if( this.id === 'last'+tp && lp) { ts.p.page=last; selclick=true;}
  2808. if(selclick) {
  2809. populate();
  2810. }
  2811. return false;
  2812. });
  2813. }
  2814. if(ts.p.pginput===true) {
  2815. $("#"+pgcnt).on('keypress','input.ui-pg-input', function(e) {
  2816. var key = e.charCode || e.keyCode || 0;
  2817. if(key === 13) {
  2818. if(!clearVals('user', this)) { return false; }
  2819. $(this).val( intNum( $(this).val(), 1));
  2820. ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page;
  2821. populate();
  2822. return false;
  2823. }
  2824. return this;
  2825. });
  2826. }
  2827. },
  2828. multiSort = function(iCol, obj, sor ) {
  2829. var cm = ts.p.colModel,
  2830. selTh = ts.p.frozenColumns ? obj : ts.grid.headers[iCol].el, so="", sn;
  2831. $("span.ui-grid-ico-sort",selTh).addClass(disabled);
  2832. $(selTh).attr("aria-selected","false");
  2833. sn = (cm[iCol].index || cm[iCol].name);
  2834. if ( typeof sor == "undefined" )
  2835. {
  2836. if(cm[iCol].lso) {
  2837. if(cm[iCol].lso==="asc") {
  2838. cm[iCol].lso += "-desc";
  2839. so = "desc";
  2840. } else if(cm[iCol].lso==="desc") {
  2841. cm[iCol].lso += "-asc";
  2842. so = "asc";
  2843. } else if(cm[iCol].lso==="asc-desc" || cm[iCol].lso==="desc-asc") {
  2844. cm[iCol].lso="";
  2845. }
  2846. } else {
  2847. cm[iCol].lso = so = cm[iCol].firstsortorder || 'asc';
  2848. }
  2849. }
  2850. else {
  2851. cm[iCol].lso = so = sor;
  2852. }
  2853. if( so ) {
  2854. $("span.s-ico",selTh).show();
  2855. $("span.ui-icon-"+so,selTh).removeClass(disabled);
  2856. $(selTh).attr("aria-selected","true");
  2857. } else {
  2858. if(!ts.p.viewsortcols[0]) {
  2859. $("span.s-ico",selTh).hide();
  2860. }
  2861. }
  2862. var isn = sortarr.indexOf( sn );
  2863. if( isn === -1 ) {
  2864. sortarr.push( sn );
  2865. sortord.push( so );
  2866. } else {
  2867. if( so ) {
  2868. sortord[isn] = so;
  2869. } else {
  2870. sortord.splice( isn, 1 );
  2871. sortarr.splice( isn, 1 );
  2872. }
  2873. }
  2874. ts.p.sortorder = "";
  2875. ts.p.sortname = "";
  2876. for( var i = 0, len = sortarr.length; i < len ; i++) {
  2877. if( i > 0) {
  2878. ts.p.sortname += ", ";
  2879. }
  2880. ts.p.sortname += sortarr[ i ];
  2881. if( i !== len -1) {
  2882. ts.p.sortname += " "+sortord[ i ];
  2883. }
  2884. }
  2885. ts.p.sortorder = sortord[ len -1 ];
  2886. /*
  2887. $.each(cm, function(i){
  2888. if(this.lso) {
  2889. if(i>0 && fs) {
  2890. sort += ", ";
  2891. }
  2892. splas = this.lso.split("-");
  2893. sort += cm[i].index || cm[i].name;
  2894. sort += " "+splas[splas.length-1];
  2895. fs = true;
  2896. ts.p.sortorder = splas[splas.length-1];
  2897. }
  2898. });
  2899. ls = sort.lastIndexOf(ts.p.sortorder);
  2900. sort = sort.substring(0, ls);
  2901. ts.p.sortname = sort;
  2902. */
  2903. },
  2904. sortData = function (index, idxcol,reload,sor, obj){
  2905. if(!ts.p.colModel[idxcol].sortable) { return; }
  2906. if(ts.p.savedRow.length > 0) {return;}
  2907. if(!reload) {
  2908. if( ts.p.lastsort === idxcol && ts.p.sortname !== "" ) {
  2909. if( ts.p.sortorder === 'asc') {
  2910. ts.p.sortorder = 'desc';
  2911. } else if(ts.p.sortorder === 'desc') { ts.p.sortorder = 'asc';}
  2912. } else { ts.p.sortorder = ts.p.colModel[idxcol].firstsortorder || 'asc'; }
  2913. ts.p.page = 1;
  2914. }
  2915. if(ts.p.multiSort) {
  2916. multiSort( idxcol, obj, sor);
  2917. } else {
  2918. if(sor) {
  2919. if(ts.p.lastsort === idxcol && ts.p.sortorder === sor && !reload) { return; }
  2920. ts.p.sortorder = sor;
  2921. }
  2922. var previousSelectedTh = ts.grid.headers[ts.p.lastsort] ? ts.grid.headers[ts.p.lastsort].el : null, newSelectedTh = ts.p.frozenColumns ? obj : ts.grid.headers[idxcol].el,
  2923. //sortrule = $.trim(ts.p.viewsortcols[1] === 'single' ? hidden : disabled);
  2924. usehide = ts.p.viewsortcols[1] === 'single' ? true : false, tmpicon;
  2925. tmpicon = $(previousSelectedTh).find("span.ui-grid-ico-sort");
  2926. tmpicon.addClass(disabled);
  2927. if(usehide) {
  2928. $(tmpicon).css("display","none");
  2929. }
  2930. $(previousSelectedTh).attr("aria-selected","false");
  2931. if(ts.p.frozenColumns) {
  2932. tmpicon = ts.grid.fhDiv.find("span.ui-grid-ico-sort");
  2933. tmpicon.addClass(disabled);
  2934. if(usehide) { tmpicon.css("display","none"); }
  2935. ts.grid.fhDiv.find("th").attr("aria-selected","false");
  2936. }
  2937. tmpicon = $(newSelectedTh).find("span.ui-icon-"+ts.p.sortorder);
  2938. tmpicon.removeClass(disabled);
  2939. if(usehide) { tmpicon.css("display",""); }
  2940. $(newSelectedTh).attr("aria-selected","true");
  2941. if(!ts.p.viewsortcols[0]) {
  2942. if(ts.p.lastsort !== idxcol) {
  2943. if(ts.p.frozenColumns){
  2944. ts.grid.fhDiv.find("span.s-ico").hide();
  2945. }
  2946. $("span.s-ico",previousSelectedTh).hide();
  2947. $("span.s-ico",newSelectedTh).show();
  2948. } else if (ts.p.sortname === "") { // if ts.p.lastsort === idxcol but ts.p.sortname === ""
  2949. $("span.s-ico",newSelectedTh).show();
  2950. }
  2951. }
  2952. index = index.substring(5 + ts.p.id.length + 1); // bad to be changed!?!
  2953. ts.p.sortname = ts.p.colModel[idxcol].index || index;
  2954. }
  2955. if ($(ts).triggerHandler("jqGridSortCol", [ts.p.sortname, idxcol, ts.p.sortorder]) === 'stop') {
  2956. ts.p.lastsort = idxcol;
  2957. return;
  2958. }
  2959. if($.isFunction(ts.p.onSortCol)) {if (ts.p.onSortCol.call(ts, ts.p.sortname, idxcol, ts.p.sortorder)==='stop') {ts.p.lastsort = idxcol; return;}}
  2960. if(ts.p.datatype === "local") {
  2961. if(ts.p.deselectAfterSort) {$(ts).jqGrid("resetSelection");}
  2962. } else {
  2963. ts.p.selrow = null;
  2964. if(ts.p.multiselect){setHeadCheckBox( false );}
  2965. ts.p.selarrrow =[];
  2966. ts.p.savedRow =[];
  2967. }
  2968. if(ts.p.scroll) {
  2969. var sscroll = ts.grid.bDiv.scrollLeft;
  2970. emptyRows.call(ts, true, false);
  2971. ts.grid.hDiv.scrollLeft = sscroll;
  2972. }
  2973. if(ts.p.subGrid && ts.p.datatype === 'local') {
  2974. $("td.sgexpanded","#"+$.jgrid.jqID(ts.p.id)).each(function(){
  2975. $(this).trigger("click");
  2976. });
  2977. }
  2978. ts.p._sort = true;
  2979. populate();
  2980. ts.p.lastsort = idxcol;
  2981. if(ts.p.sortname !== index && idxcol) {ts.p.lastsort = idxcol;}
  2982. },
  2983. setColWidth = function () {
  2984. var initwidth = 0, brd=$.jgrid.cell_width? 0: intNum(ts.p.cellLayout,0), vc=0, lvc, scw=intNum(ts.p.scrollOffset,0),cw,hs=false,aw,gw=0,cr;
  2985. $.each(ts.p.colModel, function() {
  2986. if(this.hidden === undefined) {this.hidden=false;}
  2987. if(ts.p.grouping && ts.p.autowidth) {
  2988. var ind = $.inArray(this.name, ts.p.groupingView.groupField);
  2989. if(ind >= 0 && ts.p.groupingView.groupColumnShow.length > ind) {
  2990. this.hidden = !ts.p.groupingView.groupColumnShow[ind];
  2991. }
  2992. }
  2993. this.widthOrg = cw = intNum(this.width,0);
  2994. if(this.hidden===false){
  2995. initwidth += cw+brd;
  2996. if(this.fixed) {
  2997. gw += cw+brd;
  2998. } else {
  2999. vc++;
  3000. }
  3001. }
  3002. });
  3003. if(isNaN(ts.p.width)) {
  3004. ts.p.width = initwidth + ((ts.p.shrinkToFit ===false && !isNaN(ts.p.height)) ? scw : 0);
  3005. }
  3006. grid.width = parseInt(ts.p.width,10);
  3007. ts.p.tblwidth = initwidth;
  3008. if(ts.p.shrinkToFit ===false && ts.p.forceFit === true) {ts.p.forceFit=false;}
  3009. if(ts.p.shrinkToFit===true && vc > 0) {
  3010. aw = grid.width-brd*vc-gw;
  3011. if(!isNaN(ts.p.height)) {
  3012. aw -= scw;
  3013. hs = true;
  3014. }
  3015. initwidth =0;
  3016. $.each(ts.p.colModel, function(i) {
  3017. if(this.hidden === false && !this.fixed){
  3018. cw = Math.round(aw*this.width/(ts.p.tblwidth-brd*vc-gw));
  3019. this.width =cw;
  3020. initwidth += cw;
  3021. lvc = i;
  3022. }
  3023. });
  3024. cr =0;
  3025. if (hs) {
  3026. if(grid.width-gw-(initwidth+brd*vc) !== scw){
  3027. cr = grid.width-gw-(initwidth+brd*vc)-scw;
  3028. }
  3029. } else if(!hs && Math.abs(grid.width-gw-(initwidth+brd*vc)) !== 1) {
  3030. cr = grid.width-gw-(initwidth+brd*vc);
  3031. }
  3032. ts.p.colModel[lvc].width += cr;
  3033. ts.p.tblwidth = initwidth+cr+brd*vc+gw;
  3034. if(ts.p.tblwidth > ts.p.width) {
  3035. ts.p.colModel[lvc].width -= (ts.p.tblwidth - parseInt(ts.p.width,10));
  3036. ts.p.tblwidth = ts.p.width;
  3037. }
  3038. }
  3039. },
  3040. nextVisible= function(iCol) {
  3041. var ret = iCol, j=iCol, i;
  3042. for (i = iCol+1;i<ts.p.colModel.length;i++){
  3043. if(ts.p.colModel[i].hidden !== true ) {
  3044. j=i; break;
  3045. }
  3046. }
  3047. return j-ret;
  3048. },
  3049. getOffset = function (iCol) {
  3050. var $th = $(ts.grid.headers[iCol].el), ret = [$th.position().left + $th.outerWidth()];
  3051. if(ts.p.direction==="rtl") { ret[0] = ts.p.width - ret[0]; }
  3052. ret[0] -= ts.grid.bDiv.scrollLeft;
  3053. ret.push($(ts.grid.hDiv).position().top);
  3054. ret.push($(ts.grid.bDiv).offset().top - $(ts.grid.hDiv).offset().top + $(ts.grid.bDiv).height());
  3055. return ret;
  3056. },
  3057. getColumnHeaderIndex = function (th) {
  3058. var i, headers = ts.grid.headers, ci = $.jgrid.getCellIndex(th);
  3059. for (i = 0; i < headers.length; i++) {
  3060. if (th === headers[i].el) {
  3061. ci = i;
  3062. break;
  3063. }
  3064. }
  3065. return ci;
  3066. },
  3067. buildColItems = function (top, left, parent) {
  3068. var cm = ts.p.colModel, len = cm.length, i, cols=[], disp,
  3069. texts = $.jgrid.getRegional(ts, "colmenu"),
  3070. str1 = '<ul id="col_menu" class="ui-search-menu ui-col-menu modal-content" role="menu" tabindex="0" style="left:'+left+'px;top:'+top+'px;">';
  3071. for(i=0;i<len;i++) {
  3072. //if(!cm[i].hidedlg) { // column chooser
  3073. var hid = !cm[i].hidden ? "checked" : "", nm = cm[i].name, lb = ts.p.colNames[i];
  3074. disp = (nm === 'cb' || nm==='subgrid' || nm==='rn' || cm[i].hidedlg) ? "style='display:none'" :"";
  3075. str1 += '<li '+disp+' class="ui-menu-item" role="presentation" draggable="true"><a class="g-menu-item" tabindex="0" role="menuitem" ><table class="ui-common-table" ><tr><td class="menu_icon" title="'+texts.reorder+'"><span class="'+iconbase+' '+colmenustyle.icon_move+' notclick"></span></td><td class="menu_icon"><input class="'+colmenustyle.input_checkbox+'" type="checkbox" name="'+nm+'" '+hid+'></td><td class="menu_text">'+lb+'</td></tr></table></a></li>';
  3076. cols.push(i);
  3077. }
  3078. str1 += "</ul>";
  3079. $(parent).append(str1);
  3080. $("#col_menu").addClass("ui-menu " + colmenustyle.menu_widget);
  3081. if($.fn.html5sortable()) {
  3082. $("#col_menu").html5sortable({
  3083. handle: 'span',
  3084. forcePlaceholderSize: true }
  3085. ).on('sortupdate', function(e, ui) {
  3086. cols.splice( ui.startindex, 1);
  3087. cols.splice(ui.endindex, 0, ui.startindex);
  3088. $(ts).jqGrid("destroyFrozenColumns");
  3089. $(ts).jqGrid("remapColumns", cols, true);
  3090. $(ts).jqGrid("setFrozenColumns");
  3091. for(i=0;i<len;i++) {
  3092. cols[i] = i;
  3093. }
  3094. });
  3095. } // NO jQuery UI
  3096. $("#col_menu > li > a").on("click", function(e) {
  3097. var checked;
  3098. if($(e.target).hasClass('notclick')) {
  3099. return;
  3100. }
  3101. if($(e.target).is(":input")) {
  3102. checked = $(e.target).is(":checked");
  3103. } else {
  3104. checked = !$("input", this).is(":checked");
  3105. $("input", this).prop("checked",checked);
  3106. }
  3107. if(!checked) {
  3108. $(ts).jqGrid('hideCol', $("input", this).attr('name'));
  3109. $(this).parent().attr("draggable","false");
  3110. } else {
  3111. $(ts).jqGrid('showCol', $("input", this).attr('name'));
  3112. $(this).parent().attr("draggable","true");
  3113. }
  3114. }).hover(function(){
  3115. $(this).addClass(hover);
  3116. },function(){
  3117. $(this).removeClass(hover);
  3118. });
  3119. },
  3120. buildSearchBox = function (index, top, left, parent) {
  3121. var cm = ts.p.colModel[index], rules, o1='',v1='',r1='',o2='',v2='', so, op, repstr='',selected, elem,
  3122. numopts = ['eq','ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'],
  3123. stropts = ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 'nu', 'nn', 'in', 'ni'],
  3124. texts = $.jgrid.getRegional(ts, "search"),
  3125. common = $.jgrid.styleUI[(ts.p.styleUI || 'jQueryUI')].common;
  3126. if(!cm ) {
  3127. return;
  3128. }
  3129. rules = ts.p.colFilters && ts.p.colFilters[cm.name] ? ts.p.colFilters[cm.name] : false;
  3130. if(rules && !$.isEmptyObject( rules )) {
  3131. o1 = rules.oper1;
  3132. v1 = rules.value1;
  3133. r1 = rules.rule;
  3134. o2 = rules.oper2;
  3135. v2 = rules.value2;
  3136. }
  3137. if(! cm.searchoptions ) {
  3138. cm.searchoptions = {};
  3139. }
  3140. if(cm.searchoptions.sopt) {
  3141. so = cm.searchoptions.sopt;
  3142. } else if(cm.sorttype === 'text') {
  3143. so = stropts;
  3144. } else {
  3145. so = numopts;
  3146. }
  3147. if(cm.searchoptions.groupOps) {
  3148. op = cm.searchoptions.groupOps;
  3149. } else {
  3150. op = texts.groupOps;
  3151. }
  3152. //elem = $('<ul id="search_menu" class="ui-search-menu modal-content" role="menu" tabindex="0" style="left:'+left+'px;top:'+top+'px;"></ul>');
  3153. elem = $('<form></form>');
  3154. var str1= '<div>'+$.jgrid.getRegional(ts, "colmenu.searchTitle")+'</div>';
  3155. str1 += '<div><select id="oper1" class="'+colmenustyle.filter_select+'">';
  3156. $.each(texts.odata, function(i, n) {
  3157. selected = n.oper === o1 ? 'selected="selected"' : '';
  3158. if($.inArray(n.oper, so) !== -1) {
  3159. repstr += '<option value="'+n.oper+'" '+selected+'>'+n.text+'</option>';
  3160. }
  3161. });
  3162. str1 += repstr;
  3163. str1 += '</select></div>';
  3164. elem.append(str1);
  3165. var df="";
  3166. if(cm.searchoptions.defaultValue ) {
  3167. df = $.isFunction(cm.searchoptions.defaultValue) ? cm.searchoptions.defaultValue.call(ts) : cm.searchoptions.defaultValue;
  3168. }
  3169. //overwrite default value if restore from filters
  3170. if( v1 ) {
  3171. df = v1;
  3172. }
  3173. var soptions = $.extend(cm.searchoptions, {name:cm.index || cm.name, id: "sval1_" + ts.p.idPrefix+cm.name, oper:'search'}),
  3174. input = $.jgrid.createEl.call(ts, cm.stype, soptions , df, false, $.extend({},$.jgrid.ajaxOptions, ts.p.ajaxSelectOptions || {}));
  3175. $(input).addClass( colmenustyle.filter_input );
  3176. str1 = $('<div></div>').append(input);
  3177. elem.append(str1);
  3178. // and/or
  3179. str1 ='<div><select id="operand" class="'+colmenustyle.filter_select+'">';
  3180. $.each(op, function(i, n){
  3181. selected = n.op === r1 ? 'selected="selected"' : '';
  3182. str1 += "<option value='"+n.op+"' "+selected+">"+n.text+"</option>";
  3183. });
  3184. str1 += '</select></div>';
  3185. elem.append(str1);
  3186. //oper2
  3187. repstr ='';
  3188. $.each(texts.odata, function(i, n) {
  3189. selected = n.oper === o2 ? 'selected="selected"' : '';
  3190. if($.inArray(n.oper, so) !== -1) {
  3191. repstr += '<option value="'+n.oper+'" '+selected+'>'+n.text+'</option>';
  3192. }
  3193. });
  3194. str1 = '<div><select id="oper2" class="'+colmenustyle.filter_select+'">' + repstr +'</select></div>';
  3195. elem.append(str1);
  3196. // value2
  3197. if( v2 ) {
  3198. df = v2;
  3199. } else {
  3200. df = "";
  3201. }
  3202. soptions = $.extend(cm.searchoptions, {name:cm.index || cm.name, id: "sval2_" + ts.p.idPrefix+cm.name, oper:'search'});
  3203. input = $.jgrid.createEl.call(ts, cm.stype, soptions , df, false, $.extend({},$.jgrid.ajaxOptions, ts.p.ajaxSelectOptions || {}));
  3204. $(input).addClass( colmenustyle.filter_input );
  3205. str1 = $('<div></div>').append(input);
  3206. elem.append(str1);
  3207. // buttons
  3208. str1 = "<div>";
  3209. str1 +="<div class='search_buttons'><a tabindex='0' id='bs_reset' class='fm-button " + common.button +" ui-reset'>"+texts.Reset+"</a></div>";
  3210. str1 +="<div class='search_buttons'><a tabindex='0' id='bs_search' class='fm-button " + common.button + " ui-search'>"+texts.Find+"</a></div>";
  3211. str1 += "</div>";
  3212. elem.append(str1);
  3213. elem = $('<li class="ui-menu-item" role="presentation"></li>').append( elem );
  3214. elem = $('<ul id="search_menu" class="ui-search-menu modal-content" role="menu" tabindex="0" style="left:'+left+'px;top:'+top+'px;"></ul>').append(elem);
  3215. $(parent).append(elem);
  3216. $("#search_menu").addClass("ui-menu " + colmenustyle.menu_widget);
  3217. $("#bs_reset, #bs_search", "#search_menu").hover(function(){
  3218. $(this).addClass(hover);
  3219. },function(){
  3220. $(this).removeClass(hover);
  3221. });
  3222. $("#bs_reset", elem).on('click', function(e){
  3223. ts.p.colFilters[cm.name] = {};
  3224. ts.p.postData.filters = buildFilters();
  3225. ts.p.search = false;
  3226. $(ts).trigger("reloadGrid");
  3227. $("#column_menu").remove();
  3228. });
  3229. $("#bs_search", elem).on('click', function(e){
  3230. ts.p.colFilters[cm.name] = {
  3231. oper1: $("#oper1","#search_menu").val(),
  3232. value1: $("#sval1_" + ts.p.idPrefix+cm.name,"#search_menu").val(),
  3233. rule: $("#operand","#search_menu").val(),
  3234. oper2 : $("#oper2","#search_menu").val(),
  3235. value2 : $("#sval2_" + ts.p.idPrefix+cm.name,"#search_menu").val()
  3236. };
  3237. ts.p.postData.filters = buildFilters();
  3238. ts.p.search = true;
  3239. $(ts).trigger("reloadGrid");
  3240. $("#column_menu").remove();
  3241. });
  3242. },
  3243. buildFilters = function() {
  3244. var go = "AND",
  3245. filters ="{\"groupOp\":\"" + go + "\",\"rules\":[], \"groups\" : [", i=0;
  3246. for (var item in ts.p.colFilters) {
  3247. if(ts.p.colFilters.hasOwnProperty(item)) {
  3248. var si = ts.p.colFilters[item];
  3249. if(!$.isEmptyObject(si)) {
  3250. if(i>0) {
  3251. filters += ",";
  3252. }
  3253. filters += "{\"groupOp\": \""+si.rule +"\", \"rules\" : [";
  3254. filters += "{\"field\":\"" + item + "\",";
  3255. filters += "\"op\":\"" + si.oper1 + "\",";
  3256. si.value1 +="";
  3257. filters += "\"data\":\"" + si.value1.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  3258. if(si.value2) {
  3259. filters += ",{\"field\":\"" + item + "\",";
  3260. filters += "\"op\":\"" + si.oper2 + "\",";
  3261. si.value2 +="";
  3262. filters += "\"data\":\"" + si.value2.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  3263. }
  3264. filters += "]}";
  3265. i++;
  3266. } else {
  3267. //console.log('empty object');
  3268. }
  3269. }
  3270. }
  3271. filters += "]}";
  3272. return filters;
  3273. },
  3274. buildGrouping = function( index, isgroup ) {
  3275. var cm = ts.p.colModel[index],
  3276. group = ts.p.groupingView;
  3277. if(isgroup !== -1) {
  3278. group.groupField.splice(isgroup,1);
  3279. } else {
  3280. group.groupField.push( cm.name);
  3281. }
  3282. $(ts).jqGrid('groupingGroupBy', group.groupField );
  3283. if(ts.p.frozenColumns) {
  3284. $(ts).jqGrid("destroyFrozenColumns");
  3285. $(ts).jqGrid("setFrozenColumns");
  3286. }
  3287. },
  3288. buildFreeze = function( index, isfreeze ) {
  3289. var cols = [], i, len = ts.p.colModel.length, lastfrozen = -1, cm = ts.p.colModel;
  3290. for(i=0; i < len; i++) {
  3291. if(cm[i].frozen) {
  3292. lastfrozen = i;
  3293. }
  3294. cols.push(i);
  3295. }
  3296. // from position index to lastfrozen+1
  3297. cols.splice( index, 1);
  3298. cols.splice(lastfrozen + (isfreeze ? 1 : 0), 0, index);
  3299. cm[index].frozen = isfreeze;
  3300. $(ts).jqGrid("destroyFrozenColumns");
  3301. $(ts).jqGrid("remapColumns", cols, true);
  3302. $(ts).jqGrid("setFrozenColumns");
  3303. },
  3304. buildColMenu = function( index, left, top ){
  3305. //$("#sopt_menu").remove();
  3306. left=parseInt(left,10);
  3307. top=parseInt(top,10) + 25;
  3308. var fs = $('.ui-jqgrid-view').css('font-size') || '11px';
  3309. var str = '<ul id="column_menu" class="ui-search-menu modal-content column-menu" role="menu" tabindex="0" style="font-size:'+fs+';left:'+left+'px;top:'+top+'px;">',
  3310. cm = ts.p.colModel[index], op = $.extend({sorting:true, columns: true, filtering: true, seraching:true, grouping:true, freeze : true}, cm.coloptions),
  3311. texts = $.jgrid.getRegional(ts, "colmenu"),
  3312. label = ts.p.colNames[index],
  3313. isgroup, isfreeze; // ???
  3314. // sorting
  3315. if(op.sorting) {
  3316. str += '<li class="ui-menu-item" role="presentation"><a class="g-menu-item" tabindex="0" role="menuitem" value="sortasc"><table class="ui-common-table"><tr><td class="menu_icon"><span class="'+iconbase+' '+colmenustyle.icon_sort_asc+'"></span></td><td class="menu_text">'+texts.sortasc+'</td></tr></table></a></li>';
  3317. str += '<li class="ui-menu-item" role="presentation"><a class="g-menu-item" tabindex="0" role="menuitem" value="sortdesc"><table class="ui-common-table"><tr><td class="menu_icon"><span class="'+iconbase+' '+colmenustyle.icon_sort_desc+'"></span></td><td class="menu_text">'+texts.sortdesc+'</td></tr></table></a></li>';
  3318. }
  3319. if(op.columns) {
  3320. str += '<li class="ui-menu-item divider" role="separator"></li>';
  3321. str += '<li class="ui-menu-item" role="presentation"><a class="g-menu-item" tabindex="0" role="menuitem" value="columns"><table class="ui-common-table"><tr><td class="menu_icon"><span class="'+iconbase+' '+colmenustyle.icon_columns+'"></span></td><td class="menu_text">'+texts.columns+'</td></tr></table></a></li>';
  3322. }
  3323. if(op.filtering) {
  3324. str += '<li class="ui-menu-item divider" role="separator"></li>';
  3325. str += '<li class="ui-menu-item" role="presentation"><a class="g-menu-item" tabindex="0" role="menuitem" value="filtering"><table class="ui-common-table"><tr><td class="menu_icon"><span class="'+iconbase+' '+colmenustyle.icon_filter+'"></span></td><td class="menu_text">'+texts.filter + ' ' + label +'</td></tr></table></a></li>';
  3326. }
  3327. if(op.grouping) {
  3328. isgroup = $.inArray(cm.name, ts.p.groupingView.groupField);
  3329. str += '<li class="ui-menu-item divider" role="separator"></li>';
  3330. str += '<li class="ui-menu-item" role="presentation"><a class="g-menu-item" tabindex="0" role="menuitem" value="grouping"><table class="ui-common-table"><tr><td class="menu_icon"><span class="'+iconbase+' '+colmenustyle.icon_group+'"></span></td><td class="menu_text">'+(isgroup !== -1 ? texts.ungrouping: texts.grouping + ' ' + label)+'</td></tr></table></a></li>';
  3331. }
  3332. if(op.freeze) {
  3333. isfreeze = (cm.frozen && ts.p.frozenColumns) ? false : true;
  3334. str += '<li class="ui-menu-item divider" role="separator"></li>';
  3335. str += '<li class="ui-menu-item" role="presentation"><a class="g-menu-item" tabindex="0" role="menuitem" value="freeze"><table class="ui-common-table"><tr><td class="menu_icon"><span class="'+iconbase+' '+colmenustyle.icon_freeze+'"></span></td><td class="menu_text">'+(isfreeze ? (texts.freeze + " "+ label) : texts.unfreeze)+'</td></tr></table></a></li>';
  3336. }
  3337. str += "</ul>";
  3338. $('body').append( str );
  3339. $("#column_menu").addClass("ui-menu " + colmenustyle.menu_widget);
  3340. if(ts.p.direction === "ltr") {
  3341. var wcm = $("#column_menu").width() + 26;
  3342. $("#column_menu").css("left", (left- wcm)+'px');
  3343. }
  3344. $("#column_menu > li > a").hover(
  3345. function(){
  3346. $("#col_menu").remove();
  3347. $("#search_menu").remove();
  3348. var left1, top1;
  3349. if($(this).attr("value") === 'columns') {
  3350. left1 = $(this).parent().width()+18,
  3351. top1 = $(this).parent().position().top - 5;
  3352. buildColItems(top1, left1, $(this).parent());
  3353. }
  3354. if($(this).attr("value") === 'filtering') {
  3355. left1 = $(this).parent().width()+18,
  3356. top1 = $(this).parent().position().top - 5;
  3357. buildSearchBox(index, top1, left1, $(this).parent());
  3358. }
  3359. $(this).addClass(hover);
  3360. },
  3361. function(){ $(this).removeClass(hover); }
  3362. ).click(function(){
  3363. var v = $(this).attr("value"),
  3364. sobj = ts.grid.headers[index].el;
  3365. if(v === 'sortasc') {
  3366. sortData( "jqgh_"+ts.p.id+"_" + cm.name, index, true, 'asc', sobj);
  3367. } else if(v === 'sortdesc') {
  3368. sortData( "jqgh_"+ts.p.id+"_" + cm.name, index, true, 'desc', sobj);
  3369. } else if (v === 'grouping') {
  3370. buildGrouping(index, isgroup);
  3371. } else if( v==='freeze') {
  3372. buildFreeze( index, isfreeze);
  3373. }
  3374. if(v.indexOf('sort') !== -1 || v === 'grouping' || v==='freeze') {
  3375. $(this).remove();
  3376. }
  3377. });
  3378. },
  3379. colTemplate;
  3380. if(ts.p.colMenu) {
  3381. $("body").on('click', function(e){
  3382. if(!$(e.target).closest(".column-menu").length) {
  3383. $("#column_menu").remove();
  3384. }
  3385. });
  3386. }
  3387. this.p.id = this.id;
  3388. if ($.inArray(ts.p.multikey,sortkeys) === -1 ) {ts.p.multikey = false;}
  3389. ts.p.keyName=false;
  3390. for (i=0; i<ts.p.colModel.length;i++) {
  3391. colTemplate = typeof ts.p.colModel[i].template === "string" ?
  3392. ($.jgrid.cmTemplate != null && typeof $.jgrid.cmTemplate[ts.p.colModel[i].template] === "object" ? $.jgrid.cmTemplate[ts.p.colModel[i].template]: {}) :
  3393. ts.p.colModel[i].template;
  3394. ts.p.colModel[i] = $.extend(true, {}, ts.p.cmTemplate, colTemplate || {}, ts.p.colModel[i]);
  3395. if (ts.p.keyName === false && ts.p.colModel[i].key===true) {
  3396. ts.p.keyName = ts.p.colModel[i].name;
  3397. ts.p.keyIndex = i;
  3398. }
  3399. }
  3400. ts.p.sortorder = ts.p.sortorder.toLowerCase();
  3401. $.jgrid.cell_width = $.jgrid.cellWidth();
  3402. if(ts.p.grouping===true) {
  3403. ts.p.scroll = false;
  3404. ts.p.rownumbers = false;
  3405. //ts.p.subGrid = false; expiremental
  3406. ts.p.treeGrid = false;
  3407. ts.p.gridview = true;
  3408. }
  3409. if(this.p.treeGrid === true) {
  3410. try { $(this).jqGrid("setTreeGrid");} catch (_) {}
  3411. if(ts.p.datatype !== "local") { ts.p.localReader = {id: "_id_"}; }
  3412. }
  3413. if(this.p.subGrid) {
  3414. try { $(ts).jqGrid("setSubGrid");} catch (s){}
  3415. }
  3416. if(this.p.multiselect) {
  3417. this.p.colNames.unshift("<input role='checkbox' id='cb_"+this.p.id+"' class='cbox' type='checkbox'/>");
  3418. this.p.colModel.unshift({name:'cb',width:$.jgrid.cell_width ? ts.p.multiselectWidth+ts.p.cellLayout : ts.p.multiselectWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true, frozen: true});
  3419. }
  3420. if(this.p.rownumbers) {
  3421. this.p.colNames.unshift("");
  3422. this.p.colModel.unshift({name:'rn',width:ts.p.rownumWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true, frozen : true});
  3423. }
  3424. ts.p.xmlReader = $.extend(true,{
  3425. root: "rows",
  3426. row: "row",
  3427. page: "rows>page",
  3428. total: "rows>total",
  3429. records : "rows>records",
  3430. repeatitems: true,
  3431. cell: "cell",
  3432. id: "[id]",
  3433. userdata: "userdata",
  3434. subgrid: {root:"rows", row: "row", repeatitems: true, cell:"cell"}
  3435. }, ts.p.xmlReader);
  3436. ts.p.jsonReader = $.extend(true,{
  3437. root: "rows",
  3438. page: "page",
  3439. total: "total",
  3440. records: "records",
  3441. repeatitems: true,
  3442. cell: "cell",
  3443. id: "id",
  3444. userdata: "userdata",
  3445. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  3446. },ts.p.jsonReader);
  3447. ts.p.localReader = $.extend(true,{
  3448. root: "rows",
  3449. page: "page",
  3450. total: "total",
  3451. records: "records",
  3452. repeatitems: false,
  3453. cell: "cell",
  3454. id: "id",
  3455. userdata: "userdata",
  3456. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  3457. },ts.p.localReader);
  3458. if(ts.p.scroll){
  3459. ts.p.pgbuttons = false; ts.p.pginput=false; ts.p.rowList=[];
  3460. }
  3461. if(ts.p.data.length) {
  3462. normalizeData();
  3463. refreshIndex();
  3464. }
  3465. var thead = "<thead><tr class='ui-jqgrid-labels' role='row'>",
  3466. tdc, idn, w, res, sort ="",
  3467. td, ptr, tbody, imgs, iac="", idc="", tmpcm;
  3468. if(ts.p.shrinkToFit===true && ts.p.forceFit===true) {
  3469. for (i=ts.p.colModel.length-1;i>=0;i--){
  3470. if(!ts.p.colModel[i].hidden) {
  3471. ts.p.colModel[i].resizable=false;
  3472. break;
  3473. }
  3474. }
  3475. }
  3476. if(ts.p.viewsortcols[1] === 'horizontal') {
  3477. iac=" ui-i-asc";
  3478. idc=" ui-i-desc";
  3479. } else if(ts.p.viewsortcols[1] === "single") {
  3480. iac = " ui-single-sort-asc";
  3481. idc = " ui-single-sort-desc";
  3482. sort = " style='display:none'";
  3483. ts.p.viewsortcols[0] = false;
  3484. }
  3485. tdc = isMSIE ? "class='ui-th-div-ie'" :"";
  3486. imgs = "<span class='s-ico' style='display:none'>";
  3487. imgs += "<span sort='asc' class='ui-grid-ico-sort ui-icon-asc"+iac+" ui-sort-"+dir+" "+disabled+" " + iconbase + " " + getstyle(stylemodule, 'icon_asc', true)+ "'" + sort + "></span>";
  3488. imgs += "<span sort='desc' class='ui-grid-ico-sort ui-icon-desc"+idc+" ui-sort-"+dir+" "+disabled+" " + iconbase + " " + getstyle(stylemodule, 'icon_desc', true)+"'" + sort + "></span></span>";
  3489. if(ts.p.multiSort) {
  3490. if(ts.p.sortname ) {
  3491. sortarr = ts.p.sortname.split(",");
  3492. for (i=0; i < sortarr.length; i++) {
  3493. sotmp = $.trim(sortarr[i]).split(" ");
  3494. sortarr[i] = $.trim(sotmp[0]);
  3495. sortord[i] = sotmp[1] ? $.trim(sotmp[1]) : ts.p.sortorder || "asc";
  3496. }
  3497. }
  3498. }
  3499. for(i=0;i<this.p.colNames.length;i++){
  3500. var tooltip = ts.p.headertitles ? (" title=\""+$.jgrid.stripHtml(ts.p.colNames[i])+"\"") :"";
  3501. tmpcm = ts.p.colModel[i];
  3502. if(!tmpcm.hasOwnProperty('colmenu')) {
  3503. tmpcm.colmenu = (tmpcm.name === "rn" || tmpcm.name === "cb" || tmpcm.name === "subgrid") ? false : true;
  3504. }
  3505. thead += "<th id='"+ts.p.id+"_" + tmpcm.name+"' role='columnheader' "+getstyle(stylemodule,'headerBox',false, "ui-th-column ui-th-"+dir)+" "+ tooltip+">";
  3506. idn = tmpcm.index || tmpcm.name;
  3507. thead += "<div class='ui-th-div' id='jqgh_"+ts.p.id+"_"+tmpcm.name+"' "+tdc+">"+ts.p.colNames[i];
  3508. if(!tmpcm.width) {
  3509. tmpcm.width = 150;
  3510. } else {
  3511. tmpcm.width = parseInt(tmpcm.width,10);
  3512. }
  3513. if(typeof tmpcm.title !== "boolean") {
  3514. tmpcm.title = true;
  3515. }
  3516. tmpcm.lso = "";
  3517. if (idn === ts.p.sortname) {
  3518. ts.p.lastsort = i;
  3519. }
  3520. if(ts.p.multiSort) {
  3521. sotmp = $.inArray(idn,sortarr);
  3522. if( sotmp !== -1 ) {
  3523. tmpcm.lso = sortord[sotmp];
  3524. }
  3525. }
  3526. thead += imgs;
  3527. if(ts.p.colMenu && tmpcm.colmenu) {
  3528. thead += "<a class='colmenu' href='#/'><span class='colmenuspan "+iconbase+' '+colmenustyle.icon_menu+"'></span></a>";
  3529. }
  3530. thead += "</div></th>";
  3531. }
  3532. thead += "</tr></thead>";
  3533. imgs = null;
  3534. tmpcm = null;
  3535. $(this).append(thead);
  3536. $("thead tr:first th",this).hover(
  3537. function(){ $(this).addClass(hover);},
  3538. function(){ $(this).removeClass(hover);}
  3539. );
  3540. if(this.p.multiselect) {
  3541. var emp=[], chk;
  3542. $('#cb_'+$.jgrid.jqID(ts.p.id),this).on('click',function(){
  3543. ts.p.selarrrow = [];
  3544. var froz = ts.p.frozenColumns === true ? ts.p.id + "_frozen" : "";
  3545. if (this.checked) {
  3546. $(ts.rows).each(function(i) {
  3547. if (i>0) {
  3548. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass(disabled) && !$(this).hasClass("jqfoot")){
  3549. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  3550. $(this).addClass(highlight).attr("aria-selected","true");
  3551. ts.p.selarrrow.push(this.id);
  3552. ts.p.selrow = this.id;
  3553. if(froz) {
  3554. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  3555. $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).addClass(highlight);
  3556. }
  3557. }
  3558. }
  3559. });
  3560. chk=true;
  3561. emp=[];
  3562. }
  3563. else {
  3564. $(ts.rows).each(function(i) {
  3565. if(i>0) {
  3566. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass(disabled) && !$(this).hasClass("jqfoot")){
  3567. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked", false);
  3568. $(this).removeClass(highlight).attr("aria-selected","false");
  3569. emp.push(this.id);
  3570. if(froz) {
  3571. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",false);
  3572. $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).removeClass(highlight);
  3573. }
  3574. }
  3575. }
  3576. });
  3577. ts.p.selrow = null;
  3578. chk=false;
  3579. }
  3580. $(ts).triggerHandler("jqGridSelectAll", [chk ? ts.p.selarrrow : emp, chk]);
  3581. if($.isFunction(ts.p.onSelectAll)) {ts.p.onSelectAll.call(ts, chk ? ts.p.selarrrow : emp,chk);}
  3582. });
  3583. }
  3584. if(ts.p.autowidth===true) {
  3585. var pw = $(eg).innerWidth();
  3586. ts.p.width = pw > 0? pw: 'nw';
  3587. }
  3588. setColWidth();
  3589. $(eg).css("width",grid.width+"px").append("<div class='ui-jqgrid-resize-mark' id='rs_m"+ts.p.id+"'>&#160;</div>");
  3590. if(ts.p.scrollPopUp) {
  3591. $(eg).append("<div "+ getstyle(stylemodule, 'scrollBox', false, 'loading ui-scroll-popup')+" id='scroll_g"+ts.p.id+"'></div>");
  3592. }
  3593. $(gv).css("width",grid.width+"px");
  3594. thead = $("thead:first",ts).get(0);
  3595. var tfoot = "";
  3596. if(ts.p.footerrow) { tfoot += "<table role='presentation' style='width:"+ts.p.tblwidth+"px' "+getstyle(stylemodule,'footerTable', false, 'ui-jqgrid-ftable ui-common-table')+ "><tbody><tr role='row' "+getstyle(stylemodule,'footerBox', false, 'footrow footrow-'+dir)+">"; }
  3597. var thr = $("tr:first",thead),
  3598. firstr = "<tr class='jqgfirstrow' role='row'>";
  3599. ts.p.disableClick=false;
  3600. $("th",thr).each(function ( j ) {
  3601. tmpcm = ts.p.colModel[j];
  3602. w = tmpcm.width;
  3603. if(tmpcm.resizable === undefined) {
  3604. tmpcm.resizable = true;
  3605. }
  3606. if(tmpcm.resizable){
  3607. res = document.createElement("span");
  3608. $(res).html("&#160;").addClass('ui-jqgrid-resize ui-jqgrid-resize-'+dir)
  3609. .css("cursor","col-resize");
  3610. $(this).addClass(ts.p.resizeclass);
  3611. } else {
  3612. res = "";
  3613. }
  3614. $(this).css("width",w+"px").prepend(res);
  3615. res = null;
  3616. var hdcol = "";
  3617. if( tmpcm.hidden ) {
  3618. $(this).css("display","none");
  3619. hdcol = "display:none;";
  3620. }
  3621. firstr += "<td role='gridcell' style='height:0px;width:"+w+"px;"+hdcol+"'></td>";
  3622. grid.headers[j] = { width: w, el: this };
  3623. sort = tmpcm.sortable;
  3624. if( typeof sort !== 'boolean') {
  3625. tmpcm.sortable = true;
  3626. sort=true;
  3627. }
  3628. var nm = tmpcm.name;
  3629. if( !(nm === 'cb' || nm==='subgrid' || nm==='rn') ) {
  3630. if(ts.p.viewsortcols[2]){
  3631. $(">div",this).addClass('ui-jqgrid-sortable');
  3632. }
  3633. }
  3634. if(sort) {
  3635. if(ts.p.multiSort) {
  3636. if(ts.p.viewsortcols[0]) {
  3637. $("div span.s-ico",this).show();
  3638. if(ts.tmpcm.lso){
  3639. $("div span.ui-icon-"+tmpcm.lso,this).removeClass(disabled).css("display","");
  3640. }
  3641. } else if( tmpcm.lso) {
  3642. $("div span.s-ico",this).show();
  3643. $("div span.ui-icon-"+tmpcm.lso,this).removeClass(disabled).css("display","");
  3644. }
  3645. } else {
  3646. if(ts.p.viewsortcols[0]) {
  3647. $("div span.s-ico",this).show();
  3648. if(j===ts.p.lastsort){
  3649. $("div span.ui-icon-"+ts.p.sortorder,this).removeClass(disabled).css("display","");
  3650. }
  3651. } else if(j === ts.p.lastsort && ts.p.sortname !== "") {
  3652. $("div span.s-ico",this).show();
  3653. $("div span.ui-icon-"+ts.p.sortorder,this).removeClass(disabled).css("display","");
  3654. }
  3655. }
  3656. }
  3657. if(ts.p.footerrow) {
  3658. tfoot += "<td role='gridcell' "+formatCol(j,0,'', null, '', false)+">&#160;</td>";
  3659. }
  3660. }).mousedown(function(e) {
  3661. if ($(e.target).closest("th>span.ui-jqgrid-resize").length !== 1) { return; }
  3662. var ci = getColumnHeaderIndex(this);
  3663. if(ts.p.forceFit===true) {ts.p.nv= nextVisible(ci);}
  3664. grid.dragStart(ci, e, getOffset(ci));
  3665. return false;
  3666. }).click(function(e) {
  3667. if (ts.p.disableClick) {
  3668. ts.p.disableClick = false;
  3669. return false;
  3670. }
  3671. var s = "th>div.ui-jqgrid-sortable",r,d;
  3672. if (!ts.p.viewsortcols[2]) { s = "th>div>span>span.ui-grid-ico-sort"; }
  3673. var t = $(e.target).closest(s);
  3674. if (t.length !== 1) { return; }
  3675. var ci;
  3676. if(ts.p.frozenColumns) {
  3677. var tid = $(this)[0].id.substring( ts.p.id.length + 1 );
  3678. $(ts.p.colModel).each(function(i){
  3679. if (this.name === tid) {
  3680. ci = i;return false;
  3681. }
  3682. });
  3683. } else {
  3684. ci = getColumnHeaderIndex(this);
  3685. }
  3686. //
  3687. if($(e.target).hasClass('colmenuspan')) {
  3688. if($("#column_menu")[0] != null) {
  3689. $("#column_menu").remove();
  3690. }
  3691. var colindex = $.jgrid.getCellIndex(e.target);
  3692. if(colindex === -1) { return;}
  3693. var offset = $(this).offset(),
  3694. left = ( offset.left ),
  3695. top = ( offset.top);
  3696. if(ts.p.direction === "ltr") {
  3697. left += $(this).outerWidth();
  3698. }
  3699. buildColMenu(colindex, left, top, t );
  3700. e.stopPropagation();
  3701. return;
  3702. }
  3703. //
  3704. if (!ts.p.viewsortcols[2]) { r=true;d=t.attr("sort"); }
  3705. if(ci != null){
  3706. sortData( $('div',this)[0].id, ci, r, d, this);
  3707. }
  3708. return false;
  3709. });
  3710. tmpcm = null;
  3711. if (ts.p.sortable && $.fn.sortable) {
  3712. try {
  3713. $(ts).jqGrid("sortableColumns", thr);
  3714. } catch (e){}
  3715. }
  3716. if(ts.p.footerrow) { tfoot += "</tr></tbody></table>"; }
  3717. firstr += "</tr>";
  3718. tbody = document.createElement("tbody");
  3719. //$(this).append(firstr);
  3720. this.appendChild(tbody);
  3721. $(this).addClass(getstyle(stylemodule,"rowTable", true, 'ui-jqgrid-btable ui-common-table')).append(firstr);
  3722. if(ts.p.altRows) {
  3723. $(this).addClass(getstyle(stylemodule,"stripedTable", true, ''));
  3724. }
  3725. //$(firstr).insertAfter(this);
  3726. firstr = null;
  3727. var hTable = $("<table "+getstyle(stylemodule,'headerTable',false,'ui-jqgrid-htable ui-common-table')+" style='width:"+ts.p.tblwidth+"px' role='presentation' aria-labelledby='gbox_"+this.id+"'></table>").append(thead),
  3728. hg = (ts.p.caption && ts.p.hiddengrid===true) ? true : false,
  3729. hb = $("<div class='ui-jqgrid-hbox" + (dir==="rtl" ? "-rtl" : "" )+"'></div>"),
  3730. bstw = ts.p.styleUI === 'Bootstrap' && !isNaN(ts.p.height) ? 2 : 0;
  3731. thead = null;
  3732. grid.hDiv = document.createElement("div");
  3733. grid.hDiv.style.width = (grid.width - bstw) + "px";
  3734. grid.hDiv.className = getstyle(stylemodule,'headerDiv', true,'ui-jqgrid-hdiv');
  3735. $(grid.hDiv).append(hb);
  3736. $(hb).append(hTable);
  3737. hTable = null;
  3738. if(hg) { $(grid.hDiv).hide(); }
  3739. if(ts.p.pager){
  3740. // TBD -- escape ts.p.pager here?
  3741. if(typeof ts.p.pager === "string") {if(ts.p.pager.substr(0,1) !== "#") { ts.p.pager = "#"+ts.p.pager;} }
  3742. else { ts.p.pager = "#"+ $(ts.p.pager).attr("id");}
  3743. $(ts.p.pager).css({width: grid.width+"px"}).addClass(getstyle(stylemodule,'pagerBox', true,'ui-jqgrid-pager')).appendTo(eg);
  3744. if(hg) {$(ts.p.pager).hide();}
  3745. setPager(ts.p.pager,'');
  3746. }
  3747. if( ts.p.cellEdit === false && ts.p.hoverrows === true) {
  3748. $(ts).on({
  3749. mouseover: function(e) {
  3750. ptr = $(e.target).closest("tr.jqgrow");
  3751. if($(ptr).attr("class") !== "ui-subgrid") {
  3752. $(ptr).addClass(hover);
  3753. }
  3754. },
  3755. mouseout: function(e) {
  3756. ptr = $(e.target).closest("tr.jqgrow");
  3757. $(ptr).removeClass(hover);
  3758. }
  3759. });
  3760. }
  3761. var ri,ci, tdHtml;
  3762. function selectMultiRow(ri, scb, e, selection) {
  3763. if((ts.p.multiselect && ts.p.multiboxonly) || ts.p.multimail ) {
  3764. if(scb){
  3765. $(ts).jqGrid("setSelection", ri, selection, e);
  3766. } else if( ts.p.multiboxonly && ts.p.multimail) {
  3767. // execute onSelectRow
  3768. $(ts).triggerHandler("jqGridSelectRow", [ri, false, e]);
  3769. if( ts.p.onSelectRow) { ts.p.onSelectRow.call(ts, ri, false, e); }
  3770. } else {
  3771. var frz = ts.p.frozenColumns ? ts.p.id+"_frozen" : "";
  3772. $(ts.p.selarrrow).each(function(i,n){
  3773. var trid = $(ts).jqGrid('getGridRowById',n);
  3774. if(trid) {
  3775. $( trid ).removeClass(highlight);
  3776. }
  3777. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  3778. if(frz) {
  3779. $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz)).removeClass(highlight);
  3780. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  3781. }
  3782. });
  3783. ts.p.selarrrow = [];
  3784. $(ts).jqGrid("setSelection", ri, selection, e);
  3785. }
  3786. } else {
  3787. $(ts).jqGrid("setSelection", ri, selection, e);
  3788. }
  3789. }
  3790. $(ts).before(grid.hDiv).on({
  3791. 'click': function(e) {
  3792. td = e.target;
  3793. ptr = $(td,ts.rows).closest("tr.jqgrow");
  3794. if($(ptr).length === 0 || ptr[0].className.indexOf( disabled ) > -1 || ($(td,ts).closest("table.ui-jqgrid-btable").attr('id') || '').replace("_frozen","") !== ts.id ) {
  3795. return this;
  3796. }
  3797. var scb = $(td).filter(":enabled").hasClass("cbox"),
  3798. cSel = $(ts).triggerHandler("jqGridBeforeSelectRow", [ptr[0].id, e]);
  3799. cSel = (cSel === false || cSel === 'stop') ? false : true;
  3800. if ($.isFunction(ts.p.beforeSelectRow)) {
  3801. var allowRowSelect = ts.p.beforeSelectRow.call(ts, ptr[0].id, e);
  3802. if (allowRowSelect === false || allowRowSelect === 'stop') {
  3803. cSel = false;
  3804. }
  3805. }
  3806. if (td.tagName === 'A' || ((td.tagName === 'INPUT' || td.tagName === 'TEXTAREA' || td.tagName === 'OPTION' || td.tagName === 'SELECT' ) && !scb) ) { return; }
  3807. ri = ptr[0].id;
  3808. td = $(td).closest("tr.jqgrow>td");
  3809. if (td.length > 0) {
  3810. ci = $.jgrid.getCellIndex(td);
  3811. }
  3812. if(ts.p.cellEdit === true) {
  3813. if(ts.p.multiselect && scb && cSel){
  3814. $(ts).jqGrid("setSelection", ri ,true,e);
  3815. } else if (td.length > 0) {
  3816. try {
  3817. $(ts).jqGrid("editCell", ptr[0].rowIndex, ci, true);
  3818. } catch (_) {}
  3819. }
  3820. return;
  3821. }
  3822. if (td.length > 0) {
  3823. tdHtml = $(td).closest("td,th").html();
  3824. $(ts).triggerHandler("jqGridCellSelect", [ri,ci,tdHtml,e]);
  3825. if($.isFunction(ts.p.onCellSelect)) {
  3826. ts.p.onCellSelect.call(ts,ri,ci,tdHtml,e);
  3827. }
  3828. }
  3829. if (!cSel) {
  3830. return;
  3831. }
  3832. if( ts.p.multimail && ts.p.multiselect) {
  3833. if (e.shiftKey) {
  3834. if (scb) {
  3835. var initialRowSelect = $(ts).jqGrid('getGridParam', 'selrow'),
  3836. CurrentSelectIndex = $(ts).jqGrid('getInd', ri),
  3837. InitialSelectIndex = $(ts).jqGrid('getInd', initialRowSelect),
  3838. startID = "",
  3839. endID = "";
  3840. if (CurrentSelectIndex > InitialSelectIndex) {
  3841. startID = initialRowSelect;
  3842. endID = ri;
  3843. } else {
  3844. startID = ri;
  3845. endID = initialRowSelect;
  3846. }
  3847. var shouldSelectRow = false,
  3848. shouldResetRow = false,
  3849. perform_select = true;
  3850. if( $.inArray( ri, ts.p.selarrrow) > -1) {
  3851. perform_select = false;
  3852. }
  3853. $.each($(this).getDataIDs(), function(_, id){
  3854. if ((shouldResetRow = id === startID || shouldResetRow)){
  3855. $(ts).jqGrid('resetSelection', id);
  3856. }
  3857. return id !== endID;
  3858. });
  3859. if(perform_select) {
  3860. $.each($(this).getDataIDs(), function(_, id){
  3861. if ((shouldSelectRow = id === startID || shouldSelectRow)){
  3862. $(ts).jqGrid('setSelection', id, false);
  3863. }
  3864. return id !== endID;
  3865. });
  3866. }
  3867. ts.p.selrow = (CurrentSelectIndex > InitialSelectIndex) ? endID : startID;
  3868. return;
  3869. }
  3870. window.getSelection().removeAllRanges();
  3871. }
  3872. selectMultiRow( ri, scb, e, false );
  3873. } else if ( !ts.p.multikey ) {
  3874. selectMultiRow( ri, scb, e, true );
  3875. } else {
  3876. if(e[ts.p.multikey]) {
  3877. $(ts).jqGrid("setSelection", ri, true, e);
  3878. } else if(ts.p.multiselect && scb) {
  3879. scb = $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri).is(":checked");
  3880. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri)[ts.p.useProp ? 'prop' : 'attr']("checked", !scb);
  3881. }
  3882. }
  3883. },
  3884. 'reloadGrid': function(e,opts) {
  3885. if(ts.p.treeGrid ===true) {
  3886. ts.p.datatype = ts.p.treedatatype;
  3887. }
  3888. opts = opts || {};
  3889. if (opts.current) {
  3890. ts.grid.selectionPreserver(ts);
  3891. }
  3892. if(ts.p.datatype==="local"){
  3893. $(ts).jqGrid("resetSelection");
  3894. if(ts.p.data.length) {
  3895. normalizeData();
  3896. refreshIndex();
  3897. }
  3898. } else if(!ts.p.treeGrid) {
  3899. ts.p.selrow=null;
  3900. if(ts.p.multiselect) {
  3901. ts.p.selarrrow =[];
  3902. setHeadCheckBox(false);
  3903. }
  3904. ts.p.savedRow = [];
  3905. }
  3906. if(ts.p.scroll) {
  3907. emptyRows.call(ts, true, false);
  3908. }
  3909. if (opts.page) {
  3910. var page = opts.page;
  3911. if (page > ts.p.lastpage) { page = ts.p.lastpage; }
  3912. if (page < 1) { page = 1; }
  3913. ts.p.page = page;
  3914. if (ts.grid.prevRowHeight) {
  3915. ts.grid.bDiv.scrollTop = (page - 1) * ts.grid.prevRowHeight * ts.p.rowNum;
  3916. } else {
  3917. ts.grid.bDiv.scrollTop = 0;
  3918. }
  3919. }
  3920. if (ts.grid.prevRowHeight && ts.p.scroll && opts.page === undefined) {
  3921. delete ts.p.lastpage;
  3922. ts.grid.populateVisible();
  3923. } else {
  3924. ts.grid.populate();
  3925. }
  3926. if(ts.p.inlineNav===true) {$(ts).jqGrid('showAddEditButtons');}
  3927. return false;
  3928. },
  3929. 'dblclick' : function(e) {
  3930. td = e.target;
  3931. ptr = $(td,ts.rows).closest("tr.jqgrow");
  3932. if($(ptr).length === 0 ){return;}
  3933. ri = ptr[0].rowIndex;
  3934. ci = $.jgrid.getCellIndex(td);
  3935. var dbcr = $(ts).triggerHandler("jqGridDblClickRow", [$(ptr).attr("id"),ri,ci,e]);
  3936. if( dbcr != null) { return dbcr; }
  3937. if ($.isFunction(ts.p.ondblClickRow)) {
  3938. dbcr = ts.p.ondblClickRow.call(ts,$(ptr).attr("id"),ri,ci, e);
  3939. if( dbcr != null) { return dbcr; }
  3940. }
  3941. },
  3942. 'contextmenu' : function(e) {
  3943. td = e.target;
  3944. ptr = $(td,ts.rows).closest("tr.jqgrow");
  3945. if($(ptr).length === 0 ){return;}
  3946. if(!ts.p.multiselect) { $(ts).jqGrid("setSelection",ptr[0].id,true,e); }
  3947. ri = ptr[0].rowIndex;
  3948. ci = $.jgrid.getCellIndex(td);
  3949. var rcr = $(ts).triggerHandler("jqGridRightClickRow", [$(ptr).attr("id"),ri,ci,e]);
  3950. if( rcr != null) { return rcr; }
  3951. if ($.isFunction(ts.p.onRightClickRow)) {
  3952. rcr = ts.p.onRightClickRow.call(ts,$(ptr).attr("id"),ri,ci, e);
  3953. if( rcr != null) { return rcr; }
  3954. }
  3955. }
  3956. });
  3957. //---
  3958. grid.bDiv = document.createElement("div");
  3959. if(isMSIE) { if(String(ts.p.height).toLowerCase() === "auto") { ts.p.height = "100%"; } }
  3960. $(grid.bDiv)
  3961. .append($('<div style="position:relative;"></div>').append('<div></div>').append(this))
  3962. .addClass("ui-jqgrid-bdiv")
  3963. .css({ height: ts.p.height+(isNaN(ts.p.height)?"":"px"), width: (grid.width - bstw)+"px"})
  3964. .scroll(grid.scrollGrid);
  3965. $("table:first",grid.bDiv).css({width:ts.p.tblwidth+"px"});
  3966. if( !$.support.tbody ) { //IE
  3967. if( $("tbody",this).length === 2 ) { $("tbody:gt(0)",this).remove();}
  3968. }
  3969. if(ts.p.multikey){
  3970. if( $.jgrid.msie()) {
  3971. $(grid.bDiv).on("selectstart",function(){return false;});
  3972. } else {
  3973. $(grid.bDiv).on("mousedown",function(){return false;});
  3974. }
  3975. }
  3976. if(hg) { // hidden grid
  3977. $(grid.bDiv).hide();
  3978. }
  3979. var icoo = iconbase + " " + getstyle(stylemodule,'icon_caption_open', true),
  3980. icoc = iconbase + " " + getstyle(stylemodule,'icon_caption_close', true);
  3981. grid.cDiv = document.createElement("div");
  3982. var arf = ts.p.hidegrid===true ? $("<a role='link' class='ui-jqgrid-titlebar-close HeaderButton "+cornerall+"' title='"+($.jgrid.getRegional(ts, "defaults.showhide", ts.p.showhide) || "")+"'" + " />").hover(
  3983. function(){ arf.addClass(hover);},
  3984. function() {arf.removeClass(hover);})
  3985. .append("<span class='ui-jqgrid-headlink " + icoo +"'></span>").css((dir==="rtl"?"left":"right"),"0px") : "";
  3986. $(grid.cDiv).append(arf).append("<span class='ui-jqgrid-title'>"+ts.p.caption+"</span>")
  3987. .addClass("ui-jqgrid-titlebar ui-jqgrid-caption"+(dir==="rtl" ? "-rtl" :"" )+" "+getstyle(stylemodule,'gridtitleBox',true));
  3988. $(grid.cDiv).insertBefore(grid.hDiv);
  3989. if( ts.p.toolbar[0] ) {
  3990. var tbstyle = getstyle(stylemodule, 'customtoolbarBox', true, 'ui-userdata');
  3991. grid.uDiv = document.createElement("div");
  3992. if(ts.p.toolbar[1] === "top") {$(grid.uDiv).insertBefore(grid.hDiv);}
  3993. else if (ts.p.toolbar[1]==="bottom" ) {$(grid.uDiv).insertAfter(grid.hDiv);}
  3994. if(ts.p.toolbar[1]==="both") {
  3995. grid.ubDiv = document.createElement("div");
  3996. $(grid.uDiv).addClass( tbstyle + " ui-userdata-top").attr("id","t_"+this.id).insertBefore(grid.hDiv).width(grid.width - bstw);
  3997. $(grid.ubDiv).addClass( tbstyle + " ui-userdata-bottom").attr("id","tb_"+this.id).insertAfter(grid.hDiv).width(grid.width - bstw);
  3998. if(hg) {$(grid.ubDiv).hide();}
  3999. } else {
  4000. $(grid.uDiv).width(grid.width - bstw).addClass( tbstyle + " ui-userdata-top").attr("id","t_"+this.id);
  4001. }
  4002. if(hg) {$(grid.uDiv).hide();}
  4003. }
  4004. if(ts.p.toppager) {
  4005. ts.p.toppager = $.jgrid.jqID(ts.p.id)+"_toppager";
  4006. grid.topDiv = $("<div id='"+ts.p.toppager+"'></div>")[0];
  4007. ts.p.toppager = "#"+ts.p.toppager;
  4008. $(grid.topDiv).addClass(getstyle(stylemodule, 'toppagerBox', true, 'ui-jqgrid-toppager')).width(grid.width - bstw).insertBefore(grid.hDiv);
  4009. setPager(ts.p.toppager,'_t');
  4010. }
  4011. if(ts.p.footerrow) {
  4012. grid.sDiv = $("<div class='ui-jqgrid-sdiv'></div>")[0];
  4013. hb = $("<div class='ui-jqgrid-hbox"+(dir==="rtl"?"-rtl":"")+"'></div>");
  4014. $(grid.sDiv).append(hb).width(grid.width - bstw).insertAfter(grid.hDiv);
  4015. $(hb).append(tfoot);
  4016. grid.footers = $(".ui-jqgrid-ftable",grid.sDiv)[0].rows[0].cells;
  4017. if(ts.p.rownumbers) { grid.footers[0].className = getstyle(stylemodule, 'rownumBox', true, 'jqgrid-rownum'); }
  4018. if(hg) {$(grid.sDiv).hide();}
  4019. }
  4020. hb = null;
  4021. if(ts.p.caption) {
  4022. var tdt = ts.p.datatype;
  4023. if(ts.p.hidegrid===true) {
  4024. $(".ui-jqgrid-titlebar-close",grid.cDiv).click( function(e){
  4025. var onHdCl = $.isFunction(ts.p.onHeaderClick),
  4026. elems = ".ui-jqgrid-bdiv, .ui-jqgrid-hdiv, .ui-jqgrid-toppager, .ui-jqgrid-pager, .ui-jqgrid-sdiv",
  4027. counter, self = this;
  4028. if(ts.p.toolbar[0]===true) {
  4029. if( ts.p.toolbar[1]==='both') {
  4030. elems += ', #' + $(grid.ubDiv).attr('id');
  4031. }
  4032. elems += ', #' + $(grid.uDiv).attr('id');
  4033. }
  4034. counter = $(elems,"#gview_"+$.jgrid.jqID(ts.p.id)).length;
  4035. if(ts.p.gridstate === 'visible') {
  4036. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideUp("fast", function() {
  4037. counter--;
  4038. if (counter === 0) {
  4039. $("span",self).removeClass(icoo).addClass(icoc);
  4040. ts.p.gridstate = 'hidden';
  4041. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).hide(); }
  4042. $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]);
  4043. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  4044. }
  4045. });
  4046. } else if(ts.p.gridstate === 'hidden'){
  4047. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideDown("fast", function() {
  4048. counter--;
  4049. if (counter === 0) {
  4050. $("span",self).removeClass(icoc).addClass(icoo);
  4051. if(hg) {ts.p.datatype = tdt;populate();hg=false;}
  4052. ts.p.gridstate = 'visible';
  4053. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).show(); }
  4054. $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]);
  4055. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  4056. }
  4057. });
  4058. }
  4059. return false;
  4060. });
  4061. if(hg) {ts.p.datatype="local"; $(".ui-jqgrid-titlebar-close",grid.cDiv).trigger("click");}
  4062. }
  4063. } else {
  4064. $(grid.cDiv).hide();
  4065. if(!ts.p.toppager) {
  4066. $(grid.hDiv).addClass(getstyle(ts.p.styleUI+'.common', 'cornertop', true));
  4067. }
  4068. }
  4069. $(grid.hDiv).after(grid.bDiv)
  4070. .mousemove(function (e) {
  4071. if(grid.resizing){grid.dragMove(e);return false;}
  4072. });
  4073. $(".ui-jqgrid-labels",grid.hDiv).on("selectstart", function () { return false; });
  4074. $(document).on( "mouseup.jqGrid" + ts.p.id, function () {
  4075. if(grid.resizing) { grid.dragEnd( true ); return false;}
  4076. return true;
  4077. });
  4078. if(ts.p.direction === 'rtl') {
  4079. $(ts).on('jqGridAfterGridComplete.setRTLPadding',function(){
  4080. var vScrollWidth = grid.bDiv.offsetWidth - grid.bDiv.clientWidth;
  4081. //gridhbox = $("div:first",grid.hDiv);
  4082. ts.p.scrollOffset = vScrollWidth;
  4083. // for future implementation
  4084. //if (gridhbox.hasClass("ui-jqgrid-hbox-rtl")) {
  4085. $("div:first",grid.hDiv).css({paddingLeft: vScrollWidth + "px"});
  4086. //} else {
  4087. //gridhbox.css({paddingRight: vScrollWidth + "px"});
  4088. //}
  4089. grid.hDiv.scrollLeft = grid.bDiv.scrollLeft;
  4090. });
  4091. }
  4092. ts.formatCol = formatCol;
  4093. ts.sortData = sortData;
  4094. ts.updatepager = updatepager;
  4095. ts.refreshIndex = refreshIndex;
  4096. ts.setHeadCheckBox = setHeadCheckBox;
  4097. ts.constructTr = constructTr;
  4098. ts.formatter = function ( rowId, cellval , colpos, rwdat, act){return formatter(rowId, cellval , colpos, rwdat, act);};
  4099. $.extend(grid,{populate : populate, emptyRows: emptyRows, beginReq: beginReq, endReq: endReq});
  4100. this.grid = grid;
  4101. ts.addXmlData = function(d) {addXmlData( d );};
  4102. ts.addJSONData = function(d) {addJSONData( d );};
  4103. ts.addLocalData = function(d) { return addLocalData( d );};
  4104. this.grid.cols = this.rows[0].cells;
  4105. if ($.isFunction( ts.p.onInitGrid )) { ts.p.onInitGrid.call(ts); }
  4106. populate();
  4107. ts.p.hiddengrid=false;
  4108. if(ts.p.responsive) {
  4109. var supportsOrientationChange = "onorientationchange" in window,
  4110. orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
  4111. $(window).on( orientationEvent, function(){
  4112. $(ts).jqGrid('resizeGrid');
  4113. });
  4114. }
  4115. });
  4116. };
  4117. $.jgrid.extend({
  4118. getGridParam : function(name, module) {
  4119. var $t = this[0], ret;
  4120. if (!$t || !$t.grid) {return;}
  4121. if(module === undefined && typeof module !== 'string') {
  4122. module = 'jqGrid'; //$t.p
  4123. }
  4124. ret = $t.p;
  4125. if(module !== 'jqGrid') {
  4126. try {
  4127. ret = $($t).data( module );
  4128. } catch (e) {
  4129. ret = $t.p;
  4130. }
  4131. }
  4132. if (!name) { return ret; }
  4133. return ret[name] !== undefined ? ret[name] : null;
  4134. },
  4135. setGridParam : function (newParams, overwrite){
  4136. return this.each(function(){
  4137. if(overwrite == null) {
  4138. overwrite = false;
  4139. }
  4140. if (this.grid && typeof newParams === 'object') {
  4141. if(overwrite === true) {
  4142. var params = $.extend({}, this.p, newParams);
  4143. this.p = params;
  4144. } else {
  4145. $.extend(true,this.p,newParams);
  4146. }
  4147. }
  4148. });
  4149. },
  4150. getGridRowById: function ( rowid ) {
  4151. var row;
  4152. this.each( function(){
  4153. try {
  4154. //row = this.rows.namedItem( rowid );
  4155. var i = this.rows.length;
  4156. while(i--) {
  4157. if( rowid.toString() === this.rows[i].id) {
  4158. row = this.rows[i];
  4159. break;
  4160. }
  4161. }
  4162. } catch ( e ) {
  4163. row = $(this.grid.bDiv).find( "#" + $.jgrid.jqID( rowid ));
  4164. }
  4165. });
  4166. return row;
  4167. },
  4168. getDataIDs : function () {
  4169. var ids=[], i=0, len, j=0;
  4170. this.each(function(){
  4171. len = this.rows.length;
  4172. if(len && len>0){
  4173. while(i<len) {
  4174. if($(this.rows[i]).hasClass('jqgrow')) {
  4175. ids[j] = this.rows[i].id;
  4176. j++;
  4177. }
  4178. i++;
  4179. }
  4180. }
  4181. });
  4182. return ids;
  4183. },
  4184. setSelection : function(selection,onsr, e) {
  4185. return this.each(function(){
  4186. var $t = this, stat,pt, ner, ia, tpsr, fid, csr,
  4187. getstyle = $.jgrid.getMethod("getStyleUI"),
  4188. highlight = getstyle($t.p.styleUI+'.common','highlight', true),
  4189. disabled = getstyle($t.p.styleUI+'.common','disabled', true);
  4190. if(selection === undefined) { return; }
  4191. onsr = onsr === false ? false : true;
  4192. pt=$($t).jqGrid('getGridRowById', selection);
  4193. if(!pt || !pt.className || pt.className.indexOf( disabled ) > -1 ) { return; }
  4194. function scrGrid(iR){
  4195. var ch = $($t.grid.bDiv)[0].clientHeight,
  4196. st = $($t.grid.bDiv)[0].scrollTop,
  4197. rpos = $($t.rows[iR]).position().top,
  4198. rh = $t.rows[iR].clientHeight;
  4199. if(rpos+rh >= ch+st) { $($t.grid.bDiv)[0].scrollTop = rpos-(ch+st)+rh+st; }
  4200. else if(rpos < ch+st) {
  4201. if(rpos < st) {
  4202. $($t.grid.bDiv)[0].scrollTop = rpos;
  4203. }
  4204. }
  4205. }
  4206. if($t.p.scrollrows===true) {
  4207. ner = $($t).jqGrid('getGridRowById',selection).rowIndex;
  4208. if(ner >=0 ){
  4209. scrGrid(ner);
  4210. }
  4211. }
  4212. if($t.p.frozenColumns === true ) {
  4213. fid = $t.p.id+"_frozen";
  4214. }
  4215. if(!$t.p.multiselect) {
  4216. if(pt.className !== "ui-subgrid") {
  4217. if( $t.p.selrow !== pt.id ) {
  4218. csr = $($t).jqGrid('getGridRowById', $t.p.selrow);
  4219. if( csr ) {
  4220. $( csr ).removeClass(highlight).attr({"aria-selected":"false", "tabindex" : "-1"});
  4221. }
  4222. $(pt).addClass(highlight).attr({"aria-selected":"true", "tabindex" : "0"});//.focus();
  4223. if(fid) {
  4224. $("#"+$.jgrid.jqID($t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass(highlight);
  4225. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass(highlight);
  4226. }
  4227. stat = true;
  4228. } else {
  4229. stat = false;
  4230. }
  4231. $t.p.selrow = pt.id;
  4232. if( onsr ) {
  4233. $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]);
  4234. if( $t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id, stat, e); }
  4235. }
  4236. }
  4237. } else {
  4238. //unselect selectall checkbox when deselecting a specific row
  4239. $t.setHeadCheckBox( false );
  4240. $t.p.selrow = pt.id;
  4241. ia = $.inArray($t.p.selrow,$t.p.selarrrow);
  4242. if ( ia === -1 ){
  4243. if(pt.className !== "ui-subgrid") { $(pt).addClass(highlight).attr("aria-selected","true");}
  4244. stat = true;
  4245. $t.p.selarrrow.push($t.p.selrow);
  4246. } else {
  4247. if(pt.className !== "ui-subgrid") { $(pt).removeClass(highlight).attr("aria-selected","false");}
  4248. stat = false;
  4249. $t.p.selarrrow.splice(ia,1);
  4250. tpsr = $t.p.selarrrow[0];
  4251. $t.p.selrow = (tpsr === undefined) ? null : tpsr;
  4252. }
  4253. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(pt.id))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  4254. if(fid) {
  4255. if(ia === -1) {
  4256. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass(highlight);
  4257. } else {
  4258. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).removeClass(highlight);
  4259. }
  4260. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  4261. }
  4262. if( onsr ) {
  4263. $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]);
  4264. if( $t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id , stat, e); }
  4265. }
  4266. }
  4267. });
  4268. },
  4269. resetSelection : function( rowid ){
  4270. return this.each(function(){
  4271. var t = this, sr, fid,
  4272. getstyle = $.jgrid.getMethod("getStyleUI"),
  4273. highlight = getstyle(t.p.styleUI+'.common','highlight', true),
  4274. hover = getstyle(t.p.styleUI+'.common','hover', true);
  4275. if( t.p.frozenColumns === true ) {
  4276. fid = t.p.id+"_frozen";
  4277. }
  4278. if(rowid !== undefined ) {
  4279. sr = rowid === t.p.selrow ? t.p.selrow : rowid;
  4280. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(sr)).removeClass( highlight ).attr("aria-selected","false");
  4281. if (fid) { $("#"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid)).removeClass( highlight ); }
  4282. if(t.p.multiselect) {
  4283. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(t.p.id))[t.p.useProp ? 'prop': 'attr']("checked",false);
  4284. if(fid) { $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false); }
  4285. t.setHeadCheckBox( false);
  4286. var ia = $.inArray($.jgrid.jqID(sr), t.p.selarrrow);
  4287. if ( ia !== -1 ){
  4288. t.p.selarrrow.splice(ia,1);
  4289. }
  4290. }
  4291. if( t.p.onUnSelectRow) { t.p.onUnSelectRow.call(t, sr ); }
  4292. sr = null;
  4293. } else if(!t.p.multiselect) {
  4294. if(t.p.selrow) {
  4295. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(t.p.selrow)).removeClass( highlight ).attr("aria-selected","false");
  4296. if(fid) { $("#"+$.jgrid.jqID(t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass( highlight ); }
  4297. if( t.p.onUnSelectRow) { t.p.onUnSelectRow.call(t, t.p.selrow ); }
  4298. t.p.selrow = null;
  4299. }
  4300. } else {
  4301. $(t.p.selarrrow).each(function(i,n){
  4302. $( $(t).jqGrid('getGridRowById',n) ).removeClass( highlight ).attr("aria-selected","false");
  4303. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n))[t.p.useProp ? 'prop': 'attr']("checked",false);
  4304. if(fid) {
  4305. $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid)).removeClass( highlight );
  4306. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false);
  4307. }
  4308. if( t.p.onUnSelectRow) { t.p.onUnSelectRow.call(t, n); }
  4309. });
  4310. t.setHeadCheckBox( false );
  4311. t.p.selarrrow = [];
  4312. t.p.selrow = null;
  4313. }
  4314. if(t.p.cellEdit === true) {
  4315. if(parseInt(t.p.iCol,10)>=0 && parseInt(t.p.iRow,10)>=0) {
  4316. $("td:eq("+t.p.iCol+")",t.rows[t.p.iRow]).removeClass("edit-cell " + highlight );
  4317. $(t.rows[t.p.iRow]).removeClass("selected-row " + hover );
  4318. }
  4319. }
  4320. t.p.savedRow = [];
  4321. });
  4322. },
  4323. getRowData : function( rowid, usedata ) {
  4324. var res = {}, resall, getall=false, len, j=0;
  4325. this.each(function(){
  4326. var $t = this,nm,ind;
  4327. if(rowid == null) {
  4328. getall = true;
  4329. resall = [];
  4330. len = $t.rows.length-1;
  4331. } else {
  4332. ind = $($t).jqGrid('getGridRowById', rowid);
  4333. if(!ind) { return res; }
  4334. len = 1;
  4335. }
  4336. if( !(usedata && usedata === true && $t.p.data.length > 0) ) {
  4337. usedata = false;
  4338. }
  4339. while(j<len){
  4340. if(getall) {
  4341. ind = $t.rows[j+1]; // ignore first not visible row
  4342. }
  4343. if( $(ind).hasClass('jqgrow') ) {
  4344. if(usedata) {
  4345. res = $t.p.data[$t.p._index[ind.id]];
  4346. } else {
  4347. $('td[role="gridcell"]',ind).each( function(i) {
  4348. nm = $t.p.colModel[i].name;
  4349. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  4350. if($t.p.treeGrid===true && nm === $t.p.ExpandColumn) {
  4351. res[nm] = $.jgrid.htmlDecode($("span:first",this).html());
  4352. } else {
  4353. try {
  4354. res[nm] = $.unformat.call($t,this,{rowId:ind.id, colModel:$t.p.colModel[i]},i);
  4355. } catch (e){
  4356. res[nm] = $.jgrid.htmlDecode($(this).html());
  4357. }
  4358. }
  4359. }
  4360. });
  4361. }
  4362. if(getall) { resall.push(res); res={}; }
  4363. }
  4364. j++;
  4365. }
  4366. });
  4367. return resall || res;
  4368. },
  4369. delRowData : function(rowid) {
  4370. var success = false, rowInd, ia, nextRow;
  4371. this.each(function() {
  4372. var $t = this;
  4373. rowInd = $($t).jqGrid('getGridRowById', rowid);
  4374. if(!rowInd) {return false;}
  4375. if($t.p.subGrid) {
  4376. nextRow = $(rowInd).next();
  4377. if(nextRow.hasClass('ui-subgrid')) {
  4378. nextRow.remove();
  4379. }
  4380. }
  4381. $(rowInd).remove();
  4382. $t.p.records--;
  4383. $t.p.reccount--;
  4384. $t.updatepager(true,false);
  4385. success=true;
  4386. if($t.p.multiselect) {
  4387. ia = $.inArray(rowid,$t.p.selarrrow);
  4388. if(ia !== -1) { $t.p.selarrrow.splice(ia,1);}
  4389. }
  4390. if ($t.p.multiselect && $t.p.selarrrow.length > 0) {
  4391. $t.p.selrow = $t.p.selarrrow[$t.p.selarrrow.length-1];
  4392. } else {
  4393. if( $t.p.selrow === rowid ) {
  4394. $t.p.selrow = null;
  4395. }
  4396. }
  4397. if($t.p.datatype === 'local') {
  4398. var id = $.jgrid.stripPref($t.p.idPrefix, rowid),
  4399. pos = $t.p._index[id];
  4400. if(pos !== undefined) {
  4401. $t.p.data.splice(pos,1);
  4402. $t.refreshIndex();
  4403. }
  4404. }
  4405. });
  4406. return success;
  4407. },
  4408. setRowData : function(rowid, data, cssp) {
  4409. var nm, success=true, title;
  4410. this.each(function(){
  4411. if(!this.grid) {return false;}
  4412. var t = this, vl, ind, cp = typeof cssp, lcdata={};
  4413. ind = $(this).jqGrid('getGridRowById', rowid);
  4414. if(!ind) { return false; }
  4415. if( data ) {
  4416. try {
  4417. $(this.p.colModel).each(function(i){
  4418. nm = this.name;
  4419. var dval =$.jgrid.getAccessor(data,nm);
  4420. if( dval !== undefined) {
  4421. lcdata[nm] = this.formatter && typeof this.formatter === 'string' && this.formatter === 'date' ? $.unformat.date.call(t,dval,this) : dval;
  4422. vl = t.formatter( rowid, lcdata[nm], i, data, 'edit');
  4423. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  4424. if(t.p.treeGrid===true && nm === t.p.ExpandColumn) {
  4425. $("td[role='gridcell']:eq("+i+") > span:first",ind).html(vl).attr(title);
  4426. } else {
  4427. $("td[role='gridcell']:eq("+i+")",ind).html(vl).attr(title);
  4428. }
  4429. }
  4430. });
  4431. if(t.p.datatype === 'local') {
  4432. var id = $.jgrid.stripPref(t.p.idPrefix, rowid),
  4433. pos = t.p._index[id], key;
  4434. if(t.p.treeGrid) {
  4435. for(key in t.p.treeReader){
  4436. if(t.p.treeReader.hasOwnProperty(key)) {
  4437. delete lcdata[t.p.treeReader[key]];
  4438. }
  4439. }
  4440. }
  4441. if(pos !== undefined) {
  4442. t.p.data[pos] = $.extend(true, t.p.data[pos], lcdata);
  4443. }
  4444. lcdata = null;
  4445. }
  4446. } catch (e) {
  4447. success = false;
  4448. }
  4449. }
  4450. if(success) {
  4451. if(cp === 'string') {$(ind).addClass(cssp);} else if(cssp !== null && cp === 'object') {$(ind).css(cssp);}
  4452. $(t).triggerHandler("jqGridAfterGridComplete");
  4453. }
  4454. });
  4455. return success;
  4456. },
  4457. addRowData : function(rowid,rdata,pos,src) {
  4458. if($.inArray( pos, ["first", "last", "before", "after"] ) === -1) {pos = "last";}
  4459. var success = false, nm, row, rnc="", msc="", gi, si, ni,sind, i, v, prp="", aradd, cnm, data, cm, id;
  4460. if(rdata) {
  4461. if($.isArray(rdata)) {
  4462. aradd=true;
  4463. //pos = "last";
  4464. cnm = rowid;
  4465. } else {
  4466. rdata = [rdata];
  4467. aradd = false;
  4468. }
  4469. this.each(function() {
  4470. var t = this, datalen = rdata.length;
  4471. ni = t.p.rownumbers===true ? 1 :0;
  4472. gi = t.p.multiselect ===true ? 1 :0;
  4473. si = t.p.subGrid===true ? 1 :0;
  4474. if(!aradd) {
  4475. if(rowid !== undefined) { rowid = String(rowid);}
  4476. else {
  4477. rowid = $.jgrid.randId();
  4478. if(t.p.keyName !== false) {
  4479. cnm = t.p.keyName;
  4480. if(rdata[0][cnm] !== undefined) { rowid = rdata[0][cnm]; }
  4481. }
  4482. }
  4483. }
  4484. var k = 0, classes = $(t).jqGrid('getStyleUI',t.p.styleUI+".base",'rowBox', true, 'jqgrow ui-row-'+ t.p.direction), lcdata = {},
  4485. air = $.isFunction(t.p.afterInsertRow) ? true : false;
  4486. if(ni) {
  4487. rnc = $(t).jqGrid('getStyleUI',t.p.styleUI+".base",'rownumBox', false, 'jqgrid-rownum');
  4488. }
  4489. if(gi) {
  4490. msc = $(t).jqGrid('getStyleUI',t.p.styleUI+".base",'multiBox', false, 'cbox');
  4491. }
  4492. while(k < datalen) {
  4493. data = rdata[k];
  4494. row=[];
  4495. if(aradd) {
  4496. try {
  4497. rowid = data[cnm];
  4498. if(rowid===undefined) {
  4499. rowid = $.jgrid.randId();
  4500. }
  4501. }
  4502. catch (e) {rowid = $.jgrid.randId();}
  4503. }
  4504. id = rowid;
  4505. rowid = t.p.idPrefix + rowid;
  4506. if(ni){
  4507. prp = t.formatCol(0,1,'',null,rowid, true);
  4508. row[row.length] = "<td role=\"gridcell\" " + rnc +" "+prp+">0</td>";
  4509. }
  4510. if(gi) {
  4511. v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+t.p.id+"_"+rowid+"\" "+msc+"/>";
  4512. prp = t.formatCol(ni,1,'', null, rowid, true);
  4513. row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  4514. }
  4515. if(si) {
  4516. row[row.length] = $(t).jqGrid("addSubGridCell",gi+ni,1);
  4517. }
  4518. for(i = gi+si+ni; i < t.p.colModel.length;i++){
  4519. cm = t.p.colModel[i];
  4520. nm = cm.name;
  4521. lcdata[nm] = data[nm];
  4522. v = t.formatter( rowid, $.jgrid.getAccessor(data,nm), i, data );
  4523. prp = t.formatCol(i,1,v, data, rowid, lcdata);
  4524. row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  4525. }
  4526. row.unshift( t.constructTr(rowid, false, classes, lcdata, data ) );
  4527. row[row.length] = "</tr>";
  4528. if(t.rows.length === 0){
  4529. $("table:first",t.grid.bDiv).append(row.join(''));
  4530. } else {
  4531. switch (pos) {
  4532. case 'last':
  4533. $(t.rows[t.rows.length-1]).after(row.join(''));
  4534. sind = t.rows.length-1;
  4535. break;
  4536. case 'first':
  4537. $(t.rows[0]).after(row.join(''));
  4538. sind = 1;
  4539. break;
  4540. case 'after':
  4541. sind = $(t).jqGrid('getGridRowById', src);
  4542. if (sind) {
  4543. if($(t.rows[sind.rowIndex+1]).hasClass("ui-subgrid")) { $(t.rows[sind.rowIndex+1]).after(row); }
  4544. else { $(sind).after(row.join('')); }
  4545. sind=sind.rowIndex + 1;
  4546. }
  4547. break;
  4548. case 'before':
  4549. sind = $(t).jqGrid('getGridRowById', src);
  4550. if(sind) {
  4551. $(sind).before(row.join(''));
  4552. sind=sind.rowIndex - 1;
  4553. }
  4554. break;
  4555. }
  4556. }
  4557. if(t.p.subGrid===true) {
  4558. $(t).jqGrid("addSubGrid",gi+ni, sind);
  4559. }
  4560. t.p.records++;
  4561. t.p.reccount++;
  4562. $(t).triggerHandler("jqGridAfterInsertRow", [rowid,data,data]);
  4563. if(air) { t.p.afterInsertRow.call(t,rowid,data,data); }
  4564. k++;
  4565. if(t.p.datatype === 'local') {
  4566. lcdata[t.p.localReader.id] = id;
  4567. t.p._index[id] = t.p.data.length;
  4568. t.p.data.push(lcdata);
  4569. lcdata = {};
  4570. }
  4571. }
  4572. t.updatepager(true,true);
  4573. success = true;
  4574. });
  4575. }
  4576. return success;
  4577. },
  4578. footerData : function(action,data, format) {
  4579. var nm, success=false, res={}, title;
  4580. function isEmpty(obj) {
  4581. var i;
  4582. for(i in obj) {
  4583. if (obj.hasOwnProperty(i)) { return false; }
  4584. }
  4585. return true;
  4586. }
  4587. if(action === undefined) { action = "get"; }
  4588. if(typeof format !== "boolean") { format = true; }
  4589. action = action.toLowerCase();
  4590. this.each(function(){
  4591. var t = this, vl;
  4592. if(!t.grid || !t.p.footerrow) {return false;}
  4593. if(action === "set") { if(isEmpty(data)) { return false; } }
  4594. success=true;
  4595. $(this.p.colModel).each(function(i){
  4596. nm = this.name;
  4597. if(action === "set") {
  4598. if( data[nm] !== undefined) {
  4599. vl = format ? t.formatter( "", data[nm], i, data, 'edit') : data[nm];
  4600. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  4601. $("tr.footrow td:eq("+i+")",t.grid.sDiv).html(vl).attr(title);
  4602. success = true;
  4603. }
  4604. } else if(action === "get") {
  4605. res[nm] = $("tr.footrow td:eq("+i+")",t.grid.sDiv).html();
  4606. }
  4607. });
  4608. });
  4609. return action === "get" ? res : success;
  4610. },
  4611. showHideCol : function(colname,show) {
  4612. return this.each(function() {
  4613. var $t = this, fndh=false, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, cw;
  4614. if (!$t.grid ) {return;}
  4615. if( typeof colname === 'string') {colname=[colname];}
  4616. show = show !== "none" ? "" : "none";
  4617. var sw = show === "" ? true :false,
  4618. gh = $t.p.groupHeader && ($.isArray($t.p.groupHeader) || $.isFunction($t.p.groupHeader) );
  4619. if(gh) { $($t).jqGrid('destroyGroupHeader', false); }
  4620. $(this.p.colModel).each(function(i) {
  4621. if ($.inArray(this.name,colname) !== -1 && this.hidden === sw) {
  4622. if($t.p.frozenColumns === true && this.frozen === true) {
  4623. return true;
  4624. }
  4625. $("tr[role=row]",$t.grid.hDiv).each(function(){
  4626. $(this.cells[i]).css("display", show);
  4627. });
  4628. $($t.rows).each(function(){
  4629. if (!$(this).hasClass("jqgroup")) {
  4630. $(this.cells[i]).css("display", show);
  4631. }
  4632. });
  4633. if($t.p.footerrow) { $("tr.footrow td:eq("+i+")", $t.grid.sDiv).css("display", show); }
  4634. cw = parseInt(this.width,10);
  4635. if(show === "none") {
  4636. $t.p.tblwidth -= cw+brd;
  4637. } else {
  4638. $t.p.tblwidth += cw+brd;
  4639. }
  4640. this.hidden = !sw;
  4641. fndh=true;
  4642. $($t).triggerHandler("jqGridShowHideCol", [sw,this.name,i]);
  4643. }
  4644. });
  4645. if(fndh===true) {
  4646. if($t.p.shrinkToFit === true && !isNaN($t.p.height)) { $t.p.tblwidth += parseInt($t.p.scrollOffset,10);}
  4647. $($t).jqGrid("setGridWidth",$t.p.shrinkToFit === true ? $t.p.tblwidth : $t.p.width );
  4648. }
  4649. if( gh ) {
  4650. var gHead = $.extend([],$t.p.groupHeader);
  4651. $t.p.groupHeader = null;
  4652. for(var k =0; k < gHead.length; k++) {
  4653. $($t).jqGrid('setGroupHeaders', gHead[k]);
  4654. }
  4655. }
  4656. });
  4657. },
  4658. hideCol : function (colname) {
  4659. return this.each(function(){$(this).jqGrid("showHideCol",colname,"none");});
  4660. },
  4661. showCol : function(colname) {
  4662. return this.each(function(){$(this).jqGrid("showHideCol",colname,"");});
  4663. },
  4664. remapColumns : function(permutation, updateCells, keepHeader) {
  4665. function resortArray(a) {
  4666. var ac;
  4667. if (a.length) {
  4668. ac = $.makeArray(a);
  4669. } else {
  4670. ac = $.extend({}, a);
  4671. }
  4672. $.each(permutation, function(i) {
  4673. a[i] = ac[this];
  4674. });
  4675. }
  4676. var ts = this.get(0);
  4677. function resortRows(parent, clobj) {
  4678. $(">tr"+(clobj||""), parent).each(function() {
  4679. var row = this;
  4680. var elems = $.makeArray(row.cells);
  4681. $.each(permutation, function() {
  4682. var e = elems[this];
  4683. if (e) {
  4684. row.appendChild(e);
  4685. }
  4686. });
  4687. });
  4688. }
  4689. resortArray(ts.p.colModel);
  4690. resortArray(ts.p.colNames);
  4691. resortArray(ts.grid.headers);
  4692. resortRows($("thead:first", ts.grid.hDiv), keepHeader && ":not(.ui-jqgrid-labels)");
  4693. if (updateCells) {
  4694. resortRows($("#"+$.jgrid.jqID(ts.p.id)+" tbody:first"), ".jqgfirstrow, tr.jqgrow, tr.jqfoot");
  4695. }
  4696. if (ts.p.footerrow) {
  4697. resortRows($("tbody:first", ts.grid.sDiv));
  4698. }
  4699. if (ts.p.remapColumns) {
  4700. if (!ts.p.remapColumns.length){
  4701. ts.p.remapColumns = $.makeArray(permutation);
  4702. } else {
  4703. resortArray(ts.p.remapColumns);
  4704. }
  4705. }
  4706. ts.p.lastsort = $.inArray(ts.p.lastsort, permutation);
  4707. if(ts.p.treeGrid) { ts.p.expColInd = $.inArray(ts.p.expColInd, permutation); }
  4708. $(ts).triggerHandler("jqGridRemapColumns", [permutation, updateCells, keepHeader]);
  4709. },
  4710. setGridWidth : function(nwidth, shrink) {
  4711. return this.each(function(){
  4712. if (!this.grid ) {return;}
  4713. var $t = this, cw,
  4714. initwidth = 0, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, lvc, vc=0, hs=false, scw=$t.p.scrollOffset, aw, gw=0, cr, bstw = $t.p.styleUI === 'Bootstrap' ? 2 : 0;
  4715. if(typeof shrink !== 'boolean') {
  4716. shrink=$t.p.shrinkToFit;
  4717. }
  4718. if(isNaN(nwidth)) {return;}
  4719. nwidth = parseInt(nwidth,10);
  4720. $t.grid.width = $t.p.width = nwidth;
  4721. $("#gbox_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  4722. $("#gview_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  4723. $($t.grid.bDiv).css("width",(nwidth - bstw) +"px");
  4724. $($t.grid.hDiv).css("width",(nwidth - bstw) +"px");
  4725. if($t.p.pager ) {
  4726. $($t.p.pager).css("width",nwidth+"px");
  4727. }
  4728. if($t.p.toppager ) {
  4729. $($t.p.toppager).css("width",(nwidth - bstw)+"px");
  4730. }
  4731. if($t.p.toolbar[0] === true){
  4732. $($t.grid.uDiv).css("width",(nwidth - bstw)+"px");
  4733. if($t.p.toolbar[1]==="both") {$($t.grid.ubDiv).css("width",(nwidth - bstw)+"px");}
  4734. }
  4735. if($t.p.footerrow) {
  4736. $($t.grid.sDiv).css("width",(nwidth - bstw)+"px");
  4737. }
  4738. if(shrink ===false && $t.p.forceFit === true) {$t.p.forceFit=false;}
  4739. if(shrink===true) {
  4740. $.each($t.p.colModel, function() {
  4741. if(this.hidden===false){
  4742. cw = this.widthOrg;
  4743. initwidth += cw+brd;
  4744. if(this.fixed) {
  4745. gw += cw+brd;
  4746. } else {
  4747. vc++;
  4748. }
  4749. }
  4750. });
  4751. if(vc === 0) { return; }
  4752. $t.p.tblwidth = initwidth;
  4753. aw = nwidth-brd*vc-gw;
  4754. if(!isNaN($t.p.height)) {
  4755. if($($t.grid.bDiv)[0].clientHeight < $($t.grid.bDiv)[0].scrollHeight || $t.rows.length === 1){
  4756. hs = true;
  4757. aw -= scw;
  4758. }
  4759. }
  4760. initwidth =0;
  4761. var cle = $t.grid.cols.length >0;
  4762. $.each($t.p.colModel, function(i) {
  4763. if(this.hidden === false && !this.fixed){
  4764. cw = this.widthOrg;
  4765. cw = Math.round(aw*cw/($t.p.tblwidth-brd*vc-gw));
  4766. if (cw < 0) { return; }
  4767. this.width =cw;
  4768. initwidth += cw;
  4769. $t.grid.headers[i].width=cw;
  4770. $t.grid.headers[i].el.style.width=cw+"px";
  4771. if($t.p.footerrow) { $t.grid.footers[i].style.width = cw+"px"; }
  4772. if(cle) { $t.grid.cols[i].style.width = cw+"px"; }
  4773. lvc = i;
  4774. }
  4775. });
  4776. if (!lvc) { return; }
  4777. cr =0;
  4778. if (hs) {
  4779. if(nwidth-gw-(initwidth+brd*vc) !== scw){
  4780. cr = nwidth-gw-(initwidth+brd*vc)-scw;
  4781. }
  4782. } else if( Math.abs(nwidth-gw-(initwidth+brd*vc)) !== 1) {
  4783. cr = nwidth-gw-(initwidth+brd*vc);
  4784. }
  4785. $t.p.colModel[lvc].width += cr;
  4786. $t.p.tblwidth = initwidth+cr+brd*vc+gw;
  4787. if($t.p.tblwidth > nwidth) {
  4788. var delta = $t.p.tblwidth - parseInt(nwidth,10);
  4789. $t.p.tblwidth = nwidth;
  4790. cw = $t.p.colModel[lvc].width = $t.p.colModel[lvc].width-delta;
  4791. } else {
  4792. cw= $t.p.colModel[lvc].width;
  4793. }
  4794. $t.grid.headers[lvc].width = cw;
  4795. $t.grid.headers[lvc].el.style.width=cw+"px";
  4796. if(cle) { $t.grid.cols[lvc].style.width = cw+"px"; }
  4797. if($t.p.footerrow) {
  4798. $t.grid.footers[lvc].style.width = cw+"px";
  4799. }
  4800. }
  4801. if($t.p.tblwidth) {
  4802. $('table:first',$t.grid.bDiv).css("width",$t.p.tblwidth+"px");
  4803. $('table:first',$t.grid.hDiv).css("width",$t.p.tblwidth+"px");
  4804. $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
  4805. if($t.p.footerrow) {
  4806. $('table:first',$t.grid.sDiv).css("width",$t.p.tblwidth+"px");
  4807. }
  4808. }
  4809. });
  4810. },
  4811. setGridHeight : function (nh) {
  4812. return this.each(function (){
  4813. var $t = this;
  4814. if(!$t.grid) {return;}
  4815. var bDiv = $($t.grid.bDiv);
  4816. bDiv.css({height: nh+(isNaN(nh)?"":"px")});
  4817. if($t.p.frozenColumns === true){
  4818. //follow the original set height to use 16, better scrollbar width detection
  4819. $('#'+$.jgrid.jqID($t.p.id)+"_frozen").parent().height(bDiv.height() - 16);
  4820. }
  4821. $t.p.height = nh;
  4822. if ($t.p.scroll) { $t.grid.populateVisible(); }
  4823. });
  4824. },
  4825. setCaption : function (newcap){
  4826. return this.each(function(){
  4827. var ctop = $(this).jqGrid('getStyleUI',this.p.styleUI+".common",'cornertop', true);
  4828. this.p.caption=newcap;
  4829. $(".ui-jqgrid-title, .ui-jqgrid-title-rtl",this.grid.cDiv).html(newcap);
  4830. $(this.grid.cDiv).show();
  4831. $(this.grid.hDiv).removeClass(ctop);
  4832. });
  4833. },
  4834. setLabel : function(colname, nData, prop, attrp ){
  4835. return this.each(function(){
  4836. var $t = this, pos=-1;
  4837. if(!$t.grid) {return;}
  4838. if(colname != null) {
  4839. if(isNaN(colname)) {
  4840. $($t.p.colModel).each(function(i){
  4841. if (this.name === colname) {
  4842. pos = i;return false;
  4843. }
  4844. });
  4845. } else {
  4846. pos = parseInt(colname,10);
  4847. }
  4848. } else { return; }
  4849. if(pos>=0) {
  4850. var thecol = $("tr.ui-jqgrid-labels th:eq("+pos+")",$t.grid.hDiv);
  4851. if (nData){
  4852. var ico = $(".s-ico",thecol);
  4853. $("[id^=jqgh_]",thecol).empty().html(nData).append(ico);
  4854. $t.p.colNames[pos] = nData;
  4855. }
  4856. if (prop) {
  4857. if(typeof prop === 'string') {$(thecol).addClass(prop);} else {$(thecol).css(prop);}
  4858. }
  4859. if(typeof attrp === 'object') {$(thecol).attr(attrp);}
  4860. }
  4861. });
  4862. },
  4863. setSortIcon : function(colname, position) {
  4864. return this.each(function(){
  4865. var $t = this, pos=-1;
  4866. if(!$t.grid) {return;}
  4867. if(colname != null) {
  4868. if(isNaN(colname)) {
  4869. $($t.p.colModel).each(function(i){
  4870. if (this.name === colname) {
  4871. pos = i;return false;
  4872. }
  4873. });
  4874. } else {
  4875. pos = parseInt(colname,10);
  4876. }
  4877. } else {
  4878. return;
  4879. }
  4880. if(pos>=0) {
  4881. var thecol = $("tr.ui-jqgrid-labels th:eq("+pos+")",$t.grid.hDiv);
  4882. if(position === 'left') {
  4883. thecol.find(".s-ico").css("float", "left");
  4884. } else {
  4885. thecol.find(".s-ico").css("float", "none");
  4886. }
  4887. }
  4888. });
  4889. },
  4890. setCell : function(rowid,colname,nData,cssp,attrp, forceupd) {
  4891. return this.each(function(){
  4892. var $t = this, pos =-1,v, title;
  4893. if(!$t.grid) {return;}
  4894. if(isNaN(colname)) {
  4895. $($t.p.colModel).each(function(i){
  4896. if (this.name === colname) {
  4897. pos = i;return false;
  4898. }
  4899. });
  4900. } else {pos = parseInt(colname,10);}
  4901. if(pos>=0) {
  4902. var ind = $($t).jqGrid('getGridRowById', rowid);
  4903. if (ind){
  4904. var tcell = $("td:eq("+pos+")",ind), cl=0, rawdat=[];
  4905. if(nData !== "" || forceupd === true ) {
  4906. if(ind.cells !== undefined) {
  4907. while(cl<ind.cells.length) {
  4908. // slow down speed
  4909. rawdat.push(ind.cells[cl].innerHTML);
  4910. cl++;
  4911. }
  4912. }
  4913. v = $t.formatter(rowid, nData, pos, rawdat, 'edit');
  4914. title = $t.p.colModel[pos].title ? {"title":$.jgrid.stripHtml(v)} : {};
  4915. if($t.p.treeGrid && $(".tree-wrap",$(tcell)).length>0) {
  4916. $("span",$(tcell)).html(v).attr(title);
  4917. } else {
  4918. $(tcell).html(v).attr(title);
  4919. }
  4920. if($t.p.datatype === "local") {
  4921. var cm = $t.p.colModel[pos], index;
  4922. nData = cm.formatter && typeof cm.formatter === 'string' && cm.formatter === 'date' ? $.unformat.date.call($t,nData,cm) : nData;
  4923. index = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, rowid)];
  4924. if(index !== undefined) {
  4925. $t.p.data[index][cm.name] = nData;
  4926. }
  4927. }
  4928. }
  4929. if(typeof cssp === 'string'){
  4930. $(tcell).addClass(cssp);
  4931. } else if(cssp) {
  4932. $(tcell).css(cssp);
  4933. }
  4934. if(typeof attrp === 'object') {$(tcell).attr(attrp);}
  4935. }
  4936. }
  4937. });
  4938. },
  4939. getCell : function(rowid,col) {
  4940. var ret = false;
  4941. this.each(function(){
  4942. var $t=this, pos=-1, cnm, ind;
  4943. if(!$t.grid) {return;}
  4944. cnm = col;
  4945. if(isNaN(col)) {
  4946. $($t.p.colModel).each(function(i){
  4947. if (this.name === col) {
  4948. cnm = this.name;
  4949. pos = i;
  4950. return false;
  4951. }
  4952. });
  4953. } else {
  4954. pos = parseInt(col,10);
  4955. }
  4956. if(pos>=0) {
  4957. ind = $($t).jqGrid('getGridRowById', rowid);
  4958. if(ind) {
  4959. try {
  4960. ret = $.unformat.call($t,$("td:eq("+pos+")",ind),{rowId:ind.id, colModel:$t.p.colModel[pos]},pos);
  4961. } catch (e){
  4962. ret = $.jgrid.htmlDecode($("td:eq("+pos+")",ind).html());
  4963. }
  4964. }
  4965. if($t.p.treeGrid && ret && $t.p.ExpandColumn === cnm) {
  4966. ret = $( "<div>" + ret +"</div>").find("span:first").html();
  4967. }
  4968. }
  4969. });
  4970. return ret;
  4971. },
  4972. getCol : function (col, obj, mathopr) {
  4973. var ret = [], val, sum=0, min, max, v;
  4974. obj = typeof obj !== 'boolean' ? false : obj;
  4975. if(mathopr === undefined) { mathopr = false; }
  4976. this.each(function(){
  4977. var $t=this, pos=-1;
  4978. if(!$t.grid) {return;}
  4979. if(isNaN(col)) {
  4980. $($t.p.colModel).each(function(i){
  4981. if (this.name === col) {
  4982. pos = i;return false;
  4983. }
  4984. });
  4985. } else {pos = parseInt(col,10);}
  4986. if(pos>=0) {
  4987. var ln = $t.rows.length, i =0, dlen=0;
  4988. if (ln && ln>0){
  4989. while(i<ln){
  4990. if($($t.rows[i]).hasClass('jqgrow')) {
  4991. try {
  4992. val = $.unformat.call($t,$($t.rows[i].cells[pos]),{rowId:$t.rows[i].id, colModel:$t.p.colModel[pos]},pos);
  4993. } catch (e) {
  4994. val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML);
  4995. }
  4996. if(mathopr) {
  4997. v = parseFloat(val);
  4998. if(!isNaN(v)) {
  4999. sum += v;
  5000. if (max === undefined) {max = min = v;}
  5001. min = Math.min(min, v);
  5002. max = Math.max(max, v);
  5003. dlen++;
  5004. }
  5005. }
  5006. else if(obj) { ret.push( {id:$t.rows[i].id,value:val} ); }
  5007. else { ret.push( val ); }
  5008. }
  5009. i++;
  5010. }
  5011. if(mathopr) {
  5012. switch(mathopr.toLowerCase()){
  5013. case 'sum': ret =sum; break;
  5014. case 'avg': ret = sum/dlen; break;
  5015. case 'count': ret = (ln-1); break;
  5016. case 'min': ret = min; break;
  5017. case 'max': ret = max; break;
  5018. }
  5019. }
  5020. }
  5021. }
  5022. });
  5023. return ret;
  5024. },
  5025. clearGridData : function(clearfooter) {
  5026. return this.each(function(){
  5027. var $t = this;
  5028. if(!$t.grid) {return;}
  5029. if(typeof clearfooter !== 'boolean') { clearfooter = false; }
  5030. if($t.p.deepempty) {$("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:gt(0)").remove();}
  5031. else {
  5032. var trf = $("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:first")[0];
  5033. $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").empty().append(trf);
  5034. }
  5035. if($t.p.footerrow && clearfooter) { $(".ui-jqgrid-ftable td",$t.grid.sDiv).html("&#160;"); }
  5036. $t.p.selrow = null; $t.p.selarrrow= []; $t.p.savedRow = [];
  5037. $t.p.records = 0;$t.p.page=1;$t.p.lastpage=0;$t.p.reccount=0;
  5038. $t.p.data = []; $t.p._index = {};
  5039. $t.updatepager(true,false);
  5040. });
  5041. },
  5042. getInd : function(rowid,rc){
  5043. var ret =false,rw;
  5044. this.each(function(){
  5045. rw = $(this).jqGrid('getGridRowById', rowid);
  5046. if(rw) {
  5047. ret = rc===true ? rw: rw.rowIndex;
  5048. }
  5049. });
  5050. return ret;
  5051. },
  5052. bindKeys : function( settings ){
  5053. var o = $.extend({
  5054. onEnter: null,
  5055. onSpace: null,
  5056. onLeftKey: null,
  5057. onRightKey: null,
  5058. scrollingRows : true
  5059. },settings || {});
  5060. return this.each(function(){
  5061. var $t = this;
  5062. if( !$('body').is('[role]') ){$('body').attr('role','application');}
  5063. $t.p.scrollrows = o.scrollingRows;
  5064. $($t).keydown(function(event){
  5065. var target = $($t).find('tr[tabindex=0]')[0], id, r, mind,
  5066. expanded = $t.p.treeReader.expanded_field;
  5067. //check for arrow keys
  5068. if(target) {
  5069. mind = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, target.id)];
  5070. if(event.keyCode === 37 || event.keyCode === 38 || event.keyCode === 39 || event.keyCode === 40){
  5071. // up key
  5072. if(event.keyCode === 38 ){
  5073. r = target.previousSibling;
  5074. id = "";
  5075. if(r) {
  5076. if($(r).is(":hidden")) {
  5077. while(r) {
  5078. r = r.previousSibling;
  5079. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow')) {id = r.id;break;}
  5080. }
  5081. } else {
  5082. id = r.id;
  5083. }
  5084. }
  5085. $($t).jqGrid('setSelection', id, true, event);
  5086. event.preventDefault();
  5087. }
  5088. //if key is down arrow
  5089. if(event.keyCode === 40){
  5090. r = target.nextSibling;
  5091. id ="";
  5092. if(r) {
  5093. if($(r).is(":hidden")) {
  5094. while(r) {
  5095. r = r.nextSibling;
  5096. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow') ) {id = r.id;break;}
  5097. }
  5098. } else {
  5099. id = r.id;
  5100. }
  5101. }
  5102. $($t).jqGrid('setSelection', id, true, event);
  5103. event.preventDefault();
  5104. }
  5105. // left
  5106. if(event.keyCode === 37 ){
  5107. if($t.p.treeGrid && $t.p.data[mind][expanded]) {
  5108. $(target).find("div.treeclick").trigger('click');
  5109. }
  5110. $($t).triggerHandler("jqGridKeyLeft", [$t.p.selrow]);
  5111. if($.isFunction(o.onLeftKey)) {
  5112. o.onLeftKey.call($t, $t.p.selrow);
  5113. }
  5114. }
  5115. // right
  5116. if(event.keyCode === 39 ){
  5117. if($t.p.treeGrid && !$t.p.data[mind][expanded]) {
  5118. $(target).find("div.treeclick").trigger('click');
  5119. }
  5120. $($t).triggerHandler("jqGridKeyRight", [$t.p.selrow]);
  5121. if($.isFunction(o.onRightKey)) {
  5122. o.onRightKey.call($t, $t.p.selrow);
  5123. }
  5124. }
  5125. }
  5126. //check if enter was pressed on a grid or treegrid node
  5127. else if( event.keyCode === 13 ){
  5128. $($t).triggerHandler("jqGridKeyEnter", [$t.p.selrow]);
  5129. if($.isFunction(o.onEnter)) {
  5130. o.onEnter.call($t, $t.p.selrow);
  5131. }
  5132. } else if(event.keyCode === 32) {
  5133. $($t).triggerHandler("jqGridKeySpace", [$t.p.selrow]);
  5134. if($.isFunction(o.onSpace)) {
  5135. o.onSpace.call($t, $t.p.selrow);
  5136. }
  5137. }
  5138. }
  5139. });
  5140. });
  5141. },
  5142. unbindKeys : function(){
  5143. return this.each(function(){
  5144. $(this).off('keydown');
  5145. });
  5146. },
  5147. getLocalRow : function (rowid) {
  5148. var ret = false, ind;
  5149. this.each(function(){
  5150. if(rowid !== undefined) {
  5151. ind = this.p._index[$.jgrid.stripPref(this.p.idPrefix, rowid)];
  5152. if(ind >= 0 ) {
  5153. ret = this.p.data[ind];
  5154. }
  5155. }
  5156. });
  5157. return ret;
  5158. },
  5159. progressBar : function ( p ) {
  5160. p = $.extend({
  5161. htmlcontent : "",
  5162. method : "hide",
  5163. loadtype : "disable"
  5164. }, p || {});
  5165. return this.each(function(){
  5166. var sh = p.method==="show" ? true : false,
  5167. loadDiv = $("#load_"+$.jgrid.jqID(this.p.id)),
  5168. offsetParent, top,
  5169. scrollTop = $(window).scrollTop();
  5170. if(p.htmlcontent !== "") {
  5171. loadDiv.html( p.htmlcontent );
  5172. }
  5173. switch(p.loadtype) {
  5174. case "disable":
  5175. break;
  5176. case "enable":
  5177. loadDiv.toggle( sh );
  5178. break;
  5179. case "block":
  5180. $("#lui_"+$.jgrid.jqID(this.p.id)).toggle( sh );
  5181. loadDiv.toggle( sh );
  5182. break;
  5183. }
  5184. if (loadDiv.is(':visible')) {
  5185. offsetParent = loadDiv.offsetParent();
  5186. loadDiv.css('top', '');
  5187. if (loadDiv.offset().top < scrollTop) {
  5188. top = Math.min(
  5189. 10 + scrollTop - offsetParent.offset().top,
  5190. offsetParent.height() - loadDiv.height()
  5191. );
  5192. loadDiv.css('top', top + 'px');
  5193. }
  5194. }
  5195. });
  5196. },
  5197. getColProp : function(colname){
  5198. var ret ={}, $t = this[0];
  5199. if ( !$t.grid ) { return false; }
  5200. var cM = $t.p.colModel, i;
  5201. for ( i=0;i<cM.length;i++ ) {
  5202. if ( cM[i].name === colname ) {
  5203. ret = cM[i];
  5204. break;
  5205. }
  5206. }
  5207. return ret;
  5208. },
  5209. setColProp : function(colname, obj){
  5210. //do not set width will not work
  5211. return this.each(function(){
  5212. if ( this.grid ) {
  5213. if ( $.isPlainObject( obj ) ) {
  5214. var cM = this.p.colModel, i;
  5215. for ( i=0;i<cM.length;i++ ) {
  5216. if ( cM[i].name === colname ) {
  5217. $.extend(true, this.p.colModel[i],obj);
  5218. break;
  5219. }
  5220. }
  5221. }
  5222. }
  5223. });
  5224. },
  5225. sortGrid : function(colname,reload, sor){
  5226. return this.each(function(){
  5227. var $t=this,idx=-1,i, sobj=false;
  5228. if ( !$t.grid ) { return;}
  5229. if ( !colname ) { colname = $t.p.sortname; }
  5230. for ( i=0;i<$t.p.colModel.length;i++ ) {
  5231. if ( $t.p.colModel[i].index === colname || $t.p.colModel[i].name === colname ) {
  5232. idx = i;
  5233. if($t.p.frozenColumns === true && $t.p.colModel[i].frozen === true) {
  5234. sobj = $t.grid.fhDiv.find("#" + $t.p.id + "_" + colname);
  5235. }
  5236. break;
  5237. }
  5238. }
  5239. if ( idx !== -1 ){
  5240. var sort = $t.p.colModel[idx].sortable;
  5241. if(!sobj) {
  5242. sobj = $t.grid.headers[idx].el;
  5243. }
  5244. if ( typeof sort !== 'boolean' ) { sort = true; }
  5245. if ( typeof reload !=='boolean' ) { reload = false; }
  5246. if ( sort ) { $t.sortData("jqgh_"+$t.p.id+"_" + colname, idx, reload, sor, sobj); }
  5247. }
  5248. });
  5249. },
  5250. setGridState : function(state) {
  5251. return this.each(function(){
  5252. if ( !this.grid ) {return;}
  5253. var $t = this,
  5254. open = $(this).jqGrid('getStyleUI',this.p.styleUI+".base",'icon_caption_open', true),
  5255. close = $(this).jqGrid('getStyleUI',this.p.styleUI+".base",'icon_caption_close', true);
  5256. if(state === 'hidden'){
  5257. $(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv","#gview_"+$.jgrid.jqID($t.p.id)).slideUp("fast");
  5258. if($t.p.pager) {$($t.p.pager).slideUp("fast");}
  5259. if($t.p.toppager) {$($t.p.toppager).slideUp("fast");}
  5260. if($t.p.toolbar[0]===true) {
  5261. if( $t.p.toolbar[1] === 'both') {
  5262. $($t.grid.ubDiv).slideUp("fast");
  5263. }
  5264. $($t.grid.uDiv).slideUp("fast");
  5265. }
  5266. if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$.jgrid.jqID($t.p.id)).slideUp("fast"); }
  5267. $(".ui-jqgrid-headlink",$t.grid.cDiv).removeClass( open ).addClass( close );
  5268. $t.p.gridstate = 'hidden';
  5269. } else if(state === 'visible') {
  5270. $(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv","#gview_"+$.jgrid.jqID($t.p.id)).slideDown("fast");
  5271. if($t.p.pager) {$($t.p.pager).slideDown("fast");}
  5272. if($t.p.toppager) {$($t.p.toppager).slideDown("fast");}
  5273. if($t.p.toolbar[0]===true) {
  5274. if( $t.p.toolbar[1] === 'both') {
  5275. $($t.grid.ubDiv).slideDown("fast");
  5276. }
  5277. $($t.grid.uDiv).slideDown("fast");
  5278. }
  5279. if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$.jgrid.jqID($t.p.id)).slideDown("fast"); }
  5280. $(".ui-jqgrid-headlink",$t.grid.cDiv).removeClass( close ).addClass( open );
  5281. $t.p.gridstate = 'visible';
  5282. }
  5283. });
  5284. },
  5285. setFrozenColumns : function () {
  5286. return this.each(function() {
  5287. if ( !this.grid ) {return;}
  5288. var $t = this, cm = $t.p.colModel,i=0, len = cm.length, maxfrozen = -1, frozen= false,
  5289. hd= $($t).jqGrid('getStyleUI',$t.p.styleUI+".base",'headerDiv', true, 'ui-jqgrid-hdiv'),
  5290. hover = $($t).jqGrid('getStyleUI',$t.p.styleUI+".common",'hover', true),
  5291. borderbox = $("#gbox_"+$.jgrid.jqID($t.p.id)).css("box-sizing") === 'border-box',
  5292. pixelfix = borderbox ? 1 : 0;
  5293. // TODO treeGrid and grouping Support
  5294. if($t.p.subGrid === true ||
  5295. $t.p.treeGrid === true ||
  5296. $t.p.cellEdit === true ||
  5297. $t.p.sortable ||
  5298. $t.p.scroll ||
  5299. $t.p.grouping === true)
  5300. {
  5301. return;
  5302. }
  5303. // get the max index of frozen col
  5304. while(i<len)
  5305. {
  5306. // from left, no breaking frozen
  5307. if(cm[i].frozen === true)
  5308. {
  5309. frozen = true;
  5310. maxfrozen = i;
  5311. } else {
  5312. break;
  5313. }
  5314. i++;
  5315. }
  5316. if( maxfrozen>=0 && frozen) {
  5317. var top = $t.p.caption ? $($t.grid.cDiv).outerHeight() : 0,
  5318. hth = parseInt( $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).height(), 10),
  5319. divhth = parseInt( $(".ui-jqgrid-hdiv","#gview_"+$.jgrid.jqID($t.p.id)).height(), 10);
  5320. //headers
  5321. if($t.p.toppager) {
  5322. top = top + $($t.grid.topDiv).outerHeight();
  5323. }
  5324. if($t.p.toolbar[0] === true) {
  5325. if($t.p.toolbar[1] !== "bottom") {
  5326. top = top + $($t.grid.uDiv).outerHeight();
  5327. }
  5328. }
  5329. $t.grid.fhDiv = $('<div style="position:absolute;' + ($t.p.direction === "rtl" ? 'right:0;' : 'left:0;') + 'top:'+top+'px;height:'+(divhth - pixelfix)+'px;" class="frozen-div ' + hd +'"></div>');
  5330. $t.grid.fbDiv = $('<div style="position:absolute;' + ($t.p.direction === "rtl" ? 'right:0;' : 'left:0;') + 'top:'+(parseInt(top,10)+parseInt(divhth,10) + 1 - pixelfix)+'px;overflow-y:hidden" class="frozen-bdiv ui-jqgrid-bdiv"></div>');
  5331. $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fhDiv);
  5332. var htbl = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).clone(true);
  5333. // groupheader support - only if useColSpanstyle is false
  5334. if($t.p.groupHeader) {
  5335. $("tr.jqg-first-row-header, tr.jqg-third-row-header", htbl).each(function(){
  5336. $("th:gt("+maxfrozen+")",this).remove();
  5337. });
  5338. var swapfroz = -1, fdel = -1, cs, rs;
  5339. $("tr.jqg-second-row-header th", htbl).each(function(){
  5340. cs= parseInt($(this).attr("colspan"),10);
  5341. rs= parseInt($(this).attr("rowspan"),10);
  5342. if(rs) {
  5343. swapfroz++;
  5344. fdel++;
  5345. }
  5346. if(cs) {
  5347. swapfroz = swapfroz+cs;
  5348. fdel++;
  5349. }
  5350. if(swapfroz === maxfrozen) {
  5351. fdel = maxfrozen;
  5352. return false;
  5353. }
  5354. });
  5355. if(swapfroz !== maxfrozen) {
  5356. fdel = maxfrozen;
  5357. }
  5358. $("tr.jqg-second-row-header", htbl).each(function(){
  5359. $("th:gt("+fdel+")",this).remove();
  5360. });
  5361. } else {
  5362. var maxdh=[];
  5363. $(".ui-jqgrid-htable tr","#gview_"+$.jgrid.jqID($t.p.id)).each(function(i,n){
  5364. maxdh.push(parseInt($(this).height(),10));
  5365. });
  5366. $("tr",htbl).each(function(){
  5367. $("th:gt("+maxfrozen+")",this).remove();
  5368. });
  5369. $("tr",htbl).each(function(i){
  5370. $(this).height(maxdh[i]);
  5371. });
  5372. }
  5373. $(htbl).width(1);
  5374. if(!$.jgrid.msie()) {
  5375. $(htbl).css("height","100%");
  5376. }
  5377. // resizing stuff
  5378. $($t.grid.fhDiv).append(htbl)
  5379. .mousemove(function (e) {
  5380. if($t.grid.resizing){ $t.grid.dragMove(e);return false; }
  5381. });
  5382. if($t.p.footerrow) {
  5383. var hbd = $(".ui-jqgrid-bdiv","#gview_"+$.jgrid.jqID($t.p.id)).height();
  5384. $t.grid.fsDiv = $('<div style="position:absolute;left:0px;top:'+(parseInt(top,10)+parseInt(hth,10) + parseInt(hbd,10) + 1 - pixelfix)+'px;" class="frozen-sdiv ui-jqgrid-sdiv"></div>');
  5385. $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fsDiv);
  5386. var ftbl = $(".ui-jqgrid-ftable","#gview_"+$.jgrid.jqID($t.p.id)).clone(true);
  5387. $("tr",ftbl).each(function(){
  5388. $("td:gt("+maxfrozen+")",this).remove();
  5389. });
  5390. $(ftbl).width(1);
  5391. $($t.grid.fsDiv).append(ftbl);
  5392. }
  5393. $($t).on('jqGridResizeStop.setFrozenColumns', function (e, w, index) {
  5394. var boxwidth = borderbox ? 'outerWidth' : 'width',
  5395. rhth = $(".ui-jqgrid-htable",$t.grid.fhDiv),
  5396. btd = $(".ui-jqgrid-btable",$t.grid.fbDiv);
  5397. $("th:eq("+index+")", rhth)[boxwidth]( w );
  5398. $("tr:first td:eq("+index+")", btd)[boxwidth]( w );
  5399. if($t.p.footerrow) {
  5400. var ftd = $(".ui-jqgrid-ftable",$t.grid.fsDiv);
  5401. $("tr:first td:eq("+index+")", ftd)[boxwidth]( w );
  5402. }
  5403. });
  5404. // data stuff
  5405. //TODO support for setRowData
  5406. $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fbDiv);
  5407. $($t.grid.fbDiv).on('mousewheel DOMMouseScroll', function (e) {
  5408. var st = $($t.grid.bDiv).scrollTop();
  5409. if (e.originalEvent.wheelDelta > 0 || e.originalEvent.detail < 0) {
  5410. //up
  5411. $($t.grid.bDiv).scrollTop( st - 25 );
  5412. } else {
  5413. //down
  5414. $($t.grid.bDiv).scrollTop( st + 25 );
  5415. }
  5416. e.preventDefault();
  5417. });
  5418. if($t.p.hoverrows === true) {
  5419. $("#"+$.jgrid.jqID($t.p.id)).off('mouseover mouseout');
  5420. }
  5421. $($t).on('jqGridAfterGridComplete.setFrozenColumns', function () {
  5422. $("#"+$.jgrid.jqID($t.p.id)+"_frozen").remove();
  5423. $($t.grid.fbDiv).height($($t.grid.bDiv).height() - 17);
  5424. // find max height
  5425. var mh = [];
  5426. $("#"+$.jgrid.jqID($t.p.id) + " tr[role=row].jqgrow").each(function(){
  5427. mh.push( $(this).outerHeight() );
  5428. });
  5429. var btbl = $("#"+$.jgrid.jqID($t.p.id)).clone(true);
  5430. $("tr[role=row]",btbl).each(function(){
  5431. $("td[role=gridcell]:gt("+maxfrozen+")",this).remove();
  5432. });
  5433. $(btbl).width(1).attr("id",$t.p.id+"_frozen");
  5434. $($t.grid.fbDiv).append(btbl);
  5435. // set the height
  5436. $("tr[role=row].jqgrow",btbl).each(function(i, n){
  5437. $(this).height( mh[i] );
  5438. });
  5439. if($t.p.hoverrows === true) {
  5440. $("tr.jqgrow", btbl).hover(
  5441. function(){ $(this).addClass( hover ); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).addClass( hover ); },
  5442. function(){ $(this).removeClass( hover ); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).removeClass( hover ); }
  5443. );
  5444. $("tr.jqgrow", "#"+$.jgrid.jqID($t.p.id)).hover(
  5445. function(){ $(this).addClass( hover ); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").addClass( hover );},
  5446. function(){ $(this).removeClass( hover ); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").removeClass( hover ); }
  5447. );
  5448. }
  5449. btbl=null;
  5450. });
  5451. if(!$t.grid.hDiv.loading) {
  5452. $($t).triggerHandler("jqGridAfterGridComplete");
  5453. }
  5454. $t.p.frozenColumns = true;
  5455. }
  5456. });
  5457. },
  5458. destroyFrozenColumns : function() {
  5459. return this.each(function() {
  5460. if ( !this.grid ) {return;}
  5461. if(this.p.frozenColumns === true) {
  5462. var $t = this,
  5463. hover = $($t).jqGrid('getStyleUI',$t.p.styleUI+".common",'hover', true);
  5464. $($t.grid.fhDiv).remove();
  5465. $($t.grid.fbDiv).remove();
  5466. $t.grid.fhDiv = null; $t.grid.fbDiv=null;
  5467. if($t.p.footerrow) {
  5468. $($t.grid.fsDiv).remove();
  5469. $t.grid.fsDiv = null;
  5470. }
  5471. $(this).off('.setFrozenColumns');
  5472. if($t.p.hoverrows === true) {
  5473. var ptr;
  5474. $("#"+$.jgrid.jqID($t.p.id)).on({
  5475. 'mouseover': function(e) {
  5476. ptr = $(e.target).closest("tr.jqgrow");
  5477. if($(ptr).attr("class") !== "ui-subgrid") {
  5478. $(ptr).addClass( hover );
  5479. }
  5480. },
  5481. 'mouseout' : function(e) {
  5482. ptr = $(e.target).closest("tr.jqgrow");
  5483. $(ptr).removeClass( hover );
  5484. }
  5485. });
  5486. }
  5487. this.p.frozenColumns = false;
  5488. }
  5489. });
  5490. },
  5491. resizeColumn : function (iCol, newWidth, forceresize) {
  5492. return this.each(function(){
  5493. var grid = this.grid, p = this.p, cm = p.colModel, i, cmLen = cm.length, diff, diffnv;
  5494. if(typeof iCol === "string" ) {
  5495. for(i = 0; i < cmLen; i++) {
  5496. if(cm[i].name === iCol) {
  5497. iCol = i;
  5498. break;
  5499. }
  5500. }
  5501. } else {
  5502. iCol = parseInt( iCol, 10 );
  5503. }
  5504. if(forceresize === undefined) {
  5505. forceresize = false;
  5506. }
  5507. if( !cm[iCol].resizable && !forceresize ) {
  5508. return;
  5509. }
  5510. newWidth = parseInt( newWidth, 10);
  5511. // filters
  5512. if(typeof iCol !== "number" || iCol < 0 || iCol > cm.length-1 || typeof newWidth !== "number" ) {
  5513. return;
  5514. }
  5515. if( newWidth < p.minColWidth ) { return; }
  5516. if( p.forceFit ) {
  5517. p.nv = 0;
  5518. for (i = iCol+1; i < cmLen; i++){
  5519. if(cm[i].hidden !== true ) {
  5520. p.nv = i - iCol;
  5521. break;
  5522. }
  5523. }
  5524. }
  5525. // use resize stuff
  5526. grid.resizing = {idx : iCol };
  5527. diff = newWidth - grid.headers[iCol].width;
  5528. if(p.forceFit) {
  5529. diffnv = grid.headers[ iCol + p.nv].width - diff;
  5530. if(diffnv < p.minColWidth) { return; }
  5531. grid.headers[ iCol + p.nv].newWidth = grid.headers[ iCol + p.nv].width - diff;
  5532. }
  5533. grid.newWidth = p.tblwidth + diff;
  5534. grid.headers[ iCol ].newWidth = newWidth;
  5535. grid.dragEnd( false );
  5536. });
  5537. },
  5538. getStyleUI : function( styleui, classui, notclasstag, gridclass) {
  5539. var ret = "", q = "";
  5540. try {
  5541. var stylemod = styleui.split(".");
  5542. if(!notclasstag) {
  5543. ret = "class=";
  5544. q = "\"";
  5545. }
  5546. if(gridclass == null) {
  5547. gridclass = "";
  5548. }
  5549. switch(stylemod.length) {
  5550. case 1 :
  5551. ret += q + $.trim(gridclass + " " + $.jgrid.styleUI[stylemod[0]][classui] + q);
  5552. break;
  5553. case 2 :
  5554. ret += q + $.trim(gridclass + " " + $.jgrid.styleUI[stylemod[0]][stylemod[1]][classui] + q);
  5555. }
  5556. } catch (cls) {
  5557. ret = "";
  5558. }
  5559. return ret;
  5560. },
  5561. resizeGrid : function (timeout) {
  5562. return this.each(function(){
  5563. var $t = this;
  5564. if(timeout === undefined) {
  5565. timeout = 500;
  5566. }
  5567. setTimeout(function(){
  5568. try {
  5569. var winwidth = $(window).width(),
  5570. parentwidth = $("#gbox_"+$.jgrid.jqID($t.p.id)).parent().width(),
  5571. ww = $t.p.width;
  5572. if( (winwidth-parentwidth) > 3 ) {
  5573. ww = parentwidth;
  5574. } else {
  5575. ww = winwidth;
  5576. }
  5577. $("#"+$.jgrid.jqID($t.p.id)).jqGrid('setGridWidth', ww);
  5578. } catch(e){}
  5579. }, timeout);
  5580. });
  5581. }
  5582. });
  5583. //module begin
  5584. $.jgrid.extend({
  5585. editCell : function (iRow,iCol, ed){
  5586. return this.each(function (){
  5587. var $t = this, nm, tmp,cc, cm,
  5588. highlight = $(this).jqGrid('getStyleUI',$t.p.styleUI+'.common','highlight', true),
  5589. hover = $(this).jqGrid('getStyleUI',$t.p.styleUI+'.common','hover', true),
  5590. inpclass = $(this).jqGrid('getStyleUI',$t.p.styleUI+".celledit",'inputClass', true);
  5591. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  5592. iCol = parseInt(iCol,10);
  5593. // select the row that can be used for other methods
  5594. $t.p.selrow = $t.rows[iRow].id;
  5595. if (!$t.p.knv) {$($t).jqGrid("GridNav");}
  5596. // check to see if we have already edited cell
  5597. if ($t.p.savedRow.length>0) {
  5598. // prevent second click on that field and enable selects
  5599. if (ed===true ) {
  5600. if(iRow == $t.p.iRow && iCol == $t.p.iCol){
  5601. return;
  5602. }
  5603. }
  5604. // save the cell
  5605. $($t).jqGrid("saveCell",$t.p.savedRow[0].id,$t.p.savedRow[0].ic);
  5606. } else {
  5607. window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},1);
  5608. }
  5609. cm = $t.p.colModel[iCol];
  5610. nm = cm.name;
  5611. if (nm==='subgrid' || nm==='cb' || nm==='rn') {return;}
  5612. try {
  5613. cc = $($t.rows[iRow].cells[iCol]);
  5614. } catch(e) {
  5615. cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  5616. }
  5617. if (cm.editable===true && ed===true && !cc.hasClass("not-editable-cell") && (!$.isFunction($t.p.isCellEditable) || $t.p.isCellEditable.call($t,nm,iRow,iCol))) {
  5618. if(parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  5619. //$("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell " + highlight);
  5620. $($t.rows[$t.p.iRow]).removeClass("selected-row " + hover).find("td:eq("+$t.p.iCol+")").removeClass("edit-cell " + highlight);
  5621. }
  5622. cc.addClass("edit-cell " + highlight);
  5623. $($t.rows[iRow]).addClass("selected-row " + hover);
  5624. try {
  5625. tmp = $.unformat.call($t,cc,{rowId: $t.rows[iRow].id, colModel:cm},iCol);
  5626. } catch (_) {
  5627. tmp = ( cm.edittype && cm.edittype === 'textarea' ) ? cc.text() : cc.html();
  5628. }
  5629. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  5630. if (!cm.edittype) {cm.edittype = "text";}
  5631. $t.p.savedRow.push({id:iRow,ic:iCol,name:nm,v:tmp});
  5632. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  5633. if($.isFunction($t.p.formatCell)) {
  5634. var tmp2 = $t.p.formatCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  5635. if(tmp2 !== undefined ) {tmp = tmp2;}
  5636. }
  5637. $($t).triggerHandler("jqGridBeforeEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  5638. if ($.isFunction($t.p.beforeEditCell)) {
  5639. $t.p.beforeEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  5640. }
  5641. var opt = $.extend({}, cm.editoptions || {} ,{id:iRow+"_"+nm,name:nm,rowId: $t.rows[iRow].id, oper:'edit'});
  5642. var elc = $.jgrid.createEl.call($t,cm.edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  5643. if( $.inArray(cm.edittype, ['text','textarea','password','select']) > -1) {
  5644. $(elc).addClass(inpclass);
  5645. }
  5646. cc.html("").append(elc).attr("tabindex","0");
  5647. $.jgrid.bindEv.call($t, elc, opt);
  5648. window.setTimeout(function () { $(elc).focus();},1);
  5649. $("input, select, textarea",cc).on("keydown",function(e) {
  5650. if (e.keyCode === 27) {
  5651. if($("input.hasDatepicker",cc).length >0) {
  5652. if( $(".ui-datepicker").is(":hidden") ) { $($t).jqGrid("restoreCell",iRow,iCol); }
  5653. else { $("input.hasDatepicker",cc).datepicker('hide'); }
  5654. } else {
  5655. $($t).jqGrid("restoreCell",iRow,iCol);
  5656. }
  5657. } //ESC
  5658. if (e.keyCode === 13 && !e.shiftKey) {
  5659. $($t).jqGrid("saveCell",iRow,iCol);
  5660. // Prevent default action
  5661. return false;
  5662. } //Enter
  5663. if (e.keyCode === 9) {
  5664. if(!$t.grid.hDiv.loading ) {
  5665. if (e.shiftKey) {$($t).jqGrid("prevCell",iRow,iCol);} //Shift TAb
  5666. else {$($t).jqGrid("nextCell",iRow,iCol);} //Tab
  5667. } else {
  5668. return false;
  5669. }
  5670. }
  5671. e.stopPropagation();
  5672. });
  5673. $($t).triggerHandler("jqGridAfterEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  5674. if ($.isFunction($t.p.afterEditCell)) {
  5675. $t.p.afterEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  5676. }
  5677. } else {
  5678. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  5679. //$("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell " + highlight);
  5680. $($t.rows[$t.p.iRow]).removeClass("selected-row " + hover).find("td:eq("+$t.p.iCol+")").removeClass("edit-cell " + highlight);
  5681. }
  5682. cc.addClass("edit-cell " + highlight);
  5683. $($t.rows[iRow]).addClass("selected-row " + hover);
  5684. tmp = cc.html().replace(/\&#160\;/ig,'');
  5685. $($t).triggerHandler("jqGridSelectCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  5686. if ($.isFunction($t.p.onSelectCell)) {
  5687. $t.p.onSelectCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  5688. }
  5689. }
  5690. $t.p.iCol = iCol; $t.p.iRow = iRow;
  5691. });
  5692. },
  5693. saveCell : function (iRow, iCol){
  5694. return this.each(function(){
  5695. var $t= this, fr,
  5696. errors = $.jgrid.getRegional(this, 'errors'),
  5697. edit =$.jgrid.getRegional(this, 'edit');
  5698. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  5699. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  5700. if(fr !== null) {
  5701. var cc = $("td:eq("+iCol+")",$t.rows[iRow]),v,v2,
  5702. cm = $t.p.colModel[iCol], nm = cm.name, nmjq = $.jgrid.jqID(nm),
  5703. p = $(cc).offset();
  5704. switch (cm.edittype) {
  5705. case "select":
  5706. if(!cm.editoptions.multiple) {
  5707. v = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).val();
  5708. v2 = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).text();
  5709. } else {
  5710. var sel = $("#"+iRow+"_"+nmjq,$t.rows[iRow]), selectedText = [];
  5711. v = $(sel).val();
  5712. if(v) { v.join(",");} else { v=""; }
  5713. $("option:selected",sel).each(
  5714. function(i,selected){
  5715. selectedText[i] = $(selected).text();
  5716. }
  5717. );
  5718. v2 = selectedText.join(",");
  5719. }
  5720. if(cm.formatter) { v2 = v; }
  5721. break;
  5722. case "checkbox":
  5723. var cbv = ["Yes","No"];
  5724. if(cm.editoptions && cm.editoptions.value){
  5725. cbv = cm.editoptions.value.split(":");
  5726. }
  5727. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).is(":checked") ? cbv[0] : cbv[1];
  5728. v2=v;
  5729. break;
  5730. case "password":
  5731. case "text":
  5732. case "textarea":
  5733. case "button" :
  5734. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).val();
  5735. v2=v;
  5736. break;
  5737. case 'custom' :
  5738. try {
  5739. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  5740. v = cm.editoptions.custom_value.call($t, $(".customelement",cc),'get');
  5741. if (v===undefined) { throw "e2";} else { v2=v; }
  5742. } else { throw "e1"; }
  5743. } catch (e) {
  5744. if (e==="e1") { $.jgrid.info_dialog(errors.errcap, "function 'custom_value' " + edit.msg.nodefined, edit.bClose, {styleUI : $t.p.styleUI }); }
  5745. else if (e==="e2") { $.jgrid.info_dialog(errors.errcap, "function 'custom_value' " + edit.msg.novalue, edit.bClose, {styleUI : $t.p.styleUI }); }
  5746. else {$.jgrid.info_dialog(errors.errcap, e.message, edit.bClose, {styleUI : $t.p.styleUI }); }
  5747. }
  5748. break;
  5749. }
  5750. // The common approach is if nothing changed do not do anything
  5751. if (v2 !== $t.p.savedRow[fr].v){
  5752. var vvv = $($t).triggerHandler("jqGridBeforeSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  5753. if (vvv) {v = vvv; v2=vvv;}
  5754. if ($.isFunction($t.p.beforeSaveCell)) {
  5755. var vv = $t.p.beforeSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  5756. if (vv) {v = vv; v2=vv;}
  5757. }
  5758. var cv = $.jgrid.checkValues.call($t,v,iCol), nuem = false;
  5759. if(cv[0] === true) {
  5760. var addpost = $($t).triggerHandler("jqGridBeforeSubmitCell", [$t.rows[iRow].id, nm, v, iRow, iCol]) || {};
  5761. if ($.isFunction($t.p.beforeSubmitCell)) {
  5762. addpost = $t.p.beforeSubmitCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  5763. if (!addpost) {addpost={};}
  5764. }
  5765. var retsub = $($t).triggerHandler("jqGridOnSubmitCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  5766. if(retsub === undefined) {
  5767. retsub = true;
  5768. }
  5769. if($.isFunction($t.p.onSubmitCell) ) {
  5770. retsub = $t.p.onSubmitCell($t.rows[iRow].id, nm, v, iRow, iCol);
  5771. if( retsub === undefined) {
  5772. retsub = true;
  5773. }
  5774. }
  5775. if( retsub === false) {
  5776. return;
  5777. }
  5778. if( $("input.hasDatepicker",cc).length >0) { $("input.hasDatepicker",cc).datepicker('hide'); }
  5779. if ($t.p.cellsubmit === 'remote') {
  5780. if ($t.p.cellurl) {
  5781. var postdata = {};
  5782. if($t.p.autoencode) { v = $.jgrid.htmlEncode(v); }
  5783. if(cm.editoptions && cm.editoptions.NullIfEmpty && v === "") {
  5784. v = 'null';
  5785. nuem = true;
  5786. }
  5787. postdata[nm] = v;
  5788. var idname,oper, opers;
  5789. opers = $t.p.prmNames;
  5790. idname = opers.id;
  5791. oper = opers.oper;
  5792. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, $t.rows[iRow].id);
  5793. postdata[oper] = opers.editoper;
  5794. postdata = $.extend(addpost,postdata);
  5795. $($t).jqGrid("progressBar", {method:"show", loadtype : $t.p.loadui, htmlcontent: $.jgrid.getRegional($t,'defaults.savetext') });
  5796. $t.grid.hDiv.loading = true;
  5797. $.ajax( $.extend( {
  5798. url: $t.p.cellurl,
  5799. data :$.isFunction($t.p.serializeCellData) ? $t.p.serializeCellData.call($t, postdata, nm) : postdata,
  5800. type: "POST",
  5801. complete: function (result, stat) {
  5802. $($t).jqGrid("progressBar", {method:"hide", loadtype : $t.p.loadui });
  5803. $t.grid.hDiv.loading = false;
  5804. if (stat === 'success') {
  5805. var ret = $($t).triggerHandler("jqGridAfterSubmitCell", [$t, result, postdata.id, nm, v, iRow, iCol]) || [true, ''];
  5806. if (ret[0] === true && $.isFunction($t.p.afterSubmitCell)) {
  5807. ret = $t.p.afterSubmitCell.call($t, result,postdata.id,nm,v,iRow,iCol);
  5808. }
  5809. if(ret[0] === true){
  5810. if(nuem) {
  5811. v = "";
  5812. }
  5813. $(cc).empty();
  5814. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true);
  5815. $(cc).addClass("dirty-cell");
  5816. $($t.rows[iRow]).addClass("edited");
  5817. $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  5818. if ($.isFunction($t.p.afterSaveCell)) {
  5819. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  5820. }
  5821. $t.p.savedRow.splice(0,1);
  5822. } else {
  5823. $($t).triggerHandler("jqGridErrorCell", [result, stat]);
  5824. if ($.isFunction($t.p.errorCell)) {
  5825. $t.p.errorCell.call($t, result, stat);
  5826. } else {
  5827. $.jgrid.info_dialog(errors.errcap, ret[1], edit.bClose, {
  5828. styleUI : $t.p.styleUI,
  5829. top:p.top+30,
  5830. left:p.left ,
  5831. onClose : function() {
  5832. if(!$t.p.restoreCellonFail) {
  5833. $("#"+iRow+"_"+nmjq,$t.rows[iRow]).focus();
  5834. }
  5835. }
  5836. });
  5837. }
  5838. if( $t.p.restoreCellonFail) {
  5839. $($t).jqGrid("restoreCell",iRow,iCol);
  5840. }
  5841. }
  5842. }
  5843. },
  5844. error:function(res,stat,err) {
  5845. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  5846. $t.grid.hDiv.loading = false;
  5847. $($t).triggerHandler("jqGridErrorCell", [res, stat, err]);
  5848. if ($.isFunction($t.p.errorCell)) {
  5849. $t.p.errorCell.call($t, res,stat,err);
  5850. } else {
  5851. $.jgrid.info_dialog(errors.errcap, res.status+" : "+res.statusText+"<br/>"+stat, edit.bClose, {
  5852. styleUI : $t.p.styleUI,
  5853. top:p.top+30,
  5854. left:p.left ,
  5855. onClose : function() {
  5856. if(!$t.p.restoreCellonFail) {
  5857. $("#"+iRow+"_"+nmjq,$t.rows[iRow]).focus();
  5858. }
  5859. }
  5860. });
  5861. }
  5862. if( $t.p.restoreCellonFail) {
  5863. $($t).jqGrid("restoreCell",iRow,iCol);
  5864. }
  5865. }
  5866. }, $.jgrid.ajaxOptions, $t.p.ajaxCellOptions || {}));
  5867. } else {
  5868. try {
  5869. $.jgrid.info_dialog(errors.errcap,errors.nourl, edit.bClose, {styleUI : $t.p.styleUI });
  5870. if( $t.p.restoreCellonFail) {
  5871. $($t).jqGrid("restoreCell",iRow,iCol);
  5872. }
  5873. } catch (e) {}
  5874. }
  5875. }
  5876. if ($t.p.cellsubmit === 'clientArray') {
  5877. $(cc).empty();
  5878. $($t).jqGrid("setCell",$t.rows[iRow].id,iCol, v2, false, false, true);
  5879. $(cc).addClass("dirty-cell");
  5880. $($t.rows[iRow]).addClass("edited");
  5881. $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  5882. if ($.isFunction($t.p.afterSaveCell)) {
  5883. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  5884. }
  5885. $t.p.savedRow.splice(0,1);
  5886. }
  5887. } else {
  5888. try {
  5889. if( $.isFunction($t.p.validationCell) ) {
  5890. $t.p.validationCell.call($t, $("#"+iRow+"_"+nmjq,$t.rows[iRow]), cv[1], iRow, iCol);
  5891. } else {
  5892. window.setTimeout(function(){
  5893. $.jgrid.info_dialog(errors.errcap,v+ " " + cv[1], edit.bClose, {
  5894. styleUI : $t.p.styleUI,
  5895. top:p.top+30,
  5896. left:p.left ,
  5897. onClose : function() {
  5898. if(!$t.p.restoreCellonFail) {
  5899. $("#"+iRow+"_"+nmjq,$t.rows[iRow]).focus();
  5900. }
  5901. }
  5902. });
  5903. },50);
  5904. if( $t.p.restoreCellonFail) {
  5905. $($t).jqGrid("restoreCell",iRow,iCol);
  5906. }
  5907. }
  5908. } catch (e) {
  5909. alert(cv[1]);
  5910. }
  5911. }
  5912. } else {
  5913. $($t).jqGrid("restoreCell",iRow,iCol);
  5914. }
  5915. }
  5916. window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},0);
  5917. });
  5918. },
  5919. restoreCell : function(iRow, iCol) {
  5920. return this.each(function(){
  5921. var $t= this, fr;
  5922. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  5923. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  5924. if(fr !== null) {
  5925. var cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  5926. // datepicker fix
  5927. if($.isFunction($.fn.datepicker)) {
  5928. try {
  5929. $("input.hasDatepicker",cc).datepicker('hide');
  5930. } catch (e) {}
  5931. }
  5932. $(cc).empty().attr("tabindex","-1");
  5933. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, $t.p.savedRow[fr].v, false, false, true);
  5934. $($t).triggerHandler("jqGridAfterRestoreCell", [$t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol]);
  5935. if ($.isFunction($t.p.afterRestoreCell)) {
  5936. $t.p.afterRestoreCell.call($t, $t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol);
  5937. }
  5938. $t.p.savedRow.splice(0,1);
  5939. }
  5940. window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
  5941. });
  5942. },
  5943. nextCell : function (iRow,iCol) {
  5944. return this.each(function (){
  5945. var $t = this, nCol=false, i;
  5946. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  5947. // try to find next editable cell
  5948. for (i=iCol+1; i<$t.p.colModel.length; i++) {
  5949. if ( $t.p.colModel[i].editable ===true && (!$.isFunction($t.p.isCellEditable) || $t.p.isCellEditable.call($t, $t.p.colModel[i].name,iRow,i))) {
  5950. nCol = i; break;
  5951. }
  5952. }
  5953. if(nCol !== false) {
  5954. $($t).jqGrid("editCell",iRow,nCol,true);
  5955. } else {
  5956. if ($t.p.savedRow.length >0) {
  5957. $($t).jqGrid("saveCell",iRow,iCol);
  5958. }
  5959. }
  5960. });
  5961. },
  5962. prevCell : function (iRow,iCol) {
  5963. return this.each(function (){
  5964. var $t = this, nCol=false, i;
  5965. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  5966. // try to find next editable cell
  5967. for (i=iCol-1; i>=0; i--) {
  5968. if ( $t.p.colModel[i].editable ===true && (!$.isFunction($t.p.isCellEditable) || $t.p.isCellEditable.call($t, $t.p.colModel[i].name, iRow,i))) {
  5969. nCol = i; break;
  5970. }
  5971. }
  5972. if(nCol !== false) {
  5973. $($t).jqGrid("editCell",iRow,nCol,true);
  5974. } else {
  5975. if ($t.p.savedRow.length >0) {
  5976. $($t).jqGrid("saveCell",iRow,iCol);
  5977. }
  5978. }
  5979. });
  5980. },
  5981. GridNav : function() {
  5982. return this.each(function () {
  5983. var $t = this;
  5984. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  5985. // trick to process keydown on non input elements
  5986. $t.p.knv = $t.p.id + "_kn";
  5987. var selection = $("<div style='position:fixed;top:0px;width:1px;height:1px;' tabindex='0'><div tabindex='-1' style='width:1px;height:1px;' id='"+$t.p.knv+"'></div></div>"),
  5988. i, kdir;
  5989. function scrollGrid(iR, iC, tp){
  5990. if (tp.substr(0,1)==='v') {
  5991. var ch = $($t.grid.bDiv)[0].clientHeight,
  5992. st = $($t.grid.bDiv)[0].scrollTop,
  5993. nROT = $t.rows[iR].offsetTop+$t.rows[iR].clientHeight,
  5994. pROT = $t.rows[iR].offsetTop;
  5995. if(tp === 'vd') {
  5996. if(nROT >= ch) {
  5997. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop + $t.rows[iR].clientHeight;
  5998. }
  5999. }
  6000. if(tp === 'vu'){
  6001. if (pROT < st ) {
  6002. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop - $t.rows[iR].clientHeight;
  6003. }
  6004. }
  6005. }
  6006. if(tp==='h') {
  6007. var cw = $($t.grid.bDiv)[0].clientWidth,
  6008. sl = $($t.grid.bDiv)[0].scrollLeft,
  6009. nCOL = $t.rows[iR].cells[iC].offsetLeft+$t.rows[iR].cells[iC].clientWidth,
  6010. pCOL = $t.rows[iR].cells[iC].offsetLeft;
  6011. if(nCOL >= cw+parseInt(sl,10)) {
  6012. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft + $t.rows[iR].cells[iC].clientWidth;
  6013. } else if (pCOL < sl) {
  6014. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft - $t.rows[iR].cells[iC].clientWidth;
  6015. }
  6016. }
  6017. }
  6018. function findNextVisible(iC,act){
  6019. var ind, i;
  6020. if(act === 'lft') {
  6021. ind = iC+1;
  6022. for (i=iC;i>=0;i--){
  6023. if ($t.p.colModel[i].hidden !== true) {
  6024. ind = i;
  6025. break;
  6026. }
  6027. }
  6028. }
  6029. if(act === 'rgt') {
  6030. ind = iC-1;
  6031. for (i=iC; i<$t.p.colModel.length;i++){
  6032. if ($t.p.colModel[i].hidden !== true) {
  6033. ind = i;
  6034. break;
  6035. }
  6036. }
  6037. }
  6038. return ind;
  6039. }
  6040. $(selection).insertBefore($t.grid.cDiv);
  6041. $("#"+$t.p.knv)
  6042. .focus()
  6043. .keydown(function (e){
  6044. kdir = e.keyCode;
  6045. if($t.p.direction === "rtl") {
  6046. if(kdir===37) { kdir = 39;}
  6047. else if (kdir===39) { kdir = 37; }
  6048. }
  6049. switch (kdir) {
  6050. case 38:
  6051. if ($t.p.iRow-1 >0 ) {
  6052. scrollGrid($t.p.iRow-1,$t.p.iCol,'vu');
  6053. $($t).jqGrid("editCell",$t.p.iRow-1,$t.p.iCol,false);
  6054. }
  6055. break;
  6056. case 40 :
  6057. if ($t.p.iRow+1 <= $t.rows.length-1) {
  6058. scrollGrid($t.p.iRow+1,$t.p.iCol,'vd');
  6059. $($t).jqGrid("editCell",$t.p.iRow+1,$t.p.iCol,false);
  6060. }
  6061. break;
  6062. case 37 :
  6063. if ($t.p.iCol -1 >= 0) {
  6064. i = findNextVisible($t.p.iCol-1,'lft');
  6065. scrollGrid($t.p.iRow, i,'h');
  6066. $($t).jqGrid("editCell",$t.p.iRow, i,false);
  6067. }
  6068. break;
  6069. case 39 :
  6070. if ($t.p.iCol +1 <= $t.p.colModel.length-1) {
  6071. i = findNextVisible($t.p.iCol+1,'rgt');
  6072. scrollGrid($t.p.iRow,i,'h');
  6073. $($t).jqGrid("editCell",$t.p.iRow,i,false);
  6074. }
  6075. break;
  6076. case 13:
  6077. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  6078. $($t).jqGrid("editCell",$t.p.iRow,$t.p.iCol,true);
  6079. }
  6080. break;
  6081. default :
  6082. return true;
  6083. }
  6084. return false;
  6085. });
  6086. });
  6087. },
  6088. getChangedCells : function (mthd) {
  6089. var ret=[];
  6090. if (!mthd) {mthd='all';}
  6091. this.each(function(){
  6092. var $t= this,nm;
  6093. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  6094. $($t.rows).each(function(j){
  6095. var res = {};
  6096. if ($(this).hasClass("edited")) {
  6097. $('td',this).each( function(i) {
  6098. nm = $t.p.colModel[i].name;
  6099. if ( nm !== 'cb' && nm !== 'subgrid') {
  6100. if (mthd==='dirty') {
  6101. if ($(this).hasClass('dirty-cell')) {
  6102. try {
  6103. res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id, colModel:$t.p.colModel[i]},i);
  6104. } catch (e){
  6105. res[nm] = $.jgrid.htmlDecode($(this).html());
  6106. }
  6107. }
  6108. } else {
  6109. try {
  6110. res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id,colModel:$t.p.colModel[i]},i);
  6111. } catch (e) {
  6112. res[nm] = $.jgrid.htmlDecode($(this).html());
  6113. }
  6114. }
  6115. }
  6116. });
  6117. res.id = this.id;
  6118. ret.push(res);
  6119. }
  6120. });
  6121. });
  6122. return ret;
  6123. }
  6124. /// end cell editing
  6125. });
  6126. //module begin
  6127. $.extend($.jgrid,{
  6128. // Modal functions
  6129. showModal : function(h) {
  6130. h.w.show();
  6131. },
  6132. closeModal : function(h) {
  6133. h.w.hide().attr("aria-hidden","true");
  6134. if(h.o) {h.o.remove();}
  6135. },
  6136. hideModal : function (selector,o) {
  6137. o = $.extend({jqm : true, gb :'', removemodal: false, formprop: false, form : ''}, o || {});
  6138. var thisgrid = o.gb && typeof o.gb === "string" && o.gb.substr(0,6) === "#gbox_" ? $("#" + o.gb.substr(6))[0] : false;
  6139. if(o.onClose) {
  6140. var oncret = thisgrid ? o.onClose.call(thisgrid, selector) : o.onClose(selector);
  6141. if (typeof oncret === 'boolean' && !oncret ) { return; }
  6142. }
  6143. if( o.formprop && thisgrid && o.form) {
  6144. var fh = $(selector)[0].style.height,
  6145. fw = $(selector)[0].style.width;
  6146. if(fh.indexOf("px") > -1 ) {
  6147. fh = parseFloat(fh);
  6148. }
  6149. if(fw.indexOf("px") > -1 ) {
  6150. fw = parseFloat(fw);
  6151. }
  6152. var frmgr, frmdata;
  6153. if(o.form==='edit'){
  6154. frmgr = '#' +$.jgrid.jqID("FrmGrid_"+ o.gb.substr(6));
  6155. frmdata = "formProp";
  6156. } else if( o.form === 'view') {
  6157. frmgr = '#' +$.jgrid.jqID("ViewGrid_"+ o.gb.substr(6));
  6158. frmdata = "viewProp";
  6159. }
  6160. $(thisgrid).data(frmdata, {
  6161. top:parseFloat($(selector).css("top")),
  6162. left : parseFloat($(selector).css("left")),
  6163. width : fw,
  6164. height : fh,
  6165. dataheight : $(frmgr).height(),
  6166. datawidth: $(frmgr).width()
  6167. });
  6168. }
  6169. if ($.fn.jqm && o.jqm === true) {
  6170. $(selector).attr("aria-hidden","true").jqmHide();
  6171. } else {
  6172. if(o.gb !== '') {
  6173. try {$(".jqgrid-overlay:first",o.gb).hide();} catch (e){}
  6174. }
  6175. $(selector).hide().attr("aria-hidden","true");
  6176. }
  6177. if( o.removemodal ) {
  6178. $(selector).remove();
  6179. }
  6180. },
  6181. //Helper functions
  6182. findPos : function(obj) {
  6183. var offset = $(obj).offset();
  6184. return [offset.left,offset.top];
  6185. },
  6186. createModal : function(aIDs, content, p, insertSelector, posSelector, appendsel, css) {
  6187. p = $.extend(true, {}, $.jgrid.jqModal || {}, p);
  6188. var self = this,
  6189. rtlsup = $(p.gbox).attr("dir") === "rtl" ? true : false,
  6190. classes = $.jgrid.styleUI[(p.styleUI || 'jQueryUI')].modal,
  6191. common = $.jgrid.styleUI[(p.styleUI || 'jQueryUI')].common,
  6192. mw = document.createElement('div');
  6193. css = $.extend({}, css || {});
  6194. mw.className= "ui-jqdialog " + classes.modal;
  6195. mw.id = aIDs.themodal;
  6196. var mh = document.createElement('div');
  6197. mh.className = "ui-jqdialog-titlebar " + classes.header;
  6198. mh.id = aIDs.modalhead;
  6199. $(mh).append("<span class='ui-jqdialog-title'>"+p.caption+"</span>");
  6200. var ahr= $("<a class='ui-jqdialog-titlebar-close "+common.cornerall+"'></a>")
  6201. .hover(function(){ahr.addClass(common.hover);},
  6202. function(){ahr.removeClass(common.hover);})
  6203. .append("<span class='" + common.icon_base+" " + classes.icon_close + "'></span>");
  6204. $(mh).append(ahr);
  6205. if(rtlsup) {
  6206. mw.dir = "rtl";
  6207. $(".ui-jqdialog-title",mh).css("float","right");
  6208. $(".ui-jqdialog-titlebar-close",mh).css("left",0.3+"em");
  6209. } else {
  6210. mw.dir = "ltr";
  6211. $(".ui-jqdialog-title",mh).css("float","left");
  6212. $(".ui-jqdialog-titlebar-close",mh).css("right",0.3+"em");
  6213. }
  6214. var mc = document.createElement('div');
  6215. $(mc).addClass("ui-jqdialog-content " + classes.content).attr("id",aIDs.modalcontent);
  6216. $(mc).append(content);
  6217. mw.appendChild(mc);
  6218. $(mw).prepend(mh);
  6219. if(appendsel===true) {
  6220. $('body').append(mw);
  6221. } //append as first child in body -for alert dialog
  6222. else if (typeof appendsel === "string") {
  6223. $(appendsel).append(mw);
  6224. } else {
  6225. $(mw).insertBefore(insertSelector);
  6226. }
  6227. $(mw).css(css);
  6228. if(p.jqModal === undefined) {p.jqModal = true;} // internal use
  6229. var coord = {};
  6230. if ( $.fn.jqm && p.jqModal === true) {
  6231. if(p.left ===0 && p.top===0 && p.overlay) {
  6232. var pos = [];
  6233. pos = $.jgrid.findPos(posSelector);
  6234. p.left = pos[0] + 4;
  6235. p.top = pos[1] + 4;
  6236. }
  6237. coord.top = p.top+"px";
  6238. coord.left = p.left;
  6239. } else if(p.left !==0 || p.top!==0) {
  6240. coord.left = p.left;
  6241. coord.top = p.top+"px";
  6242. }
  6243. $("a.ui-jqdialog-titlebar-close",mh).click(function(){
  6244. var oncm = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose;
  6245. var gboxclose = $("#"+$.jgrid.jqID(aIDs.themodal)).data("gbox") || p.gbox;
  6246. self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:gboxclose,jqm:p.jqModal,onClose:oncm, removemodal: p.removemodal || false, formprop : !p.recreateForm || false, form: p.form || ''});
  6247. return false;
  6248. });
  6249. if (p.width === 0 || !p.width) {p.width = 300;}
  6250. if(p.height === 0 || !p.height) {p.height =200;}
  6251. if(!p.zIndex) {
  6252. var parentZ = $(insertSelector).parents("*[role=dialog]").filter(':first').css("z-index");
  6253. if(parentZ) {
  6254. p.zIndex = parseInt(parentZ,10)+2;
  6255. } else {
  6256. p.zIndex = 950;
  6257. }
  6258. }
  6259. var rtlt = 0;
  6260. if( rtlsup && coord.left && !appendsel) {
  6261. rtlt = $(p.gbox).width()- (!isNaN(p.width) ? parseInt(p.width,10) :0) - 8; // to do
  6262. // just in case
  6263. coord.left = parseInt(coord.left,10) + parseInt(rtlt,10);
  6264. }
  6265. if(coord.left) { coord.left += "px"; }
  6266. $(mw).css($.extend({
  6267. width: isNaN(p.width) ? "auto": p.width+"px",
  6268. height:isNaN(p.height) ? "auto" : p.height + "px",
  6269. zIndex:p.zIndex,
  6270. overflow: 'hidden'
  6271. },coord))
  6272. .attr({tabIndex: "-1","role":"dialog","aria-labelledby":aIDs.modalhead,"aria-hidden":"true"});
  6273. if(p.drag === undefined) { p.drag=true;}
  6274. if(p.resize === undefined) {p.resize=true;}
  6275. if (p.drag) {
  6276. $(mh).css('cursor','move');
  6277. if($.fn.tinyDraggable) {
  6278. //$(mw).jqDrag(mh);
  6279. $(mw).tinyDraggable({ handle:"#"+$.jgrid.jqID(mh.id) });
  6280. } else {
  6281. try {
  6282. $(mw).draggable({handle: $("#"+$.jgrid.jqID(mh.id))});
  6283. } catch (e) {}
  6284. }
  6285. }
  6286. if(p.resize) {
  6287. if($.fn.jqResize) {
  6288. $(mw).append("<div class='jqResize "+classes.resizable+" "+common.icon_base + " " +classes.icon_resizable+"'></div>");
  6289. $("#"+$.jgrid.jqID(aIDs.themodal)).jqResize(".jqResize",aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false);
  6290. } else {
  6291. try {
  6292. $(mw).resizable({handles: 'se, sw',alsoResize: aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false});
  6293. } catch (r) {}
  6294. }
  6295. }
  6296. if(p.closeOnEscape === true){
  6297. $(mw).keydown( function( e ) {
  6298. if( e.which === 27 ) {
  6299. var cone = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose;
  6300. self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:p.gbox,jqm:p.jqModal,onClose: cone, removemodal: p.removemodal || false, formprop : !p.recreateForm || false, form: p.form || ''});
  6301. }
  6302. });
  6303. }
  6304. },
  6305. viewModal : function (selector,o){
  6306. o = $.extend({
  6307. toTop: true,
  6308. overlay: 10,
  6309. modal: false,
  6310. overlayClass : 'ui-widget-overlay', // to be fixed
  6311. onShow: $.jgrid.showModal,
  6312. onHide: $.jgrid.closeModal,
  6313. gbox: '',
  6314. jqm : true,
  6315. jqM : true
  6316. }, o || {});
  6317. if(o.focusField === undefined) {
  6318. o.focusField = 0;
  6319. }
  6320. if(typeof o.focusField === "number" && o.focusField >= 0 ) {
  6321. o.focusField = parseInt(o.focusField,10);
  6322. } else if(typeof o.focusField === "boolean" && !o.focusField) {
  6323. o.focusField = false;
  6324. } else {
  6325. o.focusField = 0;
  6326. }
  6327. if ($.fn.jqm && o.jqm === true) {
  6328. if(o.jqM) { $(selector).attr("aria-hidden","false").jqm(o).jqmShow(); }
  6329. else {$(selector).attr("aria-hidden","false").jqmShow();}
  6330. } else {
  6331. if(o.gbox !== '') {
  6332. $(".jqgrid-overlay:first",o.gbox).show();
  6333. $(selector).data("gbox",o.gbox);
  6334. }
  6335. $(selector).show().attr("aria-hidden","false");
  6336. if(o.focusField >= 0) {
  6337. try{$(':input:visible',selector)[o.focusField].focus();}catch(_){}
  6338. }
  6339. }
  6340. },
  6341. info_dialog : function(caption, content,c_b, modalopt) {
  6342. var mopt = {
  6343. width:290,
  6344. height:'auto',
  6345. dataheight: 'auto',
  6346. drag: true,
  6347. resize: false,
  6348. left:250,
  6349. top:170,
  6350. zIndex : 1000,
  6351. jqModal : true,
  6352. modal : false,
  6353. closeOnEscape : true,
  6354. align: 'center',
  6355. buttonalign : 'center',
  6356. buttons : []
  6357. // {text:'textbutt', id:"buttid", onClick : function(){...}}
  6358. // if the id is not provided we set it like info_button_+ the index in the array - i.e info_button_0,info_button_1...
  6359. };
  6360. $.extend(true, mopt, $.jgrid.jqModal || {}, {caption:"<b>"+caption+"</b>"}, modalopt || {});
  6361. var jm = mopt.jqModal, self = this,
  6362. classes = $.jgrid.styleUI[(mopt.styleUI || 'jQueryUI')].modal,
  6363. common = $.jgrid.styleUI[(mopt.styleUI || 'jQueryUI')].common;
  6364. if($.fn.jqm && !jm) { jm = false; }
  6365. // in case there is no jqModal
  6366. var buttstr ="", i;
  6367. if(mopt.buttons.length > 0) {
  6368. for(i=0;i<mopt.buttons.length;i++) {
  6369. if(mopt.buttons[i].id === undefined) { mopt.buttons[i].id = "info_button_"+i; }
  6370. buttstr += "<a id='"+mopt.buttons[i].id+"' class='fm-button " + common.button+"'>"+mopt.buttons[i].text+"</a>";
  6371. }
  6372. }
  6373. var dh = isNaN(mopt.dataheight) ? mopt.dataheight : mopt.dataheight+"px",
  6374. cn = "text-align:"+mopt.align+";";
  6375. var cnt = "<div id='info_id'>";
  6376. cnt += "<div id='infocnt' style='margin:0px;padding-bottom:1em;width:100%;overflow:auto;position:relative;height:"+dh+";"+cn+"'>"+content+"</div>";
  6377. cnt += c_b ? "<div class='" + classes.content + "' style='text-align:"+mopt.buttonalign+";padding-bottom:0.8em;padding-top:0.5em;background-image: none;border-width: 1px 0 0 0;'><a id='closedialog' class='fm-button " + common.button + "'>"+c_b+"</a>"+buttstr+"</div>" :
  6378. buttstr !== "" ? "<div class='" + classes.content + "' style='text-align:"+mopt.buttonalign+";padding-bottom:0.8em;padding-top:0.5em;background-image: none;border-width: 1px 0 0 0;'>"+buttstr+"</div>" : "";
  6379. cnt += "</div>";
  6380. try {
  6381. if($("#info_dialog").attr("aria-hidden") === "false") {
  6382. $.jgrid.hideModal("#info_dialog",{jqm:jm});
  6383. }
  6384. $("#info_dialog").remove();
  6385. } catch (e){}
  6386. $.jgrid.createModal({
  6387. themodal:'info_dialog',
  6388. modalhead:'info_head',
  6389. modalcontent:'info_content',
  6390. scrollelm: 'infocnt'},
  6391. cnt,
  6392. mopt,
  6393. '','',true
  6394. );
  6395. // attach onclick after inserting into the dom
  6396. if(buttstr) {
  6397. $.each(mopt.buttons,function(i){
  6398. $("#"+$.jgrid.jqID(this.id),"#info_id").on('click',function(){mopt.buttons[i].onClick.call($("#info_dialog")); return false;});
  6399. });
  6400. }
  6401. $("#closedialog", "#info_id").on('click',function(){
  6402. self.hideModal("#info_dialog",{
  6403. jqm:jm,
  6404. onClose: $("#info_dialog").data("onClose") || mopt.onClose,
  6405. gb: $("#info_dialog").data("gbox") || mopt.gbox
  6406. });
  6407. return false;
  6408. });
  6409. $(".fm-button","#info_dialog").hover(
  6410. function(){$(this).addClass(common.hover);},
  6411. function(){$(this).removeClass(common.hover);}
  6412. );
  6413. if($.isFunction(mopt.beforeOpen) ) { mopt.beforeOpen(); }
  6414. $.jgrid.viewModal("#info_dialog",{
  6415. onHide: function(h) {
  6416. h.w.hide().remove();
  6417. if(h.o) { h.o.remove(); }
  6418. },
  6419. modal :mopt.modal,
  6420. jqm:jm
  6421. });
  6422. if($.isFunction(mopt.afterOpen) ) { mopt.afterOpen(); }
  6423. try{ $("#info_dialog").focus();} catch (m){}
  6424. },
  6425. bindEv: function (el, opt) {
  6426. var $t = this;
  6427. if($.isFunction(opt.dataInit)) {
  6428. opt.dataInit.call($t,el,opt);
  6429. }
  6430. if(opt.dataEvents) {
  6431. $.each(opt.dataEvents, function() {
  6432. if (this.data !== undefined) {
  6433. $(el).on(this.type, this.data, this.fn);
  6434. } else {
  6435. $(el).on(this.type, this.fn);
  6436. }
  6437. });
  6438. }
  6439. },
  6440. // Form Functions
  6441. createEl : function(eltype,options,vl,autowidth, ajaxso) {
  6442. var elem = "", $t = this;
  6443. function setAttributes(elm, atr, exl ) {
  6444. var exclude = ['dataInit','dataEvents','dataUrl', 'buildSelect','sopt', 'searchhidden', 'defaultValue', 'attr', 'custom_element', 'custom_value', 'oper'];
  6445. exclude = exclude.concat(['cacheUrlData','delimiter','separator']);
  6446. if(exl !== undefined && $.isArray(exl)) {
  6447. $.merge(exclude, exl);
  6448. }
  6449. $.each(atr, function(key, value){
  6450. if($.inArray(key, exclude) === -1) {
  6451. $(elm).attr(key,value);
  6452. }
  6453. });
  6454. if(!atr.hasOwnProperty('id')) {
  6455. $(elm).attr('id', $.jgrid.randId());
  6456. }
  6457. }
  6458. switch (eltype)
  6459. {
  6460. case "textarea" :
  6461. elem = document.createElement("textarea");
  6462. if(autowidth) {
  6463. if(!options.cols) { $(elem).css({width:"98%"});}
  6464. } else if (!options.cols) { options.cols = 20; }
  6465. if(!options.rows) { options.rows = 2; }
  6466. if(vl==='&nbsp;' || vl==='&#160;' || (vl.length===1 && vl.charCodeAt(0)===160)) {vl="";}
  6467. elem.value = vl;
  6468. setAttributes(elem, options);
  6469. $(elem).attr({"role":"textbox","multiline":"true"});
  6470. break;
  6471. case "checkbox" : //what code for simple checkbox
  6472. elem = document.createElement("input");
  6473. elem.type = "checkbox";
  6474. if( !options.value ) {
  6475. var vl1 = (vl+"").toLowerCase();
  6476. if(vl1.search(/(false|f|0|no|n|off|undefined)/i)<0 && vl1!=="") {
  6477. elem.checked=true;
  6478. elem.defaultChecked=true;
  6479. elem.value = vl;
  6480. } else {
  6481. elem.value = "on";
  6482. }
  6483. $(elem).attr("offval","off");
  6484. } else {
  6485. var cbval = options.value.split(":");
  6486. if(vl === cbval[0]) {
  6487. elem.checked=true;
  6488. elem.defaultChecked=true;
  6489. }
  6490. elem.value = cbval[0];
  6491. $(elem).attr("offval",cbval[1]);
  6492. }
  6493. setAttributes(elem, options, ['value']);
  6494. $(elem).attr("role","checkbox");
  6495. break;
  6496. case "select" :
  6497. elem = document.createElement("select");
  6498. elem.setAttribute("role","select");
  6499. var msl, ovm = [];
  6500. if(options.multiple===true) {
  6501. msl = true;
  6502. elem.multiple="multiple";
  6503. $(elem).attr("aria-multiselectable","true");
  6504. } else { msl = false; }
  6505. if(options.dataUrl != null) {
  6506. var rowid = null, postData = options.postData || ajaxso.postData;
  6507. try {
  6508. rowid = options.rowId;
  6509. } catch(e) {}
  6510. if ($t.p && $t.p.idPrefix) {
  6511. rowid = $.jgrid.stripPref($t.p.idPrefix, rowid);
  6512. }
  6513. $.ajax($.extend({
  6514. url: $.isFunction(options.dataUrl) ? options.dataUrl.call($t, rowid, vl, String(options.name)) : options.dataUrl,
  6515. type : "GET",
  6516. dataType: "html",
  6517. data: $.isFunction(postData) ? postData.call($t, rowid, vl, String(options.name)) : postData,
  6518. context: {elem:elem, options:options, vl:vl},
  6519. success: function(data){
  6520. var ovm = [], elem = this.elem, vl = this.vl,
  6521. options = $.extend({},this.options),
  6522. msl = options.multiple===true,
  6523. cU = options.cacheUrlData === true,
  6524. oV ='', txt,
  6525. a = $.isFunction(options.buildSelect) ? options.buildSelect.call($t,data) : data;
  6526. if(typeof a === 'string') {
  6527. a = $( $.trim( a ) ).html();
  6528. }
  6529. if(a) {
  6530. $(elem).append(a);
  6531. setAttributes(elem, options, postData ? ['postData'] : undefined );
  6532. if(options.size === undefined) { options.size = msl ? 3 : 1;}
  6533. if(msl) {
  6534. ovm = vl.split(",");
  6535. ovm = $.map(ovm,function(n){return $.trim(n);});
  6536. } else {
  6537. ovm[0] = $.trim(vl);
  6538. }
  6539. //$(elem).attr(options);
  6540. //setTimeout(function(){
  6541. $("option",elem).each(function(i){
  6542. txt = $(this).text();
  6543. vl = $(this).val();
  6544. if(cU) {
  6545. oV += (i!== 0 ? ";": "")+ vl+":"+txt;
  6546. }
  6547. //if(i===0) { this.selected = ""; }
  6548. // fix IE8/IE7 problem with selecting of the first item on multiple=true
  6549. if (i === 0 && elem.multiple) { this.selected = false; }
  6550. $(this).attr("role","option");
  6551. if($.inArray($.trim(txt),ovm) > -1 || $.inArray($.trim(vl),ovm) > -1 ) {
  6552. this.selected= "selected";
  6553. }
  6554. });
  6555. if(cU) {
  6556. if(options.oper === 'edit') {
  6557. $($t).jqGrid('setColProp',options.name,{ editoptions: {buildSelect: null, dataUrl : null, value : oV} });
  6558. } else if(options.oper === 'search') {
  6559. $($t).jqGrid('setColProp',options.name,{ searchoptions: {dataUrl : null, value : oV} });
  6560. } else if(options.oper ==='filter') {
  6561. if($("#fbox_"+$t.p.id)[0].p) {
  6562. var cols = $("#fbox_"+$t.p.id)[0].p.columns, nm;
  6563. $.each(cols,function(i) {
  6564. nm = this.index || this.name;
  6565. if(options.name === nm) {
  6566. this.searchoptions.dataUrl = null;
  6567. this.searchoptions.value = oV;
  6568. return false;
  6569. }
  6570. });
  6571. }
  6572. }
  6573. }
  6574. $($t).triggerHandler("jqGridAddEditAfterSelectUrlComplete", [elem]);
  6575. //},0);
  6576. }
  6577. }
  6578. },ajaxso || {}));
  6579. } else if(options.value) {
  6580. var i;
  6581. if(options.size === undefined) {
  6582. options.size = msl ? 3 : 1;
  6583. }
  6584. if(msl) {
  6585. ovm = vl.split(",");
  6586. ovm = $.map(ovm,function(n){return $.trim(n);});
  6587. }
  6588. if(typeof options.value === 'function') { options.value = options.value(); }
  6589. var so,sv, ov, oSv, key, value,
  6590. sep = options.separator === undefined ? ":" : options.separator,
  6591. delim = options.delimiter === undefined ? ";" : options.delimiter;
  6592. if(typeof options.value === 'string') {
  6593. so = options.value.split(delim);
  6594. for(i=0; i<so.length;i++){
  6595. sv = so[i].split(sep);
  6596. if(sv.length > 2 ) {
  6597. sv[1] = $.map(sv,function(n,ii){if(ii>0) { return n;} }).join(sep);
  6598. }
  6599. ov = document.createElement("option");
  6600. ov.setAttribute("role","option");
  6601. ov.value = sv[0]; ov.innerHTML = sv[1];
  6602. elem.appendChild(ov);
  6603. if (!msl && ($.trim(sv[0]) === $.trim(vl) || $.trim(sv[1]) === $.trim(vl))) { ov.selected ="selected"; }
  6604. if (msl && ($.inArray($.trim(sv[1]), ovm)>-1 || $.inArray($.trim(sv[0]), ovm)>-1)) {ov.selected ="selected";}
  6605. }
  6606. } else if (Object.prototype.toString.call(options.value) === "[object Array]") {
  6607. oSv = options.value;
  6608. // array of arrays [[Key, Value], [Key, Value], ...]
  6609. for (i=0; i<oSv.length; i++) {
  6610. if(oSv[i].length === 2) {
  6611. key = oSv[i][0];
  6612. value = oSv[i][1];
  6613. ov = document.createElement("option");
  6614. ov.setAttribute("role","option");
  6615. ov.value = key; ov.innerHTML = value;
  6616. elem.appendChild(ov);
  6617. if (!msl && ( $.trim(key) === $.trim(vl) || $.trim(value) === $.trim(vl)) ) { ov.selected ="selected"; }
  6618. if (msl && ($.inArray($.trim(value),ovm)>-1 || $.inArray($.trim(key),ovm)>-1)) { ov.selected ="selected"; }
  6619. }
  6620. }
  6621. } else if (typeof options.value === 'object') {
  6622. oSv = options.value;
  6623. for (key in oSv) {
  6624. if (oSv.hasOwnProperty(key ) ){
  6625. ov = document.createElement("option");
  6626. ov.setAttribute("role","option");
  6627. ov.value = key; ov.innerHTML = oSv[key];
  6628. elem.appendChild(ov);
  6629. if (!msl && ( $.trim(key) === $.trim(vl) || $.trim(oSv[key]) === $.trim(vl)) ) { ov.selected ="selected"; }
  6630. if (msl && ($.inArray($.trim(oSv[key]),ovm)>-1 || $.inArray($.trim(key),ovm)>-1)) { ov.selected ="selected"; }
  6631. }
  6632. }
  6633. }
  6634. setAttributes(elem, options, ['value']);
  6635. }
  6636. break;
  6637. case "image" :
  6638. case "file" :
  6639. elem = document.createElement("input");
  6640. elem.type = eltype;
  6641. setAttributes(elem, options);
  6642. break;
  6643. case "custom" :
  6644. elem = document.createElement("span");
  6645. try {
  6646. if($.isFunction(options.custom_element)) {
  6647. var celm = options.custom_element.call($t,vl,options);
  6648. if(celm) {
  6649. celm = $(celm).addClass("customelement").attr({id:options.id,name:options.name});
  6650. $(elem).empty().append(celm);
  6651. } else {
  6652. throw "e2";
  6653. }
  6654. } else {
  6655. throw "e1";
  6656. }
  6657. } catch (e) {
  6658. var errors = $.jgrid.getRegional($t, 'errors'),
  6659. edit =$.jgrid.getRegional($t, 'edit');
  6660. if (e==="e1") { $.jgrid.info_dialog(errors.errcap,"function 'custom_element' "+edit.msg.nodefined, edit.bClose, {styleUI : $t.p.styleUI });}
  6661. else if (e==="e2") { $.jgrid.info_dialog(errors.errcap,"function 'custom_element' "+edit.msg.novalue,edit.bClose, {styleUI : $t.p.styleUI });}
  6662. else { $.jgrid.info_dialog(errors.errcap,typeof e==="string"?e:e.message,edit.bClose, {styleUI : $t.p.styleUI }); }
  6663. }
  6664. break;
  6665. default :
  6666. var role;
  6667. if(eltype==="button") { role = "button"; }
  6668. else { role = "textbox"; } // ???
  6669. elem = document.createElement("input");
  6670. elem.type = eltype;
  6671. elem.value = vl;
  6672. setAttributes(elem, options);
  6673. if(eltype !== "button"){
  6674. if(autowidth) {
  6675. if(!options.size) { $(elem).css({width:"96%"}); }
  6676. } else if (!options.size) { options.size = 20; }
  6677. }
  6678. $(elem).attr("role",role);
  6679. }
  6680. return elem;
  6681. },
  6682. // Date Validation Javascript
  6683. checkDate : function (format, date) {
  6684. var daysInFebruary = function(year){
  6685. // February has 29 days in any year evenly divisible by four,
  6686. // EXCEPT for centurial years which are not also divisible by 400.
  6687. return (((year % 4 === 0) && ( year % 100 !== 0 || (year % 400 === 0))) ? 29 : 28 );
  6688. },
  6689. tsp = {}, sep;
  6690. format = format.toLowerCase();
  6691. //we search for /,-,. for the date separator
  6692. if(format.indexOf("/") !== -1) {
  6693. sep = "/";
  6694. } else if(format.indexOf("-") !== -1) {
  6695. sep = "-";
  6696. } else if(format.indexOf(".") !== -1) {
  6697. sep = ".";
  6698. } else {
  6699. sep = "/";
  6700. }
  6701. format = format.split(sep);
  6702. date = date.split(sep);
  6703. if (date.length !== 3) { return false; }
  6704. var j=-1,yln, dln=-1, mln=-1, i;
  6705. for(i=0;i<format.length;i++){
  6706. var dv = isNaN(date[i]) ? 0 : parseInt(date[i],10);
  6707. tsp[format[i]] = dv;
  6708. yln = format[i];
  6709. if(yln.indexOf("y") !== -1) { j=i; }
  6710. if(yln.indexOf("m") !== -1) { mln=i; }
  6711. if(yln.indexOf("d") !== -1) { dln=i; }
  6712. }
  6713. if (format[j] === "y" || format[j] === "yyyy") {
  6714. yln=4;
  6715. } else if(format[j] ==="yy"){
  6716. yln = 2;
  6717. } else {
  6718. yln = -1;
  6719. }
  6720. var daysInMonth = [0,31,29,31,30,31,30,31,31,30,31,30,31],
  6721. strDate;
  6722. if (j === -1) {
  6723. return false;
  6724. }
  6725. strDate = tsp[format[j]].toString();
  6726. if(yln === 2 && strDate.length === 1) {yln = 1;}
  6727. if (strDate.length !== yln || (tsp[format[j]]===0 && date[j]!=="00")){
  6728. return false;
  6729. }
  6730. if(mln === -1) {
  6731. return false;
  6732. }
  6733. strDate = tsp[format[mln]].toString();
  6734. if (strDate.length<1 || tsp[format[mln]]<1 || tsp[format[mln]]>12){
  6735. return false;
  6736. }
  6737. if(dln === -1) {
  6738. return false;
  6739. }
  6740. strDate = tsp[format[dln]].toString();
  6741. if (strDate.length<1 || tsp[format[dln]]<1 || tsp[format[dln]]>31 || (tsp[format[mln]]===2 && tsp[format[dln]]>daysInFebruary(tsp[format[j]])) || tsp[format[dln]] > daysInMonth[tsp[format[mln]]]){
  6742. return false;
  6743. }
  6744. return true;
  6745. },
  6746. isEmpty : function(val)
  6747. {
  6748. if (val === undefined || val.match(/^\s+$/) || val === "") {
  6749. return true;
  6750. }
  6751. return false;
  6752. },
  6753. checkTime : function(time){
  6754. // checks only hh:ss (and optional am/pm)
  6755. var re = /^(\d{1,2}):(\d{2})([apAP][Mm])?$/,regs;
  6756. if(!$.jgrid.isEmpty(time))
  6757. {
  6758. regs = time.match(re);
  6759. if(regs) {
  6760. if(regs[3]) {
  6761. if(regs[1] < 1 || regs[1] > 12) { return false; }
  6762. } else {
  6763. if(regs[1] > 23) { return false; }
  6764. }
  6765. if(regs[2] > 59) {
  6766. return false;
  6767. }
  6768. } else {
  6769. return false;
  6770. }
  6771. }
  6772. return true;
  6773. },
  6774. checkValues : function(val, valref, customobject, nam) {
  6775. var edtrul,i, nm, dft, len, g = this, cm = g.p.colModel,
  6776. msg = $.jgrid.getRegional(this, 'edit.msg'), fmtdate;
  6777. if(customobject === undefined) {
  6778. if(typeof valref==='string'){
  6779. for( i =0, len=cm.length;i<len; i++){
  6780. if(cm[i].name===valref) {
  6781. edtrul = cm[i].editrules;
  6782. valref = i;
  6783. if(cm[i].formoptions != null) { nm = cm[i].formoptions.label; }
  6784. break;
  6785. }
  6786. }
  6787. } else if(valref >=0) {
  6788. edtrul = cm[valref].editrules;
  6789. }
  6790. } else {
  6791. edtrul = customobject;
  6792. nm = nam===undefined ? "_" : nam;
  6793. }
  6794. if(edtrul) {
  6795. if(!nm) { nm = g.p.colNames != null ? g.p.colNames[valref] : cm[valref].label; }
  6796. if(edtrul.required === true) {
  6797. if( $.jgrid.isEmpty(val) ) { return [false,nm+": "+msg.required,""]; }
  6798. }
  6799. // force required
  6800. var rqfield = edtrul.required === false ? false : true;
  6801. if(edtrul.number === true) {
  6802. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6803. if(isNaN(val)) { return [false,nm+": "+msg.number,""]; }
  6804. }
  6805. }
  6806. if(edtrul.minValue !== undefined && !isNaN(edtrul.minValue)) {
  6807. if (parseFloat(val) < parseFloat(edtrul.minValue) ) { return [false,nm+": "+msg.minValue+" "+edtrul.minValue,""];}
  6808. }
  6809. if(edtrul.maxValue !== undefined && !isNaN(edtrul.maxValue)) {
  6810. if (parseFloat(val) > parseFloat(edtrul.maxValue) ) { return [false,nm+": "+msg.maxValue+" "+edtrul.maxValue,""];}
  6811. }
  6812. var filter;
  6813. if(edtrul.email === true) {
  6814. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6815. // taken from $ Validate plugin
  6816. filter = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
  6817. if(!filter.test(val)) {return [false,nm+": "+msg.email,""];}
  6818. }
  6819. }
  6820. if(edtrul.integer === true) {
  6821. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6822. if(isNaN(val)) { return [false,nm+": "+msg.integer,""]; }
  6823. if ((val % 1 !== 0) || (val.indexOf('.') !== -1)) { return [false,nm+": "+msg.integer,""];}
  6824. }
  6825. }
  6826. if(edtrul.date === true) {
  6827. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6828. if(cm[valref].formatoptions && cm[valref].formatoptions.newformat) {
  6829. dft = cm[valref].formatoptions.newformat;
  6830. fmtdate = $.jgrid.getRegional(g, 'formatter.date.masks');
  6831. if(fmtdate && fmtdate.hasOwnProperty(dft) ) {
  6832. dft = fmtdate[dft];
  6833. }
  6834. } else {
  6835. dft = cm[valref].datefmt || "Y-m-d";
  6836. }
  6837. if(!$.jgrid.checkDate (dft, val)) { return [false,nm+": "+msg.date+" - "+dft,""]; }
  6838. }
  6839. }
  6840. if(edtrul.time === true) {
  6841. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6842. if(!$.jgrid.checkTime (val)) { return [false,nm+": "+msg.date+" - hh:mm (am/pm)",""]; }
  6843. }
  6844. }
  6845. if(edtrul.url === true) {
  6846. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6847. filter = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
  6848. if(!filter.test(val)) {return [false,nm+": "+msg.url,""];}
  6849. }
  6850. }
  6851. if(edtrul.custom === true) {
  6852. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6853. if($.isFunction(edtrul.custom_func)) {
  6854. var ret = edtrul.custom_func.call(g,val,nm,valref);
  6855. return $.isArray(ret) ? ret : [false,msg.customarray,""];
  6856. }
  6857. return [false,msg.customfcheck,""];
  6858. }
  6859. }
  6860. }
  6861. return [true,"",""];
  6862. }
  6863. });
  6864. //module begin
  6865. $.fn.jqFilter = function( arg ) {
  6866. if (typeof arg === 'string') {
  6867. var fn = $.fn.jqFilter[arg];
  6868. if (!fn) {
  6869. throw ("jqFilter - No such method: " + arg);
  6870. }
  6871. var args = $.makeArray(arguments).slice(1);
  6872. return fn.apply(this,args);
  6873. }
  6874. var p = $.extend(true,{
  6875. filter: null,
  6876. columns: [],
  6877. sortStrategy: null,
  6878. onChange : null,
  6879. afterRedraw : null,
  6880. checkValues : null,
  6881. error: false,
  6882. errmsg : "",
  6883. errorcheck : true,
  6884. showQuery : true,
  6885. sopt : null,
  6886. ops : [],
  6887. operands : null,
  6888. numopts : ['eq','ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'],
  6889. stropts : ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 'nu', 'nn', 'in', 'ni'],
  6890. strarr : ['text', 'string', 'blob'],
  6891. groupOps : [{ op: "AND", text: "AND" }, { op: "OR", text: "OR" }],
  6892. groupButton : true,
  6893. ruleButtons : true,
  6894. uniqueSearchFields : false,
  6895. direction : "ltr",
  6896. addsubgrup : "Add subgroup",
  6897. addrule : "Add rule",
  6898. delgroup : "Delete group",
  6899. delrule : "Delete rule",
  6900. autoencode : false
  6901. }, $.jgrid.filter, arg || {});
  6902. return this.each( function() {
  6903. if (this.filter) {return;}
  6904. this.p = p;
  6905. // setup filter in case if they is not defined
  6906. if (this.p.filter === null || this.p.filter === undefined) {
  6907. this.p.filter = {
  6908. groupOp: this.p.groupOps[0].op,
  6909. rules: [],
  6910. groups: []
  6911. };
  6912. }
  6913. // Sort the columns if the sort strategy is provided.
  6914. if (this.p.sortStrategy != null && $.isFunction(this.p.sortStrategy)) {
  6915. this.p.columns.sort(this.p.sortStrategy);
  6916. }
  6917. var i, len = this.p.columns.length, cl,
  6918. isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  6919. // translating the options
  6920. this.p.initFilter = $.extend(true,{},this.p.filter);
  6921. // set default values for the columns if they are not set
  6922. if( !len ) {return;}
  6923. for(i=0; i < len; i++) {
  6924. cl = this.p.columns[i];
  6925. if( cl.stype ) {
  6926. // grid compatibility
  6927. cl.inputtype = cl.stype;
  6928. } else if(!cl.inputtype) {
  6929. cl.inputtype = 'text';
  6930. }
  6931. if( cl.sorttype ) {
  6932. // grid compatibility
  6933. cl.searchtype = cl.sorttype;
  6934. } else if (!cl.searchtype) {
  6935. cl.searchtype = 'string';
  6936. }
  6937. if(cl.hidden === undefined) {
  6938. // jqGrid compatibility
  6939. cl.hidden = false;
  6940. }
  6941. if(!cl.label) {
  6942. cl.label = cl.name;
  6943. }
  6944. if(cl.index) {
  6945. cl.name = cl.index;
  6946. }
  6947. if(!cl.hasOwnProperty('searchoptions')) {
  6948. cl.searchoptions = {};
  6949. }
  6950. if(!cl.hasOwnProperty('searchrules')) {
  6951. cl.searchrules = {};
  6952. }
  6953. if(cl.search === undefined) {
  6954. cl.inlist = true;
  6955. } else {
  6956. cl.inlist = cl.search;
  6957. }
  6958. }
  6959. var getGrid = function () {
  6960. return $("#" + $.jgrid.jqID(p.id))[0] || null;
  6961. },
  6962. $tg = getGrid(),
  6963. classes = $.jgrid.styleUI[($tg.p.styleUI || 'jQueryUI')].filter,
  6964. common = $.jgrid.styleUI[($tg.p.styleUI || 'jQueryUI')].common;
  6965. if(this.p.showQuery) {
  6966. $(this).append("<table class='queryresult " + classes.table_widget + "' style='display:block;max-width:440px;border:0px none;' dir='"+this.p.direction+"'><tbody><tr><td class='query'></td></tr></tbody></table>");
  6967. }
  6968. /*
  6969. *Perform checking.
  6970. *
  6971. */
  6972. var checkData = function(val, colModelItem) {
  6973. var ret = [true,""], $t = getGrid();
  6974. if($.isFunction(colModelItem.searchrules)) {
  6975. ret = colModelItem.searchrules.call($t, val, colModelItem);
  6976. } else if($.jgrid && $.jgrid.checkValues) {
  6977. try {
  6978. ret = $.jgrid.checkValues.call($t, val, -1, colModelItem.searchrules, colModelItem.label);
  6979. } catch (e) {}
  6980. }
  6981. if(ret && ret.length && ret[0] === false) {
  6982. p.error = !ret[0];
  6983. p.errmsg = ret[1];
  6984. }
  6985. };
  6986. /* moving to common
  6987. randId = function() {
  6988. return Math.floor(Math.random()*10000).toString();
  6989. };
  6990. */
  6991. this.onchange = function ( ){
  6992. // clear any error
  6993. this.p.error = false;
  6994. this.p.errmsg="";
  6995. return $.isFunction(this.p.onChange) ? this.p.onChange.call( this, this.p ) : false;
  6996. };
  6997. /*
  6998. * Redraw the filter every time when new field is added/deleted
  6999. * and field is changed
  7000. */
  7001. this.reDraw = function() {
  7002. $("table.group:first",this).remove();
  7003. var t = this.createTableForGroup(p.filter, null);
  7004. $(this).append(t);
  7005. if($.isFunction(this.p.afterRedraw) ) {
  7006. this.p.afterRedraw.call(this, this.p);
  7007. }
  7008. };
  7009. /*
  7010. * Creates a grouping data for the filter
  7011. * @param group - object
  7012. * @param parentgroup - object
  7013. */
  7014. this.createTableForGroup = function(group, parentgroup) {
  7015. var that = this, i;
  7016. // this table will hold all the group (tables) and rules (rows)
  7017. var table = $("<table class='group " + classes.table_widget +" ui-search-table' style='border:0px none;'><tbody></tbody></table>"),
  7018. // create error message row
  7019. align = "left";
  7020. if(this.p.direction === "rtl") {
  7021. align = "right";
  7022. table.attr("dir","rtl");
  7023. }
  7024. if(parentgroup === null) {
  7025. table.append("<tr class='error' style='display:none;'><th colspan='5' class='" + common.error + "' align='"+align+"'></th></tr>");
  7026. }
  7027. var tr = $("<tr></tr>");
  7028. table.append(tr);
  7029. // this header will hold the group operator type and group action buttons for
  7030. // creating subgroup "+ {}", creating rule "+" or deleting the group "-"
  7031. var th = $("<th colspan='5' align='"+align+"'></th>");
  7032. tr.append(th);
  7033. if(this.p.ruleButtons === true) {
  7034. // dropdown for: choosing group operator type
  7035. var groupOpSelect = $("<select class='opsel " + classes.srSelect + "'></select>");
  7036. th.append(groupOpSelect);
  7037. // populate dropdown with all posible group operators: or, and
  7038. var str= "", selected;
  7039. for (i = 0; i < p.groupOps.length; i++) {
  7040. selected = group.groupOp === that.p.groupOps[i].op ? " selected='selected'" :"";
  7041. str += "<option value='"+that.p.groupOps[i].op+"'" + selected+">"+that.p.groupOps[i].text+"</option>";
  7042. }
  7043. groupOpSelect
  7044. .append(str)
  7045. .on('change',function() {
  7046. group.groupOp = $(groupOpSelect).val();
  7047. that.onchange(); // signals that the filter has changed
  7048. });
  7049. }
  7050. // button for adding a new subgroup
  7051. var inputAddSubgroup ="<span></span>";
  7052. if(this.p.groupButton) {
  7053. inputAddSubgroup = $("<input type='button' value='+ {}' title='" +that.p.subgroup+"' class='add-group " + common.button + "'/>");
  7054. inputAddSubgroup.on('click',function() {
  7055. if (group.groups === undefined ) {
  7056. group.groups = [];
  7057. }
  7058. group.groups.push({
  7059. groupOp: p.groupOps[0].op,
  7060. rules: [],
  7061. groups: []
  7062. }); // adding a new group
  7063. that.reDraw(); // the html has changed, force reDraw
  7064. that.onchange(); // signals that the filter has changed
  7065. return false;
  7066. });
  7067. }
  7068. th.append(inputAddSubgroup);
  7069. if(this.p.ruleButtons === true) {
  7070. // button for adding a new rule
  7071. var inputAddRule = $("<input type='button' value='+' title='"+that.p.addrule+"' class='add-rule ui-add " + common.button + "'/>"), cm;
  7072. inputAddRule.on('click',function() {
  7073. //if(!group) { group = {};}
  7074. if (group.rules === undefined) {
  7075. group.rules = [];
  7076. }
  7077. for (i = 0; i < that.p.columns.length; i++) {
  7078. // but show only serchable and serchhidden = true fields
  7079. var searchable = (that.p.columns[i].search === undefined) ? true: that.p.columns[i].search,
  7080. hidden = (that.p.columns[i].hidden === true),
  7081. ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true);
  7082. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  7083. cm = that.p.columns[i];
  7084. break;
  7085. }
  7086. }
  7087. if( !cm ) {
  7088. return false;
  7089. }
  7090. var opr;
  7091. if( cm.searchoptions.sopt ) {opr = cm.searchoptions.sopt;}
  7092. else if(that.p.sopt) { opr= that.p.sopt; }
  7093. else if ( $.inArray(cm.searchtype, that.p.strarr) !== -1 ) {opr = that.p.stropts;}
  7094. else {opr = that.p.numopts;}
  7095. group.rules.push({
  7096. field: cm.name,
  7097. op: opr[0],
  7098. data: ""
  7099. }); // adding a new rule
  7100. that.reDraw(); // the html has changed, force reDraw
  7101. // for the moment no change have been made to the rule, so
  7102. // this will not trigger onchange event
  7103. return false;
  7104. });
  7105. th.append(inputAddRule);
  7106. }
  7107. // button for delete the group
  7108. if (parentgroup !== null) { // ignore the first group
  7109. var inputDeleteGroup = $("<input type='button' value='-' title='"+that.p.delgroup+"' class='delete-group " + common.button + "'/>");
  7110. th.append(inputDeleteGroup);
  7111. inputDeleteGroup.on('click',function() {
  7112. // remove group from parent
  7113. for (i = 0; i < parentgroup.groups.length; i++) {
  7114. if (parentgroup.groups[i] === group) {
  7115. parentgroup.groups.splice(i, 1);
  7116. break;
  7117. }
  7118. }
  7119. that.reDraw(); // the html has changed, force reDraw
  7120. that.onchange(); // signals that the filter has changed
  7121. return false;
  7122. });
  7123. }
  7124. // append subgroup rows
  7125. if (group.groups !== undefined) {
  7126. for (i = 0; i < group.groups.length; i++) {
  7127. var trHolderForSubgroup = $("<tr></tr>");
  7128. table.append(trHolderForSubgroup);
  7129. var tdFirstHolderForSubgroup = $("<td class='first'></td>");
  7130. trHolderForSubgroup.append(tdFirstHolderForSubgroup);
  7131. var tdMainHolderForSubgroup = $("<td colspan='4'></td>");
  7132. tdMainHolderForSubgroup.append(this.createTableForGroup(group.groups[i], group));
  7133. trHolderForSubgroup.append(tdMainHolderForSubgroup);
  7134. }
  7135. }
  7136. if(group.groupOp === undefined) {
  7137. group.groupOp = that.p.groupOps[0].op;
  7138. }
  7139. // append rules rows
  7140. var suni = that.p.ruleButtons && that.p.uniqueSearchFields, ii;
  7141. if( suni ) {
  7142. for ( ii = 0; ii < that.p.columns.length; ii++) {
  7143. if(that.p.columns[ii].inlist) {
  7144. that.p.columns[ii].search = true;
  7145. }
  7146. }
  7147. }
  7148. if (group.rules !== undefined) {
  7149. for (i = 0; i < group.rules.length; i++) {
  7150. table.append(
  7151. this.createTableRowForRule(group.rules[i], group)
  7152. );
  7153. if( suni ) {
  7154. var field = group.rules[i].field;
  7155. for ( ii = 0; ii < that.p.columns.length; ii++) {
  7156. if(field === that.p.columns[ii].name) {
  7157. that.p.columns[ii].search = false;
  7158. break;
  7159. }
  7160. }
  7161. }
  7162. }
  7163. }
  7164. return table;
  7165. };
  7166. /*
  7167. * Create the rule data for the filter
  7168. */
  7169. this.createTableRowForRule = function(rule, group ) {
  7170. // save current entity in a variable so that it could
  7171. // be referenced in anonimous method calls
  7172. var that=this, $t = getGrid(), tr = $("<tr></tr>"),
  7173. //document.createElement("tr"),
  7174. // first column used for padding
  7175. //tdFirstHolderForRule = document.createElement("td"),
  7176. i, op, trpar, cm, str="", selected;
  7177. //tdFirstHolderForRule.setAttribute("class", "first");
  7178. tr.append("<td class='first'></td>");
  7179. // create field container
  7180. var ruleFieldTd = $("<td class='columns'></td>");
  7181. tr.append(ruleFieldTd);
  7182. // dropdown for: choosing field
  7183. var ruleFieldSelect = $("<select class='" + classes.srSelect + "'></select>"), ina, aoprs = [];
  7184. ruleFieldTd.append(ruleFieldSelect);
  7185. ruleFieldSelect.on('change',function() {
  7186. if( that.p.ruleButtons && that.p.uniqueSearchFields ) {
  7187. var prev = parseInt($(this).data('curr'),10),
  7188. curr = this.selectedIndex;
  7189. if(prev >= 0 ) {
  7190. that.p.columns[prev].search = true;
  7191. $(this).data('curr', curr);
  7192. that.p.columns[curr].search = false;
  7193. }
  7194. }
  7195. rule.field = $(ruleFieldSelect).val();
  7196. trpar = $(this).parents("tr:first");
  7197. $(".data",trpar).empty();
  7198. for (i=0;i<that.p.columns.length;i++) {
  7199. if(that.p.columns[i].name === rule.field) {
  7200. cm = that.p.columns[i];
  7201. break;
  7202. }
  7203. }
  7204. if(!cm) {return;}
  7205. cm.searchoptions.id = $.jgrid.randId();
  7206. cm.searchoptions.name = rule.field;
  7207. cm.searchoptions.oper = 'filter';
  7208. if(isIE && cm.inputtype === "text") {
  7209. if(!cm.searchoptions.size) {
  7210. cm.searchoptions.size = 10;
  7211. }
  7212. }
  7213. var elm = $.jgrid.createEl.call($t, cm.inputtype,cm.searchoptions, "", true, that.p.ajaxSelectOptions || {}, true);
  7214. $(elm).addClass("input-elm " + classes.srInput );
  7215. //that.createElement(rule, "");
  7216. if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;}
  7217. else if(that.p.sopt) { op= that.p.sopt; }
  7218. else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;}
  7219. else {op = that.p.numopts;}
  7220. // operators
  7221. var s ="", so = 0;
  7222. aoprs = [];
  7223. $.each(that.p.ops, function() { aoprs.push(this.oper); });
  7224. for ( i = 0 ; i < op.length; i++) {
  7225. ina = $.inArray(op[i],aoprs);
  7226. if(ina !== -1) {
  7227. if(so===0) {
  7228. rule.op = that.p.ops[ina].oper;
  7229. }
  7230. s += "<option value='"+that.p.ops[ina].oper+"'>"+that.p.ops[ina].text+"</option>";
  7231. so++;
  7232. }
  7233. }
  7234. $(".selectopts",trpar).empty().append( s );
  7235. $(".selectopts",trpar)[0].selectedIndex = 0;
  7236. if( $.jgrid.msie() && $.jgrid.msiever() < 9) {
  7237. var sw = parseInt($("select.selectopts",trpar)[0].offsetWidth, 10) + 1;
  7238. $(".selectopts",trpar).width( sw );
  7239. $(".selectopts",trpar).css("width","auto");
  7240. }
  7241. // data
  7242. $(".data",trpar).append( elm );
  7243. $.jgrid.bindEv.call($t, elm, cm.searchoptions);
  7244. $(".input-elm",trpar).on('change',function( e ) {
  7245. var elem = e.target;
  7246. if( cm.inputtype === 'custom' && $.isFunction(cm.searchoptions.custom_value) ) {
  7247. rule.data = cm.searchoptions.custom_value.call($t, $(".customelement", this), 'get');
  7248. } else {
  7249. rule.data = $(elem).val();
  7250. }
  7251. if(cm.inputtype === 'select' && cm.searchoptions.multiple ) {
  7252. rule.data = rule.data.join(",");
  7253. }
  7254. that.onchange(); // signals that the filter has changed
  7255. });
  7256. setTimeout(function(){ //IE, Opera, Chrome
  7257. rule.data = $(elm).val();
  7258. that.onchange(); // signals that the filter has changed
  7259. }, 0);
  7260. });
  7261. // populate drop down with user provided column definitions
  7262. var j=0;
  7263. for (i = 0; i < that.p.columns.length; i++) {
  7264. // but show only serchable and serchhidden = true fields
  7265. var searchable = (that.p.columns[i].search === undefined) ? true: that.p.columns[i].search,
  7266. hidden = (that.p.columns[i].hidden === true),
  7267. ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true);
  7268. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  7269. selected = "";
  7270. if(rule.field === that.p.columns[i].name) {
  7271. selected = " selected='selected'";
  7272. j=i;
  7273. }
  7274. str += "<option value='"+that.p.columns[i].name+"'" +selected+">"+that.p.columns[i].label+"</option>";
  7275. }
  7276. }
  7277. ruleFieldSelect.append( str );
  7278. ruleFieldSelect.data('curr', j);
  7279. // create operator container
  7280. var ruleOperatorTd = $("<td class='operators'></td>");
  7281. tr.append(ruleOperatorTd);
  7282. cm = p.columns[j];
  7283. // create it here so it can be referentiated in the onchange event
  7284. //var RD = that.createElement(rule, rule.data);
  7285. cm.searchoptions.id = $.jgrid.randId();
  7286. if(isIE && cm.inputtype === "text") {
  7287. if(!cm.searchoptions.size) {
  7288. cm.searchoptions.size = 10;
  7289. }
  7290. }
  7291. cm.searchoptions.name = rule.field;
  7292. cm.searchoptions.oper = 'filter';
  7293. var ruleDataInput = $.jgrid.createEl.call($t, cm.inputtype,cm.searchoptions, rule.data, true, that.p.ajaxSelectOptions || {}, true);
  7294. if(rule.op === 'nu' || rule.op === 'nn') {
  7295. $(ruleDataInput).attr('readonly','true');
  7296. $(ruleDataInput).attr('disabled','true');
  7297. } //retain the state of disabled text fields in case of null ops
  7298. // dropdown for: choosing operator
  7299. var ruleOperatorSelect = $("<select class='selectopts " + classes.srSelect + "'></select>");
  7300. ruleOperatorTd.append(ruleOperatorSelect);
  7301. ruleOperatorSelect.on('change',function() {
  7302. rule.op = $(ruleOperatorSelect).val();
  7303. trpar = $(this).parents("tr:first");
  7304. var rd = $(".input-elm",trpar)[0];
  7305. if (rule.op === "nu" || rule.op === "nn") { // disable for operator "is null" and "is not null"
  7306. rule.data = "";
  7307. if(rd.tagName.toUpperCase() !== 'SELECT') { rd.value = ""; }
  7308. rd.setAttribute("readonly", "true");
  7309. rd.setAttribute("disabled", "true");
  7310. } else {
  7311. if(rd.tagName.toUpperCase() === 'SELECT') { rule.data = rd.value; }
  7312. rd.removeAttribute("readonly");
  7313. rd.removeAttribute("disabled");
  7314. }
  7315. that.onchange(); // signals that the filter has changed
  7316. });
  7317. // populate drop down with all available operators
  7318. if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;}
  7319. else if(that.p.sopt) { op= that.p.sopt; }
  7320. else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;}
  7321. else {op = that.p.numopts;}
  7322. str="";
  7323. $.each(that.p.ops, function() { aoprs.push(this.oper); });
  7324. for ( i = 0; i < op.length; i++) {
  7325. ina = $.inArray(op[i],aoprs);
  7326. if(ina !== -1) {
  7327. selected = rule.op === that.p.ops[ina].oper ? " selected='selected'" : "";
  7328. str += "<option value='"+that.p.ops[ina].oper+"'"+selected+">"+that.p.ops[ina].text+"</option>";
  7329. }
  7330. }
  7331. ruleOperatorSelect.append( str );
  7332. // create data container
  7333. var ruleDataTd = $("<td class='data'></td>");
  7334. tr.append(ruleDataTd);
  7335. // textbox for: data
  7336. // is created previously
  7337. //ruleDataInput.setAttribute("type", "text");
  7338. ruleDataTd.append(ruleDataInput);
  7339. $.jgrid.bindEv.call($t, ruleDataInput, cm.searchoptions);
  7340. $(ruleDataInput)
  7341. .addClass("input-elm " + classes.srInput )
  7342. .on('change', function() {
  7343. rule.data = cm.inputtype === 'custom' ? cm.searchoptions.custom_value.call($t, $(".customelement", this),'get') : $(this).val();
  7344. that.onchange(); // signals that the filter has changed
  7345. });
  7346. // create action container
  7347. var ruleDeleteTd = $("<td></td>");
  7348. tr.append(ruleDeleteTd);
  7349. // create button for: delete rule
  7350. if(this.p.ruleButtons === true) {
  7351. var ruleDeleteInput = $("<input type='button' value='-' title='"+that.p.delrule+"' class='delete-rule ui-del " + common.button + "'/>");
  7352. ruleDeleteTd.append(ruleDeleteInput);
  7353. //$(ruleDeleteInput).html("").height(20).width(30).button({icons: { primary: "ui-icon-minus", text:false}});
  7354. ruleDeleteInput.on('click',function() {
  7355. // remove rule from group
  7356. for (i = 0; i < group.rules.length; i++) {
  7357. if (group.rules[i] === rule) {
  7358. group.rules.splice(i, 1);
  7359. break;
  7360. }
  7361. }
  7362. that.reDraw(); // the html has changed, force reDraw
  7363. that.onchange(); // signals that the filter has changed
  7364. return false;
  7365. });
  7366. }
  7367. return tr;
  7368. };
  7369. this.getStringForGroup = function(group) {
  7370. var s = "(", index;
  7371. if (group.groups !== undefined) {
  7372. for (index = 0; index < group.groups.length; index++) {
  7373. if (s.length > 1) {
  7374. s += " " + group.groupOp + " ";
  7375. }
  7376. try {
  7377. s += this.getStringForGroup(group.groups[index]);
  7378. } catch (eg) {alert(eg);}
  7379. }
  7380. }
  7381. if (group.rules !== undefined) {
  7382. try{
  7383. for (index = 0; index < group.rules.length; index++) {
  7384. if (s.length > 1) {
  7385. s += " " + group.groupOp + " ";
  7386. }
  7387. s += this.getStringForRule(group.rules[index]);
  7388. }
  7389. } catch (e) {alert(e);}
  7390. }
  7391. s += ")";
  7392. if (s === "()") {
  7393. return ""; // ignore groups that don't have rules
  7394. }
  7395. return s;
  7396. };
  7397. this.getStringForRule = function(rule) {
  7398. var opUF = "",opC="", i, cm, ret, val,
  7399. numtypes = ['int', 'integer', 'float', 'number', 'currency']; // jqGrid
  7400. for (i = 0; i < this.p.ops.length; i++) {
  7401. if (this.p.ops[i].oper === rule.op) {
  7402. opUF = this.p.operands.hasOwnProperty(rule.op) ? this.p.operands[rule.op] : "";
  7403. opC = this.p.ops[i].oper;
  7404. break;
  7405. }
  7406. }
  7407. for (i=0; i<this.p.columns.length; i++) {
  7408. if(this.p.columns[i].name === rule.field) {
  7409. cm = this.p.columns[i];
  7410. break;
  7411. }
  7412. }
  7413. if (cm === undefined) { return ""; }
  7414. val = this.p.autoencode ? $.jgrid.htmlEncode(rule.data) : rule.data;
  7415. if(opC === 'bw' || opC === 'bn') { val = val+"%"; }
  7416. if(opC === 'ew' || opC === 'en') { val = "%"+val; }
  7417. if(opC === 'cn' || opC === 'nc') { val = "%"+val+"%"; }
  7418. if(opC === 'in' || opC === 'ni') { val = " ("+val+")"; }
  7419. if(p.errorcheck) { checkData(rule.data, cm); }
  7420. if($.inArray(cm.searchtype, numtypes) !== -1 || opC === 'nn' || opC === 'nu') { ret = rule.field + " " + opUF + " " + val; }
  7421. else { ret = rule.field + " " + opUF + " \"" + val + "\""; }
  7422. return ret;
  7423. };
  7424. this.resetFilter = function () {
  7425. this.p.filter = $.extend(true,{},this.p.initFilter);
  7426. this.reDraw();
  7427. this.onchange();
  7428. };
  7429. this.hideError = function() {
  7430. $("th."+common.error, this).html("");
  7431. $("tr.error", this).hide();
  7432. };
  7433. this.showError = function() {
  7434. $("th."+common.error, this).html(this.p.errmsg);
  7435. $("tr.error", this).show();
  7436. };
  7437. this.toUserFriendlyString = function() {
  7438. return this.getStringForGroup(p.filter);
  7439. };
  7440. this.toString = function() {
  7441. // this will obtain a string that can be used to match an item.
  7442. var that = this;
  7443. function getStringRule(rule) {
  7444. if(that.p.errorcheck) {
  7445. var i, cm;
  7446. for (i=0; i<that.p.columns.length; i++) {
  7447. if(that.p.columns[i].name === rule.field) {
  7448. cm = that.p.columns[i];
  7449. break;
  7450. }
  7451. }
  7452. if(cm) {checkData(rule.data, cm);}
  7453. }
  7454. return rule.op + "(item." + rule.field + ",'" + rule.data + "')";
  7455. }
  7456. function getStringForGroup(group) {
  7457. var s = "(", index;
  7458. if (group.groups !== undefined) {
  7459. for (index = 0; index < group.groups.length; index++) {
  7460. if (s.length > 1) {
  7461. if (group.groupOp === "OR") {
  7462. s += " || ";
  7463. }
  7464. else {
  7465. s += " && ";
  7466. }
  7467. }
  7468. s += getStringForGroup(group.groups[index]);
  7469. }
  7470. }
  7471. if (group.rules !== undefined) {
  7472. for (index = 0; index < group.rules.length; index++) {
  7473. if (s.length > 1) {
  7474. if (group.groupOp === "OR") {
  7475. s += " || ";
  7476. }
  7477. else {
  7478. s += " && ";
  7479. }
  7480. }
  7481. s += getStringRule(group.rules[index]);
  7482. }
  7483. }
  7484. s += ")";
  7485. if (s === "()") {
  7486. return ""; // ignore groups that don't have rules
  7487. }
  7488. return s;
  7489. }
  7490. return getStringForGroup(this.p.filter);
  7491. };
  7492. // Here we init the filter
  7493. this.reDraw();
  7494. if(this.p.showQuery) {
  7495. this.onchange();
  7496. }
  7497. // mark is as created so that it will not be created twice on this element
  7498. this.filter = true;
  7499. });
  7500. };
  7501. $.extend($.fn.jqFilter,{
  7502. /*
  7503. * Return SQL like string. Can be used directly
  7504. */
  7505. toSQLString : function()
  7506. {
  7507. var s ="";
  7508. this.each(function(){
  7509. s = this.toUserFriendlyString();
  7510. });
  7511. return s;
  7512. },
  7513. /*
  7514. * Return filter data as object.
  7515. */
  7516. filterData : function()
  7517. {
  7518. var s;
  7519. this.each(function(){
  7520. s = this.p.filter;
  7521. });
  7522. return s;
  7523. },
  7524. getParameter : function (param) {
  7525. if(param !== undefined) {
  7526. if (this.p.hasOwnProperty(param) ) {
  7527. return this.p[param];
  7528. }
  7529. }
  7530. return this.p;
  7531. },
  7532. resetFilter: function() {
  7533. return this.each(function(){
  7534. this.resetFilter();
  7535. });
  7536. },
  7537. addFilter: function (pfilter) {
  7538. if (typeof pfilter === "string") {
  7539. pfilter = $.jgrid.parse( pfilter );
  7540. }
  7541. this.each(function(){
  7542. this.p.filter = pfilter;
  7543. this.reDraw();
  7544. this.onchange();
  7545. });
  7546. }
  7547. });
  7548. $.extend($.jgrid,{
  7549. filterRefactor : function ( p ) {
  7550. /*ruleGroup : {}, ssfield:[], splitSelect:",", groupOpSelect:"OR"*/
  7551. var filters={} /*?*/, rules, k, rule, ssdata, group;
  7552. try {
  7553. filters = typeof p.ruleGroudp === "string" ? $.jgrid.parse(p.ruleGroup) : p.ruleGroup;
  7554. if(filters.rules && filters.rules.length) {
  7555. rules = filters.rules;
  7556. for(k=0; k < rules.length; k++) {
  7557. rule = rules[k];
  7558. if($.inArray(rule.filed, p.ssfield)) {
  7559. ssdata = rule.data.split(p.splitSelect);
  7560. if(ssdata.length > 1) {
  7561. if(filters.groups === undefined) {
  7562. filters.groups = [];
  7563. }
  7564. group = { groupOp: p.groupOpSelect, groups: [], rules: [] };
  7565. filters.groups.push(group);
  7566. $.each(ssdata,function(l) {
  7567. if (ssdata[l]) {
  7568. group.rules.push({ data: ssdata[l], op: rule.op, field: rule.field});
  7569. }
  7570. });
  7571. rules.splice(k, 1);
  7572. k--;
  7573. }
  7574. }
  7575. }
  7576. }
  7577. } catch(e) {}
  7578. return filters;
  7579. }
  7580. });
  7581. $.jgrid.extend({
  7582. filterToolbar : function(p){
  7583. var regional = $.jgrid.getRegional(this[0], 'search');
  7584. p = $.extend({
  7585. autosearch: true,
  7586. autosearchDelay: 500,
  7587. searchOnEnter : true,
  7588. beforeSearch: null,
  7589. afterSearch: null,
  7590. beforeClear: null,
  7591. afterClear: null,
  7592. onClearSearchValue : null,
  7593. url : '',
  7594. stringResult: false,
  7595. groupOp: 'AND',
  7596. defaultSearch : "bw",
  7597. searchOperators : false,
  7598. resetIcon : "x",
  7599. splitSelect : ",",
  7600. groupOpSelect : "OR",
  7601. operands : { "eq" :"==", "ne":"!","lt":"<","le":"<=","gt":">","ge":">=","bw":"^","bn":"!^","in":"=","ni":"!=","ew":"|","en":"!@","cn":"~","nc":"!~","nu":"#","nn":"!#", "bt":"..."}
  7602. }, regional , p || {});
  7603. return this.each(function(){
  7604. var $t = this;
  7605. if($t.p.filterToolbar) { return; }
  7606. if(!$($t).data('filterToolbar')) {
  7607. $($t).data('filterToolbar', p);
  7608. }
  7609. if($t.p.force_regional) {
  7610. p = $.extend(p, regional);
  7611. }
  7612. var classes = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].filter,
  7613. common = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].common,
  7614. base = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].base,
  7615. triggerToolbar = function() {
  7616. var sdata={}, j=0, v, nm, sopt={},so, ms = false, ssfield = [], bbt =false, sop;
  7617. $.each($t.p.colModel,function(){
  7618. var $elem = $("#gs_"+ $t.p.idPrefix + $.jgrid.jqID(this.name), (this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv);
  7619. nm = this.index || this.name;
  7620. sop = this.searchoptions || {};
  7621. if(p.searchOperators && sop.searchOperMenu) {
  7622. so = $elem.parent().prev().children("a").attr("soper") || p.defaultSearch;
  7623. } else {
  7624. so = (sop.sopt) ? sop.sopt[0] : this.stype==='select' ? 'eq' : p.defaultSearch;
  7625. }
  7626. v = this.stype === "custom" && $.isFunction(sop.custom_value) && $elem.length > 0 ?
  7627. sop.custom_value.call($t, $elem, "get") :
  7628. $elem.val();
  7629. // detect multiselect
  7630. if(this.stype === 'select' && sop.multiple && $.isArray(v) && v.length) {
  7631. ms = true;
  7632. ssfield.push(nm);
  7633. v= v.length === 1 ? v[0] : v;
  7634. }
  7635. if(so==="bt") {
  7636. bbt = true;
  7637. }
  7638. if(v || so==="nu" || so==="nn") {
  7639. sdata[nm] = v;
  7640. sopt[nm] = so;
  7641. j++;
  7642. } else {
  7643. try {
  7644. delete $t.p.postData[nm];
  7645. } catch (z) {}
  7646. }
  7647. });
  7648. var sd = j>0 ? true : false;
  7649. if(p.stringResult === true || $t.p.datatype === "local" || p.searchOperators === true)
  7650. {
  7651. var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
  7652. var gi=0;
  7653. $.each(sdata,function(i,n){
  7654. if (gi > 0) {ruleGroup += ",";}
  7655. ruleGroup += "{\"field\":\"" + i + "\",";
  7656. ruleGroup += "\"op\":\"" + sopt[i] + "\",";
  7657. n+="";
  7658. ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  7659. gi++;
  7660. });
  7661. ruleGroup += "]}";
  7662. // multiselect
  7663. var filters, rules, k,str, rule, ssdata, group;
  7664. if(ms) {
  7665. $.jgrid.filterRefactor({
  7666. ruleGroup : ruleGroup,
  7667. ssfield : ssfield,
  7668. splitSelect : p.splitSelect,
  7669. groupOpSelect : p.groupOpSelect
  7670. });
  7671. //ruleGroup = JSON.stringify( filters );
  7672. }
  7673. if(bbt) {
  7674. if(!$.isPlainObject(filters)) {
  7675. filters = $.jgrid.parse(ruleGroup);
  7676. }
  7677. if(filters.rules && filters.rules.length) {
  7678. rules = filters.rules;
  7679. for(k=0;k < rules.length; k++) {
  7680. rule = rules[k];
  7681. if(rule.op === "bt") {
  7682. ssdata = rule.data.split("...");
  7683. if(ssdata.length > 1) {
  7684. if(filters.groups === undefined) {
  7685. filters.groups = [];
  7686. }
  7687. group = { groupOp: 'AND', groups: [], rules: [] };
  7688. filters.groups.push(group);
  7689. $.each(ssdata,function(l) {
  7690. var btop = l === 0 ? 'ge' : 'le';
  7691. str = ssdata[l];
  7692. if(str) {
  7693. group.rules.push({ data: ssdata[l], op: btop, field: rule.field});
  7694. }
  7695. });
  7696. rules.splice(k, 1);
  7697. k--;
  7698. }
  7699. }
  7700. }
  7701. }
  7702. }
  7703. if(bbt || ms ) {
  7704. ruleGroup = JSON.stringify( filters );
  7705. }
  7706. $.extend($t.p.postData,{filters:ruleGroup});
  7707. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  7708. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  7709. });
  7710. } else {
  7711. $.extend($t.p.postData,sdata);
  7712. }
  7713. var saveurl;
  7714. if(p.url) {
  7715. saveurl = $t.p.url;
  7716. $($t).jqGrid("setGridParam", { url: p.url });
  7717. }
  7718. var bsr = $($t).triggerHandler("jqGridToolbarBeforeSearch") === 'stop' ? true : false;
  7719. if(!bsr && $.isFunction(p.beforeSearch)){bsr = p.beforeSearch.call($t);}
  7720. if(!bsr) { $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); }
  7721. if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
  7722. $($t).triggerHandler("jqGridToolbarAfterSearch");
  7723. if($.isFunction(p.afterSearch)){p.afterSearch.call($t);}
  7724. },
  7725. clearToolbar = function(trigger){
  7726. var sdata={}, j=0, nm;
  7727. trigger = (typeof trigger !== 'boolean') ? true : trigger;
  7728. $.each($t.p.colModel,function(){
  7729. var v, $elem = $("#gs_"+$t.p.idPrefix+$.jgrid.jqID(this.name),(this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv);
  7730. if(this.searchoptions && this.searchoptions.defaultValue !== undefined) {
  7731. v = this.searchoptions.defaultValue;
  7732. }
  7733. nm = this.index || this.name;
  7734. switch (this.stype) {
  7735. case 'select' :
  7736. $elem.find("option").each(function (i){
  7737. if(i===0) { this.selected = true; }
  7738. if ($(this).val() === v) {
  7739. this.selected = true;
  7740. return false;
  7741. }
  7742. });
  7743. if ( v !== undefined ) {
  7744. // post the key and not the text
  7745. sdata[nm] = v;
  7746. j++;
  7747. } else {
  7748. try {
  7749. delete $t.p.postData[nm];
  7750. } catch(e) {}
  7751. }
  7752. break;
  7753. case 'text':
  7754. $elem.val(v || "");
  7755. if(v !== undefined) {
  7756. sdata[nm] = v;
  7757. j++;
  7758. } else {
  7759. try {
  7760. delete $t.p.postData[nm];
  7761. } catch (y){}
  7762. }
  7763. break;
  7764. case 'custom':
  7765. if ($.isFunction(this.searchoptions.custom_value) && $elem.length > 0 ) {
  7766. this.searchoptions.custom_value.call($t, $elem, "set", v || "");
  7767. }
  7768. break;
  7769. }
  7770. });
  7771. var sd = j>0 ? true : false;
  7772. $t.p.resetsearch = true;
  7773. if(p.stringResult === true || $t.p.datatype === "local") {
  7774. var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
  7775. var gi=0;
  7776. $.each(sdata,function(i,n){
  7777. if (gi > 0) {ruleGroup += ",";}
  7778. ruleGroup += "{\"field\":\"" + i + "\",";
  7779. ruleGroup += "\"op\":\"" + "eq" + "\",";
  7780. n+="";
  7781. ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  7782. gi++;
  7783. });
  7784. ruleGroup += "]}";
  7785. $.extend($t.p.postData,{filters:ruleGroup});
  7786. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  7787. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  7788. });
  7789. } else {
  7790. $.extend($t.p.postData,sdata);
  7791. }
  7792. var saveurl;
  7793. if(p.url) {
  7794. saveurl = $t.p.url;
  7795. $($t).jqGrid("setGridParam",{url:p.url});
  7796. }
  7797. var bcv = $($t).triggerHandler("jqGridToolbarBeforeClear") === 'stop' ? true : false;
  7798. if(!bcv && $.isFunction(p.beforeClear)){bcv = p.beforeClear.call($t);}
  7799. if(!bcv) {
  7800. if(trigger) {
  7801. $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]);
  7802. }
  7803. }
  7804. if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
  7805. $($t).triggerHandler("jqGridToolbarAfterClear");
  7806. if($.isFunction(p.afterClear)){p.afterClear();}
  7807. },
  7808. toggleToolbar = function(){
  7809. var trow = $("tr.ui-search-toolbar",$t.grid.hDiv);
  7810. if($t.p.frozenColumns === true) {
  7811. $($t).jqGrid('destroyFrozenColumns');
  7812. }
  7813. if(trow.css("display") === 'none') {
  7814. trow.show();
  7815. } else {
  7816. trow.hide();
  7817. }
  7818. if($t.p.frozenColumns === true) {
  7819. $($t).jqGrid("setFrozenColumns");
  7820. }
  7821. },
  7822. buildRuleMenu = function( elem, left, top ){
  7823. $("#sopt_menu").remove();
  7824. left=parseInt(left,10);
  7825. top=parseInt(top,10) + 18;
  7826. var fs = $('.ui-jqgrid-view').css('font-size') || '11px';
  7827. var str = '<ul id="sopt_menu" class="ui-search-menu modal-content" role="menu" tabindex="0" style="font-size:'+fs+';left:'+left+'px;top:'+top+'px;">',
  7828. selected = $(elem).attr("soper"), selclass,
  7829. aoprs = [], ina;
  7830. var i=0, nm =$(elem).attr("colname"),len = $t.p.colModel.length;
  7831. while(i<len) {
  7832. if($t.p.colModel[i].name === nm) {
  7833. break;
  7834. }
  7835. i++;
  7836. }
  7837. var cm = $t.p.colModel[i], options = $.extend({}, cm.searchoptions);
  7838. if(!options.sopt) {
  7839. options.sopt = [];
  7840. options.sopt[0]= cm.stype==='select' ? 'eq' : p.defaultSearch;
  7841. }
  7842. $.each(p.odata, function() { aoprs.push(this.oper); });
  7843. for ( i = 0 ; i < options.sopt.length; i++) {
  7844. ina = $.inArray(options.sopt[i],aoprs);
  7845. if(ina !== -1) {
  7846. selclass = selected === p.odata[ina].oper ? common.highlight : "";
  7847. str += '<li class="ui-menu-item '+selclass+'" role="presentation"><a class="'+ common.cornerall+' g-menu-item" tabindex="0" role="menuitem" value="'+p.odata[ina].oper+'" oper="'+p.operands[p.odata[ina].oper]+'"><table class="ui-common-table"><tr><td width="25px">'+p.operands[p.odata[ina].oper]+'</td><td>'+ p.odata[ina].text+'</td></tr></table></a></li>';
  7848. }
  7849. }
  7850. str += "</ul>";
  7851. $('body').append(str);
  7852. $("#sopt_menu").addClass("ui-menu " + classes.menu_widget);
  7853. $("#sopt_menu > li > a").hover(
  7854. function(){ $(this).addClass(common.hover); },
  7855. function(){ $(this).removeClass(common.hover); }
  7856. ).click(function() {
  7857. var v = $(this).attr("value"),
  7858. oper = $(this).attr("oper");
  7859. $($t).triggerHandler("jqGridToolbarSelectOper", [v, oper, elem]);
  7860. $("#sopt_menu").hide();
  7861. $(elem).text(oper).attr("soper",v);
  7862. if(p.autosearch===true){
  7863. var inpelm = $(elem).parent().next().children()[0];
  7864. if( $(inpelm).val() || v==="nu" || v ==="nn") {
  7865. triggerToolbar();
  7866. }
  7867. }
  7868. });
  7869. };
  7870. // create the row
  7871. var tr = $("<tr class='ui-search-toolbar' role='row'></tr>"),
  7872. timeoutHnd, rules, filterobj;
  7873. if( p.restoreFromFilters ) {
  7874. filterobj = $t.p.postData.filters;
  7875. if(filterobj) {
  7876. if( typeof filterobj === "string") {
  7877. filterobj = $.jgrid.parse( filterobj );
  7878. }
  7879. rules = filterobj.rules.length ? filterobj.rules : false;
  7880. }
  7881. }
  7882. $.each($t.p.colModel,function(ci){
  7883. var cm=this, soptions, select="", sot="=", so, i, st, csv, df, elem, restores,
  7884. th = $("<th role='columnheader' class='" + base.headerBox+" ui-th-"+$t.p.direction+"' id='gsh_" + $t.p.id + "_" + cm.name + "' ></th>"),
  7885. thd = $("<div></div>"),
  7886. stbl = $("<table class='ui-search-table' cellspacing='0'><tr><td class='ui-search-oper' headers=''></td><td class='ui-search-input' headers=''></td><td class='ui-search-clear' headers=''></td></tr></table>");
  7887. if(this.hidden===true) { $(th).css("display","none");}
  7888. this.search = this.search === false ? false : true;
  7889. if(this.stype === undefined) {this.stype='text';}
  7890. this.searchoptions = this.searchoptions || {};
  7891. if(this.searchoptions.searchOperMenu === undefined) {
  7892. this.searchoptions.searchOperMenu = true;
  7893. }
  7894. soptions = $.extend({},this.searchoptions , {name:cm.index || cm.name, id: "gs_"+$t.p.idPrefix+cm.name, oper:'search'});
  7895. if(this.search){
  7896. if( p.restoreFromFilters && rules) {
  7897. restores = false;
  7898. for( var is = 0; is < rules.length; is++) {
  7899. if(rules[is].field ) {
  7900. var snm = cm.index || cm.name;
  7901. if( snm === rules[is].field) {
  7902. restores = rules[is];
  7903. break;
  7904. }
  7905. }
  7906. }
  7907. }
  7908. if(p.searchOperators) {
  7909. so = (soptions.sopt) ? soptions.sopt[0] : cm.stype==='select' ? 'eq' : p.defaultSearch;
  7910. // overwrite search operators
  7911. if( p.restoreFromFilters && restores) {
  7912. so = restores.op;
  7913. }
  7914. for(i = 0;i<p.odata.length;i++) {
  7915. if(p.odata[i].oper === so) {
  7916. sot = p.operands[so] || "";
  7917. break;
  7918. }
  7919. }
  7920. st = soptions.searchtitle != null ? soptions.searchtitle : p.operandTitle;
  7921. select = this.searchoptions.searchOperMenu ? "<a title='"+st+"' style='padding-right: 0.5em;' soper='"+so+"' class='soptclass' colname='"+this.name+"'>"+sot+"</a>" : "";
  7922. }
  7923. $("td:eq(0)",stbl).attr("colindex",ci).append(select);
  7924. if(soptions.clearSearch === undefined) {
  7925. soptions.clearSearch = true;
  7926. }
  7927. if(soptions.clearSearch) {
  7928. csv = p.resetTitle || 'Clear Search Value';
  7929. $("td:eq(2)",stbl).append("<a title='"+csv+"' style='padding-right: 0.3em;padding-left: 0.3em;' class='clearsearchclass'>"+p.resetIcon+"</a>");
  7930. } else {
  7931. $("td:eq(2)", stbl).hide();
  7932. }
  7933. if(this.surl) {
  7934. soptions.dataUrl = this.surl;
  7935. }
  7936. df="";
  7937. if(soptions.defaultValue ) {
  7938. df = $.isFunction(soptions.defaultValue) ? soptions.defaultValue.call($t) : soptions.defaultValue;
  7939. }
  7940. //overwrite default value if restore from filters
  7941. if( p.restoreFromFilters && restores) {
  7942. df = restores.data;
  7943. }
  7944. elem = $.jgrid.createEl.call($t, this.stype, soptions , df, false, $.extend({},$.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {}));
  7945. $(elem).addClass( classes.srInput );
  7946. $("td:eq(1)",stbl).append(elem);
  7947. $(thd).append(stbl);
  7948. if(soptions.dataEvents == null ) {
  7949. soptions.dataEvents = [];
  7950. }
  7951. switch (this.stype)
  7952. {
  7953. case "select":
  7954. if(p.autosearch === true) {
  7955. soptions.dataEvents.push({
  7956. type : "change",
  7957. fn : function() {
  7958. triggerToolbar();
  7959. return false;
  7960. }
  7961. });
  7962. }
  7963. break;
  7964. case "text":
  7965. if(p.autosearch===true){
  7966. if(p.searchOnEnter) {
  7967. soptions.dataEvents.push({
  7968. type: "keypress",
  7969. fn : function(e) {
  7970. var key = e.charCode || e.keyCode || 0;
  7971. if(key === 13){
  7972. triggerToolbar();
  7973. return false;
  7974. }
  7975. return this;
  7976. }
  7977. });
  7978. } else {
  7979. soptions.dataEvents.push({
  7980. type: "keydown",
  7981. fn : function(e) {
  7982. var key = e.which;
  7983. switch (key) {
  7984. case 13:
  7985. return false;
  7986. case 9 :
  7987. case 16:
  7988. case 37:
  7989. case 38:
  7990. case 39:
  7991. case 40:
  7992. case 27:
  7993. break;
  7994. default :
  7995. if(timeoutHnd) { clearTimeout(timeoutHnd); }
  7996. timeoutHnd = setTimeout(function(){triggerToolbar();}, p.autosearchDelay);
  7997. }
  7998. }
  7999. });
  8000. }
  8001. }
  8002. break;
  8003. }
  8004. $.jgrid.bindEv.call($t, elem , soptions);
  8005. }
  8006. $(th).append(thd);
  8007. $(tr).append(th);
  8008. if(!p.searchOperators || select === "") {
  8009. $("td:eq(0)",stbl).hide();
  8010. }
  8011. });
  8012. $("table thead",$t.grid.hDiv).append(tr);
  8013. if(p.searchOperators) {
  8014. $(".soptclass",tr).click(function(e){
  8015. var offset = $(this).offset(),
  8016. left = ( offset.left ),
  8017. top = ( offset.top);
  8018. buildRuleMenu(this, left, top );
  8019. e.stopPropagation();
  8020. });
  8021. $("body").on('click', function(e){
  8022. if(e.target.className !== "soptclass") {
  8023. $("#sopt_menu").remove();
  8024. }
  8025. });
  8026. }
  8027. $(".clearsearchclass",tr).click(function() {
  8028. var ptr = $(this).parents("tr:first"),
  8029. coli = parseInt($("td.ui-search-oper", ptr).attr('colindex'),10),
  8030. sval = $.extend({},$t.p.colModel[coli].searchoptions || {}),
  8031. dval = sval.defaultValue ? sval.defaultValue : "",
  8032. elem;
  8033. if($t.p.colModel[coli].stype === "select") {
  8034. elem = $("td.ui-search-input select", ptr);
  8035. if(dval) {
  8036. elem.val( dval );
  8037. } else {
  8038. elem[0].selectedIndex = 0;
  8039. }
  8040. } else {
  8041. elem = $("td.ui-search-input input", ptr);
  8042. elem.val( dval );
  8043. }
  8044. $($t).triggerHandler("jqGridToolbarClearVal",[elem[0], coli, sval, dval]);
  8045. if($.isFunction(p.onClearSearchValue)) {
  8046. p.onClearSearchValue.call($t, elem[0], coli, sval, dval);
  8047. }
  8048. // ToDo custom search type
  8049. if(p.autosearch===true){
  8050. triggerToolbar();
  8051. }
  8052. });
  8053. this.p.filterToolbar = true;
  8054. this.triggerToolbar = triggerToolbar;
  8055. this.clearToolbar = clearToolbar;
  8056. this.toggleToolbar = toggleToolbar;
  8057. });
  8058. },
  8059. destroyFilterToolbar: function () {
  8060. return this.each(function () {
  8061. if (!this.p.filterToolbar) {
  8062. return;
  8063. }
  8064. this.triggerToolbar = null;
  8065. this.clearToolbar = null;
  8066. this.toggleToolbar = null;
  8067. this.p.filterToolbar = false;
  8068. $(this.grid.hDiv).find("table thead tr.ui-search-toolbar").remove();
  8069. });
  8070. },
  8071. refreshFilterToolbar : function ( p ) {
  8072. p = $.extend(true, {
  8073. filters : "",
  8074. onClearVal : null,
  8075. onSetVal : null
  8076. }, p || {});
  8077. return this.each(function () {
  8078. var $t = this, cm = $t.p.colModel, i, l = $t.p.colModel.length,
  8079. searchitem, filters, rules, rule, ssfield =[], ia;
  8080. // clear the values on toolbar.
  8081. // do not call clearToolbar
  8082. if(!$t.p.filterToolbar) {
  8083. return;
  8084. }
  8085. for (i = 0; i < l; i++) {
  8086. ssfield.push(cm[i].name);
  8087. searchitem = $("#gs_" +$t.p.idPrefix+ $.jgrid.jqID(cm[i].name));
  8088. switch (cm[i].stype) {
  8089. case 'select' :
  8090. case 'text' :
  8091. searchitem.val("");
  8092. break;
  8093. }
  8094. if($.isFunction(p.onClearVal)) {
  8095. p.onClearVal.call($t, searchitem, cm[i].name);
  8096. }
  8097. }
  8098. function setrules (filter) {
  8099. if(filter && filter.rules) { // condition to exit
  8100. rules = filter.rules;
  8101. l = rules.length;
  8102. for (i = 0; i < l; i++) {
  8103. rule = rules[i];
  8104. ia = $.inArray(rule.field, ssfield);
  8105. if( ia !== -1) {
  8106. searchitem = $("#gs_" + $t.p.idPrefix + $.jgrid.jqID(cm[ia].name));
  8107. // problem for between operator
  8108. if ( searchitem.length > 0) {
  8109. if (cm[ia].stype === "select") {
  8110. searchitem.find("option[value='" + $.jgrid.jqID(rule.data) + "']").prop('selected', true);
  8111. } else if (cm[ia].stype === "text") {
  8112. searchitem.val(rule.data);
  8113. }
  8114. if($.isFunction(p.onSetVal)) {
  8115. p.onSetVal.call($t, searchitem, cm[ia].name);
  8116. }
  8117. }
  8118. }
  8119. }
  8120. if(filter.groups) {
  8121. for(var k=0;k<filter.groups.length;k++) {
  8122. setrules(filter.groups[k]);
  8123. }
  8124. }
  8125. }
  8126. }
  8127. if (typeof (p.filters) === "string" && p.filters.length) {
  8128. filters = $.jgrid.parse(p.filters);
  8129. // flat filters only
  8130. }
  8131. if ($.isPlainObject(filters)) {
  8132. setrules( filters );
  8133. }
  8134. });
  8135. },
  8136. searchGrid : function (p) {
  8137. var regional = $.jgrid.getRegional(this[0], 'search');
  8138. p = $.extend(true, {
  8139. recreateFilter: false,
  8140. drag: true,
  8141. sField:'searchField',
  8142. sValue:'searchString',
  8143. sOper: 'searchOper',
  8144. sFilter: 'filters',
  8145. loadDefaults: true, // this options activates loading of default filters from grid's postData for Multipe Search only.
  8146. beforeShowSearch: null,
  8147. afterShowSearch : null,
  8148. onInitializeSearch: null,
  8149. afterRedraw : null,
  8150. afterChange: null,
  8151. sortStrategy: null,
  8152. closeAfterSearch : false,
  8153. closeAfterReset: false,
  8154. closeOnEscape : false,
  8155. searchOnEnter : false,
  8156. multipleSearch : false,
  8157. multipleGroup : false,
  8158. //cloneSearchRowOnAdd: true,
  8159. top : 0,
  8160. left: 0,
  8161. jqModal : true,
  8162. modal: false,
  8163. resize : true,
  8164. width: 450,
  8165. height: 'auto',
  8166. dataheight: 'auto',
  8167. showQuery: false,
  8168. errorcheck : true,
  8169. sopt: null,
  8170. stringResult: undefined,
  8171. onClose : null,
  8172. onSearch : null,
  8173. onReset : null,
  8174. toTop : true,
  8175. overlay : 30,
  8176. columns : [],
  8177. tmplNames : null,
  8178. tmplFilters : null,
  8179. tmplLabel : ' Template: ',
  8180. showOnLoad: false,
  8181. layer: null,
  8182. splitSelect : ",",
  8183. groupOpSelect : "OR",
  8184. operands : { "eq" :"=", "ne":"<>","lt":"<","le":"<=","gt":">","ge":">=","bw":"LIKE","bn":"NOT LIKE","in":"IN","ni":"NOT IN","ew":"LIKE","en":"NOT LIKE","cn":"LIKE","nc":"NOT LIKE","nu":"IS NULL","nn":"ISNOT NULL"}
  8185. }, regional, p || {});
  8186. return this.each(function() {
  8187. var $t = this;
  8188. if(!$t.grid) {return;}
  8189. var fid = "fbox_"+$t.p.id,
  8190. showFrm = true,
  8191. mustReload = true,
  8192. IDs = {themodal:'searchmod'+fid,modalhead:'searchhd'+fid,modalcontent:'searchcnt'+fid, scrollelm : fid},
  8193. defaultFilters = ($.isPlainObject($t.p_savedFilter) && !$.isEmptyObject($t.p_savedFilter ) ) ? $t.p_savedFilter : $t.p.postData[p.sFilter],
  8194. fl,
  8195. classes = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].filter,
  8196. common = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].common;
  8197. p.styleUI = $t.p.styleUI;
  8198. if(typeof defaultFilters === "string") {
  8199. defaultFilters = $.jgrid.parse( defaultFilters );
  8200. }
  8201. if(p.recreateFilter === true) {
  8202. $("#"+$.jgrid.jqID(IDs.themodal)).remove();
  8203. }
  8204. function showFilter(_filter) {
  8205. showFrm = $($t).triggerHandler("jqGridFilterBeforeShow", [_filter]);
  8206. if(showFrm === undefined) {
  8207. showFrm = true;
  8208. }
  8209. if(showFrm && $.isFunction(p.beforeShowSearch)) {
  8210. showFrm = p.beforeShowSearch.call($t,_filter);
  8211. }
  8212. if(showFrm) {
  8213. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(fid),jqm:p.jqModal, modal:p.modal, overlay: p.overlay, toTop: p.toTop});
  8214. $($t).triggerHandler("jqGridFilterAfterShow", [_filter]);
  8215. if($.isFunction(p.afterShowSearch)) {
  8216. p.afterShowSearch.call($t, _filter);
  8217. }
  8218. }
  8219. }
  8220. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  8221. showFilter($("#fbox_"+$.jgrid.jqID( $t.p.id )));
  8222. } else {
  8223. var fil = $("<div><div id='"+fid+"' class='searchFilter' style='overflow:auto'></div></div>").insertBefore("#gview_"+$.jgrid.jqID($t.p.id)),
  8224. align = "left", butleft ="";
  8225. if($t.p.direction === "rtl") {
  8226. align = "right";
  8227. butleft = " style='text-align:left'";
  8228. fil.attr("dir","rtl");
  8229. }
  8230. var columns = $.extend([],$t.p.colModel),
  8231. bS ="<a id='"+fid+"_search' class='fm-button " + common.button + " fm-button-icon-right ui-search'><span class='" + common.icon_base + " " +classes.icon_search + "'></span>"+p.Find+"</a>",
  8232. bC ="<a id='"+fid+"_reset' class='fm-button " + common.button +" fm-button-icon-left ui-reset'><span class='" + common.icon_base + " " +classes.icon_reset + "'></span>"+p.Reset+"</a>",
  8233. bQ = "", tmpl="", colnm, found = false, bt, cmi=-1, ms = false, ssfield = [];
  8234. if(p.showQuery) {
  8235. bQ ="<a id='"+fid+"_query' class='fm-button " + common.button + " fm-button-icon-left'><span class='" + common.icon_base + " " +classes.icon_query + "'></span>Query</a>";
  8236. }
  8237. if(!p.columns.length) {
  8238. $.each(columns, function(i,n){
  8239. if(!n.label) {
  8240. n.label = $t.p.colNames[i];
  8241. }
  8242. // find first searchable column and set it if no default filter
  8243. if(!found) {
  8244. var searchable = (n.search === undefined) ? true: n.search ,
  8245. hidden = (n.hidden === true),
  8246. ignoreHiding = (n.searchoptions && n.searchoptions.searchhidden === true);
  8247. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  8248. found = true;
  8249. colnm = n.index || n.name;
  8250. cmi =i;
  8251. }
  8252. }
  8253. if( n.stype==="select" && n.searchoptions && n.searchoptions.multiple) {
  8254. ms = true;
  8255. ssfield.push( n.index || n.name );
  8256. }
  8257. });
  8258. } else {
  8259. columns = p.columns;
  8260. cmi = 0;
  8261. colnm = columns[0].index || columns[0].name;
  8262. }
  8263. // old behaviour
  8264. if( (!defaultFilters && colnm) || p.multipleSearch === false ) {
  8265. var cmop = "eq";
  8266. if(cmi >=0 && columns[cmi].searchoptions && columns[cmi].searchoptions.sopt) {
  8267. cmop = columns[cmi].searchoptions.sopt[0];
  8268. } else if(p.sopt && p.sopt.length) {
  8269. cmop = p.sopt[0];
  8270. }
  8271. defaultFilters = {groupOp: "AND", rules: [{field: colnm, op: cmop, data: ""}]};
  8272. }
  8273. found = false;
  8274. if(p.tmplNames && p.tmplNames.length) {
  8275. found = true;
  8276. tmpl = "<tr><td class='ui-search-label'>"+ p.tmplLabel +"</td>";
  8277. tmpl += "<td><select class='ui-template " + classes.srSelect + "'>";
  8278. tmpl += "<option value='default'>Default</option>";
  8279. $.each(p.tmplNames, function(i,n){
  8280. tmpl += "<option value='"+i+"'>"+n+"</option>";
  8281. });
  8282. tmpl += "</select></td></tr>";
  8283. }
  8284. bt = "<table class='EditTable' style='border:0px none;margin-top:5px' id='"+fid+"_2'><tbody><tr><td colspan='2'><hr class='" + common.content + "' style='margin:1px'/></td></tr>"+tmpl+"<tr><td class='EditButton' style='text-align:"+align+"'>"+bC+"</td><td class='EditButton' "+butleft+">"+bQ+bS+"</td></tr></tbody></table>";
  8285. fid = $.jgrid.jqID( fid);
  8286. $("#"+fid).jqFilter({
  8287. columns: columns,
  8288. sortStrategy: p.sortStrategy,
  8289. filter: p.loadDefaults ? defaultFilters : null,
  8290. showQuery: p.showQuery,
  8291. errorcheck : p.errorcheck,
  8292. sopt: p.sopt,
  8293. groupButton : p.multipleGroup,
  8294. ruleButtons : p.multipleSearch,
  8295. uniqueSearchFields : p.uniqueSearchFields,
  8296. afterRedraw : p.afterRedraw,
  8297. ops : p.odata,
  8298. operands : p.operands,
  8299. ajaxSelectOptions: $t.p.ajaxSelectOptions,
  8300. groupOps: p.groupOps,
  8301. addsubgrup : p.addsubgrup,
  8302. addrule : p.addrule,
  8303. delgroup : p.delgroup,
  8304. delrule : p.delrule,
  8305. autoencode : $t.p.autoencode,
  8306. onChange : function() {
  8307. if(this.p.showQuery) {
  8308. $('.query',this).html(this.toUserFriendlyString());
  8309. }
  8310. if ($.isFunction(p.afterChange)) {
  8311. p.afterChange.call($t, $("#"+fid), p);
  8312. }
  8313. },
  8314. direction : $t.p.direction,
  8315. id: $t.p.id
  8316. });
  8317. fil.append( bt );
  8318. if(found && p.tmplFilters && p.tmplFilters.length) {
  8319. $(".ui-template", fil).on('change', function(){
  8320. var curtempl = $(this).val();
  8321. if(curtempl==="default") {
  8322. $("#"+fid).jqFilter('addFilter', defaultFilters);
  8323. } else {
  8324. $("#"+fid).jqFilter('addFilter', p.tmplFilters[parseInt(curtempl,10)]);
  8325. }
  8326. return false;
  8327. });
  8328. }
  8329. if(p.multipleGroup === true) {p.multipleSearch = true;}
  8330. $($t).triggerHandler("jqGridFilterInitialize", [$("#"+fid)]);
  8331. if($.isFunction(p.onInitializeSearch) ) {
  8332. p.onInitializeSearch.call($t, $("#"+fid));
  8333. }
  8334. p.gbox = "#gbox_"+fid;
  8335. if (p.layer) {
  8336. $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0], "#"+$.jgrid.jqID(p.layer), {position: "relative"});
  8337. } else {
  8338. $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]);
  8339. }
  8340. if (p.searchOnEnter || p.closeOnEscape) {
  8341. $("#"+$.jgrid.jqID(IDs.themodal)).keydown(function (e) {
  8342. var $target = $(e.target);
  8343. if (p.searchOnEnter && e.which === 13 && // 13 === $.ui.keyCode.ENTER
  8344. !$target.hasClass('add-group') && !$target.hasClass('add-rule') &&
  8345. !$target.hasClass('delete-group') && !$target.hasClass('delete-rule') &&
  8346. (!$target.hasClass("fm-button") || !$target.is("[id$=_query]"))) {
  8347. $("#"+fid+"_search").click();
  8348. return false;
  8349. }
  8350. if (p.closeOnEscape && e.which === 27) { // 27 === $.ui.keyCode.ESCAPE
  8351. $("#"+$.jgrid.jqID(IDs.modalhead)).find(".ui-jqdialog-titlebar-close").click();
  8352. return false;
  8353. }
  8354. });
  8355. }
  8356. if(bQ) {
  8357. $("#"+fid+"_query").on('click', function(){
  8358. $(".queryresult", fil).toggle();
  8359. return false;
  8360. });
  8361. }
  8362. if (p.stringResult===undefined) {
  8363. // to provide backward compatibility, inferring stringResult value from multipleSearch
  8364. p.stringResult = p.multipleSearch;
  8365. }
  8366. $("#"+fid+"_search").on('click', function(){
  8367. var sdata={}, res, filters;
  8368. fl = $("#"+fid);
  8369. fl.find(".input-elm:focus").change();
  8370. if( ms && p.multipleSearch) {
  8371. $t.p_savedFilter = {};
  8372. filters = $.jgrid.filterRefactor({
  8373. ruleGroup: $.extend(true, {}, fl.jqFilter('filterData')),
  8374. ssfield : ssfield,
  8375. splitSelect : p.splitSelect,
  8376. groupOpSelect : p.groupOpSelect
  8377. });
  8378. $t.p_savedFilter = $.extend(true, {}, fl.jqFilter('filterData'));
  8379. } else {
  8380. filters = fl.jqFilter('filterData');
  8381. }
  8382. if(p.errorcheck) {
  8383. fl[0].hideError();
  8384. if(!p.showQuery) {fl.jqFilter('toSQLString');}
  8385. if(fl[0].p.error) {
  8386. fl[0].showError();
  8387. return false;
  8388. }
  8389. }
  8390. if(p.stringResult) {
  8391. try {
  8392. res = JSON.stringify(filters);
  8393. } catch (e2) { }
  8394. if(typeof res==="string") {
  8395. sdata[p.sFilter] = res;
  8396. $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";});
  8397. }
  8398. } else {
  8399. if(p.multipleSearch) {
  8400. sdata[p.sFilter] = filters;
  8401. $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";});
  8402. } else {
  8403. sdata[p.sField] = filters.rules[0].field;
  8404. sdata[p.sValue] = filters.rules[0].data;
  8405. sdata[p.sOper] = filters.rules[0].op;
  8406. sdata[p.sFilter] = "";
  8407. }
  8408. }
  8409. $t.p.search = true;
  8410. $.extend($t.p.postData,sdata);
  8411. mustReload = $($t).triggerHandler("jqGridFilterSearch");
  8412. if( mustReload === undefined) {
  8413. mustReload = true;
  8414. }
  8415. if(mustReload && $.isFunction(p.onSearch) ) {
  8416. mustReload = p.onSearch.call($t, $t.p.filters);
  8417. }
  8418. if (mustReload !== false) {
  8419. $($t).trigger("reloadGrid",[{page:1}]);
  8420. }
  8421. if(p.closeAfterSearch) {
  8422. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:p.jqModal,onClose: p.onClose});
  8423. }
  8424. return false;
  8425. });
  8426. $("#"+fid+"_reset").on('click', function(){
  8427. var sdata={},
  8428. fl = $("#"+fid);
  8429. $t.p.search = false;
  8430. $t.p.resetsearch = true;
  8431. if(p.multipleSearch===false) {
  8432. sdata[p.sField] = sdata[p.sValue] = sdata[p.sOper] = "";
  8433. } else {
  8434. sdata[p.sFilter] = "";
  8435. }
  8436. fl[0].resetFilter();
  8437. if(found) {
  8438. $(".ui-template", fil).val("default");
  8439. }
  8440. $.extend($t.p.postData,sdata);
  8441. mustReload = $($t).triggerHandler("jqGridFilterReset");
  8442. if(mustReload === undefined) {
  8443. mustReload = true;
  8444. }
  8445. if(mustReload && $.isFunction(p.onReset) ) {
  8446. mustReload = p.onReset.call($t);
  8447. }
  8448. if(mustReload !== false) {
  8449. $($t).trigger("reloadGrid",[{page:1}]);
  8450. }
  8451. if (p.closeAfterReset) {
  8452. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:p.jqModal,onClose: p.onClose});
  8453. }
  8454. return false;
  8455. });
  8456. showFilter($("#"+fid));
  8457. $(".fm-button:not(."+common.disabled+")",fil).hover(
  8458. function(){$(this).addClass(common.hover);},
  8459. function(){$(this).removeClass(common.hover);}
  8460. );
  8461. }
  8462. });
  8463. },
  8464. filterInput : function( val, p) {
  8465. p = $.extend(true, {
  8466. defaultSearch : 'cn',
  8467. groupOp : 'OR',
  8468. searchAll : false,
  8469. beforeSearch : null,
  8470. afterSearch : null
  8471. }, p || {});
  8472. return this.each(function(){
  8473. var $t = this;
  8474. if(!$t.grid) {return;}
  8475. var nm, sop,ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[", gi=0, so;
  8476. val +="";
  8477. if($t.p.datatype !== 'local') { return; }
  8478. $.each($t.p.colModel,function(){
  8479. nm = this.index || this.name;
  8480. sop = this.searchoptions || {};
  8481. so = p.defaultSearch ? p.defaultSearch : (sop.sopt) ? sop.sopt[0] : p.defaultSearch;
  8482. this.search = this.search === false ? false : true;
  8483. if (this.search || p.searchAll) {
  8484. if (gi > 0) {ruleGroup += ",";}
  8485. ruleGroup += "{\"field\":\"" + nm + "\",";
  8486. ruleGroup += "\"op\":\"" + so + "\",";
  8487. ruleGroup += "\"data\":\"" + val.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  8488. gi++;
  8489. }
  8490. });
  8491. ruleGroup += "]}";
  8492. $.extend($t.p.postData,{filters:ruleGroup});
  8493. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  8494. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  8495. });
  8496. var bsr = $($t).triggerHandler("jqGridFilterInputBeforeSearch") === 'stop' ? true : false;
  8497. if(!bsr && $.isFunction(p.beforeSearch)){bsr = p.beforeSearch.call($t);}
  8498. if(!bsr) { $($t).jqGrid("setGridParam",{search:true}).trigger("reloadGrid",[{page:1}]); }
  8499. $($t).triggerHandler("jqGridFilterInputAfterSearch");
  8500. if($.isFunction(p.afterSearch)){p.afterSearch.call($t);}
  8501. });
  8502. }
  8503. });
  8504. //module begin
  8505. var rp_ge = {};
  8506. $.jgrid.extend({
  8507. editGridRow : function(rowid, p){
  8508. var regional = $.jgrid.getRegional(this[0], 'edit'),
  8509. currstyle = this[0].p.styleUI,
  8510. styles = $.jgrid.styleUI[currstyle].formedit,
  8511. commonstyle = $.jgrid.styleUI[currstyle].common;
  8512. p = $.extend(true, {
  8513. top : 0,
  8514. left: 0,
  8515. width: '500',
  8516. datawidth: 'auto',
  8517. height: 'auto',
  8518. dataheight: 'auto',
  8519. modal: false,
  8520. overlay : 30,
  8521. drag: true,
  8522. resize: true,
  8523. url: null,
  8524. mtype : "POST",
  8525. clearAfterAdd :true,
  8526. closeAfterEdit : false,
  8527. reloadAfterSubmit : true,
  8528. onInitializeForm: null,
  8529. beforeInitData: null,
  8530. beforeShowForm: null,
  8531. afterShowForm: null,
  8532. beforeSubmit: null,
  8533. afterSubmit: null,
  8534. onclickSubmit: null,
  8535. afterComplete: null,
  8536. onclickPgButtons : null,
  8537. afterclickPgButtons: null,
  8538. editData : {},
  8539. recreateForm : false,
  8540. jqModal : true,
  8541. closeOnEscape : false,
  8542. addedrow : "first",
  8543. topinfo : '',
  8544. bottominfo: '',
  8545. saveicon : [],
  8546. closeicon : [],
  8547. savekey: [false,13],
  8548. navkeys: [false,38,40],
  8549. checkOnSubmit : false,
  8550. checkOnUpdate : false,
  8551. processing : false,
  8552. onClose : null,
  8553. ajaxEditOptions : {},
  8554. serializeEditData : null,
  8555. viewPagerButtons : true,
  8556. overlayClass : commonstyle.overlay,
  8557. removemodal : true,
  8558. form: 'edit',
  8559. template : null,
  8560. focusField : true,
  8561. editselected : false
  8562. }, regional, p || {});
  8563. rp_ge[$(this)[0].p.id] = p;
  8564. return this.each(function(){
  8565. var $t = this;
  8566. if (!$t.grid || !rowid) {return;}
  8567. $t.p.savedData = {};
  8568. var gID = $t.p.id,
  8569. frmgr = "FrmGrid_"+gID, frmtborg = "TblGrid_"+gID, frmtb = "#"+$.jgrid.jqID(frmtborg), frmtb2,
  8570. IDs = {themodal:'editmod'+gID,modalhead:'edithd'+gID,modalcontent:'editcnt'+gID, scrollelm : frmgr},
  8571. showFrm = true, maxCols = 1, maxRows=0, postdata, diff, frmoper,
  8572. templ = typeof rp_ge[$t.p.id].template === "string" && rp_ge[$t.p.id].template.length > 0,
  8573. errors =$.jgrid.getRegional(this, 'errors');
  8574. rp_ge[$t.p.id].styleUI = $t.p.styleUI || 'jQueryUI';
  8575. if($.jgrid.isMobile()) {
  8576. rp_ge[$t.p.id].resize = false;
  8577. }
  8578. if (rowid === "new") {
  8579. rowid = "_empty";
  8580. frmoper = "add";
  8581. p.caption=rp_ge[$t.p.id].addCaption;
  8582. } else {
  8583. p.caption=rp_ge[$t.p.id].editCaption;
  8584. frmoper = "edit";
  8585. }
  8586. if(!p.recreateForm) {
  8587. if( $($t).data("formProp") ) {
  8588. $.extend(rp_ge[$(this)[0].p.id], $($t).data("formProp"));
  8589. }
  8590. }
  8591. var closeovrl = true;
  8592. if(p.checkOnUpdate && p.jqModal && !p.modal) {
  8593. closeovrl = false;
  8594. }
  8595. function getFormData(){
  8596. var a2 ={}, i;
  8597. $(frmtb).find(".FormElement").each(function() {
  8598. var celm = $(".customelement", this);
  8599. if (celm.length) {
  8600. var elem = celm[0], nm = $(elem).attr('name');
  8601. $.each($t.p.colModel, function(){
  8602. if(this.name === nm && this.editoptions && $.isFunction(this.editoptions.custom_value)) {
  8603. try {
  8604. postdata[nm] = this.editoptions.custom_value.call($t, $("#"+$.jgrid.jqID(nm),frmtb),'get');
  8605. if (postdata[nm] === undefined) {throw "e1";}
  8606. } catch (e) {
  8607. if (e==="e1") {$.jgrid.info_dialog(errors.errcap,"function 'custom_value' "+rp_ge[$(this)[0]].p.msg.novalue,rp_ge[$(this)[0]].p.bClose, {styleUI : rp_ge[$(this)[0]].p.styleUI });}
  8608. else {$.jgrid.info_dialog(errors.errcap,e.message,rp_ge[$(this)[0]].p.bClose, {styleUI : rp_ge[$(this)[0]].p.styleUI });}
  8609. }
  8610. return true;
  8611. }
  8612. });
  8613. } else {
  8614. switch ($(this).get(0).type) {
  8615. case "checkbox":
  8616. if($(this).is(":checked")) {
  8617. postdata[this.name]= $(this).val();
  8618. } else {
  8619. var ofv = $(this).attr("offval");
  8620. postdata[this.name]= ofv;
  8621. }
  8622. break;
  8623. case "select-one":
  8624. postdata[this.name]= $(this).val();
  8625. break;
  8626. case "select-multiple":
  8627. postdata[this.name]= $(this).val();
  8628. postdata[this.name] = postdata[this.name] ? postdata[this.name].join(",") : "";
  8629. break;
  8630. case "password":
  8631. case "text":
  8632. case "textarea":
  8633. case "button":
  8634. postdata[this.name] = $(this).val();
  8635. break;
  8636. case "radio" :
  8637. if(a2.hasOwnProperty(this.name)) {
  8638. return true;
  8639. } else {
  8640. a2[this.name] = ($(this).attr("offval") === undefined) ? "off" : $(this).attr("offval");
  8641. }
  8642. break;
  8643. }
  8644. if($t.p.autoencode) {
  8645. postdata[this.name] = $.jgrid.htmlEncode(postdata[this.name]);
  8646. }
  8647. }
  8648. });
  8649. for(i in a2 ) {
  8650. if( a2.hasOwnProperty(i)) {
  8651. var val = $('input[name="'+i+'"]:checked',frmtb).val();
  8652. postdata[i] = (val !== undefined) ? val : a2[i];
  8653. if($t.p.autoencode) {
  8654. postdata[i] = $.jgrid.htmlEncode(postdata[i]);
  8655. }
  8656. }
  8657. }
  8658. return true;
  8659. }
  8660. function createData(rowid,obj,tb,maxcols){
  8661. var nm, hc,trdata, cnt=0,tmp, dc,elc, retpos=[], ind=false,
  8662. tdtmpl = "<td class='CaptionTD'>&#160;</td><td class='DataTD'>&#160;</td>", tmpl="", i, ffld; //*2
  8663. for (i =1; i<=maxcols;i++) {
  8664. tmpl += tdtmpl;
  8665. }
  8666. if(rowid !== '_empty') {
  8667. ind = $(obj).jqGrid("getInd",rowid);
  8668. }
  8669. $(obj.p.colModel).each( function(i) {
  8670. nm = this.name;
  8671. // hidden fields are included in the form
  8672. if(this.editrules && this.editrules.edithidden === true) {
  8673. hc = false;
  8674. } else {
  8675. hc = this.hidden === true ? true : false;
  8676. }
  8677. dc = hc ? "style='display:none'" : "";
  8678. if ( nm !== 'cb' && nm !== 'subgrid' && this.editable===true && nm !== 'rn') {
  8679. if(ind === false) {
  8680. tmp = "";
  8681. } else {
  8682. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  8683. tmp = $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text();
  8684. } else {
  8685. try {
  8686. tmp = $.unformat.call(obj, $("td[role='gridcell']:eq("+i+")",obj.rows[ind]),{rowId:rowid, colModel:this},i);
  8687. } catch (_) {
  8688. tmp = (this.edittype && this.edittype === "textarea") ? $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text() : $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).html();
  8689. }
  8690. if(!tmp || tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  8691. }
  8692. }
  8693. var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm, rowId: rowid, oper:'edit'}),
  8694. frmopt = $.extend({}, {elmprefix:'',elmsuffix:'',rowabove:false,rowcontent:''}, this.formoptions || {}),
  8695. rp = parseInt(frmopt.rowpos,10) || cnt+1,
  8696. cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
  8697. if(rowid === "_empty" && opt.defaultValue ) {
  8698. tmp = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
  8699. }
  8700. if(!this.edittype) {this.edittype = "text";}
  8701. if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
  8702. elc = $.jgrid.createEl.call($t,this.edittype,opt,tmp,false,$.extend({},$.jgrid.ajaxOptions,obj.p.ajaxSelectOptions || {}));
  8703. //if(tmp === "" && this.edittype == "checkbox") {tmp = $(elc).attr("offval");}
  8704. //if(tmp === "" && this.edittype == "select") {tmp = $("option:eq(0)",elc).text();}
  8705. if(this.edittype === "select") {
  8706. tmp = $(elc).val();
  8707. if($(elc).get(0).type === 'select-multiple' && tmp) {
  8708. tmp = tmp.join(",");
  8709. }
  8710. }
  8711. if(this.edittype === 'checkbox') {
  8712. if($(elc).is(":checked")) {
  8713. tmp= $(elc).val();
  8714. } else {
  8715. tmp = $(elc).attr("offval");
  8716. }
  8717. }
  8718. $(elc).addClass("FormElement");
  8719. if( $.inArray(this.edittype, ['text','textarea','password','select']) > -1) {
  8720. $(elc).addClass( styles.inputClass );
  8721. }
  8722. ffld = true;
  8723. if(templ) {
  8724. var ftmplfld = $(frm).find("#"+nm);
  8725. if(ftmplfld.length){
  8726. ftmplfld.replaceWith( elc );
  8727. } else {
  8728. ffld = false;
  8729. }
  8730. } else {
  8731. //--------------------
  8732. trdata = $(tb).find("tr[rowpos="+rp+"]");
  8733. if(frmopt.rowabove) {
  8734. var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
  8735. $(tb).append(newdata);
  8736. newdata[0].rp = rp;
  8737. }
  8738. if ( trdata.length===0 ) {
  8739. trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","tr_"+nm);
  8740. $(trdata).append(tmpl);
  8741. $(tb).append(trdata);
  8742. trdata[0].rp = rp;
  8743. }
  8744. $("td:eq("+(cp-2)+")",trdata[0]).html("<label for='"+nm+"'>"+ (frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label) + "</label>");
  8745. $("td:eq("+(cp-1)+")",trdata[0]).append(frmopt.elmprefix).append(elc).append(frmopt.elmsuffix);
  8746. //-------------------------
  8747. }
  8748. if( (rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) && ffld) {
  8749. $t.p.savedData[nm] = tmp;
  8750. }
  8751. if(this.edittype==='custom' && $.isFunction(opt.custom_value) ) {
  8752. opt.custom_value.call($t, $("#"+nm, frmgr),'set',tmp);
  8753. }
  8754. $.jgrid.bindEv.call($t, elc, opt);
  8755. retpos[cnt] = i;
  8756. cnt++;
  8757. }
  8758. });
  8759. if( cnt > 0) {
  8760. var idrow;
  8761. if(templ) {
  8762. idrow = "<div class='FormData' style='display:none'><input class='FormElement' id='id_g' type='text' name='"+obj.p.id+"_id' value='"+rowid+"'/>";
  8763. $(frm).append(idrow);
  8764. } else {
  8765. idrow = $("<tr class='FormData' style='display:none'><td class='CaptionTD'></td><td colspan='"+ (maxcols*2-1)+"' class='DataTD'><input class='FormElement' id='id_g' type='text' name='"+obj.p.id+"_id' value='"+rowid+"'/></td></tr>");
  8766. idrow[0].rp = cnt+999;
  8767. $(tb).append(idrow);
  8768. }
  8769. //$(tb).append(idrow);
  8770. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  8771. $t.p.savedData[obj.p.id+"_id"] = rowid;
  8772. }
  8773. }
  8774. return retpos;
  8775. }
  8776. function fillData(rowid,obj,fmid){
  8777. var nm,cnt=0,tmp, fld,opt,vl,vlc;
  8778. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  8779. $t.p.savedData = {};
  8780. $t.p.savedData[obj.p.id+"_id"]=rowid;
  8781. }
  8782. var cm = obj.p.colModel;
  8783. if(rowid === '_empty') {
  8784. $(cm).each(function(){
  8785. nm = this.name;
  8786. opt = $.extend({}, this.editoptions || {} );
  8787. fld = $("#"+$.jgrid.jqID(nm),fmid);
  8788. if(fld && fld.length && fld[0] !== null) {
  8789. vl = "";
  8790. if(this.edittype === 'custom' && $.isFunction(opt.custom_value)) {
  8791. opt.custom_value.call($t, $("#"+nm,fmid),'set',vl);
  8792. } else if(opt.defaultValue ) {
  8793. vl = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
  8794. if(fld[0].type==='checkbox') {
  8795. vlc = vl.toLowerCase();
  8796. if(vlc.search(/(false|f|0|no|n|off|undefined)/i)<0 && vlc!=="") {
  8797. fld[0].checked = true;
  8798. fld[0].defaultChecked = true;
  8799. fld[0].value = vl;
  8800. } else {
  8801. fld[0].checked = false;
  8802. fld[0].defaultChecked = false;
  8803. }
  8804. } else {fld.val(vl);}
  8805. } else {
  8806. if( fld[0].type==='checkbox' ) {
  8807. fld[0].checked = false;
  8808. fld[0].defaultChecked = false;
  8809. vl = $(fld).attr("offval");
  8810. } else if (fld[0].type && fld[0].type.substr(0,6)==='select') {
  8811. fld[0].selectedIndex = 0;
  8812. } else {
  8813. fld.val(vl);
  8814. }
  8815. }
  8816. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {
  8817. $t.p.savedData[nm] = vl;
  8818. }
  8819. }
  8820. });
  8821. $("#id_g",fmid).val(rowid);
  8822. return;
  8823. }
  8824. var tre = $(obj).jqGrid("getInd",rowid,true);
  8825. if(!tre) {return;}
  8826. $('td[role="gridcell"]',tre).each( function(i) {
  8827. nm = cm[i].name;
  8828. // hidden fields are included in the form
  8829. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && cm[i].editable===true) {
  8830. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  8831. tmp = $(this).text();
  8832. } else {
  8833. try {
  8834. tmp = $.unformat.call(obj, $(this),{rowId:rowid, colModel:cm[i]},i);
  8835. } catch (_) {
  8836. tmp = cm[i].edittype==="textarea" ? $(this).text() : $(this).html();
  8837. }
  8838. }
  8839. if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
  8840. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {
  8841. $t.p.savedData[nm] = tmp;
  8842. }
  8843. nm = $.jgrid.jqID(nm);
  8844. switch (cm[i].edittype) {
  8845. case "password":
  8846. case "text":
  8847. case "button" :
  8848. case "image":
  8849. case "textarea":
  8850. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  8851. $("#"+nm,fmid).val(tmp);
  8852. break;
  8853. case "select":
  8854. var opv = tmp.split(",");
  8855. opv = $.map(opv,function(n){return $.trim(n);});
  8856. $("#"+nm+" option",fmid).each(function(){
  8857. if (!cm[i].editoptions.multiple && ($.trim(tmp) === $.trim($(this).text()) || opv[0] === $.trim($(this).text()) || opv[0] === $.trim($(this).val())) ){
  8858. this.selected= true;
  8859. } else if (cm[i].editoptions.multiple){
  8860. if( $.inArray($.trim($(this).text()), opv ) > -1 || $.inArray($.trim($(this).val()), opv ) > -1 ){
  8861. this.selected = true;
  8862. }else{
  8863. this.selected = false;
  8864. }
  8865. } else {
  8866. this.selected = false;
  8867. }
  8868. });
  8869. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {
  8870. tmp = $("#"+nm,fmid).val();
  8871. if(cm[i].editoptions.multiple) {
  8872. tmp = tmp.join(",");
  8873. }
  8874. $t.p.savedData[nm] = tmp;
  8875. }
  8876. break;
  8877. case "checkbox":
  8878. tmp = String(tmp);
  8879. if(cm[i].editoptions && cm[i].editoptions.value) {
  8880. var cb = cm[i].editoptions.value.split(":");
  8881. if(cb[0] === tmp) {
  8882. $("#"+nm, fmid)[$t.p.useProp ? 'prop': 'attr']({"checked":true, "defaultChecked" : true});
  8883. } else {
  8884. $("#"+nm, fmid)[$t.p.useProp ? 'prop': 'attr']({"checked":false, "defaultChecked" : false});
  8885. }
  8886. } else {
  8887. tmp = tmp.toLowerCase();
  8888. if(tmp.search(/(false|f|0|no|n|off|undefined)/i)<0 && tmp!=="") {
  8889. $("#"+nm, fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  8890. $("#"+nm, fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie
  8891. } else {
  8892. $("#"+nm, fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  8893. $("#"+nm, fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie
  8894. }
  8895. }
  8896. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {
  8897. if($("#"+nm, fmid).is(":checked")) {
  8898. tmp = $("#"+nm, fmid).val();
  8899. } else {
  8900. tmp = $("#"+nm, fmid).attr("offval");
  8901. }
  8902. $t.p.savedData[nm] = tmp;
  8903. }
  8904. break;
  8905. case 'custom' :
  8906. try {
  8907. if(cm[i].editoptions && $.isFunction(cm[i].editoptions.custom_value)) {
  8908. cm[i].editoptions.custom_value.call($t, $("#"+nm, fmid),'set',tmp);
  8909. } else {throw "e1";}
  8910. } catch (e) {
  8911. if (e==="e1") {$.jgrid.info_dialog(errors.errcap,"function 'custom_value' "+rp_ge[$(this)[0]].p.msg.nodefined,$.rp_ge[$(this)[0]].p.bClose, {styleUI : rp_ge[$(this)[0]].p.styleUI });}
  8912. else {$.jgrid.info_dialog(errors.errcap,e.message,$.rp_ge[$(this)[0]].p.bClose, {styleUI : rp_ge[$(this)[0]].p.styleUI });}
  8913. }
  8914. break;
  8915. }
  8916. cnt++;
  8917. }
  8918. });
  8919. if(cnt>0) {
  8920. $("#id_g",frmtb).val(rowid);
  8921. if( rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate ) {
  8922. $t.p.savedData[obj.p.id+"_id"] = rowid;
  8923. }
  8924. }
  8925. }
  8926. function setNulls() {
  8927. $.each($t.p.colModel, function(i,n){
  8928. if(n.editoptions && n.editoptions.NullIfEmpty === true) {
  8929. if(postdata.hasOwnProperty(n.name) && postdata[n.name] === "") {
  8930. postdata[n.name] = 'null';
  8931. }
  8932. }
  8933. });
  8934. }
  8935. function postIt() {
  8936. var copydata, ret=[true,"",""], onCS = {}, opers = $t.p.prmNames, idname, oper, key, selr, i, url;
  8937. var retvals = $($t).triggerHandler("jqGridAddEditBeforeCheckValues", [postdata, $(frmgr), frmoper]);
  8938. if(retvals && typeof retvals === 'object') {postdata = retvals;}
  8939. if($.isFunction(rp_ge[$t.p.id].beforeCheckValues)) {
  8940. retvals = rp_ge[$t.p.id].beforeCheckValues.call($t, postdata, $(frmgr),frmoper);
  8941. if(retvals && typeof retvals === 'object') {postdata = retvals;}
  8942. }
  8943. for( key in postdata ){
  8944. if(postdata.hasOwnProperty(key)) {
  8945. ret = $.jgrid.checkValues.call($t,postdata[key],key);
  8946. if(ret[0] === false) {break;}
  8947. }
  8948. }
  8949. setNulls();
  8950. if(ret[0]) {
  8951. onCS = $($t).triggerHandler("jqGridAddEditClickSubmit", [rp_ge[$t.p.id], postdata, frmoper]);
  8952. if( onCS === undefined && $.isFunction( rp_ge[$t.p.id].onclickSubmit)) {
  8953. onCS = rp_ge[$t.p.id].onclickSubmit.call($t, rp_ge[$t.p.id], postdata, frmoper) || {};
  8954. }
  8955. ret = $($t).triggerHandler("jqGridAddEditBeforeSubmit", [postdata, $(frmgr), frmoper]);
  8956. if(ret === undefined) {
  8957. ret = [true,"",""];
  8958. }
  8959. if( ret[0] && $.isFunction(rp_ge[$t.p.id].beforeSubmit)) {
  8960. ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata,$(frmgr), frmoper);
  8961. }
  8962. }
  8963. if(ret[0] && !rp_ge[$t.p.id].processing) {
  8964. rp_ge[$t.p.id].processing = true;
  8965. $("#sData", frmtb+"_2").addClass( commonstyle.active );
  8966. url = rp_ge[$t.p.id].url || $($t).jqGrid('getGridParam','editurl');
  8967. oper = opers.oper;
  8968. idname = url === 'clientArray' ? $t.p.keyName : opers.id;
  8969. // we add to pos data array the action - the name is oper
  8970. postdata[oper] = ($.trim(postdata[$t.p.id+"_id"]) === "_empty") ? opers.addoper : opers.editoper;
  8971. if(postdata[oper] !== opers.addoper) {
  8972. postdata[idname] = postdata[$t.p.id+"_id"];
  8973. } else {
  8974. // check to see if we have allredy this field in the form and if yes lieve it
  8975. if( postdata[idname] === undefined ) {postdata[idname] = postdata[$t.p.id+"_id"];}
  8976. }
  8977. delete postdata[$t.p.id+"_id"];
  8978. postdata = $.extend(postdata,rp_ge[$t.p.id].editData,onCS);
  8979. if($t.p.treeGrid === true) {
  8980. if(postdata[oper] === opers.addoper) {
  8981. selr = $($t).jqGrid("getGridParam", 'selrow');
  8982. var tr_par_id = $t.p.treeGridModel === 'adjacency' ? $t.p.treeReader.parent_id_field : 'parent_id';
  8983. postdata[tr_par_id] = selr;
  8984. }
  8985. for(i in $t.p.treeReader){
  8986. if($t.p.treeReader.hasOwnProperty(i)) {
  8987. var itm = $t.p.treeReader[i];
  8988. if(postdata.hasOwnProperty(itm)) {
  8989. if(postdata[oper] === opers.addoper && i === 'parent_id_field') {continue;}
  8990. delete postdata[itm];
  8991. }
  8992. }
  8993. }
  8994. }
  8995. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, postdata[idname]);
  8996. var ajaxOptions = $.extend({
  8997. url: url,
  8998. type: rp_ge[$t.p.id].mtype,
  8999. data: $.isFunction(rp_ge[$t.p.id].serializeEditData) ? rp_ge[$t.p.id].serializeEditData.call($t,postdata) : postdata,
  9000. complete:function(data,status){
  9001. var key;
  9002. $("#sData", frmtb+"_2").removeClass( commonstyle.active );
  9003. postdata[idname] = $t.p.idPrefix + postdata[idname];
  9004. if(data.status >= 300 && data.status !== 304) {
  9005. ret[0] = false;
  9006. ret[1] = $($t).triggerHandler("jqGridAddEditErrorTextFormat", [data, frmoper]);
  9007. if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
  9008. ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t, data, frmoper);
  9009. } else {
  9010. ret[1] = status + " Status: '" + data.statusText + "'. Error code: " + data.status;
  9011. }
  9012. } else {
  9013. // data is posted successful
  9014. // execute aftersubmit with the returned data from server
  9015. ret = $($t).triggerHandler("jqGridAddEditAfterSubmit", [data, postdata, frmoper]);
  9016. if(ret === undefined) {
  9017. ret = [true,"",""];
  9018. }
  9019. if( ret[0] && $.isFunction(rp_ge[$t.p.id].afterSubmit) ) {
  9020. ret = rp_ge[$t.p.id].afterSubmit.call($t, data,postdata, frmoper);
  9021. }
  9022. }
  9023. if(ret[0] === false) {
  9024. $(".FormError",frmgr).html(ret[1]);
  9025. $(".FormError",frmgr).show();
  9026. } else {
  9027. if($t.p.autoencode) {
  9028. $.each(postdata,function(n,v){
  9029. postdata[n] = $.jgrid.htmlDecode(v);
  9030. });
  9031. }
  9032. //rp_ge[$t.p.id].reloadAfterSubmit = rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype != "local";
  9033. // the action is add
  9034. if(postdata[oper] === opers.addoper ) {
  9035. //id processing
  9036. // user not set the id ret[2]
  9037. if(!ret[2]) {ret[2] = $.jgrid.randId();}
  9038. if(postdata[idname] == null || postdata[idname] === "_empty" || postdata[idname] === ""){
  9039. postdata[idname] = ret[2];
  9040. } else {
  9041. ret[2] = postdata[idname];
  9042. }
  9043. if(rp_ge[$t.p.id].reloadAfterSubmit) {
  9044. $($t).trigger("reloadGrid");
  9045. } else {
  9046. if($t.p.treeGrid === true){
  9047. $($t).jqGrid("addChildNode",ret[2],selr,postdata );
  9048. } else {
  9049. $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow);
  9050. }
  9051. }
  9052. if(rp_ge[$t.p.id].closeAfterAdd) {
  9053. if($t.p.treeGrid !== true){
  9054. $($t).jqGrid("setSelection",ret[2]);
  9055. }
  9056. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  9057. } else if (rp_ge[$t.p.id].clearAfterAdd) {
  9058. fillData("_empty", $t, frmgr);
  9059. }
  9060. } else {
  9061. // the action is update
  9062. if(rp_ge[$t.p.id].reloadAfterSubmit) {
  9063. $($t).trigger("reloadGrid");
  9064. if( !rp_ge[$t.p.id].closeAfterEdit ) {setTimeout(function(){$($t).jqGrid("setSelection",postdata[idname]);},1000);}
  9065. } else {
  9066. if($t.p.treeGrid === true) {
  9067. $($t).jqGrid("setTreeRow", postdata[idname],postdata);
  9068. } else {
  9069. $($t).jqGrid("setRowData", postdata[idname],postdata);
  9070. }
  9071. }
  9072. if(rp_ge[$t.p.id].closeAfterEdit) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});}
  9073. }
  9074. if( $.isFunction(rp_ge[$t.p.id].afterComplete) || $._data( $($t)[0], 'events' ).hasOwnProperty('jqGridAddEditAfterComplete') ) {
  9075. copydata = data;
  9076. setTimeout(function(){
  9077. $($t).triggerHandler("jqGridAddEditAfterComplete", [copydata, postdata, $(frmgr), frmoper]);
  9078. try {
  9079. rp_ge[$t.p.id].afterComplete.call($t, copydata, postdata, $(frmgr), frmoper);
  9080. } catch(excacmp) {
  9081. //do nothing
  9082. }
  9083. copydata=null;
  9084. },500);
  9085. }
  9086. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  9087. $(frmgr).data("disabled",false);
  9088. if($t.p.savedData[$t.p.id+"_id"] !== "_empty"){
  9089. for(key in $t.p.savedData) {
  9090. if($t.p.savedData.hasOwnProperty(key) && postdata[key]) {
  9091. $t.p.savedData[key] = postdata[key];
  9092. }
  9093. }
  9094. }
  9095. }
  9096. }
  9097. rp_ge[$t.p.id].processing=false;
  9098. try{$(':input:visible',frmgr)[0].focus();} catch (e){}
  9099. }
  9100. }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxEditOptions );
  9101. if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) {
  9102. if ($.isFunction($t.p.dataProxy)) {
  9103. rp_ge[$t.p.id].useDataProxy = true;
  9104. } else {
  9105. ret[0]=false;ret[1] += " "+errors.nourl;
  9106. }
  9107. }
  9108. if (ret[0]) {
  9109. if (rp_ge[$t.p.id].useDataProxy) {
  9110. var dpret = $t.p.dataProxy.call($t, ajaxOptions, "set_"+$t.p.id);
  9111. if(dpret === undefined) {
  9112. dpret = [true, ""];
  9113. }
  9114. if(dpret[0] === false ) {
  9115. ret[0] = false;
  9116. ret[1] = dpret[1] || "Error deleting the selected row!" ;
  9117. } else {
  9118. if(ajaxOptions.data.oper === opers.addoper && rp_ge[$t.p.id].closeAfterAdd ) {
  9119. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  9120. }
  9121. if(ajaxOptions.data.oper === opers.editoper && rp_ge[$t.p.id].closeAfterEdit ) {
  9122. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  9123. }
  9124. }
  9125. } else {
  9126. if(ajaxOptions.url === "clientArray") {
  9127. rp_ge[$t.p.id].reloadAfterSubmit = false;
  9128. postdata = ajaxOptions.data;
  9129. ajaxOptions.complete({status:200, statusText:''},'');
  9130. } else {
  9131. $.ajax(ajaxOptions);
  9132. }
  9133. }
  9134. }
  9135. }
  9136. if(ret[0] === false) {
  9137. $(".FormError",frmgr).html(ret[1]);
  9138. $(".FormError",frmgr).show();
  9139. // return;
  9140. }
  9141. }
  9142. function compareData(nObj, oObj ) {
  9143. var ret = false,key;
  9144. ret = !( $.isPlainObject(nObj) && $.isPlainObject(oObj) && Object.getOwnPropertyNames(nObj).length === Object.getOwnPropertyNames(oObj).length);
  9145. if(!ret) {
  9146. for (key in oObj) {
  9147. if(oObj.hasOwnProperty(key) ) {
  9148. if(nObj.hasOwnProperty(key) ) {
  9149. if( nObj[key] !== oObj[key] ) {
  9150. ret = true;
  9151. break;
  9152. }
  9153. } else {
  9154. ret = true;
  9155. break;
  9156. }
  9157. }
  9158. }
  9159. }
  9160. return ret;
  9161. }
  9162. function checkUpdates () {
  9163. var stat = true;
  9164. $(".FormError",frmgr).hide();
  9165. if(rp_ge[$t.p.id].checkOnUpdate) {
  9166. postdata = {};
  9167. getFormData();
  9168. diff = compareData(postdata, $t.p.savedData);
  9169. if(diff) {
  9170. $(frmgr).data("disabled",true);
  9171. $(".confirm","#"+IDs.themodal).show();
  9172. stat = false;
  9173. }
  9174. }
  9175. return stat;
  9176. }
  9177. function restoreInline() {
  9178. var i;
  9179. if (rowid !== "_empty" && $t.p.savedRow !== undefined && $t.p.savedRow.length > 0 && $.isFunction($.fn.jqGrid.restoreRow)) {
  9180. for (i=0;i<$t.p.savedRow.length;i++) {
  9181. if ($t.p.savedRow[i].id === rowid) {
  9182. $($t).jqGrid('restoreRow',rowid);
  9183. break;
  9184. }
  9185. }
  9186. }
  9187. }
  9188. function updateNav(cr, posarr){
  9189. var totr = posarr[1].length-1;
  9190. if (cr===0) {
  9191. $("#pData",frmtb2).addClass( commonstyle.disabled );
  9192. } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass( commonstyle.disabled )) {
  9193. $("#pData",frmtb2).addClass( commonstyle.disabled );
  9194. } else {
  9195. $("#pData",frmtb2).removeClass( commonstyle.disabled );
  9196. }
  9197. if (cr===totr) {
  9198. $("#nData",frmtb2).addClass( commonstyle.disabled );
  9199. } else if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass( commonstyle.disabled )) {
  9200. $("#nData",frmtb2).addClass( commonstyle.disabled );
  9201. } else {
  9202. $("#nData",frmtb2).removeClass( commonstyle.disabled );
  9203. }
  9204. }
  9205. function getCurrPos() {
  9206. var rowsInGrid = $($t).jqGrid("getDataIDs"),
  9207. selrow = $("#id_g",frmtb).val(), pos;
  9208. if($t.p.multiselect && rp_ge[$t.p.id].editselected) {
  9209. var arr = [];
  9210. for(var i=0, len = rowsInGrid.length;i<len;i++) {
  9211. if($.inArray(rowsInGrid[i],$t.p.selarrrow) !== -1) {
  9212. arr.push(rowsInGrid[i]);
  9213. }
  9214. }
  9215. pos = $.inArray(selrow,arr);
  9216. return [pos, arr];
  9217. } else {
  9218. pos = $.inArray(selrow,rowsInGrid);
  9219. }
  9220. return [pos,rowsInGrid];
  9221. }
  9222. function parseTemplate ( template ){
  9223. var tmpl ="";
  9224. if(typeof template === "string") {
  9225. tmpl = template.replace(/\{([\w\-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, function(m,i){
  9226. return '<span id="'+ i+ '" ></span>';
  9227. });
  9228. }
  9229. return tmpl;
  9230. }
  9231. function syncSavedData () {
  9232. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  9233. var a1=[], a2={};
  9234. a1 = $.map($t.p.savedData, function(v, i){
  9235. return i;
  9236. });
  9237. $(".FormElement", frm ).each(function(){
  9238. if( a1.indexOf(this.name) === -1 ) {
  9239. var tv = $(this).val(), tt = $(this).get(0).type;
  9240. if( tt === 'checkbox') {
  9241. if(!$(this).is(":checked")) {
  9242. tv = $(this).attr("offval");
  9243. }
  9244. } else if(tt === 'select-multiple') {
  9245. tv = tv.join(",");
  9246. } else if(tt === 'radio') {
  9247. if(a2.hasOwnProperty(this.name)) {
  9248. return true;
  9249. } else {
  9250. a2[this.name] = ($(this).attr("offval") === undefined) ? "off" : $(this).attr("offval");
  9251. }
  9252. }
  9253. $t.p.savedData[this.name] = tv;
  9254. }
  9255. });
  9256. for(var i in a2 ) {
  9257. if( a2.hasOwnProperty(i)) {
  9258. var val = $('input[name="'+i+'"]:checked',frm).val();
  9259. $t.p.savedData[i] = (val !== undefined) ? val : a2[i];
  9260. }
  9261. }
  9262. }
  9263. }
  9264. var dh = isNaN(rp_ge[$(this)[0].p.id].dataheight) ? rp_ge[$(this)[0].p.id].dataheight : rp_ge[$(this)[0].p.id].dataheight+"px",
  9265. dw = isNaN(rp_ge[$(this)[0].p.id].datawidth) ? rp_ge[$(this)[0].p.id].datawidth : rp_ge[$(this)[0].p.id].datawidth+"px",
  9266. frm = $("<form name='FormPost' id='"+frmgr+"' class='FormGrid' onSubmit='return false;' style='width:"+dw+";height:"+dh+";'></form>").data("disabled",false),
  9267. tbl;
  9268. if(templ) {
  9269. tbl = parseTemplate( rp_ge[$(this)[0].p.id].template );
  9270. frmtb2 = frmtb;
  9271. } else {
  9272. tbl = $("<table id='"+frmtborg+"' class='EditTable ui-common-table'><tbody></tbody></table>");
  9273. frmtb2 = frmtb+"_2";
  9274. }
  9275. frmgr = "#"+ $.jgrid.jqID(frmgr);
  9276. // errors
  9277. $(frm).append("<div class='FormError " + commonstyle.error + "' style='display:none;'></div>" );
  9278. // topinfo
  9279. $(frm).append("<div class='tinfo topinfo'>"+rp_ge[$t.p.id].topinfo+"</div>");
  9280. $($t.p.colModel).each( function() {
  9281. var fmto = this.formoptions;
  9282. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
  9283. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
  9284. });
  9285. $(frm).append(tbl);
  9286. showFrm = $($t).triggerHandler("jqGridAddEditBeforeInitData", [frm, frmoper]);
  9287. if(showFrm === undefined) {
  9288. showFrm = true;
  9289. }
  9290. if(showFrm && $.isFunction(rp_ge[$t.p.id].beforeInitData)) {
  9291. showFrm = rp_ge[$t.p.id].beforeInitData.call($t,frm, frmoper);
  9292. }
  9293. if(showFrm === false) {return;}
  9294. restoreInline();
  9295. // set the id.
  9296. // use carefull only to change here colproperties.
  9297. // create data
  9298. createData(rowid,$t,tbl,maxCols);
  9299. // buttons at footer
  9300. var rtlb = $t.p.direction === "rtl" ? true :false,
  9301. bp = rtlb ? "nData" : "pData",
  9302. bn = rtlb ? "pData" : "nData";
  9303. var bP = "<a id='"+bp+"' class='fm-button " + commonstyle.button + "'><span class='" + commonstyle.icon_base + " " + styles.icon_prev+ "'></span></a>",
  9304. bN = "<a id='"+bn+"' class='fm-button " + commonstyle.button + "'><span class='" + commonstyle.icon_base + " " + styles.icon_next+ "'></span></a>",
  9305. bS ="<a id='sData' class='fm-button " + commonstyle.button + "'>"+p.bSubmit+"</a>",
  9306. bC ="<a id='cData' class='fm-button " + commonstyle.button + "'>"+p.bCancel+"</a>";
  9307. var bt = "<table style='height:auto' class='EditTable ui-common-table' id='"+frmtborg+"_2'><tbody><tr><td colspan='2'><hr class='"+commonstyle.content+"' style='margin:1px'/></td></tr><tr id='Act_Buttons'><td class='navButton'>"+(rtlb ? bN+bP : bP+bN)+"</td><td class='EditButton'>"+bS+bC+"</td></tr>";
  9308. //bt += "<tr style='display:none' class='binfo'><td class='bottominfo' colspan='2'>"+rp_ge[$t.p.id].bottominfo+"</td></tr>";
  9309. bt += "</tbody></table>";
  9310. if(maxRows > 0) {
  9311. var sd=[];
  9312. $.each($(tbl)[0].rows,function(i,r){
  9313. sd[i] = r;
  9314. });
  9315. sd.sort(function(a,b){
  9316. if(a.rp > b.rp) {return 1;}
  9317. if(a.rp < b.rp) {return -1;}
  9318. return 0;
  9319. });
  9320. $.each(sd, function(index, row) {
  9321. $('tbody',tbl).append(row);
  9322. });
  9323. }
  9324. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  9325. var cle = false;
  9326. if(p.closeOnEscape===true){
  9327. p.closeOnEscape = false;
  9328. cle = true;
  9329. }
  9330. var tms;
  9331. if(templ) {
  9332. $(frm).find("#pData").replaceWith( bP );
  9333. $(frm).find("#nData").replaceWith( bN );
  9334. $(frm).find("#sData").replaceWith( bS );
  9335. $(frm).find("#cData").replaceWith( bC );
  9336. tms = $("<div id="+frmtborg+"></div>").append(frm);
  9337. } else {
  9338. tms = $("<div></div>").append(frm).append(bt);
  9339. }
  9340. $(frm).append("<div class='binfo topinfo bottominfo'>"+rp_ge[$t.p.id].bottominfo+"</div>");
  9341. $.jgrid.createModal(IDs,tms, rp_ge[$(this)[0].p.id] ,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]);
  9342. if(rtlb) {
  9343. $("#pData, #nData",frmtb+"_2").css("float","right");
  9344. $(".EditButton",frmtb+"_2").css("text-align","left");
  9345. }
  9346. if(rp_ge[$t.p.id].topinfo) {$(".tinfo", frmgr).show();}
  9347. if(rp_ge[$t.p.id].bottominfo) {$(".binfo",frmgr).show();}
  9348. tms = null;bt=null;
  9349. $("#"+$.jgrid.jqID(IDs.themodal)).keydown( function( e ) {
  9350. var wkey = e.target;
  9351. if ($(frmgr).data("disabled")===true ) {return false;}//??
  9352. if(rp_ge[$t.p.id].savekey[0] === true && e.which === rp_ge[$t.p.id].savekey[1]) { // save
  9353. if(wkey.tagName !== "TEXTAREA") {
  9354. $("#sData", frmtb+"_2").trigger("click");
  9355. return false;
  9356. }
  9357. }
  9358. if(e.which === 27) {
  9359. if(!checkUpdates()) {return false;}
  9360. if(cle) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:p.gbox,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});}
  9361. return false;
  9362. }
  9363. if(rp_ge[$t.p.id].navkeys[0]===true) {
  9364. if($("#id_g",frmtb).val() === "_empty") {return true;}
  9365. if(e.which === rp_ge[$t.p.id].navkeys[1]){ //up
  9366. $("#pData", frmtb2).trigger("click");
  9367. return false;
  9368. }
  9369. if(e.which === rp_ge[$t.p.id].navkeys[2]){ //down
  9370. $("#nData", frmtb2).trigger("click");
  9371. return false;
  9372. }
  9373. }
  9374. });
  9375. if(p.checkOnUpdate) {
  9376. $("a.ui-jqdialog-titlebar-close span","#"+$.jgrid.jqID(IDs.themodal)).removeClass("jqmClose");
  9377. $("a.ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.themodal)).off("click")
  9378. .click(function(){
  9379. if(!checkUpdates()) {return false;}
  9380. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  9381. return false;
  9382. });
  9383. }
  9384. p.saveicon = $.extend([true,"left", styles.icon_save ],p.saveicon);
  9385. p.closeicon = $.extend([true,"left", styles.icon_close ],p.closeicon);
  9386. // beforeinitdata after creation of the form
  9387. if(p.saveicon[0]===true) {
  9388. $("#sData",frmtb2).addClass(p.saveicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  9389. .append("<span class='"+commonstyle.icon_base + " " +p.saveicon[2]+"'></span>");
  9390. }
  9391. if(p.closeicon[0]===true) {
  9392. $("#cData",frmtb2).addClass(p.closeicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  9393. .append("<span class='" + commonstyle.icon_base +" "+p.closeicon[2]+"'></span>");
  9394. }
  9395. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  9396. bS ="<a id='sNew' class='fm-button "+commonstyle.button + "' style='z-index:1002'>"+p.bYes+"</a>";
  9397. bN ="<a id='nNew' class='fm-button "+commonstyle.button + "' style='z-index:1002;margin-left:5px'>"+p.bNo+"</a>";
  9398. bC ="<a id='cNew' class='fm-button "+commonstyle.button + "' style='z-index:1002;margin-left:5px;'>"+p.bExit+"</a>";
  9399. var zI = p.zIndex || 999;zI ++;
  9400. $("<div class='"+ p.overlayClass+" jqgrid-overlay confirm' style='z-index:"+zI+";display:none;'>&#160;"+"</div><div class='confirm ui-jqconfirm "+commonstyle.content+"' style='z-index:"+(zI+1)+"'>"+p.saveData+"<br/><br/>"+bS+bN+bC+"</div>").insertAfter(frmgr);
  9401. $("#sNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  9402. postIt();
  9403. $(frmgr).data("disabled",false);
  9404. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  9405. return false;
  9406. });
  9407. $("#nNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  9408. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  9409. $(frmgr).data("disabled",false);
  9410. setTimeout(function(){$(":input:visible",frmgr)[0].focus();},0);
  9411. return false;
  9412. });
  9413. $("#cNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  9414. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  9415. $(frmgr).data("disabled",false);
  9416. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  9417. return false;
  9418. });
  9419. }
  9420. // here initform
  9421. $($t).triggerHandler("jqGridAddEditInitializeForm", [$(frmgr), frmoper]);
  9422. if($.isFunction(rp_ge[$t.p.id].onInitializeForm)) { rp_ge[$t.p.id].onInitializeForm.call($t,$(frmgr), frmoper);}
  9423. if(rowid==="_empty" || !rp_ge[$t.p.id].viewPagerButtons) {$("#pData,#nData",frmtb2).hide();} else {$("#pData,#nData",frmtb2).show();}
  9424. $($t).triggerHandler("jqGridAddEditBeforeShowForm", [$(frmgr), frmoper]);
  9425. if($.isFunction(rp_ge[$t.p.id].beforeShowForm)) { rp_ge[$t.p.id].beforeShowForm.call($t, $(frmgr), frmoper);}
  9426. syncSavedData();
  9427. $("#"+$.jgrid.jqID(IDs.themodal)).data("onClose",rp_ge[$t.p.id].onClose);
  9428. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{
  9429. gbox:"#gbox_"+$.jgrid.jqID(gID),
  9430. jqm:p.jqModal,
  9431. overlay: p.overlay,
  9432. modal:p.modal,
  9433. overlayClass: p.overlayClass,
  9434. focusField : p.focusField,
  9435. onHide : function(h) {
  9436. var fh = $('#editmod'+gID)[0].style.height,
  9437. fw = $('#editmod'+gID)[0].style.width;
  9438. if(fh.indexOf("px") > -1 ) {
  9439. fh = parseFloat(fh);
  9440. }
  9441. if(fw.indexOf("px") > -1 ) {
  9442. fw = parseFloat(fw);
  9443. }
  9444. $($t).data("formProp", {
  9445. top:parseFloat($(h.w).css("top")),
  9446. left : parseFloat($(h.w).css("left")),
  9447. width : fw,
  9448. height : fh,
  9449. dataheight : $(frmgr).height(),
  9450. datawidth: $(frmgr).width()
  9451. });
  9452. h.w.remove();
  9453. if(h.o) {h.o.remove();}
  9454. }
  9455. });
  9456. if(!closeovrl) {
  9457. $("." + $.jgrid.jqID(p.overlayClass)).click(function(){
  9458. if(!checkUpdates()) {return false;}
  9459. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  9460. return false;
  9461. });
  9462. }
  9463. $(".fm-button","#"+$.jgrid.jqID(IDs.themodal)).hover(
  9464. function(){$(this).addClass( commonstyle.hover );},
  9465. function(){$(this).removeClass( commonstyle.hover );}
  9466. );
  9467. $("#sData", frmtb2).click(function(){
  9468. postdata = {};
  9469. $(".FormError",frmgr).hide();
  9470. // all depend on ret array
  9471. //ret[0] - succes
  9472. //ret[1] - msg if not succes
  9473. //ret[2] - the id that will be set if reload after submit false
  9474. getFormData();
  9475. if(postdata[$t.p.id+"_id"] === "_empty") {postIt();}
  9476. else if(p.checkOnSubmit===true ) {
  9477. diff = compareData(postdata, $t.p.savedData);
  9478. if(diff) {
  9479. $(frmgr).data("disabled",true);
  9480. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).show();
  9481. } else {
  9482. postIt();
  9483. }
  9484. } else {
  9485. postIt();
  9486. }
  9487. return false;
  9488. });
  9489. $("#cData", frmtb2).click(function(){
  9490. if(!checkUpdates()) {return false;}
  9491. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  9492. return false;
  9493. });
  9494. $("#nData", frmtb2).click(function(){
  9495. if(!checkUpdates()) {return false;}
  9496. $(".FormError",frmgr).hide();
  9497. var npos = getCurrPos();
  9498. npos[0] = parseInt(npos[0],10);
  9499. if(npos[0] !== -1 && npos[1][npos[0]+1]) {
  9500. $($t).triggerHandler("jqGridAddEditClickPgButtons", ['next',$(frmgr),npos[1][npos[0]]]);
  9501. var nposret;
  9502. if($.isFunction(p.onclickPgButtons)) {
  9503. nposret = p.onclickPgButtons.call($t, 'next',$(frmgr),npos[1][npos[0]]);
  9504. if( nposret !== undefined && nposret === false ) {return false;}
  9505. }
  9506. if( $("#"+$.jgrid.jqID(npos[1][npos[0]+1])).hasClass( commonstyle.disabled )) {return false;}
  9507. fillData(npos[1][npos[0]+1],$t,frmgr);
  9508. if(!($t.p.multiselect && rp_ge[$t.p.id].editselected)) {
  9509. $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
  9510. }
  9511. $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['next',$(frmgr),npos[1][npos[0]]]);
  9512. if($.isFunction(p.afterclickPgButtons)) {
  9513. p.afterclickPgButtons.call($t, 'next',$(frmgr),npos[1][npos[0]+1]);
  9514. }
  9515. syncSavedData();
  9516. updateNav(npos[0]+1,npos);
  9517. }
  9518. return false;
  9519. });
  9520. $("#pData", frmtb2).click(function(){
  9521. if(!checkUpdates()) {return false;}
  9522. $(".FormError",frmgr).hide();
  9523. var ppos = getCurrPos();
  9524. if(ppos[0] !== -1 && ppos[1][ppos[0]-1]) {
  9525. $($t).triggerHandler("jqGridAddEditClickPgButtons", ['prev',$(frmgr),ppos[1][ppos[0]]]);
  9526. var pposret;
  9527. if($.isFunction(p.onclickPgButtons)) {
  9528. pposret = p.onclickPgButtons.call($t, 'prev',$(frmgr),ppos[1][ppos[0]]);
  9529. if( pposret !== undefined && pposret === false ) {return false;}
  9530. }
  9531. if( $("#"+$.jgrid.jqID(ppos[1][ppos[0]-1])).hasClass( commonstyle.disabled )) {return false;}
  9532. fillData(ppos[1][ppos[0]-1],$t,frmgr);
  9533. if(!($t.p.multiselect && rp_ge[$t.p.id].editselected)) {
  9534. $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
  9535. }
  9536. $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['prev',$(frmgr),ppos[1][ppos[0]]]);
  9537. if($.isFunction(p.afterclickPgButtons)) {
  9538. p.afterclickPgButtons.call($t, 'prev',$(frmgr),ppos[1][ppos[0]-1]);
  9539. }
  9540. syncSavedData();
  9541. updateNav(ppos[0]-1,ppos);
  9542. }
  9543. return false;
  9544. });
  9545. $($t).triggerHandler("jqGridAddEditAfterShowForm", [$(frmgr), frmoper]);
  9546. if($.isFunction(rp_ge[$t.p.id].afterShowForm)) { rp_ge[$t.p.id].afterShowForm.call($t, $(frmgr), frmoper); }
  9547. var posInit =getCurrPos();
  9548. updateNav(posInit[0],posInit);
  9549. });
  9550. },
  9551. viewGridRow : function(rowid, p){
  9552. var regional = $.jgrid.getRegional(this[0], 'view'),
  9553. currstyle = this[0].p.styleUI,
  9554. styles = $.jgrid.styleUI[currstyle].formedit,
  9555. commonstyle = $.jgrid.styleUI[currstyle].common;
  9556. p = $.extend(true, {
  9557. top : 0,
  9558. left: 0,
  9559. width: 500,
  9560. datawidth: 'auto',
  9561. height: 'auto',
  9562. dataheight: 'auto',
  9563. modal: false,
  9564. overlay: 30,
  9565. drag: true,
  9566. resize: true,
  9567. jqModal: true,
  9568. closeOnEscape : false,
  9569. labelswidth: '30%',
  9570. closeicon: [],
  9571. navkeys: [false,38,40],
  9572. onClose: null,
  9573. beforeShowForm : null,
  9574. beforeInitData : null,
  9575. viewPagerButtons : true,
  9576. recreateForm : false,
  9577. removemodal: true,
  9578. form: 'view'
  9579. }, regional, p || {});
  9580. rp_ge[$(this)[0].p.id] = p;
  9581. return this.each(function(){
  9582. var $t = this;
  9583. if (!$t.grid || !rowid) {return;}
  9584. var gID = $t.p.id,
  9585. frmgr = "ViewGrid_"+$.jgrid.jqID( gID ), frmtb = "ViewTbl_" + $.jgrid.jqID( gID ),
  9586. frmgr_id = "ViewGrid_"+gID, frmtb_id = "ViewTbl_"+gID,
  9587. IDs = {themodal:'viewmod'+gID,modalhead:'viewhd'+gID,modalcontent:'viewcnt'+gID, scrollelm : frmgr},
  9588. showFrm = true,
  9589. maxCols = 1, maxRows=0;
  9590. rp_ge[$t.p.id].styleUI = $t.p.styleUI || 'jQueryUI';
  9591. if(!p.recreateForm) {
  9592. if( $($t).data("viewProp") ) {
  9593. $.extend(rp_ge[$(this)[0].p.id], $($t).data("viewProp"));
  9594. }
  9595. }
  9596. function focusaref(){ //Sfari 3 issues
  9597. if(rp_ge[$t.p.id].closeOnEscape===true || rp_ge[$t.p.id].navkeys[0]===true) {
  9598. setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).attr("tabindex", "-1").focus();},0);
  9599. }
  9600. }
  9601. function createData(rowid,obj,tb,maxcols){
  9602. var nm, hc,trdata, cnt=0,tmp, dc, retpos=[], ind=false, i,
  9603. tdtmpl = "<td class='CaptionTD form-view-label " + commonstyle.content + "' width='"+p.labelswidth+"'>&#160;</td><td class='DataTD form-view-data ui-helper-reset " + commonstyle.content +"'>&#160;</td>", tmpl="",
  9604. tdtmpl2 = "<td class='CaptionTD form-view-label " + commonstyle.content +"'>&#160;</td><td class='DataTD form-view-data " + commonstyle.content +"'>&#160;</td>",
  9605. fmtnum = ['integer','number','currency'],max1 =0, max2=0 ,maxw,setme, viewfld;
  9606. for (i=1;i<=maxcols;i++) {
  9607. tmpl += i === 1 ? tdtmpl : tdtmpl2;
  9608. }
  9609. // find max number align rigth with property formatter
  9610. $(obj.p.colModel).each( function() {
  9611. if(this.editrules && this.editrules.edithidden === true) {
  9612. hc = false;
  9613. } else {
  9614. hc = this.hidden === true ? true : false;
  9615. }
  9616. if(!hc && this.align==='right') {
  9617. if(this.formatter && $.inArray(this.formatter,fmtnum) !== -1 ) {
  9618. max1 = Math.max(max1,parseInt(this.width,10));
  9619. } else {
  9620. max2 = Math.max(max2,parseInt(this.width,10));
  9621. }
  9622. }
  9623. });
  9624. maxw = max1 !==0 ? max1 : max2 !==0 ? max2 : 0;
  9625. ind = $(obj).jqGrid("getInd",rowid);
  9626. $(obj.p.colModel).each( function(i) {
  9627. nm = this.name;
  9628. setme = false;
  9629. // hidden fields are included in the form
  9630. if(this.editrules && this.editrules.edithidden === true) {
  9631. hc = false;
  9632. } else {
  9633. hc = this.hidden === true ? true : false;
  9634. }
  9635. dc = hc ? "style='display:none'" : "";
  9636. viewfld = (typeof this.viewable !== 'boolean') ? true : this.viewable;
  9637. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && viewfld) {
  9638. if(ind === false) {
  9639. tmp = "";
  9640. } else {
  9641. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  9642. tmp = $("td:eq("+i+")",obj.rows[ind]).text();
  9643. } else {
  9644. tmp = $("td:eq("+i+")",obj.rows[ind]).html();
  9645. }
  9646. }
  9647. setme = this.align === 'right' && maxw !==0 ? true : false;
  9648. var frmopt = $.extend({},{rowabove:false,rowcontent:''}, this.formoptions || {}),
  9649. rp = parseInt(frmopt.rowpos,10) || cnt+1,
  9650. cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
  9651. if(frmopt.rowabove) {
  9652. var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
  9653. $(tb).append(newdata);
  9654. newdata[0].rp = rp;
  9655. }
  9656. trdata = $(tb).find("tr[rowpos="+rp+"]");
  9657. if ( trdata.length===0 ) {
  9658. trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","trv_"+nm);
  9659. $(trdata).append(tmpl);
  9660. $(tb).append(trdata);
  9661. trdata[0].rp = rp;
  9662. }
  9663. $("td:eq("+(cp-2)+")",trdata[0]).html('<b>'+ (frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label)+'</b>');
  9664. $("td:eq("+(cp-1)+")",trdata[0]).append("<span>"+tmp+"</span>").attr("id","v_"+nm);
  9665. if(setme){
  9666. $("td:eq("+(cp-1)+") span",trdata[0]).css({'text-align':'right',width:maxw+"px"});
  9667. }
  9668. retpos[cnt] = i;
  9669. cnt++;
  9670. }
  9671. });
  9672. if( cnt > 0) {
  9673. var idrow = $("<tr class='FormData' style='display:none'><td class='CaptionTD'></td><td colspan='"+ (maxcols*2-1)+"' class='DataTD'><input class='FormElement' id='id_g' type='text' name='id' value='"+rowid+"'/></td></tr>");
  9674. idrow[0].rp = cnt+99;
  9675. $(tb).append(idrow);
  9676. }
  9677. return retpos;
  9678. }
  9679. function fillData(rowid,obj){
  9680. var nm, hc,cnt=0,tmp,trv;
  9681. trv = $(obj).jqGrid("getInd",rowid,true);
  9682. if(!trv) {return;}
  9683. $('td',trv).each( function(i) {
  9684. nm = obj.p.colModel[i].name;
  9685. // hidden fields are included in the form
  9686. if(obj.p.colModel[i].editrules && obj.p.colModel[i].editrules.edithidden === true) {
  9687. hc = false;
  9688. } else {
  9689. hc = obj.p.colModel[i].hidden === true ? true : false;
  9690. }
  9691. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  9692. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  9693. tmp = $(this).text();
  9694. } else {
  9695. tmp = $(this).html();
  9696. }
  9697. nm = $.jgrid.jqID("v_"+nm);
  9698. $("#"+nm+" span","#"+frmtb).html(tmp);
  9699. if (hc) {$("#"+nm,"#"+frmtb).parents("tr:first").hide();}
  9700. cnt++;
  9701. }
  9702. });
  9703. if(cnt>0) {$("#id_g","#"+frmtb).val(rowid);}
  9704. }
  9705. function updateNav(cr,posarr){
  9706. var totr = posarr[1].length-1;
  9707. if (cr===0) {
  9708. $("#pData","#"+frmtb+"_2").addClass( commonstyle.disabled );
  9709. } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass(commonstyle.disabled)) {
  9710. $("#pData",frmtb+"_2").addClass( commonstyle.disabled );
  9711. } else {
  9712. $("#pData","#"+frmtb+"_2").removeClass( commonstyle.disabled );
  9713. }
  9714. if (cr===totr) {
  9715. $("#nData","#"+frmtb+"_2").addClass( commonstyle.disabled );
  9716. } else if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass( commonstyle.disabled )) {
  9717. $("#nData",frmtb+"_2").addClass( commonstyle.disabled );
  9718. } else {
  9719. $("#nData","#"+frmtb+"_2").removeClass( commonstyle.disabled );
  9720. }
  9721. }
  9722. function getCurrPos() {
  9723. var rowsInGrid = $($t).jqGrid("getDataIDs"),
  9724. selrow = $("#id_g","#"+frmtb).val(),
  9725. pos = $.inArray(selrow,rowsInGrid);
  9726. return [pos,rowsInGrid];
  9727. }
  9728. var dh = isNaN(rp_ge[$(this)[0].p.id].dataheight) ? rp_ge[$(this)[0].p.id].dataheight : rp_ge[$(this)[0].p.id].dataheight+"px",
  9729. dw = isNaN(rp_ge[$(this)[0].p.id].datawidth) ? rp_ge[$(this)[0].p.id].datawidth : rp_ge[$(this)[0].p.id].datawidth+"px",
  9730. frm = $("<form name='FormPost' id='"+frmgr_id+"' class='FormGrid' style='width:"+dw+";height:"+dh+";'></form>"),
  9731. tbl =$("<table id='"+frmtb_id+"' class='EditTable ViewTable'><tbody></tbody></table>");
  9732. $($t.p.colModel).each( function() {
  9733. var fmto = this.formoptions;
  9734. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
  9735. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
  9736. });
  9737. // set the id.
  9738. $(frm).append(tbl);
  9739. showFrm = $($t).triggerHandler("jqGridViewRowBeforeInitData", [frm]);
  9740. if(showFrm === undefined) {
  9741. showFrm = true;
  9742. }
  9743. if(showFrm && $.isFunction(rp_ge[$t.p.id].beforeInitData)) {
  9744. showFrm = rp_ge[$t.p.id].beforeInitData.call($t, frm);
  9745. }
  9746. if(showFrm === false) {return;}
  9747. createData(rowid, $t, tbl, maxCols);
  9748. var rtlb = $t.p.direction === "rtl" ? true :false,
  9749. bp = rtlb ? "nData" : "pData",
  9750. bn = rtlb ? "pData" : "nData",
  9751. // buttons at footer
  9752. bP = "<a id='"+bp+"' class='fm-button " + commonstyle.button + "'><span class='" + commonstyle.icon_base + " " + styles.icon_prev+ "'></span></a>",
  9753. bN = "<a id='"+bn+"' class='fm-button " + commonstyle.button + "'><span class='" + commonstyle.icon_base + " " + styles.icon_next+ "'></span></a>",
  9754. bC ="<a id='cData' class='fm-button " + commonstyle.button + "'>"+p.bClose+"</a>";
  9755. if(maxRows > 0) {
  9756. var sd=[];
  9757. $.each($(tbl)[0].rows,function(i,r){
  9758. sd[i] = r;
  9759. });
  9760. sd.sort(function(a,b){
  9761. if(a.rp > b.rp) {return 1;}
  9762. if(a.rp < b.rp) {return -1;}
  9763. return 0;
  9764. });
  9765. $.each(sd, function(index, row) {
  9766. $('tbody',tbl).append(row);
  9767. });
  9768. }
  9769. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  9770. var bt = $("<div></div>").append(frm).append("<table border='0' class='EditTable' id='"+frmtb+"_2'><tbody><tr id='Act_Buttons'><td class='navButton' width='"+p.labelswidth+"'>"+(rtlb ? bN+bP : bP+bN)+"</td><td class='EditButton'>"+bC+"</td></tr></tbody></table>");
  9771. $.jgrid.createModal(IDs,bt, rp_ge[$(this)[0].p.id],"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]);
  9772. if(rtlb) {
  9773. $("#pData, #nData","#"+frmtb+"_2").css("float","right");
  9774. $(".EditButton","#"+frmtb+"_2").css("text-align","left");
  9775. }
  9776. if(!p.viewPagerButtons) {$("#pData, #nData","#"+frmtb+"_2").hide();}
  9777. bt = null;
  9778. $("#"+IDs.themodal).keydown( function( e ) {
  9779. if(e.which === 27) {
  9780. if(rp_ge[$t.p.id].closeOnEscape) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:p.gbox,jqm:p.jqModal, onClose: p.onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});}
  9781. return false;
  9782. }
  9783. if(p.navkeys[0]===true) {
  9784. if(e.which === p.navkeys[1]){ //up
  9785. $("#pData", "#"+frmtb+"_2").trigger("click");
  9786. return false;
  9787. }
  9788. if(e.which === p.navkeys[2]){ //down
  9789. $("#nData", "#"+frmtb+"_2").trigger("click");
  9790. return false;
  9791. }
  9792. }
  9793. });
  9794. p.closeicon = $.extend([true,"left", styles.icon_close ],p.closeicon);
  9795. if(p.closeicon[0]===true) {
  9796. $("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  9797. .append("<span class='" + commonstyle.icon_base+ " " +p.closeicon[2]+"'></span>");
  9798. }
  9799. $($t).triggerHandler("jqGridViewRowBeforeShowForm", [$("#"+frmgr)]);
  9800. if($.isFunction(p.beforeShowForm)) {p.beforeShowForm.call($t,$("#"+frmgr));}
  9801. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{
  9802. gbox:"#gbox_"+$.jgrid.jqID(gID),
  9803. jqm:p.jqModal,
  9804. overlay: p.overlay,
  9805. modal:p.modal,
  9806. onHide : function(h) {
  9807. $($t).data("viewProp", {
  9808. top:parseFloat($(h.w).css("top")),
  9809. left : parseFloat($(h.w).css("left")),
  9810. width : $(h.w).width(),
  9811. height : $(h.w).height(),
  9812. dataheight : $("#"+frmgr).height(),
  9813. datawidth: $("#"+frmgr).width()
  9814. });
  9815. h.w.remove();
  9816. if(h.o) {h.o.remove();}
  9817. }
  9818. });
  9819. $(".fm-button:not(." + commonstyle.disabled + ")","#"+frmtb+"_2").hover(
  9820. function(){$(this).addClass( commonstyle.hover );},
  9821. function(){$(this).removeClass( commonstyle.hover );}
  9822. );
  9823. focusaref();
  9824. $("#cData", "#"+frmtb+"_2").click(function(){
  9825. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: p.onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  9826. return false;
  9827. });
  9828. $("#nData", "#"+frmtb+"_2").click(function(){
  9829. $("#FormError","#"+frmtb).hide();
  9830. var npos = getCurrPos();
  9831. npos[0] = parseInt(npos[0],10);
  9832. if(npos[0] !== -1 && npos[1][npos[0]+1]) {
  9833. $($t).triggerHandler("jqGridViewRowClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]);
  9834. if($.isFunction(p.onclickPgButtons)) {
  9835. p.onclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]]);
  9836. }
  9837. fillData(npos[1][npos[0]+1],$t);
  9838. $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
  9839. $($t).triggerHandler("jqGridViewRowAfterClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]+1]]);
  9840. if($.isFunction(p.afterclickPgButtons)) {
  9841. p.afterclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]+1]);
  9842. }
  9843. updateNav(npos[0]+1,npos);
  9844. }
  9845. focusaref();
  9846. return false;
  9847. });
  9848. $("#pData", "#"+frmtb+"_2").click(function(){
  9849. $("#FormError","#"+frmtb).hide();
  9850. var ppos = getCurrPos();
  9851. if(ppos[0] !== -1 && ppos[1][ppos[0]-1]) {
  9852. $($t).triggerHandler("jqGridViewRowClickPgButtons", ['prev',$("#"+frmgr),npos[1][npos[0]]]);
  9853. if($.isFunction(p.onclickPgButtons)) {
  9854. p.onclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]]);
  9855. }
  9856. fillData(ppos[1][ppos[0]-1],$t);
  9857. $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
  9858. $($t).triggerHandler("jqGridViewRowAfterClickPgButtons", ['prev',$("#"+frmgr),npos[1][npos[0]-1]]);
  9859. if($.isFunction(p.afterclickPgButtons)) {
  9860. p.afterclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
  9861. }
  9862. updateNav(ppos[0]-1,ppos);
  9863. }
  9864. focusaref();
  9865. return false;
  9866. });
  9867. var posInit =getCurrPos();
  9868. updateNav(posInit[0],posInit);
  9869. });
  9870. },
  9871. delGridRow : function(rowids,p) {
  9872. var regional = $.jgrid.getRegional(this[0], 'del'),
  9873. currstyle = this[0].p.styleUI,
  9874. styles = $.jgrid.styleUI[currstyle].formedit,
  9875. commonstyle = $.jgrid.styleUI[currstyle].common;
  9876. p = $.extend(true, {
  9877. top : 0,
  9878. left: 0,
  9879. width: 240,
  9880. height: 'auto',
  9881. dataheight : 'auto',
  9882. modal: false,
  9883. overlay: 30,
  9884. drag: true,
  9885. resize: true,
  9886. url : '',
  9887. mtype : "POST",
  9888. reloadAfterSubmit: true,
  9889. beforeShowForm: null,
  9890. beforeInitData : null,
  9891. afterShowForm: null,
  9892. beforeSubmit: null,
  9893. onclickSubmit: null,
  9894. afterSubmit: null,
  9895. jqModal : true,
  9896. closeOnEscape : false,
  9897. delData: {},
  9898. delicon : [],
  9899. cancelicon : [],
  9900. onClose : null,
  9901. ajaxDelOptions : {},
  9902. processing : false,
  9903. serializeDelData : null,
  9904. useDataProxy : false
  9905. }, regional, p ||{});
  9906. rp_ge[$(this)[0].p.id] = p;
  9907. return this.each(function(){
  9908. var $t = this;
  9909. if (!$t.grid ) {return;}
  9910. if(!rowids) {return;}
  9911. var gID = $t.p.id, onCS = {},
  9912. showFrm = true,
  9913. dtbl = "DelTbl_"+$.jgrid.jqID(gID),postd, idname, opers, oper,
  9914. dtbl_id = "DelTbl_" + gID,
  9915. IDs = {themodal:'delmod'+gID,modalhead:'delhd'+gID,modalcontent:'delcnt'+gID, scrollelm: dtbl};
  9916. rp_ge[$t.p.id].styleUI = $t.p.styleUI || 'jQueryUI';
  9917. if ($.isArray(rowids)) {rowids = rowids.join();}
  9918. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  9919. showFrm = $($t).triggerHandler("jqGridDelRowBeforeInitData", [$("#"+dtbl)]);
  9920. if(showFrm === undefined) {
  9921. showFrm = true;
  9922. }
  9923. if(showFrm && $.isFunction(rp_ge[$t.p.id].beforeInitData)) {
  9924. showFrm = rp_ge[$t.p.id].beforeInitData.call($t, $("#"+dtbl));
  9925. }
  9926. if(showFrm === false) {return;}
  9927. $("#DelData>td","#"+dtbl).text(rowids);
  9928. $("#DelError","#"+dtbl).hide();
  9929. if( rp_ge[$t.p.id].processing === true) {
  9930. rp_ge[$t.p.id].processing=false;
  9931. $("#dData", "#"+dtbl).removeClass( commonstyle.active );
  9932. }
  9933. $($t).triggerHandler("jqGridDelRowBeforeShowForm", [$("#"+dtbl)]);
  9934. if($.isFunction( rp_ge[$t.p.id].beforeShowForm )) {
  9935. rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));
  9936. }
  9937. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:rp_ge[$t.p.id].jqModal, overlay: rp_ge[$t.p.id].overlay, modal:rp_ge[$t.p.id].modal});
  9938. $($t).triggerHandler("jqGridDelRowAfterShowForm", [$("#"+dtbl)]);
  9939. if($.isFunction( rp_ge[$t.p.id].afterShowForm )) {
  9940. rp_ge[$t.p.id].afterShowForm.call($t, $("#"+dtbl));
  9941. }
  9942. } else {
  9943. var dh = isNaN(rp_ge[$t.p.id].dataheight) ? rp_ge[$t.p.id].dataheight : rp_ge[$t.p.id].dataheight+"px",
  9944. dw = isNaN(p.datawidth) ? p.datawidth : p.datawidth+"px",
  9945. tbl = "<div id='"+dtbl_id+"' class='formdata' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'>";
  9946. tbl += "<table class='DelTable'><tbody>";
  9947. // error data
  9948. tbl += "<tr id='DelError' style='display:none'><td class='" + commonstyle.error +"'></td></tr>";
  9949. tbl += "<tr id='DelData' style='display:none'><td >"+rowids+"</td></tr>";
  9950. tbl += "<tr><td class=\"delmsg\" style=\"white-space:pre;\">"+rp_ge[$t.p.id].msg+"</td></tr><tr><td >&#160;</td></tr>";
  9951. // buttons at footer
  9952. tbl += "</tbody></table></div>";
  9953. var bS = "<a id='dData' class='fm-button " + commonstyle.button + "'>"+p.bSubmit+"</a>",
  9954. bC = "<a id='eData' class='fm-button " + commonstyle.button + "'>"+p.bCancel+"</a>";
  9955. tbl += "<table class='EditTable ui-common-table' id='"+dtbl+"_2'><tbody><tr><td><hr class='" + commonstyle.content + "' style='margin:1px'/></td></tr><tr><td class='DelButton EditButton'>"+bS+"&#160;"+bC+"</td></tr></tbody></table>";
  9956. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  9957. $.jgrid.createModal(IDs,tbl, rp_ge[$t.p.id] ,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]);
  9958. $(".fm-button","#"+dtbl+"_2").hover(
  9959. function(){$(this).addClass( commonstyle.hover );},
  9960. function(){$(this).removeClass( commonstyle.hover );}
  9961. );
  9962. p.delicon = $.extend([true,"left", styles.icon_del ],rp_ge[$t.p.id].delicon);
  9963. p.cancelicon = $.extend([true,"left", styles.icon_cancel ],rp_ge[$t.p.id].cancelicon);
  9964. if(p.delicon[0]===true) {
  9965. $("#dData","#"+dtbl+"_2").addClass(p.delicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  9966. .append("<span class='" + commonstyle.icon_base + " " + p.delicon[2]+"'></span>");
  9967. }
  9968. if(p.cancelicon[0]===true) {
  9969. $("#eData","#"+dtbl+"_2").addClass(p.cancelicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  9970. .append("<span class='" + commonstyle.icon_base + " " + p.cancelicon[2]+"'></span>");
  9971. }
  9972. $("#dData","#"+dtbl+"_2").click(function(){
  9973. var ret=[true,""], pk,
  9974. postdata = $("#DelData>td","#"+dtbl).text(); //the pair is name=val1,val2,...
  9975. onCS = {};
  9976. onCS = $($t).triggerHandler("jqGridDelRowClickSubmit", [rp_ge[$t.p.id], postdata]);
  9977. if(onCS === undefined && $.isFunction( rp_ge[$t.p.id].onclickSubmit ) ) {
  9978. onCS = rp_ge[$t.p.id].onclickSubmit.call($t, rp_ge[$t.p.id], postdata) || {};
  9979. }
  9980. ret = $($t).triggerHandler("jqGridDelRowBeforeSubmit", [postdata]);
  9981. if(ret === undefined) {
  9982. ret = [true,"",""];
  9983. }
  9984. if( ret[0] && $.isFunction(rp_ge[$t.p.id].beforeSubmit)) {
  9985. ret = rp_ge[$t.p.id].beforeSubmit.call($t, postdata);
  9986. }
  9987. if(ret[0] && !rp_ge[$t.p.id].processing) {
  9988. rp_ge[$t.p.id].processing = true;
  9989. opers = $t.p.prmNames;
  9990. postd = $.extend({},rp_ge[$t.p.id].delData, onCS);
  9991. oper = opers.oper;
  9992. postd[oper] = opers.deloper;
  9993. idname = opers.id;
  9994. postdata = String(postdata).split(",");
  9995. if(!postdata.length) { return false; }
  9996. for(pk in postdata) {
  9997. if(postdata.hasOwnProperty(pk)) {
  9998. postdata[pk] = $.jgrid.stripPref($t.p.idPrefix, postdata[pk]);
  9999. }
  10000. }
  10001. postd[idname] = postdata.join();
  10002. $(this).addClass( commonstyle.active );
  10003. var ajaxOptions = $.extend({
  10004. url: rp_ge[$t.p.id].url || $($t).jqGrid('getGridParam','editurl'),
  10005. type: rp_ge[$t.p.id].mtype,
  10006. data: $.isFunction(rp_ge[$t.p.id].serializeDelData) ? rp_ge[$t.p.id].serializeDelData.call($t,postd) : postd,
  10007. complete:function(data,status){
  10008. var i;
  10009. $("#dData", "#"+dtbl+"_2").removeClass( commonstyle.active );
  10010. if(data.status >= 300 && data.status !== 304) {
  10011. ret[0] = false;
  10012. ret[1] = $($t).triggerHandler("jqGridDelRowErrorTextFormat", [data]);
  10013. if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
  10014. ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t, data);
  10015. }
  10016. if(ret[1] === undefined) {
  10017. ret[1] = status + " Status: '" + data.statusText + "'. Error code: " + data.status;
  10018. }
  10019. } else {
  10020. // data is posted successful
  10021. // execute aftersubmit with the returned data from server
  10022. ret = $($t).triggerHandler("jqGridDelRowAfterSubmit", [data, postd]);
  10023. if(ret === undefined) {
  10024. ret = [true,"",""];
  10025. }
  10026. if( ret[0] && $.isFunction(rp_ge[$t.p.id].afterSubmit) ) {
  10027. ret = rp_ge[$t.p.id].afterSubmit.call($t, data, postd);
  10028. }
  10029. }
  10030. if(ret[0] === false) {
  10031. $("#DelError>td","#"+dtbl).html(ret[1]);
  10032. $("#DelError","#"+dtbl).show();
  10033. } else {
  10034. if(rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype !== "local") {
  10035. $($t).trigger("reloadGrid");
  10036. } else {
  10037. if($t.p.treeGrid===true){
  10038. try {$($t).jqGrid("delTreeNode",$t.p.idPrefix+postdata[0]);} catch(e){}
  10039. } else {
  10040. for(i=0;i<postdata.length;i++) {
  10041. $($t).jqGrid("delRowData",$t.p.idPrefix+ postdata[i]);
  10042. }
  10043. }
  10044. $t.p.selrow = null;
  10045. $t.p.selarrrow = [];
  10046. }
  10047. if($.isFunction(rp_ge[$t.p.id].afterComplete) || $._data( $($t)[0], 'events' ).hasOwnProperty('jqGridDelRowAfterComplete')) {
  10048. var copydata = data;
  10049. setTimeout(function(){
  10050. $($t).triggerHandler("jqGridDelRowAfterComplete", [copydata, postd]);
  10051. try {
  10052. rp_ge[$t.p.id].afterComplete.call($t, copydata, postd);
  10053. } catch(eacg) {
  10054. // do nothing
  10055. }
  10056. },500);
  10057. }
  10058. }
  10059. rp_ge[$t.p.id].processing=false;
  10060. if(ret[0]) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});}
  10061. }
  10062. }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxDelOptions);
  10063. if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) {
  10064. if ($.isFunction($t.p.dataProxy)) {
  10065. rp_ge[$t.p.id].useDataProxy = true;
  10066. } else {
  10067. ret[0]=false;ret[1] += " "+$.jgrid.getRegional($t, 'errors.nourl');
  10068. }
  10069. }
  10070. if (ret[0]) {
  10071. if (rp_ge[$t.p.id].useDataProxy) {
  10072. var dpret = $t.p.dataProxy.call($t, ajaxOptions, "del_"+$t.p.id);
  10073. if(dpret === undefined) {
  10074. dpret = [true, ""];
  10075. }
  10076. if(dpret[0] === false ) {
  10077. ret[0] = false;
  10078. ret[1] = dpret[1] || "Error deleting the selected row!" ;
  10079. } else {
  10080. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  10081. }
  10082. }
  10083. else {
  10084. if(ajaxOptions.url === "clientArray") {
  10085. postd = ajaxOptions.data;
  10086. ajaxOptions.complete({status:200, statusText:''},'');
  10087. } else {
  10088. $.ajax(ajaxOptions);
  10089. }
  10090. }
  10091. }
  10092. }
  10093. if(ret[0] === false) {
  10094. $("#DelError>td","#"+dtbl).html(ret[1]);
  10095. $("#DelError","#"+dtbl).show();
  10096. }
  10097. return false;
  10098. });
  10099. $("#eData", "#"+dtbl+"_2").click(function(){
  10100. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:rp_ge[$t.p.id].jqModal, onClose: rp_ge[$t.p.id].onClose});
  10101. return false;
  10102. });
  10103. showFrm = $($t).triggerHandler("jqGridDelRowBeforeInitData", [$("#"+dtbl)]);
  10104. if(showFrm === undefined) {
  10105. showFrm = true;
  10106. }
  10107. if(showFrm && $.isFunction(rp_ge[$t.p.id].beforeInitData)) {
  10108. showFrm = rp_ge[$t.p.id].beforeInitData.call($t, $("#"+dtbl));
  10109. }
  10110. if(showFrm === false) {return;}
  10111. $($t).triggerHandler("jqGridDelRowBeforeShowForm", [$("#"+dtbl)]);
  10112. if($.isFunction( rp_ge[$t.p.id].beforeShowForm )) {
  10113. rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));
  10114. }
  10115. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:rp_ge[$t.p.id].jqModal, overlay: rp_ge[$t.p.id].overlay, modal:rp_ge[$t.p.id].modal});
  10116. $($t).triggerHandler("jqGridDelRowAfterShowForm", [$("#"+dtbl)]);
  10117. if($.isFunction( rp_ge[$t.p.id].afterShowForm )) {
  10118. rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));
  10119. }
  10120. }
  10121. if(rp_ge[$t.p.id].closeOnEscape===true) {
  10122. setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).attr("tabindex","-1").focus();},0);
  10123. }
  10124. });
  10125. },
  10126. navGrid : function (elem, p, pEdit, pAdd, pDel, pSearch, pView) {
  10127. var regional = $.jgrid.getRegional(this[0], 'nav'),
  10128. currstyle = this[0].p.styleUI,
  10129. styles = $.jgrid.styleUI[currstyle].navigator,
  10130. commonstyle = $.jgrid.styleUI[currstyle].common;
  10131. p = $.extend({
  10132. edit: true,
  10133. editicon: styles.icon_edit_nav,
  10134. add: true,
  10135. addicon: styles.icon_add_nav,
  10136. del: true,
  10137. delicon: styles.icon_del_nav,
  10138. search: true,
  10139. searchicon: styles.icon_search_nav,
  10140. refresh: true,
  10141. refreshicon: styles.icon_refresh_nav,
  10142. refreshstate: 'firstpage',
  10143. view: false,
  10144. viewicon : styles.icon_view_nav,
  10145. position : "left",
  10146. closeOnEscape : true,
  10147. beforeRefresh : null,
  10148. afterRefresh : null,
  10149. cloneToTop : false,
  10150. alertwidth : 200,
  10151. alertheight : 'auto',
  10152. alerttop: null,
  10153. alertleft: null,
  10154. alertzIndex : null,
  10155. dropmenu : false,
  10156. navButtonText : ''
  10157. }, regional, p ||{});
  10158. return this.each(function() {
  10159. if(this.p.navGrid) {return;}
  10160. var alertIDs = {themodal: 'alertmod_' + this.p.id, modalhead: 'alerthd_' + this.p.id,modalcontent: 'alertcnt_' + this.p.id},
  10161. $t = this, twd, tdw, o;
  10162. if(!$t.grid || typeof elem !== 'string') {return;}
  10163. if(!$($t).data('navGrid')) {
  10164. $($t).data('navGrid',p);
  10165. }
  10166. // speedoverhead, but usefull for future
  10167. o = $($t).data('navGrid');
  10168. if($t.p.force_regional) {
  10169. o = $.extend(o, regional);
  10170. }
  10171. if ($("#"+alertIDs.themodal)[0] === undefined) {
  10172. if(!o.alerttop && !o.alertleft) {
  10173. if (window.innerWidth !== undefined) {
  10174. o.alertleft = window.innerWidth;
  10175. o.alerttop = window.innerHeight;
  10176. } else if (document.documentElement !== undefined && document.documentElement.clientWidth !== undefined && document.documentElement.clientWidth !== 0) {
  10177. o.alertleft = document.documentElement.clientWidth;
  10178. o.alerttop = document.documentElement.clientHeight;
  10179. } else {
  10180. o.alertleft=1024;
  10181. o.alerttop=768;
  10182. }
  10183. o.alertleft = o.alertleft/2 - parseInt(o.alertwidth,10)/2;
  10184. o.alerttop = o.alerttop/2-25;
  10185. }
  10186. $.jgrid.createModal(alertIDs,
  10187. "<div>"+o.alerttext+"</div><span tabindex='0'><span tabindex='-1' id='jqg_alrt'></span></span>",
  10188. {
  10189. gbox:"#gbox_"+$.jgrid.jqID($t.p.id),
  10190. jqModal:true,
  10191. drag:true,
  10192. resize:true,
  10193. caption:o.alertcap,
  10194. top:o.alerttop,
  10195. left:o.alertleft,
  10196. width:o.alertwidth,
  10197. height: o.alertheight,
  10198. closeOnEscape:o.closeOnEscape,
  10199. zIndex: o.alertzIndex,
  10200. styleUI: $t.p.styleUI
  10201. },
  10202. "#gview_"+$.jgrid.jqID($t.p.id),
  10203. $("#gbox_"+$.jgrid.jqID($t.p.id))[0],
  10204. true
  10205. );
  10206. }
  10207. var clone = 1, i,
  10208. onHoverIn = function () {
  10209. if (!$(this).hasClass(commonstyle.disabled)) {
  10210. $(this).addClass(commonstyle.hover);
  10211. }
  10212. },
  10213. onHoverOut = function () {
  10214. $(this).removeClass(commonstyle.hover);
  10215. };
  10216. if(o.cloneToTop && $t.p.toppager) {clone = 2;}
  10217. for(i = 0; i<clone; i++) {
  10218. var tbd,
  10219. navtbl = $("<table class='ui-pg-table navtable ui-common-table'><tbody><tr></tr></tbody></table>"),
  10220. sep = "<td class='ui-pg-button " +commonstyle.disabled + "' style='width:4px;'><span class='ui-separator'></span></td>",
  10221. pgid, elemids;
  10222. if(i===0) {
  10223. pgid = elem;
  10224. elemids = $t.p.id;
  10225. if(pgid === $t.p.toppager) {
  10226. elemids += "_top";
  10227. clone = 1;
  10228. }
  10229. } else {
  10230. pgid = $t.p.toppager;
  10231. elemids = $t.p.id+"_top";
  10232. }
  10233. if($t.p.direction === "rtl") {
  10234. $(navtbl).attr("dir","rtl").css("float","right");
  10235. }
  10236. pAdd = pAdd || {};
  10237. if (o.add) {
  10238. tbd = $("<td class='ui-pg-button "+commonstyle.cornerall+"'></td>");
  10239. $(tbd).append("<div class='ui-pg-div'><span class='"+commonstyle.icon_base +" " +o.addicon+"'></span>"+o.addtext+"</div>");
  10240. $("tr",navtbl).append(tbd);
  10241. $(tbd,navtbl)
  10242. .attr({"title":o.addtitle || "",id : pAdd.id || "add_"+elemids})
  10243. .click(function(){
  10244. if (!$(this).hasClass( commonstyle.disabled )) {
  10245. if ($.isFunction( o.addfunc )) {
  10246. o.addfunc.call($t);
  10247. } else {
  10248. $($t).jqGrid("editGridRow","new",pAdd);
  10249. }
  10250. }
  10251. return false;
  10252. }).hover(onHoverIn, onHoverOut);
  10253. tbd = null;
  10254. }
  10255. pEdit = pEdit || {};
  10256. if (o.edit) {
  10257. tbd = $("<td class='ui-pg-button "+commonstyle.cornerall+"'></td>");
  10258. $(tbd).append("<div class='ui-pg-div'><span class='"+commonstyle.icon_base+" "+o.editicon+"'></span>"+o.edittext+"</div>");
  10259. $("tr",navtbl).append(tbd);
  10260. $(tbd,navtbl)
  10261. .attr({"title":o.edittitle || "",id: pEdit.id || "edit_"+elemids})
  10262. .click(function(){
  10263. if (!$(this).hasClass( commonstyle.disabled )) {
  10264. var sr = $t.p.selrow;
  10265. if (sr) {
  10266. if($.isFunction( o.editfunc ) ) {
  10267. o.editfunc.call($t, sr);
  10268. } else {
  10269. $($t).jqGrid("editGridRow",sr,pEdit);
  10270. }
  10271. } else {
  10272. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});
  10273. $("#jqg_alrt").focus();
  10274. }
  10275. }
  10276. return false;
  10277. }).hover(onHoverIn, onHoverOut);
  10278. tbd = null;
  10279. }
  10280. pView = pView || {};
  10281. if (o.view) {
  10282. tbd = $("<td class='ui-pg-button "+commonstyle.cornerall+"'></td>");
  10283. $(tbd).append("<div class='ui-pg-div'><span class='"+commonstyle.icon_base+" "+o.viewicon+"'></span>"+o.viewtext+"</div>");
  10284. $("tr",navtbl).append(tbd);
  10285. $(tbd,navtbl)
  10286. .attr({"title":o.viewtitle || "",id: pView.id || "view_"+elemids})
  10287. .click(function(){
  10288. if (!$(this).hasClass( commonstyle.disabled )) {
  10289. var sr = $t.p.selrow;
  10290. if (sr) {
  10291. if($.isFunction( o.viewfunc ) ) {
  10292. o.viewfunc.call($t, sr);
  10293. } else {
  10294. $($t).jqGrid("viewGridRow",sr,pView);
  10295. }
  10296. } else {
  10297. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});
  10298. $("#jqg_alrt").focus();
  10299. }
  10300. }
  10301. return false;
  10302. }).hover(onHoverIn, onHoverOut);
  10303. tbd = null;
  10304. }
  10305. pDel = pDel || {};
  10306. if (o.del) {
  10307. tbd = $("<td class='ui-pg-button "+commonstyle.cornerall+"'></td>");
  10308. $(tbd).append("<div class='ui-pg-div'><span class='"+commonstyle.icon_base+" "+o.delicon+"'></span>"+o.deltext+"</div>");
  10309. $("tr",navtbl).append(tbd);
  10310. $(tbd,navtbl)
  10311. .attr({"title":o.deltitle || "",id: pDel.id || "del_"+elemids})
  10312. .click(function(){
  10313. if (!$(this).hasClass( commonstyle.disabled )) {
  10314. var dr;
  10315. if($t.p.multiselect) {
  10316. dr = $t.p.selarrrow;
  10317. if(dr.length===0) {dr = null;}
  10318. } else {
  10319. dr = $t.p.selrow;
  10320. }
  10321. if(dr){
  10322. if($.isFunction( o.delfunc )){
  10323. o.delfunc.call($t, dr);
  10324. }else{
  10325. $($t).jqGrid("delGridRow",dr,pDel);
  10326. }
  10327. } else {
  10328. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});$("#jqg_alrt").focus();
  10329. }
  10330. }
  10331. return false;
  10332. }).hover(onHoverIn, onHoverOut);
  10333. tbd = null;
  10334. }
  10335. if(o.add || o.edit || o.del || o.view) {$("tr",navtbl).append(sep);}
  10336. pSearch = pSearch || {};
  10337. if (o.search) {
  10338. tbd = $("<td class='ui-pg-button "+commonstyle.cornerall+"'></td>");
  10339. $(tbd).append("<div class='ui-pg-div'><span class='"+commonstyle.icon_base+" "+o.searchicon+"'></span>"+o.searchtext+"</div>");
  10340. $("tr",navtbl).append(tbd);
  10341. $(tbd,navtbl)
  10342. .attr({"title":o.searchtitle || "",id:pSearch.id || "search_"+elemids})
  10343. .click(function(){
  10344. if (!$(this).hasClass( commonstyle.disabled )) {
  10345. if($.isFunction( o.searchfunc )) {
  10346. o.searchfunc.call($t, pSearch);
  10347. } else {
  10348. $($t).jqGrid("searchGrid",pSearch);
  10349. }
  10350. }
  10351. return false;
  10352. }).hover(onHoverIn, onHoverOut);
  10353. if (pSearch.showOnLoad && pSearch.showOnLoad === true) {
  10354. $(tbd,navtbl).click();
  10355. }
  10356. tbd = null;
  10357. }
  10358. if (o.refresh) {
  10359. tbd = $("<td class='ui-pg-button "+commonstyle.cornerall+"'></td>");
  10360. $(tbd).append("<div class='ui-pg-div'><span class='"+commonstyle.icon_base+" "+o.refreshicon+"'></span>"+o.refreshtext+"</div>");
  10361. $("tr",navtbl).append(tbd);
  10362. $(tbd,navtbl)
  10363. .attr({"title":o.refreshtitle || "",id: "refresh_"+elemids})
  10364. .click(function(){
  10365. if (!$(this).hasClass( commonstyle.disabled )) {
  10366. if($.isFunction(o.beforeRefresh)) {o.beforeRefresh.call($t);}
  10367. $t.p.search = false;
  10368. $t.p.resetsearch = true;
  10369. try {
  10370. if( o.refreshstate !== 'currentfilter') {
  10371. var gID = $t.p.id;
  10372. $t.p.postData.filters ="";
  10373. try {
  10374. $("#fbox_"+$.jgrid.jqID(gID)).jqFilter('resetFilter');
  10375. } catch(ef) {}
  10376. if($.isFunction($t.clearToolbar)) {$t.clearToolbar.call($t,false);}
  10377. }
  10378. } catch (e) {}
  10379. switch (o.refreshstate) {
  10380. case 'firstpage':
  10381. $($t).trigger("reloadGrid", [{page:1}]);
  10382. break;
  10383. case 'current':
  10384. case 'currentfilter':
  10385. $($t).trigger("reloadGrid", [{current:true}]);
  10386. break;
  10387. }
  10388. if($.isFunction(o.afterRefresh)) {o.afterRefresh.call($t);}
  10389. }
  10390. return false;
  10391. }).hover(onHoverIn, onHoverOut);
  10392. tbd = null;
  10393. }
  10394. tdw = $(".ui-jqgrid").css("font-size") || "11px";
  10395. $('body').append("<div id='testpg2' class='ui-jqgrid "+$.jgrid.styleUI[currstyle].base.entrieBox+"' style='font-size:"+tdw+";visibility:hidden;' ></div>");
  10396. twd = $(navtbl).clone().appendTo("#testpg2").width();
  10397. $("#testpg2").remove();
  10398. if($t.p._nvtd) {
  10399. if(o.dropmenu) {
  10400. navtbl = null;
  10401. $($t).jqGrid('_buildNavMenu', pgid, elemids, p, pEdit, pAdd, pDel, pSearch, pView );
  10402. } else if(twd > $t.p._nvtd[0] ) {
  10403. if($t.p.responsive) {
  10404. navtbl = null;
  10405. $($t).jqGrid('_buildNavMenu', pgid, elemids, p, pEdit, pAdd, pDel, pSearch, pView );
  10406. } else {
  10407. $(pgid+"_"+o.position,pgid).append(navtbl).width(twd);
  10408. }
  10409. $t.p._nvtd[0] = twd;
  10410. } else {
  10411. $(pgid+"_"+o.position,pgid).append(navtbl);
  10412. }
  10413. $t.p._nvtd[1] = twd;
  10414. }
  10415. $t.p.navGrid = true;
  10416. }
  10417. if($t.p.storeNavOptions) {
  10418. $t.p.navOptions = o;
  10419. $t.p.editOptions = pEdit;
  10420. $t.p.addOptions = pAdd;
  10421. $t.p.delOptions = pDel;
  10422. $t.p.searchOptions = pSearch;
  10423. $t.p.viewOptions = pView;
  10424. $t.p.navButtons =[];
  10425. }
  10426. });
  10427. },
  10428. navButtonAdd : function (elem, p) {
  10429. var currstyle = this[0].p.styleUI,
  10430. styles = $.jgrid.styleUI[currstyle].navigator;
  10431. p = $.extend({
  10432. caption : "newButton",
  10433. title: '',
  10434. buttonicon : styles.icon_newbutton_nav,
  10435. onClickButton: null,
  10436. position : "last",
  10437. cursor : 'pointer',
  10438. internal : false
  10439. }, p ||{});
  10440. return this.each(function() {
  10441. if( !this.grid) {return;}
  10442. if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);}
  10443. var findnav = $(".navtable",elem)[0], $t = this,
  10444. //getstyle = $.jgrid.getMethod("getStyleUI"),
  10445. disabled = $.jgrid.styleUI[currstyle].common.disabled,
  10446. hover = $.jgrid.styleUI[currstyle].common.hover,
  10447. cornerall = $.jgrid.styleUI[currstyle].common.cornerall,
  10448. iconbase = $.jgrid.styleUI[currstyle].common.icon_base;
  10449. if ($t.p.storeNavOptions && !p.internal) {
  10450. $t.p.navButtons.push([elem,p]);
  10451. }
  10452. if (findnav) {
  10453. if( p.id && $("#"+$.jgrid.jqID(p.id), findnav)[0] !== undefined ) {return;}
  10454. var tbd = $("<td></td>");
  10455. if(p.buttonicon.toString().toUpperCase() === "NONE") {
  10456. $(tbd).addClass('ui-pg-button '+cornerall).append("<div class='ui-pg-div'>"+p.caption+"</div>");
  10457. } else {
  10458. $(tbd).addClass('ui-pg-button '+cornerall).append("<div class='ui-pg-div'><span class='"+iconbase+" "+p.buttonicon+"'></span>"+p.caption+"</div>");
  10459. }
  10460. if(p.id) {$(tbd).attr("id",p.id);}
  10461. if(p.position==='first'){
  10462. if(findnav.rows[0].cells.length ===0 ) {
  10463. $("tr",findnav).append(tbd);
  10464. } else {
  10465. $("tr td:eq(0)",findnav).before(tbd);
  10466. }
  10467. } else {
  10468. $("tr",findnav).append(tbd);
  10469. }
  10470. $(tbd,findnav)
  10471. .attr("title",p.title || "")
  10472. .click(function(e){
  10473. if (!$(this).hasClass(disabled)) {
  10474. if ($.isFunction(p.onClickButton) ) {p.onClickButton.call($t,e);}
  10475. }
  10476. return false;
  10477. })
  10478. .hover(
  10479. function () {
  10480. if (!$(this).hasClass(disabled)) {
  10481. $(this).addClass(hover);
  10482. }
  10483. },
  10484. function () {$(this).removeClass(hover);}
  10485. );
  10486. } else {
  10487. findnav = $(".dropdownmenu",elem)[0];
  10488. if (findnav) {
  10489. var id = $(findnav).val(),
  10490. eid = p.id || $.jgrid.randId(),
  10491. item = $('<li class="ui-menu-item" role="presentation"><a class="'+ cornerall+' g-menu-item" tabindex="0" role="menuitem" id="'+eid+'">'+(p.caption || p.title)+'</a></li>');
  10492. if(id) {
  10493. if(p.position === 'first') {
  10494. $("#"+id).prepend( item );
  10495. } else {
  10496. $("#"+id).append( item );
  10497. }
  10498. $(item).on("click", function(e){
  10499. if (!$(this).hasClass(disabled)) {
  10500. $("#"+id).hide();
  10501. if ($.isFunction(p.onClickButton) ) {
  10502. p.onClickButton.call($t,e);
  10503. }
  10504. }
  10505. return false;
  10506. }).find("a")
  10507. .hover(
  10508. function () {
  10509. if (!$(this).hasClass(disabled)) {
  10510. $(this).addClass(hover);
  10511. }
  10512. },
  10513. function () {$(this).removeClass(hover);}
  10514. );
  10515. }
  10516. }
  10517. }
  10518. });
  10519. },
  10520. navSeparatorAdd:function (elem,p) {
  10521. var currstyle = this[0].p.styleUI,
  10522. commonstyle = $.jgrid.styleUI[currstyle].common;
  10523. p = $.extend({
  10524. sepclass : "ui-separator",
  10525. sepcontent: '',
  10526. position : "last"
  10527. }, p ||{});
  10528. return this.each(function() {
  10529. if( !this.grid) {return;}
  10530. if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);}
  10531. var findnav = $(".navtable",elem)[0], sep, id;
  10532. if ( this.p.storeNavOptions ) {
  10533. this.p.navButtons.push([elem,p]);
  10534. }
  10535. if(findnav) {
  10536. sep = "<td class='ui-pg-button "+ commonstyle.disabled +"' style='width:4px;'><span class='"+p.sepclass+"'></span>"+p.sepcontent+"</td>";
  10537. if (p.position === 'first') {
  10538. if (findnav.rows[0].cells.length === 0) {
  10539. $("tr", findnav).append(sep);
  10540. } else {
  10541. $("tr td:eq(0)", findnav).before(sep);
  10542. }
  10543. } else {
  10544. $("tr", findnav).append(sep);
  10545. }
  10546. } else {
  10547. findnav = $(".dropdownmenu",elem)[0];
  10548. sep = "<li class='ui-menu-item " +commonstyle.disabled + "' style='width:100%' role='presentation'><hr class='ui-separator-li'></li>";
  10549. if(findnav) {
  10550. id = $(findnav).val();
  10551. if(id) {
  10552. if(p.position === "first") {
  10553. $("#"+id).prepend( sep );
  10554. } else {
  10555. $("#"+id).append( sep );
  10556. }
  10557. }
  10558. }
  10559. }
  10560. });
  10561. },
  10562. _buildNavMenu : function ( elem, elemids, p, pEdit, pAdd, pDel, pSearch, pView ) {
  10563. return this.each(function() {
  10564. var $t = this,
  10565. //actions = ['add','edit', 'del', 'view', 'search','refresh'],
  10566. regional = $.jgrid.getRegional($t, 'nav'),
  10567. currstyle = $t.p.styleUI,
  10568. styles = $.jgrid.styleUI[currstyle].navigator,
  10569. classes = $.jgrid.styleUI[currstyle].filter,
  10570. commonstyle = $.jgrid.styleUI[currstyle].common,
  10571. mid = "form_menu_"+$.jgrid.randId(),
  10572. bt = p.navButtonText ? p.navButtonText : regional.selectcaption || 'Actions',
  10573. act = "<button class='dropdownmenu "+commonstyle.button+"' value='"+mid+"'>" + bt +"</button>";
  10574. $(elem+"_"+p.position, elem).append( act );
  10575. var alertIDs = {themodal: 'alertmod_' + this.p.id, modalhead: 'alerthd_' + this.p.id,modalcontent: 'alertcnt_' + this.p.id},
  10576. _buildMenu = function() {
  10577. var fs = $('.ui-jqgrid-view').css('font-size') || '11px',
  10578. eid, itm,
  10579. str = $('<ul id="'+mid+'" class="ui-nav-menu modal-content" role="menu" tabindex="0" style="display:none;font-size:'+fs+'"></ul>');
  10580. if( p.add ) {
  10581. pAdd = pAdd || {};
  10582. eid = pAdd.id || "add_"+elemids;
  10583. itm = $('<li class="ui-menu-item" role="presentation"><a class="'+ commonstyle.cornerall+' g-menu-item" tabindex="0" role="menuitem" id="'+eid+'">'+(p.addtext || p.addtitle)+'</a></li>').click(function(){
  10584. if (!$(this).hasClass( commonstyle.disabled )) {
  10585. if ($.isFunction( p.addfunc )) {
  10586. p.addfunc.call($t);
  10587. } else {
  10588. $($t).jqGrid("editGridRow","new",pAdd);
  10589. }
  10590. $(str).hide();
  10591. }
  10592. return false;
  10593. });
  10594. $(str).append(itm);
  10595. }
  10596. if( p.edit ) {
  10597. pEdit = pEdit || {};
  10598. eid = pEdit.id || "edit_"+elemids;
  10599. itm = $('<li class="ui-menu-item" role="presentation"><a class="'+ commonstyle.cornerall+' g-menu-item" tabindex="0" role="menuitem" id="'+eid+'">'+(p.edittext || p.edittitle)+'</a></li>').click(function(){
  10600. if (!$(this).hasClass( commonstyle.disabled )) {
  10601. var sr = $t.p.selrow;
  10602. if (sr) {
  10603. if($.isFunction( p.editfunc ) ) {
  10604. p.editfunc.call($t, sr);
  10605. } else {
  10606. $($t).jqGrid("editGridRow",sr,pEdit);
  10607. }
  10608. } else {
  10609. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});
  10610. $("#jqg_alrt").focus();
  10611. }
  10612. $(str).hide();
  10613. }
  10614. return false;
  10615. });
  10616. $(str).append(itm);
  10617. }
  10618. if( p.view ) {
  10619. pView = pView || {};
  10620. eid = pView.id || "view_"+elemids;
  10621. itm = $('<li class="ui-menu-item" role="presentation"><a class="'+ commonstyle.cornerall+' g-menu-item" tabindex="0" role="menuitem" id="'+eid+'">'+(p.viewtext || p.viewtitle)+'</a></li>').click(function(){
  10622. if (!$(this).hasClass( commonstyle.disabled )) {
  10623. var sr = $t.p.selrow;
  10624. if (sr) {
  10625. if($.isFunction( p.editfunc ) ) {
  10626. p.viewfunc.call($t, sr);
  10627. } else {
  10628. $($t).jqGrid("viewGridRow",sr,pView);
  10629. }
  10630. } else {
  10631. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});
  10632. $("#jqg_alrt").focus();
  10633. }
  10634. $(str).hide();
  10635. }
  10636. return false;
  10637. });
  10638. $(str).append(itm);
  10639. }
  10640. if( p.del ) {
  10641. pDel = pDel || {};
  10642. eid = pDel.id || "del_"+elemids;
  10643. itm = $('<li class="ui-menu-item" role="presentation"><a class="'+ commonstyle.cornerall+' g-menu-item" tabindex="0" role="menuitem" id="'+eid+'">'+(p.deltext || p.deltitle)+'</a></li>').click(function(){
  10644. if (!$(this).hasClass( commonstyle.disabled )) {
  10645. var dr;
  10646. if($t.p.multiselect) {
  10647. dr = $t.p.selarrrow;
  10648. if(dr.length===0) {dr = null;}
  10649. } else {
  10650. dr = $t.p.selrow;
  10651. }
  10652. if(dr){
  10653. if($.isFunction( p.delfunc )){
  10654. p.delfunc.call($t, dr);
  10655. }else{
  10656. $($t).jqGrid("delGridRow",dr,pDel);
  10657. }
  10658. } else {
  10659. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});$("#jqg_alrt").focus();
  10660. }
  10661. $(str).hide();
  10662. }
  10663. return false;
  10664. });
  10665. $(str).append(itm);
  10666. }
  10667. if(p.add || p.edit || p.del || p.view) {
  10668. $(str).append("<li class='ui-menu-item " +commonstyle.disabled + "' style='width:100%' role='presentation'><hr class='ui-separator-li'></li>");
  10669. }
  10670. if( p.search ) {
  10671. pSearch = pSearch || {};
  10672. eid = pSearch.id || "search_"+elemids;
  10673. itm = $('<li class="ui-menu-item" role="presentation"><a class="'+ commonstyle.cornerall+' g-menu-item" tabindex="0" role="menuitem" id="'+eid+'">'+(p.searchtext || p.searchtitle)+'</a></li>').click(function(){
  10674. if (!$(this).hasClass( commonstyle.disabled )) {
  10675. if($.isFunction( p.searchfunc )) {
  10676. p.searchfunc.call($t, pSearch);
  10677. } else {
  10678. $($t).jqGrid("searchGrid",pSearch);
  10679. }
  10680. $(str).hide();
  10681. }
  10682. return false;
  10683. });
  10684. $(str).append(itm);
  10685. if (pSearch.showOnLoad && pSearch.showOnLoad === true) {
  10686. $( itm ).click();
  10687. }
  10688. }
  10689. if( p.refresh ) {
  10690. eid = pSearch.id || "search_"+elemids;
  10691. itm = $('<li class="ui-menu-item" role="presentation"><a class="'+ commonstyle.cornerall+' g-menu-item" tabindex="0" role="menuitem" id="'+eid+'">'+(p.refreshtext || p.refreshtitle)+'</a></li>').click(function(){
  10692. if (!$(this).hasClass( commonstyle.disabled )) {
  10693. if($.isFunction(p.beforeRefresh)) {p.beforeRefresh.call($t);}
  10694. $t.p.search = false;
  10695. $t.p.resetsearch = true;
  10696. try {
  10697. if( p.refreshstate !== 'currentfilter') {
  10698. var gID = $t.p.id;
  10699. $t.p.postData.filters ="";
  10700. try {
  10701. $("#fbox_"+$.jgrid.jqID(gID)).jqFilter('resetFilter');
  10702. } catch(ef) {}
  10703. if($.isFunction($t.clearToolbar)) {$t.clearToolbar.call($t,false);}
  10704. }
  10705. } catch (e) {}
  10706. switch (p.refreshstate) {
  10707. case 'firstpage':
  10708. $($t).trigger("reloadGrid", [{page:1}]);
  10709. break;
  10710. case 'current':
  10711. case 'currentfilter':
  10712. $($t).trigger("reloadGrid", [{current:true}]);
  10713. break;
  10714. }
  10715. if($.isFunction(p.afterRefresh)) {p.afterRefresh.call($t);}
  10716. $(str).hide();
  10717. }
  10718. return false;
  10719. });
  10720. $(str).append(itm);
  10721. }
  10722. $(str).hide();
  10723. $('body').append(str);
  10724. $("#"+mid).addClass("ui-menu " + classes.menu_widget);
  10725. $("#"+mid+" > li > a").hover(
  10726. function(){ $(this).addClass(commonstyle.hover); },
  10727. function(){ $(this).removeClass(commonstyle.hover); }
  10728. );
  10729. };
  10730. _buildMenu();
  10731. $(".dropdownmenu", elem+"_"+p.position).on("click", function( e ){
  10732. var offset = $(this).offset(),
  10733. left = ( offset.left ),
  10734. top = parseInt( offset.top),
  10735. bid =$(this).val();
  10736. //if( $("#"+mid)[0] === undefined) {
  10737. //_buildMenu();
  10738. //}
  10739. $("#"+bid).show().css({"top":top - ($("#"+bid).height() +10)+"px", "left":left+"px"});
  10740. e.stopPropagation();
  10741. });
  10742. $("body").on('click', function(e){
  10743. if(!$(e.target).hasClass("dropdownmenu")) {
  10744. $("#"+mid).hide();
  10745. }
  10746. });
  10747. });
  10748. },
  10749. GridToForm : function( rowid, formid ) {
  10750. return this.each(function(){
  10751. var $t = this, i;
  10752. if (!$t.grid) {return;}
  10753. var rowdata = $($t).jqGrid("getRowData",rowid);
  10754. if (rowdata) {
  10755. for(i in rowdata) {
  10756. if(rowdata.hasOwnProperty(i)) {
  10757. if ( $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:radio") || $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:checkbox")) {
  10758. $("[name="+$.jgrid.jqID(i)+"]",formid).each( function() {
  10759. if( $(this).val() == rowdata[i] ) {
  10760. $(this)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  10761. } else {
  10762. $(this)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  10763. }
  10764. });
  10765. } else {
  10766. // this is very slow on big table and form.
  10767. $("[name="+$.jgrid.jqID(i)+"]",formid).val(rowdata[i]);
  10768. }
  10769. }
  10770. }
  10771. }
  10772. });
  10773. },
  10774. FormToGrid : function(rowid, formid, mode, position){
  10775. return this.each(function() {
  10776. var $t = this;
  10777. if(!$t.grid) {return;}
  10778. if(!mode) {mode = 'set';}
  10779. if(!position) {position = 'first';}
  10780. var fields = $(formid).serializeArray();
  10781. var griddata = {};
  10782. $.each(fields, function(i, field){
  10783. griddata[field.name] = field.value;
  10784. });
  10785. if(mode==='add') {$($t).jqGrid("addRowData",rowid,griddata, position);}
  10786. else if(mode==='set') {$($t).jqGrid("setRowData",rowid,griddata);}
  10787. });
  10788. }
  10789. });
  10790. //module begin
  10791. $.jgrid.extend({
  10792. groupingSetup : function () {
  10793. return this.each(function (){
  10794. var $t = this, i, j, cml, cm = $t.p.colModel, grp = $t.p.groupingView,
  10795. classes = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].grouping;
  10796. if(grp !== null && ( (typeof grp === 'object') || $.isFunction(grp) ) ) {
  10797. if(!grp.plusicon) { grp.plusicon = classes.icon_plus;}
  10798. if(!grp.minusicon) { grp.minusicon = classes.icon_minus;}
  10799. if(!grp.groupField.length) {
  10800. $t.p.grouping = false;
  10801. } else {
  10802. if (grp.visibiltyOnNextGrouping === undefined) {
  10803. grp.visibiltyOnNextGrouping = [];
  10804. }
  10805. grp.lastvalues=[];
  10806. if(!grp._locgr) {
  10807. grp.groups =[];
  10808. }
  10809. grp.counters =[];
  10810. for(i=0;i<grp.groupField.length;i++) {
  10811. if(!grp.groupOrder[i]) {
  10812. grp.groupOrder[i] = 'asc';
  10813. }
  10814. if(!grp.groupText[i]) {
  10815. grp.groupText[i] = '{0}';
  10816. }
  10817. if( typeof grp.groupColumnShow[i] !== 'boolean') {
  10818. grp.groupColumnShow[i] = true;
  10819. }
  10820. if( typeof grp.groupSummary[i] !== 'boolean') {
  10821. grp.groupSummary[i] = false;
  10822. }
  10823. if( !grp.groupSummaryPos[i]) {
  10824. grp.groupSummaryPos[i] = 'footer';
  10825. }
  10826. if(grp.groupColumnShow[i] === true) {
  10827. grp.visibiltyOnNextGrouping[i] = true;
  10828. $($t).jqGrid('showCol',grp.groupField[i]);
  10829. } else {
  10830. grp.visibiltyOnNextGrouping[i] = $("#"+$.jgrid.jqID($t.p.id+"_"+grp.groupField[i])).is(":visible");
  10831. $($t).jqGrid('hideCol',grp.groupField[i]);
  10832. }
  10833. }
  10834. grp.summary =[];
  10835. if(grp.hideFirstGroupCol) {
  10836. if($.isArray(grp.formatDisplayField) && !$.isFunction(grp.formatDisplayField[0] ) ) {
  10837. grp.formatDisplayField[0] = function (v) { return v;};
  10838. }
  10839. }
  10840. for(j=0, cml = cm.length; j < cml; j++) {
  10841. if(grp.hideFirstGroupCol) {
  10842. if(!cm[j].hidden && grp.groupField[0] === cm[j].name) {
  10843. cm[j].formatter = function(){return '';};
  10844. }
  10845. }
  10846. if(cm[j].summaryType ) {
  10847. if(cm[j].summaryDivider) {
  10848. grp.summary.push({nm:cm[j].name,st:cm[j].summaryType, v: '', sd:cm[j].summaryDivider, vd:'', sr: cm[j].summaryRound, srt: cm[j].summaryRoundType || 'round'});
  10849. } else {
  10850. grp.summary.push({nm:cm[j].name,st:cm[j].summaryType, v: '', sr: cm[j].summaryRound, srt: cm[j].summaryRoundType || 'round'});
  10851. }
  10852. }
  10853. }
  10854. }
  10855. } else {
  10856. $t.p.grouping = false;
  10857. }
  10858. });
  10859. },
  10860. groupingPrepare : function ( record, irow ) {
  10861. this.each(function(){
  10862. var grp = this.p.groupingView, $t= this, i,
  10863. sumGroups = function() {
  10864. if ($.isFunction(this.st)) {
  10865. this.v = this.st.call($t, this.v, this.nm, record);
  10866. } else {
  10867. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  10868. if(this.st.toLowerCase() === 'avg' && this.sd) {
  10869. this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record);
  10870. }
  10871. }
  10872. },
  10873. grlen = grp.groupField.length,
  10874. fieldName,
  10875. v,
  10876. displayName,
  10877. displayValue,
  10878. changed = 0;
  10879. for(i=0;i<grlen;i++) {
  10880. fieldName = grp.groupField[i];
  10881. displayName = grp.displayField[i];
  10882. v = record[fieldName];
  10883. displayValue = displayName == null ? null : record[displayName];
  10884. if( displayValue == null ) {
  10885. displayValue = v;
  10886. }
  10887. if( v !== undefined ) {
  10888. if(irow === 0 ) {
  10889. // First record always starts a new group
  10890. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  10891. grp.lastvalues[i] = v;
  10892. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  10893. $.each(grp.counters[i].summary, sumGroups);
  10894. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  10895. } else {
  10896. if (typeof v !== "object" && ($.isArray(grp.isInTheSameGroup) && $.isFunction(grp.isInTheSameGroup[i]) ? ! grp.isInTheSameGroup[i].call($t, grp.lastvalues[i], v, i, grp): grp.lastvalues[i] !== v)) {
  10897. // This record is not in same group as previous one
  10898. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  10899. grp.lastvalues[i] = v;
  10900. changed = 1;
  10901. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  10902. $.each(grp.counters[i].summary, sumGroups);
  10903. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  10904. } else {
  10905. if (changed === 1) {
  10906. // This group has changed because an earlier group changed.
  10907. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  10908. grp.lastvalues[i] = v;
  10909. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  10910. $.each(grp.counters[i].summary, sumGroups);
  10911. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  10912. } else {
  10913. grp.counters[i].cnt += 1;
  10914. grp.groups[grp.counters[i].pos].cnt = grp.counters[i].cnt;
  10915. $.each(grp.counters[i].summary, sumGroups);
  10916. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  10917. }
  10918. }
  10919. }
  10920. }
  10921. }
  10922. //gdata.push( rData );
  10923. });
  10924. return this;
  10925. },
  10926. groupingToggle : function(hid){
  10927. this.each(function(){
  10928. var $t = this,
  10929. grp = $t.p.groupingView,
  10930. strpos = hid.split('_'),
  10931. num = parseInt(strpos[strpos.length-2], 10);
  10932. strpos.splice(strpos.length-2,2);
  10933. var uid = strpos.join("_"),
  10934. minus = grp.minusicon,
  10935. plus = grp.plusicon,
  10936. tar = $("#"+$.jgrid.jqID(hid)),
  10937. r = tar.length ? tar[0].nextSibling : null,
  10938. tarspan = $("#"+$.jgrid.jqID(hid)+" span."+"tree-wrap-"+$t.p.direction),
  10939. getGroupingLevelFromClass = function (className) {
  10940. var nums = $.map(className.split(" "), function (item) {
  10941. if (item.substring(0, uid.length + 1) === uid + "_") {
  10942. return parseInt(item.substring(uid.length + 1), 10);
  10943. }
  10944. });
  10945. return nums.length > 0 ? nums[0] : undefined;
  10946. },
  10947. itemGroupingLevel,
  10948. showData,
  10949. collapsed = false,
  10950. skip = false,
  10951. frz = $t.p.frozenColumns ? $t.p.id+"_frozen" : false,
  10952. tar2 = frz ? $("#"+$.jgrid.jqID(hid), "#"+$.jgrid.jqID(frz) ) : false,
  10953. r2 = (tar2 && tar2.length) ? tar2[0].nextSibling : null;
  10954. if( tarspan.hasClass(minus) ) {
  10955. if(r){
  10956. while(r) {
  10957. itemGroupingLevel = getGroupingLevelFromClass(r.className);
  10958. if (itemGroupingLevel !== undefined && itemGroupingLevel <= num) {
  10959. break;
  10960. }
  10961. $(r).hide();
  10962. r = r.nextSibling;
  10963. if(frz) {
  10964. $(r2).hide();
  10965. r2 = r2.nextSibling;
  10966. }
  10967. }
  10968. }
  10969. tarspan.removeClass(minus).addClass(plus);
  10970. collapsed = true;
  10971. } else {
  10972. if(r){
  10973. showData = undefined;
  10974. while(r) {
  10975. itemGroupingLevel = getGroupingLevelFromClass(r.className);
  10976. if (showData === undefined) {
  10977. showData = itemGroupingLevel === undefined; // if the first row after the opening group is data row then show the data rows
  10978. }
  10979. skip = $(r).hasClass("ui-subgrid") && $(r).hasClass("ui-sg-collapsed");
  10980. if (itemGroupingLevel !== undefined) {
  10981. if (itemGroupingLevel <= num) {
  10982. break;// next item of the same lever are found
  10983. }
  10984. if (itemGroupingLevel === num + 1) {
  10985. if(!skip) {
  10986. $(r).show().find(">td>span."+"tree-wrap-"+$t.p.direction).removeClass(minus).addClass(plus);
  10987. if(frz) {
  10988. $(r2).show().find(">td>span."+"tree-wrap-"+$t.p.direction).removeClass(minus).addClass(plus);
  10989. }
  10990. }
  10991. }
  10992. } else if (showData) {
  10993. if(!skip) {
  10994. $(r).show();
  10995. if(frz) {
  10996. $(r2).show();
  10997. }
  10998. }
  10999. }
  11000. r = r.nextSibling;
  11001. if(frz) {
  11002. r2 = r2.nextSibling;
  11003. }
  11004. }
  11005. }
  11006. tarspan.removeClass(plus).addClass(minus);
  11007. }
  11008. $($t).triggerHandler("jqGridGroupingClickGroup", [hid , collapsed]);
  11009. if( $.isFunction($t.p.onClickGroup)) { $t.p.onClickGroup.call($t, hid , collapsed); }
  11010. });
  11011. return false;
  11012. },
  11013. groupingRender : function (grdata, colspans, page, rn ) {
  11014. return this.each(function(){
  11015. var $t = this,
  11016. grp = $t.p.groupingView,
  11017. str = "", icon = "", hid, clid, pmrtl = grp.groupCollapse ? grp.plusicon : grp.minusicon, gv, cp=[], len =grp.groupField.length,
  11018. //classes = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')]['grouping'],
  11019. common = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].common;
  11020. pmrtl = pmrtl+" tree-wrap-"+$t.p.direction;
  11021. $.each($t.p.colModel, function (i,n){
  11022. var ii;
  11023. for(ii=0;ii<len;ii++) {
  11024. if(grp.groupField[ii] === n.name ) {
  11025. cp[ii] = i;
  11026. break;
  11027. }
  11028. }
  11029. });
  11030. var toEnd = 0;
  11031. function findGroupIdx( ind , offset, grp) {
  11032. var ret = false, i;
  11033. if(offset===0) {
  11034. ret = grp[ind];
  11035. } else {
  11036. var id = grp[ind].idx;
  11037. if(id===0) {
  11038. ret = grp[ind];
  11039. } else {
  11040. for(i=ind;i >= 0; i--) {
  11041. if(grp[i].idx === id-offset) {
  11042. ret = grp[i];
  11043. break;
  11044. }
  11045. }
  11046. }
  11047. }
  11048. return ret;
  11049. }
  11050. function buildSummaryTd(i, ik, grp, foffset) {
  11051. var fdata = findGroupIdx(i, ik, grp),
  11052. cm = $t.p.colModel,
  11053. vv, grlen = fdata.cnt, str="", k;
  11054. for(k=foffset; k<colspans;k++) {
  11055. var tmpdata = "<td "+$t.formatCol(k,1,'')+">&#160;</td>",
  11056. tplfld = "{0}";
  11057. $.each(fdata.summary,function(){
  11058. if(this.nm === cm[k].name) {
  11059. if(cm[k].summaryTpl) {
  11060. tplfld = cm[k].summaryTpl;
  11061. }
  11062. if(typeof this.st === 'string' && this.st.toLowerCase() === 'avg') {
  11063. if(this.sd && this.vd) {
  11064. this.v = (this.v/this.vd);
  11065. } else if(this.v && grlen > 0) {
  11066. this.v = (this.v/grlen);
  11067. }
  11068. }
  11069. try {
  11070. this.groupCount = fdata.cnt;
  11071. this.groupIndex = fdata.dataIndex;
  11072. this.groupValue = fdata.value;
  11073. vv = $t.formatter('', this.v, k, this);
  11074. } catch (ef) {
  11075. vv = this.v;
  11076. }
  11077. tmpdata= "<td "+$t.formatCol(k,1,'')+">"+$.jgrid.template(tplfld, vv, fdata.cnt)+ "</td>";
  11078. return false;
  11079. }
  11080. });
  11081. str += tmpdata;
  11082. }
  11083. return str;
  11084. }
  11085. var sumreverse = $.makeArray(grp.groupSummary), mul;
  11086. sumreverse.reverse();
  11087. mul = $t.p.multiselect ? " colspan=\"2\"" : "";
  11088. $.each(grp.groups,function(i,n){
  11089. if(grp._locgr) {
  11090. if( !(n.startRow +n.cnt > (page-1)*rn && n.startRow < page*rn)) {
  11091. return true;
  11092. }
  11093. }
  11094. toEnd++;
  11095. clid = $t.p.id+"ghead_"+n.idx;
  11096. hid = clid+"_"+i;
  11097. icon = "<span style='cursor:pointer;margin-right:8px;margin-left:5px;' class='" + common.icon_base +" "+pmrtl+"' onclick=\"jQuery('#"+$.jgrid.jqID($t.p.id)+"').jqGrid('groupingToggle','"+hid+"');return false;\"></span>";
  11098. try {
  11099. if ($.isArray(grp.formatDisplayField) && $.isFunction(grp.formatDisplayField[n.idx])) {
  11100. gv = grp.formatDisplayField[n.idx].call($t, n.displayValue, n.value, $t.p.colModel[cp[n.idx]], n.idx, grp);
  11101. } else {
  11102. gv = $t.formatter(hid, n.displayValue, cp[n.idx], n.value );
  11103. }
  11104. } catch (egv) {
  11105. gv = n.displayValue;
  11106. }
  11107. var grpTextStr = '';
  11108. if($.isFunction(grp.groupText[n.idx])) {
  11109. grpTextStr = grp.groupText[n.idx].call($t, gv, n.cnt, n.summary);
  11110. } else {
  11111. grpTextStr = $.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary);
  11112. }
  11113. if( !(typeof grpTextStr ==='string' || typeof grpTextStr ==='number' ) ) {
  11114. grpTextStr = gv;
  11115. }
  11116. if(grp.groupSummaryPos[n.idx] === 'header') {
  11117. str += "<tr id=\""+hid+"\"" +(grp.groupCollapse && n.idx>0 ? " style=\"display:none;\" " : " ") + "role=\"row\" class= \"" + common.content + " jqgroup ui-row-"+$t.p.direction+" "+clid+"\"><td style=\"padding-left:"+(n.idx * 12) + "px;"+"\"" + mul +">" + icon+grpTextStr + "</td>";
  11118. str += buildSummaryTd(i, 0, grp.groups, grp.groupColumnShow[n.idx] === false ? (mul ==="" ? 2 : 3) : ((mul ==="") ? 1 : 2) );
  11119. str += "</tr>";
  11120. } else {
  11121. str += "<tr id=\""+hid+"\"" +(grp.groupCollapse && n.idx>0 ? " style=\"display:none;\" " : " ") + "role=\"row\" class= \"" + common.content + " jqgroup ui-row-"+$t.p.direction+" "+clid+"\"><td style=\"padding-left:"+(n.idx * 12) + "px;"+"\" colspan=\""+(grp.groupColumnShow[n.idx] === false ? colspans-1 : colspans)+"\">" + icon + grpTextStr + "</td></tr>";
  11122. }
  11123. var leaf = len-1 === n.idx;
  11124. if( leaf ) {
  11125. var gg = grp.groups[i+1], kk, ik, offset = 0, sgr = n.startRow,
  11126. end = gg !== undefined ? gg.startRow : grp.groups[i].startRow + grp.groups[i].cnt;
  11127. if(grp._locgr) {
  11128. offset = (page-1)*rn;
  11129. if(offset > n.startRow) {
  11130. sgr = offset;
  11131. }
  11132. }
  11133. for(kk=sgr;kk<end;kk++) {
  11134. if(!grdata[kk - offset]) { break; }
  11135. str += grdata[kk - offset].join('');
  11136. }
  11137. if(grp.groupSummaryPos[n.idx] !== 'header') {
  11138. var jj;
  11139. if (gg !== undefined) {
  11140. for (jj = 0; jj < grp.groupField.length; jj++) {
  11141. if (gg.dataIndex === grp.groupField[jj]) {
  11142. break;
  11143. }
  11144. }
  11145. toEnd = grp.groupField.length - jj;
  11146. }
  11147. for (ik = 0; ik < toEnd; ik++) {
  11148. if(!sumreverse[ik]) { continue; }
  11149. var hhdr = "";
  11150. if(grp.groupCollapse && !grp.showSummaryOnHide) {
  11151. hhdr = " style=\"display:none;\"";
  11152. }
  11153. str += "<tr"+hhdr+" jqfootlevel=\""+(n.idx-ik)+"\" role=\"row\" class=\"" + common.content + " jqfoot ui-row-"+$t.p.direction+"\">";
  11154. str += buildSummaryTd(i, ik, grp.groups, 0);
  11155. str += "</tr>";
  11156. }
  11157. toEnd = jj;
  11158. }
  11159. }
  11160. });
  11161. $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").append(str);
  11162. // free up memory
  11163. str = null;
  11164. });
  11165. },
  11166. groupingGroupBy : function (name, options ) {
  11167. return this.each(function(){
  11168. var $t = this;
  11169. if(typeof name === "string") {
  11170. name = [name];
  11171. }
  11172. var grp = $t.p.groupingView;
  11173. $t.p.grouping = true;
  11174. grp._locgr = false;
  11175. //Set default, in case visibilityOnNextGrouping is undefined
  11176. if (grp.visibiltyOnNextGrouping === undefined) {
  11177. grp.visibiltyOnNextGrouping = [];
  11178. }
  11179. var i;
  11180. // show previous hidden groups if they are hidden and weren't removed yet
  11181. for(i=0;i<grp.groupField.length;i++) {
  11182. if(!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) {
  11183. $($t).jqGrid('showCol',grp.groupField[i]);
  11184. }
  11185. }
  11186. // set visibility status of current group columns on next grouping
  11187. for(i=0;i<name.length;i++) {
  11188. grp.visibiltyOnNextGrouping[i] = $("#"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(name[i])).is(":visible");
  11189. }
  11190. $t.p.groupingView = $.extend($t.p.groupingView, options || {});
  11191. grp.groupField = name;
  11192. $($t).trigger("reloadGrid");
  11193. });
  11194. },
  11195. groupingRemove : function (current) {
  11196. return this.each(function(){
  11197. var $t = this;
  11198. if(current === undefined) {
  11199. current = true;
  11200. }
  11201. $t.p.grouping = false;
  11202. if(current===true) {
  11203. var grp = $t.p.groupingView, i;
  11204. // show previous hidden groups if they are hidden and weren't removed yet
  11205. for(i=0;i<grp.groupField.length;i++) {
  11206. if (!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) {
  11207. $($t).jqGrid('showCol', grp.groupField);
  11208. }
  11209. }
  11210. $("tr.jqgroup, tr.jqfoot","#"+$.jgrid.jqID($t.p.id)+" tbody:first").remove();
  11211. $("tr.jqgrow:hidden","#"+$.jgrid.jqID($t.p.id)+" tbody:first").show();
  11212. } else {
  11213. $($t).trigger("reloadGrid");
  11214. }
  11215. });
  11216. },
  11217. groupingCalculations : {
  11218. handler: function(fn, v, field, round, roundType, rc) {
  11219. var funcs = {
  11220. sum: function() {
  11221. return parseFloat(v||0) + parseFloat((rc[field]||0));
  11222. },
  11223. min: function() {
  11224. if(v==="") {
  11225. return parseFloat(rc[field]||0);
  11226. }
  11227. return Math.min(parseFloat(v),parseFloat(rc[field]||0));
  11228. },
  11229. max: function() {
  11230. if(v==="") {
  11231. return parseFloat(rc[field]||0);
  11232. }
  11233. return Math.max(parseFloat(v),parseFloat(rc[field]||0));
  11234. },
  11235. count: function() {
  11236. if(v==="") {v=0;}
  11237. if(rc.hasOwnProperty(field)) {
  11238. return v+1;
  11239. }
  11240. return 0;
  11241. },
  11242. avg: function() {
  11243. // the same as sum, but at end we divide it
  11244. // so use sum instead of duplicating the code (?)
  11245. return funcs.sum();
  11246. }
  11247. };
  11248. if(!funcs[fn]) {
  11249. throw ("jqGrid Grouping No such method: " + fn);
  11250. }
  11251. var res = funcs[fn]();
  11252. if (round != null) {
  11253. if (roundType === 'fixed') {
  11254. res = res.toFixed(round);
  11255. } else {
  11256. var mul = Math.pow(10, round);
  11257. res = Math.round(res * mul) / mul;
  11258. }
  11259. }
  11260. return res;
  11261. }
  11262. },
  11263. setGroupHeaders : function ( o ) {
  11264. o = $.extend({
  11265. useColSpanStyle : false,
  11266. groupHeaders: []
  11267. },o || {});
  11268. return this.each(function(){
  11269. var ts = this,
  11270. i, cmi, skip = 0, $tr, $colHeader, th, $th, thStyle,
  11271. iCol,
  11272. cghi,
  11273. //startColumnName,
  11274. numberOfColumns,
  11275. titleText,
  11276. cVisibleColumns,
  11277. className,
  11278. colModel = ts.p.colModel,
  11279. cml = colModel.length,
  11280. ths = ts.grid.headers,
  11281. $htable = $("table.ui-jqgrid-htable", ts.grid.hDiv),
  11282. $trLabels = $htable.children("thead").children("tr.ui-jqgrid-labels:last").addClass("jqg-second-row-header"),
  11283. $thead = $htable.children("thead"),
  11284. $theadInTable,
  11285. $firstHeaderRow = $htable.find(".jqg-first-row-header"),
  11286. //classes = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')]['grouping'],
  11287. base = $.jgrid.styleUI[(ts.p.styleUI || 'jQueryUI')].base;
  11288. if(!ts.p.groupHeader) {
  11289. ts.p.groupHeader = [];
  11290. }
  11291. ts.p.groupHeader.push(o);
  11292. if($firstHeaderRow[0] === undefined) {
  11293. $firstHeaderRow = $('<tr>', {role: "row", "aria-hidden": "true"}).addClass("jqg-first-row-header").css("height", "auto");
  11294. } else {
  11295. $firstHeaderRow.empty();
  11296. }
  11297. var $firstRow,
  11298. inColumnHeader = function (text, columnHeaders) {
  11299. var length = columnHeaders.length, i;
  11300. for (i = 0; i < length; i++) {
  11301. if (columnHeaders[i].startColumnName === text) {
  11302. return i;
  11303. }
  11304. }
  11305. return -1;
  11306. };
  11307. $(ts).prepend($thead);
  11308. $tr = $('<tr>', {role: "row"}).addClass("ui-jqgrid-labels jqg-third-row-header");
  11309. for (i = 0; i < cml; i++) {
  11310. th = ths[i].el;
  11311. $th = $(th);
  11312. cmi = colModel[i];
  11313. // build the next cell for the first header row
  11314. thStyle = { height: '0px', width: ths[i].width + 'px', display: (cmi.hidden ? 'none' : '')};
  11315. $("<th>", {role: 'gridcell'}).css(thStyle).addClass("ui-first-th-"+ts.p.direction).appendTo($firstHeaderRow);
  11316. th.style.width = ""; // remove unneeded style
  11317. iCol = inColumnHeader(cmi.name, o.groupHeaders);
  11318. if (iCol >= 0) {
  11319. cghi = o.groupHeaders[iCol];
  11320. numberOfColumns = cghi.numberOfColumns;
  11321. titleText = cghi.titleText;
  11322. className = cghi.className || "";
  11323. // caclulate the number of visible columns from the next numberOfColumns columns
  11324. for (cVisibleColumns = 0, iCol = 0; iCol < numberOfColumns && (i + iCol < cml); iCol++) {
  11325. if (!colModel[i + iCol].hidden) {
  11326. cVisibleColumns++;
  11327. }
  11328. }
  11329. // The next numberOfColumns headers will be moved in the next row
  11330. // in the current row will be placed the new column header with the titleText.
  11331. // The text will be over the cVisibleColumns columns
  11332. $colHeader = $('<th>').attr({role: "columnheader"})
  11333. .addClass(base.headerBox+ " ui-th-column-header ui-th-"+ts.p.direction+" "+className)
  11334. //.css({'height':'22px', 'border-top': '0 none'})
  11335. .html(titleText);
  11336. if(cVisibleColumns > 0) {
  11337. $colHeader.attr("colspan", String(cVisibleColumns));
  11338. }
  11339. if (ts.p.headertitles) {
  11340. $colHeader.attr("title", $colHeader.text());
  11341. }
  11342. // hide if not a visible cols
  11343. if( cVisibleColumns === 0) {
  11344. $colHeader.hide();
  11345. }
  11346. $th.before($colHeader); // insert new column header before the current
  11347. $tr.append(th); // move the current header in the next row
  11348. // set the coumter of headers which will be moved in the next row
  11349. skip = numberOfColumns - 1;
  11350. } else {
  11351. if (skip === 0) {
  11352. if (o.useColSpanStyle) {
  11353. // expand the header height to n rows
  11354. var rowspan = $th.attr("rowspan") ? parseInt($th.attr("rowspan"),10) + 1 : 2;
  11355. $th.attr("rowspan", rowspan);
  11356. } else {
  11357. $('<th>', {role: "columnheader"})
  11358. .addClass(base.headerBox+" ui-th-column-header ui-th-"+ts.p.direction)
  11359. .css({"display": cmi.hidden ? 'none' : ''})
  11360. .insertBefore($th);
  11361. $tr.append(th);
  11362. }
  11363. } else {
  11364. // move the header to the next row
  11365. //$th.css({"padding-top": "2px", height: "19px"});
  11366. $tr.append(th);
  11367. skip--;
  11368. }
  11369. }
  11370. }
  11371. $theadInTable = $(ts).children("thead");
  11372. $theadInTable.prepend($firstHeaderRow);
  11373. $tr.insertAfter($trLabels);
  11374. $htable.append($theadInTable);
  11375. if (o.useColSpanStyle) {
  11376. // Increase the height of resizing span of visible headers
  11377. $htable.find("span.ui-jqgrid-resize").each(function () {
  11378. var $parent = $(this).parent();
  11379. if ($parent.is(":visible")) {
  11380. this.style.cssText = 'height: ' + $parent.height() + 'px !important; cursor: col-resize;';
  11381. }
  11382. });
  11383. // Set position of the sortable div (the main lable)
  11384. // with the column header text to the middle of the cell.
  11385. // One should not do this for hidden headers.
  11386. $htable.find("div.ui-jqgrid-sortable").each(function () {
  11387. var $ts = $(this), $parent = $ts.parent();
  11388. if ($parent.is(":visible") && $parent.is(":has(span.ui-jqgrid-resize)")) {
  11389. // minus 4px from the margins of the resize markers
  11390. $ts.css('top', ($parent.height() - $ts.outerHeight()) / 2 - 4 + 'px');
  11391. }
  11392. });
  11393. }
  11394. $firstRow = $theadInTable.find("tr.jqg-first-row-header");
  11395. $(ts).on('jqGridResizeStop.setGroupHeaders', function (e, nw, idx) {
  11396. $firstRow.find('th').eq(idx)[0].style.width = nw + "px";
  11397. });
  11398. });
  11399. },
  11400. destroyGroupHeader : function(nullHeader) {
  11401. if(nullHeader === undefined) {
  11402. nullHeader = true;
  11403. }
  11404. return this.each(function()
  11405. {
  11406. var $t = this, $tr, i, l, headers, $th, $resizing, grid = $t.grid,
  11407. thead = $("table.ui-jqgrid-htable thead", grid.hDiv), cm = $t.p.colModel, hc;
  11408. if(!grid) { return; }
  11409. $(this).off('.setGroupHeaders');
  11410. $tr = $("<tr>", {role: "row"}).addClass("ui-jqgrid-labels");
  11411. headers = grid.headers;
  11412. for (i = 0, l = headers.length; i < l; i++) {
  11413. hc = cm[i].hidden ? "none" : "";
  11414. $th = $(headers[i].el)
  11415. .width(headers[i].width)
  11416. .css('display',hc);
  11417. try {
  11418. $th.removeAttr("rowSpan");
  11419. } catch (rs) {
  11420. //IE 6/7
  11421. $th.attr("rowSpan",1);
  11422. }
  11423. $tr.append($th);
  11424. $resizing = $th.children("span.ui-jqgrid-resize");
  11425. if ($resizing.length>0) {// resizable column
  11426. $resizing[0].style.height = "";
  11427. }
  11428. $th.children("div")[0].style.top = "";
  11429. }
  11430. $(thead).children('tr.ui-jqgrid-labels').remove();
  11431. $(thead).prepend($tr);
  11432. if(nullHeader === true) {
  11433. $($t).jqGrid('setGridParam',{ 'groupHeader': null});
  11434. }
  11435. });
  11436. }
  11437. });
  11438. //module begin
  11439. $.jgrid = $.jgrid || {};
  11440. $.extend($.jgrid,{
  11441. saveState : function ( jqGridId, o ) {
  11442. o = $.extend({
  11443. useStorage : true,
  11444. storageType : "localStorage", // localStorage or sessionStorage
  11445. beforeSetItem : null,
  11446. compression: false,
  11447. compressionModule : 'LZString', // object by example gzip, LZString
  11448. compressionMethod : 'compressToUTF16', // string by example zip, compressToUTF16
  11449. debug : false,
  11450. saveData : true
  11451. }, o || {});
  11452. if(!jqGridId) { return; }
  11453. var gridstate = "", data = "", ret, $t = $("#"+jqGridId)[0], tmp;
  11454. // to use navigator set storeNavOptions to true in grid options
  11455. if(!$t.grid) { return;}
  11456. tmp = $($t).data('inlineNav');
  11457. if(tmp && $t.p.inlineNav) {
  11458. $($t).jqGrid('setGridParam',{_iN: tmp});
  11459. }
  11460. tmp = $($t).data('filterToolbar');
  11461. if(tmp && $t.p.filterToolbar) {
  11462. $($t).jqGrid('setGridParam',{_fT: tmp});
  11463. }
  11464. gridstate = $($t).jqGrid('jqGridExport', { exptype : "jsonstring", ident:"", root:"" });
  11465. data = '';
  11466. if( o.saveData ) {
  11467. data = $($t.grid.bDiv).find(".ui-jqgrid-btable tbody:first").html();
  11468. var firstrow = data.indexOf("</tr>");
  11469. data = data.slice(firstrow + 5);
  11470. }
  11471. if($.isFunction(o.beforeSetItem)) {
  11472. ret = o.beforeSetItem.call($t, gridstate);
  11473. if(ret != null) {
  11474. gridstate = ret;
  11475. }
  11476. }
  11477. if(o.debug) {
  11478. $("#gbox_tree").prepend('<a id="link_save" target="_blank" download="jqGrid_dump.txt">Click to save Dump Data</a>');
  11479. var temp = [], file, properties = {}, url;
  11480. temp.push("Grid Options\n");
  11481. temp.push(gridstate);
  11482. temp.push("\n");
  11483. temp.push("GridData\n");
  11484. temp.push(data);
  11485. properties.type = 'plain/text;charset=utf-8'; // Specify the file's mime-type.
  11486. try {
  11487. file = new File(temp, "jqGrid_dump.txt", properties);
  11488. } catch (e) {
  11489. file = new Blob(temp, properties);
  11490. }
  11491. url = URL.createObjectURL(file);
  11492. $("#link_save").attr("href",url).on('click',function(){
  11493. $(this).remove();
  11494. });
  11495. }
  11496. if(o.compression) {
  11497. if(o.compressionModule) {
  11498. try {
  11499. ret = window[o.compressionModule][o.compressionMethod](gridstate);
  11500. if(ret != null) {
  11501. gridstate = ret;
  11502. data = window[o.compressionModule][o.compressionMethod](data);
  11503. }
  11504. } catch (e) {
  11505. // can not execute a compression.
  11506. }
  11507. }
  11508. }
  11509. if(o.useStorage && $.jgrid.isLocalStorage()) {
  11510. try {
  11511. window[o.storageType].setItem("jqGrid"+$t.p.id, gridstate);
  11512. window[o.storageType].setItem("jqGrid"+$t.p.id+"_data", data);
  11513. } catch (e) {
  11514. if(e.code === 22) { // chrome is 21
  11515. // just for now. we should make some additionla changes and eventually clear some local items
  11516. alert("Local storage limit is over!");
  11517. }
  11518. }
  11519. }
  11520. return gridstate;
  11521. },
  11522. loadState : function (jqGridId, gridstring, o) {
  11523. o = $.extend({
  11524. useStorage : true,
  11525. storageType : "localStorage",
  11526. clearAfterLoad: false, // clears the jqGrid localStorage items aftre load
  11527. beforeSetGrid : null,
  11528. afterSetGrid : null,
  11529. decompression: false,
  11530. decompressionModule : 'LZString', // object by example gzip, LZString
  11531. decompressionMethod : 'decompressFromUTF16', // string by example unzip, decompressFromUTF16
  11532. restoreData : true
  11533. }, o || {});
  11534. if(!jqGridId) { return; }
  11535. var ret, tmp, $t = $("#"+jqGridId)[0], data, iN, fT;
  11536. if(o.useStorage) {
  11537. try {
  11538. gridstring = window[o.storageType].getItem("jqGrid"+$t.id);
  11539. data = window[o.storageType].getItem("jqGrid"+$t.id+"_data");
  11540. } catch (e) {
  11541. // can not get data
  11542. }
  11543. }
  11544. if(!gridstring) { return; }
  11545. if(o.decompression) {
  11546. if(o.decompressionModule) {
  11547. try {
  11548. ret = window[o.decompressionModule][o.decompressionMethod]( gridstring );
  11549. if(ret != null ) {
  11550. gridstring = ret;
  11551. data = window[o.decompressionModule][o.decompressionMethod]( data );
  11552. }
  11553. } catch (e) {
  11554. // decompression can not be done
  11555. }
  11556. }
  11557. }
  11558. ret = $.jgrid.parseFunc( gridstring );
  11559. if( ret && $.type(ret) === 'object') {
  11560. if($t.grid) {
  11561. $.jgrid.gridUnload( jqGridId );
  11562. }
  11563. if($.isFunction(o.beforeSetGrid)) {
  11564. tmp = o.beforeSetGrid( ret );
  11565. if(tmp && $.type(tmp) === 'object') {
  11566. ret = tmp;
  11567. }
  11568. }
  11569. // some preparings
  11570. var retfunc = function( param ) { var p; p = param; return p;},
  11571. prm = {
  11572. "reccount" : ret.reccount,
  11573. "records" : ret.records,
  11574. "lastpage" : ret.lastpage,
  11575. "shrinkToFit" : retfunc( ret.shrinkToFit),
  11576. "data": retfunc(ret.data),
  11577. "datatype" : retfunc(ret.datatype),
  11578. "grouping" : retfunc(ret.grouping)
  11579. };
  11580. ret.shrinkToFit = false;
  11581. ret.data = [];
  11582. ret.datatype = 'local';
  11583. ret.grouping = false;
  11584. //ret.navGrid = false;
  11585. if(ret.inlineNav) {
  11586. iN = retfunc( ret._iN );
  11587. ret._iN = null; delete ret._iN;
  11588. }
  11589. if(ret.filterToolbar) {
  11590. fT = retfunc( ret._fT );
  11591. ret._fT = null; delete ret._fT;
  11592. }
  11593. var grid = $("#"+jqGridId).jqGrid( ret );
  11594. if( o.restoreData && $.trim( data ) !== '') {
  11595. grid.append( data );
  11596. }
  11597. grid.jqGrid( 'setGridParam', prm);
  11598. if(ret.storeNavOptions && ret.navGrid) {
  11599. // set to false so that nav grid can be run
  11600. grid[0].p.navGrid = false;
  11601. grid.jqGrid('navGrid', ret.pager, ret.navOptions, ret.editOptions, ret.addOptions, ret.delOptions, ret.searchOptions, ret.viewOptions);
  11602. if(ret.navButtons && ret.navButtons.length) {
  11603. for(var b = 0; b < ret.navButtons.length; b++) {
  11604. if( 'sepclass' in ret.navButtons[b][1]) {
  11605. grid.jqGrid('navSeparatorAdd', ret.navButtons[b][0], ret.navButtons[b][1]);
  11606. } else {
  11607. grid.jqGrid('navButtonAdd', ret.navButtons[b][0], ret.navButtons[b][1]);
  11608. }
  11609. }
  11610. }
  11611. }
  11612. // refresh index
  11613. grid[0].refreshIndex();
  11614. // subgrid
  11615. if(ret.subGrid) {
  11616. var ms = ret.multiselect === 1 ? 1 : 0,
  11617. rn = ret.rownumbers === true ? 1 :0;
  11618. grid.jqGrid('addSubGrid', ms + rn);
  11619. }
  11620. // treegrid
  11621. if(ret.treeGrid) {
  11622. var i = 1, len = grid[0].rows.length,
  11623. expCol = ret.expColInd,
  11624. isLeaf = ret.treeReader.leaf_field,
  11625. expanded = ret.treeReader.expanded_field;
  11626. // optimization of code needed here
  11627. while(i<len) {
  11628. $(grid[0].rows[i].cells[expCol])
  11629. .find("div.treeclick")
  11630. .on("click",function(e){
  11631. var target = e.target || e.srcElement,
  11632. ind2 =$.jgrid.stripPref(ret.idPrefix,$(target,grid[0].rows).closest("tr.jqgrow")[0].id),
  11633. pos = grid[0].p._index[ind2];
  11634. if(!grid[0].p.data[pos][isLeaf]){
  11635. if(grid[0].p.data[pos][expanded]){
  11636. grid.jqGrid("collapseRow",grid[0].p.data[pos]);
  11637. grid.jqGrid("collapseNode",grid[0].p.data[pos]);
  11638. } else {
  11639. grid.jqGrid("expandRow",grid[0].p.data[pos]);
  11640. grid.jqGrid("expandNode",grid[0].p.data[pos]);
  11641. }
  11642. }
  11643. return false;
  11644. });
  11645. if(ret.ExpandColClick === true) {
  11646. $(grid[0].rows[i].cells[expCol])
  11647. .find("span.cell-wrapper")
  11648. .css("cursor","pointer")
  11649. .on("click",function(e) {
  11650. var target = e.target || e.srcElement,
  11651. ind2 =$.jgrid.stripPref(ret.idPrefix,$(target,grid[0].rows).closest("tr.jqgrow")[0].id),
  11652. pos = grid[0].p._index[ind2];
  11653. if(!grid[0].p.data[pos][isLeaf]){
  11654. if(grid[0].p.data[pos][expanded]){
  11655. grid.jqGrid("collapseRow", grid[0].p.data[pos]);
  11656. grid.jqGrid("collapseNode", grid[0].p.data[pos]);
  11657. } else {
  11658. grid.jqGrid("expandRow", grid[0].p.data[pos]);
  11659. grid.jqGrid("expandNode", grid[0].p.data[pos]);
  11660. }
  11661. }
  11662. grid.jqGrid("setSelection",ind2);
  11663. return false;
  11664. });
  11665. }
  11666. i++;
  11667. }
  11668. }
  11669. // multiselect
  11670. if(ret.multiselect) {
  11671. $.each(ret.selarrrow, function(){
  11672. $("#jqg_" + jqGridId + "_"+this)[ret.useProp ? 'prop': 'attr']("checked", "checked");
  11673. });
  11674. }
  11675. // grouping
  11676. // pivotgrid
  11677. if(ret.inlineNav && iN) {
  11678. grid.jqGrid('setGridParam', { inlineNav:false });
  11679. grid.jqGrid('inlineNav', ret.pager, iN);
  11680. }
  11681. if(ret.filterToolbar && fT) {
  11682. grid.jqGrid('setGridParam', { filterToolbar:false });
  11683. fT.restoreFromFilters = true;
  11684. grid.jqGrid('filterToolbar', fT);
  11685. }
  11686. // finally frozenColums
  11687. if( ret.frozenColumns ) {
  11688. grid.jqGrid('setFrozenColumns');
  11689. }
  11690. grid[0].updatepager(true, true);
  11691. if($.isFunction(o.afterSetGrid)) {
  11692. o.afterSetGrid( grid );
  11693. }
  11694. if(o.clearAfterLoad) {
  11695. window[o.storageType].removeItem("jqGrid"+$t.id);
  11696. window[o.storageType].removeItem("jqGrid"+$t.id + "_data");
  11697. }
  11698. } else {
  11699. alert("can not convert to object");
  11700. }
  11701. },
  11702. isGridInStorage : function ( jqGridId, options ) {
  11703. var o = {
  11704. storageType: "localStorage"
  11705. };
  11706. o = $.extend(o , options || {});
  11707. var ret, gridstring, data;
  11708. try {
  11709. gridstring = window[o.storageType].getItem("jqGrid"+jqGridId);
  11710. data = window[o.storageType].getItem("jqGrid" + jqGridId + "_data");
  11711. ret = gridstring != null && data != null && typeof gridstring === "string" && typeof data === "string" ;
  11712. } catch (e) {
  11713. ret = false;
  11714. }
  11715. return ret;
  11716. },
  11717. setRegional : function( jqGridId , options) {
  11718. var o = {
  11719. storageType: "sessionStorage"
  11720. };
  11721. o = $.extend(o , options || {});
  11722. if( !o.regional ) {
  11723. return;
  11724. }
  11725. $.jgrid.saveState( jqGridId, o );
  11726. o.beforeSetGrid = function(params) {
  11727. params.regional = o.regional;
  11728. params.force_regional = true;
  11729. return params;
  11730. };
  11731. $.jgrid.loadState( jqGridId, null, o);
  11732. // check for formatter actions
  11733. var grid = $("#"+jqGridId)[0],
  11734. model = $(grid).jqGrid('getGridParam','colModel'), i=-1, nav = $.jgrid.getRegional(grid, 'nav');
  11735. $.each(model,function(k){
  11736. if(this.formatter && this.formatter === 'actions') {
  11737. i = k;
  11738. return false;
  11739. }
  11740. });
  11741. if(i !== -1 && nav) {
  11742. $("#"+jqGridId + " tbody tr").each(function(){
  11743. var td = this.cells[i];
  11744. $(td).find(".ui-inline-edit").attr("title",nav.edittitle);
  11745. $(td).find(".ui-inline-del").attr("title",nav.deltitle);
  11746. $(td).find(".ui-inline-save").attr("title",nav.savetitle);
  11747. $(td).find(".ui-inline-cancel").attr("title",nav.canceltitle);
  11748. });
  11749. }
  11750. try {
  11751. window[o.storageType].removeItem("jqGrid"+grid.id);
  11752. window[o.storageType].removeItem("jqGrid"+grid.id+"_data");
  11753. } catch (e) {}
  11754. },
  11755. jqGridImport : function(jqGridId, o) {
  11756. o = $.extend({
  11757. imptype : "xml", // xml, json, xmlstring, jsonstring
  11758. impstring: "",
  11759. impurl: "",
  11760. mtype: "GET",
  11761. impData : {},
  11762. xmlGrid :{
  11763. config : "root>grid",
  11764. data: "root>rows"
  11765. },
  11766. jsonGrid :{
  11767. config : "grid",
  11768. data: "data"
  11769. },
  11770. ajaxOptions :{}
  11771. }, o || {});
  11772. var $t = (jqGridId.indexOf("#") === 0 ? "": "#") + $.jgrid.jqID(jqGridId);
  11773. var xmlConvert = function (xml,o) {
  11774. var cnfg = $(o.xmlGrid.config,xml)[0];
  11775. var xmldata = $(o.xmlGrid.data,xml)[0], jstr, jstr1, key;
  11776. if($.grid.xmlToJSON ) {
  11777. jstr = $.jgrid.xmlToJSON( cnfg );
  11778. //jstr = $.jgrid.parse(jstr);
  11779. for(key in jstr) {
  11780. if(jstr.hasOwnProperty(key)) {
  11781. jstr1=jstr[key];
  11782. }
  11783. }
  11784. if(xmldata) {
  11785. // save the datatype
  11786. var svdatatype = jstr.grid.datatype;
  11787. jstr.grid.datatype = 'xmlstring';
  11788. jstr.grid.datastr = xml;
  11789. $($t).jqGrid( jstr1 ).jqGrid("setGridParam",{datatype:svdatatype});
  11790. } else {
  11791. setTimeout(function() { $($t).jqGrid( jstr1 ); },0);
  11792. }
  11793. } else {
  11794. alert("xml2json or parse are not present");
  11795. }
  11796. };
  11797. var jsonConvert = function (jsonstr,o){
  11798. if (jsonstr && typeof jsonstr === 'string') {
  11799. var json = $.jgrid.parseFunc(jsonstr);
  11800. var gprm = json[o.jsonGrid.config];
  11801. var jdata = json[o.jsonGrid.data];
  11802. if(jdata) {
  11803. var svdatatype = gprm.datatype;
  11804. gprm.datatype = 'jsonstring';
  11805. gprm.datastr = jdata;
  11806. $($t).jqGrid( gprm ).jqGrid("setGridParam",{datatype:svdatatype});
  11807. } else {
  11808. $($t).jqGrid( gprm );
  11809. }
  11810. }
  11811. };
  11812. switch (o.imptype){
  11813. case 'xml':
  11814. $.ajax($.extend({
  11815. url:o.impurl,
  11816. type:o.mtype,
  11817. data: o.impData,
  11818. dataType:"xml",
  11819. complete: function(xml,stat) {
  11820. if(stat === 'success') {
  11821. xmlConvert(xml.responseXML,o);
  11822. $($t).triggerHandler("jqGridImportComplete", [xml, o]);
  11823. if($.isFunction(o.importComplete)) {
  11824. o.importComplete(xml);
  11825. }
  11826. }
  11827. xml=null;
  11828. }
  11829. }, o.ajaxOptions));
  11830. break;
  11831. case 'xmlstring' :
  11832. // we need to make just the conversion and use the same code as xml
  11833. if(o.impstring && typeof o.impstring === 'string') {
  11834. var xmld = $.parseXML(o.impstring);
  11835. if(xmld) {
  11836. xmlConvert(xmld,o);
  11837. $($t).triggerHandler("jqGridImportComplete", [xmld, o]);
  11838. if($.isFunction(o.importComplete)) {
  11839. o.importComplete(xmld);
  11840. }
  11841. }
  11842. }
  11843. break;
  11844. case 'json':
  11845. $.ajax($.extend({
  11846. url:o.impurl,
  11847. type:o.mtype,
  11848. data: o.impData,
  11849. dataType:"json",
  11850. complete: function(json) {
  11851. try {
  11852. jsonConvert(json.responseText,o );
  11853. $($t).triggerHandler("jqGridImportComplete", [json, o]);
  11854. if($.isFunction(o.importComplete)) {
  11855. o.importComplete(json);
  11856. }
  11857. } catch (ee){}
  11858. json=null;
  11859. }
  11860. }, o.ajaxOptions ));
  11861. break;
  11862. case 'jsonstring' :
  11863. if(o.impstring && typeof o.impstring === 'string') {
  11864. jsonConvert(o.impstring,o );
  11865. $($t).triggerHandler("jqGridImportComplete", [o.impstring, o]);
  11866. if($.isFunction(o.importComplete)) {
  11867. o.importComplete(o.impstring);
  11868. }
  11869. }
  11870. break;
  11871. }
  11872. }
  11873. });
  11874. $.jgrid.extend({
  11875. jqGridExport : function(o) {
  11876. o = $.extend({
  11877. exptype : "xmlstring",
  11878. root: "grid",
  11879. ident: "\t",
  11880. addOptions : {}
  11881. }, o || {});
  11882. var ret = null;
  11883. this.each(function () {
  11884. if(!this.grid) { return;}
  11885. var gprm = $.extend(true, {}, $(this).jqGrid("getGridParam"), o.addOptions);
  11886. // we need to check for:
  11887. // 1.multiselect, 2.subgrid 3. treegrid and remove the unneded columns from colNames
  11888. if(gprm.rownumbers) {
  11889. gprm.colNames.splice(0,1);
  11890. gprm.colModel.splice(0,1);
  11891. }
  11892. if(gprm.multiselect) {
  11893. gprm.colNames.splice(0,1);
  11894. gprm.colModel.splice(0,1);
  11895. }
  11896. if(gprm.subGrid) {
  11897. gprm.colNames.splice(0,1);
  11898. gprm.colModel.splice(0,1);
  11899. }
  11900. gprm.knv = null;
  11901. switch (o.exptype) {
  11902. case 'xmlstring' :
  11903. ret = "<"+o.root+">"+ $.jgrid.jsonToXML( gprm, {xmlDecl:""} )+"</"+o.root+">";
  11904. break;
  11905. case 'jsonstring' :
  11906. ret = $.jgrid.stringify( gprm );
  11907. if(o.root) { ret = "{"+ o.root +":"+ret+"}"; }
  11908. break;
  11909. }
  11910. });
  11911. return ret;
  11912. },
  11913. excelExport : function(o) {
  11914. o = $.extend({
  11915. exptype : "remote",
  11916. url : null,
  11917. oper: "oper",
  11918. tag: "excel",
  11919. beforeExport : null,
  11920. exporthidden : false,
  11921. exportgrouping: false,
  11922. exportOptions : {}
  11923. }, o || {});
  11924. return this.each(function(){
  11925. if(!this.grid) { return;}
  11926. var url;
  11927. if(o.exptype === "remote") {
  11928. var pdata = $.extend({},this.p.postData), expg;
  11929. pdata[o.oper] = o.tag;
  11930. if($.isFunction(o.beforeExport)) {
  11931. var result = o.beforeExport.call(this, pdata );
  11932. if( $.isPlainObject( result ) ) {
  11933. pdata = result;
  11934. }
  11935. }
  11936. if(o.exporthidden) {
  11937. var cm = this.p.colModel, i, len = cm.length, newm=[];
  11938. for(i=0; i< len; i++) {
  11939. if(cm[i].hidden === undefined) { cm[i].hidden = false; }
  11940. newm.push({name:cm[i].name, hidden:cm[i].hidden});
  11941. }
  11942. var newm1 = JSON.stringify( newm );
  11943. if(typeof newm1 === 'string' ) {
  11944. pdata.colModel = newm1;
  11945. }
  11946. }
  11947. if(o.exportgrouping) {
  11948. expg = JSON.stringify( this.p.groupingView );
  11949. if(typeof expg === 'string' ) {
  11950. pdata.groupingView = expg;
  11951. }
  11952. }
  11953. var params = jQuery.param(pdata);
  11954. if(o.url.indexOf("?") !== -1) { url = o.url+"&"+params; }
  11955. else { url = o.url+"?"+params; }
  11956. window.location = url;
  11957. }
  11958. });
  11959. }
  11960. });
  11961. //module begin
  11962. $.jgrid.inlineEdit = $.jgrid.inlineEdit || {};
  11963. $.jgrid.extend({
  11964. //Editing
  11965. editRow : function(rowid,keys,oneditfunc,successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
  11966. // Compatible mode old versions
  11967. var o={}, args = $.makeArray(arguments).slice(1), $t = this[0];
  11968. if( $.type(args[0]) === "object" ) {
  11969. o = args[0];
  11970. } else {
  11971. if (keys !== undefined) { o.keys = keys; }
  11972. if ($.isFunction(oneditfunc)) { o.oneditfunc = oneditfunc; }
  11973. if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
  11974. if (url !== undefined) { o.url = url; }
  11975. if (extraparam !== undefined) { o.extraparam = extraparam; }
  11976. if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
  11977. if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
  11978. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  11979. // last two not as param, but as object (sorry)
  11980. //if (restoreAfterError !== undefined) { o.restoreAfterError = restoreAfterError; }
  11981. //if (mtype !== undefined) { o.mtype = mtype || "POST"; }
  11982. }
  11983. o = $.extend(true, {
  11984. keys : false,
  11985. keyevent : "keydown",
  11986. oneditfunc: null,
  11987. successfunc: null,
  11988. url: null,
  11989. extraparam: {},
  11990. aftersavefunc: null,
  11991. errorfunc: null,
  11992. afterrestorefunc: null,
  11993. restoreAfterError: true,
  11994. mtype: "POST",
  11995. focusField : true,
  11996. saveui : "enable",
  11997. savetext : $.jgrid.getRegional($t,'defaults.savetext')
  11998. }, $.jgrid.inlineEdit, o );
  11999. // End compatible
  12000. return this.each(function(){
  12001. var nm, tmp, editable, cnt=0, focus=null, svr={}, ind,cm, bfer,
  12002. inpclass = $(this).jqGrid('getStyleUI',$t.p.styleUI+".inlinedit",'inputClass', true);
  12003. if (!$t.grid ) { return; }
  12004. ind = $($t).jqGrid("getInd",rowid,true);
  12005. if( ind === false ) {return;}
  12006. $t.p.beforeAction = true;
  12007. bfer = $.isFunction( o.beforeEditRow ) ? o.beforeEditRow.call($t,o, rowid) : undefined;
  12008. if( bfer === undefined ) {
  12009. bfer = true;
  12010. }
  12011. if(!bfer) {
  12012. $t.p.beforeAction = false;
  12013. return;
  12014. }
  12015. editable = $(ind).attr("editable") || "0";
  12016. if (editable === "0" && !$(ind).hasClass("not-editable-row")) {
  12017. cm = $t.p.colModel;
  12018. $('td[role="gridcell"]',ind).each( function(i) {
  12019. nm = cm[i].name;
  12020. var treeg = $t.p.treeGrid===true && nm === $t.p.ExpandColumn;
  12021. if(treeg) { tmp = $("span:first",this).html();}
  12022. else {
  12023. try {
  12024. tmp = $.unformat.call($t,this,{rowId:rowid, colModel:cm[i]},i);
  12025. } catch (_) {
  12026. tmp = ( cm[i].edittype && cm[i].edittype === 'textarea' ) ? $(this).text() : $(this).html();
  12027. }
  12028. }
  12029. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  12030. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  12031. svr[nm]=tmp;
  12032. if(cm[i].editable===true) {
  12033. if(focus===null) { focus = i; }
  12034. if (treeg) { $("span:first",this).html(""); }
  12035. else { $(this).html(""); }
  12036. var opt = $.extend({},cm[i].editoptions || {},{id:rowid+"_"+nm,name:nm,rowId:rowid, oper:'edit'});
  12037. if(!cm[i].edittype) { cm[i].edittype = "text"; }
  12038. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  12039. var elc = $.jgrid.createEl.call($t,cm[i].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  12040. $(elc).addClass("editable inline-edit-cell");
  12041. if( $.inArray(cm[i].edittype, ['text','textarea','password','select']) > -1) {
  12042. $(elc).addClass( inpclass );
  12043. }
  12044. if(treeg) { $("span:first",this).append(elc); }
  12045. else { $(this).append(elc); }
  12046. $.jgrid.bindEv.call($t, elc, opt);
  12047. //Again IE
  12048. if(cm[i].edittype === "select" && cm[i].editoptions!==undefined && cm[i].editoptions.multiple===true && cm[i].editoptions.dataUrl===undefined && $.jgrid.msie()) {
  12049. $(elc).width($(elc).width());
  12050. }
  12051. cnt++;
  12052. }
  12053. }
  12054. });
  12055. if(cnt > 0) {
  12056. svr.id = rowid; $t.p.savedRow.push(svr);
  12057. $(ind).attr("editable","1");
  12058. if(o.focusField ) {
  12059. if(typeof o.focusField === 'number' && parseInt(o.focusField,10) <= cm.length) {
  12060. focus = o.focusField;
  12061. }
  12062. setTimeout(function(){
  12063. var fe = $("td:eq("+focus+") :input:visible",ind).not(":disabled");
  12064. if(fe.length > 0) {
  12065. fe.focus();
  12066. }
  12067. },0);
  12068. }
  12069. if(o.keys===true) {
  12070. $(ind).on( o.keyevent ,function(e) {
  12071. if (e.keyCode === 27) {
  12072. $($t).jqGrid("restoreRow",rowid, o);
  12073. if($t.p.inlineNav) {
  12074. try {
  12075. $($t).jqGrid('showAddEditButtons');
  12076. } catch (eer1) {}
  12077. }
  12078. return false;
  12079. }
  12080. if (e.keyCode === 13) {
  12081. var ta = e.target;
  12082. if(ta.tagName === 'TEXTAREA') { return true; }
  12083. if( $($t).jqGrid("saveRow", rowid, o ) ) {
  12084. if($t.p.inlineNav) {
  12085. try {
  12086. $($t).jqGrid('showAddEditButtons');
  12087. } catch (eer2) {}
  12088. }
  12089. }
  12090. return false;
  12091. }
  12092. });
  12093. }
  12094. $($t).triggerHandler("jqGridInlineEditRow", [rowid, o]);
  12095. if( $.isFunction(o.oneditfunc)) { o.oneditfunc.call($t, rowid); }
  12096. }
  12097. }
  12098. });
  12099. },
  12100. saveRow : function(rowid, successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
  12101. // Compatible mode old versions
  12102. var args = $.makeArray(arguments).slice(1), o = {}, $t = this[0];
  12103. if( $.type(args[0]) === "object" ) {
  12104. o = args[0];
  12105. } else {
  12106. if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
  12107. if (url !== undefined) { o.url = url; }
  12108. if (extraparam !== undefined) { o.extraparam = extraparam; }
  12109. if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
  12110. if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
  12111. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  12112. }
  12113. o = $.extend(true, {
  12114. successfunc: null,
  12115. url: null,
  12116. extraparam: {},
  12117. aftersavefunc: null,
  12118. errorfunc: null,
  12119. afterrestorefunc: null,
  12120. restoreAfterError: true,
  12121. mtype: "POST",
  12122. saveui : "enable",
  12123. savetext : $.jgrid.getRegional($t,'defaults.savetext')
  12124. }, $.jgrid.inlineEdit, o );
  12125. // End compatible
  12126. var success = false, nm, tmp={}, tmp2={}, tmp3= {}, editable, fr, cv, ind, nullIfEmpty=false,
  12127. error = $.trim( $($t).jqGrid('getStyleUI', $t.p.styleUI+'.common', 'error', true) );
  12128. if (!$t.grid ) { return success; }
  12129. ind = $($t).jqGrid("getInd",rowid,true);
  12130. if(ind === false) {return success;}
  12131. var errors = $.jgrid.getRegional($t, 'errors'),
  12132. edit =$.jgrid.getRegional($t, 'edit'),
  12133. bfsr = $.isFunction( o.beforeSaveRow ) ? o.beforeSaveRow.call($t,o, rowid) : undefined;
  12134. if( bfsr === undefined ) {
  12135. bfsr = true;
  12136. }
  12137. if(!bfsr) { return; }
  12138. editable = $(ind).attr("editable");
  12139. o.url = o.url || $t.p.editurl;
  12140. if (editable==="1") {
  12141. var cm, index, elem;
  12142. $('td[role="gridcell"]',ind).each(function(i) {
  12143. cm = $t.p.colModel[i];
  12144. nm = cm.name;
  12145. elem = "";
  12146. if ( nm !== 'cb' && nm !== 'subgrid' && cm.editable===true && nm !== 'rn' && !$(this).hasClass('not-editable-cell')) {
  12147. switch (cm.edittype) {
  12148. case "checkbox":
  12149. var cbv = ["Yes","No"];
  12150. if(cm.editoptions && cm.editoptions.value) {
  12151. cbv = cm.editoptions.value.split(":");
  12152. }
  12153. tmp[nm]= $("input",this).is(":checked") ? cbv[0] : cbv[1];
  12154. elem = $("input",this);
  12155. break;
  12156. case 'text':
  12157. case 'password':
  12158. case 'textarea':
  12159. case "button" :
  12160. tmp[nm]=$("input, textarea",this).val();
  12161. elem = $("input, textarea",this);
  12162. break;
  12163. case 'select':
  12164. if(!cm.editoptions.multiple) {
  12165. tmp[nm] = $("select option:selected",this).val();
  12166. tmp2[nm] = $("select option:selected", this).text();
  12167. } else {
  12168. var sel = $("select",this), selectedText = [];
  12169. tmp[nm] = $(sel).val();
  12170. if(tmp[nm]) { tmp[nm]= tmp[nm].join(","); } else { tmp[nm] =""; }
  12171. $("select option:selected",this).each(
  12172. function(i,selected){
  12173. selectedText[i] = $(selected).text();
  12174. }
  12175. );
  12176. tmp2[nm] = selectedText.join(",");
  12177. }
  12178. if(cm.formatter && cm.formatter === 'select') { tmp2={}; }
  12179. elem = $("select",this);
  12180. break;
  12181. case 'custom' :
  12182. try {
  12183. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  12184. tmp[nm] = cm.editoptions.custom_value.call($t, $(".customelement",this),'get');
  12185. if (tmp[nm] === undefined) { throw "e2"; }
  12186. } else { throw "e1"; }
  12187. } catch (e) {
  12188. if (e==="e1") { $.jgrid.info_dialog(errors.errcap,"function 'custom_value' "+edit.msg.nodefined,edit.bClose, {styleUI : $t.p.styleUI }); }
  12189. else { $.jgrid.info_dialog(errors.errcap,e.message,edit.bClose, {styleUI : $t.p.styleUI }); }
  12190. }
  12191. break;
  12192. }
  12193. cv = $.jgrid.checkValues.call($t,tmp[nm],i);
  12194. if(cv[0] === false) {
  12195. index = i;
  12196. return false;
  12197. }
  12198. if($t.p.autoencode) { tmp[nm] = $.jgrid.htmlEncode(tmp[nm]); }
  12199. if(o.url !== 'clientArray' && cm.editoptions && cm.editoptions.NullIfEmpty === true) {
  12200. if(tmp[nm] === "") {
  12201. tmp3[nm] = 'null';
  12202. nullIfEmpty = true;
  12203. }
  12204. }
  12205. }
  12206. });
  12207. if (cv[0] === false){
  12208. try {
  12209. if( $.isFunction($t.p.validationCell) ) {
  12210. $t.p.validationCell.call($t, elem, cv[1], ind.rowIndex, index);
  12211. } else {
  12212. var tr = $($t).jqGrid('getGridRowById', rowid),
  12213. positions = $.jgrid.findPos(tr);
  12214. $.jgrid.info_dialog(errors.errcap,cv[1],edit.bClose,{
  12215. left:positions[0],
  12216. top:positions[1]+$(tr).outerHeight(),
  12217. styleUI : $t.p.styleUI,
  12218. onClose: function(){
  12219. if(index >= 0 ) {
  12220. $("#"+rowid+"_" +$t.p.colModel[index].name).focus();
  12221. }
  12222. }
  12223. });
  12224. }
  12225. } catch (e) {
  12226. alert(cv[1]);
  12227. }
  12228. return success;
  12229. }
  12230. var idname, opers = $t.p.prmNames, oldRowId = rowid;
  12231. if ($t.p.keyName === false) {
  12232. idname = opers.id;
  12233. } else {
  12234. idname = $t.p.keyName;
  12235. }
  12236. if(tmp) {
  12237. tmp[opers.oper] = opers.editoper;
  12238. if (tmp[idname] === undefined || tmp[idname]==="") {
  12239. tmp[idname] = rowid;
  12240. } else if (ind.id !== $t.p.idPrefix + tmp[idname]) {
  12241. // rename rowid
  12242. var oldid = $.jgrid.stripPref($t.p.idPrefix, rowid);
  12243. if ($t.p._index[oldid] !== undefined) {
  12244. $t.p._index[tmp[idname]] = $t.p._index[oldid];
  12245. delete $t.p._index[oldid];
  12246. }
  12247. rowid = $t.p.idPrefix + tmp[idname];
  12248. $(ind).attr("id", rowid);
  12249. if ($t.p.selrow === oldRowId) {
  12250. $t.p.selrow = rowid;
  12251. }
  12252. if ($.isArray($t.p.selarrrow)) {
  12253. var i = $.inArray(oldRowId, $t.p.selarrrow);
  12254. if (i>=0) {
  12255. $t.p.selarrrow[i] = rowid;
  12256. }
  12257. }
  12258. if ($t.p.multiselect) {
  12259. var newCboxId = "jqg_" + $t.p.id + "_" + rowid;
  12260. $("input.cbox",ind)
  12261. .attr("id", newCboxId)
  12262. .attr("name", newCboxId);
  12263. }
  12264. // TODO: to test the case of frozen columns
  12265. }
  12266. if($t.p.inlineData === undefined) { $t.p.inlineData ={}; }
  12267. tmp = $.extend({},tmp,$t.p.inlineData,o.extraparam);
  12268. }
  12269. if (o.url === 'clientArray') {
  12270. tmp = $.extend({},tmp, tmp2);
  12271. if($t.p.autoencode) {
  12272. $.each(tmp,function(n,v){
  12273. tmp[n] = $.jgrid.htmlDecode(v);
  12274. });
  12275. }
  12276. var k, resp = $($t).jqGrid("setRowData",rowid,tmp);
  12277. $(ind).attr("editable","0");
  12278. for(k=0;k<$t.p.savedRow.length;k++) {
  12279. if( String($t.p.savedRow[k].id) === String(oldRowId)) {fr = k; break;}
  12280. }
  12281. if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
  12282. $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, resp, tmp, o]);
  12283. if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid, resp, tmp, o); }
  12284. success = true;
  12285. $(ind).removeClass("jqgrid-new-row").off("keydown");
  12286. } else {
  12287. $($t).jqGrid("progressBar", {method:"show", loadtype : o.saveui, htmlcontent: o.savetext });
  12288. tmp3 = $.extend({},tmp,tmp3);
  12289. tmp3[idname] = $.jgrid.stripPref($t.p.idPrefix, tmp3[idname]);
  12290. $.ajax($.extend({
  12291. url:o.url,
  12292. data: $.isFunction($t.p.serializeRowData) ? $t.p.serializeRowData.call($t, tmp3) : tmp3,
  12293. type: o.mtype,
  12294. async : false, //?!?
  12295. complete: function(res,stat){
  12296. $($t).jqGrid("progressBar", {method:"hide", loadtype : o.saveui, htmlcontent: o.savetext});
  12297. if (stat === "success"){
  12298. var ret = true, sucret, k;
  12299. sucret = $($t).triggerHandler("jqGridInlineSuccessSaveRow", [res, rowid, o]);
  12300. if (!$.isArray(sucret)) {sucret = [true, tmp3];}
  12301. if (sucret[0] && $.isFunction(o.successfunc)) {sucret = o.successfunc.call($t, res);}
  12302. if($.isArray(sucret)) {
  12303. // expect array - status, data, rowid
  12304. ret = sucret[0];
  12305. tmp = sucret[1] || tmp;
  12306. } else {
  12307. ret = sucret;
  12308. }
  12309. if (ret===true) {
  12310. if($t.p.autoencode) {
  12311. $.each(tmp,function(n,v){
  12312. tmp[n] = $.jgrid.htmlDecode(v);
  12313. });
  12314. }
  12315. if(nullIfEmpty) {
  12316. $.each(tmp,function( n ){
  12317. if(tmp[n] === 'null' ) {
  12318. tmp[n] = '';
  12319. }
  12320. });
  12321. }
  12322. tmp = $.extend({},tmp, tmp2);
  12323. $($t).jqGrid("setRowData",rowid,tmp);
  12324. $(ind).attr("editable","0");
  12325. for(k=0;k<$t.p.savedRow.length;k++) {
  12326. if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;}
  12327. }
  12328. if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
  12329. $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, res, tmp, o]);
  12330. if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid, res, tmp, o); }
  12331. success = true;
  12332. $(ind).removeClass("jqgrid-new-row").off("keydown");
  12333. } else {
  12334. $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, null, o]);
  12335. if($.isFunction(o.errorfunc) ) {
  12336. o.errorfunc.call($t, rowid, res, stat, null);
  12337. }
  12338. if(o.restoreAfterError === true) {
  12339. $($t).jqGrid("restoreRow",rowid, o);
  12340. }
  12341. }
  12342. }
  12343. },
  12344. error:function(res,stat,err){
  12345. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  12346. $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, err, o]);
  12347. if($.isFunction(o.errorfunc) ) {
  12348. o.errorfunc.call($t, rowid, res, stat, err);
  12349. } else {
  12350. var rT = res.responseText || res.statusText;
  12351. try {
  12352. $.jgrid.info_dialog(errors.errcap,'<div class="'+error+'">'+ rT +'</div>', edit.bClose, {buttonalign:'right', styleUI : $t.p.styleUI });
  12353. } catch(e) {
  12354. alert(rT);
  12355. }
  12356. }
  12357. if(o.restoreAfterError === true) {
  12358. $($t).jqGrid("restoreRow",rowid, o);
  12359. }
  12360. }
  12361. }, $.jgrid.ajaxOptions, $t.p.ajaxRowOptions || {}));
  12362. }
  12363. }
  12364. return success;
  12365. },
  12366. restoreRow : function(rowid, afterrestorefunc) {
  12367. // Compatible mode old versions
  12368. var args = $.makeArray(arguments).slice(1), o={};
  12369. if( $.type(args[0]) === "object" ) {
  12370. o = args[0];
  12371. } else {
  12372. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  12373. }
  12374. o = $.extend(true, {}, $.jgrid.inlineEdit, o );
  12375. // End compatible
  12376. return this.each(function(){
  12377. var $t= this, fr=-1, ind, ares={}, k;
  12378. if (!$t.grid ) { return; }
  12379. ind = $($t).jqGrid("getInd",rowid,true);
  12380. if(ind === false) {return;}
  12381. var bfcr = $.isFunction( o.beforeCancelRow ) ? o.beforeCancelRow.call($t, o, rowid) : undefined;
  12382. if( bfcr === undefined ) {
  12383. bfcr = true;
  12384. }
  12385. if(!bfcr) { return; }
  12386. for(k=0;k<$t.p.savedRow.length;k++) {
  12387. if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;}
  12388. }
  12389. if(fr >= 0) {
  12390. if($.isFunction($.fn.datepicker)) {
  12391. try {
  12392. $("input.hasDatepicker","#"+$.jgrid.jqID(ind.id)).datepicker('hide');
  12393. } catch (e) {}
  12394. }
  12395. $.each($t.p.colModel, function(){
  12396. if( $t.p.savedRow[fr].hasOwnProperty(this.name)) {
  12397. ares[this.name] = $t.p.savedRow[fr][this.name];
  12398. }
  12399. });
  12400. $($t).jqGrid("setRowData",rowid,ares);
  12401. $(ind).attr("editable","0").off("keydown");
  12402. $t.p.savedRow.splice(fr,1);
  12403. if($("#"+$.jgrid.jqID(rowid), "#"+$.jgrid.jqID($t.p.id)).hasClass("jqgrid-new-row")){
  12404. setTimeout(function(){
  12405. $($t).jqGrid("delRowData",rowid);
  12406. $($t).jqGrid('showAddEditButtons');
  12407. },0);
  12408. }
  12409. }
  12410. $($t).triggerHandler("jqGridInlineAfterRestoreRow", [rowid]);
  12411. if ($.isFunction(o.afterrestorefunc))
  12412. {
  12413. o.afterrestorefunc.call($t, rowid);
  12414. }
  12415. });
  12416. },
  12417. addRow : function ( p ) {
  12418. p = $.extend(true, {
  12419. rowID : null,
  12420. initdata : {},
  12421. position :"first",
  12422. useDefValues : true,
  12423. useFormatter : false,
  12424. addRowParams : {extraparam:{}}
  12425. },p || {});
  12426. return this.each(function(){
  12427. if (!this.grid ) { return; }
  12428. var $t = this;
  12429. $t.p.beforeAction = true;
  12430. var bfar = $.isFunction( p.beforeAddRow ) ? p.beforeAddRow.call($t,p.addRowParams) : undefined;
  12431. if( bfar === undefined ) {
  12432. bfar = true;
  12433. }
  12434. if(!bfar) {
  12435. $t.p.beforeAction = false;
  12436. return;
  12437. }
  12438. p.rowID = $.isFunction(p.rowID) ? p.rowID.call($t, p) : ( (p.rowID != null) ? p.rowID : $.jgrid.randId());
  12439. if(p.useDefValues === true) {
  12440. $($t.p.colModel).each(function(){
  12441. if( this.editoptions && this.editoptions.defaultValue ) {
  12442. var opt = this.editoptions.defaultValue,
  12443. tmp = $.isFunction(opt) ? opt.call($t) : opt;
  12444. p.initdata[this.name] = tmp;
  12445. }
  12446. });
  12447. }
  12448. $($t).jqGrid('addRowData', p.rowID, p.initdata, p.position);
  12449. p.rowID = $t.p.idPrefix + p.rowID;
  12450. $("#"+$.jgrid.jqID(p.rowID), "#"+$.jgrid.jqID($t.p.id)).addClass("jqgrid-new-row");
  12451. if(p.useFormatter) {
  12452. $("#"+$.jgrid.jqID(p.rowID)+" .ui-inline-edit", "#"+$.jgrid.jqID($t.p.id)).click();
  12453. } else {
  12454. var opers = $t.p.prmNames,
  12455. oper = opers.oper;
  12456. p.addRowParams.extraparam[oper] = opers.addoper;
  12457. $($t).jqGrid('editRow', p.rowID, p.addRowParams);
  12458. $($t).jqGrid('setSelection', p.rowID);
  12459. }
  12460. });
  12461. },
  12462. inlineNav : function (elem, o) {
  12463. var $t = this[0],
  12464. regional = $.jgrid.getRegional($t, 'nav'),
  12465. icons = $.jgrid.styleUI[$t.p.styleUI].inlinedit;
  12466. o = $.extend(true,{
  12467. edit: true,
  12468. editicon: icons.icon_edit_nav,
  12469. add: true,
  12470. addicon:icons.icon_add_nav,
  12471. save: true,
  12472. saveicon: icons.icon_save_nav,
  12473. cancel: true,
  12474. cancelicon: icons.icon_cancel_nav,
  12475. addParams : {addRowParams: {extraparam: {}}},
  12476. editParams : {},
  12477. restoreAfterSelect : true,
  12478. saveAfterSelect : false
  12479. }, regional, o ||{});
  12480. return this.each(function(){
  12481. if (!this.grid || this.p.inlineNav) { return; }
  12482. var gID = $.jgrid.jqID($t.p.id),
  12483. disabled = $.trim( $($t).jqGrid('getStyleUI', $t.p.styleUI+'.common', 'disabled', true) );
  12484. // check to see if navgrid is started, if not call it with all false parameters.
  12485. if(!$t.p.navGrid) {
  12486. $($t).jqGrid('navGrid',elem, {refresh:false, edit: false, add: false, del: false, search: false, view: false});
  12487. }
  12488. if(!$($t).data('inlineNav')) {
  12489. $($t).data('inlineNav',o);
  12490. }
  12491. if($t.p.force_regional) {
  12492. o = $.extend(o, regional);
  12493. }
  12494. $t.p.inlineNav = true;
  12495. // detect the formatactions column
  12496. if(o.addParams.useFormatter === true) {
  12497. var cm = $t.p.colModel,i;
  12498. for (i = 0; i<cm.length; i++) {
  12499. if(cm[i].formatter && cm[i].formatter === "actions" ) {
  12500. if(cm[i].formatoptions) {
  12501. var defaults = {
  12502. keys:false,
  12503. onEdit : null,
  12504. onSuccess: null,
  12505. afterSave:null,
  12506. onError: null,
  12507. afterRestore: null,
  12508. extraparam: {},
  12509. url: null
  12510. },
  12511. ap = $.extend( defaults, cm[i].formatoptions );
  12512. o.addParams.addRowParams = {
  12513. "keys" : ap.keys,
  12514. "oneditfunc" : ap.onEdit,
  12515. "successfunc" : ap.onSuccess,
  12516. "url" : ap.url,
  12517. "extraparam" : ap.extraparam,
  12518. "aftersavefunc" : ap.afterSave,
  12519. "errorfunc": ap.onError,
  12520. "afterrestorefunc" : ap.afterRestore
  12521. };
  12522. }
  12523. break;
  12524. }
  12525. }
  12526. }
  12527. if(o.add) {
  12528. $($t).jqGrid('navButtonAdd', elem,{
  12529. caption : o.addtext,
  12530. title : o.addtitle,
  12531. buttonicon : o.addicon,
  12532. id : $t.p.id+"_iladd",
  12533. internal : true,
  12534. onClickButton : function () {
  12535. if($t.p.beforeAction === undefined) {
  12536. $t.p.beforeAction = true;
  12537. }
  12538. $($t).jqGrid('addRow', o.addParams);
  12539. if(!o.addParams.useFormatter && $t.p.beforeAction) {
  12540. $("#"+gID+"_ilsave").removeClass( disabled );
  12541. $("#"+gID+"_ilcancel").removeClass( disabled );
  12542. $("#"+gID+"_iladd").addClass( disabled );
  12543. $("#"+gID+"_iledit").addClass( disabled );
  12544. }
  12545. }
  12546. });
  12547. }
  12548. if(o.edit) {
  12549. $($t).jqGrid('navButtonAdd', elem,{
  12550. caption : o.edittext,
  12551. title : o.edittitle,
  12552. buttonicon : o.editicon,
  12553. id : $t.p.id+"_iledit",
  12554. internal : true,
  12555. onClickButton : function () {
  12556. var sr = $($t).jqGrid('getGridParam','selrow');
  12557. if(sr) {
  12558. if($t.p.beforeAction === undefined) {
  12559. $t.p.beforeAction = true;
  12560. }
  12561. $($t).jqGrid('editRow', sr, o.editParams);
  12562. if($t.p.beforeAction) {
  12563. $("#"+gID+"_ilsave").removeClass( disabled );
  12564. $("#"+gID+"_ilcancel").removeClass( disabled );
  12565. $("#"+gID+"_iladd").addClass( disabled );
  12566. $("#"+gID+"_iledit").addClass( disabled );
  12567. }
  12568. } else {
  12569. $.jgrid.viewModal("#alertmod_"+gID, {gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  12570. }
  12571. }
  12572. });
  12573. }
  12574. if(o.save) {
  12575. $($t).jqGrid('navButtonAdd', elem,{
  12576. caption : o.savetext || '',
  12577. title : o.savetitle || 'Save row',
  12578. buttonicon : o.saveicon,
  12579. id : $t.p.id+"_ilsave",
  12580. internal : true,
  12581. onClickButton : function () {
  12582. var sr = $t.p.savedRow[0].id;
  12583. if(sr) {
  12584. var opers = $t.p.prmNames,
  12585. oper = opers.oper, tmpParams = o.editParams;
  12586. if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) {
  12587. o.addParams.addRowParams.extraparam[oper] = opers.addoper;
  12588. tmpParams = o.addParams.addRowParams;
  12589. } else {
  12590. if(!o.editParams.extraparam) {
  12591. o.editParams.extraparam = {};
  12592. }
  12593. o.editParams.extraparam[oper] = opers.editoper;
  12594. }
  12595. if( $($t).jqGrid('saveRow', sr, tmpParams) ) {
  12596. $($t).jqGrid('showAddEditButtons');
  12597. }
  12598. } else {
  12599. $.jgrid.viewModal("#alertmod_"+gID, {gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  12600. }
  12601. }
  12602. });
  12603. $("#"+gID+"_ilsave").addClass( disabled );
  12604. }
  12605. if(o.cancel) {
  12606. $($t).jqGrid('navButtonAdd', elem,{
  12607. caption : o.canceltext || '',
  12608. title : o.canceltitle || 'Cancel row editing',
  12609. buttonicon : o.cancelicon,
  12610. id : $t.p.id+"_ilcancel",
  12611. internal : true,
  12612. onClickButton : function () {
  12613. var sr = $t.p.savedRow[0].id, cancelPrm = o.editParams;
  12614. if(sr) {
  12615. if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) {
  12616. cancelPrm = o.addParams.addRowParams;
  12617. }
  12618. $($t).jqGrid('restoreRow', sr, cancelPrm);
  12619. $($t).jqGrid('showAddEditButtons');
  12620. } else {
  12621. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  12622. }
  12623. }
  12624. });
  12625. $("#"+gID+"_ilcancel").addClass( disabled );
  12626. }
  12627. if(o.restoreAfterSelect === true || o.saveAfterSelect === true) {
  12628. $($t).on("jqGridBeforeSelectRow.inlineNav", function( event, id ) {
  12629. if($t.p.savedRow.length > 0 && $t.p.inlineNav===true && ( id !== $t.p.selrow && $t.p.selrow !==null) ) {
  12630. if($t.p.selrow === o.addParams.rowID ) {
  12631. $($t).jqGrid('delRowData', $t.p.selrow);
  12632. } else {
  12633. if(o.restoreAfterSelect === true) {
  12634. $($t).jqGrid('restoreRow', $t.p.selrow, o.editParams);
  12635. } else {
  12636. $($t).jqGrid('saveRow', $t.p.selrow, o.editParams);
  12637. }
  12638. }
  12639. $($t).jqGrid('showAddEditButtons');
  12640. }
  12641. });
  12642. }
  12643. });
  12644. },
  12645. showAddEditButtons : function() {
  12646. return this.each(function(){
  12647. if (!this.grid ) { return; }
  12648. var gID = $.jgrid.jqID(this.p.id),
  12649. disabled = $.trim( $(this).jqGrid('getStyleUI', this.p.styleUI+'.common', 'disabled', true) );
  12650. $("#"+gID+"_ilsave").addClass( disabled );
  12651. $("#"+gID+"_ilcancel").addClass( disabled );
  12652. $("#"+gID+"_iladd").removeClass( disabled );
  12653. $("#"+gID+"_iledit").removeClass( disabled );
  12654. });
  12655. },
  12656. showSaveCancelButtons : function() {
  12657. return this.each(function(){
  12658. if (!this.grid ) { return; }
  12659. var gID = $.jgrid.jqID(this.p.id),
  12660. disabled = $.trim( $(this).jqGrid('getStyleUI', this.p.styleUI+'.common', 'disabled', true) );
  12661. $("#"+gID+"_ilsave").removeClass( disabled );
  12662. $("#"+gID+"_ilcancel").removeClass( disabled );
  12663. $("#"+gID+"_iladd").addClass( disabled );
  12664. $("#"+gID+"_iledit").addClass( disabled );
  12665. });
  12666. }
  12667. //end inline edit
  12668. });
  12669. //module begin
  12670. if ($.jgrid.msie() && $.jgrid.msiever()===8) {
  12671. $.expr[":"].hidden = function(elem) {
  12672. return elem.offsetWidth === 0 || elem.offsetHeight === 0 ||
  12673. elem.style.display === "none";
  12674. };
  12675. }
  12676. // requiere load multiselect before grid
  12677. $.jgrid._multiselect = false;
  12678. if($.ui) {
  12679. if ($.ui.multiselect ) {
  12680. if($.ui.multiselect.prototype._setSelected) {
  12681. var setSelected = $.ui.multiselect.prototype._setSelected;
  12682. $.ui.multiselect.prototype._setSelected = function(item,selected) {
  12683. var ret = setSelected.call(this,item,selected);
  12684. if (selected && this.selectedList) {
  12685. var elt = this.element;
  12686. this.selectedList.find('li').each(function() {
  12687. if ($(this).data('optionLink')) {
  12688. $(this).data('optionLink').remove().appendTo(elt);
  12689. }
  12690. });
  12691. }
  12692. return ret;
  12693. };
  12694. }
  12695. if($.ui.multiselect.prototype.destroy) {
  12696. $.ui.multiselect.prototype.destroy = function() {
  12697. this.element.show();
  12698. this.container.remove();
  12699. if ($.Widget === undefined) {
  12700. $.widget.prototype.destroy.apply(this, arguments);
  12701. } else {
  12702. $.Widget.prototype.destroy.apply(this, arguments);
  12703. }
  12704. };
  12705. }
  12706. $.jgrid._multiselect = true;
  12707. }
  12708. }
  12709. $.jgrid.extend({
  12710. sortableColumns : function (tblrow)
  12711. {
  12712. return this.each(function (){
  12713. var ts = this, tid= $.jgrid.jqID( ts.p.id );
  12714. function start() {ts.p.disableClick = true;}
  12715. function stop() { setTimeout(function () { ts.p.disableClick = false; }, 50); }
  12716. var sortable_opts = {
  12717. "tolerance" : "pointer",
  12718. "axis" : "x",
  12719. "scrollSensitivity": "1",
  12720. "items": '>th:not(:has(#jqgh_'+tid+'_cb'+',#jqgh_'+tid+'_rn'+',#jqgh_'+tid+'_subgrid),:hidden)',
  12721. "placeholder": {
  12722. element: function(item) {
  12723. var el = $(document.createElement(item[0].nodeName))
  12724. .addClass(item[0].className+" ui-sortable-placeholder ui-state-highlight")
  12725. .removeClass("ui-sortable-helper")[0];
  12726. return el;
  12727. },
  12728. update: function(self, p) {
  12729. p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.currentItem.css('paddingBottom')||0, 10));
  12730. p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft')||0, 10) - parseInt(self.currentItem.css('paddingRight')||0, 10));
  12731. }
  12732. },
  12733. "update": function(event, ui) {
  12734. var p = $(ui.item).parent(),
  12735. th = $(">th", p),
  12736. colModel = ts.p.colModel,
  12737. cmMap = {}, tid= ts.p.id+"_";
  12738. $.each(colModel, function(i) { cmMap[this.name]=i; });
  12739. var permutation = [];
  12740. th.each(function() {
  12741. var id = $(">div", this).get(0).id.replace(/^jqgh_/, "").replace(tid,"");
  12742. if (cmMap.hasOwnProperty(id)) {
  12743. permutation.push(cmMap[id]);
  12744. }
  12745. });
  12746. $(ts).jqGrid("remapColumns",permutation, true, true);
  12747. if ($.isFunction(ts.p.sortable.update)) {
  12748. ts.p.sortable.update(permutation);
  12749. }
  12750. }
  12751. };
  12752. if (ts.p.sortable.options) {
  12753. $.extend(sortable_opts, ts.p.sortable.options);
  12754. } else if ($.isFunction(ts.p.sortable)) {
  12755. ts.p.sortable = { "update" : ts.p.sortable };
  12756. }
  12757. if (sortable_opts.start) {
  12758. var s = sortable_opts.start;
  12759. sortable_opts.start = function(e,ui) {
  12760. start();
  12761. s.call(this,e,ui);
  12762. };
  12763. } else {
  12764. sortable_opts.start = start;
  12765. }
  12766. if (sortable_opts.stop) {
  12767. var st = sortable_opts.stop;
  12768. sortable_opts.stop = function(e,ui) {
  12769. stop();
  12770. st.call(this,e,ui);
  12771. };
  12772. } else {
  12773. sortable_opts.stop = stop;
  12774. }
  12775. if (ts.p.sortable.exclude) {
  12776. sortable_opts.items += ":not("+ts.p.sortable.exclude+")";
  12777. }
  12778. var $e = tblrow.sortable(sortable_opts), dataObj = $e.data("sortable") || $e.data("uiSortable");
  12779. if (dataObj != null) {
  12780. dataObj.data("sortable").floating = true;
  12781. }
  12782. });
  12783. },
  12784. columnChooser : function(opts) {
  12785. var self = this, selector, select, colMap = {}, fixedCols = [], dopts, mopts, $dialogContent, multiselectData, listHeight,
  12786. colModel = self.jqGrid("getGridParam", "colModel"),
  12787. colNames = self.jqGrid("getGridParam", "colNames"),
  12788. getMultiselectWidgetData = function ($elem) {
  12789. return ($.ui.multiselect.prototype && $elem.data($.ui.multiselect.prototype.widgetFullName || $.ui.multiselect.prototype.widgetName)) ||
  12790. $elem.data("ui-multiselect") || $elem.data("multiselect");
  12791. },
  12792. regional = $.jgrid.getRegional(this[0], 'col');
  12793. if ($("#colchooser_" + $.jgrid.jqID(self[0].p.id)).length) { return; }
  12794. selector = $('<div id="colchooser_'+self[0].p.id+'" style="position:relative;overflow:hidden"><div><select multiple="multiple"></select></div></div>');
  12795. select = $('select', selector);
  12796. function insert(perm,i,v) {
  12797. var a, b;
  12798. if(i>=0){
  12799. a = perm.slice();
  12800. b = a.splice(i,Math.max(perm.length-i,i));
  12801. if(i>perm.length) { i = perm.length; }
  12802. a[i] = v;
  12803. return a.concat(b);
  12804. }
  12805. return perm;
  12806. }
  12807. function call(fn, obj) {
  12808. if (!fn) { return; }
  12809. if (typeof fn === 'string') {
  12810. if ($.fn[fn]) {
  12811. $.fn[fn].apply(obj, $.makeArray(arguments).slice(2));
  12812. }
  12813. } else if ($.isFunction(fn)) {
  12814. fn.apply(obj, $.makeArray(arguments).slice(2));
  12815. }
  12816. }
  12817. function resize_select() {
  12818. var widgetData = getMultiselectWidgetData(select),
  12819. $thisDialogContent = widgetData.container.closest(".ui-dialog-content");
  12820. if ($thisDialogContent.length > 0 && typeof $thisDialogContent[0].style === "object") {
  12821. $thisDialogContent[0].style.width = "";
  12822. } else {
  12823. $thisDialogContent.css("width", ""); // or just remove width style
  12824. }
  12825. widgetData.selectedList.height(Math.max(widgetData.selectedContainer.height() - widgetData.selectedActions.outerHeight() -1, 1));
  12826. widgetData.availableList.height(Math.max(widgetData.availableContainer.height() - widgetData.availableActions.outerHeight() -1, 1));
  12827. }
  12828. opts = $.extend({
  12829. width : 400,
  12830. height : 240,
  12831. classname : null,
  12832. done : function(perm) { if (perm) { self.jqGrid("remapColumns", perm, true); } },
  12833. /* msel is either the name of a ui widget class that
  12834. extends a multiselect, or a function that supports
  12835. creating a multiselect object (with no argument,
  12836. or when passed an object), and destroying it (when
  12837. passed the string "destroy"). */
  12838. msel : "multiselect",
  12839. /* "msel_opts" : {}, */
  12840. /* dlog is either the name of a ui widget class that
  12841. behaves in a dialog-like way, or a function, that
  12842. supports creating a dialog (when passed dlog_opts)
  12843. or destroying a dialog (when passed the string
  12844. "destroy")
  12845. */
  12846. dlog : "dialog",
  12847. dialog_opts : {
  12848. minWidth: 470,
  12849. dialogClass: "ui-jqdialog"
  12850. },
  12851. /* dlog_opts is either an option object to be passed
  12852. to "dlog", or (more likely) a function that creates
  12853. the options object.
  12854. The default produces a suitable options object for
  12855. ui.dialog */
  12856. dlog_opts : function(options) {
  12857. var buttons = {};
  12858. buttons[options.bSubmit] = function() {
  12859. options.apply_perm();
  12860. options.cleanup(false);
  12861. };
  12862. buttons[options.bCancel] = function() {
  12863. options.cleanup(true);
  12864. };
  12865. return $.extend(true, {
  12866. buttons: buttons,
  12867. close: function() {
  12868. options.cleanup(true);
  12869. },
  12870. modal: options.modal || false,
  12871. resizable: options.resizable || true,
  12872. width: options.width + 70,
  12873. resize: resize_select
  12874. }, options.dialog_opts || {});
  12875. },
  12876. /* Function to get the permutation array, and pass it to the
  12877. "done" function */
  12878. apply_perm : function() {
  12879. var perm = [];
  12880. $('option',select).each(function() {
  12881. if ($(this).is(":selected")) {
  12882. self.jqGrid("showCol", colModel[this.value].name);
  12883. } else {
  12884. self.jqGrid("hideCol", colModel[this.value].name);
  12885. }
  12886. });
  12887. //fixedCols.slice(0);
  12888. $('option[selected]',select).each(function() { perm.push(parseInt(this.value,10)); });
  12889. $.each(perm, function() { delete colMap[colModel[parseInt(this,10)].name]; });
  12890. $.each(colMap, function() {
  12891. var ti = parseInt(this,10);
  12892. perm = insert(perm,ti,ti);
  12893. });
  12894. if (opts.done) {
  12895. opts.done.call(self, perm);
  12896. }
  12897. self.jqGrid("setGridWidth", self[0].p.width, self[0].p.shrinkToFit);
  12898. },
  12899. /* Function to cleanup the dialog, and select. Also calls the
  12900. done function with no permutation (to indicate that the
  12901. columnChooser was aborted */
  12902. cleanup : function(calldone) {
  12903. call(opts.dlog, selector, 'destroy');
  12904. call(opts.msel, select, 'destroy');
  12905. selector.remove();
  12906. if (calldone && opts.done) {
  12907. opts.done.call(self);
  12908. }
  12909. },
  12910. msel_opts : {}
  12911. }, regional, opts || {} );
  12912. if($.ui) {
  12913. if ($.ui.multiselect && $.ui.multiselect.defaults) {
  12914. if (!$.jgrid._multiselect) {
  12915. // should be in language file
  12916. alert("Multiselect plugin loaded after jqGrid. Please load the plugin before the jqGrid!");
  12917. return;
  12918. }
  12919. // ??? the next line uses $.ui.multiselect.defaults which will be typically undefined
  12920. opts.msel_opts = $.extend($.ui.multiselect.defaults, opts.msel_opts);
  12921. }
  12922. }
  12923. if (opts.caption) {
  12924. selector.attr("title", opts.caption);
  12925. }
  12926. if (opts.classname) {
  12927. selector.addClass(opts.classname);
  12928. select.addClass(opts.classname);
  12929. }
  12930. if (opts.width) {
  12931. $(">div",selector).css({width: opts.width,margin:"0 auto"});
  12932. select.css("width", opts.width);
  12933. }
  12934. if (opts.height) {
  12935. $(">div",selector).css("height", opts.height);
  12936. select.css("height", opts.height - 10);
  12937. }
  12938. select.empty();
  12939. $.each(colModel, function(i) {
  12940. colMap[this.name] = i;
  12941. if (this.hidedlg) {
  12942. if (!this.hidden) {
  12943. fixedCols.push(i);
  12944. }
  12945. return;
  12946. }
  12947. select.append("<option value='"+i+"' "+
  12948. (this.hidden?"":"selected='selected'")+">"+$.jgrid.stripHtml(colNames[i])+"</option>");
  12949. });
  12950. dopts = $.isFunction(opts.dlog_opts) ? opts.dlog_opts.call(self, opts) : opts.dlog_opts;
  12951. call(opts.dlog, selector, dopts);
  12952. mopts = $.isFunction(opts.msel_opts) ? opts.msel_opts.call(self, opts) : opts.msel_opts;
  12953. call(opts.msel, select, mopts);
  12954. // fix height of elements of the multiselect widget
  12955. $dialogContent = $("#colchooser_" + $.jgrid.jqID(self[0].p.id));
  12956. $dialogContent.css({ margin: "auto" });
  12957. $dialogContent.find(">div").css({ width: "100%", height: "100%", margin: "auto" });
  12958. multiselectData = getMultiselectWidgetData(select);
  12959. multiselectData.container.css({ width: "100%", height: "100%", margin: "auto" });
  12960. multiselectData.selectedContainer.css({ width: multiselectData.options.dividerLocation * 100 + "%", height: "100%", margin: "auto", boxSizing: "border-box" });
  12961. multiselectData.availableContainer.css({ width: (100 - multiselectData.options.dividerLocation * 100) + "%", height: "100%", margin: "auto", boxSizing: "border-box" });
  12962. // set height for both selectedList and availableList
  12963. multiselectData.selectedList.css("height", "auto");
  12964. multiselectData.availableList.css("height", "auto");
  12965. listHeight = Math.max(multiselectData.selectedList.height(), multiselectData.availableList.height());
  12966. listHeight = Math.min(listHeight, $(window).height());
  12967. multiselectData.selectedList.css("height", listHeight);
  12968. multiselectData.availableList.css("height", listHeight);
  12969. resize_select();
  12970. },
  12971. sortableRows : function (opts) {
  12972. // Can accept all sortable options and events
  12973. return this.each(function(){
  12974. var $t = this;
  12975. if(!$t.grid) { return; }
  12976. // Currently we disable a treeGrid sortable
  12977. if($t.p.treeGrid) { return; }
  12978. if($.fn.sortable) {
  12979. opts = $.extend({
  12980. "cursor":"move",
  12981. "axis" : "y",
  12982. "items": " > .jqgrow"
  12983. },
  12984. opts || {});
  12985. if(opts.start && $.isFunction(opts.start)) {
  12986. opts._start_ = opts.start;
  12987. delete opts.start;
  12988. } else {opts._start_=false;}
  12989. if(opts.update && $.isFunction(opts.update)) {
  12990. opts._update_ = opts.update;
  12991. delete opts.update;
  12992. } else {opts._update_ = false;}
  12993. opts.start = function(ev,ui) {
  12994. $(ui.item).css("border-width","0");
  12995. $("td",ui.item).each(function(i){
  12996. this.style.width = $t.grid.cols[i].style.width;
  12997. });
  12998. if($t.p.subGrid) {
  12999. var subgid = $(ui.item).attr("id");
  13000. try {
  13001. $($t).jqGrid('collapseSubGridRow',subgid);
  13002. } catch (e) {}
  13003. }
  13004. if(opts._start_) {
  13005. opts._start_.apply(this,[ev,ui]);
  13006. }
  13007. };
  13008. opts.update = function (ev,ui) {
  13009. $(ui.item).css("border-width","");
  13010. if($t.p.rownumbers === true) {
  13011. $("td.jqgrid-rownum",$t.rows).each(function( i ){
  13012. $(this).html( i+1+(parseInt($t.p.page,10)-1)*parseInt($t.p.rowNum,10) );
  13013. });
  13014. }
  13015. if(opts._update_) {
  13016. opts._update_.apply(this,[ev,ui]);
  13017. }
  13018. };
  13019. $("tbody:first",$t).sortable(opts);
  13020. $("tbody:first > .jqgrow",$t).disableSelection();
  13021. }
  13022. });
  13023. },
  13024. gridDnD : function(opts) {
  13025. return this.each(function(){
  13026. var $t = this, i, cn;
  13027. if(!$t.grid) { return; }
  13028. // Currently we disable a treeGrid drag and drop
  13029. if($t.p.treeGrid) { return; }
  13030. if(!$.fn.draggable || !$.fn.droppable) { return; }
  13031. function updateDnD ()
  13032. {
  13033. var datadnd = $.data($t,"dnd");
  13034. $("tr.jqgrow:not(.ui-draggable)",$t).draggable($.isFunction(datadnd.drag) ? datadnd.drag.call($($t),datadnd) : datadnd.drag);
  13035. }
  13036. var appender = "<table id='jqgrid_dnd' class='ui-jqgrid-dnd'></table>";
  13037. if($("#jqgrid_dnd")[0] === undefined) {
  13038. $('body').append(appender);
  13039. }
  13040. if(typeof opts === 'string' && opts === 'updateDnD' && $t.p.jqgdnd===true) {
  13041. updateDnD();
  13042. return;
  13043. }
  13044. var tid;
  13045. opts = $.extend({
  13046. "drag" : function (opts) {
  13047. return $.extend({
  13048. start : function (ev, ui) {
  13049. var i, subgid;
  13050. // if we are in subgrid mode try to collapse the node
  13051. if($t.p.subGrid) {
  13052. subgid = $(ui.helper).attr("id");
  13053. try {
  13054. $($t).jqGrid('collapseSubGridRow',subgid);
  13055. } catch (e) {}
  13056. }
  13057. // hack
  13058. // drag and drop does not insert tr in table, when the table has no rows
  13059. // we try to insert new empty row on the target(s)
  13060. for (i=0;i<$.data($t,"dnd").connectWith.length;i++){
  13061. if($($.data($t,"dnd").connectWith[i]).jqGrid('getGridParam','reccount') === 0 ){
  13062. $($.data($t,"dnd").connectWith[i]).jqGrid('addRowData','jqg_empty_row',{});
  13063. }
  13064. }
  13065. ui.helper.addClass("ui-state-highlight");
  13066. $("td",ui.helper).each(function(i) {
  13067. this.style.width = $t.grid.headers[i].width+"px";
  13068. });
  13069. if(opts.onstart && $.isFunction(opts.onstart) ) { opts.onstart.call($($t),ev,ui); }
  13070. },
  13071. stop :function(ev,ui) {
  13072. var i, ids;
  13073. if(ui.helper.dropped && !opts.dragcopy) {
  13074. ids = $(ui.helper).attr("id");
  13075. if(ids === undefined) { ids = $(this).attr("id"); }
  13076. $($t).jqGrid('delRowData',ids );
  13077. }
  13078. // if we have a empty row inserted from start event try to delete it
  13079. for (i=0;i<$.data($t,"dnd").connectWith.length;i++){
  13080. $($.data($t,"dnd").connectWith[i]).jqGrid('delRowData','jqg_empty_row');
  13081. }
  13082. if(opts.onstop && $.isFunction(opts.onstop) ) { opts.onstop.call($($t),ev,ui); }
  13083. }
  13084. },opts.drag_opts || {});
  13085. },
  13086. "drop" : function (opts) {
  13087. return $.extend({
  13088. accept: function(d) {
  13089. if (!$(d).hasClass('jqgrow')) { return d;}
  13090. tid = $(d).closest("table.ui-jqgrid-btable");
  13091. if(tid.length > 0 && $.data(tid[0],"dnd") !== undefined) {
  13092. var cn = $.data(tid[0],"dnd").connectWith;
  13093. return $.inArray('#'+$.jgrid.jqID(this.id),cn) !== -1 ? true : false;
  13094. }
  13095. return false;
  13096. },
  13097. drop: function(ev, ui) {
  13098. if (!$(ui.draggable).hasClass('jqgrow')) { return; }
  13099. var accept = $(ui.draggable).attr("id");
  13100. var getdata = ui.draggable.parent().parent().jqGrid('getRowData',accept);
  13101. if(!opts.dropbyname) {
  13102. var j =0, tmpdata = {}, nm, key;
  13103. var dropmodel = $("#"+$.jgrid.jqID(this.id)).jqGrid('getGridParam','colModel');
  13104. try {
  13105. for (key in getdata) {
  13106. if (getdata.hasOwnProperty(key)) {
  13107. nm = dropmodel[j].name;
  13108. if( !(nm === 'cb' || nm === 'rn' || nm === 'subgrid' )) {
  13109. if(getdata.hasOwnProperty(key) && dropmodel[j]) {
  13110. tmpdata[nm] = getdata[key];
  13111. }
  13112. }
  13113. j++;
  13114. }
  13115. }
  13116. getdata = tmpdata;
  13117. } catch (e) {}
  13118. }
  13119. ui.helper.dropped = true;
  13120. if($.data(tid[0],"dnd").beforedrop && $.isFunction($.data(tid[0],"dnd").beforedrop) ) {
  13121. //parameters to this callback - event, element, data to be inserted, sender, reciever
  13122. // should return object which will be inserted into the reciever
  13123. var datatoinsert = $.data(tid[0],"dnd").beforedrop.call(this,ev,ui,getdata,$(tid[0]),$(this));
  13124. if (datatoinsert !== undefined && datatoinsert !== null && typeof datatoinsert === "object") { getdata = datatoinsert; }
  13125. }
  13126. if(ui.helper.dropped) {
  13127. var grid;
  13128. if(opts.autoid) {
  13129. if($.isFunction(opts.autoid)) {
  13130. grid = opts.autoid.call(this,getdata);
  13131. } else {
  13132. grid = Math.ceil(Math.random()*1000);
  13133. grid = opts.autoidprefix+grid;
  13134. }
  13135. }
  13136. // NULL is interpreted as undefined while null as object
  13137. $("#"+$.jgrid.jqID(this.id)).jqGrid('addRowData',grid,getdata,opts.droppos);
  13138. }
  13139. if(opts.ondrop && $.isFunction(opts.ondrop) ) { opts.ondrop.call(this,ev,ui, getdata); }
  13140. }}, opts.drop_opts || {});
  13141. },
  13142. "onstart" : null,
  13143. "onstop" : null,
  13144. "beforedrop": null,
  13145. "ondrop" : null,
  13146. "drop_opts" : {
  13147. "activeClass": "ui-state-active",
  13148. "hoverClass": "ui-state-hover"
  13149. },
  13150. "drag_opts" : {
  13151. "revert": "invalid",
  13152. "helper": "clone",
  13153. "cursor": "move",
  13154. "appendTo" : "#jqgrid_dnd",
  13155. "zIndex": 5000
  13156. },
  13157. "dragcopy": false,
  13158. "dropbyname" : false,
  13159. "droppos" : "first",
  13160. "autoid" : true,
  13161. "autoidprefix" : "dnd_"
  13162. }, opts || {});
  13163. if(!opts.connectWith) { return; }
  13164. opts.connectWith = opts.connectWith.split(",");
  13165. opts.connectWith = $.map(opts.connectWith,function(n){return $.trim(n);});
  13166. $.data($t,"dnd",opts);
  13167. if($t.p.reccount !== 0 && !$t.p.jqgdnd) {
  13168. updateDnD();
  13169. }
  13170. $t.p.jqgdnd = true;
  13171. for (i=0;i<opts.connectWith.length;i++){
  13172. cn =opts.connectWith[i];
  13173. $(cn).droppable($.isFunction(opts.drop) ? opts.drop.call($($t),opts) : opts.drop);
  13174. }
  13175. });
  13176. },
  13177. gridResize : function(opts) {
  13178. return this.each(function(){
  13179. var $t = this, gID = $.jgrid.jqID($t.p.id), req;
  13180. if(!$t.grid || !$.fn.resizable) { return; }
  13181. opts = $.extend({}, opts || {});
  13182. if(opts.alsoResize ) {
  13183. opts._alsoResize_ = opts.alsoResize;
  13184. delete opts.alsoResize;
  13185. } else {
  13186. opts._alsoResize_ = false;
  13187. }
  13188. if(opts.stop && $.isFunction(opts.stop)) {
  13189. opts._stop_ = opts.stop;
  13190. delete opts.stop;
  13191. } else {
  13192. opts._stop_ = false;
  13193. }
  13194. opts.stop = function (ev, ui) {
  13195. $($t).jqGrid('setGridParam',{height:$("#gview_"+gID+" .ui-jqgrid-bdiv").height()});
  13196. $($t).jqGrid('setGridWidth',ui.size.width,opts.shrinkToFit);
  13197. if(opts._stop_) { opts._stop_.call($t,ev,ui); }
  13198. if($t.p.caption) {
  13199. $("#gbox_"+ gID).css({ 'height': 'auto' });
  13200. }
  13201. if($t.p.frozenColumns) {
  13202. if (req ) clearTimeout(req);
  13203. req = setTimeout(function(){
  13204. if (req ) clearTimeout(req);
  13205. $("#" + gID).jqGrid("destroyFrozenColumns");
  13206. $("#" + gID).jqGrid("setFrozenColumns");
  13207. });
  13208. }
  13209. };
  13210. if(opts._alsoResize_) {
  13211. var optstest = "{\'#gview_"+gID+" .ui-jqgrid-bdiv\':true,'" +opts._alsoResize_+"':true}";
  13212. opts.alsoResize = eval('('+optstest+')'); // the only way that I found to do this
  13213. } else {
  13214. opts.alsoResize = $(".ui-jqgrid-bdiv","#gview_"+gID);
  13215. }
  13216. delete opts._alsoResize_;
  13217. $("#gbox_"+gID).resizable(opts);
  13218. });
  13219. }
  13220. });
  13221. //module begin
  13222. function _pivotfilter (fn, context) {
  13223. /*jshint validthis: true */
  13224. var i,
  13225. value,
  13226. result = [],
  13227. length;
  13228. if (!this || typeof fn !== 'function' || (fn instanceof RegExp)) {
  13229. throw new TypeError();
  13230. }
  13231. length = this.length;
  13232. for (i = 0; i < length; i++) {
  13233. if (this.hasOwnProperty(i)) {
  13234. value = this[i];
  13235. if (fn.call(context, value, i, this)) {
  13236. result.push(value);
  13237. // We need break in order to cancel loop
  13238. // in case the row is found
  13239. break;
  13240. }
  13241. }
  13242. }
  13243. return result;
  13244. }
  13245. $.assocArraySize = function(obj) {
  13246. // http://stackoverflow.com/a/6700/11236
  13247. var size = 0, key;
  13248. for (key in obj) {
  13249. if (obj.hasOwnProperty(key)) {
  13250. size++;
  13251. }
  13252. }
  13253. return size;
  13254. };
  13255. $.jgrid.extend({
  13256. pivotSetup : function( data, options ){
  13257. // data should come in json format
  13258. // The function return the new colModel and the transformed data
  13259. // again with group setup options which then will be passed to the grid
  13260. var columns =[],
  13261. pivotrows =[],
  13262. summaries = [],
  13263. member=[],
  13264. labels=[],
  13265. groupOptions = {
  13266. grouping : true,
  13267. groupingView : {
  13268. groupField : [],
  13269. groupSummary: [],
  13270. groupSummaryPos:[]
  13271. }
  13272. },
  13273. headers = [],
  13274. o = $.extend ( {
  13275. rowTotals : false,
  13276. rowTotalsText : 'Total',
  13277. // summary columns
  13278. colTotals : false,
  13279. groupSummary : true,
  13280. groupSummaryPos : 'header',
  13281. frozenStaticCols : false
  13282. }, options || {});
  13283. this.each(function(){
  13284. var
  13285. $t = this,
  13286. row,
  13287. rowindex,
  13288. i,
  13289. rowlen = data.length,
  13290. xlen, ylen, aggrlen,
  13291. tmp,
  13292. newObj,
  13293. r=0;
  13294. // utility funcs
  13295. /*
  13296. * Filter the data to a given criteria. Return the firt occurance
  13297. */
  13298. function find(ar, fun, extra) {
  13299. var res;
  13300. res = _pivotfilter.call(ar, fun, extra);
  13301. return res.length > 0 ? res[0] : null;
  13302. }
  13303. /*
  13304. * Check if the grouped row column exist (See find)
  13305. * If the row is not find in pivot rows retun null,
  13306. * otherviese the column
  13307. */
  13308. function findGroup(item, index) {
  13309. /*jshint validthis: true */
  13310. var j = 0, ret = true, i;
  13311. for(i in item) {
  13312. if( item.hasOwnProperty(i) ) {
  13313. if(item[i] != this[j]) {
  13314. ret = false;
  13315. break;
  13316. }
  13317. j++;
  13318. if(j>=this.length) {
  13319. break;
  13320. }
  13321. }
  13322. }
  13323. if(ret) {
  13324. rowindex = index;
  13325. }
  13326. return ret;
  13327. }
  13328. /*
  13329. * Perform calculations of the pivot values.
  13330. */
  13331. function calculation(oper, v, field, rc, _cnt) {
  13332. var ret;
  13333. if( $.isFunction(oper)) {
  13334. ret = oper.call($t, v, field, rc);
  13335. } else {
  13336. switch (oper) {
  13337. case "sum" :
  13338. ret = parseFloat(v||0) + parseFloat((rc[field]||0));
  13339. break;
  13340. case "count" :
  13341. if(v==="" || v == null) {
  13342. v=0;
  13343. }
  13344. if(rc.hasOwnProperty(field)) {
  13345. ret = v+1;
  13346. } else {
  13347. ret = 0;
  13348. }
  13349. break;
  13350. case "min" :
  13351. if(v==="" || v == null) {
  13352. ret = parseFloat(rc[field]||0);
  13353. } else {
  13354. ret =Math.min(parseFloat(v),parseFloat(rc[field]||0));
  13355. }
  13356. break;
  13357. case "max" :
  13358. if(v==="" || v == null) {
  13359. ret = parseFloat(rc[field]||0);
  13360. } else {
  13361. ret = Math.max(parseFloat(v),parseFloat(rc[field]||0));
  13362. }
  13363. break;
  13364. case "avg" : //avg grouping
  13365. ret = (parseFloat(v||0) * (_cnt -1) + parseFloat(rc[field]||0) ) /_cnt;
  13366. break;
  13367. }
  13368. }
  13369. return ret;
  13370. }
  13371. /*
  13372. * The function agragates the values of the pivot grid.
  13373. * Return the current row with pivot summary values
  13374. */
  13375. function agregateFunc ( row, aggr, value, curr) {
  13376. // default is sum
  13377. var arrln = aggr.length, i, label, j, jv, mainval="",swapvals=[], swapstr, _cntavg = 1, lbl;
  13378. if($.isArray(value)) {
  13379. jv = value.length;
  13380. swapvals = value;
  13381. } else {
  13382. jv = 1;
  13383. swapvals[0]=value;
  13384. }
  13385. member = [];
  13386. labels = [];
  13387. member.root = 0;
  13388. for(j=0;j<jv;j++) {
  13389. var tmpmember = [], vl;
  13390. for(i=0; i < arrln; i++) {
  13391. swapstr = typeof aggr[i].aggregator === 'string' ? aggr[i].aggregator : 'cust';
  13392. if(value == null) {
  13393. label = $.trim(aggr[i].member)+"_" + swapstr;
  13394. vl = label;
  13395. swapvals[0]= aggr[i].label || (swapstr + " " +$.trim(aggr[i].member));
  13396. } else {
  13397. vl = value[j].replace(/\s+/g, '');
  13398. try {
  13399. label = (arrln === 1 ? mainval + vl : mainval + vl + "_" + swapstr + "_" + String(i));
  13400. } catch(e) {}
  13401. swapvals[j] = value[j];
  13402. }
  13403. //if(j<=1 && vl !== '_r_Totals' && mainval === "") { // this does not fix full the problem
  13404. //mainval = vl;
  13405. //}
  13406. label = !isNaN(parseInt(label,10)) ? label + " " : label;
  13407. if(aggr[i].aggregator === 'avg') {
  13408. lbl = rowindex === -1 ? pivotrows.length+"_"+label : rowindex+"_"+label;
  13409. if(!_avg[lbl]) {
  13410. _avg[lbl] = 1;
  13411. } else {
  13412. _avg[lbl]++;
  13413. }
  13414. _cntavg = _avg[lbl];
  13415. }
  13416. curr[label] = tmpmember[label] = calculation( aggr[i].aggregator, curr[label], aggr[i].member, row, _cntavg);
  13417. }
  13418. mainval += (value && value[j] != null) ? value[j].replace(/\s+/g, '') : '';
  13419. //vl = !isNaN(parseInt(vl,10)) ? vl + " " : vl;
  13420. member[label] = tmpmember;
  13421. labels[label] = swapvals[j];
  13422. }
  13423. return curr;
  13424. }
  13425. // Making the row totals without to add in yDimension
  13426. if(o.rowTotals && o.yDimension.length > 0) {
  13427. var dn = o.yDimension[0].dataName;
  13428. o.yDimension.splice(0,0,{dataName:dn});
  13429. o.yDimension[0].converter = function(){ return '_r_Totals'; };
  13430. }
  13431. // build initial columns (colModel) from xDimension
  13432. xlen = $.isArray(o.xDimension) ? o.xDimension.length : 0;
  13433. ylen = o.yDimension.length;
  13434. aggrlen = $.isArray(o.aggregates) ? o.aggregates.length : 0;
  13435. if(xlen === 0 || aggrlen === 0) {
  13436. throw("xDimension or aggregates optiona are not set!");
  13437. }
  13438. var colc;
  13439. for(i = 0; i< xlen; i++) {
  13440. colc = {name:o.xDimension[i].dataName, frozen: o.frozenStaticCols};
  13441. if(o.xDimension[i].isGroupField == null) {
  13442. o.xDimension[i].isGroupField = true;
  13443. }
  13444. colc = $.extend(true, colc, o.xDimension[i]);
  13445. columns.push( colc );
  13446. }
  13447. var groupfields = xlen - 1, tree={}, _avg=[];
  13448. //tree = { text: 'root', leaf: false, children: [] };
  13449. //loop over alll the source data
  13450. while( r < rowlen ) {
  13451. row = data[r];
  13452. var xValue = [];
  13453. var yValue = [];
  13454. tmp = {};
  13455. i = 0;
  13456. // build the data from xDimension
  13457. do {
  13458. xValue[i] = $.trim(row[o.xDimension[i].dataName]);
  13459. tmp[o.xDimension[i].dataName] = xValue[i];
  13460. i++;
  13461. } while( i < xlen );
  13462. var k = 0;
  13463. rowindex = -1;
  13464. // check to see if the row is in our new pivotrow set
  13465. newObj = find(pivotrows, findGroup, xValue);
  13466. if(!newObj) {
  13467. // if the row is not in our set
  13468. k = 0;
  13469. // if yDimension is set
  13470. if(ylen>=1) {
  13471. // build the cols set in yDimension
  13472. for(k=0;k<ylen;k++) {
  13473. yValue[k] = $.trim(row[o.yDimension[k].dataName]);
  13474. // Check to see if we have user defined conditions
  13475. if(o.yDimension[k].converter && $.isFunction(o.yDimension[k].converter)) {
  13476. yValue[k] = o.yDimension[k].converter.call(this, yValue[k], xValue, yValue);
  13477. }
  13478. }
  13479. // make the colums based on aggregates definition
  13480. // and return the members for late calculation
  13481. tmp = agregateFunc( row, o.aggregates, yValue, tmp );
  13482. } else if( ylen === 0 ) {
  13483. // if not set use direct the aggregates
  13484. tmp = agregateFunc( row, o.aggregates, null, tmp );
  13485. }
  13486. // add the result in pivot rows
  13487. pivotrows.push( tmp );
  13488. } else {
  13489. // the pivot exists
  13490. if( rowindex >= 0) {
  13491. k = 0;
  13492. // make the recalculations
  13493. if(ylen>=1) {
  13494. for(k=0;k<ylen;k++) {
  13495. yValue[k] = $.trim(row[o.yDimension[k].dataName]);
  13496. if(o.yDimension[k].converter && $.isFunction(o.yDimension[k].converter)) {
  13497. yValue[k] = o.yDimension[k].converter.call(this, yValue[k], xValue, yValue);
  13498. }
  13499. }
  13500. newObj = agregateFunc( row, o.aggregates, yValue, newObj );
  13501. } else if( ylen === 0 ) {
  13502. newObj = agregateFunc( row, o.aggregates, null, newObj );
  13503. }
  13504. // update the row
  13505. pivotrows[rowindex] = newObj;
  13506. }
  13507. }
  13508. var kj=0, current = null,existing = null, kk;
  13509. // Build a JSON tree from the member (see aggregateFunc)
  13510. // to make later the columns
  13511. //
  13512. for (kk in member) {
  13513. if(member.hasOwnProperty( kk )) {
  13514. if(kj === 0) {
  13515. if (!tree.children||tree.children === undefined){
  13516. tree = { text: kk, level : 0, children: [], label: kk };
  13517. }
  13518. current = tree.children;
  13519. } else {
  13520. existing = null;
  13521. for (i=0; i < current.length; i++) {
  13522. if (current[i].text === kk) {
  13523. //current[i].fields=member[kk];
  13524. existing = current[i];
  13525. break;
  13526. }
  13527. }
  13528. if (existing) {
  13529. current = existing.children;
  13530. } else {
  13531. current.push({ children: [], text: kk, level: kj, fields: member[kk], label: labels[kk] });
  13532. current = current[current.length - 1].children;
  13533. }
  13534. }
  13535. kj++;
  13536. }
  13537. }
  13538. r++;
  13539. }
  13540. _avg = null; // free mem
  13541. var lastval=[], initColLen = columns.length, swaplen = initColLen;
  13542. if(ylen>0) {
  13543. headers[ylen-1] = { useColSpanStyle: false, groupHeaders: []};
  13544. }
  13545. /*
  13546. * Recursive function which uses the tree to build the
  13547. * columns from the pivot values and set the group Headers
  13548. */
  13549. function list(items) {
  13550. var l, j, key, k, col;
  13551. for (key in items) { // iterate
  13552. if (items.hasOwnProperty(key)) {
  13553. // write amount of spaces according to level
  13554. // and write name and newline
  13555. if(typeof items[key] !== "object") {
  13556. // If not a object build the header of the appropriate level
  13557. if( key === 'level') {
  13558. if(lastval[items.level] === undefined) {
  13559. lastval[items.level] ='';
  13560. if(items.level>0 && items.text.indexOf('_r_Totals') === -1) {
  13561. headers[items.level-1] = {
  13562. useColSpanStyle: false,
  13563. groupHeaders: []
  13564. };
  13565. }
  13566. }
  13567. if(lastval[items.level] !== items.text && items.children.length && items.text.indexOf('_r_Totals') === -1 ) {
  13568. if(items.level>0) {
  13569. headers[items.level-1].groupHeaders.push({
  13570. titleText: items.label,
  13571. numberOfColumns : 0
  13572. });
  13573. var collen = headers[items.level-1].groupHeaders.length-1,
  13574. colpos = collen === 0 ? swaplen : initColLen;//+aggrlen;
  13575. if(items.level-1=== (o.rowTotals ? 1 : 0)) {
  13576. if(collen>0) {
  13577. var l1=0;
  13578. for(var kk=0; kk<collen; kk++) {
  13579. l1 += headers[items.level-1].groupHeaders[kk].numberOfColumns;
  13580. }
  13581. if(l1) {
  13582. colpos = l1 + xlen;
  13583. }
  13584. }
  13585. }
  13586. if(columns[colpos]) {
  13587. headers[items.level-1].groupHeaders[collen].startColumnName = columns[colpos].name;
  13588. headers[items.level-1].groupHeaders[collen].numberOfColumns = columns.length - colpos;
  13589. }
  13590. initColLen = columns.length;
  13591. }
  13592. }
  13593. lastval[items.level] = items.text;
  13594. }
  13595. // This is in case when the member contain more than one summary item
  13596. if(items.level === ylen && key==='level' && ylen >0) {
  13597. if( aggrlen > 1){
  13598. var ll=1;
  13599. for( l in items.fields) {
  13600. if(items.fields.hasOwnProperty(l)) {
  13601. if(ll===1) {
  13602. headers[ylen-1].groupHeaders.push({startColumnName: l, numberOfColumns: 1, titleText: items.label || items.text});
  13603. }
  13604. ll++;
  13605. }
  13606. }
  13607. headers[ylen-1].groupHeaders[headers[ylen-1].groupHeaders.length-1].numberOfColumns = ll-1;
  13608. } else {
  13609. headers.splice(ylen-1,1);
  13610. }
  13611. }
  13612. }
  13613. // if object, call recursively
  13614. if (items[key] != null && typeof items[key] === "object") {
  13615. list(items[key]);
  13616. }
  13617. // Finally build the columns
  13618. if( key === 'level') {
  13619. if( items.level > 0 && (items.level === (ylen===0?items.level:ylen) || lastval[items.level].indexOf('_r_Totals') !== -1 ) ){
  13620. j=0;
  13621. for(l in items.fields) {
  13622. if(items.fields.hasOwnProperty( l ) ) {
  13623. col = {};
  13624. for(k in o.aggregates[j]) {
  13625. if(o.aggregates[j].hasOwnProperty(k)) {
  13626. switch( k ) {
  13627. case 'member':
  13628. case 'label':
  13629. case 'aggregator':
  13630. break;
  13631. default:
  13632. col[k] = o.aggregates[j][k];
  13633. }
  13634. }
  13635. }
  13636. if(aggrlen > 1) {
  13637. col.name = l;
  13638. col.label = o.aggregates[j].label || items.label;
  13639. } else {
  13640. col.name = items.text;
  13641. col.label = items.text==='_r_Totals' ? o.rowTotalsText : items.label;
  13642. }
  13643. columns.push (col);
  13644. j++;
  13645. }
  13646. }
  13647. }
  13648. }
  13649. }
  13650. }
  13651. }
  13652. list( tree );
  13653. var nm;
  13654. // loop again trougth the pivot rows in order to build grand total
  13655. if(o.colTotals) {
  13656. var plen = pivotrows.length;
  13657. while(plen--) {
  13658. for(i=xlen;i<columns.length;i++) {
  13659. nm = columns[i].name;
  13660. if(!summaries[nm]) {
  13661. summaries[nm] = parseFloat(pivotrows[plen][nm] || 0);
  13662. } else {
  13663. summaries[nm] += parseFloat(pivotrows[plen][nm] || 0);
  13664. }
  13665. }
  13666. }
  13667. }
  13668. // based on xDimension levels build grouping
  13669. if( groupfields > 0) {
  13670. for(i=0;i<groupfields;i++) {
  13671. if(columns[i].isGroupField) {
  13672. groupOptions.groupingView.groupField.push(columns[i].name);
  13673. groupOptions.groupingView.groupSummary.push(o.groupSummary);
  13674. groupOptions.groupingView.groupSummaryPos.push(o.groupSummaryPos);
  13675. }
  13676. }
  13677. } else {
  13678. // no grouping is needed
  13679. groupOptions.grouping = false;
  13680. }
  13681. groupOptions.sortname = columns[groupfields].name;
  13682. groupOptions.groupingView.hideFirstGroupCol = true;
  13683. });
  13684. // return the final result.
  13685. return { "colModel" : columns, "rows": pivotrows, "groupOptions" : groupOptions, "groupHeaders" : headers, summary : summaries };
  13686. },
  13687. jqPivot : function( data, pivotOpt, gridOpt, ajaxOpt) {
  13688. return this.each(function(){
  13689. var $t = this;
  13690. function pivot( data) {
  13691. if(!$.isArray(data)) {
  13692. throw "data provides is not an array";
  13693. }
  13694. var pivotGrid = jQuery($t).jqGrid('pivotSetup',data, pivotOpt),
  13695. footerrow = $.assocArraySize(pivotGrid.summary) > 0 ? true : false,
  13696. query= $.jgrid.from.call($t, pivotGrid.rows), i, so, st, len;
  13697. if(pivotOpt.ignoreCase) {
  13698. query = query.ignoreCase();
  13699. }
  13700. for(i=0; i< pivotGrid.groupOptions.groupingView.groupField.length; i++) {
  13701. so = pivotOpt.xDimension[i].sortorder ? pivotOpt.xDimension[i].sortorder : 'asc';
  13702. st = pivotOpt.xDimension[i].sorttype ? pivotOpt.xDimension[i].sorttype : 'text';
  13703. query.orderBy(pivotGrid.groupOptions.groupingView.groupField[i], so, st, '', st);
  13704. }
  13705. len = pivotOpt.xDimension.length;
  13706. if(gridOpt.sortname) { // should be a part of xDimension
  13707. so = gridOpt.sortorder ? gridOpt.sortorder : 'asc';
  13708. st = 'text';
  13709. for( i=0; i< len; i++) {
  13710. if(pivotOpt.xDimension[i].dataName === gridOpt.sortname) {
  13711. st = pivotOpt.xDimension[i].sorttype ? pivotOpt.xDimension[i].sorttype : 'text';
  13712. break;
  13713. }
  13714. }
  13715. query.orderBy(gridOpt.sortname, so, st, '', st);
  13716. } else {
  13717. if(pivotGrid.groupOptions.sortname && len) {
  13718. so = pivotOpt.xDimension[len-1].sortorder ? pivotOpt.xDimension[len-1].sortorder : 'asc';
  13719. st = pivotOpt.xDimension[len-1].sorttype ? pivotOpt.xDimension[len-1].sorttype : 'text';
  13720. query.orderBy(pivotGrid.groupOptions.sortname, so, st, '', st);
  13721. }
  13722. }
  13723. jQuery($t).jqGrid($.extend(true, {
  13724. datastr: $.extend(query.select(),footerrow ? {userdata:pivotGrid.summary} : {}),
  13725. datatype: "jsonstring",
  13726. footerrow : footerrow,
  13727. userDataOnFooter: footerrow,
  13728. colModel: pivotGrid.colModel,
  13729. viewrecords: true,
  13730. sortname: pivotOpt.xDimension[0].dataName // ?????
  13731. }, pivotGrid.groupOptions, gridOpt || {}));
  13732. var gHead = pivotGrid.groupHeaders;
  13733. if(gHead.length) {
  13734. for( i = 0;i < gHead.length ; i++) {
  13735. if(gHead[i] && gHead[i].groupHeaders.length) {
  13736. jQuery($t).jqGrid('setGroupHeaders',gHead[i]);
  13737. }
  13738. }
  13739. }
  13740. if(pivotOpt.frozenStaticCols) {
  13741. jQuery($t).jqGrid("setFrozenColumns");
  13742. }
  13743. }
  13744. if(typeof data === "string") {
  13745. $.ajax($.extend({
  13746. url : data,
  13747. dataType: 'json',
  13748. success : function(response) {
  13749. pivot($.jgrid.getAccessor(response, ajaxOpt && ajaxOpt.reader ? ajaxOpt.reader: 'rows') );
  13750. }
  13751. }, ajaxOpt || {}) );
  13752. } else {
  13753. pivot( data );
  13754. }
  13755. });
  13756. }
  13757. });
  13758. //module begin
  13759. $.jgrid.extend({
  13760. setSubGrid : function () {
  13761. return this.each(function (){
  13762. var $t = this, cm, i,
  13763. classes = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].subgrid,
  13764. suboptions = {
  13765. plusicon : classes.icon_plus,
  13766. minusicon : classes.icon_minus,
  13767. openicon: classes.icon_open,
  13768. expandOnLoad: false,
  13769. selectOnExpand : false,
  13770. selectOnCollapse : false,
  13771. reloadOnExpand : true
  13772. };
  13773. $t.p.subGridOptions = $.extend(suboptions, $t.p.subGridOptions || {});
  13774. $t.p.colNames.unshift("");
  13775. $t.p.colModel.unshift({name:'subgrid',width: $.jgrid.cell_width ? $t.p.subGridWidth+$t.p.cellLayout : $t.p.subGridWidth,sortable: false,resizable:false,hidedlg:true,search:false,fixed:true});
  13776. cm = $t.p.subGridModel;
  13777. if(cm[0]) {
  13778. cm[0].align = $.extend([],cm[0].align || []);
  13779. for(i=0;i<cm[0].name.length;i++) { cm[0].align[i] = cm[0].align[i] || 'left';}
  13780. }
  13781. });
  13782. },
  13783. addSubGridCell :function (pos,iRow) {
  13784. var prp='', ic, sid, icb ;
  13785. this.each(function(){
  13786. prp = this.formatCol(pos,iRow);
  13787. sid= this.p.id;
  13788. ic = this.p.subGridOptions.plusicon;
  13789. icb = $.jgrid.styleUI[(this.p.styleUI || 'jQueryUI')].common;
  13790. });
  13791. return "<td role=\"gridcell\" aria-describedby=\""+sid+"_subgrid\" class=\"ui-sgcollapsed sgcollapsed\" "+prp+"><a style='cursor:pointer;' class='ui-sghref'><span class='" + icb.icon_base +" "+ic+"'></span></a></td>";
  13792. },
  13793. addSubGrid : function( pos, sind ) {
  13794. return this.each(function(){
  13795. var ts = this;
  13796. if (!ts.grid ) { return; }
  13797. var base = $.jgrid.styleUI[(ts.p.styleUI || 'jQueryUI')].base,
  13798. common = $.jgrid.styleUI[(ts.p.styleUI || 'jQueryUI')].common;
  13799. //-------------------------
  13800. var subGridCell = function(trdiv,cell,pos)
  13801. {
  13802. var tddiv = $("<td align='"+ts.p.subGridModel[0].align[pos]+"'></td>").html(cell);
  13803. $(trdiv).append(tddiv);
  13804. };
  13805. var subGridXml = function(sjxml, sbid){
  13806. var tddiv, i, sgmap,
  13807. dummy = $("<table class='" + base.rowTable + " ui-common-table'><tbody></tbody></table>"),
  13808. trdiv = $("<tr></tr>");
  13809. for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
  13810. tddiv = $("<th class='" + base.headerBox+" ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
  13811. $(tddiv).html(ts.p.subGridModel[0].name[i]);
  13812. $(tddiv).width( ts.p.subGridModel[0].width[i]);
  13813. $(trdiv).append(tddiv);
  13814. }
  13815. $(dummy).append(trdiv);
  13816. if (sjxml){
  13817. sgmap = ts.p.xmlReader.subgrid;
  13818. $(sgmap.root+" "+sgmap.row, sjxml).each( function(){
  13819. trdiv = $("<tr class='" + common.content+" ui-subtblcell'></tr>");
  13820. if(sgmap.repeatitems === true) {
  13821. $(sgmap.cell,this).each( function(i) {
  13822. subGridCell(trdiv, $(this).text() || '&#160;',i);
  13823. });
  13824. } else {
  13825. var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
  13826. if (f) {
  13827. for (i=0;i<f.length;i++) {
  13828. subGridCell(trdiv, $(f[i],this).text() || '&#160;',i);
  13829. }
  13830. }
  13831. }
  13832. $(dummy).append(trdiv);
  13833. });
  13834. }
  13835. var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
  13836. $("#"+$.jgrid.jqID(pID+sbid)).append(dummy);
  13837. ts.grid.hDiv.loading = false;
  13838. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  13839. return false;
  13840. };
  13841. var subGridJson = function(sjxml, sbid){
  13842. var tddiv,result,i,cur, sgmap,j,
  13843. dummy = $("<table class='" + base.rowTable + " ui-common-table'><tbody></tbody></table>"),
  13844. trdiv = $("<tr></tr>");
  13845. for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
  13846. tddiv = $("<th class='" + base.headerBox + " ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
  13847. $(tddiv).html(ts.p.subGridModel[0].name[i]);
  13848. $(tddiv).width( ts.p.subGridModel[0].width[i]);
  13849. $(trdiv).append(tddiv);
  13850. }
  13851. $(dummy).append(trdiv);
  13852. if (sjxml){
  13853. sgmap = ts.p.jsonReader.subgrid;
  13854. result = $.jgrid.getAccessor(sjxml, sgmap.root);
  13855. if ( result !== undefined ) {
  13856. for (i=0;i<result.length;i++) {
  13857. cur = result[i];
  13858. trdiv = $("<tr class='" + common.content+" ui-subtblcell'></tr>");
  13859. if(sgmap.repeatitems === true) {
  13860. if(sgmap.cell) { cur=cur[sgmap.cell]; }
  13861. for (j=0;j<cur.length;j++) {
  13862. subGridCell(trdiv, cur[j] || '&#160;',j);
  13863. }
  13864. } else {
  13865. var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
  13866. if(f.length) {
  13867. for (j=0;j<f.length;j++) {
  13868. subGridCell(trdiv, cur[f[j]] || '&#160;',j);
  13869. }
  13870. }
  13871. }
  13872. $(dummy).append(trdiv);
  13873. }
  13874. }
  13875. }
  13876. var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
  13877. $("#"+$.jgrid.jqID(pID+sbid)).append(dummy);
  13878. ts.grid.hDiv.loading = false;
  13879. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  13880. return false;
  13881. };
  13882. var populatesubgrid = function( rd )
  13883. {
  13884. var sid,dp, i, j;
  13885. sid = $(rd).attr("id");
  13886. dp = {nd_: (new Date().getTime())};
  13887. dp[ts.p.prmNames.subgridid]=sid;
  13888. if(!ts.p.subGridModel[0]) { return false; }
  13889. if(ts.p.subGridModel[0].params) {
  13890. for(j=0; j < ts.p.subGridModel[0].params.length; j++) {
  13891. for(i=0; i<ts.p.colModel.length; i++) {
  13892. if(ts.p.colModel[i].name === ts.p.subGridModel[0].params[j]) {
  13893. dp[ts.p.colModel[i].name]= $("td:eq("+i+")",rd).text().replace(/\&#160\;/ig,'');
  13894. }
  13895. }
  13896. }
  13897. }
  13898. if(!ts.grid.hDiv.loading) {
  13899. ts.grid.hDiv.loading = true;
  13900. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  13901. if(!ts.p.subgridtype) { ts.p.subgridtype = ts.p.datatype; }
  13902. if($.isFunction(ts.p.subgridtype)) {
  13903. ts.p.subgridtype.call(ts, dp);
  13904. } else {
  13905. ts.p.subgridtype = ts.p.subgridtype.toLowerCase();
  13906. }
  13907. switch(ts.p.subgridtype) {
  13908. case "xml":
  13909. case "json":
  13910. $.ajax($.extend({
  13911. type:ts.p.mtype,
  13912. url: $.isFunction(ts.p.subGridUrl) ? ts.p.subGridUrl.call(ts, dp) : ts.p.subGridUrl,
  13913. dataType:ts.p.subgridtype,
  13914. data: $.isFunction(ts.p.serializeSubGridData)? ts.p.serializeSubGridData.call(ts, dp) : dp,
  13915. complete: function(sxml) {
  13916. if(ts.p.subgridtype === "xml") {
  13917. subGridXml(sxml.responseXML, sid);
  13918. } else {
  13919. subGridJson($.jgrid.parse(sxml.responseText), sid);
  13920. }
  13921. sxml=null;
  13922. }
  13923. }, $.jgrid.ajaxOptions, ts.p.ajaxSubgridOptions || {}));
  13924. break;
  13925. }
  13926. }
  13927. return false;
  13928. };
  13929. var _id, pID,atd, nhc=0, bfsc, $r;
  13930. $.each(ts.p.colModel,function(){
  13931. if(this.hidden === true || this.name === 'rn' || this.name === 'cb') {
  13932. nhc++;
  13933. }
  13934. });
  13935. var len = ts.rows.length, i=1,hsret, ishsg = $.isFunction(ts.p.isHasSubGrid);
  13936. if( sind !== undefined && sind > 0) {
  13937. i = sind;
  13938. len = sind+1;
  13939. }
  13940. while(i < len) {
  13941. if($(ts.rows[i]).hasClass('jqgrow')) {
  13942. if(ts.p.scroll) {
  13943. $(ts.rows[i].cells[pos]).off('click');
  13944. }
  13945. hsret = null;
  13946. if(ishsg) {
  13947. hsret = ts.p.isHasSubGrid.call(ts, ts.rows[i].id);
  13948. }
  13949. if(hsret === false) {
  13950. ts.rows[i].cells[pos].innerHTML = "";
  13951. } else {
  13952. $(ts.rows[i].cells[pos]).on('click', function() {
  13953. var tr = $(this).parent("tr")[0];
  13954. pID = ts.p.id;
  13955. _id = tr.id;
  13956. $r = $("#" + pID + "_" + _id + "_expandedContent");
  13957. if($(this).hasClass("sgcollapsed")) {
  13958. bfsc = $(ts).triggerHandler("jqGridSubGridBeforeExpand", [pID + "_" + _id, _id]);
  13959. bfsc = (bfsc === false || bfsc === 'stop') ? false : true;
  13960. if(bfsc && $.isFunction(ts.p.subGridBeforeExpand)) {
  13961. bfsc = ts.p.subGridBeforeExpand.call(ts, pID+"_"+_id,_id);
  13962. }
  13963. if(bfsc === false) {return false;}
  13964. if(ts.p.subGridOptions.reloadOnExpand === true || ( ts.p.subGridOptions.reloadOnExpand === false && !$r.hasClass('ui-subgrid') ) ) {
  13965. atd = pos >=1 ? "<td colspan='"+pos+"'>&#160;</td>":"";
  13966. $(tr).after( "<tr role='row' id='" + pID + "_" + _id + "_expandedContent" + "' class='ui-subgrid ui-sg-expanded'>"+atd+"<td class='" + common.content +" subgrid-cell'><span class='" + common.icon_base +" "+ts.p.subGridOptions.openicon+"'></span></td><td colspan='"+parseInt(ts.p.colNames.length-1-nhc,10)+"' class='" + common.content +" subgrid-data'><div id="+pID+"_"+_id+" class='tablediv'></div></td></tr>" );
  13967. $(ts).triggerHandler("jqGridSubGridRowExpanded", [pID + "_" + _id, _id]);
  13968. if( $.isFunction(ts.p.subGridRowExpanded)) {
  13969. ts.p.subGridRowExpanded.call(ts, pID+"_"+ _id,_id);
  13970. } else {
  13971. populatesubgrid(tr);
  13972. }
  13973. } else {
  13974. $r.show().removeClass("ui-sg-collapsed").addClass("ui-sg-expanded");
  13975. }
  13976. $(this).html("<a style='cursor:pointer;' class='ui-sghref'><span class='" + common.icon_base +" "+ts.p.subGridOptions.minusicon+"'></span></a>").removeClass("sgcollapsed").addClass("sgexpanded");
  13977. if(ts.p.subGridOptions.selectOnExpand) {
  13978. $(ts).jqGrid('setSelection',_id);
  13979. }
  13980. } else if($(this).hasClass("sgexpanded")) {
  13981. bfsc = $(ts).triggerHandler("jqGridSubGridRowColapsed", [pID + "_" + _id, _id]);
  13982. bfsc = (bfsc === false || bfsc === 'stop') ? false : true;
  13983. if( bfsc && $.isFunction(ts.p.subGridRowColapsed)) {
  13984. bfsc = ts.p.subGridRowColapsed.call(ts, pID+"_"+_id,_id );
  13985. }
  13986. if(bfsc===false) {return false;}
  13987. if(ts.p.subGridOptions.reloadOnExpand === true) {
  13988. $r.remove(".ui-subgrid");
  13989. } else if($r.hasClass('ui-subgrid')) { // incase of dynamic deleting
  13990. $r.hide().addClass("ui-sg-collapsed").removeClass("ui-sg-expanded");
  13991. }
  13992. $(this).html("<a style='cursor:pointer;' class='ui-sghref'><span class='"+common.icon_base +" "+ts.p.subGridOptions.plusicon+"'></span></a>").removeClass("sgexpanded").addClass("sgcollapsed");
  13993. if(ts.p.subGridOptions.selectOnCollapse) {
  13994. $(ts).jqGrid('setSelection',_id);
  13995. }
  13996. }
  13997. return false;
  13998. });
  13999. }
  14000. }
  14001. i++;
  14002. }
  14003. if(ts.p.subGridOptions.expandOnLoad === true) {
  14004. $(ts.rows).filter('.jqgrow').each(function(index,row){
  14005. $(row.cells[0]).click();
  14006. });
  14007. }
  14008. ts.subGridXml = function(xml,sid) {subGridXml(xml,sid);};
  14009. ts.subGridJson = function(json,sid) {subGridJson(json,sid);};
  14010. });
  14011. },
  14012. expandSubGridRow : function(rowid) {
  14013. return this.each(function () {
  14014. var $t = this;
  14015. if(!$t.grid && !rowid) {return;}
  14016. if($t.p.subGrid===true) {
  14017. var rc = $(this).jqGrid("getInd",rowid,true);
  14018. if(rc) {
  14019. var sgc = $("td.sgcollapsed",rc)[0];
  14020. if(sgc) {
  14021. $(sgc).trigger("click");
  14022. }
  14023. }
  14024. }
  14025. });
  14026. },
  14027. collapseSubGridRow : function(rowid) {
  14028. return this.each(function () {
  14029. var $t = this;
  14030. if(!$t.grid && !rowid) {return;}
  14031. if($t.p.subGrid===true) {
  14032. var rc = $(this).jqGrid("getInd",rowid,true);
  14033. if(rc) {
  14034. var sgc = $("td.sgexpanded",rc)[0];
  14035. if(sgc) {
  14036. $(sgc).trigger("click");
  14037. }
  14038. }
  14039. }
  14040. });
  14041. },
  14042. toggleSubGridRow : function(rowid) {
  14043. return this.each(function () {
  14044. var $t = this;
  14045. if(!$t.grid && !rowid) {return;}
  14046. if($t.p.subGrid===true) {
  14047. var rc = $(this).jqGrid("getInd",rowid,true);
  14048. if(rc) {
  14049. var sgc = $("td.sgcollapsed",rc)[0];
  14050. if(sgc) {
  14051. $(sgc).trigger("click");
  14052. } else {
  14053. sgc = $("td.sgexpanded",rc)[0];
  14054. if(sgc) {
  14055. $(sgc).trigger("click");
  14056. }
  14057. }
  14058. }
  14059. }
  14060. });
  14061. }
  14062. });
  14063. //module begin
  14064. $.jgrid.extend({
  14065. setTreeNode : function(i, len){
  14066. return this.each(function(){
  14067. var $t = this;
  14068. if( !$t.grid || !$t.p.treeGrid ) {return;}
  14069. var expCol = $t.p.expColInd,
  14070. expanded = $t.p.treeReader.expanded_field,
  14071. isLeaf = $t.p.treeReader.leaf_field,
  14072. level = $t.p.treeReader.level_field,
  14073. icon = $t.p.treeReader.icon_field,
  14074. loaded = $t.p.treeReader.loaded, lft, rgt, curLevel, ident,lftpos, twrap,
  14075. ldat, lf,
  14076. common = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].common,
  14077. index = i;
  14078. $($t).triggerHandler("jqGridBeforeSetTreeNode", [index, len]);
  14079. if($.isFunction($t.p.beforeSetTreeNode)) {
  14080. $t.p.beforeSetTreeNode.call($t, index, len);
  14081. }
  14082. while(i<len) {
  14083. var ind = $.jgrid.stripPref($t.p.idPrefix, $t.rows[i].id), dind = $t.p._index[ind], expan;
  14084. ldat = $t.p.data[dind];
  14085. //$t.rows[i].level = ldat[level];
  14086. if($t.p.treeGridModel === 'nested') {
  14087. if(!ldat[isLeaf]) {
  14088. lft = parseInt(ldat[$t.p.treeReader.left_field],10);
  14089. rgt = parseInt(ldat[$t.p.treeReader.right_field],10);
  14090. // NS Model
  14091. ldat[isLeaf] = (rgt === lft+1) ? 'true' : 'false';
  14092. $t.rows[i].cells[$t.p._treeleafpos].innerHTML = ldat[isLeaf];
  14093. }
  14094. }
  14095. //else {
  14096. //row.parent_id = rd[$t.p.treeReader.parent_id_field];
  14097. //}
  14098. curLevel = parseInt(ldat[level],10);
  14099. if($t.p.tree_root_level === 0) {
  14100. ident = curLevel+1;
  14101. lftpos = curLevel;
  14102. } else {
  14103. ident = curLevel;
  14104. lftpos = curLevel -1;
  14105. }
  14106. twrap = "<div class='tree-wrap tree-wrap-"+$t.p.direction+"' style='width:"+(ident*18)+"px;'>";
  14107. twrap += "<div style='"+($t.p.direction==="rtl" ? "right:" : "left:")+(lftpos*18)+"px;' class='"+common.icon_base+" ";
  14108. if(ldat[loaded] !== undefined) {
  14109. if(ldat[loaded]==="true" || ldat[loaded]===true) {
  14110. ldat[loaded] = true;
  14111. } else {
  14112. ldat[loaded] = false;
  14113. }
  14114. }
  14115. if(ldat[isLeaf] === "true" || ldat[isLeaf] === true) {
  14116. twrap += ((ldat[icon] !== undefined && ldat[icon] !== "") ? ldat[icon] : $t.p.treeIcons.leaf)+" tree-leaf treeclick";
  14117. ldat[isLeaf] = true;
  14118. lf="leaf";
  14119. } else {
  14120. ldat[isLeaf] = false;
  14121. lf="";
  14122. }
  14123. ldat[expanded] = ((ldat[expanded] === "true" || ldat[expanded] === true) ? true : false) && (ldat[loaded] || ldat[loaded] === undefined);
  14124. if(ldat[expanded] === false) {
  14125. twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.plus+" tree-plus treeclick'");
  14126. } else {
  14127. twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.minus+" tree-minus treeclick'");
  14128. }
  14129. twrap += "></div></div>";
  14130. $($t.rows[i].cells[expCol]).wrapInner("<span class='cell-wrapper"+lf+"'></span>").prepend(twrap);
  14131. if(curLevel !== parseInt($t.p.tree_root_level,10)) {
  14132. //var pn = $($t).jqGrid('getNodeParent',ldat);
  14133. //expan = pn && pn.hasOwnProperty(expanded) ? pn[expanded] : true;
  14134. expan = $($t).jqGrid('isVisibleNode',ldat); // overhead
  14135. if( !expan ){
  14136. $($t.rows[i]).css("display","none");
  14137. }
  14138. }
  14139. $($t.rows[i].cells[expCol])
  14140. .find("div.treeclick")
  14141. .on("click",function(e){
  14142. var target = e.target || e.srcElement,
  14143. ind2 =$.jgrid.stripPref($t.p.idPrefix,$(target,$t.rows).closest("tr.jqgrow")[0].id),
  14144. pos = $t.p._index[ind2];
  14145. if(!$t.p.data[pos][isLeaf]){
  14146. if($t.p.data[pos][expanded]){
  14147. $($t).jqGrid("collapseRow",$t.p.data[pos]);
  14148. $($t).jqGrid("collapseNode",$t.p.data[pos]);
  14149. } else {
  14150. $($t).jqGrid("expandRow",$t.p.data[pos]);
  14151. $($t).jqGrid("expandNode",$t.p.data[pos]);
  14152. }
  14153. }
  14154. return false;
  14155. });
  14156. if($t.p.ExpandColClick === true) {
  14157. $($t.rows[i].cells[expCol])
  14158. .find("span.cell-wrapper")
  14159. .css("cursor","pointer")
  14160. .on("click",function(e) {
  14161. var target = e.target || e.srcElement,
  14162. ind2 =$.jgrid.stripPref($t.p.idPrefix,$(target,$t.rows).closest("tr.jqgrow")[0].id),
  14163. pos = $t.p._index[ind2];
  14164. if(!$t.p.data[pos][isLeaf]){
  14165. if($t.p.data[pos][expanded]){
  14166. $($t).jqGrid("collapseRow",$t.p.data[pos]);
  14167. $($t).jqGrid("collapseNode",$t.p.data[pos]);
  14168. } else {
  14169. $($t).jqGrid("expandRow",$t.p.data[pos]);
  14170. $($t).jqGrid("expandNode",$t.p.data[pos]);
  14171. }
  14172. }
  14173. $($t).jqGrid("setSelection",ind2);
  14174. return false;
  14175. });
  14176. }
  14177. i++;
  14178. }
  14179. $($t).triggerHandler("jqGridAfterSetTreeNode", [index, len]);
  14180. if($.isFunction($t.p.afterSetTreeNode)) {
  14181. $t.p.afterSetTreeNode.call($t, index, len);
  14182. }
  14183. });
  14184. },
  14185. setTreeGrid : function() {
  14186. return this.each(function (){
  14187. var $t = this, i=0, pico, ecol = false, nm, key, tkey, dupcols=[],
  14188. classes = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].treegrid;
  14189. if(!$t.p.treeGrid) {return;}
  14190. if(!$t.p.treedatatype ) {$.extend($t.p,{treedatatype: $t.p.datatype});}
  14191. if($t.p.loadonce) { $t.p.treedatatype = 'local'; }
  14192. $t.p.subGrid = false;$t.p.altRows =false;
  14193. $t.p.pgbuttons = false;$t.p.pginput = false;
  14194. $t.p.gridview = true;
  14195. if($t.p.rowTotal === null ) { $t.p.rowNum = 10000; }
  14196. $t.p.multiselect = false;$t.p.rowList = [];
  14197. $t.p.expColInd = 0;
  14198. pico = classes.icon_plus;
  14199. if($t.p.styleUI === 'jQueryUI') {
  14200. pico += ($t.p.direction==="rtl" ? 'w' : 'e');
  14201. }
  14202. $t.p.treeIcons = $.extend({plus:pico, minus: classes.icon_minus, leaf: classes.icon_leaf},$t.p.treeIcons || {});
  14203. if($t.p.treeGridModel === 'nested') {
  14204. $t.p.treeReader = $.extend({
  14205. level_field: "level",
  14206. left_field:"lft",
  14207. right_field: "rgt",
  14208. leaf_field: "isLeaf",
  14209. expanded_field: "expanded",
  14210. loaded: "loaded",
  14211. icon_field: "icon"
  14212. },$t.p.treeReader);
  14213. } else if($t.p.treeGridModel === 'adjacency') {
  14214. $t.p.treeReader = $.extend({
  14215. level_field: "level",
  14216. parent_id_field: "parent",
  14217. leaf_field: "isLeaf",
  14218. expanded_field: "expanded",
  14219. loaded: "loaded",
  14220. icon_field: "icon"
  14221. },$t.p.treeReader );
  14222. }
  14223. for ( key in $t.p.colModel){
  14224. if($t.p.colModel.hasOwnProperty(key)) {
  14225. nm = $t.p.colModel[key].name;
  14226. if( nm === $t.p.ExpandColumn && !ecol ) {
  14227. ecol = true;
  14228. $t.p.expColInd = i;
  14229. }
  14230. i++;
  14231. //
  14232. for(tkey in $t.p.treeReader) {
  14233. if($t.p.treeReader.hasOwnProperty(tkey) && $t.p.treeReader[tkey] === nm) {
  14234. dupcols.push(nm);
  14235. }
  14236. }
  14237. }
  14238. }
  14239. $.each($t.p.treeReader,function(j,n){
  14240. if(n && $.inArray(n, dupcols) === -1){
  14241. if(j==='leaf_field') { $t.p._treeleafpos= i; }
  14242. i++;
  14243. $t.p.colNames.push(n);
  14244. $t.p.colModel.push({name:n,width:1,hidden:true,sortable:false,resizable:false,hidedlg:true,editable:true,search:false});
  14245. }
  14246. });
  14247. });
  14248. },
  14249. expandRow: function (record){
  14250. this.each(function(){
  14251. var $t = this;
  14252. if(!$t.grid || !$t.p.treeGrid) {return;}
  14253. var childern = $($t).jqGrid("getNodeChildren",record),
  14254. //if ($($t).jqGrid("isVisibleNode",record)) {
  14255. expanded = $t.p.treeReader.expanded_field,
  14256. rowid = record[$t.p.localReader.id],
  14257. ret = $($t).triggerHandler("jqGridBeforeExpandTreeGridRow", [rowid, record, childern]);
  14258. if(ret === undefined ) {
  14259. ret = true;
  14260. }
  14261. if(ret && $.isFunction($t.p.beforeExpandTreeGridRow)) {
  14262. ret = $t.p.beforeExpandTreeGridRow.call($t, rowid, record, childern);
  14263. }
  14264. if( ret === false ) { return; }
  14265. $(childern).each(function(){
  14266. var id = $t.p.idPrefix + $.jgrid.getAccessor(this,$t.p.localReader.id);
  14267. $($($t).jqGrid('getGridRowById', id)).css("display","");
  14268. if(this[expanded]) {
  14269. $($t).jqGrid("expandRow",this);
  14270. }
  14271. });
  14272. $($t).triggerHandler("jqGridAfterExpandTreeGridRow", [rowid, record, childern]);
  14273. if($.isFunction($t.p.afterExpandTreeGridRow)) {
  14274. $t.p.afterExpandTreeGridRow.call($t, rowid, record, childern);
  14275. }
  14276. //}
  14277. });
  14278. },
  14279. collapseRow : function (record) {
  14280. this.each(function(){
  14281. var $t = this;
  14282. if(!$t.grid || !$t.p.treeGrid) {return;}
  14283. var childern = $($t).jqGrid("getNodeChildren",record),
  14284. expanded = $t.p.treeReader.expanded_field,
  14285. rowid = record[$t.p.localReader.id],
  14286. ret = $($t).triggerHandler("jqGridBeforeCollapseTreeGridRow", [rowid, record, childern]);
  14287. if(ret === undefined ) {
  14288. ret = true;
  14289. }
  14290. if(ret && $.isFunction($t.p.beforeCollapseTreeGridRow)) {
  14291. ret = $t.p.beforeCollapseTreeGridRow.call($t, rowid, record, childern);
  14292. }
  14293. if( ret === false ) { return; }
  14294. $(childern).each(function(){
  14295. var id = $t.p.idPrefix + $.jgrid.getAccessor(this,$t.p.localReader.id);
  14296. $($($t).jqGrid('getGridRowById', id)).css("display","none");
  14297. if(this[expanded]){
  14298. $($t).jqGrid("collapseRow",this);
  14299. }
  14300. });
  14301. $($t).triggerHandler("jqGridAfterCollapseTreeGridRow", [rowid, record, childern]);
  14302. if($.isFunction($t.p.afterCollapseTreeGridRow)) {
  14303. $t.p.afterCollapseTreeGridRow.call($t, rowid, record, childern);
  14304. }
  14305. });
  14306. },
  14307. // NS ,adjacency models
  14308. getRootNodes : function(currentview) {
  14309. var result = [];
  14310. this.each(function(){
  14311. var $t = this, level, parent_id, view;
  14312. if(!$t.grid || !$t.p.treeGrid) {return;}
  14313. if( typeof currentview !== 'boolean') {
  14314. currentview = false;
  14315. }
  14316. if(currentview) {
  14317. view = $($t).jqGrid('getRowData', null, true);
  14318. } else {
  14319. view = $t.p.data;
  14320. }
  14321. switch ($t.p.treeGridModel) {
  14322. case 'nested' :
  14323. level = $t.p.treeReader.level_field;
  14324. $(view).each(function() {
  14325. if(parseInt(this[level],10) === parseInt($t.p.tree_root_level,10)) {
  14326. if(currentview){
  14327. result.push($t.p.data[$t.p._index[this[$t.p.keyName]]]);
  14328. } else {
  14329. result.push(this);
  14330. }
  14331. }
  14332. });
  14333. break;
  14334. case 'adjacency' :
  14335. parent_id = $t.p.treeReader.parent_id_field;
  14336. $(view).each(function(){
  14337. if(this[parent_id] === null || String(this[parent_id]).toLowerCase() === "null") {
  14338. if(currentview){
  14339. result.push($t.p.data[$t.p._index[this[$t.p.keyName]]]);
  14340. } else {
  14341. result.push(this);
  14342. }
  14343. }
  14344. });
  14345. break;
  14346. }
  14347. });
  14348. return result;
  14349. },
  14350. getNodeDepth : function(rc) {
  14351. var ret = null;
  14352. this.each(function(){
  14353. if(!this.grid || !this.p.treeGrid) {return;}
  14354. var $t = this;
  14355. switch ($t.p.treeGridModel) {
  14356. case 'nested' :
  14357. var level = $t.p.treeReader.level_field;
  14358. ret = parseInt(rc[level],10) - parseInt($t.p.tree_root_level,10);
  14359. break;
  14360. case 'adjacency' :
  14361. ret = $($t).jqGrid("getNodeAncestors",rc).length;
  14362. break;
  14363. }
  14364. });
  14365. return ret;
  14366. },
  14367. getNodeParent : function(rc) {
  14368. var result = null;
  14369. this.each(function(){
  14370. var $t = this;
  14371. if(!$t.grid || !$t.p.treeGrid) {return;}
  14372. switch ($t.p.treeGridModel) {
  14373. case 'nested' :
  14374. var lftc = $t.p.treeReader.left_field,
  14375. rgtc = $t.p.treeReader.right_field,
  14376. levelc = $t.p.treeReader.level_field,
  14377. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  14378. $(this.p.data).each(function(){
  14379. if(parseInt(this[levelc],10) === level-1 && parseInt(this[lftc],10) < lft && parseInt(this[rgtc],10) > rgt) {
  14380. result = this;
  14381. return false;
  14382. }
  14383. });
  14384. break;
  14385. case 'adjacency' :
  14386. var parent_id = $t.p.treeReader.parent_id_field,
  14387. dtid = $t.p.localReader.id,
  14388. ind = rc[dtid], pos = $t.p._index[ind];
  14389. while(pos--) {
  14390. if( String( $t.p.data[pos][dtid]) === String( $.jgrid.stripPref($t.p.idPrefix, rc[parent_id]) ) ) {
  14391. result = $t.p.data[pos];
  14392. break;
  14393. }
  14394. }
  14395. break;
  14396. }
  14397. });
  14398. return result;
  14399. },
  14400. getNodeChildren : function(rc, currentview) {
  14401. var result = [];
  14402. this.each(function(){
  14403. var $t = this;
  14404. if(!$t.grid || !$t.p.treeGrid) {return;}
  14405. var i, len = currentview ? this.rows.length : this.p.data.length, row;
  14406. switch ($t.p.treeGridModel) {
  14407. case 'nested' :
  14408. var lftc = $t.p.treeReader.left_field,
  14409. rgtc = $t.p.treeReader.right_field,
  14410. levelc = $t.p.treeReader.level_field,
  14411. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  14412. for(i=0; i < len; i++) {
  14413. row = currentview ? $t.p.data[$t.p._index[this.rows[i].id]] : $t.p.data[i];
  14414. if(row && parseInt(row[levelc],10) === level+1 && parseInt(row[lftc],10) > lft && parseInt(row[rgtc],10) < rgt) {
  14415. result.push(row);
  14416. }
  14417. }
  14418. break;
  14419. case 'adjacency' :
  14420. var parent_id = $t.p.treeReader.parent_id_field,
  14421. dtid = $t.p.localReader.id;
  14422. for(i=0; i < len; i++) {
  14423. row = currentview ? $t.p.data[$t.p._index[this.rows[i].id]] : $t.p.data[i];
  14424. if(row && String(row[parent_id]) === String( $.jgrid.stripPref($t.p.idPrefix, rc[dtid]) ) ) {
  14425. result.push(row);
  14426. }
  14427. }
  14428. break;
  14429. }
  14430. });
  14431. return result;
  14432. },
  14433. getFullTreeNode : function(rc, expand) {
  14434. var result = [];
  14435. this.each(function(){
  14436. var $t = this, len,expanded = $t.p.treeReader.expanded_field;
  14437. if(!$t.grid || !$t.p.treeGrid) {return;}
  14438. if(expand == null || typeof expand !== 'boolean') {
  14439. expand = false;
  14440. }
  14441. switch ($t.p.treeGridModel) {
  14442. case 'nested' :
  14443. var lftc = $t.p.treeReader.left_field,
  14444. rgtc = $t.p.treeReader.right_field,
  14445. levelc = $t.p.treeReader.level_field,
  14446. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  14447. $(this.p.data).each(function(){
  14448. if(parseInt(this[levelc],10) >= level && parseInt(this[lftc],10) >= lft && parseInt(this[lftc],10) <= rgt) {
  14449. if(expand) { this[expanded] = true; }
  14450. result.push(this);
  14451. }
  14452. });
  14453. break;
  14454. case 'adjacency' :
  14455. if(rc) {
  14456. result.push(rc);
  14457. var parent_id = $t.p.treeReader.parent_id_field,
  14458. dtid = $t.p.localReader.id;
  14459. $(this.p.data).each(function(i){
  14460. len = result.length;
  14461. for (i = 0; i < len; i++) {
  14462. if ( String( $.jgrid.stripPref($t.p.idPrefix, result[i][dtid]) ) === String( this[parent_id] ) ) {
  14463. if(expand) { this[expanded] = true; }
  14464. result.push(this);
  14465. break;
  14466. }
  14467. }
  14468. });
  14469. }
  14470. break;
  14471. }
  14472. });
  14473. return result;
  14474. },
  14475. // End NS, adjacency Model
  14476. getNodeAncestors : function(rc, reverse, expanded) {
  14477. var ancestors = [];
  14478. if(reverse === undefined ) {
  14479. reverse = false;
  14480. }
  14481. this.each(function(){
  14482. if(!this.grid || !this.p.treeGrid) {return;}
  14483. if(expanded === undefined ) {
  14484. expanded = false;
  14485. } else {
  14486. expanded = this.p.treeReader.expanded_field;
  14487. }
  14488. var parent = $(this).jqGrid("getNodeParent",rc);
  14489. while (parent) {
  14490. if(expanded) {
  14491. try{
  14492. parent[expanded] = true;
  14493. } catch (etn) {}
  14494. }
  14495. if(reverse) {
  14496. ancestors.unshift(parent);
  14497. } else {
  14498. ancestors.push(parent);
  14499. }
  14500. parent = $(this).jqGrid("getNodeParent",parent);
  14501. }
  14502. });
  14503. return ancestors;
  14504. },
  14505. isVisibleNode : function(rc) {
  14506. var result = true;
  14507. this.each(function(){
  14508. var $t = this;
  14509. if(!$t.grid || !$t.p.treeGrid) {return;}
  14510. var ancestors = $($t).jqGrid("getNodeAncestors",rc),
  14511. expanded = $t.p.treeReader.expanded_field;
  14512. $(ancestors).each(function(){
  14513. result = result && this[expanded];
  14514. if(!result) {return false;}
  14515. });
  14516. });
  14517. return result;
  14518. },
  14519. isNodeLoaded : function(rc) {
  14520. var result;
  14521. this.each(function(){
  14522. var $t = this;
  14523. if(!$t.grid || !$t.p.treeGrid) {return;}
  14524. var isLeaf = $t.p.treeReader.leaf_field,
  14525. loaded = $t.p.treeReader.loaded;
  14526. if(rc !== undefined ) {
  14527. if(rc[loaded] !== undefined) {
  14528. result = rc[loaded];
  14529. } else if( rc[isLeaf] || $($t).jqGrid("getNodeChildren",rc).length > 0){
  14530. result = true;
  14531. } else {
  14532. result = false;
  14533. }
  14534. } else {
  14535. result = false;
  14536. }
  14537. });
  14538. return result;
  14539. },
  14540. setLeaf : function (rc, state, collapsed) {
  14541. return this.each(function(){
  14542. var id = $.jgrid.getAccessor(rc,this.p.localReader.id),
  14543. rc1 = $("#"+id,this.grid.bDiv)[0],
  14544. isLeaf = this.p.treeReader.leaf_field;
  14545. try {
  14546. var dr = this.p._index[id];
  14547. if(dr != null) {
  14548. this.p.data[dr][isLeaf] = state;
  14549. }
  14550. } catch(E){}
  14551. if(state === true) {
  14552. // set it in data
  14553. $("div.treeclick",rc1).removeClass(this.p.treeIcons.minus+" tree-minus "+this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.leaf +" tree-leaf");
  14554. } else if(state === false) {
  14555. var ico = this.p.treeIcons.minus+" tree-minus";
  14556. if(collapsed) {
  14557. ico = this.p.treeIcons.plus+" tree-plus";
  14558. }
  14559. $("div.treeclick",rc1).removeClass(this.p.treeIcons.leaf +" tree-leaf").addClass( ico );
  14560. }
  14561. });
  14562. },
  14563. reloadNode: function(rc, reloadcurrent) {
  14564. return this.each(function(){
  14565. if(!this.grid || !this.p.treeGrid) {return;}
  14566. var rid = this.p.localReader.id,
  14567. currselection = this.p.selrow;
  14568. $(this).jqGrid("delChildren", rc[rid]);
  14569. if(reloadcurrent=== undefined) {
  14570. reloadcurrent = false;
  14571. }
  14572. if(!reloadcurrent) {
  14573. if(!jQuery._data( this, "events" ).jqGridAfterSetTreeNode) {
  14574. $(this).on("jqGridAfterSetTreeNode.reloadNode", function(){
  14575. var isLeaf = this.p.treeReader.leaf_field;
  14576. if(this.p.reloadnode ) {
  14577. var rc = this.p.reloadnode,
  14578. chld = $(this).jqGrid('getNodeChildren', rc);
  14579. if(rc[isLeaf] && chld.length) {
  14580. $(this).jqGrid('setLeaf', rc, false);
  14581. } else if(!rc[isLeaf] && chld.length === 0) {
  14582. $(this).jqGrid('setLeaf', rc, true);
  14583. }
  14584. }
  14585. this.p.reloadnode = false;
  14586. });
  14587. }
  14588. }
  14589. var expanded = this.p.treeReader.expanded_field,
  14590. parent = this.p.treeReader.parent_id_field,
  14591. loaded = this.p.treeReader.loaded,
  14592. level = this.p.treeReader.level_field,
  14593. isLeaf = this.p.treeReader.leaf_field,
  14594. lft = this.p.treeReader.left_field,
  14595. rgt = this.p.treeReader.right_field;
  14596. var id = $.jgrid.getAccessor(rc,this.p.localReader.id),
  14597. rc1 = $("#"+id,this.grid.bDiv)[0];
  14598. rc[expanded] = true;
  14599. if(!rc[isLeaf]) {
  14600. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  14601. }
  14602. this.p.treeANode = rc1.rowIndex;
  14603. this.p.datatype = this.p.treedatatype;
  14604. this.p.reloadnode = rc;
  14605. if(reloadcurrent) {
  14606. this.p.treeANode = rc1.rowIndex > 0 ? rc1.rowIndex - 1 : 1;
  14607. $(this).jqGrid('delRowData', id);
  14608. }
  14609. if(this.p.treeGridModel === 'nested') {
  14610. $(this).jqGrid("setGridParam",{postData:{nodeid:id,n_left:rc[lft],n_right:rc[rgt],n_level:rc[level]}});
  14611. } else {
  14612. $(this).jqGrid("setGridParam",{postData:{nodeid:id,parentid:rc[parent],n_level:rc[level]}} );
  14613. }
  14614. $(this).trigger("reloadGrid");
  14615. rc[loaded] = true;
  14616. if(this.p.treeGridModel === 'nested') {
  14617. $(this).jqGrid("setGridParam",{selrow: currselection, postData:{nodeid:'',n_left:'',n_right:'',n_level:''}});
  14618. } else {
  14619. $(this).jqGrid("setGridParam",{selrow: currselection, postData:{nodeid:'',parentid:'',n_level:''}});
  14620. }
  14621. });
  14622. },
  14623. expandNode : function(rc) {
  14624. return this.each(function(){
  14625. if(!this.grid || !this.p.treeGrid) {return;}
  14626. var $t = this,
  14627. expanded = this.p.treeReader.expanded_field,
  14628. parent = this.p.treeReader.parent_id_field,
  14629. loaded = this.p.treeReader.loaded,
  14630. level = this.p.treeReader.level_field,
  14631. lft = this.p.treeReader.left_field,
  14632. rgt = this.p.treeReader.right_field;
  14633. if(!rc[expanded]) {
  14634. var id = $.jgrid.getAccessor(rc,this.p.localReader.id),
  14635. rc1 = $("#" + this.p.idPrefix + $.jgrid.jqID(id),this.grid.bDiv)[0],
  14636. position = this.p._index[id],
  14637. ret = $($t).triggerHandler("jqGridBeforeExpandTreeGridNode", [id, rc]);
  14638. if(ret === undefined ) {
  14639. ret = true;
  14640. }
  14641. if( ret && $.isFunction(this.p.beforeExpandTreeGridNode) ) {
  14642. ret = this.p.beforeExpandTreeGridNode.call(this, id, rc );
  14643. }
  14644. if( ret === false ) { return; }
  14645. if( $(this).jqGrid("isNodeLoaded",this.p.data[position]) ) {
  14646. rc[expanded] = true;
  14647. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  14648. } else if (!this.grid.hDiv.loading) {
  14649. rc[expanded] = true;
  14650. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  14651. this.p.treeANode = rc1.rowIndex;
  14652. this.p.datatype = this.p.treedatatype;
  14653. if(this.p.treeGridModel === 'nested') {
  14654. $(this).jqGrid("setGridParam",{postData:{nodeid:id,n_left:rc[lft],n_right:rc[rgt],n_level:rc[level]}});
  14655. } else {
  14656. $(this).jqGrid("setGridParam",{postData:{nodeid:id,parentid:rc[parent],n_level:rc[level]}} );
  14657. }
  14658. $(this).trigger("reloadGrid");
  14659. rc[loaded] = true;
  14660. if(this.p.treeGridModel === 'nested') {
  14661. $(this).jqGrid("setGridParam",{postData:{nodeid:'',n_left:'',n_right:'',n_level:''}});
  14662. } else {
  14663. $(this).jqGrid("setGridParam",{postData:{nodeid:'',parentid:'',n_level:''}});
  14664. }
  14665. }
  14666. $($t).triggerHandler("jqGridAfterExpandTreeGridNode", [id, rc]);
  14667. if($.isFunction(this.p.afterExpandTreeGridNode)) {
  14668. this.p.afterExpandTreeGridNode.call(this, id, rc );
  14669. }
  14670. }
  14671. });
  14672. },
  14673. collapseNode : function(rc) {
  14674. return this.each(function(){
  14675. if(!this.grid || !this.p.treeGrid) {return;}
  14676. var expanded = this.p.treeReader.expanded_field,
  14677. $t = this;
  14678. if(rc[expanded]) {
  14679. var id = $.jgrid.getAccessor(rc,this.p.localReader.id),
  14680. rc1 = $("#" + this.p.idPrefix + $.jgrid.jqID(id),this.grid.bDiv)[0],
  14681. ret = $($t).triggerHandler("jqGridBeforeCollapseTreeGridNode", [id, rc]);
  14682. if(ret === undefined ) {
  14683. ret = true;
  14684. }
  14685. if( ret && $.isFunction(this.p.beforeCollapseTreeGridNode) ) {
  14686. ret = this.p.beforeCollapseTreeGridNode.call(this, id, rc );
  14687. }
  14688. rc[expanded] = false;
  14689. if( ret === false ) { return; }
  14690. $("div.treeclick",rc1).removeClass(this.p.treeIcons.minus+" tree-minus").addClass(this.p.treeIcons.plus+" tree-plus");
  14691. $($t).triggerHandler("jqGridAfterCollapseTreeGridNode", [id, rc]);
  14692. if($.isFunction(this.p.afterCollapseTreeGridNode)) {
  14693. this.p.afterCollapseTreeGridNode.call(this, id, rc );
  14694. }
  14695. }
  14696. });
  14697. },
  14698. SortTree : function( sortname, newDir, st, datefmt) {
  14699. return this.each(function(){
  14700. if(!this.grid || !this.p.treeGrid) {return;}
  14701. var i, len,
  14702. rec, records = [], $t = this, query, roots,
  14703. rt = $(this).jqGrid("getRootNodes", $t.p.search);
  14704. // Sorting roots
  14705. query = $.jgrid.from.call(this, rt);
  14706. query.orderBy(sortname, newDir, st, datefmt);
  14707. roots = query.select();
  14708. // Sorting children
  14709. for (i = 0, len = roots.length; i < len; i++) {
  14710. rec = roots[i];
  14711. records.push(rec);
  14712. $(this).jqGrid("collectChildrenSortTree",records, rec, sortname, newDir, st, datefmt);
  14713. }
  14714. $.each(records, function(index) {
  14715. var id = $.jgrid.getAccessor(this, $t.p.localReader.id);
  14716. $('#'+$.jgrid.jqID($t.p.id)+ ' tbody tr:eq('+index+')').after($('tr#'+$.jgrid.jqID(id), $t.grid.bDiv));
  14717. });
  14718. query = null;roots=null;records=null;
  14719. });
  14720. },
  14721. searchTree : function ( recs ) {
  14722. var i= recs.length || 0, ancestors=[], lid, roots=[], result=[],tid, alen, rlen, j, k;
  14723. this.each(function(){
  14724. if(!this.grid || !this.p.treeGrid) {
  14725. return;
  14726. }
  14727. if(i) {
  14728. lid = this.p.localReader.id;
  14729. while( i-- ) { // reverse
  14730. ancestors = $(this).jqGrid('getNodeAncestors', recs[i], true, true);
  14731. //add the searched item
  14732. ancestors.push(recs[i]);
  14733. tid = ancestors[0][lid];
  14734. if($.inArray(tid, roots ) !== -1) { // ignore repeated, but add missing
  14735. for( j = 0, alen = ancestors.length; j < alen; j++) {
  14736. //$.inArray ?!?
  14737. var found = false;
  14738. for( k=0, rlen = result.length; k < rlen; k++) {
  14739. if(ancestors[j][lid] === result[k][lid]) {
  14740. found = true;
  14741. break;
  14742. }
  14743. }
  14744. if(!found) {
  14745. result.push(ancestors[j]);
  14746. }
  14747. }
  14748. continue;
  14749. } else {
  14750. roots.push( tid );
  14751. }
  14752. result = result.concat( ancestors );
  14753. }
  14754. }
  14755. });
  14756. return result;
  14757. },
  14758. collectChildrenSortTree : function(records, rec, sortname, newDir,st, datefmt) {
  14759. return this.each(function(){
  14760. if(!this.grid || !this.p.treeGrid) {return;}
  14761. var i, len,
  14762. child, ch, query, children;
  14763. ch = $(this).jqGrid("getNodeChildren",rec, this.p.search);
  14764. query = $.jgrid.from.call(this, ch);
  14765. query.orderBy(sortname, newDir, st, datefmt);
  14766. children = query.select();
  14767. for (i = 0, len = children.length; i < len; i++) {
  14768. child = children[i];
  14769. records.push(child);
  14770. $(this).jqGrid("collectChildrenSortTree",records, child, sortname, newDir, st, datefmt);
  14771. }
  14772. });
  14773. },
  14774. // experimental
  14775. setTreeRow : function(rowid, data) {
  14776. var success=false;
  14777. this.each(function(){
  14778. var t = this;
  14779. if(!t.grid || !t.p.treeGrid) {return;}
  14780. success = $(t).jqGrid("setRowData", rowid, data);
  14781. });
  14782. return success;
  14783. },
  14784. delTreeNode : function (rowid) {
  14785. return this.each(function () {
  14786. var $t = this, rid = $t.p.localReader.id, i,
  14787. left = $t.p.treeReader.left_field,
  14788. right = $t.p.treeReader.right_field, myright, width, res, key;
  14789. if(!$t.grid || !$t.p.treeGrid) {return;}
  14790. var rc = $t.p._index[rowid];
  14791. if (rc !== undefined) {
  14792. // nested
  14793. myright = parseInt($t.p.data[rc][right],10);
  14794. width = myright - parseInt($t.p.data[rc][left],10) + 1;
  14795. var dr = $($t).jqGrid("getFullTreeNode",$t.p.data[rc]);
  14796. if(dr.length>0){
  14797. for (i=0;i<dr.length;i++){
  14798. $($t).jqGrid("delRowData",dr[i][rid]);
  14799. }
  14800. }
  14801. if( $t.p.treeGridModel === "nested") {
  14802. // ToDo - update grid data
  14803. res = $.jgrid.from.call($t, $t.p.data)
  14804. .greater(left,myright,{stype:'integer'})
  14805. .select();
  14806. if(res.length) {
  14807. for( key in res) {
  14808. if(res.hasOwnProperty(key)) {
  14809. res[key][left] = parseInt(res[key][left],10) - width ;
  14810. }
  14811. }
  14812. }
  14813. res = $.jgrid.from.call($t, $t.p.data)
  14814. .greater(right,myright,{stype:'integer'})
  14815. .select();
  14816. if(res.length) {
  14817. for( key in res) {
  14818. if(res.hasOwnProperty(key)) {
  14819. res[key][right] = parseInt(res[key][right],10) - width ;
  14820. }
  14821. }
  14822. }
  14823. }
  14824. }
  14825. });
  14826. },
  14827. delChildren : function (rowid) {
  14828. return this.each(function () {
  14829. var $t = this, rid = $t.p.localReader.id,
  14830. left = $t.p.treeReader.left_field,
  14831. right = $t.p.treeReader.right_field, myright, width, res, key;
  14832. if(!$t.grid || !$t.p.treeGrid) {return;}
  14833. var rc = $t.p._index[rowid];
  14834. if (rc !== undefined) {
  14835. // nested
  14836. myright = parseInt($t.p.data[rc][right],10);
  14837. width = myright - parseInt($t.p.data[rc][left],10) + 1;
  14838. var dr = $($t).jqGrid("getFullTreeNode",$t.p.data[rc]);
  14839. if(dr.length>0){
  14840. for (var i=0;i<dr.length;i++){
  14841. if(dr[i][rid] !== rowid)
  14842. $($t).jqGrid("delRowData",dr[i][rid]);
  14843. }
  14844. }
  14845. if( $t.p.treeGridModel === "nested") {
  14846. // ToDo - update grid data
  14847. res = $.jgrid.from($t.p.data)
  14848. .greater(left,myright,{stype:'integer'})
  14849. .select();
  14850. if(res.length) {
  14851. for( key in res) {
  14852. if(res.hasOwnProperty(key)) {
  14853. res[key][left] = parseInt(res[key][left],10) - width ;
  14854. }
  14855. }
  14856. }
  14857. res = $.jgrid.from($t.p.data)
  14858. .greater(right,myright,{stype:'integer'})
  14859. .select();
  14860. if(res.length) {
  14861. for( key in res) {
  14862. if(res.hasOwnProperty(key)) {
  14863. res[key][right] = parseInt(res[key][right],10) - width ;
  14864. }
  14865. }
  14866. }
  14867. }
  14868. }
  14869. });
  14870. },
  14871. addChildNode : function( nodeid, parentid, data, expandData ) {
  14872. //return this.each(function(){
  14873. var $t = this[0];
  14874. if(data) {
  14875. // we suppose tha the id is autoincremet and
  14876. var expanded = $t.p.treeReader.expanded_field,
  14877. isLeaf = $t.p.treeReader.leaf_field,
  14878. level = $t.p.treeReader.level_field,
  14879. //icon = $t.p.treeReader.icon_field,
  14880. parent = $t.p.treeReader.parent_id_field,
  14881. left = $t.p.treeReader.left_field,
  14882. right = $t.p.treeReader.right_field,
  14883. loaded = $t.p.treeReader.loaded,
  14884. method, parentindex, parentdata, parentlevel, i, len, max=0, rowind = parentid, leaf, maxright;
  14885. if(expandData===undefined) {expandData = false;}
  14886. if ( nodeid == null ) {
  14887. i = $t.p.data.length-1;
  14888. if( i>= 0 ) {
  14889. while(i>=0){max = Math.max(max, parseInt($t.p.data[i][$t.p.localReader.id],10)); i--;}
  14890. }
  14891. nodeid = max+1;
  14892. }
  14893. var prow = $($t).jqGrid('getInd', parentid);
  14894. leaf = false;
  14895. // if not a parent we assume root
  14896. if ( parentid === undefined || parentid === null || parentid==="") {
  14897. parentid = null;
  14898. rowind = null;
  14899. method = 'last';
  14900. parentlevel = $t.p.tree_root_level;
  14901. i = $t.p.data.length+1;
  14902. } else {
  14903. method = 'after';
  14904. parentindex = $t.p._index[parentid];
  14905. parentdata = $t.p.data[parentindex];
  14906. parentid = parentdata[$t.p.localReader.id];
  14907. parentlevel = parseInt(parentdata[level],10)+1;
  14908. var childs = $($t).jqGrid('getFullTreeNode', parentdata);
  14909. // if there are child nodes get the last index of it
  14910. if(childs.length) {
  14911. i = childs[childs.length-1][$t.p.localReader.id];
  14912. rowind = i;
  14913. i = $($t).jqGrid('getInd',rowind)+1;
  14914. } else {
  14915. i = $($t).jqGrid('getInd', parentid)+1;
  14916. }
  14917. // if the node is leaf
  14918. if(parentdata[isLeaf]) {
  14919. leaf = true;
  14920. parentdata[expanded] = true;
  14921. //var prow = $($t).jqGrid('getInd', parentid);
  14922. $($t.rows[prow])
  14923. .find("span.cell-wrapperleaf").removeClass("cell-wrapperleaf").addClass("cell-wrapper")
  14924. .end()
  14925. .find("div.tree-leaf").removeClass($t.p.treeIcons.leaf+" tree-leaf").addClass($t.p.treeIcons.minus+" tree-minus");
  14926. $t.p.data[parentindex][isLeaf] = false;
  14927. parentdata[loaded] = true;
  14928. }
  14929. }
  14930. len = i+1;
  14931. if( data[expanded]===undefined) {data[expanded]= false;}
  14932. if( data[loaded]===undefined ) { data[loaded] = false;}
  14933. data[level] = parentlevel;
  14934. if( data[isLeaf]===undefined) {data[isLeaf]= true;}
  14935. if( $t.p.treeGridModel === "adjacency") {
  14936. data[parent] = parentid;
  14937. }
  14938. if( $t.p.treeGridModel === "nested") {
  14939. // this method requiere more attention
  14940. var query, res, key;
  14941. //maxright = parseInt(maxright,10);
  14942. // ToDo - update grid data
  14943. if(parentid !== null) {
  14944. maxright = parseInt(parentdata[right],10);
  14945. query = $.jgrid.from.call($t, $t.p.data);
  14946. query = query.greaterOrEquals(right,maxright,{stype:'integer'});
  14947. res = query.select();
  14948. if(res.length) {
  14949. for( key in res) {
  14950. if(res.hasOwnProperty(key)) {
  14951. res[key][left] = res[key][left] > maxright ? parseInt(res[key][left],10) +2 : res[key][left];
  14952. res[key][right] = res[key][right] >= maxright ? parseInt(res[key][right],10) +2 : res[key][right];
  14953. }
  14954. }
  14955. }
  14956. data[left] = maxright;
  14957. data[right]= maxright+1;
  14958. } else {
  14959. maxright = parseInt( $($t).jqGrid('getCol', right, false, 'max'), 10);
  14960. res = $.jgrid.from.call($t, $t.p.data)
  14961. .greater(left,maxright,{stype:'integer'})
  14962. .select();
  14963. if(res.length) {
  14964. for( key in res) {
  14965. if(res.hasOwnProperty(key)) {
  14966. res[key][left] = parseInt(res[key][left],10) +2 ;
  14967. }
  14968. }
  14969. }
  14970. res = $.jgrid.from.call($t, $t.p.data)
  14971. .greater(right,maxright,{stype:'integer'})
  14972. .select();
  14973. if(res.length) {
  14974. for( key in res) {
  14975. if(res.hasOwnProperty(key)) {
  14976. res[key][right] = parseInt(res[key][right],10) +2 ;
  14977. }
  14978. }
  14979. }
  14980. data[left] = maxright+1;
  14981. data[right] = maxright + 2;
  14982. }
  14983. }
  14984. if( parentid === null || $($t).jqGrid("isNodeLoaded",parentdata) || leaf ) {
  14985. $($t).jqGrid('addRowData', nodeid, data, method, rowind);
  14986. $($t).jqGrid('setTreeNode', i, len);
  14987. }
  14988. if(parentdata && !parentdata[expanded] && expandData) {
  14989. $($t.rows[prow])
  14990. .find("div.treeclick")
  14991. .click();
  14992. }
  14993. }
  14994. //});
  14995. }
  14996. });
  14997. //module begin
  14998. $.fn.jqDrag=function(h){return i(this,h,'d');};
  14999. $.fn.jqResize=function(h,ar){return i(this,h,'r',ar);};
  15000. $.jqDnR={
  15001. dnr:{},
  15002. e:0,
  15003. drag:function(v){
  15004. if(M.k == 'd'){E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});}
  15005. else {
  15006. E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)});
  15007. if(M1){E1.css({width:Math.max(v.pageX-M1.pX+M1.W,0),height:Math.max(v.pageY-M1.pY+M1.H,0)});}
  15008. }
  15009. return false;
  15010. },
  15011. stop:function(){
  15012. //E.css('opacity',M.o);
  15013. $(document).off('mousemove',J.drag).off('mouseup',J.stop);
  15014. }
  15015. };
  15016. var J=$.jqDnR,M=J.dnr,E=J.e,E1,M1,
  15017. i=function(e,h,k,aR){
  15018. return e.each(function(){
  15019. h=(h)?$(h,e):e;
  15020. h.on('mousedown',{e:e,k:k},function(v){
  15021. var d=v.data,p={};E=d.e;E1 = aR ? $(aR) : false;
  15022. // attempt utilization of dimensions plugin to fix IE issues
  15023. if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}}
  15024. M={
  15025. X:p.left||f('left')||0,
  15026. Y:p.top||f('top')||0,
  15027. W:f('width')||E[0].scrollWidth||0,
  15028. H:f('height')||E[0].scrollHeight||0,
  15029. pX:v.pageX,
  15030. pY:v.pageY,
  15031. k:d.k
  15032. //o:E.css('opacity')
  15033. };
  15034. // also resize
  15035. if(E1 && d.k != 'd'){
  15036. M1={
  15037. X:p.left||f1('left')||0,
  15038. Y:p.top||f1('top')||0,
  15039. W:E1[0].offsetWidth||f1('width')||0,
  15040. H:E1[0].offsetHeight||f1('height')||0,
  15041. pX:v.pageX,
  15042. pY:v.pageY,
  15043. k:d.k
  15044. };
  15045. } else {M1 = false;}
  15046. //E.css({opacity:0.8});
  15047. if($("input.hasDatepicker",E[0])[0]) {
  15048. try {$("input.hasDatepicker",E[0]).datepicker('hide');}catch (dpe){}
  15049. }
  15050. $(document).mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
  15051. return false;
  15052. });
  15053. });
  15054. },
  15055. f=function(k){return parseInt(E.css(k),10)||false;},
  15056. f1=function(k){return parseInt(E1.css(k),10)||false;};
  15057. /*
  15058. jQuery tinyDraggable v1.0.2
  15059. Copyright (c) 2014 Simon Steinberger / Pixabay
  15060. GitHub: https://github.com/Pixabay/jQuery-tinyDraggable
  15061. More info: https://pixabay.com/blog/posts/p-52/
  15062. License: http://www.opensource.org/licenses/mit-license.php
  15063. */
  15064. $.fn.tinyDraggable = function(options){
  15065. var settings = $.extend({ handle: 0, exclude: 0 }, options);
  15066. return this.each(function(){
  15067. var dx, dy, el = $(this), handle = settings.handle ? $(settings.handle, el) : el;
  15068. handle.on({
  15069. mousedown: function(e){
  15070. if (settings.exclude && ~$.inArray(e.target, $(settings.exclude, el))) { return; }
  15071. e.preventDefault();
  15072. var os = el.offset(); dx = e.pageX-os.left, dy = e.pageY-os.top;
  15073. $(document).on('mousemove.drag', function(e){ el.offset({top: e.pageY-dy, left: e.pageX-dx}); });
  15074. },
  15075. mouseup: function(e){ $(document).off('mousemove.drag'); }
  15076. });
  15077. });
  15078. };
  15079. //module begin
  15080. $.fn.jqm=function(o){
  15081. var p={
  15082. overlay: 50,
  15083. closeoverlay : true,
  15084. overlayClass: 'jqmOverlay',
  15085. closeClass: 'jqmClose',
  15086. trigger: '.jqModal',
  15087. ajax: F,
  15088. ajaxText: '',
  15089. target: F,
  15090. modal: F,
  15091. toTop: F,
  15092. onShow: F,
  15093. onHide: F,
  15094. onLoad: F
  15095. };
  15096. return this.each(function(){if(this._jqm){ return H[this._jqm].c=$.extend({},H[this._jqm].c,o);} s++;this._jqm=s;
  15097. H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
  15098. if(p.trigger){$(this).jqmAddTrigger(p.trigger);}
  15099. });};
  15100. $.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
  15101. $.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
  15102. $.fn.jqmShow=function(t){return this.each(function(){$.jqm.open(this._jqm,t);});};
  15103. $.fn.jqmHide=function(t){return this.each(function(){$.jqm.close(this._jqm,t);});};
  15104. $.jqm = {
  15105. hash:{},
  15106. open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=(parseInt(h.w.css('z-index')));z=(z>0)?z:3000;var o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});if(h.a){return F;} h.t=t;h.a=true;h.w.css('z-index',z);
  15107. if(c.modal) {if(!A[0]){setTimeout(function(){ new L('bind');},1); }A.push(s);}
  15108. else if(c.overlay > 0) {if(c.closeoverlay) {h.w.jqmAddClose(o);}}
  15109. else {o=F;}
  15110. h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
  15111. if(c.ajax) {var r=c.target||h.w,u=c.ajax;r=(typeof r === 'string')?$(r,h.w):$(r);u=(u.substr(0,1) === '@')?$(t).attr(u.substring(1)):u;
  15112. r.html(c.ajaxText).load(u,function(){if(c.onLoad){c.onLoad.call(this,h);}if(cc){h.w.jqmAddClose($(cc,h.w));}e(h);});}
  15113. else if(cc){h.w.jqmAddClose($(cc,h.w));}
  15114. if(c.toTop&&h.o){h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);}
  15115. (c.onShow)?c.onShow(h):h.w.show();e(h);return F;
  15116. },
  15117. close:function(s){var h=H[s];if(!h.a){return F;}h.a=F;
  15118. if(A[0]){A.pop();if(!A[0]){new L('unbind');}}
  15119. if(h.c.toTop&&h.o){$('#jqmP'+h.w[0]._jqm).after(h.w).remove();}
  15120. if(h.c.onHide){h.c.onHide(h);}else{h.w.hide();if(h.o){h.o.remove();}} return F;
  15121. },
  15122. params:{}};
  15123. var s=0,H=$.jqm.hash,A=[],F=false,
  15124. e=function(h){ if(h.c.focusField===undefined) {h.c.focusField = 0;}if(h.c.focusField >=0 ) {f(h);} },
  15125. f=function(h){try{$(':input:visible',h.w)[parseInt(h.c.focusField,10)].focus(); }catch(_){}},
  15126. L=function(t){$(document)[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
  15127. m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r){$('.jqmID'+h.s).each(function(){var $self=$(this),offset=$self.offset();if(offset.top<=e.pageY && e.pageY<=offset.top+$self.height() && offset.left<=e.pageX && e.pageX<=offset.left+$self.width()){r=false;return false;}});f(h);}return !r;},
  15128. hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
  15129. if(!this[c]){this[c]=[];$(this).click(function(){for(var i in {jqmShow:1,jqmHide:1}){for(var s in this[i]){if(H[this[i][s]]){H[this[i][s]].w[i](this);}}}return F;});}
  15130. this[c].push(s);});});};
  15131. //module begin
  15132. $.fmatter = {};
  15133. //opts can be id:row id for the row, rowdata:the data for the row, colmodel:the column model for this column
  15134. //example {id:1234,}
  15135. $.extend($.fmatter,{
  15136. isBoolean : function(o) {
  15137. return typeof o === 'boolean';
  15138. },
  15139. isObject : function(o) {
  15140. return (o && (typeof o === 'object' || $.isFunction(o))) || false;
  15141. },
  15142. isString : function(o) {
  15143. return typeof o === 'string';
  15144. },
  15145. isNumber : function(o) {
  15146. return typeof o === 'number' && isFinite(o);
  15147. },
  15148. isValue : function (o) {
  15149. return (this.isObject(o) || this.isString(o) || this.isNumber(o) || this.isBoolean(o));
  15150. },
  15151. isEmpty : function(o) {
  15152. if(!this.isString(o) && this.isValue(o)) {
  15153. return false;
  15154. }
  15155. if (!this.isValue(o)){
  15156. return true;
  15157. }
  15158. o = $.trim(o).replace(/\&nbsp\;/ig,'').replace(/\&#160\;/ig,'');
  15159. return o==="";
  15160. }
  15161. });
  15162. $.fn.fmatter = function(formatType, cellval, opts, rwd, act) {
  15163. // build main options before element iteration
  15164. var v=cellval;
  15165. opts = $.extend({}, $.jgrid.getRegional(this, 'formatter') , opts);
  15166. try {
  15167. v = $.fn.fmatter[formatType].call(this, cellval, opts, rwd, act);
  15168. } catch(fe){}
  15169. return v;
  15170. };
  15171. $.fmatter.util = {
  15172. // Taken from YAHOO utils
  15173. NumberFormat : function(nData,opts) {
  15174. if(!$.fmatter.isNumber(nData)) {
  15175. nData *= 1;
  15176. }
  15177. if($.fmatter.isNumber(nData)) {
  15178. var bNegative = (nData < 0);
  15179. var sOutput = String(nData);
  15180. var sDecimalSeparator = opts.decimalSeparator || ".";
  15181. var nDotIndex;
  15182. if($.fmatter.isNumber(opts.decimalPlaces)) {
  15183. // Round to the correct decimal place
  15184. var nDecimalPlaces = opts.decimalPlaces;
  15185. var nDecimal = Math.pow(10, nDecimalPlaces);
  15186. sOutput = String(Math.round(nData*nDecimal)/nDecimal);
  15187. nDotIndex = sOutput.lastIndexOf(".");
  15188. if(nDecimalPlaces > 0) {
  15189. // Add the decimal separator
  15190. if(nDotIndex < 0) {
  15191. sOutput += sDecimalSeparator;
  15192. nDotIndex = sOutput.length-1;
  15193. }
  15194. // Replace the "."
  15195. else if(sDecimalSeparator !== "."){
  15196. sOutput = sOutput.replace(".",sDecimalSeparator);
  15197. }
  15198. // Add missing zeros
  15199. while((sOutput.length - 1 - nDotIndex) < nDecimalPlaces) {
  15200. sOutput += "0";
  15201. }
  15202. }
  15203. }
  15204. if(opts.thousandsSeparator) {
  15205. var sThousandsSeparator = opts.thousandsSeparator;
  15206. nDotIndex = sOutput.lastIndexOf(sDecimalSeparator);
  15207. nDotIndex = (nDotIndex > -1) ? nDotIndex : sOutput.length;
  15208. var sNewOutput = sOutput.substring(nDotIndex);
  15209. var nCount = -1, i;
  15210. for (i=nDotIndex; i>0; i--) {
  15211. nCount++;
  15212. if ((nCount%3 === 0) && (i !== nDotIndex) && (!bNegative || (i > 1))) {
  15213. sNewOutput = sThousandsSeparator + sNewOutput;
  15214. }
  15215. sNewOutput = sOutput.charAt(i-1) + sNewOutput;
  15216. }
  15217. sOutput = sNewOutput;
  15218. }
  15219. // Prepend prefix
  15220. sOutput = (opts.prefix) ? opts.prefix + sOutput : sOutput;
  15221. // Append suffix
  15222. sOutput = (opts.suffix) ? sOutput + opts.suffix : sOutput;
  15223. return sOutput;
  15224. }
  15225. return nData;
  15226. }
  15227. };
  15228. $.fn.fmatter.defaultFormat = function(cellval, opts) {
  15229. return ($.fmatter.isValue(cellval) && cellval!=="" ) ? cellval : opts.defaultValue || "&#160;";
  15230. };
  15231. $.fn.fmatter.email = function(cellval, opts) {
  15232. if(!$.fmatter.isEmpty(cellval)) {
  15233. return "<a href=\"mailto:" + cellval + "\">" + cellval + "</a>";
  15234. }
  15235. return $.fn.fmatter.defaultFormat(cellval,opts );
  15236. };
  15237. $.fn.fmatter.checkbox =function(cval, opts) {
  15238. var op = $.extend({},opts.checkbox), ds;
  15239. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  15240. op = $.extend({},op,opts.colModel.formatoptions);
  15241. }
  15242. if(op.disabled===true) {ds = "disabled=\"disabled\"";} else {ds="";}
  15243. if($.fmatter.isEmpty(cval) || cval === undefined ) {cval = $.fn.fmatter.defaultFormat(cval,op);}
  15244. cval=String(cval);
  15245. cval=(cval+"").toLowerCase();
  15246. var bchk = cval.search(/(false|f|0|no|n|off|undefined)/i)<0 ? " checked='checked' " : "";
  15247. return "<input type=\"checkbox\" " + bchk + " value=\""+ cval+"\" offval=\"no\" "+ds+ "/>";
  15248. };
  15249. $.fn.fmatter.link = function(cellval, opts) {
  15250. var op = {target:opts.target};
  15251. var target = "";
  15252. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  15253. op = $.extend({},op,opts.colModel.formatoptions);
  15254. }
  15255. if(op.target) {target = 'target=' + op.target;}
  15256. if(!$.fmatter.isEmpty(cellval)) {
  15257. return "<a "+target+" href=\"" + cellval + "\">" + cellval + "</a>";
  15258. }
  15259. return $.fn.fmatter.defaultFormat(cellval,opts);
  15260. };
  15261. $.fn.fmatter.showlink = function(cellval, opts) {
  15262. var op = {baseLinkUrl: opts.baseLinkUrl,showAction:opts.showAction, addParam: opts.addParam || "", target: opts.target, idName: opts.idName},
  15263. target = "", idUrl;
  15264. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  15265. op = $.extend({},op,opts.colModel.formatoptions);
  15266. }
  15267. if(op.target) {target = 'target=' + op.target;}
  15268. idUrl = op.baseLinkUrl+op.showAction + '?'+ op.idName+'='+opts.rowId+op.addParam;
  15269. if($.fmatter.isString(cellval) || $.fmatter.isNumber(cellval)) { //add this one even if its blank string
  15270. return "<a "+target+" href=\"" + idUrl + "\">" + cellval + "</a>";
  15271. }
  15272. return $.fn.fmatter.defaultFormat(cellval,opts);
  15273. };
  15274. $.fn.fmatter.integer = function(cellval, opts) {
  15275. var op = $.extend({},opts.integer);
  15276. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  15277. op = $.extend({},op,opts.colModel.formatoptions);
  15278. }
  15279. if($.fmatter.isEmpty(cellval)) {
  15280. return op.defaultValue;
  15281. }
  15282. return $.fmatter.util.NumberFormat(cellval,op);
  15283. };
  15284. $.fn.fmatter.number = function (cellval, opts) {
  15285. var op = $.extend({},opts.number);
  15286. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  15287. op = $.extend({},op,opts.colModel.formatoptions);
  15288. }
  15289. if($.fmatter.isEmpty(cellval)) {
  15290. return op.defaultValue;
  15291. }
  15292. return $.fmatter.util.NumberFormat(cellval,op);
  15293. };
  15294. $.fn.fmatter.currency = function (cellval, opts) {
  15295. var op = $.extend({},opts.currency);
  15296. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  15297. op = $.extend({},op,opts.colModel.formatoptions);
  15298. }
  15299. if($.fmatter.isEmpty(cellval)) {
  15300. return op.defaultValue;
  15301. }
  15302. return $.fmatter.util.NumberFormat(cellval,op);
  15303. };
  15304. $.fn.fmatter.date = function (cellval, opts, rwd, act) {
  15305. var op = $.extend({},opts.date);
  15306. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  15307. op = $.extend({},op,opts.colModel.formatoptions);
  15308. }
  15309. if(!op.reformatAfterEdit && act === 'edit'){
  15310. return $.fn.fmatter.defaultFormat(cellval, opts);
  15311. }
  15312. if(!$.fmatter.isEmpty(cellval)) {
  15313. return $.jgrid.parseDate.call(this, op.srcformat,cellval,op.newformat,op);
  15314. }
  15315. return $.fn.fmatter.defaultFormat(cellval, opts);
  15316. };
  15317. $.fn.fmatter.select = function (cellval,opts) {
  15318. // jqGrid specific
  15319. cellval = String(cellval);
  15320. var oSelect = false, ret=[], sep, delim;
  15321. if(opts.colModel.formatoptions !== undefined){
  15322. oSelect= opts.colModel.formatoptions.value;
  15323. sep = opts.colModel.formatoptions.separator === undefined ? ":" : opts.colModel.formatoptions.separator;
  15324. delim = opts.colModel.formatoptions.delimiter === undefined ? ";" : opts.colModel.formatoptions.delimiter;
  15325. } else if(opts.colModel.editoptions !== undefined){
  15326. oSelect= opts.colModel.editoptions.value;
  15327. sep = opts.colModel.editoptions.separator === undefined ? ":" : opts.colModel.editoptions.separator;
  15328. delim = opts.colModel.editoptions.delimiter === undefined ? ";" : opts.colModel.editoptions.delimiter;
  15329. }
  15330. if (oSelect) {
  15331. var msl = (opts.colModel.editoptions != null && opts.colModel.editoptions.multiple === true) === true ? true : false,
  15332. scell = [], sv;
  15333. if(msl) {scell = cellval.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
  15334. if ($.fmatter.isString(oSelect)) {
  15335. // mybe here we can use some caching with care ????
  15336. var so = oSelect.split(delim), j=0, i;
  15337. for(i=0; i<so.length;i++){
  15338. sv = so[i].split(sep);
  15339. if(sv.length > 2 ) {
  15340. sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep);
  15341. }
  15342. if(msl) {
  15343. if($.inArray(sv[0],scell)>-1) {
  15344. ret[j] = sv[1];
  15345. j++;
  15346. }
  15347. } else if($.trim(sv[0]) === $.trim(cellval)) {
  15348. ret[0] = sv[1];
  15349. break;
  15350. }
  15351. }
  15352. } else if($.fmatter.isObject(oSelect)) {
  15353. // this is quicker
  15354. if(msl) {
  15355. ret = $.map(scell, function(n){
  15356. return oSelect[n];
  15357. });
  15358. } else {
  15359. ret[0] = oSelect[cellval] || "";
  15360. }
  15361. }
  15362. }
  15363. cellval = ret.join(", ");
  15364. return cellval === "" ? $.fn.fmatter.defaultFormat(cellval,opts) : cellval;
  15365. };
  15366. $.fn.fmatter.rowactions = function(act) {
  15367. var $tr = $(this).closest("tr.jqgrow"),
  15368. rid = $tr.attr("id"),
  15369. $id = $(this).closest("table.ui-jqgrid-btable").attr('id').replace(/_frozen([^_]*)$/,'$1'),
  15370. $grid = $("#"+$id),
  15371. $t = $grid[0],
  15372. p = $t.p,
  15373. cm = p.colModel[$.jgrid.getCellIndex(this)],
  15374. $actionsDiv = cm.frozen ? $("tr#"+rid+" td:eq("+$.jgrid.getCellIndex(this)+") > div",$grid) :$(this).parent(),
  15375. op = {
  15376. extraparam: {}
  15377. },
  15378. saverow = function(rowid, res) {
  15379. if($.isFunction(op.afterSave)) { op.afterSave.call($t, rowid, res); }
  15380. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  15381. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  15382. },
  15383. restorerow = function(rowid) {
  15384. if($.isFunction(op.afterRestore)) { op.afterRestore.call($t, rowid); }
  15385. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  15386. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  15387. };
  15388. if (cm.formatoptions !== undefined) {
  15389. // Deep clone before copying over to op, to avoid creating unintentional references.
  15390. // Otherwise, the assignment of op.extraparam[p.prmNames.oper] below may persist into the colModel config.
  15391. var formatoptionsClone = $.extend(true, {}, cm.formatoptions);
  15392. op = $.extend(op, formatoptionsClone);
  15393. }
  15394. if (p.editOptions !== undefined) {
  15395. op.editOptions = p.editOptions;
  15396. }
  15397. if (p.delOptions !== undefined) {
  15398. op.delOptions = p.delOptions;
  15399. }
  15400. if ($tr.hasClass("jqgrid-new-row")){
  15401. op.extraparam[p.prmNames.oper] = p.prmNames.addoper;
  15402. }
  15403. var actop = {
  15404. keys: op.keys,
  15405. oneditfunc: op.onEdit,
  15406. successfunc: op.onSuccess,
  15407. url: op.url,
  15408. extraparam: op.extraparam,
  15409. aftersavefunc: saverow,
  15410. errorfunc: op.onError,
  15411. afterrestorefunc: restorerow,
  15412. restoreAfterError: op.restoreAfterError,
  15413. mtype: op.mtype
  15414. };
  15415. switch(act)
  15416. {
  15417. case 'edit':
  15418. $grid.jqGrid('editRow', rid, actop);
  15419. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").hide();
  15420. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").show();
  15421. $grid.triggerHandler("jqGridAfterGridComplete");
  15422. break;
  15423. case 'save':
  15424. if ($grid.jqGrid('saveRow', rid, actop)) {
  15425. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  15426. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  15427. $grid.triggerHandler("jqGridAfterGridComplete");
  15428. }
  15429. break;
  15430. case 'cancel' :
  15431. $grid.jqGrid('restoreRow', rid, restorerow);
  15432. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  15433. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  15434. $grid.triggerHandler("jqGridAfterGridComplete");
  15435. break;
  15436. case 'del':
  15437. $grid.jqGrid('delGridRow', rid, op.delOptions);
  15438. break;
  15439. case 'formedit':
  15440. $grid.jqGrid('setSelection', rid);
  15441. $grid.jqGrid('editGridRow', rid, op.editOptions);
  15442. break;
  15443. }
  15444. };
  15445. $.fn.fmatter.actions = function(cellval,opts) {
  15446. var op={keys:false, editbutton:true, delbutton:true, editformbutton: false},
  15447. rowid=opts.rowId, str="",ocl,
  15448. nav = $.jgrid.getRegional(this, 'nav'),
  15449. classes = $.jgrid.styleUI[(opts.styleUI || 'jQueryUI')].fmatter,
  15450. common = $.jgrid.styleUI[(opts.styleUI || 'jQueryUI')].common;
  15451. if(opts.colModel.formatoptions !== undefined) {
  15452. op = $.extend(op,opts.colModel.formatoptions);
  15453. }
  15454. if(rowid === undefined || $.fmatter.isEmpty(rowid)) {return "";}
  15455. var hover = "onmouseover=jQuery(this).addClass('" + common.hover +"'); onmouseout=jQuery(this).removeClass('" + common.hover +"'); ";
  15456. if(op.editformbutton){
  15457. ocl = "id='jEditButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'formedit'); " + hover;
  15458. str += "<div title='"+nav.edittitle+"' style='float:left;cursor:pointer;' class='ui-pg-div ui-inline-edit' "+ocl+"><span class='" + common.icon_base +" "+classes.icon_edit +"'></span></div>";
  15459. } else if(op.editbutton){
  15460. ocl = "id='jEditButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'edit'); " + hover;
  15461. str += "<div title='"+nav.edittitle+"' style='float:left;cursor:pointer;' class='ui-pg-div ui-inline-edit' "+ocl+"><span class='" + common.icon_base +" "+classes.icon_edit +"'></span></div>";
  15462. }
  15463. if(op.delbutton) {
  15464. ocl = "id='jDeleteButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'del'); " + hover;
  15465. str += "<div title='"+nav.deltitle+"' style='float:left;' class='ui-pg-div ui-inline-del' "+ocl+"><span class='" + common.icon_base +" "+classes.icon_del +"'></span></div>";
  15466. }
  15467. ocl = "id='jSaveButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'save'); " + hover;
  15468. str += "<div title='"+nav.savetitle+"' style='float:left;display:none' class='ui-pg-div ui-inline-save' "+ocl+"><span class='" + common.icon_base +" "+classes.icon_save +"'></span></div>";
  15469. ocl = "id='jCancelButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'cancel'); " + hover;
  15470. str += "<div title='"+nav.canceltitle+"' style='float:left;display:none;' class='ui-pg-div ui-inline-cancel' "+ocl+"><span class='" + common.icon_base +" "+classes.icon_cancel +"'></span></div>";
  15471. return "<div style='margin-left:8px;'>" + str + "</div>";
  15472. };
  15473. $.unformat = function (cellval,options,pos,cnt) {
  15474. // specific for jqGrid only
  15475. var ret, formatType = options.colModel.formatter,
  15476. op =options.colModel.formatoptions || {}, sep,
  15477. re = /([\.\*\_\'\(\)\{\}\+\?\\])/g,
  15478. unformatFunc = options.colModel.unformat||($.fn.fmatter[formatType] && $.fn.fmatter[formatType].unformat);
  15479. if(unformatFunc !== undefined && $.isFunction(unformatFunc) ) {
  15480. ret = unformatFunc.call(this, $(cellval).text(), options, cellval);
  15481. } else if(formatType !== undefined && $.fmatter.isString(formatType) ) {
  15482. var opts = $.jgrid.getRegional(this, 'formatter') || {}, stripTag;
  15483. switch(formatType) {
  15484. case 'integer' :
  15485. op = $.extend({},opts.integer,op);
  15486. sep = op.thousandsSeparator.replace(re,"\\$1");
  15487. stripTag = new RegExp(sep, "g");
  15488. ret = $(cellval).text().replace(stripTag,'');
  15489. break;
  15490. case 'number' :
  15491. op = $.extend({},opts.number,op);
  15492. sep = op.thousandsSeparator.replace(re,"\\$1");
  15493. stripTag = new RegExp(sep, "g");
  15494. ret = $(cellval).text().replace(stripTag,"").replace(op.decimalSeparator,'.');
  15495. break;
  15496. case 'currency':
  15497. op = $.extend({},opts.currency,op);
  15498. sep = op.thousandsSeparator.replace(re,"\\$1");
  15499. stripTag = new RegExp(sep, "g");
  15500. ret = $(cellval).text();
  15501. if (op.prefix && op.prefix.length) {
  15502. ret = ret.substr(op.prefix.length);
  15503. }
  15504. if (op.suffix && op.suffix.length) {
  15505. ret = ret.substr(0, ret.length - op.suffix.length);
  15506. }
  15507. ret = ret.replace(stripTag,'').replace(op.decimalSeparator,'.');
  15508. break;
  15509. case 'checkbox':
  15510. var cbv = (options.colModel.editoptions) ? options.colModel.editoptions.value.split(":") : ["Yes","No"];
  15511. ret = $('input',cellval).is(":checked") ? cbv[0] : cbv[1];
  15512. break;
  15513. case 'select' :
  15514. ret = $.unformat.select(cellval,options,pos,cnt);
  15515. break;
  15516. case 'actions':
  15517. return "";
  15518. default:
  15519. ret= $(cellval).text();
  15520. }
  15521. }
  15522. return ret !== undefined ? ret : cnt===true ? $(cellval).text() : $.jgrid.htmlDecode($(cellval).html());
  15523. };
  15524. $.unformat.select = function (cellval,options,pos,cnt) {
  15525. // Spacial case when we have local data and perform a sort
  15526. // cnt is set to true only in sortDataArray
  15527. var ret = [];
  15528. var cell = $(cellval).text();
  15529. if(cnt===true) {return cell;}
  15530. var op = $.extend({}, options.colModel.formatoptions !== undefined ? options.colModel.formatoptions: options.colModel.editoptions),
  15531. sep = op.separator === undefined ? ":" : op.separator,
  15532. delim = op.delimiter === undefined ? ";" : op.delimiter;
  15533. if(op.value){
  15534. var oSelect = op.value,
  15535. msl = op.multiple === true ? true : false,
  15536. scell = [], sv;
  15537. if(msl) {scell = cell.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
  15538. if ($.fmatter.isString(oSelect)) {
  15539. var so = oSelect.split(delim), j=0, i;
  15540. for(i=0; i<so.length;i++){
  15541. sv = so[i].split(sep);
  15542. if(sv.length > 2 ) {
  15543. sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep);
  15544. }
  15545. if(msl) {
  15546. if($.inArray($.trim(sv[1]),scell)>-1) {
  15547. ret[j] = sv[0];
  15548. j++;
  15549. }
  15550. } else if($.trim(sv[1]) === $.trim(cell)) {
  15551. ret[0] = sv[0];
  15552. break;
  15553. }
  15554. }
  15555. } else if($.fmatter.isObject(oSelect) || $.isArray(oSelect) ){
  15556. if(!msl) {scell[0] = cell;}
  15557. ret = $.map(scell, function(n){
  15558. var rv;
  15559. $.each(oSelect, function(i,val){
  15560. if (val === n) {
  15561. rv = i;
  15562. return false;
  15563. }
  15564. });
  15565. if( rv !== undefined ) {return rv;}
  15566. });
  15567. }
  15568. return ret.join(", ");
  15569. }
  15570. return cell || "";
  15571. };
  15572. $.unformat.date = function (cellval, opts) {
  15573. var op = $.jgrid.getRegional(this, 'formatter.date') || {};
  15574. if(opts.formatoptions !== undefined) {
  15575. op = $.extend({},op,opts.formatoptions);
  15576. }
  15577. if(!$.fmatter.isEmpty(cellval)) {
  15578. return $.jgrid.parseDate.call(this, op.newformat,cellval,op.srcformat,op);
  15579. }
  15580. return $.fn.fmatter.defaultFormat(cellval, opts);
  15581. };
  15582. //module begin
  15583. var dragging, placeholders = $();
  15584. $.fn.html5sortable = function(options) {
  15585. var method = String(options);
  15586. options = $.extend({
  15587. connectWith: false
  15588. }, options);
  15589. return this.each(function() {
  15590. var items;
  15591. if (/^enable|disable|destroy$/.test(method)) {
  15592. items = $(this).children($(this).data('items')).attr('draggable', method === 'enable');
  15593. if (method === 'destroy') {
  15594. items.add(this).removeData('connectWith items')
  15595. .off('dragstart.h5s dragend.h5s selectstart.h5s dragover.h5s dragenter.h5s drop.h5s');
  15596. }
  15597. return;
  15598. }
  15599. var isHandle, index;
  15600. items = $(this).children(options.items);
  15601. var placeholder = $('<' + (/^ul|ol$/i.test(this.tagName) ? 'li' : /^tbody$/i.test(this.tagName) ? 'tr' : 'div') +
  15602. ' class="sortable-placeholder ' + options.placeholderClass + '">').html('&nbsp;');
  15603. items.find(options.handle).mousedown(function() {
  15604. isHandle = true;
  15605. }).mouseup(function() {
  15606. isHandle = false;
  15607. });
  15608. $(this).data('items', options.items);
  15609. placeholders = placeholders.add(placeholder);
  15610. if (options.connectWith) {
  15611. $(options.connectWith).add(this).data('connectWith', options.connectWith);
  15612. }
  15613. items.attr('draggable', 'true').on('dragstart.h5s', function(e) {
  15614. if (options.handle && !isHandle) {
  15615. return false;
  15616. }
  15617. isHandle = false;
  15618. var dt = e.originalEvent.dataTransfer;
  15619. dt.effectAllowed = 'move';
  15620. dt.setData('Text', 'dummy');
  15621. index = (dragging = $(this)).addClass('sortable-dragging').index();
  15622. }).on('dragend.h5s', function() {
  15623. if (!dragging) {
  15624. return;
  15625. }
  15626. dragging.removeClass('sortable-dragging').show();
  15627. placeholders.detach();
  15628. if (index !== dragging.index()) {
  15629. dragging.parent().trigger('sortupdate', {item: dragging, startindex: index, endindex: dragging.index()});
  15630. }
  15631. dragging = null;
  15632. }).not('a[href], img').on('selectstart.h5s', function() {
  15633. this.dragDrop && this.dragDrop();
  15634. return false;
  15635. }).end().add([this, placeholder]).on('dragover.h5s dragenter.h5s drop.h5s', function(e) {
  15636. if (!items.is(dragging) && options.connectWith !== $(dragging).parent().data('connectWith')) {
  15637. return true;
  15638. }
  15639. if (e.type === 'drop') {
  15640. e.stopPropagation();
  15641. placeholders.filter(':visible').after(dragging);
  15642. dragging.trigger('dragend.h5s');
  15643. return false;
  15644. }
  15645. e.preventDefault();
  15646. e.originalEvent.dataTransfer.dropEffect = 'move';
  15647. if (items.is(this)) {
  15648. if (options.forcePlaceholderSize) {
  15649. placeholder.height(dragging.outerHeight());
  15650. }
  15651. dragging.hide();
  15652. $(this)[placeholder.index() < $(this).index() ? 'after' : 'before'](placeholder);
  15653. placeholders.not(placeholder).detach();
  15654. } else if (!placeholders.is(this) && !$(this).children(options.items).length) {
  15655. placeholders.detach();
  15656. $(this).append(placeholder);
  15657. }
  15658. return false;
  15659. });
  15660. });
  15661. };
  15662. //module begin
  15663. $.extend($.jgrid,{
  15664. //window.jqGridUtils = {
  15665. stringify : function(obj) {
  15666. return JSON.stringify(obj,function(key, value){
  15667. return (typeof value === 'function' ) ? value.toString() : value;
  15668. });
  15669. },
  15670. parseFunc : function(str) {
  15671. return JSON.parse(str,function(key, value){
  15672. if(typeof value === "string" && value.indexOf("function") !== -1) {
  15673. var sv = value.split(" ");
  15674. if(sv[0].trim() === 'function' && value.trim().slice(-1) === "}") {
  15675. return eval('('+value+')');
  15676. } else {
  15677. return value;
  15678. }
  15679. }
  15680. return value;
  15681. });
  15682. },
  15683. encode : function ( text ) { // repeated, but should not depend on grid
  15684. return String(text).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
  15685. },
  15686. jsonToXML : function ( tree, options ) {
  15687. var o = $.extend( {
  15688. xmlDecl : '<?xml version="1.0" encoding="UTF-8" ?>\n',
  15689. attr_prefix : '-',
  15690. encode : true
  15691. }, options || {}),
  15692. that = this,
  15693. scalarToxml = function ( name, text ) {
  15694. if ( name === "#text" ) {
  15695. return (o.encode ? that.encode(text) : text);
  15696. } else if(typeof(text) ==='function') {
  15697. return "<"+name+"><![CDATA["+ text +"]]></"+name+">\n";
  15698. } if(text === "") {
  15699. return "<"+name+">__EMPTY_STRING_</"+name+">\n";
  15700. } else {
  15701. return "<"+name+">"+(o.encode ? that.encode(text) : text )+"</"+name+">\n";
  15702. }
  15703. },
  15704. arrayToxml = function ( name, array ) {
  15705. var out = [];
  15706. for( var i=0; i<array.length; i++ ) {
  15707. var val = array[i];
  15708. if ( typeof(val) === "undefined" || val == null ) {
  15709. out[out.length] = "<"+name+" />";
  15710. } else if ( typeof(val) === "object" && val.constructor == Array ) {
  15711. out[out.length] = arrayToxml( name, val );
  15712. } else if ( typeof(val) === "object" ) {
  15713. out[out.length] = hashToxml( name, val );
  15714. } else {
  15715. out[out.length] = scalarToxml( name, val );
  15716. }
  15717. }
  15718. if(!out.length) {
  15719. out[0] = "<"+ name+">__EMPTY_ARRAY_</"+name+">\n";
  15720. }
  15721. return out.join("");
  15722. },
  15723. hashToxml = function ( name, tree ) {
  15724. var elem = [];
  15725. var attr = [];
  15726. for( var key in tree ) {
  15727. if ( ! tree.hasOwnProperty(key) ) continue;
  15728. var val = tree[key];
  15729. if ( key.charAt(0) !== o.attr_prefix ) {
  15730. if ( val == null ) { // null or undefined
  15731. elem[elem.length] = "<"+key+" />";
  15732. } else if ( typeof(val) === "object" && val.constructor === Array ) {
  15733. elem[elem.length] = arrayToxml( key, val );
  15734. } else if ( typeof(val) === "object" ) {
  15735. elem[elem.length] = hashToxml( key, val );
  15736. } else {
  15737. elem[elem.length] = scalarToxml( key, val );
  15738. }
  15739. } else {
  15740. attr[attr.length] = " "+(key.substring(1))+'="'+(o.encode ? that.encode( val ) : val)+'"';
  15741. }
  15742. }
  15743. var jattr = attr.join("");
  15744. var jelem = elem.join("");
  15745. if ( name == null ) { // null or undefined
  15746. // no tag
  15747. } else if ( elem.length > 0 ) {
  15748. if ( jelem.match( /\n/ )) {
  15749. jelem = "<"+name+jattr+">\n"+jelem+"</"+name+">\n";
  15750. } else {
  15751. jelem = "<"+name+jattr+">" +jelem+"</"+name+">\n";
  15752. }
  15753. } else {
  15754. jelem = "<"+name+jattr+" />\n";
  15755. }
  15756. return jelem;
  15757. };
  15758. var xml = hashToxml( null, tree );
  15759. return o.xmlDecl + xml;
  15760. },
  15761. xmlToJSON : function ( root, options ) {
  15762. var o = $.extend ( {
  15763. force_array : [], //[ "rdf:li", "item", "-xmlns" ];
  15764. attr_prefix : '-'
  15765. }, options || {} );
  15766. if(!root) { return; }
  15767. var __force_array = {};
  15768. if ( o.force_array ) {
  15769. for( var i=0; i< o.force_array.length; i++ ) {
  15770. __force_array[o.force_array[i]] = 1;
  15771. }
  15772. }
  15773. if(typeof root === 'string') {
  15774. root = $.parseXML(root);
  15775. }
  15776. if(root.documentElement) {
  15777. root = root.documentElement;
  15778. }
  15779. var addNode = function ( hash, key, cnts, val ) {
  15780. if(typeof val === 'string') {
  15781. if( val.indexOf('function') !== -1) {
  15782. val = eval( '(' + val +')'); // we need this in our implement
  15783. } else {
  15784. switch(val) {
  15785. case '__EMPTY_ARRAY_' :
  15786. val = [];
  15787. break;
  15788. case '__EMPTY_STRING_':
  15789. val = "";
  15790. break;
  15791. case "false" :
  15792. val = false;
  15793. break;
  15794. case "true":
  15795. val = true;
  15796. break;
  15797. }
  15798. }
  15799. }
  15800. if ( __force_array[key] ) {
  15801. if ( cnts === 1 ) {
  15802. hash[key] = [];
  15803. }
  15804. hash[key][hash[key].length] = val; // push
  15805. } else if ( cnts === 1 ) { // 1st sibling
  15806. hash[key] = val;
  15807. } else if ( cnts === 2 ) { // 2nd sibling
  15808. hash[key] = [ hash[key], val ];
  15809. } else { // 3rd sibling and more
  15810. hash[key][hash[key].length] = val;
  15811. }
  15812. },
  15813. parseElement = function ( elem ) {
  15814. // COMMENT_NODE
  15815. if ( elem.nodeType === 7 ) {
  15816. return;
  15817. }
  15818. // TEXT_NODE CDATA_SECTION_NODE
  15819. if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
  15820. var bool = elem.nodeValue.match( /[^\x00-\x20]/ );
  15821. if ( bool == null ) return; // ignore white spaces
  15822. return elem.nodeValue;
  15823. }
  15824. var retval, cnt = {}, i, key, val;
  15825. // parse attributes
  15826. if ( elem.attributes && elem.attributes.length ) {
  15827. retval = {};
  15828. for ( i=0; i<elem.attributes.length; i++ ) {
  15829. key = elem.attributes[i].nodeName;
  15830. if ( typeof(key) !== "string" ) {
  15831. continue;
  15832. }
  15833. val = elem.attributes[i].nodeValue;
  15834. if ( ! val ) {
  15835. continue;
  15836. }
  15837. key = o.attr_prefix + key;
  15838. if ( typeof(cnt[key]) === "undefined" ) {
  15839. cnt[key] = 0;
  15840. }
  15841. cnt[key] ++;
  15842. addNode( retval, key, cnt[key], val );
  15843. }
  15844. }
  15845. // parse child nodes (recursive)
  15846. if ( elem.childNodes && elem.childNodes.length ) {
  15847. var textonly = true;
  15848. if ( retval ) {
  15849. textonly = false;
  15850. } // some attributes exists
  15851. for ( i=0; i<elem.childNodes.length && textonly; i++ ) {
  15852. var ntype = elem.childNodes[i].nodeType;
  15853. if ( ntype === 3 || ntype === 4 ) {
  15854. continue;
  15855. }
  15856. textonly = false;
  15857. }
  15858. if ( textonly ) {
  15859. if ( ! retval ) {
  15860. retval = "";
  15861. }
  15862. for ( i=0; i<elem.childNodes.length; i++ ) {
  15863. retval += elem.childNodes[i].nodeValue;
  15864. }
  15865. } else {
  15866. if ( ! retval ) {
  15867. retval = {};
  15868. }
  15869. for ( i=0; i<elem.childNodes.length; i++ ) {
  15870. key = elem.childNodes[i].nodeName;
  15871. if ( typeof(key) !== "string" ) {
  15872. continue;
  15873. }
  15874. val = parseElement( elem.childNodes[i] );
  15875. if ( !val ) {
  15876. continue;
  15877. }
  15878. if ( typeof(cnt[key]) === "undefined" ) {
  15879. cnt[key] = 0;
  15880. }
  15881. cnt[key] ++;
  15882. addNode( retval, key, cnt[key], val );
  15883. }
  15884. }
  15885. }
  15886. return retval;
  15887. };
  15888. var json = parseElement( root ); // parse root node
  15889. if ( __force_array[root.nodeName] ) {
  15890. json = [ json ];
  15891. }
  15892. if ( root.nodeType !== 11 ) { // DOCUMENT_FRAGMENT_NODE
  15893. var tmp = {};
  15894. tmp[root.nodeName] = json; // root nodeName
  15895. json = tmp;
  15896. }
  15897. return json;
  15898. },
  15899. saveAs : function (data, fname, opts) {
  15900. opts = $.extend(true,{
  15901. type : 'plain/text;charset=utf-8'
  15902. }, opts || {});
  15903. var file, url, tmp = [];
  15904. fname = fname == null || fname === '' ? 'jqGridFile.txt' : fname;
  15905. if(!$.isArray(data) ) {
  15906. tmp[0]= data ;
  15907. } else {
  15908. tmp = data;
  15909. }
  15910. try {
  15911. file = new File(tmp, fname, opts);
  15912. } catch (e) {
  15913. file = new Blob(tmp, opts);
  15914. }
  15915. if ( window.navigator && window.navigator.msSaveOrOpenBlob) {
  15916. window.navigator.msSaveOrOpenBlob( file , fname );
  15917. } else {
  15918. url = URL.createObjectURL(file);
  15919. var a = document.createElement("a");
  15920. a.href = url;
  15921. a.download = fname;
  15922. document.body.appendChild(a);
  15923. a.click();
  15924. setTimeout(function() {
  15925. document.body.removeChild(a);
  15926. window.URL.revokeObjectURL(url);
  15927. }, 0);
  15928. }
  15929. }
  15930. });
  15931. //module begin
  15932. $.jgrid = $.jgrid || {};
  15933. $.extend($.jgrid,{
  15934. formatCell : function ( cellval , colpos, rwdat, cm, $t){
  15935. var v;
  15936. if(cm.formatter !== undefined) {
  15937. var opts= {rowId: '', colModel:cm, gid: $t.p.id, pos:colpos, styleUI: '' };
  15938. if($.isFunction( cm.formatter ) ) {
  15939. v = cm.formatter.call($t,cellval,opts,rwdat);
  15940. } else if($.fmatter){
  15941. v = $.fn.fmatter.call($t,cm.formatter,cellval,opts,rwdat);
  15942. } else {
  15943. v = cellval;
  15944. }
  15945. } else {
  15946. v = cellval;
  15947. }
  15948. return v;
  15949. },
  15950. formatCellCsv : function (v, p) {
  15951. v = v == null ? '' : String(v);
  15952. try {
  15953. v = v.replace(p._regexsep ,p.separatorReplace).replace(/\r\n/g, p.replaceNewLine).replace(/\n/g, p.replaceNewLine);
  15954. } catch (_e) {
  15955. v="";
  15956. }
  15957. if(p.escquote) {
  15958. v = v.replace(p._regexquot, p.escquote + p.quote);
  15959. }
  15960. if( v.indexOf(p.separator) === -1 || v.indexOf(p.qoute) === -1) {
  15961. v = p.quote + v + p.quote;
  15962. }
  15963. return v;
  15964. },
  15965. excelCellPos : function ( n ){
  15966. var ordA = 'A'.charCodeAt(0),
  15967. ordZ = 'Z'.charCodeAt(0),
  15968. len = ordZ - ordA + 1,
  15969. s = "";
  15970. while( n >= 0 ) {
  15971. s = String.fromCharCode(n % len + ordA) + s;
  15972. n = Math.floor(n / len) - 1;
  15973. }
  15974. return s;
  15975. },
  15976. makeNode : function ( root, elemName, options ) {
  15977. var currNode = root.createElement( elemName );
  15978. if ( options ) {
  15979. if ( options.attr ) {
  15980. $(currNode).attr( options.attr );
  15981. }
  15982. if( options.children ) {
  15983. $.each( options.children, function ( key, value ) {
  15984. currNode.appendChild( value );
  15985. });
  15986. }
  15987. if( options.text ) {
  15988. currNode.appendChild( root.createTextNode( options.text ) );
  15989. }
  15990. }
  15991. return currNode;
  15992. },
  15993. xmlToZip : function ( zip, obj ) {
  15994. var $t = this,
  15995. xmlserialiser = new XMLSerializer(),
  15996. // IE >= 9
  15997. ieExcel = xmlserialiser.serializeToString(
  15998. $.parseXML( $.jgrid.excelStrings['xl/worksheets/sheet1.xml'] ) )
  15999. .indexOf( 'xmlns:r' ) === -1,
  16000. newDir, worksheet, i, ien, attr, attrs = [], str;
  16001. $.each( obj, function ( name, val ) {
  16002. if ( $.isPlainObject( val ) ) {
  16003. newDir = zip.folder( name );
  16004. $t.xmlToZip( newDir, val );
  16005. } else {
  16006. if ( ieExcel ) {
  16007. worksheet = val.childNodes[0];
  16008. for ( i=worksheet.attributes.length-1 ; i>=0 ; i-- ) {
  16009. var attrName = worksheet.attributes[i].nodeName;
  16010. var attrValue = worksheet.attributes[i].nodeValue;
  16011. if ( attrName.indexOf( ':' ) !== -1 ) {
  16012. attrs.push( { name: attrName, value: attrValue } );
  16013. worksheet.removeAttribute( attrName );
  16014. }
  16015. }
  16016. for ( i=0, ien=attrs.length ; i<ien ; i++ ) {
  16017. attr = val.createAttribute( attrs[i].name.replace( ':', '_dt_b_namespace_token_' ) );
  16018. attr.value = attrs[i].value;
  16019. worksheet.setAttributeNode( attr );
  16020. }
  16021. }
  16022. // suuport of all browsers
  16023. str = xmlserialiser.serializeToString(val);
  16024. // Fix IE's XML
  16025. if ( ieExcel ) {
  16026. if ( str.indexOf( '<?xml' ) === -1 ) {
  16027. str = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+str;
  16028. }
  16029. str = str.replace( /_dt_b_namespace_token_/g, ':' );
  16030. }
  16031. str = str
  16032. .replace( /<row xmlns="" /g, '<row ' )
  16033. .replace( /<cols xmlns="">/g, '<cols>' )
  16034. .replace( /<mergeCells xmlns="" /g, '<mergeCells ' );
  16035. zip.file( name, str );
  16036. }
  16037. } );
  16038. },
  16039. // Excel - Pre-defined strings to build a basic XLSX file
  16040. excelStrings : {
  16041. "_rels/.rels":
  16042. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+
  16043. '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'+
  16044. '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>'+
  16045. '</Relationships>',
  16046. "xl/_rels/workbook.xml.rels":
  16047. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+
  16048. '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'+
  16049. '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>'+
  16050. '<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>'+
  16051. '</Relationships>',
  16052. "[Content_Types].xml":
  16053. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+
  16054. '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">'+
  16055. '<Default Extension="xml" ContentType="application/xml" />'+
  16056. '<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />'+
  16057. '<Default Extension="jpeg" ContentType="image/jpeg" />'+
  16058. '<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml" />'+
  16059. '<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" />'+
  16060. '<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml" />'+
  16061. '</Types>',
  16062. "xl/workbook.xml":
  16063. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+
  16064. '<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">'+
  16065. '<fileVersion appName="xl" lastEdited="5" lowestEdited="5" rupBuild="24816"/>'+
  16066. '<workbookPr showInkAnnotation="0" autoCompressPictures="0"/>'+
  16067. '<bookViews>'+
  16068. '<workbookView xWindow="0" yWindow="0" windowWidth="25600" windowHeight="19020" tabRatio="500"/>'+
  16069. '</bookViews>'+
  16070. '<sheets>'+
  16071. '<sheet name="Sheet1" sheetId="1" r:id="rId1"/>'+
  16072. '</sheets>'+
  16073. '</workbook>',
  16074. "xl/worksheets/sheet1.xml":
  16075. '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+
  16076. '<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac">'+
  16077. '<sheetData/>'+
  16078. '</worksheet>',
  16079. "xl/styles.xml":
  16080. '<?xml version="1.0" encoding="UTF-8"?>'+
  16081. '<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac">'+
  16082. '<fonts count="5" x14ac:knownFonts="1">'+
  16083. '<font>'+
  16084. '<sz val="11" />'+
  16085. '<name val="Calibri" />'+
  16086. '</font>'+
  16087. '<font>'+
  16088. '<sz val="11" />'+
  16089. '<name val="Calibri" />'+
  16090. '<color rgb="FFFFFFFF" />'+
  16091. '</font>'+
  16092. '<font>'+
  16093. '<sz val="11" />'+
  16094. '<name val="Calibri" />'+
  16095. '<b />'+
  16096. '</font>'+
  16097. '<font>'+
  16098. '<sz val="11" />'+
  16099. '<name val="Calibri" />'+
  16100. '<i />'+
  16101. '</font>'+
  16102. '<font>'+
  16103. '<sz val="11" />'+
  16104. '<name val="Calibri" />'+
  16105. '<u />'+
  16106. '</font>'+
  16107. '</fonts>'+
  16108. '<fills count="6">'+
  16109. '<fill>'+
  16110. '<patternFill patternType="none" />'+
  16111. '</fill>'+
  16112. '<fill/>'+
  16113. '<fill>'+
  16114. '<patternFill patternType="solid">'+
  16115. '<fgColor rgb="FFD9D9D9" />'+
  16116. '<bgColor indexed="64" />'+
  16117. '</patternFill>'+
  16118. '</fill>'+
  16119. '<fill>'+
  16120. '<patternFill patternType="solid">'+
  16121. '<fgColor rgb="FFD99795" />'+
  16122. '<bgColor indexed="64" />'+
  16123. '</patternFill>'+
  16124. '</fill>'+
  16125. '<fill>'+
  16126. '<patternFill patternType="solid">'+
  16127. '<fgColor rgb="ffc6efce" />'+
  16128. '<bgColor indexed="64" />'+
  16129. '</patternFill>'+
  16130. '</fill>'+
  16131. '<fill>'+
  16132. '<patternFill patternType="solid">'+
  16133. '<fgColor rgb="ffc6cfef" />'+
  16134. '<bgColor indexed="64" />'+
  16135. '</patternFill>'+
  16136. '</fill>'+
  16137. '</fills>'+
  16138. '<borders count="2">'+
  16139. '<border>'+
  16140. '<left />'+
  16141. '<right />'+
  16142. '<top />'+
  16143. '<bottom />'+
  16144. '<diagonal />'+
  16145. '</border>'+
  16146. '<border diagonalUp="false" diagonalDown="false">'+
  16147. '<left style="thin">'+
  16148. '<color auto="1" />'+
  16149. '</left>'+
  16150. '<right style="thin">'+
  16151. '<color auto="1" />'+
  16152. '</right>'+
  16153. '<top style="thin">'+
  16154. '<color auto="1" />'+
  16155. '</top>'+
  16156. '<bottom style="thin">'+
  16157. '<color auto="1" />'+
  16158. '</bottom>'+
  16159. '<diagonal />'+
  16160. '</border>'+
  16161. '</borders>'+
  16162. '<cellStyleXfs count="1">'+
  16163. '<xf numFmtId="0" fontId="0" fillId="0" borderId="0" />'+
  16164. '</cellStyleXfs>'+
  16165. '<cellXfs count="2">'+
  16166. '<xf numFmtId="0" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16167. '<xf numFmtId="0" fontId="1" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16168. '<xf numFmtId="0" fontId="2" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1"><alignment horizontal="center" /></xf>'+
  16169. '<xf numFmtId="0" fontId="3" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16170. '<xf numFmtId="0" fontId="4" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16171. '<xf numFmtId="0" fontId="0" fillId="2" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16172. '<xf numFmtId="0" fontId="1" fillId="2" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16173. '<xf numFmtId="0" fontId="2" fillId="2" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16174. '<xf numFmtId="0" fontId="3" fillId="2" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16175. '<xf numFmtId="0" fontId="4" fillId="2" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16176. '<xf numFmtId="0" fontId="0" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16177. '<xf numFmtId="0" fontId="1" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16178. '<xf numFmtId="0" fontId="2" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16179. '<xf numFmtId="0" fontId="3" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16180. '<xf numFmtId="0" fontId="4" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16181. '<xf numFmtId="0" fontId="0" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16182. '<xf numFmtId="0" fontId="1" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16183. '<xf numFmtId="0" fontId="2" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16184. '<xf numFmtId="0" fontId="3" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16185. '<xf numFmtId="0" fontId="4" fillId="4" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16186. '<xf numFmtId="0" fontId="0" fillId="5" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16187. '<xf numFmtId="0" fontId="1" fillId="5" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16188. '<xf numFmtId="0" fontId="2" fillId="5" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16189. '<xf numFmtId="0" fontId="3" fillId="5" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16190. '<xf numFmtId="0" fontId="4" fillId="5" borderId="0" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16191. '<xf numFmtId="0" fontId="0" fillId="0" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16192. '<xf numFmtId="0" fontId="1" fillId="0" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16193. '<xf numFmtId="0" fontId="2" fillId="0" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16194. '<xf numFmtId="0" fontId="3" fillId="0" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16195. '<xf numFmtId="0" fontId="4" fillId="0" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16196. '<xf numFmtId="0" fontId="0" fillId="2" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16197. '<xf numFmtId="0" fontId="1" fillId="2" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16198. '<xf numFmtId="0" fontId="2" fillId="2" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16199. '<xf numFmtId="0" fontId="3" fillId="2" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16200. '<xf numFmtId="0" fontId="4" fillId="2" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16201. '<xf numFmtId="0" fontId="0" fillId="3" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16202. '<xf numFmtId="0" fontId="1" fillId="3" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16203. '<xf numFmtId="0" fontId="2" fillId="3" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16204. '<xf numFmtId="0" fontId="3" fillId="3" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16205. '<xf numFmtId="0" fontId="4" fillId="3" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16206. '<xf numFmtId="0" fontId="0" fillId="4" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16207. '<xf numFmtId="0" fontId="1" fillId="4" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16208. '<xf numFmtId="0" fontId="2" fillId="4" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16209. '<xf numFmtId="0" fontId="3" fillId="4" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16210. '<xf numFmtId="0" fontId="4" fillId="4" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16211. '<xf numFmtId="0" fontId="0" fillId="5" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16212. '<xf numFmtId="0" fontId="1" fillId="5" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16213. '<xf numFmtId="0" fontId="2" fillId="5" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16214. '<xf numFmtId="0" fontId="3" fillId="5" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16215. '<xf numFmtId="0" fontId="4" fillId="5" borderId="1" applyFont="1" applyFill="1" applyBorder="1"/>'+
  16216. '</cellXfs>'+
  16217. '<cellStyles count="1">'+
  16218. '<cellStyle name="Normal" xfId="0" builtinId="0" />'+
  16219. '</cellStyles>'+
  16220. '<dxfs count="0" />'+
  16221. '<tableStyles count="0" defaultTableStyle="TableStyleMedium9" defaultPivotStyle="PivotStyleMedium4" />'+
  16222. '</styleSheet>'
  16223. }
  16224. });
  16225. /********************************************************************
  16226. *
  16227. * due to speed, every export method will have separate module
  16228. * to collect grouped data
  16229. *
  16230. *********************************************************************/
  16231. $.jgrid.extend({
  16232. exportToCsv : function ( p ) {
  16233. p = $.extend(true, {
  16234. separator: ",",
  16235. separatorReplace : " ",
  16236. quote : '"',
  16237. escquote : '"',
  16238. newLine : "\r\n", // navigator.userAgent.match(/Windows/) ? '\r\n' : '\n';
  16239. replaceNewLine : " ",
  16240. includeCaption : true,
  16241. includeLabels : true,
  16242. includeGroupHeader : true,
  16243. includeFooter: true,
  16244. fileName : "jqGridExport.csv",
  16245. mimetype : "text/csv;charset=utf-8",
  16246. returnAsString : false
  16247. }, p || {});
  16248. var ret ="";
  16249. this.each(function(){
  16250. p._regexsep = new RegExp(p.separator, "g");
  16251. p._regexquot = new RegExp(p.quote, "g");
  16252. var $t = this,
  16253. // get the filtered data
  16254. data1 = this.addLocalData( true ),
  16255. dlen = data1.length,
  16256. cm = $t.p.colModel,
  16257. cmlen = cm.length,
  16258. clbl = $t.p.colNames,
  16259. i, j=0, row, str = '' , tmp, k,
  16260. cap = "", hdr = "", ftr="", lbl="", albl=[], restorevis = [];
  16261. function groupToCsv (grdata, p) {
  16262. var str="",
  16263. grp = $t.p.groupingView,
  16264. cp=[], len =grp.groupField.length,
  16265. cm = $t.p.colModel,
  16266. colspans = cm.length,
  16267. toEnd = 0;
  16268. $.each(cm, function (i,n){
  16269. var ii;
  16270. for(ii=0;ii<len;ii++) {
  16271. if(grp.groupField[ii] === n.name ) {
  16272. cp[ii] = i;
  16273. break;
  16274. }
  16275. }
  16276. });
  16277. function findGroupIdx( ind , offset, grp) {
  16278. var ret = false, i;
  16279. if(offset===0) {
  16280. ret = grp[ind];
  16281. } else {
  16282. var id = grp[ind].idx;
  16283. if(id===0) {
  16284. ret = grp[ind];
  16285. } else {
  16286. for(i=ind;i >= 0; i--) {
  16287. if(grp[i].idx === id-offset) {
  16288. ret = grp[i];
  16289. break;
  16290. }
  16291. }
  16292. }
  16293. }
  16294. return ret;
  16295. }
  16296. function buildSummaryTd(i, ik, grp, foffset) {
  16297. var fdata = findGroupIdx(i, ik, grp),
  16298. //cm = $t.p.colModel,
  16299. vv, grlen = fdata.cnt, k, retarr= new Array(p.collen), j=0;
  16300. for(k=foffset; k<colspans;k++) {
  16301. if(cm[k].hidden) {
  16302. continue;
  16303. }
  16304. var tplfld = "{0}";
  16305. $.each(fdata.summary,function(){
  16306. if(this.nm === cm[k].name) {
  16307. if(cm[k].summaryTpl) {
  16308. tplfld = cm[k].summaryTpl;
  16309. }
  16310. if(typeof this.st === 'string' && this.st.toLowerCase() === 'avg') {
  16311. if(this.sd && this.vd) {
  16312. this.v = (this.v/this.vd);
  16313. } else if(this.v && grlen > 0) {
  16314. this.v = (this.v/grlen);
  16315. }
  16316. }
  16317. try {
  16318. this.groupCount = fdata.cnt;
  16319. this.groupIndex = fdata.dataIndex;
  16320. this.groupValue = fdata.value;
  16321. vv = $t.formatter('', this.v, k, this);
  16322. } catch (ef) {
  16323. vv = this.v;
  16324. }
  16325. retarr[j] =
  16326. $.jgrid.formatCellCsv(
  16327. $.jgrid.stripHtml(
  16328. $.jgrid.template(tplfld,vv)
  16329. ), p ) ;
  16330. return false;
  16331. }
  16332. });
  16333. j++;
  16334. }
  16335. return retarr;
  16336. }
  16337. var sumreverse = $.makeArray(grp.groupSummary), gv, k;
  16338. sumreverse.reverse();
  16339. $.each(grp.groups,function(i,n){
  16340. toEnd++;
  16341. try {
  16342. if ($.isArray(grp.formatDisplayField) && $.isFunction(grp.formatDisplayField[n.idx])) {
  16343. gv = grp.formatDisplayField[n.idx].call($t, n.displayValue, n.value, $t.p.colModel[cp[n.idx]], n.idx, grp);
  16344. } else {
  16345. gv = $t.formatter('', n.displayValue, cp[n.idx], n.value );
  16346. }
  16347. } catch (egv) {
  16348. gv = n.displayValue;
  16349. }
  16350. var grpTextStr = '';
  16351. if($.isFunction(grp.groupText[n.idx])) {
  16352. grpTextStr = grp.groupText[n.idx].call($t, gv, n.cnt, n.summary);
  16353. } else {
  16354. grpTextStr = $.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary);
  16355. }
  16356. if( !(typeof grpTextStr ==='string' || typeof grpTextStr ==='number' ) ) {
  16357. grpTextStr = gv;
  16358. }
  16359. var arr;
  16360. if(grp.groupSummaryPos[n.idx] === 'header') {
  16361. arr = buildSummaryTd(i, 0, grp.groups, 0 /*grp.groupColumnShow[n.idx] === false ? (mul ==="" ? 2 : 3) : ((mul ==="") ? 1 : 2)*/ );
  16362. } else {
  16363. arr = new Array(p.collen);
  16364. }
  16365. arr[0] = $.jgrid.formatCellCsv( $.jgrid.stripHtml( grpTextStr ), p);
  16366. str += arr.join( p.separator ) + p.newLine;
  16367. var leaf = len-1 === n.idx;
  16368. if( leaf ) {
  16369. var gg = grp.groups[i+1], kk, ik, offset = 0, sgr = n.startRow, to,
  16370. end = gg !== undefined ? gg.startRow : grp.groups[i].startRow + grp.groups[i].cnt;
  16371. for(kk=sgr;kk<end;kk++) {
  16372. if(!grdata[kk - offset]) { break; }
  16373. to = grdata[kk - offset];
  16374. k = 0;
  16375. for(ik = 0; ik < cm.length; ik++) {
  16376. if(!cm[ik].hidden) {
  16377. arr[k] = $.jgrid.formatCellCsv(
  16378. $.jgrid.formatCell( to[cm[ik].name], ik, to, cm[ik], $t ) , p);
  16379. k++;
  16380. }
  16381. }
  16382. str += arr.join( p.separator ) + p.newLine;
  16383. }
  16384. if(grp.groupSummaryPos[n.idx] !== 'header') {
  16385. var jj;
  16386. if (gg !== undefined) {
  16387. for (jj = 0; jj < grp.groupField.length; jj++) {
  16388. if (gg.dataIndex === grp.groupField[jj]) {
  16389. break;
  16390. }
  16391. }
  16392. toEnd = grp.groupField.length - jj;
  16393. }
  16394. for (ik = 0; ik < toEnd; ik++) {
  16395. if(!sumreverse[ik]) { continue; }
  16396. arr = buildSummaryTd(i, ik, grp.groups, 0);
  16397. str += arr.join( p.separator ) + p.newLine;
  16398. }
  16399. toEnd = jj;
  16400. }
  16401. }
  16402. });
  16403. return str;
  16404. }
  16405. // end group function
  16406. var def = [], key, restorexcol=[];
  16407. $.each(cm,function(i,n) {
  16408. if(n.exportcol === undefined) {
  16409. n.exportcol = true;
  16410. }
  16411. if((n.name === 'cb' || n.name === 'rn') && !n.hidden) {
  16412. restorevis.push(i);
  16413. n.hidden = true;
  16414. }
  16415. if(!n.exportcol) {
  16416. if(!n.hidden) {
  16417. restorexcol.push(i);
  16418. n.hidden = true;
  16419. }
  16420. }
  16421. if(!n.hidden && n.exportcol) {
  16422. albl.push( $.jgrid.formatCellCsv( clbl[i], p) );
  16423. def.push( n.name ); // clbl[i];
  16424. }
  16425. });
  16426. if(p.includeLabels) {
  16427. lbl = albl.join( p.separator ) + p.newLine;
  16428. }
  16429. p.collen = albl.length;
  16430. if( $t.p.grouping ) {
  16431. str += groupToCsv(data1, p);
  16432. } else {
  16433. while(j < dlen) {
  16434. row = data1[j];
  16435. tmp = [];
  16436. k =0;
  16437. for(i = 0; i < cmlen; i++) {
  16438. if(!cm[i].hidden) {
  16439. tmp[k] = $.jgrid.formatCellCsv( $.jgrid.formatCell( row[cm[i].name], i, row, cm[i], $t ), p );
  16440. k++;
  16441. }
  16442. }
  16443. str += tmp.join( p.separator ) + p.newLine;
  16444. j++;
  16445. }
  16446. }
  16447. data1 = null; // free
  16448. // get the column length.
  16449. tmp = new Array(p.collen);
  16450. if(p.includeCaption && $t.p.caption) {
  16451. j=p.collen;
  16452. while(--j) {tmp[j]="";}
  16453. tmp[0] = $.jgrid.formatCellCsv( $t.p.caption, p );
  16454. cap += tmp.join( p.separator ) + p.newLine;
  16455. }
  16456. if(p.includeGroupHeader && $t.p.groupHeader && $t.p.groupHeader.length) {
  16457. var gh = $t.p.groupHeader;
  16458. for (i=0;i < gh.length; i++) {
  16459. var ghdata = gh[i].groupHeaders;
  16460. j = 0; tmp = [];
  16461. for(key=0; key<def.length; key++ ) {
  16462. //if(!def.hasOwnProperty( key )) {
  16463. // continue;
  16464. //}
  16465. tmp[j] = '';
  16466. for(k=0;k<ghdata.length;k++) {
  16467. if(ghdata[k].startColumnName === def[key]) {
  16468. tmp[j]= $.jgrid.formatCellCsv( ghdata[k].titleText, p);
  16469. }
  16470. }
  16471. j++;
  16472. }
  16473. hdr += tmp.join( p.separator ) + p.newLine;
  16474. }
  16475. }
  16476. if(p.includeFooter && $t.p.footerrow) {
  16477. // already formated
  16478. var foot = $(".ui-jqgrid-ftable", this.sDiv);
  16479. if(foot.length) {
  16480. var frows = foot[0].rows[0];
  16481. i=0;j=0; tmp=[];
  16482. while(i < frows.cells.length){
  16483. var fc = frows.cells[i],
  16484. coln = $(fc).attr('aria-describedby').slice(-3);
  16485. if(!fc.hidden && coln !== '_cb' && coln !== '_rn' ) {
  16486. tmp[j] = $.jgrid.formatCellCsv( $(fc).text(), p );
  16487. j++;
  16488. }
  16489. i++;
  16490. }
  16491. ftr += tmp.join( p.separator ) + p.newLine;
  16492. }
  16493. }
  16494. ret = cap + hdr + lbl + str + ftr;
  16495. for(i=0;i<restorevis.length;i++) {
  16496. cm[restorevis[i]].hidden = false;
  16497. }
  16498. for(i=0;i<restorexcol.length;i++) {
  16499. cm[restorexcol[i]].hidden = false;
  16500. }
  16501. });
  16502. if (p.returnAsString) {
  16503. return ret;
  16504. } else {
  16505. $.jgrid.saveAs( ret, p.fileName, { type : p.mimetype });
  16506. }
  16507. },
  16508. /*
  16509. *
  16510. * @param object o - settings for the export
  16511. * @returns excel 2007 document
  16512. * The method requiere jsZip lib in order to create excel document
  16513. */
  16514. exportToExcel : function ( o ) {
  16515. o = $.extend(true, {
  16516. includeLabels : true,
  16517. includeGroupHeader : true,
  16518. includeFooter: true,
  16519. fileName : "jqGridExport.xlsx",
  16520. mimetype : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  16521. maxlength : 40, // maxlength for visible string data
  16522. onBeforeExport : null,
  16523. replaceStr : null
  16524. }, o || {} );
  16525. this.each(function() {
  16526. var $t = this,
  16527. es = $.jgrid.excelStrings,
  16528. rowPos = 0,
  16529. rels = $.parseXML( es['xl/worksheets/sheet1.xml']),
  16530. relsGet = rels.getElementsByTagName( "sheetData" )[0],
  16531. xlsx = {
  16532. _rels: {
  16533. ".rels": $.parseXML( es['_rels/.rels'])
  16534. },
  16535. xl: {
  16536. _rels: {
  16537. "workbook.xml.rels": $.parseXML( es['xl/_rels/workbook.xml.rels'])
  16538. },
  16539. "workbook.xml": $.parseXML( es['xl/workbook.xml']),
  16540. "styles.xml": $.parseXML( es['xl/styles.xml']),
  16541. "worksheets": {
  16542. "sheet1.xml": rels
  16543. }
  16544. },
  16545. "[Content_Types].xml": $.parseXML( es['[Content_Types].xml'])
  16546. },
  16547. cm = $t.p.colModel,
  16548. i=0, j, ien, //obj={},
  16549. data = {
  16550. body : $t.addLocalData( true ),
  16551. header : [],
  16552. footer : [],
  16553. width : [],
  16554. map : []
  16555. };
  16556. for ( j=0, ien=cm.length ; j<ien ; j++ ) {
  16557. if(cm[j].exportcol === undefined) {
  16558. cm[j].exportcol = true;
  16559. }
  16560. if(cm[j].hidden || cm[j].name === 'cb' || cm[j].name === 'rn' || !cm[j].exportcol) {
  16561. continue;
  16562. }
  16563. data.header[i] = cm[j].name;
  16564. data.width[ i ] = 5;
  16565. data.map[i] = j;
  16566. i++;
  16567. }
  16568. function _replStrFunc (v) {
  16569. return v.replace(/</g, '&lt;')
  16570. .replace(/>/g, '&gt;')
  16571. .replace(/[\x00-\x09\x0B\x0C\x0E-\x1F\x7F-\x9F]/g, '');
  16572. }
  16573. var _replStr = $.isFunction(o.replaceStr) ? o.replaceStr : _replStrFunc,
  16574. currentRow, rowNode,
  16575. addRow = function ( row, header ) {
  16576. currentRow = rowPos+1;
  16577. rowNode = $.jgrid.makeNode( rels, "row", { attr: {r:currentRow} } );
  16578. for ( var i =0; i < data.header.length; i++) {
  16579. // key = cm[i].name;
  16580. // Concat both the Cell Columns as a letter and the Row of the cell.
  16581. var cellId = $.jgrid.excelCellPos(i) + '' + currentRow,
  16582. cell,
  16583. v= ($.isArray(row) && header) ? $t.p.colNames[data.map[i]] : row[ data.header[i] ];
  16584. if ( v == null ) {
  16585. v = '';
  16586. }
  16587. if(!header) {
  16588. v = v !== '' ? $.jgrid.formatCell( v, data.map[i], row, cm[data.map[i]], $t) : v;
  16589. }
  16590. data.width[i] = Math.max(data.width[i], Math.min(parseInt(v.length,10), o.maxlength) );
  16591. // Detect numbers - don't match numbers with leading zeros or a negative
  16592. // anywhere but the start
  16593. // $.jgrid.formatCell( row[cm[i].name], i, row, cm[i], $t )
  16594. if ( typeof v === 'number' || (
  16595. v.match &&
  16596. $.trim(v).match(/^-?\d+(\.\d+)?$/) &&
  16597. ! $.trim(v).match(/^0\d+/) )
  16598. ) {
  16599. cell = $.jgrid.makeNode( rels, 'c', {
  16600. attr: {
  16601. t: 'n',
  16602. r: cellId
  16603. },
  16604. children: [
  16605. $.jgrid.makeNode( rels, 'v', { text: v } )
  16606. ]
  16607. } );
  16608. } else {
  16609. // Replace non standard characters for text output
  16610. var text = ! v.replace ?
  16611. v : _replStr(v);
  16612. //$.jgrid.htmlEncode (v );
  16613. cell = $.jgrid.makeNode( rels, 'c', {
  16614. attr: {
  16615. t: 'inlineStr',
  16616. r: cellId
  16617. },
  16618. children:{
  16619. row: $.jgrid.makeNode( rels, 'is', {
  16620. children: {
  16621. row: $.jgrid.makeNode( rels, 't', {
  16622. text: text
  16623. } )
  16624. }
  16625. } )
  16626. }
  16627. } );
  16628. }
  16629. rowNode.appendChild( cell );
  16630. }
  16631. relsGet.appendChild(rowNode);
  16632. rowPos++;
  16633. };
  16634. //=========================================================================
  16635. function groupToExcel ( grdata ) {
  16636. var grp = $t.p.groupingView,
  16637. cp=[], len =grp.groupField.length,
  16638. colspans = cm.length,
  16639. toEnd = 0;
  16640. $.each(cm, function (i,n){
  16641. var ii;
  16642. for(ii=0;ii<len;ii++) {
  16643. if(grp.groupField[ii] === n.name ) {
  16644. cp[ii] = i;
  16645. break;
  16646. }
  16647. }
  16648. });
  16649. function findGroupIdx( ind , offset, grp) {
  16650. var ret = false, i;
  16651. if(offset===0) {
  16652. ret = grp[ind];
  16653. } else {
  16654. var id = grp[ind].idx;
  16655. if(id===0) {
  16656. ret = grp[ind];
  16657. } else {
  16658. for(i=ind;i >= 0; i--) {
  16659. if(grp[i].idx === id-offset) {
  16660. ret = grp[i];
  16661. break;
  16662. }
  16663. }
  16664. }
  16665. }
  16666. return ret;
  16667. }
  16668. function buildSummaryTd(i, ik, grp, foffset) {
  16669. var fdata = findGroupIdx(i, ik, grp),
  16670. //cm = $t.p.colModel,
  16671. vv, grlen = fdata.cnt, k, retarr = emptyData(data.header);
  16672. for(k=foffset; k<colspans;k++) {
  16673. if(cm[k].hidden || cm[k].exportcol) {
  16674. continue;
  16675. }
  16676. var tplfld = "{0}";
  16677. $.each(fdata.summary,function(){
  16678. if(this.nm === cm[k].name) {
  16679. if(cm[k].summaryTpl) {
  16680. tplfld = cm[k].summaryTpl;
  16681. }
  16682. if(typeof this.st === 'string' && this.st.toLowerCase() === 'avg') {
  16683. if(this.sd && this.vd) {
  16684. this.v = (this.v/this.vd);
  16685. } else if(this.v && grlen > 0) {
  16686. this.v = (this.v/grlen);
  16687. }
  16688. }
  16689. try {
  16690. this.groupCount = fdata.cnt;
  16691. this.groupIndex = fdata.dataIndex;
  16692. this.groupValue = fdata.value;
  16693. vv = $t.formatter('', this.v, k, this);
  16694. } catch (ef) {
  16695. vv = this.v;
  16696. }
  16697. retarr[this.nm] = $.jgrid.stripHtml( $.jgrid.template(tplfld,vv) );
  16698. return false;
  16699. }
  16700. });
  16701. }
  16702. return retarr;
  16703. }
  16704. function emptyData ( d ) {
  16705. var clone = {};
  16706. for(var key=0;key<d.length; key++ ) {
  16707. clone[ d[key] ] = "";
  16708. }
  16709. return clone;
  16710. }
  16711. var sumreverse = $.makeArray(grp.groupSummary), gv;
  16712. sumreverse.reverse();
  16713. $.each(grp.groups,function(i,n){
  16714. toEnd++;
  16715. try {
  16716. if ($.isArray(grp.formatDisplayField) && $.isFunction(grp.formatDisplayField[n.idx])) {
  16717. gv = grp.formatDisplayField[n.idx].call($t, n.displayValue, n.value, $t.p.colModel[cp[n.idx]], n.idx, grp);
  16718. } else {
  16719. gv = $t.formatter('', n.displayValue, cp[n.idx], n.value );
  16720. }
  16721. } catch (egv) {
  16722. gv = n.displayValue;
  16723. }
  16724. var grpTextStr = '';
  16725. if($.isFunction(grp.groupText[n.idx])) {
  16726. grpTextStr = grp.groupText[n.idx].call($t, gv, n.cnt, n.summary);
  16727. } else {
  16728. grpTextStr = $.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary);
  16729. }
  16730. if( !(typeof grpTextStr ==='string' || typeof grpTextStr ==='number' ) ) {
  16731. grpTextStr = gv;
  16732. }
  16733. var arr;
  16734. if(grp.groupSummaryPos[n.idx] === 'header') {
  16735. arr = buildSummaryTd(i, 0, grp.groups, 0 /*grp.groupColumnShow[n.idx] === false ? (mul ==="" ? 2 : 3) : ((mul ==="") ? 1 : 2)*/ );
  16736. } else {
  16737. arr = emptyData(data.header);
  16738. }
  16739. var fkey = Object.keys(arr);
  16740. arr[fkey[0]] = $.jgrid.stripHtml( new Array(n.idx*5).join(' ') + grpTextStr );
  16741. addRow( arr, true );
  16742. var leaf = len-1 === n.idx;
  16743. if( leaf ) {
  16744. var gg = grp.groups[i+1], kk, ik, offset = 0, sgr = n.startRow,
  16745. end = gg !== undefined ? gg.startRow : grp.groups[i].startRow + grp.groups[i].cnt;
  16746. for(kk=sgr;kk<end;kk++) {
  16747. if(!grdata[kk - offset]) { break; }
  16748. var to = grdata[kk - offset];
  16749. addRow( to, false );
  16750. }
  16751. if(grp.groupSummaryPos[n.idx] !== 'header') {
  16752. var jj;
  16753. if (gg !== undefined) {
  16754. for (jj = 0; jj < grp.groupField.length; jj++) {
  16755. if (gg.dataIndex === grp.groupField[jj]) {
  16756. break;
  16757. }
  16758. }
  16759. toEnd = grp.groupField.length - jj;
  16760. }
  16761. for (ik = 0; ik < toEnd; ik++) {
  16762. if(!sumreverse[ik]) { continue; }
  16763. arr = buildSummaryTd(i, ik, grp.groups, 0);
  16764. addRow( arr, true );
  16765. }
  16766. toEnd = jj;
  16767. }
  16768. }
  16769. });
  16770. }
  16771. //============================================================================
  16772. $( 'sheets sheet', xlsx.xl['workbook.xml'] ).attr( 'name', o.sheetName );
  16773. if(o.includeGroupHeader && $t.p.groupHeader && $t.p.groupHeader.length) {
  16774. var gh = $t.p.groupHeader, mergecell=[],
  16775. mrow = 0, key, l;
  16776. for (l = 0; l < gh.length; l++) {
  16777. var ghdata = gh[l].groupHeaders, clone ={};
  16778. mrow++; j=0;
  16779. for(j = 0; j < data.header.length; j++ ) {
  16780. key = data.header[j];
  16781. clone[key] = "";
  16782. for(var k = 0; k < ghdata.length; k++) {
  16783. if(ghdata[k].startColumnName === key) {
  16784. clone[key] = ghdata[k].titleText;
  16785. var start = $.jgrid.excelCellPos(j) + mrow,
  16786. end = $.jgrid.excelCellPos(j+ghdata[k].numberOfColumns -1) + mrow;
  16787. mergecell.push({ ref: start+":"+end });
  16788. }
  16789. }
  16790. }
  16791. addRow( clone, true );
  16792. }
  16793. $('row c', rels).attr( 's', '2' ); // bold
  16794. var merge = $.jgrid.makeNode( rels, 'mergeCells', {
  16795. attr : {
  16796. count : mergecell.length
  16797. }
  16798. });
  16799. $('worksheet', rels).append( merge );
  16800. for(i=0;i<mergecell.length;i++) {
  16801. merge.appendChild($.jgrid.makeNode(rels, 'mergeCell',{
  16802. attr: mergecell[i]
  16803. }));
  16804. }
  16805. }
  16806. if ( o.includeLabels ) {
  16807. addRow( data.header, true );
  16808. $('row:last c', rels).attr( 's', '2' ); // bold
  16809. }
  16810. if( $t.p.grouping ) {
  16811. groupToExcel(data.body);
  16812. } else {
  16813. for ( var n=0, ie=data.body.length ; n<ie ; n++ ) {
  16814. addRow( data.body[n], false );
  16815. }
  16816. }
  16817. if ( o.includeFooter || $t.p.footerrow) {
  16818. data.footer = $($t).jqGrid('footerData', 'get');
  16819. for( i in data.footer) {
  16820. if(data.footer.hasOwnProperty(i)) {
  16821. data.footer[i] = $.jgrid.stripHtml(data.footer[i]);
  16822. }
  16823. }
  16824. addRow( data.footer, true );
  16825. $('row:last c', rels).attr( 's', '2' ); // bold
  16826. }
  16827. // Set column widths
  16828. var cols = $.jgrid.makeNode( rels, 'cols' );
  16829. $('worksheet', rels).prepend( cols );
  16830. for ( i=0, ien=data.width.length ; i<ien ; i++ ) {
  16831. cols.appendChild( $.jgrid.makeNode( rels, 'col', {
  16832. attr: {
  16833. min: i+1,
  16834. max: i+1,
  16835. width: data.width[i],
  16836. customWidth: 1
  16837. }
  16838. } ) );
  16839. }
  16840. if($.isFunction( o.onBeforeExport) ) {
  16841. o.onBeforeExport( xlsx );
  16842. }
  16843. data = null; // free memory
  16844. try {
  16845. var zip = new JSZip();
  16846. var zipConfig = {
  16847. type: 'blob',
  16848. mimeType: o.mimetype
  16849. };
  16850. $.jgrid.xmlToZip( zip, xlsx );
  16851. if ( zip.generateAsync ) {
  16852. // JSZip 3+
  16853. zip.generateAsync( zipConfig )
  16854. .then( function ( blob ) {
  16855. $.jgrid.saveAs( blob, o.fileName, { type : o.mimetype } );
  16856. });
  16857. } else {
  16858. // JSZip 2.5
  16859. $.jgrid.saveAs( zip.generate( zipConfig ), o.fileName, { type : o.mimetype } ); }
  16860. } catch(e) {
  16861. throw e;
  16862. }
  16863. });
  16864. },
  16865. exportToPdf : function (o) {
  16866. o = $.extend(true,{
  16867. title: null,
  16868. orientation: 'portrait',
  16869. pageSize: 'A4',
  16870. description: null,
  16871. onBeforeExport: null,
  16872. download: 'download',
  16873. includeLabels : true,
  16874. includeGroupHeader : true,
  16875. includeFooter: true,
  16876. fileName : "jqGridExport.pdf",
  16877. mimetype : "application/pdf"
  16878. }, o || {} );
  16879. return this.each(function() {
  16880. var $t = this, rows = [], j, cm = $t.p.colModel, ien, obj = {}, key,
  16881. data = $t.addLocalData( true ), def = [], i=0, map=[], test=[], widths = [], align={};
  16882. // Group function
  16883. function groupToPdf ( grdata ) {
  16884. var grp = $t.p.groupingView,
  16885. cp=[], len =grp.groupField.length,
  16886. cm = $t.p.colModel,
  16887. colspans = cm.length,
  16888. toEnd = 0;
  16889. $.each(cm, function (i,n){
  16890. var ii;
  16891. for(ii=0;ii<len;ii++) {
  16892. if(grp.groupField[ii] === n.name ) {
  16893. cp[ii] = i;
  16894. break;
  16895. }
  16896. }
  16897. });
  16898. function constructRow( row, fmt ) {
  16899. var k =0, test=[];
  16900. //row = data[i];
  16901. for( var key=0; key < def.length; key++ ) {
  16902. obj = {
  16903. text: row[def[key]] == null ? '' : (fmt ? $.jgrid.formatCell( row[def[key]] + '', map[k], data[i], cm[map[k]], $t) : row[def[key]]),
  16904. alignment : align[key],
  16905. style : 'tableBody'
  16906. };
  16907. test.push(obj);
  16908. k++;
  16909. }
  16910. return test;
  16911. }
  16912. function findGroupIdx( ind , offset, grp) {
  16913. var ret = false, i;
  16914. if(offset===0) {
  16915. ret = grp[ind];
  16916. } else {
  16917. var id = grp[ind].idx;
  16918. if(id===0) {
  16919. ret = grp[ind];
  16920. } else {
  16921. for(i=ind;i >= 0; i--) {
  16922. if(grp[i].idx === id-offset) {
  16923. ret = grp[i];
  16924. break;
  16925. }
  16926. }
  16927. }
  16928. }
  16929. return ret;
  16930. }
  16931. function buildSummaryTd(i, ik, grp, foffset) {
  16932. var fdata = findGroupIdx(i, ik, grp),
  16933. //cm = $t.p.colModel,
  16934. vv, grlen = fdata.cnt, k, retarr = emptyData(def);
  16935. for(k=foffset; k<colspans;k++) {
  16936. if(cm[k].hidden || !cm[k].exportcol) {
  16937. continue;
  16938. }
  16939. var tplfld = "{0}";
  16940. $.each(fdata.summary,function(){
  16941. if(this.nm === cm[k].name) {
  16942. if(cm[k].summaryTpl) {
  16943. tplfld = cm[k].summaryTpl;
  16944. }
  16945. if(typeof this.st === 'string' && this.st.toLowerCase() === 'avg') {
  16946. if(this.sd && this.vd) {
  16947. this.v = (this.v/this.vd);
  16948. } else if(this.v && grlen > 0) {
  16949. this.v = (this.v/grlen);
  16950. }
  16951. }
  16952. try {
  16953. this.groupCount = fdata.cnt;
  16954. this.groupIndex = fdata.dataIndex;
  16955. this.groupValue = fdata.value;
  16956. vv = $t.formatter('', this.v, k, this);
  16957. } catch (ef) {
  16958. vv = this.v;
  16959. }
  16960. retarr[this.nm] = $.jgrid.stripHtml( $.jgrid.template(tplfld,vv) );
  16961. return false;
  16962. }
  16963. });
  16964. }
  16965. return retarr;
  16966. }
  16967. function emptyData ( d ) {
  16968. var clone = {};
  16969. for(var key = 0; key< d.length; key++ ) {
  16970. clone[d[key]] = "";
  16971. }
  16972. return clone;
  16973. }
  16974. var sumreverse = $.makeArray(grp.groupSummary), gv;
  16975. sumreverse.reverse();
  16976. $.each(grp.groups,function(i,n){
  16977. toEnd++;
  16978. try {
  16979. if ($.isArray(grp.formatDisplayField) && $.isFunction(grp.formatDisplayField[n.idx])) {
  16980. gv = grp.formatDisplayField[n.idx].call($t, n.displayValue, n.value, $t.p.colModel[cp[n.idx]], n.idx, grp);
  16981. } else {
  16982. gv = $t.formatter('', n.displayValue, cp[n.idx], n.value );
  16983. }
  16984. } catch (egv) {
  16985. gv = n.displayValue;
  16986. }
  16987. var grpTextStr = '';
  16988. if($.isFunction(grp.groupText[n.idx])) {
  16989. grpTextStr = grp.groupText[n.idx].call($t, gv, n.cnt, n.summary);
  16990. } else {
  16991. grpTextStr = $.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary);
  16992. }
  16993. if( !(typeof grpTextStr ==='string' || typeof grpTextStr ==='number' ) ) {
  16994. grpTextStr = gv;
  16995. }
  16996. var arr;
  16997. if(grp.groupSummaryPos[n.idx] === 'header') {
  16998. arr = buildSummaryTd(i, 0, grp.groups, 0 /*grp.groupColumnShow[n.idx] === false ? (mul ==="" ? 2 : 3) : ((mul ==="") ? 1 : 2)*/ );
  16999. } else {
  17000. arr = emptyData(def);
  17001. }
  17002. var fkey = Object.keys(arr);
  17003. arr[fkey[0]] = $.jgrid.stripHtml( new Array(n.idx*5).join(' ') + grpTextStr );
  17004. rows.push( constructRow (arr, false) );
  17005. var leaf = len-1 === n.idx;
  17006. if( leaf ) {
  17007. var gg = grp.groups[i+1], kk, ik, offset = 0, sgr = n.startRow,
  17008. end = gg !== undefined ? gg.startRow : grp.groups[i].startRow + grp.groups[i].cnt;
  17009. for(kk=sgr;kk<end;kk++) {
  17010. if(!grdata[kk - offset]) { break; }
  17011. var to = grdata[kk - offset];
  17012. rows.push( constructRow (to, true) );
  17013. }
  17014. if(grp.groupSummaryPos[n.idx] !== 'header') {
  17015. var jj;
  17016. if (gg !== undefined) {
  17017. for (jj = 0; jj < grp.groupField.length; jj++) {
  17018. if (gg.dataIndex === grp.groupField[jj]) {
  17019. break;
  17020. }
  17021. }
  17022. toEnd = grp.groupField.length - jj;
  17023. }
  17024. for (ik = 0; ik < toEnd; ik++) {
  17025. if(!sumreverse[ik]) { continue; }
  17026. arr = buildSummaryTd(i, ik, grp.groups, 0);
  17027. rows.push( constructRow (arr, false) );
  17028. }
  17029. toEnd = jj;
  17030. }
  17031. }
  17032. });
  17033. }
  17034. //============================================================================
  17035. var k;
  17036. for ( j=0, ien=cm.length ; j<ien ; j++ ) {
  17037. if(cm[j].exportcol === undefined ) {
  17038. cm[j].exportcol = true;
  17039. }
  17040. if(cm[j].hidden || cm[j].name === 'cb' || cm[j].name === 'rn' || !cm[j].exportcol) {
  17041. continue;
  17042. }
  17043. obj = { text: $t.p.colNames[j], style: 'tableHeader' };
  17044. test.push( obj );
  17045. def[i] = cm[j].name;
  17046. map[i] = j;
  17047. widths.push(cm[j].width);
  17048. align[cm[j].name] = cm[j].align || 'left';
  17049. i++;
  17050. }
  17051. var gh;
  17052. if(o.includeGroupHeader && $t.p.groupHeader && $t.p.groupHeader.length) {
  17053. gh = $t.p.groupHeader;
  17054. for (i=0;i < gh.length; i++) {
  17055. var clone = [],
  17056. ghdata = gh[i].groupHeaders;
  17057. for(key=0; key < def.length; key++ ) {
  17058. obj = {text:'', style: 'tableHeader'};
  17059. for(k=0;k<ghdata.length;k++) {
  17060. if(ghdata[k].startColumnName === def[key]) {
  17061. obj = {
  17062. text : ghdata[k].titleText,
  17063. colSpan: ghdata[k].numberOfColumns,
  17064. style: 'tableHeader'
  17065. };
  17066. }
  17067. }
  17068. clone.push(obj);
  17069. j++;
  17070. }
  17071. rows.push(clone);
  17072. }
  17073. }
  17074. if(o.includeLabels) {
  17075. rows.push( test );
  17076. }
  17077. if($t.p.grouping) {
  17078. groupToPdf(data);
  17079. } else {
  17080. var row;
  17081. for ( i=0, ien=data.length ; i<ien ; i++ ) {
  17082. k =0;
  17083. test=[];
  17084. row = data[i];
  17085. for( key = 0;key < def.length; key++ ) {
  17086. obj = {
  17087. text: row[def[key]] == null ? '' : $.jgrid.formatCell( row[def[key]] + '', map[k], data[i], cm[map[k]], $t),
  17088. alignment : align[def[key]],
  17089. style : 'tableBody'
  17090. };
  17091. test.push(obj);
  17092. k++;
  17093. }
  17094. rows.push(test);
  17095. }
  17096. }
  17097. if ( o.includeFooter && $t.p.footerrow) {
  17098. var fdata = $($t).jqGrid('footerData', 'get');
  17099. test=[];
  17100. for( key =0; key< def.length; key++) {
  17101. obj = {
  17102. text : $.jgrid.stripHtml(fdata[def[key]]),
  17103. style : 'tableFooter',
  17104. alignment : align[def[key]]
  17105. };
  17106. test.push( obj );
  17107. }
  17108. rows.push( test );
  17109. }
  17110. var doc = {
  17111. pageSize: o.pageSize,
  17112. pageOrientation: o.orientation,
  17113. content: [
  17114. {
  17115. style : 'tableExample',
  17116. widths : widths,
  17117. table: {
  17118. headerRows: (gh!=null) ? 0 : 1,
  17119. body: rows
  17120. }
  17121. }
  17122. ],
  17123. styles: {
  17124. tableHeader: {
  17125. bold: true,
  17126. fontSize: 11,
  17127. color: '#2e6e9e',
  17128. fillColor: '#dfeffc',
  17129. alignment: 'center'
  17130. },
  17131. tableBody: {
  17132. fontSize: 10
  17133. },
  17134. tableFooter: {
  17135. bold: true,
  17136. fontSize: 11,
  17137. color: '#2e6e9e',
  17138. fillColor: '#dfeffc'
  17139. },
  17140. title: {
  17141. alignment: 'center',
  17142. fontSize: 15
  17143. },
  17144. description: {}
  17145. },
  17146. defaultStyle: {
  17147. fontSize: 10
  17148. }
  17149. };
  17150. if ( o.description ) {
  17151. doc.content.unshift( {
  17152. text: o.description,
  17153. style: 'description',
  17154. margin: [ 0, 0, 0, 12 ]
  17155. } );
  17156. }
  17157. if ( o.title ) {
  17158. doc.content.unshift( {
  17159. text: o.title,
  17160. style: 'title',
  17161. margin: [ 0, 0, 0, 12 ]
  17162. } );
  17163. }
  17164. if( $.isFunction( o.onBeforeExport ) ) {
  17165. o.onBeforeExport.call($t, doc);
  17166. }
  17167. try {
  17168. var pdf = pdfMake.createPdf( doc );
  17169. if ( o.download === 'open' ) {
  17170. pdf.open();
  17171. } else {
  17172. pdf.getBuffer( function (buffer) {
  17173. $.jgrid.saveAs( buffer, o.fileName, {type: o.mimetype } );
  17174. } );
  17175. }
  17176. } catch(e) {
  17177. throw e;
  17178. }
  17179. });
  17180. }
  17181. });
  17182. }));